aboutsummaryrefslogtreecommitdiff
path: root/networking/telnetd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-22 00:47:18 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-22 00:47:18 +0200
commitfbb12ddc6a53ad97ff6bcc7ed9b253c09001ad2f (patch)
tree94c82f9eac30c86a1ec4f4d06f6c17b72b47cf3e /networking/telnetd.c
parentb6bca7703bbe6aacec0bda964c82fad389a02b69 (diff)
downloadbusybox-w32-1_14_2.tar.gz
busybox-w32-1_14_2.tar.bz2
busybox-w32-1_14_2.zip
post 1.14.1 fixes; bump version to 1.14.21_14_2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/telnetd.c')
-rw-r--r--networking/telnetd.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c
index ccf328925..4c5ea3ab3 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -199,9 +199,17 @@ static size_t iac_safe_write(int fd, const char *buf, size_t count)
199 return total + rc; 199 return total + rc;
200} 200}
201 201
202/* Must match getopt32 string */
203enum {
204 OPT_WATCHCHILD = (1 << 2), /* -K */
205 OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
206 OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
207 OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
208};
209
202static struct tsession * 210static struct tsession *
203make_new_session( 211make_new_session(
204 USE_FEATURE_TELNETD_STANDALONE(int sock) 212 USE_FEATURE_TELNETD_STANDALONE(int master_fd, int sock)
205 SKIP_FEATURE_TELNETD_STANDALONE(void) 213 SKIP_FEATURE_TELNETD_STANDALONE(void)
206) { 214) {
207 const char *login_argv[2]; 215 const char *login_argv[2];
@@ -288,9 +296,29 @@ make_new_session(
288 /* Restore default signal handling ASAP */ 296 /* Restore default signal handling ASAP */
289 bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL); 297 bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
290 298
299#if ENABLE_FEATURE_TELNETD_STANDALONE
300 if (!(option_mask32 & OPT_INETD)) {
301 struct tsession *tp = sessions;
302 while (tp) {
303 close(tp->ptyfd);
304 close(tp->sockfd_read);
305 /* sockfd_write == sockfd_read for standalone telnetd */
306 /*close(tp->sockfd_write);*/
307 tp = tp->next;
308 }
309 }
310#endif
311
291 /* Make new session and process group */ 312 /* Make new session and process group */
292 setsid(); 313 setsid();
293 314
315 close(fd);
316#if ENABLE_FEATURE_TELNETD_STANDALONE
317 close(sock);
318 if (master_fd >= 0)
319 close(master_fd);
320#endif
321
294 /* Open the child's side of the tty. */ 322 /* Open the child's side of the tty. */
295 /* NB: setsid() disconnects from any previous ctty's. Therefore 323 /* NB: setsid() disconnects from any previous ctty's. Therefore
296 * we must open child's side of the tty AFTER setsid! */ 324 * we must open child's side of the tty AFTER setsid! */
@@ -329,14 +357,6 @@ make_new_session(
329 _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", loginpath);*/ 357 _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", loginpath);*/
330} 358}
331 359
332/* Must match getopt32 string */
333enum {
334 OPT_WATCHCHILD = (1 << 2), /* -K */
335 OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
336 OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
337 OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
338};
339
340#if ENABLE_FEATURE_TELNETD_STANDALONE 360#if ENABLE_FEATURE_TELNETD_STANDALONE
341 361
342static void 362static void
@@ -465,7 +485,7 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv)
465 485
466#if ENABLE_FEATURE_TELNETD_STANDALONE 486#if ENABLE_FEATURE_TELNETD_STANDALONE
467 if (IS_INETD) { 487 if (IS_INETD) {
468 sessions = make_new_session(0); 488 sessions = make_new_session(-1, 0);
469 if (!sessions) /* pty opening or vfork problem, exit */ 489 if (!sessions) /* pty opening or vfork problem, exit */
470 return 1; /* make_new_session prints error message */ 490 return 1; /* make_new_session prints error message */
471 } else { 491 } else {
@@ -553,7 +573,7 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv)
553 if (fd < 0) 573 if (fd < 0)
554 goto again; 574 goto again;
555 /* Create a new session and link it into our active list */ 575 /* Create a new session and link it into our active list */
556 new_ts = make_new_session(fd); 576 new_ts = make_new_session(master_fd, fd);
557 if (new_ts) { 577 if (new_ts) {
558 new_ts->next = sessions; 578 new_ts->next = sessions;
559 sessions = new_ts; 579 sessions = new_ts;