mirror of
https://github.com/clearml/dropbear
synced 2025-03-03 10:41:39 +00:00
Improve exit message formatting
This commit is contained in:
parent
4f5d0756c2
commit
8fd720c3e3
21
cli-main.c
21
cli-main.c
@ -98,29 +98,30 @@ int main(int argc, char ** argv) {
|
|||||||
#endif /* DBMULTI stuff */
|
#endif /* DBMULTI stuff */
|
||||||
|
|
||||||
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
|
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
|
||||||
|
char exitmsg[150];
|
||||||
|
char fullmsg[300];
|
||||||
|
|
||||||
char fmtbuf[300];
|
/* Note that exit message must be rendered before session cleanup */
|
||||||
char exitmsg[500];
|
|
||||||
|
|
||||||
|
/* Render the formatted exit message */
|
||||||
|
vsnprintf(exitmsg, sizeof(exitmsg), format, param);
|
||||||
|
|
||||||
|
/* Add the prefix depending on session/auth state */
|
||||||
if (!sessinitdone) {
|
if (!sessinitdone) {
|
||||||
snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s",
|
snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg);
|
||||||
format);
|
|
||||||
} else {
|
} else {
|
||||||
snprintf(fmtbuf, sizeof(fmtbuf),
|
snprintf(fullmsg, sizeof(fullmsg),
|
||||||
"Connection to %s@%s:%s exited: %s",
|
"Connection to %s@%s:%s exited: %s",
|
||||||
cli_opts.username, cli_opts.remotehost,
|
cli_opts.username, cli_opts.remotehost,
|
||||||
cli_opts.remoteport, format);
|
cli_opts.remoteport, exitmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Arguments to the exit printout may be unsafe to use after session_cleanup() */
|
|
||||||
vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param);
|
|
||||||
|
|
||||||
/* Do the cleanup first, since then the terminal will be reset */
|
/* Do the cleanup first, since then the terminal will be reset */
|
||||||
session_cleanup();
|
session_cleanup();
|
||||||
/* Avoid printing onwards from terminal cruft */
|
/* Avoid printing onwards from terminal cruft */
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
dropbear_log(LOG_INFO, "%s", exitmsg);;
|
dropbear_log(LOG_INFO, "%s", fullmsg);
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,31 +144,33 @@ void svr_session(int sock, int childpipe) {
|
|||||||
|
|
||||||
/* failure exit - format must be <= 100 chars */
|
/* failure exit - format must be <= 100 chars */
|
||||||
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 fmtbuf[300];
|
char fullmsg[300];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* Render the formatted exit message */
|
||||||
|
vsnprintf(exitmsg, sizeof(exitmsg), format, param);
|
||||||
|
|
||||||
|
/* Add the prefix depending on session/auth state */
|
||||||
if (!sessinitdone) {
|
if (!sessinitdone) {
|
||||||
/* before session init */
|
/* before session init */
|
||||||
snprintf(fmtbuf, sizeof(fmtbuf),
|
snprintf(fullmsg, sizeof(fullmsg), "Early exit: %s", exitmsg);
|
||||||
"Early exit: %s", format);
|
|
||||||
} else if (ses.authstate.authdone) {
|
} else if (ses.authstate.authdone) {
|
||||||
/* user has authenticated */
|
/* user has authenticated */
|
||||||
snprintf(fmtbuf, sizeof(fmtbuf),
|
snprintf(fullmsg, sizeof(fullmsg),
|
||||||
"Exit (%s): %s",
|
"Exit (%s): %s",
|
||||||
ses.authstate.pw_name, format);
|
ses.authstate.pw_name, exitmsg);
|
||||||
} else if (ses.authstate.pw_name) {
|
} else if (ses.authstate.pw_name) {
|
||||||
/* we have a potential user */
|
/* we have a potential user */
|
||||||
snprintf(fmtbuf, sizeof(fmtbuf),
|
snprintf(fullmsg, sizeof(fullmsg),
|
||||||
"Exit before auth (user '%s', %u fails): %s",
|
"Exit before auth (user '%s', %u fails): %s",
|
||||||
ses.authstate.pw_name, ses.authstate.failcount, format);
|
ses.authstate.pw_name, ses.authstate.failcount, exitmsg);
|
||||||
} else {
|
} else {
|
||||||
/* before userauth */
|
/* before userauth */
|
||||||
snprintf(fmtbuf, sizeof(fmtbuf),
|
snprintf(fullmsg, sizeof(fullmsg), "Exit before auth: %s", exitmsg);
|
||||||
"Exit before auth: %s", format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dropbear_log(LOG_INFO, fmtbuf, param);
|
dropbear_log(LOG_INFO, "%s", fullmsg);
|
||||||
|
|
||||||
#ifdef USE_VFORK
|
#ifdef USE_VFORK
|
||||||
/* For uclinux only the main server process should cleanup - we don't want
|
/* For uclinux only the main server process should cleanup - we don't want
|
||||||
|
Loading…
Reference in New Issue
Block a user