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