dovecot: Allow passwd-file ti contain empty uid/gid fields.

dovecot at dovecot.org dovecot at dovecot.org
Tue Jul 3 03:55:59 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/cda9824bab63
changeset: 5875:cda9824bab63
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jul 03 03:47:39 2007 +0300
description:
Allow passwd-file ti contain empty uid/gid fields.

diffstat:

2 files changed, 32 insertions(+), 22 deletions(-)
src/auth/db-passwd-file.c     |   44 ++++++++++++++++++++++-------------------
src/auth/userdb-passwd-file.c |   10 +++++++--

diffs (82 lines):

diff -r 5fa84de81413 -r cda9824bab63 src/auth/db-passwd-file.c
--- a/src/auth/db-passwd-file.c	Tue Jul 03 03:29:23 2007 +0300
+++ b/src/auth/db-passwd-file.c	Tue Jul 03 03:47:39 2007 +0300
@@ -67,34 +67,38 @@ static void passwd_file_add(struct passw
 		pu->password = p_strdup(pw->pool, pass);
 	}
 
-	if (*args != NULL && **args != '\0') {
-		pu->uid = !pw->db->userdb ? (uid_t)-1 :
-			userdb_parse_uid(NULL, *args);
-		if ((pu->uid == 0 || pu->uid == (uid_t)-1) && pw->db->userdb) {
-			i_error("passwd-file %s: User %s has invalid UID %s",
+	pu->uid = (uid_t)-1;
+	pu->gid = (gid_t)-1;
+
+	if (*args == NULL)
+		;
+	else if (!pw->db->userdb || **args == '\0') {
+		args++;
+	} else {
+		pu->uid = userdb_parse_uid(NULL, *args);
+		if (pu->uid == 0 || pu->uid == (uid_t)-1) {
+			i_error("passwd-file %s: User %s has invalid UID '%s'",
 				pw->path, username, *args);
 			return;
 		}
 		args++;
-	} else if (*args != NULL)
-		args++;
-
-	if (*args != NULL && **args != '\0') {
-		pu->gid = !pw->db->userdb ? (gid_t)-1 :
-			userdb_parse_gid(NULL, *args);
-		if ((pu->gid == 0 || pu->gid == (gid_t)-1) && pw->db->userdb) {
-			i_error("passwd-file %s: User %s has invalid GID %s",
-				pw->path, username, *args);
-			return;
-		}
-		args++;
-	} else {
+	}
+
+	if (*args == NULL) {
 		if (pw->db->userdb) {
 			i_error("passwd-file %s: User %s is missing "
 				"userdb info", pw->path, username);
 		}
-		if (*args != NULL)
-			args++;
+	} else if (!pw->db->userdb || **args == '\0')
+		args++;
+	else {
+		pu->gid = userdb_parse_gid(NULL, *args);
+		if (pu->gid == 0 || pu->gid == (gid_t)-1) {
+			i_error("passwd-file %s: User %s has invalid GID '%s'",
+				pw->path, username, *args);
+			return;
+		}
+		args++;
 	}
 
 	/* user info */
diff -r 5fa84de81413 -r cda9824bab63 src/auth/userdb-passwd-file.c
--- a/src/auth/userdb-passwd-file.c	Tue Jul 03 03:29:23 2007 +0300
+++ b/src/auth/userdb-passwd-file.c	Tue Jul 03 03:47:39 2007 +0300
@@ -38,8 +38,14 @@ static void passwd_file_lookup(struct au
 	}
 
 	auth_request_init_userdb_reply(auth_request);
-	auth_request_set_userdb_field(auth_request, "uid", dec2str(pu->uid));
-	auth_request_set_userdb_field(auth_request, "gid", dec2str(pu->gid));
+	if (pu->uid != (uid_t)-1) {
+		auth_request_set_userdb_field(auth_request, "uid",
+					      dec2str(pu->uid));
+	}
+	if (pu->gid != (gid_t)-1) {
+		auth_request_set_userdb_field(auth_request, "gid",
+					      dec2str(pu->gid));
+	}
 
 	if (pu->home != NULL)
 		auth_request_set_userdb_field(auth_request, "home", pu->home);


More information about the dovecot-cvs mailing list