Branch data Line data Source code
1 : : /* simple.c --- Test the simple SASL mechanisms, using old APIs.
2 : : * Copyright (C) 2002-2012 Simon Josefsson
3 : : *
4 : : * This file is part of GNU SASL.
5 : : *
6 : : * This program is free software: you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation, either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * This program 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
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : : *
19 : : */
20 : :
21 : : #ifdef HAVE_CONFIG_H
22 : : #include "config.h"
23 : : #endif
24 : :
25 : : #include <stdio.h>
26 : : #include <stdarg.h>
27 : : #include <stdlib.h>
28 : : #include <string.h>
29 : : #include <gsasl.h>
30 : :
31 : : #include "utils.h"
32 : :
33 : : #define MAX_LINE_LENGTH BUFSIZ
34 : :
35 : : #define MAXSTEP 50
36 : : #define CLIENT 1
37 : : #define SERVER 0
38 : : #define UTF8_a "\xC2\xAA"
39 : :
40 : : struct sasltv
41 : : {
42 : : int clientp;
43 : : const char *mech;
44 : : const char *step[MAXSTEP];
45 : : const char *password;
46 : : const char *authzid;
47 : : const char *authid;
48 : : const char *service;
49 : : const char *hostname;
50 : : const char *servicename;
51 : : const char *anonymous;
52 : : const char *passcode;
53 : : const char *suggestpin;
54 : : const char *pin;
55 : : int securidrc;
56 : : };
57 : : static struct sasltv sasltv[] = {
58 : : {CLIENT, "EXTERNAL", {"", NULL}},
59 : : {SERVER, "EXTERNAL", {"", NULL}},
60 : : {CLIENT, "ANONYMOUS", {"", "Zm9vQGJhci5jb20=", NULL, NULL}, NULL, NULL,
61 : : NULL, NULL, NULL, NULL, "foo@bar.com"},
62 : : {SERVER, "ANONYMOUS", {"Zm9vQGJhci5jb20=", NULL, NULL}, NULL, NULL, NULL,
63 : : NULL, NULL, NULL, "foo@bar.com"},
64 : : {CLIENT, "NTLM",
65 : : {"Kw==", "TlRMTVNTUAABAAAAB7IAAAYABgAgAAAAAAAAACYAAABhdXRoaWQ=",
66 : : "TlRMTVNTUAAAAAAAAAAAAAAAAAAAAGFiY2RlZmdoMDEyMzQ1Njc4ODY2NDQwMTIz",
67 : : "TlRMTVNTUAADAAAAGAAYAFgAAAAYABgAcAAAAAAAAABAAAAADAAMAEAAAAAMAAwATAAAA"
68 : : "AAAAACIAAAAAABhYmEAdQB0AGgAaQBkAGEAdQB0AGgAaQBkABeBBp9xJad9eYo3oh1k55"
69 : : "GNFDIui8H8Qz4CfWYVVToBhVzFFbzyzqAZN5Wl59K/Fg==",
70 : : NULL, NULL}, "password", "authzid", "authid"},
71 : : {CLIENT, "PLAIN",
72 : : {"", "YXV0aHppZABhdXRoaWQAcGFzc3dvcmQ=", NULL, NULL}, "password",
73 : : "authzid", "authid"},
74 : : {CLIENT, "PLAIN",
75 : : {"", "YQBhAGE=", NULL, NULL}, "a", "a", "a"},
76 : : {CLIENT, "PLAIN",
77 : : {"", "wqoAwqoAwqo=", NULL, NULL}, UTF8_a, UTF8_a, UTF8_a},
78 : : {SERVER, "PLAIN",
79 : : {"YXV0aHppZABhdXRoaWQAcGFzc3dvcmQ=", NULL, NULL}, "password", "authzid",
80 : : "authid"},
81 : : {SERVER, "PLAIN",
82 : : {"", "", "YXV0aHppZABhdXRoaWQAcGFzc3dvcmQ=", NULL, NULL}, "password",
83 : : "authzid", "authid"},
84 : : {CLIENT, "LOGIN",
85 : : {"VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "cGFzc3dvcmQ=", NULL,
86 : : NULL}, "password", NULL, "authid"},
87 : : {CLIENT, "LOGIN",
88 : : {"VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "YQ==", NULL, NULL}, "a",
89 : : NULL,
90 : : "authid"},
91 : : {CLIENT, "LOGIN",
92 : : {"VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "wqo=", NULL, NULL}, UTF8_a,
93 : : NULL, "authid"},
94 : : {SERVER, "LOGIN",
95 : : {"", "VXNlciBOYW1l", "YXV0aGlk", "UGFzc3dvcmQ=", "cGFzc3dvcmQ=",
96 : : NULL, NULL}, "password", NULL, "authid"},
97 : : {CLIENT, "CRAM-MD5",
98 : : {"PGNiNmQ5YTQ5ZDA3ZjEwY2MubGliZ3Nhc2xAbG9jYWxob3N0Pg==",
99 : : "YXV0aGlkIGZkNjRmMjYxZWYxYjBjYjg0ZmZjNGVmYzgwZDk3NjFj", NULL, NULL},
100 : : "password", "authzid", "authid"},
101 : : {CLIENT, "SECURID",
102 : : {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid",
103 : : "authid", NULL, NULL, NULL, NULL, "4711"},
104 : : {CLIENT, "SECURID",
105 : : {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGFzc2NvZGU=",
106 : : "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid", "authid",
107 : : NULL, NULL, NULL, NULL, "4711"},
108 : : {CLIENT, "SECURID",
109 : : {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGlu",
110 : : "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", NULL, NULL}, NULL, "authzid",
111 : : "authid", NULL, NULL, NULL, NULL, "4711", NULL, "42"},
112 : : {CLIENT, "SECURID",
113 : : {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGluMjM=",
114 : : "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", NULL, NULL}, NULL, "authzid",
115 : : "authid", NULL, NULL, NULL, NULL, "4711", "23", "42"},
116 : : {CLIENT, "SECURID",
117 : : {"", "YXV0aHppZABhdXRoaWQANDcxMQA=", "cGluMjM=",
118 : : "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", "cGFzc2NvZGU=",
119 : : "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid", "authid",
120 : : NULL, NULL, NULL, NULL, "4711", "23", "42"},
121 : : {SERVER, "SECURID",
122 : : {"YXV0aHppZABhdXRoaWQANDcxMQA=", "", NULL, NULL}, NULL, "authzid",
123 : : "authid", NULL, NULL, NULL, NULL, "4711"},
124 : : {SERVER, "SECURID",
125 : : {"YXV0aHppZABhdXRoaWQANDcxMQA=", "", NULL, NULL}, NULL, "authzid",
126 : : "authid", NULL, NULL, NULL, NULL, "4711"},
127 : : {SERVER, "SECURID",
128 : : {"YXV0aHppZABhdXRoaWQANDcxMQA=", "cGlu",
129 : : "YXV0aHppZABhdXRoaWQANDcxMQA0MgA=", "", NULL, NULL}, NULL, "authzid",
130 : : "authid", NULL, NULL, NULL, NULL, "4711", NULL, "42",
131 : : GSASL_SECURID_SERVER_NEED_NEW_PIN},
132 : : {SERVER, "SECURID",
133 : : {"YXV0aHppZABhdXRoaWQANDcxMQA=", "cGluMTc=",
134 : : "YXV0aHppZABhdXRoaWQANDcxMQAyMwA=", "", NULL, NULL}, NULL, "authzid",
135 : : "authid", NULL, NULL, NULL, NULL, "4711", "17", "23",
136 : : GSASL_SECURID_SERVER_NEED_NEW_PIN},
137 : : {SERVER, "SECURID",
138 : : {"YXV0aHppZABhdXRoaWQANDcxMQA=", "cGFzc2NvZGU=",
139 : : "YXV0aHppZABhdXRoaWQANDcxMQA=", NULL, NULL}, NULL, "authzid", "authid",
140 : : NULL, NULL, NULL, NULL, "4711", NULL, NULL,
141 : : GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE}
142 : : };
143 : :
144 : : static int
145 : 9 : client_callback_authorization_id (Gsasl_session_ctx * xctx,
146 : : char *out, size_t * outlen)
147 : : {
148 : 9 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
149 : 9 : int i = *(int *) gsasl_application_data_get (ctx);
150 [ + + ]: 9 : size_t needlen = sasltv[i].authzid ? strlen (sasltv[i].authzid) : 0;
151 : :
152 [ - + ]: 9 : if (*outlen < needlen)
153 : 0 : return GSASL_TOO_SMALL_BUFFER;
154 : :
155 : 9 : *outlen = needlen;
156 [ + - ][ + + ]: 9 : if (out && sasltv[i].authzid)
157 : 8 : memcpy (out, sasltv[i].authzid, needlen);
158 : :
159 : 9 : return GSASL_OK;
160 : : }
161 : :
162 : : static int
163 : 12 : client_callback_authentication_id (Gsasl_session_ctx * xctx,
164 : : char *out, size_t * outlen)
165 : : {
166 : 12 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
167 : 12 : int i = *(int *) gsasl_application_data_get (ctx);
168 : 12 : size_t needlen = strlen (sasltv[i].authid);
169 : :
170 [ - + ]: 12 : if (*outlen < needlen)
171 : 0 : return GSASL_TOO_SMALL_BUFFER;
172 : :
173 : 12 : *outlen = needlen;
174 [ + - ]: 12 : if (out)
175 : 12 : memcpy (out, sasltv[i].authid, needlen);
176 : :
177 : 12 : return GSASL_OK;
178 : : }
179 : :
180 : : static int
181 : 0 : client_callback_password (Gsasl_session_ctx * xctx, char *out,
182 : : size_t * outlen)
183 : : {
184 : 0 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
185 : 0 : int i = *(int *) gsasl_application_data_get (ctx);
186 : 0 : size_t needlen = strlen (sasltv[i].password);
187 : :
188 [ # # ]: 0 : if (*outlen < needlen)
189 : 0 : return GSASL_TOO_SMALL_BUFFER;
190 : :
191 : 0 : *outlen = needlen;
192 [ # # ]: 0 : if (out)
193 : 0 : memcpy (out, sasltv[i].password, needlen);
194 : :
195 : 0 : return GSASL_OK;
196 : : }
197 : :
198 : : static int
199 : 3 : server_callback_validate (Gsasl_session_ctx * xctx,
200 : : const char *authorization_id,
201 : : const char *authentication_id, const char *password)
202 : : {
203 : 3 : Gsasl_ctx *ctx = gsasl_server_ctx_get (xctx);
204 : 3 : int i = *(int *) gsasl_application_data_get (ctx);
205 : :
206 [ + + ][ + - ]: 3 : if (authorization_id && sasltv[i].authzid &&
[ - + ]
207 : 2 : strcmp (authorization_id, sasltv[i].authzid) != 0)
208 : 0 : return GSASL_AUTHENTICATION_ERROR;
209 : :
210 [ + + ][ + - ]: 3 : if ((authorization_id == NULL && sasltv[i].authzid != NULL) ||
[ + + ]
211 [ - + ]: 2 : (authorization_id != NULL && sasltv[i].authzid == NULL))
212 : 0 : return GSASL_AUTHENTICATION_ERROR;
213 : :
214 [ + - ][ + - ]: 3 : if (authentication_id && sasltv[i].authid &&
[ - + ]
215 : 3 : strcmp (authentication_id, sasltv[i].authid) != 0)
216 : 0 : return GSASL_AUTHENTICATION_ERROR;
217 : :
218 [ - + ]: 3 : if (strcmp (password, sasltv[i].password) != 0)
219 : 0 : return GSASL_AUTHENTICATION_ERROR;
220 : :
221 : 3 : return GSASL_OK;
222 : : }
223 : :
224 : : static int
225 : 7 : server_callback_retrieve (Gsasl_session_ctx * xctx,
226 : : const char *authentication_id,
227 : : const char *authorization_id,
228 : : const char *realm, char *key, size_t * keylen)
229 : : {
230 : 7 : Gsasl_ctx *ctx = gsasl_server_ctx_get (xctx);
231 : 7 : int i = *(int *) gsasl_application_data_get (ctx);
232 : 7 : size_t needlen = strlen (sasltv[i].password);
233 : :
234 [ - + ]: 7 : if (*keylen < needlen)
235 : 0 : return GSASL_TOO_SMALL_BUFFER;
236 : :
237 : 7 : *keylen = strlen (sasltv[i].password);
238 [ + - ]: 7 : if (key)
239 : 7 : memcpy (key, sasltv[i].password, needlen);
240 : :
241 : 7 : return GSASL_OK;
242 : : }
243 : :
244 : : static int
245 : 0 : client_callback_service (Gsasl_session_ctx * ctx,
246 : : char *srv,
247 : : size_t * srvlen,
248 : : char *host,
249 : : size_t * hostlen, char *srvname, size_t * srvnamelen)
250 : : {
251 [ # # ]: 0 : if (srvlen)
252 : 0 : *srvlen = 0;
253 [ # # ]: 0 : if (hostlen)
254 : 0 : *hostlen = 0;
255 [ # # ]: 0 : if (srvnamelen)
256 : 0 : *srvnamelen = 0;
257 : :
258 : 0 : return GSASL_OK;
259 : : }
260 : :
261 : : static int
262 : 1 : client_callback_anonymous (Gsasl_session_ctx * xctx, char *out,
263 : : size_t * outlen)
264 : : {
265 : 1 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
266 : 1 : int i = *(int *) gsasl_application_data_get (ctx);
267 : 1 : size_t needlen = strlen (sasltv[i].anonymous);
268 : :
269 [ - + ]: 1 : if (*outlen < needlen)
270 : 0 : return GSASL_TOO_SMALL_BUFFER;
271 : :
272 : 1 : *outlen = needlen;
273 [ + - ]: 1 : if (out)
274 : 1 : memcpy (out, sasltv[i].anonymous, strlen (sasltv[i].anonymous));
275 : :
276 : 1 : return GSASL_OK;
277 : : }
278 : :
279 : : static int
280 : 1 : server_callback_anonymous (Gsasl_session_ctx * xctx, const char *token)
281 : : {
282 : 1 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
283 : 1 : int i = *(int *) gsasl_application_data_get (ctx);
284 : :
285 [ + - ]: 1 : return strcmp (sasltv[i].anonymous, token) == 0 ? GSASL_OK :
286 : : GSASL_AUTHENTICATION_ERROR;
287 : : }
288 : :
289 : : static int
290 : 1 : server_callback_external (Gsasl_session_ctx * xctx)
291 : : {
292 : 1 : return GSASL_OK;
293 : : }
294 : :
295 : : static int
296 : 5 : client_callback_passcode (Gsasl_session_ctx * xctx, char *out,
297 : : size_t * outlen)
298 : : {
299 : 5 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
300 : 5 : int i = *(int *) gsasl_application_data_get (ctx);
301 : 5 : size_t needlen = strlen (sasltv[i].passcode);
302 : :
303 [ - + ]: 5 : if (*outlen < needlen)
304 : 0 : return GSASL_TOO_SMALL_BUFFER;
305 : :
306 : 5 : *outlen = needlen;
307 [ + - ]: 5 : if (out)
308 : 5 : memcpy (out, sasltv[i].passcode, needlen);
309 : :
310 : 5 : return GSASL_OK;
311 : : }
312 : :
313 : : static int
314 : 3 : client_callback_pin (Gsasl_session_ctx * xctx, char *suggestion,
315 : : char *out, size_t * outlen)
316 : : {
317 : 3 : Gsasl_ctx *ctx = gsasl_client_ctx_get (xctx);
318 : 3 : int i = *(int *) gsasl_application_data_get (ctx);
319 : 3 : size_t needlen = strlen (sasltv[i].pin);
320 : :
321 [ + + ][ + - ]: 3 : if (suggestion && sasltv[i].suggestpin &&
[ - + ]
322 : 2 : strcmp (suggestion, sasltv[i].suggestpin) != 0)
323 : 0 : return GSASL_AUTHENTICATION_ERROR;
324 : :
325 [ + + ][ + - ]: 3 : if ((suggestion == NULL && sasltv[i].suggestpin != NULL) ||
[ + + ]
326 [ - + ]: 2 : (suggestion != NULL && sasltv[i].suggestpin == NULL))
327 : 0 : return GSASL_AUTHENTICATION_ERROR;
328 : :
329 [ - + ]: 3 : if (*outlen < needlen)
330 : 0 : return GSASL_TOO_SMALL_BUFFER;
331 : :
332 : 3 : *outlen = needlen;
333 [ + - ]: 3 : if (out)
334 : 3 : memcpy (out, sasltv[i].pin, needlen);
335 : :
336 : 3 : return GSASL_OK;
337 : : }
338 : :
339 : : static int
340 : 8 : server_callback_securid (Gsasl_session_ctx * xctx,
341 : : const char *authentication_id,
342 : : const char *authorization_id,
343 : : const char *passcode,
344 : : char *pin, char *suggestpin, size_t * suggestpinlen)
345 : : {
346 : 8 : Gsasl_ctx *ctx = gsasl_server_ctx_get (xctx);
347 : 8 : int i = *(int *) gsasl_application_data_get (ctx);
348 : : int res;
349 : :
350 [ - + ]: 8 : if (strcmp (passcode, sasltv[i].passcode) != 0)
351 : 0 : return GSASL_AUTHENTICATION_ERROR;
352 : :
353 [ + + ]: 8 : if (sasltv[i].securidrc == GSASL_SECURID_SERVER_NEED_NEW_PIN)
354 : : {
355 : 2 : res = sasltv[i].securidrc;
356 : 2 : sasltv[i].securidrc = GSASL_OK;
357 : :
358 [ + + ]: 2 : if (sasltv[i].suggestpin)
359 : : {
360 [ + - ]: 1 : if (*suggestpinlen)
361 : 1 : *suggestpinlen = strlen (sasltv[i].suggestpin);
362 [ + - ]: 1 : if (suggestpin)
363 : 1 : memcpy (suggestpin, sasltv[i].suggestpin,
364 : : strlen (sasltv[i].suggestpin));
365 : : }
366 [ + - ]: 1 : else if (*suggestpinlen)
367 : 1 : *suggestpinlen = 0;
368 : : }
369 [ + + ]: 6 : else if (sasltv[i].securidrc ==
370 : : GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE)
371 : : {
372 : 1 : res = sasltv[i].securidrc;
373 : 1 : sasltv[i].securidrc = GSASL_OK;
374 : : }
375 : : else
376 : : {
377 : 5 : res = sasltv[i].securidrc;
378 : :
379 [ + + ][ + - ]: 5 : if (pin && sasltv[i].pin && strcmp (pin, sasltv[i].pin) != 0)
[ - + ]
380 : 0 : return GSASL_AUTHENTICATION_ERROR;
381 : :
382 [ + + ][ + - ]: 5 : if ((pin == NULL && sasltv[i].pin != NULL) ||
[ + + ]
383 [ - + ]: 2 : (pin != NULL && sasltv[i].pin == NULL))
384 : 0 : return GSASL_AUTHENTICATION_ERROR;
385 : :
386 [ + - ]: 5 : if (*suggestpinlen)
387 : 5 : *suggestpinlen = 0;
388 : : }
389 : :
390 : 8 : return res;
391 : : }
392 : :
393 : : void
394 : 1 : doit (void)
395 : : {
396 : 1 : Gsasl_ctx *ctx = NULL;
397 : 1 : Gsasl_session_ctx *xctx = NULL;
398 : : char output[MAX_LINE_LENGTH];
399 : : size_t outputlen;
400 : : int i, j;
401 : : int res;
402 : :
403 [ - + ]: 1 : if (!gsasl_check_version (GSASL_VERSION))
404 : 0 : fail ("gsasl_check_version failure");
405 : :
406 : 1 : success ("Header version %s library version %s\n",
407 : : GSASL_VERSION, gsasl_check_version (NULL));
408 : :
409 : 1 : res = gsasl_init (&ctx);
410 [ - + ]: 1 : if (res != GSASL_OK)
411 : : {
412 : 0 : fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res));
413 : 1 : return;
414 : : }
415 : :
416 : : gsasl_client_callback_authentication_id_set
417 : 1 : (ctx, client_callback_authentication_id);
418 : : gsasl_client_callback_authorization_id_set
419 : 1 : (ctx, client_callback_authorization_id);
420 : 1 : gsasl_client_callback_password_set (ctx, client_callback_password);
421 : 1 : gsasl_server_callback_validate_set (ctx, server_callback_validate);
422 : 1 : gsasl_server_callback_retrieve_set (ctx, server_callback_retrieve);
423 : 1 : gsasl_client_callback_service_set (ctx, client_callback_service);
424 : 1 : gsasl_client_callback_anonymous_set (ctx, client_callback_anonymous);
425 : 1 : gsasl_server_callback_anonymous_set (ctx, server_callback_anonymous);
426 : 1 : gsasl_server_callback_external_set (ctx, server_callback_external);
427 : 1 : gsasl_client_callback_passcode_set (ctx, client_callback_passcode);
428 : 1 : gsasl_client_callback_pin_set (ctx, client_callback_pin);
429 : 1 : gsasl_server_callback_securid_set (ctx, server_callback_securid);
430 : :
431 : 1 : outputlen = sizeof (output);
432 : 1 : res = gsasl_client_listmech (ctx, output, &outputlen);
433 [ - + ]: 1 : if (res != GSASL_OK)
434 : 0 : fail ("gsasl_client_listmech() failed (%d):\n%s\n",
435 : : res, gsasl_strerror (res));
436 : :
437 : 1 : outputlen = sizeof (output);
438 : 1 : res = gsasl_server_listmech (ctx, output, &outputlen);
439 [ - + ]: 1 : if (res != GSASL_OK)
440 : 0 : fail ("gsasl_server_listmech() failed (%d):\n%s\n",
441 : : res, gsasl_strerror (res));
442 : :
443 [ + + ]: 26 : for (i = 0; i < sizeof (sasltv) / sizeof (sasltv[0]); i++)
444 : : {
445 : 25 : gsasl_application_data_set (ctx, &i);
446 : :
447 [ + - ]: 25 : if (debug)
448 [ + + ]: 25 : printf ("Entry %d %s mechanism %s:\n",
449 : 25 : i, sasltv[i].clientp ? "client" : "server", sasltv[i].mech);
450 : :
451 [ + + ]: 25 : if (sasltv[i].clientp)
452 : 15 : res = gsasl_client_support_p (ctx, sasltv[i].mech);
453 : : else
454 : 10 : res = gsasl_server_support_p (ctx, sasltv[i].mech);
455 [ + + ]: 25 : if (!res)
456 : 1 : continue;
457 : :
458 [ + + ]: 24 : if (sasltv[i].clientp)
459 : 14 : res = gsasl_client_start (ctx, sasltv[i].mech, &xctx);
460 : : else
461 : 10 : res = gsasl_server_start (ctx, sasltv[i].mech, &xctx);
462 [ - + ]: 24 : if (res != GSASL_OK)
463 : : {
464 [ # # ]: 0 : fail ("SASL %s start for mechanism %s failed (%d):\n%s\n",
465 : 0 : sasltv[i].clientp ? "client" : "server",
466 : : sasltv[i].mech, res, gsasl_strerror (res));
467 : 0 : continue;
468 : : }
469 : :
470 [ + + ]: 48 : for (j = 0; sasltv[i].step[j]; j += 2)
471 : : {
472 [ + + ]: 38 : if (sasltv[i].clientp)
473 : 22 : gsasl_client_application_data_set (xctx, &j);
474 : : else
475 : 16 : gsasl_server_application_data_set (xctx, &j);
476 : :
477 [ + - ]: 38 : if (debug)
478 [ + - ]: 38 : printf ("Input : %s\n",
479 : 76 : sasltv[i].step[j] ? sasltv[i].step[j] : "");
480 : :
481 : 38 : output[0] = '\0';
482 : 38 : outputlen = sizeof (output);
483 [ + + ]: 38 : if (sasltv[i].clientp)
484 : 22 : res = gsasl_client_step_base64 (xctx, sasltv[i].step[j],
485 : : output, outputlen);
486 : : else
487 : 16 : res = gsasl_server_step_base64 (xctx, sasltv[i].step[j],
488 : : output, outputlen);
489 : :
490 [ + - ]: 38 : if (debug)
491 : 38 : printf ("Output: %s\n", output);
492 : :
493 [ + + ][ - + ]: 38 : if (res != GSASL_OK && res != GSASL_NEEDS_MORE)
494 : 0 : break;
495 : :
496 [ - + ]: 38 : if (strlen (output) !=
497 [ + + ]: 38 : strlen (sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : ""))
498 : : {
499 [ # # ]: 0 : printf ("Expected: %s\n", sasltv[i].step[j + 1] ?
500 : 0 : sasltv[i].step[j + 1] : "");
501 : : fail
502 : 0 : ("SASL entry %d mechanism %s client step %d length error\n",
503 : : i, sasltv[i].mech, j);
504 : 0 : j = -1;
505 : 0 : break;
506 : : }
507 : :
508 [ + + ][ - + ]: 38 : if (strcmp (output, sasltv[i].step[j + 1] ?
509 : 31 : sasltv[i].step[j + 1] : "") != 0)
510 : : {
511 [ # # ]: 0 : printf ("Expected: %s\n", sasltv[i].step[j + 1] ?
512 : 0 : sasltv[i].step[j + 1] : "");
513 : 0 : fail ("SASL entry %d mechanism %s client step %d data error\n",
514 : : i, sasltv[i].mech, j);
515 : 0 : j = -1;
516 : 0 : break;
517 : : }
518 : :
519 [ + + ][ + + ]: 38 : if (strcmp (sasltv[i].mech, "SECURID") != 0 && res == GSASL_OK)
520 : 14 : break;
521 : : }
522 : :
523 [ + - ][ + - ]: 24 : if (j != (size_t) - 1 && res == GSASL_OK && sasltv[i].step[j + 2])
[ - + ]
524 : 0 : fail ("SASL entry %d mechanism %s step %d code ended prematurely\n",
525 : : i, sasltv[i].mech, j);
526 [ + - ][ - + ]: 24 : else if (j != (size_t) - 1 && res == GSASL_NEEDS_MORE)
527 : 0 : fail ("SASL entry %d mechanism %s step %d table ended prematurely\n",
528 : : i, sasltv[i].mech, j);
529 [ + - ][ - + ]: 24 : else if (j != (size_t) - 1 && res != GSASL_OK)
530 : 0 : fail ("SASL entry %d mechanism %s step %d failed (%d):\n%s\n",
531 : : i, sasltv[i].mech, j, res, gsasl_strerror (res));
532 : : else
533 [ + + ]: 24 : printf ("PASS: simple %s %s %d\n", sasltv[i].mech,
534 : 24 : sasltv[i].clientp ? "client" : "server", i);
535 : :
536 [ + + ]: 24 : if (sasltv[i].clientp)
537 : 14 : gsasl_client_finish (xctx);
538 : : else
539 : 10 : gsasl_server_finish (xctx);
540 : :
541 [ + - ]: 24 : if (debug)
542 : 24 : printf ("\n");
543 : : }
544 : :
545 : 1 : gsasl_done (ctx);
546 : : }
|