[PATCH] Enable ssh_config to set LogPath option (-E)

bryon bryon at fryer.io
Thu Apr 25 11:32:20 AEST 2024


ssh client has the ability to set the destination of debug logs via the `-E` flag.  ssh_config lacks an equivalent keyword to set the same option via configs.

This patch follows the same semantics of other `*Path` type keywords and creates a new ssh_config keyword `LogPath`.

[0] Bugzilla: https://bugzilla.mindrot.org/show_bug.cgi?id=3683
[1] GitHub PR: https://github.com/openssh/openssh-portable/pull/491

---
readconf.c |  8 +++++++-
readconf.h |  1 +
ssh.c      | 12 ++++++------
3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/readconf.c b/readconf.c
index 3a64a0441..d7e301e78 100644
--- a/readconf.c
+++ b/readconf.c
@@ -156,7 +156,7 @@ typedef enum {
        oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
        oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
        oTCPKeepAlive, oNumberOfPasswordPrompts,
-       oLogFacility, oLogLevel, oLogVerbose, oCiphers, oMacs,
+       oLogFacility, oLogLevel, oLogPath, oLogVerbose, oCiphers, oMacs,
        oPubkeyAuthentication,
        oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
        oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
@@ -271,6 +271,7 @@ static struct {
        { "numberofpasswordprompts", oNumberOfPasswordPrompts },
        { "syslogfacility", oLogFacility },
        { "loglevel", oLogLevel },
+       { "logpath", oLogPath },
        { "logverbose", oLogVerbose },
        { "dynamicforward", oDynamicForward },
        { "preferredauthentications", oPreferredAuthentications },
@@ -1629,6 +1630,10 @@ parse_pubkey_algos:
                }
                break;
 
+       case oLogPath:
+               charptr = &options->log_path;
+               goto parse_string;
+
        case oLocalForward:
        case oRemoteForward:
        case oDynamicForward:
@@ -2585,6 +2590,7 @@ initialize_options(Options * options)
        options->num_permitted_remote_opens = 0;
        options->log_facility = SYSLOG_FACILITY_NOT_SET;
        options->log_level = SYSLOG_LEVEL_NOT_SET;
+       options->log_path = NULL;
        options->num_log_verbose = 0;
        options->log_verbose = NULL;
        options->preferred_authentications = NULL;
diff --git a/readconf.h b/readconf.h
index 9447d5d6e..0137b6690 100644
--- a/readconf.h
+++ b/readconf.h
@@ -54,6 +54,7 @@ typedef struct {
        int     ip_qos_bulk;            /* IP ToS/DSCP/class for bulk traffic */
        SyslogFacility log_facility;    /* Facility for system logging. */
        LogLevel log_level;     /* Level for logging. */
+       char   *log_path;       /* Path for debug logs. */
        u_int   num_log_verbose;        /* Verbose log overrides */
        char   **log_verbose;
        int     port;           /* Port to connect. */
diff --git a/ssh.c b/ssh.c
index 0019281f4..f38c96f7d 100644
--- a/ssh.c
+++ b/ssh.c
@@ -670,7 +670,7 @@ main(int ac, char **av)
        struct ssh *ssh = NULL;
        int i, r, opt, exit_status, use_syslog, direct, timeout_ms;
        int was_addr, config_test = 0, opt_terminated = 0, want_final_pass = 0;
-       char *p, *cp, *line, *argv0, *logfile;
+       char *p, *cp, *line, *argv0;
        char cname[NI_MAXHOST], thishost[NI_MAXHOST];
        struct stat st;
        struct passwd *pw;
@@ -741,7 +741,6 @@ main(int ac, char **av)
        /* Parse command-line arguments. */
        host = NULL;
        use_syslog = 0;
-       logfile = NULL;
        argv0 = av[0];
 
  again:
@@ -777,7 +776,8 @@ main(int ac, char **av)
                        use_syslog = 1;
                        break;
                case 'E':
-                       logfile = optarg;
+                       free(options.log_path);
+                       options.log_path = xstrdup(optarg);
                        break;
                case 'G':
                        config_test = 1;
@@ -1190,10 +1190,10 @@ main(int ac, char **av)
         * Initialize "log" output.  Since we are the client all output
         * goes to stderr unless otherwise specified by -y or -E.
         */
-       if (use_syslog && logfile != NULL)
+       if (use_syslog && options.log_path != NULL)
                fatal("Can't specify both -y and -E");
-       if (logfile != NULL)
-               log_redirect_stderr_to(logfile);
+       if (options.log_path != NULL)
+               log_redirect_stderr_to(options.log_path);
        log_init(argv0,
            options.log_level == SYSLOG_LEVEL_NOT_SET ?
            SYSLOG_LEVEL_INFO : options.log_level,
-- 
2.39.2


More information about the openssh-unix-dev mailing list