Commit Graph

2991 Commits

Author SHA1 Message Date
Sergey Ponomarev
a949399d17 httpd: Make Deny/Allow by IP config support optional
When disabled:

function                                             old     new   delta
if_ip_denied_send_HTTP_FORBIDDEN_and_exit             52       -     -52
handle_incoming_and_exit                            2201    2097    -104
scan_ip                                              170       -    -170
parse_conf                                          1365    1065    -300
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-626)           Total: -626 bytes

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-16 14:58:31 +02:00
Sergey Ponomarev
4864a68596 httpd: Support caching via ETag header
If server responds with ETag then next time client can resend it via If-None-Match header.
Then httpd will check if file wasn't modified and if not return 304 Not Modified status code.
The ETag value is constructed from file's last modification date in unix epoch and it's size:
"hex(last_mod)-hex(file_size)" e.g. "5e132e20-417" (with quotes).
That means that it's not completely reliable as hash functions but fair enough.
The same form of ETag is used by Nginx so load balancing of static content is safe.

function                                             old     new   delta
handle_incoming_and_exit                            2135    2201     +66
http_response                                         88      96      +8
send_headers                                         676     683      +7
parse_conf                                          1362    1365      +3
http_response_type                                    22      24      +2
send_file_and_exit                                   847     841      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/1 up/down: 86/-6)              Total: 80 bytes

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 23:54:48 +02:00
Sergey Ponomarev
b6efac31d8 httpd: Don't add Last-Modified header to response
The Last-Modified header is used for caching.
The client (browser) will send back the received date to server via If-Modified-Since request header.
But both headers MUST be an RFC 1123 formatted string.
And the formatting consumes resources on request parsing and response generation.
Instead we can use ETag header.
This simplifies logic and the only downside is that in JavaScript the document.lastModified will return null.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 23:23:45 +02:00
Sergey Ponomarev
68f75bb9ce httpd: Don't add Date header to response
RFC 2616 sec. 14.18 says that server MUST send Date header.
But in fact the header make sense only for Cache-Control and can be omitted.
In the same time the Date eats power, CPU and network resources which are critical for embedded systems.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 23:04:49 +02:00
Sergey Ponomarev
b414cdf5b4 httpd: Update to HTTP/1.1
HTTP v1.1 was released in 1999 year and it's time to update BB HTTPD.
Browsers may behave badly with HTTP/1.0
E.g. Chrome does not send the If-None-Match header with ETag.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 22:51:14 +02:00
Ron Yorston
5c69ad0ecd build system: drop PLATFORM_LINUX
PLATFORM_LINUX is a hidden configuration option which is disabled by
default and enabled at over a hundred locations for features that are
deemed to be Linux specific.

The only effect of PLATFORM_LINUX is to control compilation of
libbb/match_fstype.c.  This file is only needed by mount and umount.

Remove all references to PLATFORM_LINUX and compile match_fstype.c
if mount or umount is enabled.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-13 17:12:56 +02:00
Martin Lewis
9914d8b861 udhcpc: add support for long options
Duplicate options are currently overridden (only the last option is kept).
This leads to unexpected behavior when using long options.

The patch adds support for long options in compliance with RFC 3396.

Fixes #13136.

function                                             old     new   delta
udhcp_run_script                                     601     725    +124
optitem_unset_env_and_free                             -      38     +38
putenvp                                               46      59     +13
static.xmalloc_optname_optval                        718     717      -1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 175/-1)            Total: 174 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-13 16:48:07 +02:00
Christian Eggers
8a485b0a36 ip address: Add support for "valid_lft" and "preferred_lft" options
Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:48:50 +02:00
Christian Eggers
31d34f3bd8 ip: Add support for "noprefixroute" option
The "noprefixroute" option suppresses automatic generation of a routing
table entry based on the interface's ip address.

The ifa_flags field has only 8 bit. If higher bits are set,
rta_tb[IFA_FLAGS] has to be used instead.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:45:36 +02:00
Sergey Ponomarev
a088da4476 httpd_indexcgi.c: use CSS for odd/even rows
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:14:54 +02:00
Sergey Ponomarev
197ae0f9ae httpd_indexcgi.c: minimize style CSS
Remove new lines \n and some semicolons ;. This minimize page style size from 655 to 604

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 17:53:48 +02:00
Denys Vlasenko
9a2d899273 ntpd: fix refid reported in server mode, closes 13056
function                                             old     new   delta
resolve_peer_hostname                                129     196     +67
recv_and_process_peer_pkt                           2475    2476      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 68/0)               Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-20 00:04:33 +02:00
Denys Vlasenko
06a407c628 networking: support ftp PASV responses not ending with ')'
Patch by Baruch Burstein <bmburstein@gmail.com>

function                                             old     new   delta
parse_pasv_epsv                                      153     181     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-19 20:59:35 +02:00
Martin Lewis
4468c569f7 domain_codec: optimize dname_dec and convert_dname
dname_dec: now iterates over the packet only once.
convert_dname: remove redundant checks and code shrink.

While testing I've noticed that some of the tests didn't compile
properly, so I fixed them.

function                                             old     new   delta
dname_dec                                            286     267     -19
dname_enc                                            166     143     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-42)             Total: -42 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-12 21:19:13 +02:00
Martin Lewis
1f86ecb729 udhcpc: fix a TODO in fill_envp using option scanner
fill_envp now iterates over the packet only once instead of a few hundred times
using the new option scanner.

function                                             old     new   delta
udhcp_scan_options                                     -     189    +189
putenvp                                                -      46     +46
init_scan_state                                        -      22     +22
udhcp_get_option                                     227     104    -123
udhcp_run_script                                     835     601    -234
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/2 up/down: 257/-357)         Total: -100 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 15:26:09 +02:00
Martin Lewis
acdc8eed89 udhcp: add option scanner
Added an option scanner to udhcp to enable iteration over packet options.

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:57:02 +02:00
Scott Court
fc2ce04a38 wget: fix openssl options for cert verification
function                                             old     new   delta
is_ip_address                                          -      54     +54
spawn_https_helper_openssl                           461     486     +25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 79/0)               Total: 79 bytes

Signed-off-by: Scott Court <z5t1@z5t1.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:32:09 +02:00
Norbert Lange
79bd7c3f7b acpid: only display -p if supported in usage
Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:11:03 +02:00
Norbert Lange
05faa6103b dhcpd: remove hardcoded pidfile path
Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:07:57 +02:00
Norbert Lange
a16c8ef212 nc_bloaty: support udp broadcast ports
Add a -b option, identical to debians "traditional" netcat.
This allows sending (subnet) UDP Broadcasts.

function                                             old     new   delta
packed_usage                                       33420   33441     +21
nc_main                                             1041    1057     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 13:53:17 +02:00
Denys Vlasenko
df1f479fc5 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-23 03:13:55 +02:00
Denys Vlasenko
6eb38fded2 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-23 02:46:53 +02:00
Uwe Glaeser
faab906d28 udhcpc6: use correct multicast MAC
function                                             old     new   delta
static.MAC_DHCP6MCAST_ADDR                             -       6      +6

Signed-off-by: Uwe Glaeser <uwe.glaeser@dormakaba.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-21 02:56:12 +02:00
Martin Lewis
d30d1ebc11 dhcpc: refactor xmalloc_optname_optval to shrink binary size
function                                             old     new   delta
len_of_option_as_string                               14      13      -1
dhcp_option_lengths                                   14      13      -1
udhcp_str2optset                                     641     637      -4
static.xmalloc_optname_optval                        777     718     -59
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-65)             Total: -65 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 17:59:56 +02:00
Ron Yorston
17764603f2 httpd: allow '-h' to work when daemonized with NOMMU enabled
Commit d1b75e184 (httpd: permit non-default home directory with NOMMU
enabled) only works when used with the '-f' (foreground) option.

When '-f' isn't specified and NOMMU is enabled bb_daemonize_or_rexec()
is called to daemonize the server.  Since the server process has been
re-execed the previous patch results in the xchdir() not being called.

Fix this by resetting the re_execed variable in this case.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 17:38:21 +02:00
Denys Vlasenko
0cad5f9b6d udhcp: comment out unused domain compression code
function                                             old     new   delta
attach_option                                        411     406      -5
dname_enc                                            381     167    -214
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-219)           Total: -219 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 17:22:06 +02:00
Martin Lewis
726d0d148b dhcpc: code shrink in good_hostname
Incorporated valid_domain_label into good_hostname to simplify the implementation.

function                                             old     new   delta
static.xmalloc_optname_optval                        973     958     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-15)             Total: -15 bytes
   text	   data	    bss	    dec	    hex	filename
 993144	  16915	   1872	1011931	  f70db	busybox_old
 993129	  16915	   1872	1011916	  f70cc	busybox_unstripped

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 01:49:10 +02:00
Dimitri John Ledkov
45fa3f18ad wget: implement TLS verification with ENABLE_FEATURE_WGET_OPENSSL
When ENABLE_FEATURE_WGET_OPENSSL is enabled, correctly implement TLS
verification by default. And only ignore verification errors, if
--no-check-certificate was passed.

Also note, that previously OPENSSL implementation did not implement
TLS verification, nor printed any warning messages that verification
was not performed.

Bug-Ubuntu: https://bugs.launchpad.net/bugs/1879533

CVE-2018-1000500

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-05-20 15:10:44 +02:00
Ron Yorston
d1b75e1842 httpd: permit non-default home directory with NOMMU enabled
When BusyBox is compiled with NOMMU enabled running httpd with
the '-h' option fails even if the specified directory exists:

   $ ls -d www
   www
   $ busybox httpd  -fvvvp 8080 -h www
   ...
   ... try to access http://localhost:8080/www
   ...
   httpd: can't change directory to 'www': No such file or directory

The parent process executes xchdir("www").  When a connection is accepted
it's handled by re-executing httpd in inetd mode.  The child process
inherits the current directory "www" and tries to change directory again
to "www", which fails.

Omit the call to xchdir() when httpd is re-executed.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-30 16:37:44 +02:00
Denys Vlasenko
adc540f0db tftp: on download, open local file only when first bit of data arrived
No reason to potentially clobber existing file before absolutely necessary.

function                                             old     new   delta
tftp_protocol                                       1947    2020     +73
tftp_main                                            393     376     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 73/-17)             Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 15:27:23 +01:00
Denys Vlasenko
0c4e5977df tftp: fix thinko in code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 15:03:12 +01:00
Denys Vlasenko
779df9f228 tftp: code shrink
function                                             old     new   delta
tftp_protocol                                       1949    1947      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 13:01:43 +01:00
Denys Vlasenko
260bd21169 tftpd: show requested file name in open error message
function                                             old     new   delta
tftp_protocol                                       1902    1949     +47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 12:58:46 +01:00
Denys Vlasenko
020abc8856 udhcpd: mangle hostnames starting with dash ("-option")
function                                             old     new   delta
add_lease                                            316     328     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-14 17:07:18 +01:00
Denys Vlasenko
9ec836c033 whois: limit total length of response to 32+2 kb
function                                             old     new   delta
query                                                517     554     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-12-03 14:52:17 +01:00
Denys Vlasenko
ea096d6c13 ntpd: decrease MIN_FREQHOLD by 2, increase "penalty" for largish offset x2
> 2018-07-25:
> ntpd: increase MIN_FREQHOLD by 3
> This means we'll start correcting frequency ~5 minutes after start,
> not ~3.5 ones.
> With previous settings I still often see largish ~0.7s initial offsets
> only about 1/2 corrected before frequency correction kicks in,
> resulting in ~200ppm "correction" which is then slowly undone.

Review of real-world results of the above shows that with small
initial offsets, freq correction can be allowed to kick in sooner,
whereas with large (~0.8s) offsets, we still start freq correction
a bit too soon.

Let's rebalance this a bit.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-30 12:18:07 +01:00
Jo-Philipp Wich
6b4960155e nslookup: implement support for SRV records
Add support for querying and parsing SRV DNS records.

function                                             old     new   delta
send_queries                                        1711    1865    +154
qtypes                                                72      80      +8

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-27 17:07:35 +01:00
Jo-Philipp Wich
8c3b520d4f nslookup: handle replies without RRs
Under some circumstances, a DNS reply might contain no resource records,
e.g. when a valid domain is queried that does not have records of the
requested type.

Example with nslookup from BIND dnsutils:

    $ nslookup -q=SRV example.org
    Server:	10.11.12.13
    Address:	10.11.12.13#53

    Non-authoritative answer:
    *** Can't find example.org: No answer

Currently the busybox nslookup applet simply prints nothing after the
"Non-authoritative answer:" line in the same situation.

This change modifies nslookup to either print "Parse error" or "No answer"
diagnostics, depending on the parse_reply() return value.

function                                             old     new   delta
send_queries                                        1676    1711     +35

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-27 17:02:08 +01:00
Denys Vlasenko
d6ff27de15 ntpd: abs(tmx.offset) was truncating a "long" typed value
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 17:35:58 +02:00
Denys Vlasenko
b4ad1d86b6 tc: array address is never NULL
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:41:31 +02:00
Denys Vlasenko
e076162897 traceroute: fix gcc-ism
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:39:41 +02:00
Denys Vlasenko
e5897d041d suppress a few "unused function" warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:05:15 +02:00
Denys Vlasenko
1f1492bb96 netstat: suppress a warning (conversion from 'int' to 'smallint' changes value)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:00:01 +02:00
Denys Vlasenko
95867147f5 telnet: add disabled code to emit EC and IP
> I'm trying to connect to a Korenix 3005 switch through telnet
> for management purposes, and all is well except for the backspace character
> - seems like my switch doesn't handle it too well and instead of erasing
> the last character all it does is print some garbage to the screen.
> I've had the same issue before while using putty, but saw a solution that
> suggests to enable "Telnet special commands" in the options menu, and it
> worked.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-18 16:47:37 +02:00
Denys Vlasenko
37a9008f8e brctl: code shrink
function                                             old     new   delta
show_bridge                                          323     317      -6
brctl_main                                          2171    2164      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-13)             Total: -13 bytes
   text	   data	    bss	    dec	    hex	filename
1002083	    551	   5612	1008246	  f6276	busybox_old
1002065	    551	   5612	1008228	  f6264	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-15 12:31:54 +02:00
Denys Vlasenko
eb1395147a brctl: tweak help text, fix comments
function                                             old     new   delta
packed_usage                                       33255   33236     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-12 19:51:46 +02:00
Denys Vlasenko
b4fa16d5ed brctl: fold show_bridge_ports_ into its caller
function                                             old     new   delta
brctl_main                                          2235    2171     -64

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-12 19:42:37 +02:00
Denys Vlasenko
3398753818 brctl: code shrink
packed_usage                                       33253   33255      +2
write_uint                                            96      90      -6
show_bridge_timer                                     93      69     -24
brctl_main                                          2338    2235    -103
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 2/-133)           Total: -131 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-12 19:24:38 +02:00
Martin Lewis
6dcf563633 brctl: add support for showstp command
function                                             old     new   delta
brctl_main                                           974    2339   +1365
show_bridge_timer                                      -      93     +93
static.state_names                                     -      48     +48
printf_xstrtou                                         -      26     +26
packed_usage                                       33243   33253     +10
show_bridge                                          333     323     -10
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/1 up/down: 1542/-10)         Total: 1532 bytes
   text	   data	    bss	    dec	    hex	filename
 999868	    551	   5612	1006031	  f59cf	busybox_old
1002309	    551	   5612	1008472	  f6358	busybox_unstripped

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-11 17:58:15 +02:00
Michal Kazior
1f1988d525 udhcpc: fix segmentation fault on empty bin opt
The following caused udhcpc to segfault:
  busybox udhcpc -i lo -s /dev/null -x 0x3d:

function                                             old     new   delta
udhcp_str2optset                                     629     641     +12

Signed-off-by: Michal Kazior <michal@plume.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-08 15:14:46 +02:00