dovecot-2.0: auth: Fixed using same passwd-file with different u...

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 5 23:59:11 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/2fbd31f90277
changeset: 11079:2fbd31f90277
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 05 23:59:08 2010 +0300
description:
auth: Fixed using same passwd-file with different username_format settings.

diffstat:

 src/auth/db-passwd-file.c     |   9 ++++-----
 src/auth/db-passwd-file.h     |   7 +++----
 src/auth/passdb-passwd-file.c |  10 +++++++---
 src/auth/userdb-passwd-file.c |   9 ++++++---
 4 files changed, 20 insertions(+), 15 deletions(-)

diffs (149 lines):

diff -r 46d4f3264417 -r 2fbd31f90277 src/auth/db-passwd-file.c
--- a/src/auth/db-passwd-file.c	Mon Apr 05 23:06:19 2010 +0300
+++ b/src/auth/db-passwd-file.c	Mon Apr 05 23:59:08 2010 +0300
@@ -267,8 +267,7 @@
 }
 
 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->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 @@
 }
 
 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 @@
 	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",
diff -r 46d4f3264417 -r 2fbd31f90277 src/auth/db-passwd-file.h
--- a/src/auth/db-passwd-file.h	Mon Apr 05 23:06:19 2010 +0300
+++ b/src/auth/db-passwd-file.h	Mon Apr 05 23:59:08 2010 +0300
@@ -34,7 +34,6 @@
 	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 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);
 
diff -r 46d4f3264417 -r 2fbd31f90277 src/auth/passdb-passwd-file.c
--- a/src/auth/passdb-passwd-file.c	Mon Apr 05 23:06:19 2010 +0300
+++ b/src/auth/passdb-passwd-file.c	Mon Apr 05 23:59:08 2010 +0300
@@ -15,6 +15,7 @@
 	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 @@
 	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 @@
 	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 @@
 		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;
diff -r 46d4f3264417 -r 2fbd31f90277 src/auth/userdb-passwd-file.c
--- a/src/auth/userdb-passwd-file.c	Mon Apr 05 23:06:19 2010 +0300
+++ b/src/auth/userdb-passwd-file.c	Mon Apr 05 23:59:08 2010 +0300
@@ -26,6 +26,7 @@
         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 @@
 	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 @@
 		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 @@
 		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;


More information about the dovecot-cvs mailing list