[PATCH 1/1] do not print warning about missing home directory in chroot

Christian Hesse list at eworm.de
Mon Sep 7 23:10:26 AEST 2015


From: Christian Hesse <mail at eworm.de>

Since setting options.chroot_directory to NULL after successful chroot
the following error message is back:

Could not chdir to home directory /home/user: No such file or
directory

Remember that we are inside a chroot and do not print error message
about missing home directory.

Signed-off-by: Christian Hesse <mail at eworm.de>
---
 session.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/session.c b/session.c
index 5a64715..35790cf 100644
--- a/session.c
+++ b/session.c
@@ -160,6 +160,7 @@ login_cap_t *lc;
 #endif
 
 static int is_child = 0;
+static int in_chroot = 0;
 
 /* Name and directory of socket for authentication agent forwarding. */
 static char *auth_sock_name = NULL;
@@ -1529,6 +1530,14 @@ do_setusercontext(struct passwd *pw)
 			safely_chroot(chroot_path, pw->pw_uid);
 			free(tmp);
 			free(chroot_path);
+
+			/*
+			 * Remember we are inside a chroot. We need this later
+			 * to know whether or not to print a warning about
+			 * missing home directory.
+			 */
+			in_chroot = 1;
+
 			/* Make sure we don't attempt to chroot again */
 			free(options.chroot_directory);
 			options.chroot_directory = NULL;
@@ -1790,8 +1799,7 @@ do_child(Session *s, const char *command)
 #ifdef HAVE_LOGIN_CAP
 		r = login_getcapbool(lc, "requirehome", 0);
 #endif
-		if (r || options.chroot_directory == NULL ||
-		    strcasecmp(options.chroot_directory, "none") == 0)
+		if (r || in_chroot == 0)
 			fprintf(stderr, "Could not chdir to home "
 			    "directory %s: %s\n", pw->pw_dir,
 			    strerror(errno));
-- 
2.5.1



More information about the openssh-unix-dev mailing list