comparison cli-main.c @ 1069:2fa71c3b2827 pam

merge pam branch up to date
author Matt Johnston <matt@ucc.asn.au>
date Mon, 16 Mar 2015 21:34:05 +0800
parents 23103e1e9548
children fb58cf341951
comparison
equal deleted inserted replaced
1068:9a6395ddb1b6 1069:2fa71c3b2827
28 #include "dbutil.h" 28 #include "dbutil.h"
29 #include "runopts.h" 29 #include "runopts.h"
30 #include "session.h" 30 #include "session.h"
31 #include "dbrandom.h" 31 #include "dbrandom.h"
32 #include "crypto_desc.h" 32 #include "crypto_desc.h"
33 #include "netio.h"
33 34
34 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) ATTRIB_NORETURN; 35 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
35 static void cli_dropbear_log(int priority, const char* format, va_list param); 36 static void cli_dropbear_log(int priority, const char* format, va_list param);
36 37
37 #ifdef ENABLE_CLI_PROXYCMD 38 #ifdef ENABLE_CLI_PROXYCMD
44 #else 45 #else
45 int main(int argc, char ** argv) { 46 int main(int argc, char ** argv) {
46 #endif 47 #endif
47 48
48 int sock_in, sock_out; 49 int sock_in, sock_out;
49 char* error = NULL; 50 struct dropbear_progress_connection *progress = NULL;
50 51
51 _dropbear_exit = cli_dropbear_exit; 52 _dropbear_exit = cli_dropbear_exit;
52 _dropbear_log = cli_dropbear_log; 53 _dropbear_log = cli_dropbear_log;
53 54
54 disallow_core(); 55 disallow_core();
70 cli_proxy_cmd(&sock_in, &sock_out); 71 cli_proxy_cmd(&sock_in, &sock_out);
71 m_free(cli_opts.proxycmd); 72 m_free(cli_opts.proxycmd);
72 } else 73 } else
73 #endif 74 #endif
74 { 75 {
75 int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, 76 progress = connect_remote(cli_opts.remotehost, cli_opts.remoteport, cli_connected, &ses);
76 0, &error); 77 sock_in = sock_out = -1;
77 sock_in = sock_out = sock;
78 } 78 }
79 79
80 if (sock_in < 0) { 80 cli_session(sock_in, sock_out, progress);
81 dropbear_exit("%s", error);
82 }
83
84 cli_session(sock_in, sock_out);
85 81
86 /* not reached */ 82 /* not reached */
87 return -1; 83 return -1;
88 } 84 }
89 #endif /* DBMULTI stuff */ 85 #endif /* DBMULTI stuff */
90 86
91 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { 87 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
92 88
93 char fmtbuf[300]; 89 char fmtbuf[300];
90 char exitmsg[500];
94 91
95 if (!sessinitdone) { 92 if (!sessinitdone) {
96 snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", 93 snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s",
97 format); 94 format);
98 } else { 95 } else {
100 "Connection to %s@%s:%s exited: %s", 97 "Connection to %s@%s:%s exited: %s",
101 cli_opts.username, cli_opts.remotehost, 98 cli_opts.username, cli_opts.remotehost,
102 cli_opts.remoteport, format); 99 cli_opts.remoteport, format);
103 } 100 }
104 101
102 /* Arguments to the exit printout may be unsafe to use after session_cleanup() */
103 vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param);
104
105 /* Do the cleanup first, since then the terminal will be reset */ 105 /* Do the cleanup first, since then the terminal will be reset */
106 session_cleanup(); 106 session_cleanup();
107 /* Avoid printing onwards from terminal cruft */ 107 /* Avoid printing onwards from terminal cruft */
108 fprintf(stderr, "\n"); 108 fprintf(stderr, "\n");
109 109
110 _dropbear_log(LOG_INFO, fmtbuf, param); 110 dropbear_log(LOG_INFO, "%s", exitmsg);;
111 exit(exitcode); 111 exit(exitcode);
112 } 112 }
113 113
114 static void cli_dropbear_log(int UNUSED(priority), 114 static void cli_dropbear_log(int UNUSED(priority),
115 const char* format, va_list param) { 115 const char* format, va_list param) {