changeset 5445:3a7ec48f8808 HEAD

After chrooting try to chroot to $HOME instead of to /. If home doesn't exist or chrooting fails there, fallback to /.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Mar 2007 23:05:14 +0300
parents 208c4fe8e1c9
children ce1e1fab1e1d
files src/lib/restrict-access.c
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/restrict-access.c	Wed Mar 28 22:21:24 2007 +0300
+++ b/src/lib/restrict-access.c	Wed Mar 28 23:05:14 2007 +0300
@@ -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 */