summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-10-18 13:21:59 +0200
committerDamien Miller <djm@mindrot.org>2020-10-18 13:34:20 +0200
commit9e2c4f64224f68fb84c49b5182e449f94b0dc985 (patch)
treeaa4a81152c6f6a3f06e466024680788f87069f56
parentupstream: remove a level of macro indirection; ok markus@ (diff)
downloadopenssh-9e2c4f64224f68fb84c49b5182e449f94b0dc985.tar.xz
openssh-9e2c4f64224f68fb84c49b5182e449f94b0dc985.zip
upstream: variants of the log methods that append a ssherr.h string
from a supplied error code; ok markus@ OpenBSD-Commit-ID: aed98c4435d48d036ae6740300f6a8357b7cc0bf
Diffstat (limited to '')
-rw-r--r--fatal.c6
-rw-r--r--log.c26
-rw-r--r--log.h74
-rw-r--r--monitor.c7
-rw-r--r--ssh-keyscan.c6
5 files changed, 80 insertions, 39 deletions
diff --git a/fatal.c b/fatal.c
index 40daa08b8..da5bf9069 100644
--- a/fatal.c
+++ b/fatal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fatal.c,v 1.9 2020/10/17 01:28:20 djm Exp $ */
+/* $OpenBSD: fatal.c,v 1.10 2020/10/18 11:21:59 djm Exp $ */
/*
* Copyright (c) 2002 Markus Friedl. All rights reserved.
*
@@ -35,12 +35,12 @@
void
sshfatal(const char *file, const char *func, int line, int showfunc,
- LogLevel level, const char *fmt, ...)
+ LogLevel level, const char *suffix, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- ssh_log(file, func, line, showfunc, level, fmt, args);
+ sshlog(file, func, line, showfunc, level, suffix, fmt, args);
va_end(args);
cleanup_exit(255);
}
diff --git a/log.c b/log.c
index 164a843d0..f57e75506 100644
--- a/log.c
+++ b/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.54 2020/10/17 01:28:20 djm Exp $ */
+/* $OpenBSD: log.c,v 1.55 2020/10/18 11:21:59 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -334,7 +334,7 @@ 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 *fmt, va_list args)
+ int force, const char *suffix, const char *fmt, va_list args)
{
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
struct syslog_data sdata = SYSLOG_DATA_INIT;
@@ -389,6 +389,10 @@ do_log(const char *file, const char *func, int line, LogLevel level,
} else {
vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
}
+ if (suffix != NULL) {
+ snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", msgbuf, suffix);
+ strlcpy(msgbuf, fmtbuf, sizeof(msgbuf));
+ }
strnvis(fmtbuf, msgbuf, sizeof(fmtbuf),
log_on_stderr ? LOG_STDERR_VIS : LOG_SYSLOG_VIS);
if (log_handler != NULL) {
@@ -417,42 +421,44 @@ do_log(const char *file, const char *func, int line, LogLevel level,
void
sshlog(const char *file, const char *func, int line, int showfunc,
- LogLevel level, const char *fmt, ...)
+ LogLevel level, const char *suffix, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- sshlogv(file, func, line, showfunc, level, fmt, args);
+ sshlogv(file, func, line, showfunc, level, suffix, fmt, args);
va_end(args);
}
void
sshlogdie(const char *file, const char *func, int line, int showfunc,
- LogLevel level, const char *fmt, ...)
+ LogLevel level, const char *suffix, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- sshlogv(file, func, line, showfunc, SYSLOG_LEVEL_INFO, fmt, args);
+ sshlogv(file, func, line, showfunc, SYSLOG_LEVEL_INFO,
+ suffix, fmt, args);
va_end(args);
cleanup_exit(255);
}
void
sshsigdie(const char *file, const char *func, int line, int showfunc,
- LogLevel level, const char *fmt, ...)
+ LogLevel level, const char *suffix, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- sshlogv(file, func, line, showfunc, SYSLOG_LEVEL_FATAL, fmt, args);
+ sshlogv(file, func, line, showfunc, SYSLOG_LEVEL_FATAL,
+ suffix, fmt, args);
va_end(args);
_exit(1);
}
void
sshlogv(const char *file, const char *func, int line, int showfunc,
- LogLevel level, const char *fmt, va_list args)
+ LogLevel level, const char *suffix, const char *fmt, va_list args)
{
char tag[128], fmt2[MSGBUFSIZ + 128];
int forced = 0;
@@ -475,5 +481,5 @@ sshlogv(const char *file, const char *func, int line, int showfunc,
else
strlcpy(fmt2, fmt, sizeof(fmt2));
- do_log(file, func, line, level, forced, fmt2, args);
+ do_log(file, func, line, level, forced, suffix, fmt2, args);
}
diff --git a/log.h b/log.h
index a8892f762..ee81ec568 100644
--- a/log.h
+++ b/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.28 2020/10/18 11:14:27 djm Exp $ */
+/* $OpenBSD: log.h,v 1.29 2020/10/18 11:21:59 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -16,6 +16,7 @@
#define SSH_LOG_H
#include <stdarg.h> /* va_list */
+#include <ssherr.h> /* ssh_err() */
/* Supported syslog facilities and levels. */
typedef enum {
@@ -68,28 +69,63 @@ void set_log_handler(log_handler_fn *, void *);
void cleanup_exit(int) __attribute__((noreturn));
void sshlog(const char *, const char *, int, int,
- LogLevel, const char *, ...) __attribute__((format(printf, 6, 7)));
+ LogLevel, const char *, const char *, ...)
+ __attribute__((format(printf, 7, 8)));
void sshlogv(const char *, const char *, int, int,
- LogLevel, const char *, va_list);
+ LogLevel, const char *, const char *, va_list);
void sshsigdie(const char *, const char *, int, int,
- LogLevel, const char *, ...) __attribute__((noreturn))
- __attribute__((format(printf, 6, 7)));
+ LogLevel, const char *, const char *, ...) __attribute__((noreturn))
+ __attribute__((format(printf, 7, 8)));
void sshlogdie(const char *, const char *, int, int,
- LogLevel, const char *, ...) __attribute__((noreturn))
- __attribute__((format(printf, 6, 7)));
+ LogLevel, const char *, const char *, ...) __attribute__((noreturn))
+ __attribute__((format(printf, 7, 8)));
void sshfatal(const char *, const char *, int, int,
- LogLevel, const char *, ...) __attribute__((noreturn))
- __attribute__((format(printf, 6, 7)));
+ LogLevel, const char *, const char *, ...) __attribute__((noreturn))
+ __attribute__((format(printf, 7, 8)));
-#define do_log2(level, ...) sshlog(__FILE__, __func__, __LINE__, 0, level, __VA_ARGS__)
-#define debug3(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG3, __VA_ARGS__)
-#define debug2(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG2, __VA_ARGS__)
-#define debug(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG1, __VA_ARGS__)
-#define verbose(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_VERBOSE, __VA_ARGS__)
-#define logit(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_INFO, __VA_ARGS__)
-#define error(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, __VA_ARGS__)
-#define fatal(...) sshfatal(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_FATAL, __VA_ARGS__)
-#define logdie(...) sshlogdie(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, __VA_ARGS__)
-#define sigdie(...) sshsigdie(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, __VA_ARGS__)
+#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__)
+#define debug2(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG2, NULL, __VA_ARGS__)
+#define debug(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG1, NULL, __VA_ARGS__)
+#define verbose(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_VERBOSE, NULL, __VA_ARGS__)
+#define logit(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_INFO, NULL, __VA_ARGS__)
+#define error(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, NULL, __VA_ARGS__)
+#define fatal(...) sshfatal(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_FATAL, NULL, __VA_ARGS__)
+#define logdie(...) sshlogdie(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, NULL, __VA_ARGS__)
+#define sigdie(...) sshsigdie(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, NULL, __VA_ARGS__)
+
+/* Variants that prepend the caller's function */
+#define do_log2_f(level, ...) sshlog(__FILE__, __func__, __LINE__, 1, level, NULL, __VA_ARGS__)
+#define debug3_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__)
+#define debug2_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG2, NULL, __VA_ARGS__)
+#define debug_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG1, NULL, __VA_ARGS__)
+#define verbose_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_VERBOSE, NULL, __VA_ARGS__)
+#define logit_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_INFO, NULL, __VA_ARGS__)
+#define error_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_ERROR, NULL, __VA_ARGS__)
+#define fatal_f(...) sshfatal(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_FATAL, NULL, __VA_ARGS__)
+#define logdie_f(...) sshlogdie(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_ERROR, NULL, __VA_ARGS__)
+#define sigdie_f(...) sshsigdie(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_ERROR, NULL, __VA_ARGS__)
+
+/* Variants that appends a ssh_err message */
+#define do_log2_r(r, level, ...) sshlog(__FILE__, __func__, __LINE__, 0, level, ssh_err(r), __VA_ARGS__)
+#define debug3_r(r, ...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG3, ssh_err(r), __VA_ARGS__)
+#define debug2_r(r, ...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG2, ssh_err(r), __VA_ARGS__)
+#define debug_r(r, ...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG1, ssh_err(r), __VA_ARGS__)
+#define verbose_r(r, ...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_VERBOSE, ssh_err(r), __VA_ARGS__)
+#define logit_r(r, ...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_INFO, ssh_err(r), __VA_ARGS__)
+#define error_r(r, ...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, ssh_err(r), __VA_ARGS__)
+#define fatal_r(r, ...) sshfatal(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_FATAL, ssh_err(r), __VA_ARGS__)
+#define logdie_r(r, ...) sshlogdie(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, ssh_err(r), __VA_ARGS__)
+#define sigdie_r(r, ...) sshsigdie(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_ERROR, ssh_err(r), __VA_ARGS__)
+#define do_log2_fr(r, level, ...) sshlog(__FILE__, __func__, __LINE__, 1, level, ssh_err(r), __VA_ARGS__)
+#define debug3_fr(r, ...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, ssh_err(r), __VA_ARGS__)
+#define debug2_fr(r, ...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG2, ssh_err(r), __VA_ARGS__)
+#define debug_fr(r, ...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG1, ssh_err(r), __VA_ARGS__)
+#define verbose_fr(r, ...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_VERBOSE, ssh_err(r), __VA_ARGS__)
+#define logit_fr(r, ...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_INFO, ssh_err(r), __VA_ARGS__)
+#define error_fr(r, ...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_ERROR, ssh_err(r), __VA_ARGS__)
+#define fatal_fr(r, ...) sshfatal(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_FATAL, ssh_err(r), __VA_ARGS__)
+#define logdie_fr(r, ...) sshlogdie(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_ERROR, ssh_err(r), __VA_ARGS__)
+#define sigdie_fr(r, ...) sshsigdie(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_ERROR, ssh_err(r), __VA_ARGS__)
#endif
diff --git a/monitor.c b/monitor.c
index 9f22f0681..c4e07ba4d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor.c,v 1.215 2020/10/16 13:24:45 djm Exp $ */
+/* $OpenBSD: monitor.c,v 1.216 2020/10/18 11:21:59 djm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -461,9 +461,8 @@ monitor_read_log(struct monitor *pmonitor)
/* Log it */
if (log_level_name(level) == NULL)
- fatal("%s: invalid log level %u (corrupted message?)",
- __func__, level);
- sshlog(file, func, line, 0, level, "%s [preauth]", msg);
+ fatal_f("invalid log level %u (corrupted message?)", level);
+ sshlog(file, func, line, 0, level, NULL, "%s [preauth]", msg);
sshbuf_free(logmsg);
free(file);
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index 118165595..034ed48c7 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.134 2020/10/17 01:28:20 djm Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.135 2020/10/18 11:21:59 djm Exp $ */
/*
* Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
*
@@ -636,12 +636,12 @@ do_host(char *host)
void
sshfatal(const char *file, const char *func, int line, int showfunc,
- LogLevel level, const char *fmt, ...)
+ LogLevel level, const char *suffix, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- ssh_log(file, func, line, showfunc, level, fmt, args);
+ sshlog(file, func, line, showfunc, level, suffix, fmt, args);
va_end(args);
cleanup_exit(255);
}