aboutsummaryrefslogtreecommitdiff
path: root/networking/telnetd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-04-06 17:43:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-04-06 17:43:29 +0200
commitf6916dbed4233ef0e202d1b299cb5a2e9287a696 (patch)
treea761598c5f3d6e935239d8631e7f984c4cd490d6 /networking/telnetd.c
parentfcad7681f8a835f5c7b2093da505f46865a89d25 (diff)
downloadbusybox-w32-f6916dbed4233ef0e202d1b299cb5a2e9287a696.tar.gz
busybox-w32-f6916dbed4233ef0e202d1b299cb5a2e9287a696.tar.bz2
busybox-w32-f6916dbed4233ef0e202d1b299cb5a2e9287a696.zip
telnetd: fill hostname field in utmp/wtmp records
function old new delta get_lsa - 109 +109 make_new_session 438 504 +66 get_peer_lsa - 10 +10 ftpd_main 2340 2267 -73 get_sock_lsa 101 10 -91 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 1/2 up/down: 185/-164) Total: 21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/telnetd.c')
-rw-r--r--networking/telnetd.c21
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);