diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-17 12:43:54 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-17 12:43:54 +0200 |
commit | 2aeb201c9751d4ee82978c623310e14b9e831b94 (patch) | |
tree | 3f4d72e70d39889e981de68b56799ee2bf85ce78 | |
parent | 816d8d7a668b541cee99469edb90e4917ea11c3e (diff) | |
download | busybox-w32-2aeb201c9751d4ee82978c623310e14b9e831b94.tar.gz busybox-w32-2aeb201c9751d4ee82978c623310e14b9e831b94.tar.bz2 busybox-w32-2aeb201c9751d4ee82978c623310e14b9e831b94.zip |
libbb: new option FEATURE_ETC_SERVICES: if off, /etc/services reads often avoided
In practice, "wget http://host.com/" always uses port 80.
People explicitly set non-standard ports via options or parameters
("telnet 1.2.3.4 567" or "telnet 1.2.3.4 ftp") instead of modifying
/etc/services.
function old new delta
telnet_main 1466 1464 -2
rdate_main 215 198 -17
fakeidentd_main 269 252 -17
parse_url 459 392 -67
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-103) Total: -103 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/Config.src | 12 | ||||
-rw-r--r-- | networking/isrv_identd.c | 2 | ||||
-rw-r--r-- | networking/telnet.c | 3 | ||||
-rw-r--r-- | networking/wget.c | 8 | ||||
-rw-r--r-- | util-linux/rdate.c | 2 |
6 files changed, 25 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h index 646c58bf2..a605c7f03 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -640,6 +640,11 @@ int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC; | |||
640 | int bb_getsockname(int sockfd, void *addr, socklen_t addrlen) FAST_FUNC; | 640 | int bb_getsockname(int sockfd, void *addr, socklen_t addrlen) FAST_FUNC; |
641 | /* NB: returns port in host byte order */ | 641 | /* NB: returns port in host byte order */ |
642 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) FAST_FUNC; | 642 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) FAST_FUNC; |
643 | #if ENABLE_FEATURE_ETC_SERVICES | ||
644 | # define bb_lookup_std_port(portstr, protocol, portnum) bb_lookup_port(portstr, protocol, portnum) | ||
645 | #else | ||
646 | # define bb_lookup_std_port(portstr, protocol, portnum) (portnum) | ||
647 | #endif | ||
643 | typedef struct len_and_sockaddr { | 648 | typedef struct len_and_sockaddr { |
644 | socklen_t len; | 649 | socklen_t len; |
645 | union { | 650 | union { |
diff --git a/libbb/Config.src b/libbb/Config.src index fdf8bbb28..16e16480b 100644 --- a/libbb/Config.src +++ b/libbb/Config.src | |||
@@ -76,6 +76,18 @@ config FEATURE_ETC_NETWORKS | |||
76 | a rarely used feature which allows you to use names | 76 | a rarely used feature which allows you to use names |
77 | instead of IP/mask pairs in route command. | 77 | instead of IP/mask pairs in route command. |
78 | 78 | ||
79 | config FEATURE_ETC_SERVICES | ||
80 | bool "Consult /etc/services even for well-known ports" | ||
81 | default n | ||
82 | help | ||
83 | Look up e.g. "telnet" and "http" in /etc/services file | ||
84 | instead of assuming ports 23 and 80. | ||
85 | This is almost never necessary (everybody uses standard ports), | ||
86 | and it makes sense to avoid reading this file. | ||
87 | If you disable this option, in the cases where port is explicitly | ||
88 | specified as a service name (e.g. "telnet HOST PORTNAME"), | ||
89 | it will still be looked up in /etc/services. | ||
90 | |||
79 | config FEATURE_EDITING | 91 | config FEATURE_EDITING |
80 | bool "Command line editing" | 92 | bool "Command line editing" |
81 | default y | 93 | default y |
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index 133d62a65..0c33dde4f 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c | |||
@@ -159,7 +159,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv) | |||
159 | fd = 0; | 159 | fd = 0; |
160 | if (!(opt & OPT_inetdwait)) { | 160 | if (!(opt & OPT_inetdwait)) { |
161 | fd = create_and_bind_stream_or_die(bind_address, | 161 | fd = create_and_bind_stream_or_die(bind_address, |
162 | bb_lookup_port("identd", "tcp", 113)); | 162 | bb_lookup_std_port("identd", "tcp", 113)); |
163 | xlisten(fd, 5); | 163 | xlisten(fd, 5); |
164 | } | 164 | } |
165 | 165 | ||
diff --git a/networking/telnet.c b/networking/telnet.c index 15d6a08d8..1e6be85bd 100644 --- a/networking/telnet.c +++ b/networking/telnet.c | |||
@@ -643,7 +643,8 @@ int telnet_main(int argc UNUSED_PARAM, char **argv) | |||
643 | if (!*argv) | 643 | if (!*argv) |
644 | bb_show_usage(); | 644 | bb_show_usage(); |
645 | host = *argv++; | 645 | host = *argv++; |
646 | port = bb_lookup_port(*argv ? *argv++ : "telnet", "tcp", 23); | 646 | port = *argv ? bb_lookup_port(*argv++, "tcp", 23) |
647 | : bb_lookup_std_port("telnet", "tcp", 23); | ||
647 | if (*argv) /* extra params?? */ | 648 | if (*argv) /* extra params?? */ |
648 | bb_show_usage(); | 649 | bb_show_usage(); |
649 | 650 | ||
diff --git a/networking/wget.c b/networking/wget.c index 2650b5384..b6c76e9dc 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -505,23 +505,23 @@ static void parse_url(const char *src_url, struct host_info *h) | |||
505 | *p = '\0'; | 505 | *p = '\0'; |
506 | h->host = p + 3; | 506 | h->host = p + 3; |
507 | if (strcmp(url, P_FTP) == 0) { | 507 | if (strcmp(url, P_FTP) == 0) { |
508 | h->port = bb_lookup_port(P_FTP, "tcp", 21); | 508 | h->port = bb_lookup_std_port(P_FTP, "tcp", 21); |
509 | } else | 509 | } else |
510 | #if SSL_SUPPORTED | 510 | #if SSL_SUPPORTED |
511 | # if ENABLE_FEATURE_WGET_HTTPS | 511 | # if ENABLE_FEATURE_WGET_HTTPS |
512 | if (strcmp(url, P_FTPS) == 0) { | 512 | if (strcmp(url, P_FTPS) == 0) { |
513 | h->port = bb_lookup_port(P_FTPS, "tcp", 990); | 513 | h->port = bb_lookup_std_port(P_FTPS, "tcp", 990); |
514 | h->protocol = P_FTPS; | 514 | h->protocol = P_FTPS; |
515 | } else | 515 | } else |
516 | # endif | 516 | # endif |
517 | if (strcmp(url, P_HTTPS) == 0) { | 517 | if (strcmp(url, P_HTTPS) == 0) { |
518 | h->port = bb_lookup_port(P_HTTPS, "tcp", 443); | 518 | h->port = bb_lookup_std_port(P_HTTPS, "tcp", 443); |
519 | h->protocol = P_HTTPS; | 519 | h->protocol = P_HTTPS; |
520 | } else | 520 | } else |
521 | #endif | 521 | #endif |
522 | if (strcmp(url, P_HTTP) == 0) { | 522 | if (strcmp(url, P_HTTP) == 0) { |
523 | http: | 523 | http: |
524 | h->port = bb_lookup_port(P_HTTP, "tcp", 80); | 524 | h->port = bb_lookup_std_port(P_HTTP, "tcp", 80); |
525 | h->protocol = P_HTTP; | 525 | h->protocol = P_HTTP; |
526 | } else { | 526 | } else { |
527 | *p = ':'; | 527 | *p = ':'; |
diff --git a/util-linux/rdate.c b/util-linux/rdate.c index f27294e25..5ec795208 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c | |||
@@ -45,7 +45,7 @@ static time_t askremotedate(const char *host) | |||
45 | alarm(10); | 45 | alarm(10); |
46 | signal(SIGALRM, socket_timeout); | 46 | signal(SIGALRM, socket_timeout); |
47 | 47 | ||
48 | fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37)); | 48 | fd = create_and_connect_stream_or_die(host, bb_lookup_std_port("time", "tcp", 37)); |
49 | 49 | ||
50 | if (safe_read(fd, &nett, 4) != 4) /* read time from server */ | 50 | if (safe_read(fd, &nett, 4) != 4) /* read time from server */ |
51 | bb_error_msg_and_die("%s: %s", host, "short read"); | 51 | bb_error_msg_and_die("%s: %s", host, "short read"); |