1 | /* client.c --- Non-standard SASL mechanism LOGIN, client side. |
2 | * Copyright (C) 2002-2012 Simon Josefsson |
3 | * |
4 | * This file is part of GNU SASL Library. |
5 | * |
6 | * GNU SASL Library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public License |
8 | * as published by the Free Software Foundation; either version 2.1 of |
9 | * the License, or (at your option) any later version. |
10 | * |
11 | * GNU SASL Library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with GNU SASL Library; if not, write to the Free |
18 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #ifdef HAVE_CONFIG_H |
24 | #include "config.h" |
25 | #endif |
26 | |
27 | /* Get malloc, free. */ |
28 | #include <stdlib.h> |
29 | |
30 | /* Get strlen. */ |
31 | #include <string.h> |
32 | |
33 | /* Get specification. */ |
34 | #include "login.h" |
35 | |
36 | struct _Gsasl_login_client_state |
37 | { |
38 | int step; |
39 | }; |
40 | |
41 | int |
42 | _gsasl_login_client_start (Gsasl_session * sctx, void **mech_data) |
43 | { |
44 | struct _Gsasl_login_client_state *state; |
45 | |
46 | state = malloc (sizeof (*state)); |
47 | if (state == NULL) |
48 | return GSASL_MALLOC_ERROR; |
49 | |
50 | state->step = 0; |
51 | |
52 | *mech_data = state; |
53 | |
54 | return GSASL_OK; |
55 | } |
56 | |
57 | int |
58 | _gsasl_login_client_step (Gsasl_session * sctx, |
59 | void *mech_data, |
60 | const char *input, size_t input_len, |
61 | char **output, size_t * output_len) |
62 | { |
63 | struct _Gsasl_login_client_state *state = mech_data; |
64 | const char *p; |
65 | int res; |
66 | |
67 | switch (state->step) |
68 | { |
69 | case 0: |
70 | p = gsasl_property_get (sctx, GSASL_AUTHID); |
71 | if (!p) |
72 | return GSASL_NO_AUTHID; |
73 | |
74 | *output = strdup (p); |
75 | *output_len = strlen (p); |
76 | |
77 | state->step++; |
78 | res = GSASL_NEEDS_MORE; |
79 | break; |
80 | |
81 | case 1: |
82 | p = gsasl_property_get (sctx, GSASL_PASSWORD); |
83 | if (!p) |
84 | return GSASL_NO_PASSWORD; |
85 | |
86 | *output = strdup (p); |
87 | *output_len = strlen (*output); |
88 | |
89 | state->step++; |
90 | res = GSASL_OK; |
91 | break; |
92 | |
93 | default: |
94 | res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES; |
95 | break; |
96 | } |
97 | |
98 | return res; |
99 | } |
100 | |
101 | void |
102 | _gsasl_login_client_finish (Gsasl_session * sctx, void *mech_data) |
103 | { |
104 | struct _Gsasl_login_client_state *state = mech_data; |
105 | |
106 | if (!state) |
107 | return; |
108 | |
109 | free (state); |
110 | } |
111 | |