vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Petr Lautrbach cd5891
diff --git a/session.c b/session.c
Petr Lautrbach cd5891
index 436ea48..49c9321 100644
Petr Lautrbach cd5891
--- a/session.c
Petr Lautrbach cd5891
+++ b/session.c
Petr Lautrbach cd5891
@@ -1561,6 +1561,13 @@ do_setusercontext(struct passwd *pw)
Petr Lautrbach cd5891
 #endif
Petr Lautrbach cd5891
 	}
Petr Lautrbach cd5891
 
Petr Lautrbach cd5891
+#ifdef WITH_SELINUX
Petr Lautrbach cd5891
+	if (options.chroot_directory == NULL ||
Petr Lautrbach cd5891
+	    strcasecmp(options.chroot_directory, "none") == 0) {
Petr Lautrbach cd5891
+		ssh_selinux_copy_context();
Petr Lautrbach cd5891
+	}
Petr Lautrbach cd5891
+#endif
Petr Lautrbach cd5891
+
Petr Lautrbach cd5891
 	if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
Petr Lautrbach cd5891
 		fatal("Failed to set uids to %u.", (u_int) pw->pw_uid);
Petr Lautrbach cd5891
 }
Petr Lautrbach c3bb45
@@ -1670,7 +1677,9 @@ do_child(Session *s, const char *command
Petr Lautrbach cd5891
 		/* When PAM is enabled we rely on it to do the nologin check */
Petr Lautrbach cd5891
 		if (!options.use_pam)
Petr Lautrbach cd5891
 			do_nologin(pw);
Petr Lautrbach cd5891
-		do_setusercontext(pw);
Petr Lautrbach cd5891
+		/* We are already separated */
Petr Lautrbach cd5891
+		if (!use_privsep)
Petr Lautrbach cd5891
+			do_setusercontext(pw);
Petr Lautrbach cd5891
 		/*
Petr Lautrbach cd5891
 		 * PAM session modules in do_setusercontext may have
Petr Lautrbach cd5891
 		 * generated messages, so if this in an interactive
Petr Lautrbach c3bb45
@@ -1791,8 +1800,8 @@ do_child(Session *s, const char *command
Petr Lautrbach c3bb45
 		optind = optreset = 1;
Petr Lautrbach c3bb45
 		__progname = argv[0];
Petr Lautrbach c3bb45
 #ifdef WITH_SELINUX
Petr Lautrbach c3bb45
-		if (options.chroot_directory == NULL ||
Petr Lautrbach c3bb45
-		    strcasecmp(options.chroot_directory, "none") == 0) {
Petr Lautrbach c3bb45
+		if (!use_privsep &&
Petr Lautrbach c3bb45
+		    (options.chroot_directory == NULL || strcasecmp(options.chroot_directory, "none") == 0)) {
Petr Lautrbach c3bb45
 			ssh_selinux_copy_context();
Petr Lautrbach c3bb45
 		}
Petr Lautrbach c3bb45
 #endif