diff options
author | Sergey Ponomarev <stokito@gmail.com> | 2021-08-25 23:12:37 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-09-09 21:42:48 +0200 |
commit | 82c5eb8e4681ba345500e5c368fb54741bb0c450 (patch) | |
tree | c07e755a12962fab796bb06d351caa0227a3fd4c | |
parent | 857800c65584d544242c54eb873129c23ba20265 (diff) | |
download | busybox-w32-82c5eb8e4681ba345500e5c368fb54741bb0c450.tar.gz busybox-w32-82c5eb8e4681ba345500e5c368fb54741bb0c450.tar.bz2 busybox-w32-82c5eb8e4681ba345500e5c368fb54741bb0c450.zip |
httpd,telnetd: make default port configurable
BusyBox on Termux can't use ports less than 1024 it's patched to change default port for httpd to 8080 and telnetd to 8023.
https://github.com/termux/termux-packages/blob/master/packages/busybox/0011-networking-telnetd-default-port.patch
https://github.com/termux/termux-packages/blob/master/packages/busybox/0010-networking-httpd-default-port.patch
To avoid such patches we can make port configurable.
function old new delta
packed_usage 33920 33914 -6
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/usage.src.h | 3 | ||||
-rw-r--r-- | networking/httpd.c | 12 | ||||
-rw-r--r-- | networking/telnetd.c | 10 |
3 files changed, 21 insertions, 4 deletions
diff --git a/include/usage.src.h b/include/usage.src.h index 1ac252d1b..5d2038834 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
@@ -31,6 +31,9 @@ | |||
31 | # define ADJTIME_PATH "/etc/adjtime" | 31 | # define ADJTIME_PATH "/etc/adjtime" |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #define STR1(s) #s | ||
35 | #define STR(s) STR1(s) | ||
36 | |||
34 | INSERT | 37 | INSERT |
35 | 38 | ||
36 | #define busybox_notes_usage \ | 39 | #define busybox_notes_usage \ |
diff --git a/networking/httpd.c b/networking/httpd.c index 56ab85b82..9972a5378 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -102,6 +102,11 @@ | |||
102 | //config: help | 102 | //config: help |
103 | //config: HTTP server. | 103 | //config: HTTP server. |
104 | //config: | 104 | //config: |
105 | //config:config FEATURE_HTTPD_PORT_DEFAULT | ||
106 | //config: int "Default port" | ||
107 | //config: default 80 | ||
108 | //config: range 1 65535 | ||
109 | //config: | ||
105 | //config:config FEATURE_HTTPD_RANGES | 110 | //config:config FEATURE_HTTPD_RANGES |
106 | //config: bool "Support 'Ranges:' header" | 111 | //config: bool "Support 'Ranges:' header" |
107 | //config: default y | 112 | //config: default y |
@@ -270,7 +275,7 @@ | |||
270 | //usage: "\n -i Inetd mode" | 275 | //usage: "\n -i Inetd mode" |
271 | //usage: "\n -f Don't daemonize" | 276 | //usage: "\n -f Don't daemonize" |
272 | //usage: "\n -v[v] Verbose" | 277 | //usage: "\n -v[v] Verbose" |
273 | //usage: "\n -p [IP:]PORT Bind to IP:PORT (default *:80)" | 278 | //usage: "\n -p [IP:]PORT Bind to IP:PORT (default *:"STR(CONFIG_FEATURE_HTTPD_PORT_DEFAULT)")" |
274 | //usage: IF_FEATURE_HTTPD_SETUID( | 279 | //usage: IF_FEATURE_HTTPD_SETUID( |
275 | //usage: "\n -u USER[:GRP] Set uid/gid after binding to port") | 280 | //usage: "\n -u USER[:GRP] Set uid/gid after binding to port") |
276 | //usage: IF_FEATURE_HTTPD_BASIC_AUTH( | 281 | //usage: IF_FEATURE_HTTPD_BASIC_AUTH( |
@@ -316,6 +321,9 @@ | |||
316 | 321 | ||
317 | #define HEADER_READ_TIMEOUT 60 | 322 | #define HEADER_READ_TIMEOUT 60 |
318 | 323 | ||
324 | #define STR1(s) #s | ||
325 | #define STR(s) STR1(s) | ||
326 | |||
319 | static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc"; | 327 | static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc"; |
320 | static const char HTTPD_CONF[] ALIGN1 = "httpd.conf"; | 328 | static const char HTTPD_CONF[] ALIGN1 = "httpd.conf"; |
321 | static const char HTTP_200[] ALIGN1 = "HTTP/1.1 200 OK\r\n"; | 329 | static const char HTTP_200[] ALIGN1 = "HTTP/1.1 200 OK\r\n"; |
@@ -542,7 +550,7 @@ enum { | |||
542 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 550 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
543 | IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ | 551 | IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ |
544 | IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ | 552 | IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ |
545 | bind_addr_or_port = "80"; \ | 553 | bind_addr_or_port = STR(CONFIG_FEATURE_HTTPD_PORT_DEFAULT); \ |
546 | index_page = index_html; \ | 554 | index_page = index_html; \ |
547 | file_size = -1; \ | 555 | file_size = -1; \ |
548 | } while (0) | 556 | } while (0) |
diff --git a/networking/telnetd.c b/networking/telnetd.c index de4d733f9..581da1924 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -68,6 +68,12 @@ | |||
68 | //config: help | 68 | //config: help |
69 | //config: Selecting this will make telnetd able to run standalone. | 69 | //config: Selecting this will make telnetd able to run standalone. |
70 | //config: | 70 | //config: |
71 | //config:config FEATURE_TELNETD_PORT_DEFAULT | ||
72 | //config: int "Default port" | ||
73 | //config: default 23 | ||
74 | //config: range 1 65535 | ||
75 | //config: depends on FEATURE_TELNETD_STANDALONE | ||
76 | //config: | ||
71 | //config:config FEATURE_TELNETD_INETD_WAIT | 77 | //config:config FEATURE_TELNETD_INETD_WAIT |
72 | //config: bool "Support -w SEC option (inetd wait mode)" | 78 | //config: bool "Support -w SEC option (inetd wait mode)" |
73 | //config: default y | 79 | //config: default y |
@@ -103,7 +109,7 @@ | |||
103 | //usage: "\n -K Close connection as soon as login exits" | 109 | //usage: "\n -K Close connection as soon as login exits" |
104 | //usage: "\n (normally wait until all programs close slave pty)" | 110 | //usage: "\n (normally wait until all programs close slave pty)" |
105 | //usage: IF_FEATURE_TELNETD_STANDALONE( | 111 | //usage: IF_FEATURE_TELNETD_STANDALONE( |
106 | //usage: "\n -p PORT Port to listen on" | 112 | //usage: "\n -p PORT Port to listen on. Default "STR(CONFIG_FEATURE_TELNETD_PORT_DEFAULT) |
107 | //usage: "\n -b ADDR[:PORT] Address to bind to" | 113 | //usage: "\n -b ADDR[:PORT] Address to bind to" |
108 | //usage: "\n -F Run in foreground" | 114 | //usage: "\n -F Run in foreground" |
109 | //usage: "\n -i Inetd mode" | 115 | //usage: "\n -i Inetd mode" |
@@ -708,7 +714,7 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv) | |||
708 | } else { | 714 | } else { |
709 | master_fd = 0; | 715 | master_fd = 0; |
710 | if (!(opt & OPT_WAIT)) { | 716 | if (!(opt & OPT_WAIT)) { |
711 | unsigned portnbr = 23; | 717 | unsigned portnbr = CONFIG_FEATURE_TELNETD_PORT_DEFAULT; |
712 | if (opt & OPT_PORT) | 718 | if (opt & OPT_PORT) |
713 | portnbr = xatou16(opt_portnbr); | 719 | portnbr = xatou16(opt_portnbr); |
714 | master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr); | 720 | master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr); |