Skip to content

Commit

Permalink
username logging fix (#762)
Browse files Browse the repository at this point in the history
* initial pass at including username from sftp

* initialize user to unknown

* update tests

* fix spacing

* fix test take 2
  • Loading branch information
tgauth authored Nov 21, 2024
1 parent 27f6cfa commit 0dd6d2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,14 @@ monitor_read_log(struct monitor *pmonitor)

/*log it*/
if (authctxt->authenticated == 0)
sshlogdirect(level, forced, "%s [preauth]", msg);
sshlogdirect(level, forced, "user: %s: %s [preauth]", authctxt->user, msg);
else {
if (strcmp(pname, "sftp-server") == 0) {
log_init(pname, sftp_log_level, sftp_log_facility, sftp_log_stderr);
sshlogdirect(level, forced, "%s", msg);
sshlogdirect(level, forced, "user: %s: %s", authctxt->user, msg);
log_init("sshd", options.log_level, options.log_facility, log_stderr);
} else
sshlogdirect(level, forced, "%s", msg);
sshlogdirect(level, forced, "user: %s: %s", authctxt->user, msg);
}
#else
/*log it*/
Expand Down
8 changes: 4 additions & 4 deletions regress/pesterTests/FileBasedLogging.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ exit"

$sshdlog | Should Contain "Accepted publickey for $nonadminusername"
$sshdlog | Should Contain "KEX done \[preauth\]"
$sshdlog | Should Contain "debug2: subsystem request for sftp by user $nonadminusername"
$sshdlog | Should Contain "debug2: user: $nonadminusername`: subsystem request for sftp by user $nonadminusername"
$sftplog | Should Contain "session opened for local user $nonadminusername"
$sftplog | Should Contain "debug3: request 3: opendir"
$sftplog | Should Contain "debug3: user: $nonadminusername`: request 3: opendir"
$sftplog | Should Contain "session closed for local user $nonadminusername"
}

Expand All @@ -216,9 +216,9 @@ exit"

$sshdlog | Should Contain "Accepted publickey for $adminusername"
$sshdlog | Should Contain "KEX done \[preauth\]"
$sshdlog | Should Contain "debug2: subsystem request for sftp by user $adminusername"
$sshdlog | Should Contain "debug2: user: $adminusername`: subsystem request for sftp by user $adminusername"
$sftplog | Should Contain "session opened for local user $adminusername"
$sftplog | Should Contain "debug3: request 3: opendir"
$sftplog | Should Contain "debug3: user: $adminusername`: request 3: opendir"
$sftplog | Should Contain "session closed for local user $adminusername"
}
}
Expand Down

0 comments on commit 0dd6d2c

Please sign in to comment.