dovecot-2.2: auth: passdb passwd supports now lookup_credentials...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Nov 2 12:37:21 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/47848e9fc622
changeset: 16904:47848e9fc622
user: Timo Sirainen <tss at iki.fi>
date: Sat Nov 02 12:37:10 2013 +0200
description:
auth: passdb passwd supports now lookup_credentials() API
It's not very useful, but at least it allows the lookup itself to succeed.
diffstat:
src/auth/passdb-passwd.c | 74 ++++++++++++++++++++++++++++++++---------------
1 files changed, 50 insertions(+), 24 deletions(-)
diffs (107 lines):
diff -r 8cdd4124de0b -r 47848e9fc622 src/auth/passdb-passwd.c
--- a/src/auth/passdb-passwd.c Sat Nov 02 12:25:09 2013 +0200
+++ b/src/auth/passdb-passwd.c Sat Nov 02 12:37:10 2013 +0200
@@ -11,38 +11,46 @@
#define PASSWD_CACHE_KEY "%u"
#define PASSWD_PASS_SCHEME "CRYPT"
+static enum passdb_result
+passwd_lookup(struct auth_request *request, struct passwd *pw_r)
+{
+ auth_request_log_debug(request, "passwd", "lookup");
+
+ switch (i_getpwnam(request->user, pw_r)) {
+ case -1:
+ auth_request_log_error(request, "passwd",
+ "getpwnam() failed: %m");
+ return PASSDB_RESULT_INTERNAL_FAILURE;
+ case 0:
+ auth_request_log_unknown_user(request, "passwd");
+ return PASSDB_RESULT_USER_UNKNOWN;
+ }
+
+ if (!IS_VALID_PASSWD(pw_r->pw_passwd)) {
+ auth_request_log_info(request, "passwd",
+ "invalid password field '%s'", pw_r->pw_passwd);
+ return PASSDB_RESULT_USER_DISABLED;
+ }
+
+ /* save the password so cache can use it */
+ auth_request_set_field(request, "password", pw_r->pw_passwd,
+ PASSWD_PASS_SCHEME);
+ return PASSDB_RESULT_OK;
+}
+
static void
passwd_verify_plain(struct auth_request *request, const char *password,
verify_plain_callback_t *callback)
{
struct passwd pw;
+ enum passdb_result res;
int ret;
- auth_request_log_debug(request, "passwd", "lookup");
-
- switch (i_getpwnam(request->user, &pw)) {
- case -1:
- auth_request_log_error(request, "passwd",
- "getpwnam() failed: %m");
- callback(PASSDB_RESULT_INTERNAL_FAILURE, request);
- return;
- case 0:
- auth_request_log_unknown_user(request, "passwd");
- callback(PASSDB_RESULT_USER_UNKNOWN, request);
+ res = passwd_lookup(request, &pw);
+ if (res != PASSDB_RESULT_OK) {
+ callback(res, request);
return;
}
-
- if (!IS_VALID_PASSWD(pw.pw_passwd)) {
- auth_request_log_info(request, "passwd",
- "invalid password field '%s'", pw.pw_passwd);
- callback(PASSDB_RESULT_USER_DISABLED, request);
- return;
- }
-
- /* save the password so cache can use it */
- auth_request_set_field(request, "password", pw.pw_passwd,
- PASSWD_PASS_SCHEME);
-
/* check if the password is valid */
ret = auth_request_password_verify(request, password, pw.pw_passwd,
PASSWD_PASS_SCHEME, "passwd");
@@ -61,6 +69,24 @@
callback(PASSDB_RESULT_OK, request);
}
+static void
+passwd_lookup_credentials(struct auth_request *request,
+ lookup_credentials_callback_t *callback)
+{
+ struct passwd pw;
+ enum passdb_result res;
+
+ res = passwd_lookup(request, &pw);
+ if (res != PASSDB_RESULT_OK) {
+ callback(res, NULL, 0, request);
+ return;
+ }
+ /* make sure we're using the username exactly as it's in the database */
+ auth_request_set_field(request, "user", pw.pw_name, NULL);
+ passdb_handle_credentials(PASSDB_RESULT_OK, pw.pw_passwd,
+ PASSWD_PASS_SCHEME, callback, request);
+}
+
static struct passdb_module *
passwd_preinit(pool_t pool, const char *args)
{
@@ -91,7 +117,7 @@
passwd_deinit,
passwd_verify_plain,
- NULL,
+ passwd_lookup_credentials,
NULL
};
More information about the dovecot-cvs
mailing list