]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Fixed using same passwd-file with different username_format settings.
authorTimo Sirainen <tss@iki.fi>
Mon, 5 Apr 2010 20:59:08 +0000 (23:59 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 5 Apr 2010 20:59:08 +0000 (23:59 +0300)
--HG--
branch : HEAD

src/auth/db-passwd-file.c
src/auth/db-passwd-file.h
src/auth/passdb-passwd-file.c
src/auth/userdb-passwd-file.c

index 5d620f693ee7630ee0e7d69ff6b0d6a139940a41..15327b800983b52c5bd958f9883a4c601e207c1e 100644 (file)
@@ -267,8 +267,7 @@ static struct db_passwd_file *db_passwd_file_find(const char *path)
 }
 
 struct db_passwd_file *
-db_passwd_file_init(const char *path, const char *username_format,
-                   bool userdb, bool debug)
+db_passwd_file_init(const char *path, bool userdb, bool debug)
 {
        struct db_passwd_file *db;
        const char *p;
@@ -285,7 +284,6 @@ db_passwd_file_init(const char *path, const char *username_format,
        db->refcount = 1;
        db->userdb = userdb;
        db->debug = debug;
-       db->username_format = username_format;
 
        for (p = path; *p != '\0'; p++) {
                if (*p == '%' && p[1] != '\0') {
@@ -381,7 +379,8 @@ path_fix(const char *path,
 }
 
 struct passwd_user *
-db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request)
+db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request,
+                     const char *username_format)
 {
        struct passwd_file *pw;
        struct passwd_user *pu;
@@ -414,7 +413,7 @@ db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request)
        username = t_str_new(256);
        table = auth_request_get_var_expand_table(request,
                                                  auth_request_str_escape);
-       var_expand(username, db->username_format, table);
+       var_expand(username, username_format, table);
 
        auth_request_log_debug(request, "passwd-file",
                               "lookup: user=%s file=%s",
index c3685441ebc33b8eb03d95171998397e3c7eec18..3bf97f7bf265ab362411020df49594befef53c4b 100644 (file)
@@ -34,7 +34,6 @@ struct db_passwd_file {
        char *path;
        struct hash_table *files;
         struct passwd_file *default_file;
-       const char *username_format;
 
        unsigned int vars:1;
        unsigned int userdb:1;
@@ -42,11 +41,11 @@ struct db_passwd_file {
 };
 
 struct passwd_user *
-db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request);
+db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request,
+                     const char *username_format);
 
 struct db_passwd_file *
-db_passwd_file_init(const char *path, const char *username_format,
-                   bool userdb, bool debug);
+db_passwd_file_init(const char *path, bool userdb, bool debug);
 void db_passwd_file_parse(struct db_passwd_file *db);
 void db_passwd_file_unref(struct db_passwd_file **db);
 
index 9ec35858558c21fcac26d389ca3fac0379b9ea57..978f55111df0f39a77505f6ad362e3d4d0c334d5 100644 (file)
@@ -15,6 +15,7 @@ struct passwd_file_passdb_module {
        struct passdb_module module;
 
        struct db_passwd_file *pwf;
+       const char *username_format;
 };
 
 static void passwd_file_save_results(struct auth_request *request,
@@ -69,7 +70,8 @@ passwd_file_verify_plain(struct auth_request *request, const char *password,
        const char *scheme, *crypted_pass;
         int ret;
 
-       pu = db_passwd_file_lookup(module->pwf, request);
+       pu = db_passwd_file_lookup(module->pwf, request,
+                                  module->username_format);
        if (pu == NULL) {
                callback(PASSDB_RESULT_USER_UNKNOWN, request);
                return;
@@ -94,7 +96,8 @@ passwd_file_lookup_credentials(struct auth_request *request,
        struct passwd_user *pu;
        const char *crypted_pass, *scheme;
 
-       pu = db_passwd_file_lookup(module->pwf, request);
+       pu = db_passwd_file_lookup(module->pwf, request,
+                                  module->username_format);
        if (pu == NULL) {
                callback(PASSDB_RESULT_USER_UNKNOWN, NULL, 0, request);
                return;
@@ -146,8 +149,9 @@ passwd_file_preinit(pool_t pool, const char *args)
                i_fatal("passdb passwd-file: Missing args");
 
        module = p_new(pool, struct passwd_file_passdb_module, 1);
-       module->pwf = db_passwd_file_init(args, format, FALSE,
+       module->pwf = db_passwd_file_init(args, FALSE,
                                          global_auth_settings->debug);
+       module->username_format = format;
 
        if (!module->pwf->vars)
                module->module.cache_key = format;
index 25d8b537c88d520dec8c7dcb7324491e7150ddf3..538b1028e5891f6d25fea8d9a6d9042829e3b288 100644 (file)
@@ -26,6 +26,7 @@ struct passwd_file_userdb_module {
         struct userdb_module module;
 
        struct db_passwd_file *pwf;
+       const char *username_format;
 };
 
 static void passwd_file_lookup(struct auth_request *auth_request,
@@ -40,7 +41,8 @@ static void passwd_file_lookup(struct auth_request *auth_request,
        const char *key, *value;
        char **p;
 
-       pu = db_passwd_file_lookup(module->pwf, auth_request);
+       pu = db_passwd_file_lookup(module->pwf, auth_request,
+                                  module->username_format);
        if (pu == NULL) {
                callback(USERDB_RESULT_USER_UNKNOWN, auth_request);
                return;
@@ -164,7 +166,7 @@ passwd_file_preinit(pool_t pool, const char *args)
                args += 16;
                p = strchr(args, ' ');
                if (p == NULL) {
-                       format = args;
+                       format = p_strdup(pool, args);
                        args = "";
                } else {
                        format = p_strdup_until(pool, args, p);
@@ -176,8 +178,9 @@ passwd_file_preinit(pool_t pool, const char *args)
                i_fatal("userdb passwd-file: Missing args");
 
        module = p_new(pool, struct passwd_file_userdb_module, 1);
-       module->pwf = db_passwd_file_init(args, format, TRUE,
+       module->pwf = db_passwd_file_init(args, TRUE,
                                          global_auth_settings->debug);
+       module->username_format = format;
 
        if (!module->pwf->vars)
                module->module.cache_key = PASSWD_FILE_CACHE_KEY;