135 static MAPS *smtp_sasl_passwd_map;
150 #ifdef HAVE_SASL_AUTH_CACHE
151 static SMTP_SASL_AUTH_CACHE *smtp_sasl_auth_cache;
159 const char *myname =
"smtp_sasl_passwd_lookup";
168 if (smtp_sasl_passwd_map == 0)
169 msg_panic(
"%s: passwd map not initialized", myname);
184 smtp_sasl_passwd_map->
error = 0;
189 || (smtp_sasl_passwd_map->
error == 0
190 && (value =
maps_find(smtp_sasl_passwd_map,
192 || (smtp_sasl_passwd_map->
error == 0
193 && (value =
maps_find(smtp_sasl_passwd_map,
195 if (session->sasl_username)
196 myfree(session->sasl_username);
197 session->sasl_username =
mystrdup(value);
198 passwd =
split_at(session->sasl_username,
':');
199 if (session->sasl_passwd)
200 myfree(session->sasl_passwd);
201 session->sasl_passwd =
mystrdup(passwd ? passwd :
"");
203 msg_info(
"%s: host `%s' user `%s' pass `%s'",
205 session->sasl_username, session->sasl_passwd);
207 }
else if (smtp_sasl_passwd_map->
error) {
213 msg_info(
"%s: no auth info found (sender=`%s', host=`%s')",
227 if (smtp_sasl_passwd_map || smtp_sasl_impl)
228 msg_panic(
"smtp_sasl_initialize: repeated call");
230 msg_fatal(
"specify a password table via the `%s' configuration parameter",
243 msg_fatal(
"SASL library initialization");
257 #ifdef HAVE_SASL_AUTH_CACHE
258 smtp_sasl_auth_cache =
262 msg_warn(
"not compiled with TLS support -- "
263 "ignoring the %s setting",
VAR_LMTP_SMTP(SASL_AUTH_CACHE_NAME));
277 session->sasl_mechanism_list = 0;
278 session->sasl_username = 0;
279 session->sasl_passwd = 0;
280 session->sasl_client = 0;
281 session->sasl_reply = 0;
287 const char *sasl_opts_val)
293 msg_info(
"starting new SASL client");
294 if ((session->sasl_client =
299 security_options = sasl_opts_val)) == 0)
300 msg_fatal(
"SASL per-connection initialization failed");
308 const char *myname =
"smtp_sasl_authenticate";
311 const char *mechanism;
319 if (session->sasl_mechanism_list == 0)
320 msg_panic(
"%s: no mechanism list", myname);
323 msg_info(
"%s: %s: SASL mechanisms %s",
324 myname, session->
namaddrport, session->sasl_mechanism_list);
329 #ifdef HAVE_SASL_AUTH_CACHE
330 if (smtp_sasl_auth_cache
331 && smtp_sasl_auth_cache_find(smtp_sasl_auth_cache, session)) {
332 char *resp_dsn = smtp_sasl_auth_cache_dsn(smtp_sasl_auth_cache);
333 char *resp_str = smtp_sasl_auth_cache_text(smtp_sasl_auth_cache);
339 "SASL [CACHED] authentication failed; server %s said: %s",
349 session->sasl_mechanism_list,
350 session->sasl_username,
351 session->sasl_passwd,
352 &mechanism, session->sasl_reply);
356 "SASL authentication failed; "
357 "cannot authenticate to server %s: %s",
367 if (
LEN(session->sasl_reply) > 0) {
369 STR(session->sasl_reply));
384 dsb_simple(why,
"4.3.0",
"SASL authentication failed; "
385 "authentication protocol loop with server %s",
396 session->sasl_reply);
400 "SASL authentication failed; "
401 "cannot authenticate to server %s: %s",
415 if (resp->
code / 100 != 2) {
416 #ifdef HAVE_SASL_AUTH_CACHE
418 if (smtp_sasl_auth_cache && resp->
code == 535)
419 smtp_sasl_auth_cache_store(smtp_sasl_auth_cache, session, resp);
426 "SASL authentication failed; server %s said: %s",
437 if (session->sasl_username) {
438 myfree(session->sasl_username);
439 session->sasl_username = 0;
441 if (session->sasl_passwd) {
442 myfree(session->sasl_passwd);
443 session->sasl_passwd = 0;
445 if (session->sasl_mechanism_list) {
447 myfree(session->sasl_mechanism_list);
448 session->sasl_mechanism_list = 0;
450 if (session->sasl_client) {
452 msg_info(
"disposing SASL state information");
454 session->sasl_client = 0;
456 if (session->sasl_reply) {
458 session->sasl_reply = 0;
int smtp_sasl_passwd_lookup(SMTP_SESSION *)
char * mystrdup(const char *str)
XSASL_CLIENT_IMPL * xsasl_client_init(const char *, const char *)
NORETURN msg_panic(const char *fmt,...)
DSN_BUF * dsb_update(DSN_BUF *dsb, const char *status, const char *action, const char *mtype, const char *mname, const char *dtype, const char *dtext, const char *format,...)
char * var_smtp_sasl_passwd
DELIVER_REQUEST * request
#define vstream_longjmp(stream, val)
void smtp_sasl_passivate(SMTP_SESSION *, VSTRING *)
#define DICT_FLAG_UTF8_REQUEST
char * mystrtok(char **src, const char *sep)
#define DICT_FLAG_FOLD_FIX
void smtp_sasl_start(SMTP_SESSION *, const char *, const char *)
#define string_list_init(o, f, p)
#define xsasl_client_first(client, server, method, user, pass, init_resp)
#define VAR_SMTP_SASL_MECHS
char * var_smtp_sasl_path
int var_smtp_sasl_auth_cache_time
MAPS * maps_create(const char *title, const char *map_names, int dict_flags)
#define mail_addr_find(maps, address, extension)
char * var_smtp_sasl_mechs
void msg_warn(const char *fmt,...)
int smtp_sasl_activate(SMTP_SESSION *, char *)
VSTRING * vstring_alloc(ssize_t len)
void smtp_sasl_connect(SMTP_SESSION *)
bool var_smtp_sender_auth
DSN_BUF * dsb_simple(DSN_BUF *dsb, const char *status, const char *format,...)
NORETURN msg_fatal(const char *fmt,...)
void smtp_sasl_initialize(void)
int smtp_sasl_authenticate(SMTP_SESSION *, DSN_BUF *)
char * var_smtp_sasl_auth_cache_name
#define xsasl_client_free(client)
char * var_smtp_sasl_type
#define XSASL_CLIENT_CREATE(impl, args, a1, a2, a3, a4)
#define xsasl_client_next(client, request, reply)
void smtp_chat_cmd(SMTP_SESSION *session, const char *fmt,...)
void smtp_sasl_cleanup(SMTP_SESSION *)
VSTRING * vstring_free(VSTRING *vp)
char * split_at(char *string, int delimiter)
SMTP_RESP * smtp_chat_resp(SMTP_SESSION *)
bool var_smtp_sasl_auth_soft_bounce
const char * maps_find(MAPS *maps, const char *name, int flags)
STRING_LIST * smtp_sasl_mechs
void msg_info(const char *fmt,...)