aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-06-30 21:13:06 +0100
committerRon Yorston <rmy@pobox.com>2014-06-30 21:13:06 +0100
commit099e8b6438345baae560a629d548af07a8c3125c (patch)
tree71b5600b22b0019af675e4a991394ce32c8207c5 /networking
parente19594cc6e49e78fa50a654f15cf9a04e77d054a (diff)
parent184b2669175e562d58894e22f6320cebf3316c25 (diff)
downloadbusybox-w32-099e8b6438345baae560a629d548af07a8c3125c.tar.gz
busybox-w32-099e8b6438345baae560a629d548af07a8c3125c.tar.bz2
busybox-w32-099e8b6438345baae560a629d548af07a8c3125c.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpd.c77
-rw-r--r--networking/libiproute/iproute.c2
-rw-r--r--networking/route.c2
-rw-r--r--networking/udhcp/Config.src11
-rw-r--r--networking/udhcp/dhcpc.c4
5 files changed, 56 insertions, 40 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c
index 33db964fa..2d2a3a44c 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -623,13 +623,7 @@ popen_ls(const char *opt)
623 623
624 argv[0] = "ftpd"; 624 argv[0] = "ftpd";
625 argv[1] = opt; /* "-l" or "-1" */ 625 argv[1] = opt; /* "-l" or "-1" */
626#if BB_MMU
627 argv[2] = "--"; 626 argv[2] = "--";
628#else
629 /* NOMMU ftpd ls helper chdirs to argv[2],
630 * preventing peer from seeing real root. */
631 argv[2] = xrealloc_getcwd_or_warn(NULL);
632#endif
633 argv[3] = G.ftp_arg; 627 argv[3] = G.ftp_arg;
634 argv[4] = NULL; 628 argv[4] = NULL;
635 629
@@ -650,17 +644,10 @@ popen_ls(const char *opt)
650 /*fflush_all(); - so far we dont use stdio on output */ 644 /*fflush_all(); - so far we dont use stdio on output */
651 pid = BB_MMU ? xfork() : xvfork(); 645 pid = BB_MMU ? xfork() : xvfork();
652 if (pid == 0) { 646 if (pid == 0) {
653 /* child */
654#if !BB_MMU 647#if !BB_MMU
655 /* On NOMMU, we want to execute a child - copy of ourself. 648 int cur_fd;
656 * In chroot we usually can't do it. Thus we chdir
657 * out of the chroot back to original root,
658 * and (see later below) execute bb_busybox_exec_path
659 * relative to current directory */
660 if (fchdir(G.root_fd) != 0)
661 _exit(127);
662 /*close(G.root_fd); - close_on_exec_on() took care of this */
663#endif 649#endif
650 /* child */
664 /* NB: close _first_, then move fd! */ 651 /* NB: close _first_, then move fd! */
665 close(outfd.rd); 652 close(outfd.rd);
666 xmove_fd(outfd.wr, STDOUT_FILENO); 653 xmove_fd(outfd.wr, STDOUT_FILENO);
@@ -674,19 +661,26 @@ popen_ls(const char *opt)
674 /* memset(&G, 0, sizeof(G)); - ls_main does it */ 661 /* memset(&G, 0, sizeof(G)); - ls_main does it */
675 exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv)); 662 exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv));
676#else 663#else
677 /* + 1: we must use relative path here if in chroot. 664 cur_fd = xopen(".", O_RDONLY | O_DIRECTORY);
678 * For example, execv("/proc/self/exe") will fail, since 665 /* On NOMMU, we want to execute a child - copy of ourself
679 * it looks for "/proc/self/exe" _relative to chroot!_ */ 666 * in order to unblock parent after vfork.
680 execv(bb_busybox_exec_path + 1, (char**) argv); 667 * In chroot we usually can't re-exec. Thus we escape
668 * out of the chroot back to original root.
669 */
670 if (G.root_fd >= 0) {
671 if (fchdir(G.root_fd) != 0 || chroot(".") != 0)
672 _exit(127);
673 /*close(G.root_fd); - close_on_exec_on() took care of this */
674 }
675 /* Child expects directory to list on fd #3 */
676 xmove_fd(cur_fd, 3);
677 execv(bb_busybox_exec_path, (char**) argv);
681 _exit(127); 678 _exit(127);
682#endif 679#endif
683 } 680 }
684 681
685 /* parent */ 682 /* parent */
686 close(outfd.wr); 683 close(outfd.wr);
687#if !BB_MMU
688 free((char*)argv[2]);
689#endif
690 return outfd.rd; 684 return outfd.rd;
691} 685}
692 686
@@ -705,10 +699,9 @@ handle_dir_common(int opts)
705 if (!(opts & USE_CTRL_CONN) && !port_or_pasv_was_seen()) 699 if (!(opts & USE_CTRL_CONN) && !port_or_pasv_was_seen())
706 return; /* port_or_pasv_was_seen emitted error response */ 700 return; /* port_or_pasv_was_seen emitted error response */
707 701
708 /* -n prevents user/groupname display,
709 * which can be problematic in chroot */
710 ls_fd = popen_ls((opts & LONG_LISTING) ? "-l" : "-1"); 702 ls_fd = popen_ls((opts & LONG_LISTING) ? "-l" : "-1");
711 ls_fp = xfdopen_for_read(ls_fd); 703 ls_fp = xfdopen_for_read(ls_fd);
704/* FIXME: filenames with embedded newlines are mishandled */
712 705
713 if (opts & USE_CTRL_CONN) { 706 if (opts & USE_CTRL_CONN) {
714 /* STAT <filename> */ 707 /* STAT <filename> */
@@ -729,16 +722,20 @@ handle_dir_common(int opts)
729 int remote_fd = get_remote_transfer_fd(" Directory listing"); 722 int remote_fd = get_remote_transfer_fd(" Directory listing");
730 if (remote_fd >= 0) { 723 if (remote_fd >= 0) {
731 while (1) { 724 while (1) {
732 line = xmalloc_fgetline(ls_fp); 725 unsigned len;
726
727 line = xmalloc_fgets(ls_fp);
733 if (!line) 728 if (!line)
734 break; 729 break;
735 /* I've seen clients complaining when they 730 /* I've seen clients complaining when they
736 * are fed with ls output with bare '\n'. 731 * are fed with ls output with bare '\n'.
737 * Pity... that would be much simpler. 732 * Replace trailing "\n\0" with "\r\n".
738 */ 733 */
739/* TODO: need to s/LF/NUL/g here */ 734 len = strlen(line);
740 xwrite_str(remote_fd, line); 735 if (len != 0) /* paranoia check */
741 xwrite(remote_fd, "\r\n", 2); 736 line[len - 1] = '\r';
737 line[len] = '\n';
738 xwrite(remote_fd, line, len + 1);
742 free(line); 739 free(line);
743 } 740 }
744 } 741 }
@@ -1085,6 +1082,8 @@ enum {
1085 const_PASV = mk_const4('P', 'A', 'S', 'V'), 1082 const_PASV = mk_const4('P', 'A', 'S', 'V'),
1086 const_PORT = mk_const4('P', 'O', 'R', 'T'), 1083 const_PORT = mk_const4('P', 'O', 'R', 'T'),
1087 const_PWD = mk_const3('P', 'W', 'D'), 1084 const_PWD = mk_const3('P', 'W', 'D'),
1085 /* Same as PWD. Reportedly used by windows ftp client */
1086 const_XPWD = mk_const4('X', 'P', 'W', 'D'),
1088 const_QUIT = mk_const4('Q', 'U', 'I', 'T'), 1087 const_QUIT = mk_const4('Q', 'U', 'I', 'T'),
1089 const_REST = mk_const4('R', 'E', 'S', 'T'), 1088 const_REST = mk_const4('R', 'E', 'S', 'T'),
1090 const_RETR = mk_const4('R', 'E', 'T', 'R'), 1089 const_RETR = mk_const4('R', 'E', 'T', 'R'),
@@ -1132,11 +1131,10 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1132 opts = getopt32(argv, "l1vS" IF_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); 1131 opts = getopt32(argv, "l1vS" IF_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
1133 if (opts & (OPT_l|OPT_1)) { 1132 if (opts & (OPT_l|OPT_1)) {
1134 /* Our secret backdoor to ls */ 1133 /* Our secret backdoor to ls */
1135/* TODO: pass -n? It prevents user/group resolution, which may not work in chroot anyway */
1136/* TODO: pass -A? It shows dot files */ 1134/* TODO: pass -A? It shows dot files */
1137/* TODO: pass --group-directories-first? would be nice, but ls doesn't do that yet */ 1135/* TODO: pass --group-directories-first? would be nice, but ls doesn't do that yet */
1138 xchdir(argv[2]); 1136 if (fchdir(3) != 0)
1139 argv[2] = (char*)"--"; 1137 _exit(127);
1140 /* memset(&G, 0, sizeof(G)); - ls_main does it */ 1138 /* memset(&G, 0, sizeof(G)); - ls_main does it */
1141 return ls_main(argc, argv); 1139 return ls_main(argc, argv);
1142 } 1140 }
@@ -1175,12 +1173,15 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1175 applet_name = xasprintf("%s[%u]", applet_name, (int)getpid()); 1173 applet_name = xasprintf("%s[%u]", applet_name, (int)getpid());
1176 1174
1177#if !BB_MMU 1175#if !BB_MMU
1178 G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY); 1176 G.root_fd = -1;
1179 close_on_exec_on(G.root_fd);
1180#endif 1177#endif
1181 1178 argv += optind;
1182 if (argv[optind]) { 1179 if (argv[0]) {
1183 xchroot(argv[optind]); 1180#if !BB_MMU
1181 G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY);
1182 close_on_exec_on(G.root_fd);
1183#endif
1184 xchroot(argv[0]);
1184 } 1185 }
1185 1186
1186 //umask(077); - admin can set umask before starting us 1187 //umask(077); - admin can set umask before starting us
@@ -1292,7 +1293,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1292 WRITE_OK(FTP_ALLOOK); 1293 WRITE_OK(FTP_ALLOOK);
1293 else if (cmdval == const_SYST) 1294 else if (cmdval == const_SYST)
1294 cmdio_write_raw(STR(FTP_SYSTOK)" UNIX Type: L8\r\n"); 1295 cmdio_write_raw(STR(FTP_SYSTOK)" UNIX Type: L8\r\n");
1295 else if (cmdval == const_PWD) 1296 else if (cmdval == const_PWD || cmdval == const_XPWD)
1296 handle_pwd(); 1297 handle_pwd();
1297 else if (cmdval == const_CWD) 1298 else if (cmdval == const_CWD)
1298 handle_cwd(); 1299 handle_cwd();
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index f8a67d9ee..ec4d8ba03 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -73,7 +73,7 @@ static unsigned get_hz(void)
73 fclose(fp); 73 fclose(fp);
74 } 74 }
75 if (!hz_internal) 75 if (!hz_internal)
76 hz_internal = sysconf(_SC_CLK_TCK); 76 hz_internal = bb_clk_tck();
77 return hz_internal; 77 return hz_internal;
78} 78}
79 79
diff --git a/networking/route.c b/networking/route.c
index 4235ea72c..24cc2eb5a 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -283,7 +283,7 @@ static NOINLINE void INET_setroute(int action, char **args)
283 if (k == KW_IPVx_IRTT) { 283 if (k == KW_IPVx_IRTT) {
284 rt->rt_flags |= RTF_IRTT; 284 rt->rt_flags |= RTF_IRTT;
285 rt->rt_irtt = xatoul(args_m1); 285 rt->rt_irtt = xatoul(args_m1);
286 rt->rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ 286 rt->rt_irtt *= (bb_clk_tck() / 100); /* FIXME */
287#if 0 /* FIXME: do we need to check anything of this? */ 287#if 0 /* FIXME: do we need to check anything of this? */
288 if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) { 288 if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) {
289 bb_error_msg_and_die("bad irtt"); 289 bb_error_msg_and_die("bad irtt");
diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src
index 6bfa398ea..c34c8d6f0 100644
--- a/networking/udhcp/Config.src
+++ b/networking/udhcp/Config.src
@@ -84,6 +84,17 @@ config FEATURE_UDHCPC_ARPING
84 will DHCPDECLINE the offer if the address is in use, 84 will DHCPDECLINE the offer if the address is in use,
85 and restart the discover process. 85 and restart the discover process.
86 86
87config FEATURE_UDHCPC_SANITIZEOPT
88 bool "Do not pass malformed host and domain names"
89 default y
90 depends on UDHCPC
91 help
92 If selected, udhcpc will check some options (such as option 12 -
93 hostname) and if they don't look like valid hostnames
94 (for example, if they start with dash or contain spaces),
95 they will be replaced with string "bad" when exporting
96 to the environment.
97
87config FEATURE_UDHCP_PORT 98config FEATURE_UDHCP_PORT
88 bool "Enable '-P port' option for udhcpd and udhcpc" 99 bool "Enable '-P port' option for udhcpd and udhcpc"
89 default n 100 default n
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 7dfc160e2..e468b7bbb 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -136,6 +136,7 @@ static int mton(uint32_t mask)
136 return i; 136 return i;
137} 137}
138 138
139#if ENABLE_FEATURE_UDHCPC_SANITIZEOPT
139/* Check if a given label represents a valid DNS label 140/* Check if a given label represents a valid DNS label
140 * Return pointer to the first character after the label upon success, 141 * Return pointer to the first character after the label upon success,
141 * NULL otherwise. 142 * NULL otherwise.
@@ -192,6 +193,9 @@ static int good_hostname(const char *name)
192 name++; 193 name++;
193 } 194 }
194} 195}
196#else
197# define good_hostname(name) 1
198#endif
195 199
196/* Create "opt_name=opt_value" string */ 200/* Create "opt_name=opt_value" string */
197static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_optflag *optflag, const char *opt_name) 201static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_optflag *optflag, const char *opt_name)