# HG changeset patch # User Matt Johnston # Date 1450187751 -28800 # Node ID 61d3f56808a49f7f33d020326a4b226c04610686 # Parent ab7d9c12caa78d03a42e26ad9ecd36a6f680e7a3# Parent 7fd1211a1f63f4741472357729eb7773e39b4b8a Merge pull request #18 from annulen/dbclient_syslog Support syslog logging in dbclient. diff -r ab7d9c12caa7 -r 61d3f56808a4 cli-kex.c --- a/cli-kex.c Tue Dec 15 21:40:32 2015 +0800 +++ b/cli-kex.c Tue Dec 15 21:55:51 2015 +0800 @@ -190,7 +190,7 @@ fp = sign_key_fingerprint(keyblob, keybloblen); if (cli_opts.always_accept_key) { - fprintf(stderr, "\nHost '%s' key accepted unconditionally.\n(%s fingerprint %s)\n", + dropbear_log(LOG_INFO, "\nHost '%s' key accepted unconditionally.\n(%s fingerprint %s)\n", cli_opts.remotehost, algoname, fp); @@ -290,7 +290,7 @@ int ret; if (cli_opts.no_hostkey_check) { - fprintf(stderr, "Caution, skipping hostkey check for %s\n", cli_opts.remotehost); + dropbear_log(LOG_INFO, "Caution, skipping hostkey check for %s\n", cli_opts.remotehost); return; } diff -r ab7d9c12caa7 -r 61d3f56808a4 cli-main.c --- a/cli-main.c Tue Dec 15 21:40:32 2015 +0800 +++ b/cli-main.c Tue Dec 15 21:55:51 2015 +0800 @@ -60,6 +60,12 @@ 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 @@ 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 -r ab7d9c12caa7 -r 61d3f56808a4 cli-runopts.c --- a/cli-runopts.c Tue Dec 15 21:40:32 2015 +0800 +++ b/cli-runopts.c Tue Dec 15 21:55:51 2015 +0800 @@ -173,6 +173,9 @@ opts.cipher_list = NULL; opts.mac_list = NULL; #endif +#ifndef DISABLE_SYSLOG + opts.usingsyslog = 0; +#endif /* not yet opts.ipv4 = 1; opts.ipv6 = 1; @@ -488,7 +491,7 @@ keytype = DROPBEAR_SIGNKEY_ANY; if ( readhostkey(filename, key, &keytype) != DROPBEAR_SUCCESS ) { if (warnfail) { - fprintf(stderr, "Failed loading keyfile '%s'\n", filename); + dropbear_log(LOG_WARNING, "Failed loading keyfile '%s'\n", filename); } sign_key_free(key); } else { @@ -861,6 +864,9 @@ #ifdef ENABLE_CLI_ANYTCPFWD "\tExitOnForwardFailure\n" #endif +#ifndef DISABLE_SYSLOG + "\tUseSyslog\n" +#endif ); exit(EXIT_SUCCESS); } @@ -872,5 +878,12 @@ } #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 -r ab7d9c12caa7 -r 61d3f56808a4 cli-session.c --- a/cli-session.c Tue Dec 15 21:40:32 2015 +0800 +++ b/cli-session.c Tue Dec 15 21:55:51 2015 +0800 @@ -269,6 +269,11 @@ 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 -r ab7d9c12caa7 -r 61d3f56808a4 dbclient.1 --- a/dbclient.1 Tue Dec 15 21:40:32 2015 +0800 +++ b/dbclient.1 Tue Dec 15 21:55:51 2015 +0800 @@ -133,12 +133,14 @@ 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 diff -r ab7d9c12caa7 -r 61d3f56808a4 dbutil.c --- a/dbutil.c Tue Dec 15 21:40:32 2015 +0800 +++ b/dbutil.c Tue Dec 15 21:55:51 2015 +0800 @@ -84,9 +84,9 @@ #endif #ifndef DISABLE_SYSLOG -void startsyslog() { +void startsyslog(const char *ident) { - openlog(PROGNAME, LOG_PID, LOG_AUTHPRIV); + openlog(ident, LOG_PID, LOG_AUTHPRIV); } #endif /* DISABLE_SYSLOG */ diff -r ab7d9c12caa7 -r 61d3f56808a4 dbutil.h --- a/dbutil.h Tue Dec 15 21:40:32 2015 +0800 +++ b/dbutil.h Tue Dec 15 21:55:51 2015 +0800 @@ -31,7 +31,7 @@ #include "queue.h" #ifndef DISABLE_SYSLOG -void startsyslog(); +void startsyslog(const char *ident); #endif #ifdef __GNUC__ diff -r ab7d9c12caa7 -r 61d3f56808a4 runopts.h --- a/runopts.h Tue Dec 15 21:40:32 2015 +0800 +++ b/runopts.h Tue Dec 15 21:55:51 2015 +0800 @@ -40,6 +40,7 @@ unsigned int recv_window; time_t keepalive_secs; /* Time between sending keepalives. 0 is off */ time_t idle_timeout_secs; /* Exit if no traffic is sent/received in this time */ + int usingsyslog; #ifndef DISABLE_ZLIB /* TODO: add a commandline flag. Currently this is on by default if compression @@ -70,7 +71,6 @@ char * bannerfile; int forkbg; - int usingsyslog; /* ports and addresses are arrays of the portcount listening ports. strings are malloced. */ diff -r ab7d9c12caa7 -r 61d3f56808a4 svr-main.c --- a/svr-main.c Tue Dec 15 21:40:32 2015 +0800 +++ b/svr-main.c Tue Dec 15 21:55:51 2015 +0800 @@ -145,7 +145,7 @@ if (svr_opts.forkbg) { int closefds = 0; #ifndef DEBUG_TRACE - if (!svr_opts.usingsyslog) { + if (!opts.usingsyslog) { closefds = 1; } #endif @@ -367,8 +367,8 @@ struct sigaction sa_chld; #ifndef DISABLE_SYSLOG - if (svr_opts.usingsyslog) { - startsyslog(); + if (opts.usingsyslog) { + startsyslog(PROGNAME); } #endif diff -r ab7d9c12caa7 -r 61d3f56808a4 svr-runopts.c --- a/svr-runopts.c Tue Dec 15 21:40:32 2015 +0800 +++ b/svr-runopts.c Tue Dec 15 21:55:51 2015 +0800 @@ -158,7 +158,7 @@ svr_opts.domotd = 1; #endif #ifndef DISABLE_SYSLOG - svr_opts.usingsyslog = 1; + opts.usingsyslog = 1; #endif opts.recv_window = DEFAULT_RECV_WINDOW; opts.keepalive_secs = DEFAULT_KEEPALIVE; @@ -189,7 +189,7 @@ break; #ifndef DISABLE_SYSLOG case 'E': - svr_opts.usingsyslog = 0; + opts.usingsyslog = 0; break; #endif #ifdef ENABLE_SVR_LOCALTCPFWD diff -r ab7d9c12caa7 -r 61d3f56808a4 svr-session.c --- a/svr-session.c Tue Dec 15 21:40:32 2015 +0800 +++ b/svr-session.c Tue Dec 15 21:55:51 2015 +0800 @@ -204,7 +204,7 @@ vsnprintf(printbuf, sizeof(printbuf), format, param); #ifndef DISABLE_SYSLOG - if (svr_opts.usingsyslog) { + if (opts.usingsyslog) { syslog(priority, "%s", printbuf); } #endif @@ -215,7 +215,7 @@ havetrace = debug_trace; #endif - if (!svr_opts.usingsyslog || havetrace) + if (!opts.usingsyslog || havetrace) { struct tm * local_tm = NULL; timesec = time(NULL);