Commit edfa04de edfa04de0dd478c56beeed34054251f00cd74698 by Sergey Poznyakoff

(cb_retrieve): Fall back to SQL if plaintext password file is not available.

1 parent d924063f
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 #include <gsasl.h> 19 #include <gsasl.h>
20 #include <mailutils/gsasl.h> 20 #include <mailutils/gsasl.h>
21 #ifdef USE_SQL
22 # include <mailutils/sql.h>
23 #endif
21 24
22 static Gsasl_ctx *ctx; 25 static Gsasl_ctx *ctx;
23 static Gsasl_session_ctx *sess_ctx; 26 static Gsasl_session_ctx *sess_ctx;
...@@ -262,11 +265,35 @@ cb_retrieve (Gsasl_session_ctx *ctx, ...@@ -262,11 +265,35 @@ cb_retrieve (Gsasl_session_ctx *ctx,
262 { 265 {
263 char **username = gsasl_server_application_data_get (ctx); 266 char **username = gsasl_server_application_data_get (ctx);
264 267
265 if (username && authentication_id) 268 if (username && *username == 0 && authentication_id)
266 *username = strdup (authentication_id); 269 *username = strdup (authentication_id);
267 270
268 return gsasl_md5pwd_get_password (gsasl_cram_md5_pwd, authentication_id, 271 if (gsasl_cram_md5_pwd && access (gsasl_cram_md5_pwd, R_OK) == 0)
272 {
273 int rc = gsasl_md5pwd_get_password (gsasl_cram_md5_pwd,
274 authentication_id,
269 key, keylen); 275 key, keylen);
276 if (rc == GSASL_OK)
277 return rc;
278 }
279
280 #ifdef USE_SQL
281 if (mu_sql_password_type == password_plaintext)
282 {
283 char *passwd;
284 int status = mu_sql_getpass (username, &passwd);
285 if (status == 0)
286 {
287 *keylen = strlen (passwd);
288 if (key)
289 memcpy (key, passwd, *keylen);
290 free (passwd);
291 return GSASL_OK;
292 }
293 }
294 #endif
295
296 return GSASL_AUTHENTICATION_ERROR;
270 } 297 }
271 298
272 void 299 void
...@@ -286,10 +313,7 @@ auth_gsasl_init () ...@@ -286,10 +313,7 @@ auth_gsasl_init ()
286 gsasl_server_callback_validate_set (ctx, cb_validate); 313 gsasl_server_callback_validate_set (ctx, cb_validate);
287 gsasl_server_callback_service_set (ctx, cb_service); 314 gsasl_server_callback_service_set (ctx, cb_service);
288 315
289 if (gsasl_cram_md5_pwd && access (gsasl_cram_md5_pwd, R_OK) == 0)
290 {
291 gsasl_server_callback_retrieve_set (ctx, cb_retrieve); 316 gsasl_server_callback_retrieve_set (ctx, cb_retrieve);
292 }
293 317
294 auth_gsasl_capa_init (0); 318 auth_gsasl_capa_init (0);
295 } 319 }
......