2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/log.c openssh-7.6p1-patched/log.c
|
|
|
|
--- openssh-7.6p1/log.c 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/log.c 2017-12-17 01:11:56.897272190 +1000
|
2016-09-30 05:06:40 -04:00
|
|
|
@@ -250,6 +250,11 @@
|
|
|
|
void
|
|
|
|
log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
|
|
|
|
{
|
|
|
|
+ log_init_handler(av0, level, facility, on_stderr, 1);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+log_init_handler(char *av0, LogLevel level, SyslogFacility facility, int on_stderr, int reset_handler) {
|
|
|
|
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
|
|
|
|
struct syslog_data sdata = SYSLOG_DATA_INIT;
|
|
|
|
#endif
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -262,8 +267,10 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
- log_handler = NULL;
|
|
|
|
- log_handler_ctx = NULL;
|
|
|
|
+ if (reset_handler) {
|
|
|
|
+ log_handler = NULL;
|
|
|
|
+ log_handler_ctx = NULL;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
log_on_stderr = on_stderr;
|
|
|
|
if (on_stderr)
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/log.h openssh-7.6p1-patched/log.h
|
|
|
|
--- openssh-7.6p1/log.h 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/log.h 2017-12-17 01:11:56.898272190 +1000
|
2016-09-30 05:06:40 -04:00
|
|
|
@@ -49,6 +49,7 @@
|
|
|
|
typedef void (log_handler_fn)(LogLevel, const char *, void *);
|
|
|
|
|
|
|
|
void log_init(char *, LogLevel, SyslogFacility, int);
|
|
|
|
+void log_init_handler(char *, LogLevel, SyslogFacility, int, int);
|
2017-12-17 01:17:56 +10:00
|
|
|
int log_change_level(LogLevel);
|
2016-09-30 05:06:40 -04:00
|
|
|
int log_is_on_stderr(void);
|
|
|
|
void log_redirect_stderr_to(const char *);
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/monitor.c openssh-7.6p1-patched/monitor.c
|
|
|
|
--- openssh-7.6p1/monitor.c 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/monitor.c 2017-12-17 01:11:56.899272190 +1000
|
|
|
|
@@ -293,6 +293,8 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
close(pmonitor->m_log_sendfd);
|
|
|
|
pmonitor->m_log_sendfd = pmonitor->m_recvfd = -1;
|
|
|
|
|
|
|
|
+ pmonitor->m_state = "preauth";
|
|
|
|
+
|
|
|
|
authctxt = _authctxt;
|
|
|
|
memset(authctxt, 0, sizeof(*authctxt));
|
|
|
|
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -394,6 +396,8 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
close(pmonitor->m_recvfd);
|
|
|
|
pmonitor->m_recvfd = -1;
|
|
|
|
|
|
|
|
+ pmonitor->m_state = "postauth";
|
|
|
|
+
|
|
|
|
monitor_set_child_handler(pmonitor->m_pid);
|
|
|
|
signal(SIGHUP, &monitor_child_handler);
|
|
|
|
signal(SIGTERM, &monitor_child_handler);
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -457,7 +461,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
if (log_level_name(level) == NULL)
|
|
|
|
fatal("%s: invalid log level %u (corrupted message?)",
|
|
|
|
__func__, level);
|
|
|
|
- do_log2(level, "%s [preauth]", msg);
|
|
|
|
+ do_log2(level, "%s [%s]", msg, pmonitor->m_state);
|
|
|
|
|
|
|
|
buffer_free(&logmsg);
|
|
|
|
free(msg);
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -1697,13 +1701,28 @@
|
2017-07-28 14:28:10 +03:00
|
|
|
mon = xcalloc(1, sizeof(*mon));
|
|
|
|
monitor_openfds(mon, 1);
|
2016-09-30 05:06:40 -04:00
|
|
|
|
|
|
|
+ mon->m_state = "";
|
|
|
|
+
|
|
|
|
return mon;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-monitor_reinit(struct monitor *mon)
|
|
|
|
+monitor_reinit(struct monitor *mon, const char *chroot_dir)
|
|
|
|
{
|
|
|
|
- monitor_openfds(mon, 0);
|
|
|
|
+ struct stat dev_log_stat;
|
|
|
|
+ char *dev_log_path;
|
|
|
|
+ int do_logfds = 0;
|
|
|
|
+
|
|
|
|
+ if (chroot_dir != NULL) {
|
|
|
|
+ xasprintf(&dev_log_path, "%s/dev/log", chroot_dir);
|
|
|
|
+
|
|
|
|
+ if (stat(dev_log_path, &dev_log_stat) != 0) {
|
|
|
|
+ debug("%s: /dev/log doesn't exist in %s chroot - will try to log via monitor using [postauth] suffix", __func__, chroot_dir);
|
|
|
|
+ do_logfds = 1;
|
|
|
|
+ }
|
|
|
|
+ free(dev_log_path);
|
|
|
|
+ }
|
|
|
|
+ monitor_openfds(mon, do_logfds);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GSSAPI
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/monitor.h openssh-7.6p1-patched/monitor.h
|
|
|
|
--- openssh-7.6p1/monitor.h 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/monitor.h 2017-12-17 01:11:56.900272190 +1000
|
|
|
|
@@ -74,10 +74,11 @@
|
2017-07-28 14:28:10 +03:00
|
|
|
int m_log_sendfd;
|
2016-09-30 05:06:40 -04:00
|
|
|
struct kex **m_pkex;
|
|
|
|
pid_t m_pid;
|
|
|
|
+ char *m_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct monitor *monitor_init(void);
|
|
|
|
-void monitor_reinit(struct monitor *);
|
|
|
|
+void monitor_reinit(struct monitor *, const char *);
|
|
|
|
|
|
|
|
struct Authctxt;
|
2017-07-28 14:28:10 +03:00
|
|
|
void monitor_child_preauth(struct Authctxt *, struct monitor *);
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/session.c openssh-7.6p1-patched/session.c
|
|
|
|
--- openssh-7.6p1/session.c 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/session.c 2017-12-17 01:13:36.965278562 +1000
|
2017-07-28 14:28:10 +03:00
|
|
|
@@ -160,6 +160,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
|
|
|
|
static int is_child = 0;
|
|
|
|
static int in_chroot = 0;
|
|
|
|
+static int have_dev_log = 1;
|
|
|
|
|
2017-12-17 01:17:56 +10:00
|
|
|
/* File containing userauth info, if ExposeAuthInfo set */
|
|
|
|
static char *auth_info_file = NULL;
|
|
|
|
@@ -651,6 +652,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
int ret;
|
|
|
|
const char *forced = NULL, *tty = NULL;
|
|
|
|
char session_type[1024];
|
|
|
|
+ struct stat dev_log_stat;
|
|
|
|
|
|
|
|
if (options.adm_forced_command) {
|
|
|
|
original_command = command;
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -685,6 +687,10 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
tty += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (lstat("/dev/log", &dev_log_stat) != 0) {
|
|
|
|
+ have_dev_log = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
verbose("Starting session: %s%s%s for %s from %.200s port %d id %d",
|
|
|
|
session_type,
|
|
|
|
tty == NULL ? "" : " on ",
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -1445,14 +1451,6 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
* descriptors left by system functions. They will be closed later.
|
|
|
|
*/
|
|
|
|
endpwent();
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- * Close any extra open file descriptors so that we don't have them
|
|
|
|
- * hanging around in clients. Note that we want to do this after
|
|
|
|
- * initgroups, because at least on Solaris 2.3 it leaves file
|
|
|
|
- * descriptors open.
|
|
|
|
- */
|
|
|
|
- closefrom(STDERR_FILENO + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -1589,8 +1587,6 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
- closefrom(STDERR_FILENO + 1);
|
|
|
|
-
|
2017-07-28 14:28:10 +03:00
|
|
|
do_rc_files(s, shell);
|
2016-09-30 05:06:40 -04:00
|
|
|
|
2017-07-28 14:28:10 +03:00
|
|
|
/* restore SIGPIPE for child */
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -1616,9 +1612,17 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
ssh_selinux_change_context("sftpd_t");
|
|
|
|
#endif
|
|
|
|
- exit(sftp_server_main(i, argv, s->pw));
|
|
|
|
+ exit(sftp_server_main(i, argv, s->pw, have_dev_log));
|
|
|
|
}
|
|
|
|
|
2017-07-28 14:28:10 +03:00
|
|
|
+ /*
|
2017-12-17 01:17:56 +10:00
|
|
|
+ * Close any extra open file descriptors so that we don't have them
|
|
|
|
+ * hanging around in clients. Note that we want to do this after
|
|
|
|
+ * initgroups, because at least on Solaris 2.3 it leaves file
|
|
|
|
+ * descriptors open.
|
|
|
|
+ */
|
2017-07-28 14:28:10 +03:00
|
|
|
+ closefrom(STDERR_FILENO + 1);
|
|
|
|
+
|
2016-09-30 05:06:40 -04:00
|
|
|
fflush(NULL);
|
2017-07-28 14:28:10 +03:00
|
|
|
|
|
|
|
/* Get the last component of the shell name. */
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/sftp.h openssh-7.6p1-patched/sftp.h
|
|
|
|
--- openssh-7.6p1/sftp.h 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/sftp.h 2017-12-17 01:11:56.901272190 +1000
|
2016-09-30 05:06:40 -04:00
|
|
|
@@ -97,5 +97,5 @@
|
|
|
|
|
|
|
|
struct passwd;
|
|
|
|
|
|
|
|
-int sftp_server_main(int, char **, struct passwd *);
|
|
|
|
+int sftp_server_main(int, char **, struct passwd *, int);
|
|
|
|
void sftp_server_cleanup_exit(int) __attribute__((noreturn));
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/sftp-server.c openssh-7.6p1-patched/sftp-server.c
|
|
|
|
--- openssh-7.6p1/sftp-server.c 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/sftp-server.c 2017-12-17 01:11:56.901272190 +1000
|
2017-07-28 14:28:10 +03:00
|
|
|
@@ -1497,7 +1497,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
-sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
|
|
|
+sftp_server_main(int argc, char **argv, struct passwd *user_pw, int reset_handler)
|
|
|
|
{
|
|
|
|
fd_set *rset, *wset;
|
|
|
|
int i, r, in, out, max, ch, skipargs = 0, log_stderr = 0;
|
2017-07-28 14:28:10 +03:00
|
|
|
@@ -1511,7 +1511,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
|
|
|
|
ssh_malloc_init(); /* must be called before any mallocs */
|
|
|
|
__progname = ssh_get_progname(argv[0]);
|
|
|
|
- log_init(__progname, log_level, log_facility, log_stderr);
|
|
|
|
+ log_init_handler(__progname, log_level, log_facility, log_stderr, reset_handler);
|
|
|
|
|
|
|
|
pw = pwcopy(user_pw);
|
|
|
|
|
2017-07-28 14:28:10 +03:00
|
|
|
@@ -1582,7 +1582,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- log_init(__progname, log_level, log_facility, log_stderr);
|
|
|
|
+ log_init_handler(__progname, log_level, log_facility, log_stderr, reset_handler);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On platforms where we can, avoid making /proc/self/{mem,maps}
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/sftp-server-main.c openssh-7.6p1-patched/sftp-server-main.c
|
|
|
|
--- openssh-7.6p1/sftp-server-main.c 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/sftp-server-main.c 2017-12-17 01:11:56.901272190 +1000
|
2016-09-30 05:06:40 -04:00
|
|
|
@@ -49,5 +49,5 @@
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- return (sftp_server_main(argc, argv, user_pw));
|
|
|
|
+ return (sftp_server_main(argc, argv, user_pw, 0));
|
|
|
|
}
|
2017-12-17 01:17:56 +10:00
|
|
|
diff -urN openssh-7.6p1/sshd.c openssh-7.6p1-patched/sshd.c
|
|
|
|
--- openssh-7.6p1/sshd.c 2017-10-03 05:34:26.000000000 +1000
|
|
|
|
+++ openssh-7.6p1-patched/sshd.c 2017-12-17 01:11:56.902272190 +1000
|
|
|
|
@@ -640,7 +640,7 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* New socket pair */
|
|
|
|
- monitor_reinit(pmonitor);
|
|
|
|
+ monitor_reinit(pmonitor, options.chroot_directory);
|
|
|
|
|
|
|
|
pmonitor->m_pid = fork();
|
|
|
|
if (pmonitor->m_pid == -1)
|
2017-12-17 01:17:56 +10:00
|
|
|
@@ -659,6 +659,11 @@
|
2016-09-30 05:06:40 -04:00
|
|
|
|
|
|
|
close(pmonitor->m_sendfd);
|
|
|
|
pmonitor->m_sendfd = -1;
|
|
|
|
+ close(pmonitor->m_log_recvfd);
|
|
|
|
+ pmonitor->m_log_recvfd = -1;
|
|
|
|
+
|
|
|
|
+ if (pmonitor->m_log_sendfd != -1)
|
|
|
|
+ set_log_handler(mm_log_handler, pmonitor);
|
|
|
|
|
|
|
|
/* Demote the private keys to public keys. */
|
|
|
|
demote_sensitive_data();
|