|
|
3e8b5b |
diff -up openssh-7.4p1/log.c.log-in-chroot openssh-7.4p1/log.c
|
|
|
3e8b5b |
--- openssh-7.4p1/log.c.log-in-chroot 2016-12-19 05:59:41.000000000 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/log.c 2016-12-23 15:14:33.330168088 +0100
|
|
|
3e8b5b |
@@ -250,6 +250,11 @@ debug3(const char *fmt,...)
|
|
|
3e8b5b |
void
|
|
|
3e8b5b |
log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
|
|
|
3e8b5b |
{
|
|
|
3e8b5b |
+ log_init_handler(av0, level, facility, on_stderr, 1);
|
|
|
3e8b5b |
+}
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
+void
|
|
|
3e8b5b |
+log_init_handler(char *av0, LogLevel level, SyslogFacility facility, int on_stderr, int reset_handler) {
|
|
|
3e8b5b |
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
|
|
|
3e8b5b |
struct syslog_data sdata = SYSLOG_DATA_INIT;
|
|
|
3e8b5b |
#endif
|
|
|
3e8b5b |
@@ -273,8 +278,10 @@ log_init(char *av0, LogLevel level, Sysl
|
|
|
3e8b5b |
exit(1);
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
- log_handler = NULL;
|
|
|
3e8b5b |
- log_handler_ctx = NULL;
|
|
|
3e8b5b |
+ if (reset_handler) {
|
|
|
3e8b5b |
+ log_handler = NULL;
|
|
|
3e8b5b |
+ log_handler_ctx = NULL;
|
|
|
3e8b5b |
+ }
|
|
|
3e8b5b |
|
|
|
3e8b5b |
log_on_stderr = on_stderr;
|
|
|
3e8b5b |
if (on_stderr)
|
|
|
3e8b5b |
diff -up openssh-7.4p1/log.h.log-in-chroot openssh-7.4p1/log.h
|
|
|
3e8b5b |
--- openssh-7.4p1/log.h.log-in-chroot 2016-12-19 05:59:41.000000000 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/log.h 2016-12-23 15:14:33.330168088 +0100
|
|
|
3e8b5b |
@@ -49,6 +49,7 @@ typedef enum {
|
|
|
3e8b5b |
typedef void (log_handler_fn)(LogLevel, const char *, void *);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
void log_init(char *, LogLevel, SyslogFacility, int);
|
|
|
3e8b5b |
+void log_init_handler(char *, LogLevel, SyslogFacility, int, int);
|
|
|
3e8b5b |
LogLevel log_level_get(void);
|
|
|
3e8b5b |
int log_change_level(LogLevel);
|
|
|
3e8b5b |
int log_is_on_stderr(void);
|
|
|
3e8b5b |
diff -up openssh-7.4p1/monitor.c.log-in-chroot openssh-7.4p1/monitor.c
|
|
|
3e8b5b |
--- openssh-7.4p1/monitor.c.log-in-chroot 2016-12-23 15:14:33.311168085 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/monitor.c 2016-12-23 15:16:42.154193100 +0100
|
|
|
3e8b5b |
@@ -307,6 +307,8 @@ monitor_child_preauth(Authctxt *_authctx
|
|
|
3e8b5b |
close(pmonitor->m_log_sendfd);
|
|
|
3e8b5b |
pmonitor->m_log_sendfd = pmonitor->m_recvfd = -1;
|
|
|
3e8b5b |
|
|
|
3e8b5b |
+ pmonitor->m_state = "preauth";
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
authctxt = (Authctxt *)ssh->authctxt;
|
|
|
3e8b5b |
memset(authctxt, 0, sizeof(*authctxt));
|
|
|
3e8b5b |
ssh->authctxt = authctxt;
|
|
|
3e8b5b |
@@ -405,6 +407,8 @@ monitor_child_postauth(struct monitor *p
|
|
|
3e8b5b |
close(pmonitor->m_recvfd);
|
|
|
3e8b5b |
pmonitor->m_recvfd = -1;
|
|
|
3e8b5b |
|
|
|
3e8b5b |
+ pmonitor->m_state = "postauth";
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
monitor_set_child_handler(pmonitor->m_pid);
|
|
|
3e8b5b |
signal(SIGHUP, &monitor_child_handler);
|
|
|
3e8b5b |
signal(SIGTERM, &monitor_child_handler);
|
|
|
3e8b5b |
@@ -472,7 +476,7 @@ monitor_read_log(struct monitor *pmonito
|
|
|
3e8b5b |
if (log_level_name(level) == NULL)
|
|
|
3e8b5b |
fatal("%s: invalid log level %u (corrupted message?)",
|
|
|
3e8b5b |
__func__, level);
|
|
|
3e8b5b |
- do_log2(level, "%s [preauth]", msg);
|
|
|
3e8b5b |
+ do_log2(level, "%s [%s]", msg, pmonitor->m_state);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
sshbuf_free(logmsg);
|
|
|
3e8b5b |
free(msg);
|
|
|
3e8b5b |
@@ -1719,13 +1723,28 @@ monitor_init(void)
|
|
|
3e8b5b |
mon = xcalloc(1, sizeof(*mon));
|
|
|
3e8b5b |
monitor_openfds(mon, 1);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
+ mon->m_state = "";
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
return mon;
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
void
|
|
|
3e8b5b |
-monitor_reinit(struct monitor *mon)
|
|
|
3e8b5b |
+monitor_reinit(struct monitor *mon, const char *chroot_dir)
|
|
|
3e8b5b |
{
|
|
|
3e8b5b |
- monitor_openfds(mon, 0);
|
|
|
3e8b5b |
+ struct stat dev_log_stat;
|
|
|
3e8b5b |
+ char *dev_log_path;
|
|
|
3e8b5b |
+ int do_logfds = 0;
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
+ if (chroot_dir != NULL) {
|
|
|
3e8b5b |
+ xasprintf(&dev_log_path, "%s/dev/log", chroot_dir);
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
+ if (stat(dev_log_path, &dev_log_stat) != 0) {
|
|
|
3e8b5b |
+ debug("%s: /dev/log doesn't exist in %s chroot - will try to log via monitor using [postauth] suffix", __func__, chroot_dir);
|
|
|
3e8b5b |
+ do_logfds = 1;
|
|
|
3e8b5b |
+ }
|
|
|
3e8b5b |
+ free(dev_log_path);
|
|
|
3e8b5b |
+ }
|
|
|
3e8b5b |
+ monitor_openfds(mon, do_logfds);
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
#ifdef GSSAPI
|
|
|
3e8b5b |
diff -up openssh-7.4p1/monitor.h.log-in-chroot openssh-7.4p1/monitor.h
|
|
|
3e8b5b |
--- openssh-7.4p1/monitor.h.log-in-chroot 2016-12-23 15:14:33.330168088 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/monitor.h 2016-12-23 15:16:28.372190424 +0100
|
|
|
3e8b5b |
@@ -83,10 +83,11 @@ struct monitor {
|
|
|
3e8b5b |
int m_log_sendfd;
|
|
|
3e8b5b |
struct kex **m_pkex;
|
|
|
3e8b5b |
pid_t m_pid;
|
|
|
3e8b5b |
+ char *m_state;
|
|
|
3e8b5b |
};
|
|
|
3e8b5b |
|
|
|
3e8b5b |
struct monitor *monitor_init(void);
|
|
|
3e8b5b |
-void monitor_reinit(struct monitor *);
|
|
|
3e8b5b |
+void monitor_reinit(struct monitor *, const char *);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
struct Authctxt;
|
|
|
3e8b5b |
void monitor_child_preauth(struct ssh *, struct monitor *);
|
|
|
3e8b5b |
diff -up openssh-7.4p1/session.c.log-in-chroot openssh-7.4p1/session.c
|
|
|
3e8b5b |
--- openssh-7.4p1/session.c.log-in-chroot 2016-12-23 15:14:33.319168086 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/session.c 2016-12-23 15:18:18.742211853 +0100
|
|
|
3e8b5b |
@@ -160,6 +160,7 @@ login_cap_t *lc;
|
|
|
3e8b5b |
|
|
|
3e8b5b |
static int is_child = 0;
|
|
|
3e8b5b |
static int in_chroot = 0;
|
|
|
3e8b5b |
+static int have_dev_log = 1;
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/* File containing userauth info, if ExposeAuthInfo set */
|
|
|
3e8b5b |
static char *auth_info_file = NULL;
|
|
|
3e8b5b |
@@ -619,6 +620,7 @@ do_exec(Session *s, const char *command)
|
|
|
3e8b5b |
int ret;
|
|
|
3e8b5b |
const char *forced = NULL, *tty = NULL;
|
|
|
3e8b5b |
char session_type[1024];
|
|
|
3e8b5b |
+ struct stat dev_log_stat;
|
|
|
3e8b5b |
|
|
|
3e8b5b |
if (options.adm_forced_command) {
|
|
|
3e8b5b |
original_command = command;
|
|
|
3e8b5b |
@@ -676,6 +678,10 @@ do_exec(Session *s, const char *command)
|
|
|
3e8b5b |
tty += 5;
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
+ if (lstat("/dev/log", &dev_log_stat) != 0) {
|
|
|
3e8b5b |
+ have_dev_log = 0;
|
|
|
3e8b5b |
+ }
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
verbose("Starting session: %s%s%s for %s from %.200s port %d id %d",
|
|
|
3e8b5b |
session_type,
|
|
|
3e8b5b |
tty == NULL ? "" : " on ",
|
|
|
3e8b5b |
@@ -1486,14 +1492,6 @@ child_close_fds(void)
|
|
|
3e8b5b |
* descriptors left by system functions. They will be closed later.
|
|
|
3e8b5b |
*/
|
|
|
3e8b5b |
endpwent();
|
|
|
3e8b5b |
-
|
|
|
3e8b5b |
- /*
|
|
|
3e8b5b |
- * Close any extra open file descriptors so that we don't have them
|
|
|
3e8b5b |
- * hanging around in clients. Note that we want to do this after
|
|
|
3e8b5b |
- * initgroups, because at least on Solaris 2.3 it leaves file
|
|
|
3e8b5b |
- * descriptors open.
|
|
|
3e8b5b |
- */
|
|
|
3e8b5b |
- closefrom(STDERR_FILENO + 1);
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/*
|
|
|
3e8b5b |
@@ -1629,8 +1627,6 @@ do_child(Session *s, const char *command
|
|
|
3e8b5b |
exit(1);
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
- closefrom(STDERR_FILENO + 1);
|
|
|
3e8b5b |
-
|
|
|
3e8b5b |
do_rc_files(ssh, s, shell);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/* restore SIGPIPE for child */
|
|
|
3e8b5b |
@@ -1653,9 +1649,17 @@ do_child(Session *s, const char *command
|
|
|
3e8b5b |
argv[i] = NULL;
|
|
|
3e8b5b |
optind = optreset = 1;
|
|
|
3e8b5b |
__progname = argv[0];
|
|
|
3e8b5b |
- exit(sftp_server_main(i, argv, s->pw));
|
|
|
3e8b5b |
+ exit(sftp_server_main(i, argv, s->pw, have_dev_log));
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
+ /*
|
|
|
3e8b5b |
+ * Close any extra open file descriptors so that we don't have them
|
|
|
3e8b5b |
+ * hanging around in clients. Note that we want to do this after
|
|
|
3e8b5b |
+ * initgroups, because at least on Solaris 2.3 it leaves file
|
|
|
3e8b5b |
+ * descriptors open.
|
|
|
3e8b5b |
+ */
|
|
|
3e8b5b |
+ closefrom(STDERR_FILENO + 1);
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
fflush(NULL);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/* Get the last component of the shell name. */
|
|
|
3e8b5b |
diff -up openssh-7.4p1/sftp.h.log-in-chroot openssh-7.4p1/sftp.h
|
|
|
3e8b5b |
--- openssh-7.4p1/sftp.h.log-in-chroot 2016-12-19 05:59:41.000000000 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/sftp.h 2016-12-23 15:14:33.331168088 +0100
|
|
|
3e8b5b |
@@ -97,5 +97,5 @@
|
|
|
3e8b5b |
|
|
|
3e8b5b |
struct passwd;
|
|
|
3e8b5b |
|
|
|
3e8b5b |
-int sftp_server_main(int, char **, struct passwd *);
|
|
|
3e8b5b |
+int sftp_server_main(int, char **, struct passwd *, int);
|
|
|
3e8b5b |
void sftp_server_cleanup_exit(int) __attribute__((noreturn));
|
|
|
3e8b5b |
diff -up openssh-7.4p1/sftp-server.c.log-in-chroot openssh-7.4p1/sftp-server.c
|
|
|
3e8b5b |
--- openssh-7.4p1/sftp-server.c.log-in-chroot 2016-12-19 05:59:41.000000000 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/sftp-server.c 2016-12-23 15:14:33.331168088 +0100
|
|
|
3e8b5b |
@@ -1497,7 +1497,7 @@ sftp_server_usage(void)
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
int
|
|
|
3e8b5b |
-sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
|
|
3e8b5b |
+sftp_server_main(int argc, char **argv, struct passwd *user_pw, int reset_handler)
|
|
|
3e8b5b |
{
|
|
|
3e8b5b |
fd_set *rset, *wset;
|
|
|
3e8b5b |
int i, r, in, out, max, ch, skipargs = 0, log_stderr = 0;
|
|
|
3e8b5b |
@@ -1511,7 +1511,7 @@ sftp_server_main(int argc, char **argv,
|
|
|
3e8b5b |
|
|
|
3e8b5b |
ssh_malloc_init(); /* must be called before any mallocs */
|
|
|
3e8b5b |
__progname = ssh_get_progname(argv[0]);
|
|
|
3e8b5b |
- log_init(__progname, log_level, log_facility, log_stderr);
|
|
|
3e8b5b |
+ log_init_handler(__progname, log_level, log_facility, log_stderr, reset_handler);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
pw = pwcopy(user_pw);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
@@ -1582,7 +1582,7 @@ sftp_server_main(int argc, char **argv,
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
- log_init(__progname, log_level, log_facility, log_stderr);
|
|
|
3e8b5b |
+ log_init_handler(__progname, log_level, log_facility, log_stderr, reset_handler);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/*
|
|
|
3e8b5b |
* On platforms where we can, avoid making /proc/self/{mem,maps}
|
|
|
3e8b5b |
diff -up openssh-7.4p1/sftp-server-main.c.log-in-chroot openssh-7.4p1/sftp-server-main.c
|
|
|
3e8b5b |
--- openssh-7.4p1/sftp-server-main.c.log-in-chroot 2016-12-19 05:59:41.000000000 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/sftp-server-main.c 2016-12-23 15:14:33.331168088 +0100
|
|
|
3e8b5b |
@@ -49,5 +49,5 @@ main(int argc, char **argv)
|
|
|
3e8b5b |
return 1;
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
- return (sftp_server_main(argc, argv, user_pw));
|
|
|
3e8b5b |
+ return (sftp_server_main(argc, argv, user_pw, 0));
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
diff -up openssh-7.4p1/sshd.c.log-in-chroot openssh-7.4p1/sshd.c
|
|
|
3e8b5b |
--- openssh-7.4p1/sshd.c.log-in-chroot 2016-12-23 15:14:33.328168088 +0100
|
|
|
3e8b5b |
+++ openssh-7.4p1/sshd.c 2016-12-23 15:14:33.332168088 +0100
|
|
|
3e8b5b |
@@ -650,7 +650,7 @@ privsep_postauth(Authctxt *authctxt)
|
|
|
3e8b5b |
}
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/* New socket pair */
|
|
|
3e8b5b |
- monitor_reinit(pmonitor);
|
|
|
3e8b5b |
+ monitor_reinit(pmonitor, options.chroot_directory);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
pmonitor->m_pid = fork();
|
|
|
3e8b5b |
if (pmonitor->m_pid == -1)
|
|
|
3e8b5b |
@@ -668,6 +668,11 @@ privsep_postauth(Authctxt *authctxt)
|
|
|
3e8b5b |
|
|
|
3e8b5b |
close(pmonitor->m_sendfd);
|
|
|
3e8b5b |
pmonitor->m_sendfd = -1;
|
|
|
3e8b5b |
+ close(pmonitor->m_log_recvfd);
|
|
|
3e8b5b |
+ pmonitor->m_log_recvfd = -1;
|
|
|
3e8b5b |
+
|
|
|
3e8b5b |
+ if (pmonitor->m_log_sendfd != -1)
|
|
|
3e8b5b |
+ set_log_handler(mm_log_handler, pmonitor);
|
|
|
3e8b5b |
|
|
|
3e8b5b |
/* Demote the private keys to public keys. */
|
|
|
3e8b5b |
demote_sensitive_data();
|