From: markus Date: Thu, 15 Apr 2021 16:24:31 +0000 (+0000) Subject: do not pass file/func to monitor; noted by Ilja van Sprundel; ok djm@ X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=31d2fcf0bc94adc782bafe40b1e0dbbb3c2aeb84;p=openbsd do not pass file/func to monitor; noted by Ilja van Sprundel; ok djm@ --- diff --git a/usr.bin/ssh/log.c b/usr.bin/ssh/log.c index bb80f17df9b..0f3f151e396 100644 --- a/usr.bin/ssh/log.c +++ b/usr.bin/ssh/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.57 2021/04/03 06:18:40 djm Exp $ */ +/* $OpenBSD: log.c,v 1.58 2021/04/15 16:24:31 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -301,8 +301,8 @@ set_log_handler(log_handler_fn *handler, void *ctx) } static void -do_log(const char *file, const char *func, int line, LogLevel level, - int force, const char *suffix, const char *fmt, va_list args) +do_log(LogLevel level, int force, const char *suffix, const char *fmt, + va_list args) { struct syslog_data sdata = SYSLOG_DATA_INIT; char msgbuf[MSGBUFSIZ]; @@ -364,7 +364,7 @@ do_log(const char *file, const char *func, int line, LogLevel level, /* Avoid recursion */ tmp_handler = log_handler; log_handler = NULL; - tmp_handler(file, func, line, level, fmtbuf, log_handler_ctx); + tmp_handler(level, force, fmtbuf, log_handler_ctx); log_handler = tmp_handler; } else if (log_on_stderr) { snprintf(msgbuf, sizeof msgbuf, "%.*s\r\n", @@ -433,12 +433,22 @@ sshlogv(const char *file, const char *func, int line, int showfunc, } } - if (log_handler == NULL && forced) + if (forced) snprintf(fmt2, sizeof(fmt2), "%s: %s", tag, fmt); else if (showfunc) snprintf(fmt2, sizeof(fmt2), "%s: %s", func, fmt); else strlcpy(fmt2, fmt, sizeof(fmt2)); - do_log(file, func, line, level, forced, suffix, fmt2, args); + do_log(level, forced, suffix, fmt2, args); +} + +void +sshlogdirect(LogLevel level, int forced, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + do_log(level, forced, NULL, fmt, args); + va_end(args); } diff --git a/usr.bin/ssh/log.h b/usr.bin/ssh/log.h index 7d84e388472..6221f57f55b 100644 --- a/usr.bin/ssh/log.h +++ b/usr.bin/ssh/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.32 2021/04/06 23:24:30 djm Exp $ */ +/* $OpenBSD: log.h,v 1.33 2021/04/15 16:24:31 markus Exp $ */ /* * Author: Tatu Ylonen @@ -46,8 +46,7 @@ typedef enum { SYSLOG_LEVEL_NOT_SET = -1 } LogLevel; -typedef void (log_handler_fn)(const char *, const char *, int, LogLevel, - const char *, void *); +typedef void (log_handler_fn)(LogLevel, int, const char *, void *); void log_init(const char *, LogLevel, SyslogFacility, int); LogLevel log_level_get(void); @@ -79,6 +78,8 @@ void sshlogdie(const char *, const char *, int, int, void sshfatal(const char *, const char *, int, int, LogLevel, const char *, const char *, ...) __attribute__((noreturn)) __attribute__((format(printf, 7, 8))); +void sshlogdirect(LogLevel, int, const char *, ...) + __attribute__((format(printf, 3, 4))); #define do_log2(level, ...) sshlog(__FILE__, __func__, __LINE__, 0, level, NULL, __VA_ARGS__) #define debug3(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__) diff --git a/usr.bin/ssh/monitor.c b/usr.bin/ssh/monitor.c index b8fb848e578..14361912378 100644 --- a/usr.bin/ssh/monitor.c +++ b/usr.bin/ssh/monitor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor.c,v 1.224 2021/03/03 22:41:49 djm Exp $ */ +/* $OpenBSD: monitor.c,v 1.225 2021/04/15 16:24:31 markus Exp $ */ /* * Copyright 2002 Niels Provos * Copyright 2002 Markus Friedl @@ -351,8 +351,8 @@ static int monitor_read_log(struct monitor *pmonitor) { struct sshbuf *logmsg; - u_int len, level, line; - char *msg, *file, *func; + u_int len, level, forced; + char *msg; u_char *p; int r; @@ -383,21 +383,17 @@ monitor_read_log(struct monitor *pmonitor) fatal_fr(r, "reserve msg"); if (atomicio(read, pmonitor->m_log_recvfd, p, len) != len) fatal_f("log fd read: %s", strerror(errno)); - if ((r = sshbuf_get_cstring(logmsg, &file, NULL)) != 0 || - (r = sshbuf_get_cstring(logmsg, &func, NULL)) != 0 || - (r = sshbuf_get_u32(logmsg, &line)) != 0 || - (r = sshbuf_get_u32(logmsg, &level)) != 0 || + if ((r = sshbuf_get_u32(logmsg, &level)) != 0 || + (r = sshbuf_get_u32(logmsg, &forced)) != 0 || (r = sshbuf_get_cstring(logmsg, &msg, NULL)) != 0) fatal_fr(r, "parse"); /* Log it */ if (log_level_name(level) == NULL) fatal_f("invalid log level %u (corrupted message?)", level); - sshlog(file, func, line, 0, level, NULL, "%s [preauth]", msg); + sshlogdirect(level, forced, "%s [preauth]", msg); sshbuf_free(logmsg); - free(file); - free(func); free(msg); return 0; diff --git a/usr.bin/ssh/monitor_wrap.c b/usr.bin/ssh/monitor_wrap.c index 890925005f1..3a7145aa6f4 100644 --- a/usr.bin/ssh/monitor_wrap.c +++ b/usr.bin/ssh/monitor_wrap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor_wrap.c,v 1.122 2020/11/27 00:37:10 djm Exp $ */ +/* $OpenBSD: monitor_wrap.c,v 1.123 2021/04/15 16:24:31 markus Exp $ */ /* * Copyright 2002 Niels Provos * Copyright 2002 Markus Friedl @@ -78,8 +78,7 @@ extern struct sshbuf *loginmsg; extern ServerOptions options; void -mm_log_handler(const char *file, const char *func, int line, - LogLevel level, const char *msg, void *ctx) +mm_log_handler(LogLevel level, int forced, const char *msg, void *ctx) { struct sshbuf *log_msg; struct monitor *mon = (struct monitor *)ctx; @@ -93,10 +92,8 @@ mm_log_handler(const char *file, const char *func, int line, fatal_f("sshbuf_new failed"); if ((r = sshbuf_put_u32(log_msg, 0)) != 0 || /* length; filled below */ - (r = sshbuf_put_cstring(log_msg, file)) != 0 || - (r = sshbuf_put_cstring(log_msg, func)) != 0 || - (r = sshbuf_put_u32(log_msg, (u_int)line)) != 0 || (r = sshbuf_put_u32(log_msg, level)) != 0 || + (r = sshbuf_put_u32(log_msg, forced)) != 0 || (r = sshbuf_put_cstring(log_msg, msg)) != 0) fatal_fr(r, "assemble"); if ((len = sshbuf_len(log_msg)) < 4 || len > 0xffffffff) diff --git a/usr.bin/ssh/monitor_wrap.h b/usr.bin/ssh/monitor_wrap.h index bbb6f978914..e4bf0fa3116 100644 --- a/usr.bin/ssh/monitor_wrap.h +++ b/usr.bin/ssh/monitor_wrap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor_wrap.h,v 1.46 2020/10/16 13:24:45 djm Exp $ */ +/* $OpenBSD: monitor_wrap.h,v 1.47 2021/04/15 16:24:31 markus Exp $ */ /* * Copyright 2002 Niels Provos @@ -40,8 +40,7 @@ struct sshkey; struct sshauthopt; struct sshkey_sig_details; -void mm_log_handler(const char *, const char *, int, LogLevel, - const char *, void *); +void mm_log_handler(LogLevel, int, const char *, void *); int mm_is_monitor(void); #ifdef WITH_OPENSSL DH *mm_choose_dh(int, int, int);