Mercurial > dropbear
comparison cli-session.c @ 1745:a6824c54962a
Merge fuzz branch
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 18 Oct 2020 22:53:44 +0800 |
parents | 6e71440b1e47 |
children | 1fc0012b9c38 |
comparison
equal
deleted
inserted
replaced
1738:4f13df974cf4 | 1745:a6824c54962a |
---|---|
350 /* Ignore return value since there's nothing we can do */ | 350 /* Ignore return value since there's nothing we can do */ |
351 (void)fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags); | 351 (void)fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags); |
352 (void)fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags); | 352 (void)fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags); |
353 (void)fcntl(cli_ses.stderrcopy, F_SETFL, cli_ses.stderrflags); | 353 (void)fcntl(cli_ses.stderrcopy, F_SETFL, cli_ses.stderrflags); |
354 | 354 |
355 /* Don't leak */ | |
356 m_close(cli_ses.stdincopy); | |
357 m_close(cli_ses.stdoutcopy); | |
358 m_close(cli_ses.stderrcopy); | |
359 | |
355 cli_tty_cleanup(); | 360 cli_tty_cleanup(); |
356 if (cli_ses.server_sig_algs) { | 361 if (cli_ses.server_sig_algs) { |
357 buf_free(cli_ses.server_sig_algs); | 362 buf_free(cli_ses.server_sig_algs); |
358 } | 363 } |
359 } | 364 } |
405 static void recv_msg_global_request_cli(void) { | 410 static void recv_msg_global_request_cli(void) { |
406 TRACE(("recv_msg_global_request_cli")) | 411 TRACE(("recv_msg_global_request_cli")) |
407 /* Send a proper rejection */ | 412 /* Send a proper rejection */ |
408 send_msg_request_failure(); | 413 send_msg_request_failure(); |
409 } | 414 } |
415 | |
416 void cli_dropbear_exit(int exitcode, const char* format, va_list param) { | |
417 char exitmsg[150]; | |
418 char fullmsg[300]; | |
419 | |
420 /* Note that exit message must be rendered before session cleanup */ | |
421 | |
422 /* Render the formatted exit message */ | |
423 vsnprintf(exitmsg, sizeof(exitmsg), format, param); | |
424 TRACE(("Exited, cleaning up: %s", exitmsg)) | |
425 | |
426 /* Add the prefix depending on session/auth state */ | |
427 if (!ses.init_done) { | |
428 snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg); | |
429 } else { | |
430 snprintf(fullmsg, sizeof(fullmsg), | |
431 "Connection to %s@%s:%s exited: %s", | |
432 cli_opts.username, cli_opts.remotehost, | |
433 cli_opts.remoteport, exitmsg); | |
434 } | |
435 | |
436 /* Do the cleanup first, since then the terminal will be reset */ | |
437 session_cleanup(); | |
438 | |
439 #if DROPBEAR_FUZZ | |
440 if (fuzz.do_jmp) { | |
441 longjmp(fuzz.jmp, 1); | |
442 } | |
443 #endif | |
444 | |
445 /* Avoid printing onwards from terminal cruft */ | |
446 fprintf(stderr, "\n"); | |
447 | |
448 dropbear_log(LOG_INFO, "%s", fullmsg); | |
449 | |
450 exit(exitcode); | |
451 } | |
452 | |
453 void cli_dropbear_log(int priority, const char* format, va_list param) { | |
454 | |
455 char printbuf[1024]; | |
456 const char *name; | |
457 | |
458 name = cli_opts.progname; | |
459 if (!name) { | |
460 name = "dbclient"; | |
461 } | |
462 | |
463 vsnprintf(printbuf, sizeof(printbuf), format, param); | |
464 | |
465 #ifndef DISABLE_SYSLOG | |
466 if (opts.usingsyslog) { | |
467 syslog(priority, "%s", printbuf); | |
468 } | |
469 #endif | |
470 | |
471 fprintf(stderr, "%s: %s\n", name, printbuf); | |
472 fflush(stderr); | |
473 } | |
474 |