614c179b770319f24d24deeafb4512d6987170f3
[exim.git] / src / src / auths / gsasl_exim.c
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* See the file NOTICE for conditions of use and distribution. */
7
8 /* Copyright (c) Twitter Inc 2012
9 Author: Phil Pennock <pdp@exim.org> */
10 /* Copyright (c) Phil Pennock 2012 */
11
12 /* Interface to GNU SASL library for generic authentication. */
13
14 /* Trade-offs:
15
16 GNU SASL does not provide authentication data itself, so we have to expose
17 that decision to configuration. For some mechanisms, we need to act much
18 like plaintext. For others, we only need to be able to provide some
19 evaluated data on demand. There's no abstracted way (ie, without hardcoding
20 knowledge of authenticators here) to know which need what properties; we
21 can't query a session or the library for "we will need these for mechanism X".
22
23 So: we always require server_condition, even if sometimes it will just be
24 set as "yes". We do provide a number of other hooks, which might not make
25 sense in all contexts. For some, we can do checks at init time.
26 */
27
28 #include "../exim.h"
29
30 #ifndef AUTH_GSASL
31 /* dummy function to satisfy compilers when we link in an "empty" file. */
32 static void dummy(int x);
33 static void dummy2(int x) { dummy(x-1); }
34 static void dummy(int x) { dummy2(x-1); }
35 #else
36
37 #include <gsasl.h>
38 #include "gsasl_exim.h"
39
40 /* Authenticator-specific options. */
41 /* I did have server_*_condition options for various mechanisms, but since
42 we only ever handle one mechanism at a time, I didn't see the point in keeping
43 that. In case someone sees a point, I've left the condition_check() API
44 alone. */
45 optionlist auth_gsasl_options[] = {
46 { "server_channelbinding", opt_bool,
47 (void *)(offsetof(auth_gsasl_options_block, server_channelbinding)) },
48 { "server_hostname", opt_stringptr,
49 (void *)(offsetof(auth_gsasl_options_block, server_hostname)) },
50 { "server_mech", opt_stringptr,
51 (void *)(offsetof(auth_gsasl_options_block, server_mech)) },
52 { "server_password", opt_stringptr,
53 (void *)(offsetof(auth_gsasl_options_block, server_password)) },
54 { "server_realm", opt_stringptr,
55 (void *)(offsetof(auth_gsasl_options_block, server_realm)) },
56 { "server_scram_iter", opt_stringptr,
57 (void *)(offsetof(auth_gsasl_options_block, server_scram_iter)) },
58 { "server_scram_salt", opt_stringptr,
59 (void *)(offsetof(auth_gsasl_options_block, server_scram_salt)) },
60 { "server_service", opt_stringptr,
61 (void *)(offsetof(auth_gsasl_options_block, server_service)) }
62 };
63 /* GSASL_SCRAM_SALTED_PASSWORD documented only for client, so not implementing
64 hooks to avoid cleartext passwords in the Exim server. */
65
66 int auth_gsasl_options_count =
67 sizeof(auth_gsasl_options)/sizeof(optionlist);
68
69 /* Defaults for the authenticator-specific options. */
70 auth_gsasl_options_block auth_gsasl_option_defaults = {
71 US"smtp", /* server_service */
72 US"$primary_hostname", /* server_hostname */
73 NULL, /* server_realm */
74 NULL, /* server_mech */
75 NULL, /* server_password */
76 NULL, /* server_scram_iter */
77 NULL, /* server_scram_salt */
78 FALSE /* server_channelbinding */
79 };
80
81
82 #ifdef MACRO_PREDEF
83
84 /* Dummy values */
85 void auth_gsasl_init(auth_instance *ablock) {}
86 int auth_gsasl_server(auth_instance *ablock, uschar *data) {return 0;}
87 int auth_gsasl_client(auth_instance *ablock, smtp_inblock * sx,
88 int timeout, uschar *buffer, int buffsize) {return 0;}
89 void auth_gsasl_version_report(FILE *f) {}
90
91 #else /*!MACRO_PREDEF*/
92
93
94
95 /* "Globals" for managing the gsasl interface. */
96
97 static Gsasl *gsasl_ctx = NULL;
98 static int
99 main_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop);
100 static int
101 server_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop, auth_instance *ablock);
102 static int
103 client_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop, auth_instance *ablock);
104
105 static BOOL sasl_error_should_defer = FALSE;
106 static Gsasl_property callback_loop = 0;
107 static BOOL checked_server_condition = FALSE;
108
109 enum { CURRENTLY_SERVER = 1, CURRENTLY_CLIENT = 2 };
110
111 struct callback_exim_state {
112 auth_instance *ablock;
113 int currently;
114 };
115
116
117 /*************************************************
118 * Initialization entry point *
119 *************************************************/
120
121 /* Called for each instance, after its options have been read, to
122 enable consistency checks to be done, or anything else that needs
123 to be set up. */
124
125 void
126 auth_gsasl_init(auth_instance *ablock)
127 {
128 char *p;
129 int rc, supported;
130 auth_gsasl_options_block *ob =
131 (auth_gsasl_options_block *)(ablock->options_block);
132
133 /* As per existing Cyrus glue, use the authenticator's public name as
134 the default for the mechanism name; we don't handle multiple mechanisms
135 in one authenticator, but the same driver can be used multiple times. */
136
137 if (!ob->server_mech)
138 ob->server_mech = string_copy(ablock->public_name);
139
140 /* Can get multiple session contexts from one library context, so just
141 initialise the once. */
142
143 if (!gsasl_ctx)
144 {
145 if ((rc = gsasl_init(&gsasl_ctx)) != GSASL_OK)
146 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
147 "couldn't initialise GNU SASL library: %s (%s)",
148 ablock->name, gsasl_strerror_name(rc), gsasl_strerror(rc));
149
150 gsasl_callback_set(gsasl_ctx, main_callback);
151 }
152
153 /* We don't need this except to log it for debugging. */
154
155 if ((rc = gsasl_server_mechlist(gsasl_ctx, &p)) != GSASL_OK)
156 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
157 "failed to retrieve list of mechanisms: %s (%s)",
158 ablock->name, gsasl_strerror_name(rc), gsasl_strerror(rc));
159
160 HDEBUG(D_auth) debug_printf("GNU SASL supports: %s\n", p);
161
162 supported = gsasl_client_support_p(gsasl_ctx, CCS ob->server_mech);
163 if (!supported)
164 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
165 "GNU SASL does not support mechanism \"%s\"",
166 ablock->name, ob->server_mech);
167
168 if ( !ablock->server_condition
169 && ( streqic(ob->server_mech, US"EXTERNAL")
170 || streqic(ob->server_mech, US"ANONYMOUS")
171 || streqic(ob->server_mech, US"PLAIN")
172 || streqic(ob->server_mech, US"LOGIN")
173 ) )
174 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
175 "Need server_condition for %s mechanism",
176 ablock->name, ob->server_mech);
177
178 /* This does *not* scale to new SASL mechanisms. Need a better way to ask
179 which properties will be needed. */
180
181 if ( !ob->server_realm
182 && streqic(ob->server_mech, US"DIGEST-MD5"))
183 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
184 "Need server_realm for %s mechanism",
185 ablock->name, ob->server_mech);
186
187 /* At present, for mechanisms we don't panic on absence of server_condition;
188 need to figure out the most generically correct approach to deciding when
189 it's critical and when it isn't. Eg, for simple validation (PLAIN mechanism,
190 etc) it clearly is critical.
191
192 So don't activate without server_condition, this might be relaxed in the future.
193 */
194
195 if (ablock->server_condition) ablock->server = TRUE;
196 ablock->client = FALSE;
197 }
198
199
200 /* GNU SASL uses one top-level callback, registered at library level.
201 We dispatch to client and server functions instead. */
202
203 static int
204 main_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
205 {
206 int rc = 0;
207 struct callback_exim_state *cb_state =
208 (struct callback_exim_state *)gsasl_session_hook_get(sctx);
209
210 HDEBUG(D_auth)
211 debug_printf("GNU SASL Callback entered, prop=%d (loop prop=%d)\n",
212 prop, callback_loop);
213
214 if (!cb_state)
215 {
216 HDEBUG(D_auth) debug_printf(" not from our server/client processing.\n");
217 return GSASL_NO_CALLBACK;
218 }
219
220 if (callback_loop > 0)
221 {
222 /* Most likely is that we were asked for property foo, and to
223 expand the string we asked for property bar to put into an auth
224 variable, but property bar is not supplied for this mechanism. */
225 HDEBUG(D_auth)
226 debug_printf("Loop, asked for property %d while handling property %d\n",
227 prop, callback_loop);
228 return GSASL_NO_CALLBACK;
229 }
230 callback_loop = prop;
231
232 if (cb_state->currently == CURRENTLY_CLIENT)
233 rc = client_callback(ctx, sctx, prop, cb_state->ablock);
234 else if (cb_state->currently == CURRENTLY_SERVER)
235 rc = server_callback(ctx, sctx, prop, cb_state->ablock);
236 else
237 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
238 "unhandled callback state, bug in Exim", cb_state->ablock->name);
239 /* NOTREACHED */
240
241 callback_loop = 0;
242 return rc;
243 }
244
245
246 /*************************************************
247 * Server entry point *
248 *************************************************/
249
250 /* For interface, see auths/README */
251
252 int
253 auth_gsasl_server(auth_instance *ablock, uschar *initial_data)
254 {
255 char *tmps;
256 char *to_send, *received;
257 Gsasl_session *sctx = NULL;
258 auth_gsasl_options_block *ob =
259 (auth_gsasl_options_block *)(ablock->options_block);
260 struct callback_exim_state cb_state;
261 int rc, auth_result, exim_error, exim_error_override;
262
263 HDEBUG(D_auth)
264 debug_printf("GNU SASL: initialising session for %s, mechanism %s.\n",
265 ablock->name, ob->server_mech);
266
267 if ((rc = gsasl_server_start(gsasl_ctx, CCS ob->server_mech, &sctx)) != GSASL_OK)
268 {
269 auth_defer_msg = string_sprintf("GNU SASL: session start failure: %s (%s)",
270 gsasl_strerror_name(rc), gsasl_strerror(rc));
271 HDEBUG(D_auth) debug_printf("%s\n", auth_defer_msg);
272 return DEFER;
273 }
274 /* Hereafter: gsasl_finish(sctx) please */
275
276 gsasl_session_hook_set(sctx, (void *)ablock);
277 cb_state.ablock = ablock;
278 cb_state.currently = CURRENTLY_SERVER;
279 gsasl_session_hook_set(sctx, (void *)&cb_state);
280
281 tmps = CS expand_string(ob->server_service);
282 gsasl_property_set(sctx, GSASL_SERVICE, tmps);
283 tmps = CS expand_string(ob->server_hostname);
284 gsasl_property_set(sctx, GSASL_HOSTNAME, tmps);
285 if (ob->server_realm)
286 {
287 tmps = CS expand_string(ob->server_realm);
288 if (tmps && *tmps)
289 gsasl_property_set(sctx, GSASL_REALM, tmps);
290 }
291 /* We don't support protection layers. */
292 gsasl_property_set(sctx, GSASL_QOPS, "qop-auth");
293
294 #ifndef DISABLE_TLS
295 if (tls_in.channelbinding)
296 {
297 /* Some auth mechanisms can ensure that both sides are talking withing the
298 same security context; for TLS, this means that even if a bad certificate
299 has been accepted, they remain MitM-proof because both sides must be within
300 the same negotiated session; if someone is terminating one session and
301 proxying data on within a second, authentication will fail.
302
303 We might not have this available, depending upon TLS implementation,
304 ciphersuite, phase of moon ...
305
306 If we do, it results in extra SASL mechanisms being available; here,
307 Exim's one-mechanism-per-authenticator potentially causes problems.
308 It depends upon how GNU SASL will implement the PLUS variants of GS2
309 and whether it automatically mandates a switch to the bound PLUS
310 if the data is available. Since default-on, despite being more secure,
311 would then result in mechanism name changes on a library update, we
312 have little choice but to default it off and let the admin choose to
313 enable it. *sigh*
314 */
315 if (ob->server_channelbinding)
316 {
317 HDEBUG(D_auth) debug_printf("Auth %s: Enabling channel-binding\n",
318 ablock->name);
319 gsasl_property_set(sctx, GSASL_CB_TLS_UNIQUE,
320 CCS tls_in.channelbinding);
321 }
322 else
323 HDEBUG(D_auth)
324 debug_printf("Auth %s: Not enabling channel-binding (data available)\n",
325 ablock->name);
326 }
327 else
328 HDEBUG(D_auth)
329 debug_printf("Auth %s: no channel-binding data available\n",
330 ablock->name);
331 #endif
332
333 checked_server_condition = FALSE;
334
335 received = CS initial_data;
336 to_send = NULL;
337 exim_error = exim_error_override = OK;
338
339 do {
340 switch (rc = gsasl_step64(sctx, received, &to_send))
341 {
342 case GSASL_OK:
343 if (!to_send)
344 goto STOP_INTERACTION;
345 break;
346
347 case GSASL_NEEDS_MORE:
348 break;
349
350 case GSASL_AUTHENTICATION_ERROR:
351 case GSASL_INTEGRITY_ERROR:
352 case GSASL_NO_AUTHID:
353 case GSASL_NO_ANONYMOUS_TOKEN:
354 case GSASL_NO_AUTHZID:
355 case GSASL_NO_PASSWORD:
356 case GSASL_NO_PASSCODE:
357 case GSASL_NO_PIN:
358 case GSASL_BASE64_ERROR:
359 HDEBUG(D_auth) debug_printf("GNU SASL permanent error: %s (%s)\n",
360 gsasl_strerror_name(rc), gsasl_strerror(rc));
361 log_write(0, LOG_REJECT, "%s authenticator (%s):\n "
362 "GNU SASL permanent failure: %s (%s)",
363 ablock->name, ob->server_mech,
364 gsasl_strerror_name(rc), gsasl_strerror(rc));
365 if (rc == GSASL_BASE64_ERROR)
366 exim_error_override = BAD64;
367 goto STOP_INTERACTION;
368
369 default:
370 auth_defer_msg = string_sprintf("GNU SASL temporary error: %s (%s)",
371 gsasl_strerror_name(rc), gsasl_strerror(rc));
372 HDEBUG(D_auth) debug_printf("%s\n", auth_defer_msg);
373 exim_error_override = DEFER;
374 goto STOP_INTERACTION;
375 }
376
377 if ((rc == GSASL_NEEDS_MORE) || (to_send && *to_send))
378 exim_error = auth_get_no64_data((uschar **)&received, US to_send);
379
380 if (to_send)
381 {
382 free(to_send);
383 to_send = NULL;
384 }
385
386 if (exim_error)
387 break; /* handles * cancelled check */
388
389 } while (rc == GSASL_NEEDS_MORE);
390
391 STOP_INTERACTION:
392 auth_result = rc;
393
394 gsasl_finish(sctx);
395
396 /* Can return: OK DEFER FAIL CANCELLED BAD64 UNEXPECTED */
397
398 if (exim_error != OK)
399 return exim_error;
400
401 if (auth_result != GSASL_OK)
402 {
403 HDEBUG(D_auth) debug_printf("authentication returned %s (%s)\n",
404 gsasl_strerror_name(auth_result), gsasl_strerror(auth_result));
405 if (exim_error_override != OK)
406 return exim_error_override; /* might be DEFER */
407 if (sasl_error_should_defer) /* overriding auth failure SASL error */
408 return DEFER;
409 return FAIL;
410 }
411
412 /* Auth succeeded, check server_condition unless already done in callback */
413 return checked_server_condition ? OK : auth_check_serv_cond(ablock);
414 }
415
416
417 /* returns the GSASL status of expanding the Exim string given */
418 static int
419 condition_check(auth_instance *ablock, uschar *label, uschar *condition_string)
420 {
421 int exim_rc = auth_check_some_cond(ablock, label, condition_string, FAIL);
422 switch (exim_rc)
423 {
424 case OK: return GSASL_OK;
425 case DEFER: sasl_error_should_defer = TRUE;
426 return GSASL_AUTHENTICATION_ERROR;
427 case FAIL: return GSASL_AUTHENTICATION_ERROR;
428 default: log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s authenticator: "
429 "Unhandled return from checking %s: %d",
430 ablock->name, label, exim_rc);
431 }
432
433 /* NOTREACHED */
434 return GSASL_AUTHENTICATION_ERROR;
435 }
436
437 static int
438 server_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop,
439 auth_instance *ablock)
440 {
441 char *tmps;
442 uschar *propval;
443 int cbrc = GSASL_NO_CALLBACK;
444 auth_gsasl_options_block *ob =
445 (auth_gsasl_options_block *)(ablock->options_block);
446
447 HDEBUG(D_auth)
448 debug_printf("GNU SASL callback %d for %s/%s as server\n",
449 prop, ablock->name, ablock->public_name);
450
451 for (int i = 0; i < AUTH_VARS; i++) auth_vars[i] = NULL;
452 expand_nmax = 0;
453
454 switch (prop)
455 {
456 case GSASL_VALIDATE_SIMPLE:
457 /* GSASL_AUTHID, GSASL_AUTHZID, and GSASL_PASSWORD */
458 propval = US gsasl_property_fast(sctx, GSASL_AUTHID);
459 auth_vars[0] = expand_nstring[1] = propval ? string_copy(propval) : US"";
460 propval = US gsasl_property_fast(sctx, GSASL_AUTHZID);
461 auth_vars[1] = expand_nstring[2] = propval ? string_copy(propval) : US"";
462 propval = US gsasl_property_fast(sctx, GSASL_PASSWORD);
463 auth_vars[2] = expand_nstring[3] = propval ? string_copy(propval) : US"";
464 expand_nmax = 3;
465 for (int i = 1; i <= 3; ++i)
466 expand_nlength[i] = Ustrlen(expand_nstring[i]);
467
468 cbrc = condition_check(ablock, US"server_condition", ablock->server_condition);
469 checked_server_condition = TRUE;
470 break;
471
472 case GSASL_VALIDATE_EXTERNAL:
473 if (!ablock->server_condition)
474 {
475 HDEBUG(D_auth) debug_printf("No server_condition supplied, to validate EXTERNAL.\n");
476 cbrc = GSASL_AUTHENTICATION_ERROR;
477 break;
478 }
479 propval = US gsasl_property_fast(sctx, GSASL_AUTHZID);
480
481 /* We always set $auth1, even if only to empty string. */
482 auth_vars[0] = expand_nstring[1] = propval ? string_copy(propval) : US"";
483 expand_nlength[1] = Ustrlen(expand_nstring[1]);
484 expand_nmax = 1;
485
486 cbrc = condition_check(ablock,
487 US"server_condition (EXTERNAL)", ablock->server_condition);
488 checked_server_condition = TRUE;
489 break;
490
491 case GSASL_VALIDATE_ANONYMOUS:
492 if (!ablock->server_condition)
493 {
494 HDEBUG(D_auth) debug_printf("No server_condition supplied, to validate ANONYMOUS.\n");
495 cbrc = GSASL_AUTHENTICATION_ERROR;
496 break;
497 }
498 propval = US gsasl_property_fast(sctx, GSASL_ANONYMOUS_TOKEN);
499
500 /* We always set $auth1, even if only to empty string. */
501
502 auth_vars[0] = expand_nstring[1] = propval ? string_copy(propval) : US"";
503 expand_nlength[1] = Ustrlen(expand_nstring[1]);
504 expand_nmax = 1;
505
506 cbrc = condition_check(ablock,
507 US"server_condition (ANONYMOUS)", ablock->server_condition);
508 checked_server_condition = TRUE;
509 break;
510
511 case GSASL_VALIDATE_GSSAPI:
512 /* GSASL_AUTHZID and GSASL_GSSAPI_DISPLAY_NAME
513 The display-name is authenticated as part of GSS, the authzid is claimed
514 by the SASL integration after authentication; protected against tampering
515 (if the SASL mechanism supports that, which Kerberos does) but is
516 unverified, same as normal for other mechanisms.
517 First coding, we had these values swapped, but for consistency and prior
518 to the first release of Exim with this authenticator, they've been
519 switched to match the ordering of GSASL_VALIDATE_SIMPLE. */
520
521 propval = US gsasl_property_fast(sctx, GSASL_GSSAPI_DISPLAY_NAME);
522 auth_vars[0] = expand_nstring[1] = propval ? string_copy(propval) : US"";
523 propval = US gsasl_property_fast(sctx, GSASL_AUTHZID);
524 auth_vars[1] = expand_nstring[2] = propval ? string_copy(propval) : US"";
525 expand_nmax = 2;
526 for (int i = 1; i <= 2; ++i)
527 expand_nlength[i] = Ustrlen(expand_nstring[i]);
528
529 /* In this one case, it perhaps makes sense to default back open?
530 But for consistency, let's just mandate server_condition here too. */
531
532 cbrc = condition_check(ablock,
533 US"server_condition (GSSAPI family)", ablock->server_condition);
534 checked_server_condition = TRUE;
535 break;
536
537 case GSASL_SCRAM_ITER:
538 if (ob->server_scram_iter)
539 {
540 tmps = CS expand_string(ob->server_scram_iter);
541 gsasl_property_set(sctx, GSASL_SCRAM_ITER, tmps);
542 cbrc = GSASL_OK;
543 }
544 break;
545
546 case GSASL_SCRAM_SALT:
547 if (ob->server_scram_iter)
548 {
549 tmps = CS expand_string(ob->server_scram_salt);
550 gsasl_property_set(sctx, GSASL_SCRAM_SALT, tmps);
551 cbrc = GSASL_OK;
552 }
553 break;
554
555 case GSASL_PASSWORD:
556 /* DIGEST-MD5: GSASL_AUTHID, GSASL_AUTHZID and GSASL_REALM
557 CRAM-MD5: GSASL_AUTHID
558 PLAIN: GSASL_AUTHID and GSASL_AUTHZID
559 LOGIN: GSASL_AUTHID
560 */
561 if (ob->server_scram_iter)
562 {
563 tmps = CS expand_string(ob->server_scram_iter);
564 gsasl_property_set(sctx, GSASL_SCRAM_ITER, tmps);
565 }
566 if (ob->server_scram_salt)
567 {
568 tmps = CS expand_string(ob->server_scram_salt);
569 gsasl_property_set(sctx, GSASL_SCRAM_SALT, tmps);
570 }
571
572 /* Asking for GSASL_AUTHZID calls back into us if we use
573 gsasl_property_get(), thus the use of gsasl_property_fast().
574 Do we really want to hardcode limits per mechanism? What happens when
575 a new mechanism is added to the library. It *shouldn't* result in us
576 needing to add more glue, since avoiding that is a large part of the
577 point of SASL. */
578
579 propval = US gsasl_property_fast(sctx, GSASL_AUTHID);
580 auth_vars[0] = expand_nstring[1] = propval ? string_copy(propval) : US"";
581 propval = US gsasl_property_fast(sctx, GSASL_AUTHZID);
582 auth_vars[1] = expand_nstring[2] = propval ? string_copy(propval) : US"";
583 propval = US gsasl_property_fast(sctx, GSASL_REALM);
584 auth_vars[2] = expand_nstring[3] = propval ? string_copy(propval) : US"";
585 expand_nmax = 3;
586 for (int i = 1; i <= 3; ++i)
587 expand_nlength[i] = Ustrlen(expand_nstring[i]);
588
589 if (!(tmps = CS expand_string(ob->server_password)))
590 {
591 sasl_error_should_defer = f.expand_string_forcedfail ? FALSE : TRUE;
592 HDEBUG(D_auth) debug_printf("server_password expansion failed, so "
593 "can't tell GNU SASL library the password for %s\n", auth_vars[0]);
594 return GSASL_AUTHENTICATION_ERROR;
595 }
596 gsasl_property_set(sctx, GSASL_PASSWORD, tmps);
597
598 /* This is inadequate; don't think Exim's store stacks are geared
599 for memory wiping, so expanding strings will leave stuff laying around.
600 But no need to compound the problem, so get rid of the one we can. */
601
602 memset(tmps, '\0', strlen(tmps));
603 cbrc = GSASL_OK;
604 break;
605
606 default:
607 HDEBUG(D_auth) debug_printf("Unrecognised callback: %d\n", prop);
608 cbrc = GSASL_NO_CALLBACK;
609 }
610
611 HDEBUG(D_auth) debug_printf("Returning %s (%s)\n",
612 gsasl_strerror_name(cbrc), gsasl_strerror(cbrc));
613
614 return cbrc;
615 }
616
617
618 /*************************************************
619 * Client entry point *
620 *************************************************/
621
622 /* For interface, see auths/README */
623
624 int
625 auth_gsasl_client(
626 auth_instance *ablock, /* authenticator block */
627 smtp_inblock * sx, /* connection */
628 int timeout, /* command timeout */
629 uschar *buffer, /* buffer for reading response */
630 int buffsize) /* size of buffer */
631 {
632 HDEBUG(D_auth)
633 debug_printf("Client side NOT IMPLEMENTED: you should not see this!\n");
634 /* NOT IMPLEMENTED */
635 return FAIL;
636 }
637
638 static int
639 client_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop, auth_instance *ablock)
640 {
641 int cbrc = GSASL_NO_CALLBACK;
642 HDEBUG(D_auth)
643 debug_printf("GNU SASL callback %d for %s/%s as client\n",
644 prop, ablock->name, ablock->public_name);
645
646 HDEBUG(D_auth)
647 debug_printf("Client side NOT IMPLEMENTED: you should not see this!\n");
648
649 return cbrc;
650 }
651
652 /*************************************************
653 * Diagnostic API *
654 *************************************************/
655
656 void
657 auth_gsasl_version_report(FILE *f)
658 {
659 const char *runtime;
660 runtime = gsasl_check_version(NULL);
661 fprintf(f, "Library version: GNU SASL: Compile: %s\n"
662 " Runtime: %s\n",
663 GSASL_VERSION, runtime);
664 }
665
666 #endif /*!MACRO_PREDEF*/
667 #endif /* AUTH_GSASL */
668
669 /* End of gsasl_exim.c */