summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2020-10-18 11:22:00 +0000
committerDamien Miller <djm@cvs.openbsd.org>2020-10-18 11:22:00 +0000
commit76ac85c3c0818c9e092206a0e616a35f30f07885 (patch)
treef127713f7a5c3dd0918fa2739f6400bdcebcaffb
parent20c45c431db010b6e914d1e4f0ba02c22e4b390c (diff)
variants of the log methods that append a ssherr.h string from
a supplied error code; ok markus@
-rw-r--r--usr.bin/ssh/fatal.c6
-rw-r--r--usr.bin/ssh/log.c26
-rw-r--r--usr.bin/ssh/log.h74
-rw-r--r--usr.bin/ssh/monitor.c7
-rw-r--r--usr.bin/ssh/ssh-keyscan.c6
5 files changed, 80 insertions, 39 deletions
diff --git a/usr.bin/ssh/fatal.c b/usr.bin/ssh/fatal.c
index fe290b44150..996dbdb171c 100644
--- a/usr.bin/ssh/fatal.c
+++ b/usr.bin/ssh/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.
*
@@ -33,12 +33,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/usr.bin/ssh/log.c b/usr.bin/ssh/log.c
index 6c01d79abb4..b33d4a6a952 100644
--- a/usr.bin/ssh/log.c
+++ b/usr.bin/ssh/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
@@ -301,7 +301,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)
{
struct syslog_data sdata = SYSLOG_DATA_INIT;
char msgbuf[MSGBUFSIZ];
@@ -354,6 +354,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), VIS_SAFE|VIS_OCTAL);
if (log_handler != NULL) {
/* Avoid recursion */
@@ -375,42 +379,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;
@@ -433,5 +439,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/usr.bin/ssh/log.h b/usr.bin/ssh/log.h
index 042dcfeb4c0..0f029f18507 100644
--- a/usr.bin/ssh/log.h
+++ b/usr.bin/ssh/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 {
@@ -65,28 +66,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/usr.bin/ssh/monitor.c b/usr.bin/ssh/monitor.c
index 85125f3ff60..a298834fcf0 100644
--- a/usr.bin/ssh/monitor.c
+++ b/usr.bin/ssh/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>
@@ -395,9 +395,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/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c
index 4c3a202b5df..dd5d2344ab7 100644
--- a/usr.bin/ssh/ssh-keyscan.c
+++ b/usr.bin/ssh/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>.
*
@@ -618,12 +618,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);
}