[dovecot-cvs] dovecot/src/lib restrict-access.c,1.22,1.23

tss at dovecot.org tss at dovecot.org
Wed Mar 28 23:05:16 EEST 2007


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

Modified Files:
	restrict-access.c 
Log Message:
After chrooting try to chroot to $HOME instead of to /. If home doesn't
exist or chrooting fails there, fallback to /.



Index: restrict-access.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/restrict-access.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- restrict-access.c	3 Dec 2006 15:45:10 -0000	1.22
+++ restrict-access.c	28 Mar 2007 20:05:14 -0000	1.23
@@ -169,14 +169,23 @@
 	if (env != NULL && *env != '\0') {
 		/* kludge: localtime() must be called before chroot(),
 		   or the timezone isn't known */
+		const char *home = getenv("HOME");
 		time_t t = 0;
 		(void)localtime(&t);
 
 		if (chroot(env) != 0)
 			i_fatal("chroot(%s) failed: %m", env);
 
-		if (chdir("/") != 0)
-			i_fatal("chdir(/) failed: %m");
+		if (home != NULL) {
+			if (chdir(home) < 0) {
+				i_error("chdir(%s) failed: %m", home);
+				home = NULL;
+			}
+		}
+		if (home == NULL) {
+			if (chdir("/") != 0)
+				i_fatal("chdir(/) failed: %m");
+		}
 	}
 
 	/* uid last */



More information about the dovecot-cvs mailing list