[dovecot-cvs] dovecot/src/auth checkpassword-reply.c,1.3,1.3.2.1

tss at dovecot.org tss at dovecot.org
Fri Feb 16 17:13:37 UTC 2007


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv13184

Modified Files:
      Tag: branch_1_0
	checkpassword-reply.c 
Log Message:
Don't crash if USER or HOME environment is missing. Allow HOME environment
not to exist.



Index: checkpassword-reply.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/checkpassword-reply.c,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -d -r1.3 -r1.3.2.1
--- checkpassword-reply.c	20 Feb 2006 13:39:37 -0000	1.3
+++ checkpassword-reply.c	16 Feb 2007 17:13:04 -0000	1.3.2.1
@@ -10,26 +10,33 @@
 int main(void)
 {
 	string_t *str;
+	const char *user, *home;
 	const char *extra_env, *value, *const *tmp;
 
 	lib_init();
 	str = t_str_new(1024);
 
-	if (strchr(getenv("USER"), '\t') != NULL) {
-		i_error("USER contains TAB");
-		return 1;
-	}
-	if (strchr(getenv("HOME"), '\t') != NULL) {
-		i_error("HOME contains TAB");
+	user = getenv("USER");
+	if (user == NULL)
+		i_fatal("checkpassword: USER environment missing");
+	if (strchr(user, '\t') != NULL) {
+		i_error("checkpassword: USER contains TAB");
 		return 1;
 	}
 
 	str_printfa(str, "userdb_user=%s\t"
-		    "userdb_home=%s\t"
 		    "userdb_uid=%s\t"
 		    "userdb_gid=%s\t",
-		    getenv("USER"), getenv("HOME"),
-		    dec2str(getuid()), dec2str(getgid()));
+		    user, dec2str(getuid()), dec2str(getgid()));
+
+	home = getenv("HOME");
+	if (home != NULL) {
+		if (strchr(home, '\t') != NULL) {
+			i_error("checkpassword: HOME contains TAB");
+			return 1;
+		}
+		str_printfa(str, "userdb_home=%s\t", home);
+	}
 
 	extra_env = getenv("EXTRA");
 	if (extra_env != NULL) {
@@ -43,7 +50,7 @@
 	}
 
 	if (write_full(4, str_data(str), str_len(str)) < 0) {
-		i_error("write_full() failed: %m");
+		i_error("checkpassword: write_full() failed: %m");
 		exit(111);
 	}
 	return 0;



More information about the dovecot-cvs mailing list