comparison svr-session.c @ 1666:c148e7afa0d1

Handle early exit when addrstring isn't set
author Matt Johnston <matt@ucc.asn.au>
date Wed, 18 Mar 2020 23:37:45 +0800
parents 7c17995bcdfb
children d5cdc60db08e
comparison
equal deleted inserted replaced
1665:7c17995bcdfb 1666:c148e7afa0d1
205 205
206 /* failure exit - format must be <= 100 chars */ 206 /* failure exit - format must be <= 100 chars */
207 void svr_dropbear_exit(int exitcode, const char* format, va_list param) { 207 void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
208 char exitmsg[150]; 208 char exitmsg[150];
209 char fullmsg[300]; 209 char fullmsg[300];
210 char fromaddr[60];
210 int i; 211 int i;
211 212
212 #if DROPBEAR_PLUGIN 213 #if DROPBEAR_PLUGIN
213 if ((ses.plugin_session != NULL)) { 214 if ((ses.plugin_session != NULL)) {
214 svr_ses.plugin_instance->delete_session(ses.plugin_session); 215 svr_ses.plugin_instance->delete_session(ses.plugin_session);
217 #endif 218 #endif
218 219
219 /* Render the formatted exit message */ 220 /* Render the formatted exit message */
220 vsnprintf(exitmsg, sizeof(exitmsg), format, param); 221 vsnprintf(exitmsg, sizeof(exitmsg), format, param);
221 222
223 /* svr_ses.addrstring may not be set for some early exits, or for
224 the listener process */
225 fromaddr[0] = '\0';
226 if (svr_ses.addrstring) {
227 snprintf(fromaddr, sizeof(fromaddr), " from <%s>", svr_ses.addrstring);
228 }
229
222 /* Add the prefix depending on session/auth state */ 230 /* Add the prefix depending on session/auth state */
223 if (!ses.init_done) { 231 if (!ses.init_done) {
224 /* before session init */ 232 /* before session init */
225 snprintf(fullmsg, sizeof(fullmsg), "Early exit from <%s> %s", svr_ses.addrstring, exitmsg); 233 snprintf(fullmsg, sizeof(fullmsg), "Early exit%s: %s", fromaddr, exitmsg);
226 } else if (ses.authstate.authdone) { 234 } else if (ses.authstate.authdone) {
227 /* user has authenticated */ 235 /* user has authenticated */
228 snprintf(fullmsg, sizeof(fullmsg), 236 snprintf(fullmsg, sizeof(fullmsg),
229 "Exit (%s): %s", 237 "Exit (%s)%s: %s",
230 ses.authstate.pw_name, exitmsg); 238 ses.authstate.pw_name, fromaddr, exitmsg);
231 } else if (ses.authstate.pw_name) { 239 } else if (ses.authstate.pw_name) {
232 /* we have a potential user */ 240 /* we have a potential user */
233 snprintf(fullmsg, sizeof(fullmsg), 241 snprintf(fullmsg, sizeof(fullmsg),
234 "Exit before auth from <%s> (user '%s', %u fails): %s", 242 "Exit before auth%s: (user '%s', %u fails): %s",
235 svr_ses.addrstring, ses.authstate.pw_name, ses.authstate.failcount, exitmsg); 243 fromaddr, ses.authstate.pw_name, ses.authstate.failcount, exitmsg);
236 } else { 244 } else {
237 /* before userauth */ 245 /* before userauth */
238 snprintf(fullmsg, sizeof(fullmsg), "Exit before auth from <%s> %s", svr_ses.addrstring, exitmsg); 246 snprintf(fullmsg, sizeof(fullmsg), "Exit before auth%s: %s", fromaddr, exitmsg);
239 } 247 }
240 248
241 dropbear_log(LOG_INFO, "%s", fullmsg); 249 dropbear_log(LOG_INFO, "%s", fullmsg);
242 250
243 #if DROPBEAR_VFORK 251 #if DROPBEAR_VFORK