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