93a4744
diff -up openssh-5.1p1/sshd.c.log-chroot openssh-5.1p1/sshd.c
93a4744
--- openssh-5.1p1/sshd.c.log-chroot	2008-07-23 15:18:52.000000000 +0200
93a4744
+++ openssh-5.1p1/sshd.c	2008-07-23 15:18:52.000000000 +0200
93a4744
@@ -591,6 +591,10 @@ privsep_preauth_child(void)
c9833c9
 	/* Demote the private keys to public keys. */
c9833c9
 	demote_sensitive_data();
e01ed66
 
c9833c9
+	/* Open the syslog permanently so the chrooted process still
c9833c9
+	   can write to syslog. */
c9833c9
+	open_log();
c9833c9
+	
c9833c9
 	/* Change our root directory */
c9833c9
 	if (chroot(_PATH_PRIVSEP_CHROOT_DIR) == -1)
c9833c9
 		fatal("chroot(\"%s\"): %s", _PATH_PRIVSEP_CHROOT_DIR,
93a4744
diff -up openssh-5.1p1/log.c.log-chroot openssh-5.1p1/log.c
93a4744
--- openssh-5.1p1/log.c.log-chroot	2008-06-10 15:01:51.000000000 +0200
93a4744
+++ openssh-5.1p1/log.c	2008-07-23 15:18:52.000000000 +0200
061e214
@@ -45,6 +45,7 @@
061e214
 #include <syslog.h>
061e214
 #include <unistd.h>
061e214
 #include <errno.h>
061e214
+#include <fcntl.h>
061e214
 #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
061e214
 # include <vis.h>
061e214
 #endif
061e214
@@ -56,6 +57,7 @@
e01ed66
 static int log_on_stderr = 1;
e01ed66
 static int log_facility = LOG_AUTH;
e01ed66
 static char *argv0;
061e214
+int log_fd_keep = 0;
e01ed66
 
e01ed66
 extern char *__progname;
e01ed66
 
061e214
@@ -310,6 +312,8 @@
061e214
 		exit(1);
061e214
 	}
061e214
 
061e214
+	if (log_fd_keep != 0)
061e214
+		return;
061e214
 	/*
061e214
 	 * If an external library (eg libwrap) attempts to use syslog
061e214
 	 * immediately after reexec, syslog may be pointing to the wrong
061e214
@@ -392,10 +396,33 @@
e01ed66
 		syslog_r(pri, &sdata, "%.500s", fmtbuf);
e01ed66
 		closelog_r(&sdata);
e01ed66
 #else
e01ed66
+	    if (!log_fd_keep) {
e01ed66
 		openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
e01ed66
+	    }
e01ed66
 		syslog(pri, "%.500s", fmtbuf);
e01ed66
+	    if (!log_fd_keep) {
e01ed66
 		closelog();
e01ed66
+	    }
e01ed66
 #endif
e01ed66
 	}
c9833c9
 	errno = saved_errno;
e01ed66
 }
e01ed66
+
e01ed66
+void
e01ed66
+open_log(void)
e01ed66
+{
061e214
+	int temp1, temp2;
061e214
+
061e214
+	temp1 = open("/dev/null", O_RDONLY);
e01ed66
+	openlog(argv0 ? argv0 : __progname, LOG_PID|LOG_NDELAY, log_facility);
061e214
+	temp2 = open("/dev/null", O_RDONLY);
061e214
+	if (temp1 + 2 ==  temp2)
061e214
+		log_fd_keep = temp1 + 1;
061e214
+	else 
061e214
+		log_fd_keep = -1;
061e214
+
061e214
+	if (temp1 != -1)
061e214
+		close(temp1);
061e214
+	if (temp2 != -1)
061e214
+		close(temp2);
e01ed66
+}
93a4744
diff -up openssh-5.1p1/log.h.log-chroot openssh-5.1p1/log.h
93a4744
--- openssh-5.1p1/log.h.log-chroot	2008-06-13 02:22:54.000000000 +0200
93a4744
+++ openssh-5.1p1/log.h	2008-07-23 15:20:11.000000000 +0200
061e214
@@ -46,6 +46,9 @@
061e214
 	SYSLOG_LEVEL_NOT_SET = -1
061e214
 }       LogLevel;
061e214
 
061e214
+
061e214
+extern int log_fd_keep;
061e214
+
061e214
 void     log_init(char *, LogLevel, SyslogFacility, int);
061e214
 
061e214
 SyslogFacility	log_facility_number(char *);
061e214
@@ -66,4 +69,6 @@
e01ed66
 
c9833c9
 void	 do_log(LogLevel, const char *, va_list);
93a4744
 void	 cleanup_exit(int) __attribute__((noreturn));
c9833c9
+
c9833c9
+void     open_log(void);
c9833c9
 #endif
061e214
--- openssh-5.2p1/session.c.	2009-03-20 18:32:01.004151364 +0100
061e214
+++ openssh-5.2p1/session.c	2009-03-20 19:00:28.328742384 +0100
061e214
@@ -1445,6 +1456,7 @@
061e214
 	if (chdir(path) == -1)
061e214
 		fatal("Unable to chdir to chroot path \"%s\": "
061e214
 		    "%s", path, strerror(errno));
061e214
+	open_log ();
061e214
 	if (chroot(path) == -1)
061e214
 		fatal("chroot(\"%s\"): %s", path, strerror(errno));
061e214
 	if (chdir("/") == -1)
061e214
@@ -1632,7 +1644,8 @@
061e214
 	 * descriptors open.
061e214
 	 */
061e214
 	for (i = 3; i < 64; i++)
061e214
-		close(i);
061e214
+		if (i != log_fd_keep)
061e214
+			close(i);
061e214
 }
061e214
 
061e214
 /*