Handle early exit when addrstring isn't set

This commit is contained in:
Matt Johnston 2020-03-18 23:37:45 +08:00
parent fa4c4646d8
commit 201e359363

View File

@ -207,6 +207,7 @@ void svr_session(int sock, int childpipe) {
void svr_dropbear_exit(int exitcode, const char* format, va_list param) { void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
char exitmsg[150]; char exitmsg[150];
char fullmsg[300]; char fullmsg[300];
char fromaddr[60];
int i; int i;
#if DROPBEAR_PLUGIN #if DROPBEAR_PLUGIN
@ -219,23 +220,30 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
/* Render the formatted exit message */ /* Render the formatted exit message */
vsnprintf(exitmsg, sizeof(exitmsg), format, param); vsnprintf(exitmsg, sizeof(exitmsg), format, param);
/* svr_ses.addrstring may not be set for some early exits, or for
the listener process */
fromaddr[0] = '\0';
if (svr_ses.addrstring) {
snprintf(fromaddr, sizeof(fromaddr), " from <%s>", svr_ses.addrstring);
}
/* Add the prefix depending on session/auth state */ /* Add the prefix depending on session/auth state */
if (!ses.init_done) { if (!ses.init_done) {
/* before session init */ /* before session init */
snprintf(fullmsg, sizeof(fullmsg), "Early exit from <%s> %s", svr_ses.addrstring, exitmsg); snprintf(fullmsg, sizeof(fullmsg), "Early exit%s: %s", fromaddr, exitmsg);
} else if (ses.authstate.authdone) { } else if (ses.authstate.authdone) {
/* user has authenticated */ /* user has authenticated */
snprintf(fullmsg, sizeof(fullmsg), snprintf(fullmsg, sizeof(fullmsg),
"Exit (%s): %s", "Exit (%s)%s: %s",
ses.authstate.pw_name, exitmsg); ses.authstate.pw_name, fromaddr, exitmsg);
} else if (ses.authstate.pw_name) { } else if (ses.authstate.pw_name) {
/* we have a potential user */ /* we have a potential user */
snprintf(fullmsg, sizeof(fullmsg), snprintf(fullmsg, sizeof(fullmsg),
"Exit before auth from <%s> (user '%s', %u fails): %s", "Exit before auth%s: (user '%s', %u fails): %s",
svr_ses.addrstring, ses.authstate.pw_name, ses.authstate.failcount, exitmsg); fromaddr, ses.authstate.pw_name, ses.authstate.failcount, exitmsg);
} else { } else {
/* before userauth */ /* before userauth */
snprintf(fullmsg, sizeof(fullmsg), "Exit before auth from <%s> %s", svr_ses.addrstring, exitmsg); snprintf(fullmsg, sizeof(fullmsg), "Exit before auth%s: %s", fromaddr, exitmsg);
} }
dropbear_log(LOG_INFO, "%s", fullmsg); dropbear_log(LOG_INFO, "%s", fullmsg);