diff options
Diffstat (limited to 'networking/telnetd.c')
-rw-r--r-- | networking/telnetd.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c index b3e66eb4b..a8c86b62f 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -226,6 +226,9 @@ make_new_session( | |||
226 | IF_FEATURE_TELNETD_STANDALONE(int sock) | 226 | IF_FEATURE_TELNETD_STANDALONE(int sock) |
227 | IF_NOT_FEATURE_TELNETD_STANDALONE(void) | 227 | IF_NOT_FEATURE_TELNETD_STANDALONE(void) |
228 | ) { | 228 | ) { |
229 | #if !ENABLE_FEATURE_TELNETD_STANDALONE | ||
230 | enum { sock = 0 ); | ||
231 | #endif | ||
229 | const char *login_argv[2]; | 232 | const char *login_argv[2]; |
230 | struct termios termbuf; | 233 | struct termios termbuf; |
231 | int fd, pid; | 234 | int fd, pid; |
@@ -243,9 +246,9 @@ make_new_session( | |||
243 | ndelay_on(fd); | 246 | ndelay_on(fd); |
244 | close_on_exec_on(fd); | 247 | close_on_exec_on(fd); |
245 | 248 | ||
246 | #if ENABLE_FEATURE_TELNETD_STANDALONE | ||
247 | /* SO_KEEPALIVE by popular demand */ | 249 | /* SO_KEEPALIVE by popular demand */ |
248 | setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); | 250 | setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); |
251 | #if ENABLE_FEATURE_TELNETD_STANDALONE | ||
249 | ts->sockfd_read = sock; | 252 | ts->sockfd_read = sock; |
250 | ndelay_on(sock); | 253 | ndelay_on(sock); |
251 | if (sock == 0) { /* We are called with fd 0 - we are in inetd mode */ | 254 | if (sock == 0) { /* We are called with fd 0 - we are in inetd mode */ |
@@ -256,8 +259,6 @@ make_new_session( | |||
256 | if (sock > G.maxfd) | 259 | if (sock > G.maxfd) |
257 | G.maxfd = sock; | 260 | G.maxfd = sock; |
258 | #else | 261 | #else |
259 | /* SO_KEEPALIVE by popular demand */ | ||
260 | setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); | ||
261 | /* ts->sockfd_read = 0; - done by xzalloc */ | 262 | /* ts->sockfd_read = 0; - done by xzalloc */ |
262 | ts->sockfd_write = 1; | 263 | ts->sockfd_write = 1; |
263 | ndelay_on(0); | 264 | ndelay_on(0); |
@@ -313,6 +314,17 @@ make_new_session( | |||
313 | /* Restore default signal handling ASAP */ | 314 | /* Restore default signal handling ASAP */ |
314 | bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL); | 315 | bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL); |
315 | 316 | ||
317 | if (ENABLE_FEATURE_UTMP) { | ||
318 | len_and_sockaddr *lsa = get_peer_lsa(sock); | ||
319 | char *hostname = NULL; | ||
320 | if (lsa) { | ||
321 | hostname = xmalloc_sockaddr2dotted(&lsa->u.sa); | ||
322 | free(lsa); | ||
323 | } | ||
324 | write_new_utmp(pid, LOGIN_PROCESS, tty_name, /*username:*/ "LOGIN", hostname); | ||
325 | free(hostname); | ||
326 | } | ||
327 | |||
316 | /* Make new session and process group */ | 328 | /* Make new session and process group */ |
317 | setsid(); | 329 | setsid(); |
318 | 330 | ||
@@ -326,9 +338,6 @@ make_new_session( | |||
326 | pid = getpid(); | 338 | pid = getpid(); |
327 | tcsetpgrp(0, pid); /* switch this tty's process group to us */ | 339 | tcsetpgrp(0, pid); /* switch this tty's process group to us */ |
328 | 340 | ||
329 | //TODO: fetch remote addr via getpeername (see ftpd.c) | ||
330 | write_new_utmp(pid, LOGIN_PROCESS, tty_name, /*username:*/ "LOGIN", /*hostname:*/ NULL); | ||
331 | |||
332 | /* The pseudo-terminal allocated to the client is configured to operate | 341 | /* The pseudo-terminal allocated to the client is configured to operate |
333 | * in cooked mode, and with XTABS CRMOD enabled (see tty(4)) */ | 342 | * in cooked mode, and with XTABS CRMOD enabled (see tty(4)) */ |
334 | tcgetattr(0, &termbuf); | 343 | tcgetattr(0, &termbuf); |