summaryrefslogtreecommitdiff
path: root/networking/httpd.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'busybox' into mergeRon Yorston2021-02-051-2/+2
|\
| * libbb: introduce and use fputs_stdoutRon Yorston2021-02-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta fputs_stdout - 12 +12 zxc_vm_process 7237 7230 -7 yes_main 85 78 -7 write_block 380 373 -7 wrapf 305 298 -7 strings_main 437 430 -7 show_bridge 353 346 -7 rev_main 384 377 -7 put_prompt_custom 58 51 -7 put_cur_glyph_and_inc_cursor 168 161 -7 print_numbered_lines 152 145 -7 print_named_ascii 130 123 -7 print_name 135 128 -7 print_login_issue 386 379 -7 print_ascii 208 201 -7 powertop_main 1249 1242 -7 od_main 1789 1782 -7 logread_main 518 511 -7 head_main 804 797 -7 display_process_list 1319 1312 -7 cut_main 1002 995 -7 bb_dump_dump 1550 1543 -7 bb_ask_noecho 393 386 -7 baseNUM_main 702 695 -7 expand_main 755 745 -10 dumpleases_main 497 487 -10 write1 12 - -12 putcsi 37 23 -14 print_login_prompt 55 41 -14 paste_main 525 511 -14 cat_main 440 426 -14 print_it 245 230 -15 print_addrinfo 1188 1171 -17 print_rule 770 750 -20 print_linkinfo 842 822 -20 httpd_main 791 771 -20 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/34 up/down: 12/-341) Total: -329 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-01-141-44/+10
|\|
| * Fix httpd compilation on the FreeBSDAlex Samorukov2021-01-041-0/+5
| | | | | | | | | | | | | | FreeBSD is not exporting s6_addr32 by default, but has it. Signed-off-by: Alex Samorukov <samm@os2.kiev.ua> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * httpd: fix offset for sendfileMaxim Storchak2020-12-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the Range: header is not present it the request, the offset passed to sendfile is wrong, and httpd falls back to the read-write loop. function old new delta send_file_and_exit 857 865 +8 handle_incoming_and_exit 2239 2230 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 8/-9) Total: -1 bytes Signed-off-by: Maxim Storchak <m.storchak@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: change decode_base32/64 API to return the end of _dst_, not _src_.Denys Vlasenko2020-11-281-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta decode_base64 173 178 +5 read_base64 222 220 -2 decode_base32 186 182 -4 handle_incoming_and_exit 2263 2239 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-30) Total: -25 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: smaller and faster decode_base64()Denys Vlasenko2020-11-271-37/+0
| | | | | | | | | | | | | | function old new delta decode_base64 195 180 -15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2020-11-121-0/+7
|\|
| * httpd: code shrinkXabier Oneca2020-10-061-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | Use decode_base64() from uuencode.c when uudecode/base64 applets are included. That function is bigger than httpd's decodeBase64(), so we use the old one when those applets are disabled. Bloat-o-meter when one of those is enabled: function old new delta handle_incoming_and_exit 2371 2265 -106 Signed-off-by: Xabier Oneca <xoneca@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | httpd: silence compiler warnings about %llx formatRon Yorston2020-08-231-1/+1
| |
* | Merge branch 'busybox' into mergeRon Yorston2020-08-231-41/+151
|\|
| * httpd: Make Deny/Allow by IP config support optionalSergey Ponomarev2020-08-161-18/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * httpd: Support caching via ETag headerSergey Ponomarev2020-08-151-3/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * httpd: Don't add Last-Modified header to responseSergey Ponomarev2020-08-151-6/+25
| | | | | | | | | | | | | | | | | | | | | | | | 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>
| * httpd: Don't add Date header to responseSergey Ponomarev2020-08-151-2/+16
| | | | | | | | | | | | | | | | | | 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>
| * httpd: Update to HTTP/1.1Sergey Ponomarev2020-08-151-8/+8
| | | | | | | | | | | | | | | | | | 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>
* | httpd: code shrinkRon Yorston2020-08-131-3/+2
| | | | | | | | Use the new need_system_drive() function in httpd. Saves 16 bytes.
* | win32: use a static buffer in get_system_drive()Ron Yorston2020-08-131-1/+1
| | | | | | | | | | | | | | Allocate static storage for the system drive string instead of making a new allocation on every call. This is easier to manage. Adds 16 bytes.
* | Merge branch 'busybox' into mergeRon Yorston2020-07-091-2/+3
|\|
| * httpd: allow '-h' to work when daemonized with NOMMU enabledRon Yorston2020-06-091-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeFRP-3466-g53c09d0e1Ron Yorston2020-05-291-0/+6
|\|
| * httpd: permit non-default home directory with NOMMU enabledRon Yorston2020-04-301-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | httpd: allow use of MD5-encrypted passwordsRon Yorston2020-04-091-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Allow use of MD5-encrypted passwords in HTTP authentication. However: - Since it adds 4K to the size of the binary it isn't enabled by default. Unencrypted password are allowed in the default build. - The use of '*' wildcards for user/password in the configuration file isn't allowed. - Enabling this feature requires enabling 'Use internal crypt functions' (USE_BB_CRYPT) in the 'Login/Password Management Utilities' section.
* | httpd: prevent access to config file and authenticated URLsRon Yorston2020-04-081-0/+12
| | | | | | | | | | | | | | | | | | | | | | Filesystems on Microsoft Windows are usually case-insensitive. This allows clients to circumvent security by requesting URLs with changes in case that aren't anticipated by the server: http://example.com/Httpd.conf vs http://example.com/httpd.conf http://example.com/SeCuReDir vs http://example.com/SecureDir Use case-insensitive comparisons to avoid this.
* | httpd: don't change directory in inetd modeRon Yorston2020-04-071-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the WIN32 port inetd mode is used in the same way as in NOMMU to process each new connection. However, it shares a problem with NOMMU mode upstream: the child process changes directory unnecessarily. Thus, 'httpd -fvvvp 8080 -h www' fails with errors: httpd: can't change directory to 'www': No such file or directory Fix this in the WIN32 port by not changing directory in inetd mode. The behaviour of inetd mode is now quite unlike upstream so the option have been changed to '-I' and removed from the help message. Since the -e/-d options appear in the help message unconditionally FEATURE_HTTPD_ENCODE_URL_STR has been enabled.
* | httpd: WIN32 portRon Yorston2020-04-051-2/+133
|/ | | | | | | | Use mingw_spawn_detach() to daemonize the server. Pass the open socket to the child process on the command line. Omit handling of SIGHUP and SIGALRM. Timeouts are handled using poll(2) instead of alarm(2).
* libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne2019-07-021-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: .js is "application/javascript", not "application/x-javascript"Denys Vlasenko2019-06-071-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: add js to built in MIME types listDenys Vlasenko2019-06-071-0/+1
| | | | | | Firefox needs this to execute .js Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: add svg to built in MIME types listVicente Jimenez Aguilar2019-06-071-0/+1
| | | | | Signed-off-by: Vicente Jimenez Aguilar <googuy@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: do disable header reading timeout even if proxyingDenys Vlasenko2019-04-191-0/+2
| | | | | | | function old new delta handle_incoming_and_exit 2362 2369 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: use full size of iobuf[] when piping CGI dataDenys Vlasenko2019-04-191-11/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: do not set alarm() timeout if we read cached headerDenys Vlasenko2019-04-191-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: deindent code block, no code changesDenys Vlasenko2019-04-191-91/+91
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: require "HTTP/xyz" at the end of request lineDenys Vlasenko2019-04-191-14/+8
| | | | | | | | | | | | function old new delta handle_incoming_and_exit 2379 2362 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-17) Total: -17 bytes text data bss dec hex filename 981787 485 7296 989568 f1980 busybox_old 981779 485 7296 989560 f1978 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: pass authorization header to CGI if not BasicAlexander Vickberg2019-04-181-7/+7
| | | | | | | | | | | | Pass the Authorization header to CGI if not of type Basic. This will make it possible for CGI to verify authorization headers of type Bearer <token>. function old new delta handle_incoming_and_exit 2370 2379 +9 Signed-off-by: Alexander Vickberg <wickbergster@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: When sending gzipped content use content-length headerAlexander Vickberg2019-04-171-2/+45
| | | | | | | | | | | | | | | Today for gzipped content httpd is using a header with name Transfer-Length. However I can't find a header with that name in the standards. Instead use Content-Length. function old new delta .rodata 157940 157936 -4 send_headers 980 939 -41 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-45) Total: -45 bytes Signed-off-by: Alexander Vickberg <wickbergster@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: extract query string only after proxying checkDenys Vlasenko2019-04-161-12/+7
| | | | | | | function old new delta handle_incoming_and_exit 2398 2370 -28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: make rmt_ip variable localDenys Vlasenko2019-04-161-17/+22
| | | | | | | | | | | function old new delta handle_incoming_and_exit 2385 2398 +13 if_ip_denied_send_HTTP_FORBIDDEN_and_exit 51 54 +3 get_line 110 106 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4) Total: 12 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: check denied IPs even before reading 1st query lineDenys Vlasenko2019-04-161-2/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: do not decode URL and headers if proxying - send all verbatimDenys Vlasenko2019-04-161-68/+46
| | | | | | | function old new delta handle_incoming_and_exit 2566 2385 -181 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: remove duplicate "decode URL escape sequences" codeDenys Vlasenko2019-04-161-9/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: put all headers into environment as HTTP_UPPERCASED_HEADER=valDenys Vlasenko2019-04-161-105/+120
| | | | | | | | | | | | | | | | | | | | | | | | | Set up environment variables before running the CGI script. The variables will be named HTTP_<filtered_name> where the <filtered_name> is the header name capitalized and all characters not matching [a-z] | [A-Z] | [0-9] replaced with '_'. function old new delta http_response 80 88 +8 http_response_type 20 22 +2 send_headers 718 715 -3 parse_conf 1481 1478 -3 get_line 128 110 -18 cgi_io_loop_and_exit 599 569 -30 send_cgi_and_exit 882 738 -144 handle_incoming_and_exit 2793 2592 -201 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/6 up/down: 10/-399) Total: -389 bytes text data bss dec hex filename 982178 485 7296 989959 f1b07 busybox_old 981675 485 7296 989456 f1910 busybox_unstripped Signed-off-by: Alexander Vickberg <wickbergster@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: fix handling of EOF in get_line()Denys Vlasenko2019-04-161-8/+10
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: add missing {}Denys Vlasenko2019-04-161-1/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: do not percent-decode URI if proxyingDenys Vlasenko2019-04-161-10/+22
| | | | | | | | | | | | | | | | | | | | | | | | The proxying is documented as follows: P:/url:[http://]hostname[:port]/new/path Howeverm urlcopy is not a true copy anymore when it is fdprint'ed to proxy_fd, this is because percent_decode_in_place() is called after the copy is created. This breaks reverse proxying all URIs containing percent encoded spaces, e.g. - because a decoded URI will be printed out to proxy_fd instead of the original. The fix keeps the logic in place to canonicalize the uri first, before reverse proxying (one could argue that the uri should be proxied completely unaltered, except for the prefix rewrite). function old new delta handle_incoming_and_exit 2752 2792 +40 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: fix proxy headers passing - full_write() instead of write()Denys Vlasenko2019-04-141-11/+16
| | | | | | | function old new delta handle_incoming_and_exit 2763 2752 -11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: if remote IP is denied, send FORBIDDEN reply earlierDenys Vlasenko2019-04-141-10/+14
| | | | | | | | | | | | | | While at it, fix sighup_handler to not clobber errno. function old new delta send_HTTP_FORBIDDEN_and_exit_if_denied_ip - 47 +47 sighup_handler 15 30 +15 handle_incoming_and_exit 2791 2763 -28 checkPermIP 48 - -48 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/1 up/down: 62/-76) Total: -14 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* httpd: do not default to Content-type: application/octet-streamDenys Vlasenko2018-04-071-30/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead, simply don't send this header. On Mon, Apr 2, 2018 at 8:17 PM, xisd <xisd-dev@riseup.net> wrote: > I had some trouble using busybox httpd to serve a static website and I > thought the issue might be of interest. > > My problem is related to something that seem quite common for static > site generator : the use of html files without the '.html' extension > (it is called 'clean url'...) > > Most web server guess that these files are html and display them like > any other .html files. > > From what I understood, the MIME type for files without extension in > busybox htttp default settings is 'application/octet-stream', and > because of that 'clean url' pages are not displayed. > > It is only trouble because I wanted to deploy my website on freshly > installed linux without editing any configuration. > > The default MIME setting make sense to me as it is, I just thought that > might be worth mentioning since the use of 'clean url' seem to be a > common practice for static sites generators (the one I use is callled > 'yellow' (https://github.com/datenstrom/yellow)) > > Here is a link for the related issue on github : > https://github.com/datenstrom/yellow/issues/317 function old new delta send_headers 702 718 +16 send_headers_and_exit 23 20 -3 handle_incoming_and_exit 2794 2791 -3 send_file_and_exit 772 756 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 16/-22) Total: -6 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* use gmtime_r() instead of gmtime()Denys Vlasenko2018-03-061-2/+4
| | | | | | | | | | | | | | | | | This avoids pulling in gmtime's static buffer: function old new delta svlogd_main 1401 1412 +11 send_headers 668 678 +10 gmtime 21 - -21 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 2/0 up/down: 21/-21) Total: 0 bytes text data bss dec hex filename 920221 555 5804 926580 e2374 busybox_old 920221 555 5740 926516 e2334 busybox_unstripped ^^^^ Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>