Mercurial > dropbear
comparison svr-session.c @ 1304:b66a483f3dcb
Improve exit message formatting
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 11 Jul 2016 23:09:33 +0800 |
parents | 9169e4e7cbee |
children | 2c9dac2d6707 b28624698130 |
comparison
equal
deleted
inserted
replaced
1303:eed9376a4ad6 | 1304:b66a483f3dcb |
---|---|
142 | 142 |
143 } | 143 } |
144 | 144 |
145 /* failure exit - format must be <= 100 chars */ | 145 /* failure exit - format must be <= 100 chars */ |
146 void svr_dropbear_exit(int exitcode, const char* format, va_list param) { | 146 void svr_dropbear_exit(int exitcode, const char* format, va_list param) { |
147 | 147 char exitmsg[150]; |
148 char fmtbuf[300]; | 148 char fullmsg[300]; |
149 int i; | 149 int i; |
150 | 150 |
151 /* Render the formatted exit message */ | |
152 vsnprintf(exitmsg, sizeof(exitmsg), format, param); | |
153 | |
154 /* Add the prefix depending on session/auth state */ | |
151 if (!sessinitdone) { | 155 if (!sessinitdone) { |
152 /* before session init */ | 156 /* before session init */ |
153 snprintf(fmtbuf, sizeof(fmtbuf), | 157 snprintf(fullmsg, sizeof(fullmsg), "Early exit: %s", exitmsg); |
154 "Early exit: %s", format); | |
155 } else if (ses.authstate.authdone) { | 158 } else if (ses.authstate.authdone) { |
156 /* user has authenticated */ | 159 /* user has authenticated */ |
157 snprintf(fmtbuf, sizeof(fmtbuf), | 160 snprintf(fullmsg, sizeof(fullmsg), |
158 "Exit (%s): %s", | 161 "Exit (%s): %s", |
159 ses.authstate.pw_name, format); | 162 ses.authstate.pw_name, exitmsg); |
160 } else if (ses.authstate.pw_name) { | 163 } else if (ses.authstate.pw_name) { |
161 /* we have a potential user */ | 164 /* we have a potential user */ |
162 snprintf(fmtbuf, sizeof(fmtbuf), | 165 snprintf(fullmsg, sizeof(fullmsg), |
163 "Exit before auth (user '%s', %u fails): %s", | 166 "Exit before auth (user '%s', %u fails): %s", |
164 ses.authstate.pw_name, ses.authstate.failcount, format); | 167 ses.authstate.pw_name, ses.authstate.failcount, exitmsg); |
165 } else { | 168 } else { |
166 /* before userauth */ | 169 /* before userauth */ |
167 snprintf(fmtbuf, sizeof(fmtbuf), | 170 snprintf(fullmsg, sizeof(fullmsg), "Exit before auth: %s", exitmsg); |
168 "Exit before auth: %s", format); | 171 } |
169 } | 172 |
170 | 173 dropbear_log(LOG_INFO, "%s", fullmsg); |
171 _dropbear_log(LOG_INFO, fmtbuf, param); | |
172 | 174 |
173 #ifdef USE_VFORK | 175 #ifdef USE_VFORK |
174 /* For uclinux only the main server process should cleanup - we don't want | 176 /* For uclinux only the main server process should cleanup - we don't want |
175 * forked children doing that */ | 177 * forked children doing that */ |
176 if (svr_ses.server_pid == getpid()) | 178 if (svr_ses.server_pid == getpid()) |