vishalmishra434 / rpms / openssh

Forked from rpms/openssh 3 months ago
Clone
Jan F. Chadima 061e21
--- openssh-5.2p1/session.c	2009-03-20 18:08:11.263662384 +0100
Jan F. Chadima 061e21
+++ openssh-5.2p1/session.c	2009-03-20 18:26:29.925498409 +0100
Jan F. Chadima 061e21
@@ -1408,6 +1408,7 @@
Jan F. Chadima 061e21
 	const char *cp;
Jan F. Chadima 061e21
 	char component[MAXPATHLEN];
Jan F. Chadima 061e21
 	struct stat st;
Jan F. Chadima 061e21
+	int last;
Jan F. Chadima 061e21
 
Jan F. Chadima 061e21
 	if (*path != '/')
Jan F. Chadima 061e21
 		fatal("chroot path does not begin at root");
Jan F. Chadima 061e21
@@ -1419,7 +1420,7 @@
Jan F. Chadima 061e21
 	 * root-owned directory with strict permissions.
Jan F. Chadima 061e21
 	 */
Jan F. Chadima 061e21
 	for (cp = path; cp != NULL;) {
Jan F. Chadima 061e21
-		if ((cp = strchr(cp, '/')) == NULL)
Jan F. Chadima 061e21
+		if (((last = ((cp = strchr(cp, '/')) == NULL))))
Jan F. Chadima 061e21
 			strlcpy(component, path, sizeof(component));
Jan F. Chadima 061e21
 		else {
Jan F. Chadima 061e21
 			cp++;
Jan F. Chadima 061e21
@@ -1432,7 +1433,7 @@
Jan F. Chadima 061e21
 		if (stat(component, &st) != 0)
Jan F. Chadima 061e21
 			fatal("%s: stat(\"%s\"): %s", __func__,
Jan F. Chadima 061e21
 			    component, strerror(errno));
Jan F. Chadima 061e21
-		if (st.st_uid != 0 || (st.st_mode & 022) != 0)
Jan F. Chadima 061e21
+		if ((st.st_uid != 0 || (st.st_mode & 022) != 0) && !(last && st.st_uid == uid))
Jan F. Chadima 061e21
 			fatal("bad ownership or modes for chroot "
Jan F. Chadima 061e21
 			    "directory %s\"%s\"", 
Jan F. Chadima 061e21
 			    cp == NULL ? "" : "component ", component);