From 3cb278c35c8889a2738f4f70775ec7f8036e76a4 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev <ktokarev@smartlabs.tv> Date: Tue, 1 Dec 2015 21:55:34 +0300 Subject: [PATCH] Support syslog logging in dbclient. --- cli-main.c | 14 +++++++++++++- cli-runopts.c | 10 ++++++++++ cli-session.c | 5 +++++ dbclient.1 | 10 ++++++---- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/cli-main.c b/cli-main.c index dfb94fd7..9506759d 100644 --- a/cli-main.c +++ b/cli-main.c @@ -60,6 +60,12 @@ int main(int argc, char ** argv) { cli_getopts(argc, argv); +#ifndef DISABLE_SYSLOG + if (opts.usingsyslog) { + startsyslog("dbclient"); + } +#endif + TRACE(("user='%s' host='%s' port='%s'", cli_opts.username, cli_opts.remotehost, cli_opts.remoteport)) @@ -118,13 +124,19 @@ static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { exit(exitcode); } -static void cli_dropbear_log(int UNUSED(priority), +static void cli_dropbear_log(int priority, const char* format, va_list param) { char printbuf[1024]; vsnprintf(printbuf, sizeof(printbuf), format, param); +#ifndef DISABLE_SYSLOG + if (opts.usingsyslog) { + syslog(priority, "%s", printbuf); + } +#endif + fprintf(stderr, "%s: %s\n", cli_opts.progname, printbuf); fflush(stderr); } diff --git a/cli-runopts.c b/cli-runopts.c index 25a2f161..2ecf599a 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -863,6 +863,9 @@ static void add_extendedopt(const char* origstr) { dropbear_log(LOG_INFO, "Available options:\n" #ifdef ENABLE_CLI_ANYTCPFWD "\tExitOnForwardFailure\n" +#endif +#ifndef DISABLE_SYSLOG + "\tUseSyslog\n" #endif ); exit(EXIT_SUCCESS); @@ -875,5 +878,12 @@ static void add_extendedopt(const char* origstr) { } #endif +#ifndef DISABLE_SYSLOG + if (match_extendedopt(&optstr, "UseSyslog") == DROPBEAR_SUCCESS) { + opts.usingsyslog = parse_flag_value(optstr); + return; + } +#endif + dropbear_exit("Bad configuration option '%s'", origstr); } diff --git a/cli-session.c b/cli-session.c index 9be958e3..a93d1925 100644 --- a/cli-session.c +++ b/cli-session.c @@ -269,6 +269,11 @@ static void cli_sessionloop() { return; case USERAUTH_SUCCESS_RCVD: +#ifndef DISABLE_SYSLOG + if (opts.usingsyslog) { + dropbear_log(LOG_INFO, "Authentication succeeded."); + } +#endif #ifdef DROPBEAR_NONE_CIPHER if (cli_ses.cipher_none_after_auth) diff --git a/dbclient.1 b/dbclient.1 index cd6b5c7f..e521af6c 100644 --- a/dbclient.1 +++ b/dbclient.1 @@ -133,12 +133,14 @@ useful for specifying options for which there is no separate command-line flag. For full details of the options listed below, and their possible values, see ssh_config(5). -For now only following options have been implemented: -.RS +For now following options have been implemented: .RS .TP -ExitOnForwardFailure -.RE +.B ExitOnForwardFailure +Specifies whether dbclient should terminate the connection if it cannot set up all requested local and remote port forwardings. The argument must be “yes†or “noâ€. The default is “noâ€. +.TP +.B UseSyslog +Send dbclient log messages to syslog in addition to stderr. .RE .TP .B \-s -- GitLab