aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* win32: enable globbing by defaultRon Yorston2020-06-145-15/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change how busybox.exe expands wildcards on the command line. When globbing is enabled at compile time provide an implementation of _setargv(), which is run early during startup of C programs. This: - enables globbing by setting _dowildcard to -1 - checks for the presence of the environment BB_GLOBBING - if it exists and is set to 0 disables globbing - if it doesn't exist sets BB_GLOBBING=0 but continues to apply Windows' globbing in the current process The consequences of this are: - When busybox.exe is initially run from a Command Prompt Windows' globbing is applied; - Windows' globbing is turned off for future child processes, thus allowing the shell re-execute busybox.exe without it interfering with wildcards; - this behaviour can be overridden by setting BB_GLOBBING explicitly. Globbing can still be disabled at compile time if required. In that case BB_GLOBBING has no effect. With these changes globbing can be enabled by default and BusyBox will do the right thing in most circumstances. (See GitHub issues #172 and #189.)
* win32: minor improvements to process spawningRon Yorston2020-06-121-3/+2
| | | | | | | | | | | | | | The function mingw_spawn_forkshell() was introduced to handle spawning a forkshell process. Since we know that: - the binary being executed doesn't meet any of the special cases handled by spawnveq() - the arguments don't require quoting we can call spawnve() directly instead of spawnveq(). Also, use xzalloc() to allocate new_argv so we don't need to set the final NULL pointer explicitly.
* ash: treat all applets as NOEXECRon Yorston2020-06-092-0/+8
| | | | | | | | | In standalone shell mode tryexec() treats all applets as NOEXEC. Except for the shell: calling ash_main() recursively seems unwise. This avoids creating a new process for the applet (which is a Good Thing on Microsoft Windows where creating processes is expensive) but leaves the resources used by the invoking shell in the current process.
* ash: minimise work when a forkshell process is startedRon Yorston2020-06-091-19/+27
| | | | | | | | | | | There's no need to create or initialise the global data structures when a forkshell is being started: they'll soon be replaced by data from the forkshell data block. Move the call to forkshell_init() to the top of ash_main() along with some initialisation that's common to forkshell shells and ordinary shells. Add the minimum necessary initialisation to forkshell_init().
* winansi: suppress console flags redefinition warningBiswa962020-06-071-0/+5
| | | | Modern versions of MinGW-w64 define more console modes.
* printf: emit more contiguous text to improve escape sequencesRon Yorston2020-06-041-1/+50
| | | | | | | | | | | | | | | | Users have a reasonable expectation that printf should be able to construct ANSI escape sequences and have them take effect. This expectation isn't met because printf tends to output one character at a time whereas busybox-w32 needs escape sequences to be output contiguously Force printf to output contiguous text in two cases: - literal text in the format string - string arguments output using the '%b' format specifier (See GitHub issue #189.)
* time: detect when spawn failsRon Yorston2020-06-041-1/+1
| | | | | | | In the 64-bit build the time applet reported garbage when it was unable to run the program to be timed. The error return from mingw_spawn_pid() was incorrect.
* win32: fix networking problemsRon Yorston2020-06-033-2/+6
| | | | | | | | | The subprocess that handles incoming connections for httpd didn't work. It has an accepted connection on stdin and calls getpeername() to obtain its details, but getpeername() didn't initialise networking. ssl_client only seems to deal with file descriptors. Expose init_winsock() again and call it from ssl_client.
* win32: use lazy loading for certain DLLsRon Yorston2020-06-025-24/+43
| | | | | | | | | Only a handful of functions are used from shell32.dll, userenv.dll and psapi.dll. Mostly these functions are in out of the way places. By loading the functions only when required we can avoid the startup cost of linking the three DLLs in the common case that they aren't needed.
* win32: only initialise networking if necessaryRon Yorston2020-06-013-10/+43
| | | | | | A call to initialise networking is made during start up even if the applet doesn't need it. Instead, only initialise networking when a call is made to a function that definitely requires it.
* ash: don't initialise shell variables in forkshell childRon Yorston2020-06-011-2/+9
| | | | | | | | | | The forkshell child process calls init(), which mostly just initialises shell variables. Since these variables are overwritten with values from the parent process there's no point in doing that. In particular, init() initialises HOSTNAME by calling gethostname() which involves network access and is slow. Avoid this cost when we know the shell is a forkshell child.
* ash: simplify spawning during forkshellRon Yorston2020-06-013-1/+11
| | | | | | | | | | | | | spawn_forkshell() uses mingw_spawn_proc() to start the child shell. mingw_spawn_proc() then calls mingw_spawn_1() which determines that "sh" is an applet, thus calling mingw_spawn_applet() which finally calls spawnveq(). Not only is this convoluted it also won't work if PREFER_APPLETS and SH_STANDALONE aren't enabled. Simplify matters by adding a new function, mingw_spawn_forkshell(), which is tailored for just this case.
* ash: minor changes to forkshell error handlingRon Yorston2020-06-011-3/+9
| | | | | | | | forkshell_prepare() now returns NULL if it fails to map its view of the data block. Detect and report this error in spawn_forkshell(). If forkshell_init() fails it now returns to ash_main() where a generic error is reported.
* ash: improve forkshell debuggingRon Yorston2020-06-011-4/+14
| | | | | | | | | The name of the output file depended only on the pid of the shell. Since a single shell can execute many forkshells it's useful to include a serial number in the filename so it isn't constantly overwritten. Also, output the type of forkshell.
* Merge branch 'busybox' into mergeFRP-3466-g53c09d0e1Ron Yorston2020-05-2920-36/+138
|\
| * wget: implement TLS verification with ENABLE_FEATURE_WGET_OPENSSLDimitri John Ledkov2020-05-201-3/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash,hush: drop pointer check before calls to show_historyRon Yorston2020-04-302-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | show_history() checks that its argument in non-null so there's no need to repeat the test at call sites. function old new delta historycmd 25 17 -8 builtin_history 29 21 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-16) Total: -16 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * mim: run scripts from a specification fileRon Yorston2020-04-302-0/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mim runs scripts from a specification file which can be thought of as an extremely limited Makefile. Neither make variables nor dependencies are supported. By default the file 'Mimfile' is read. An example: hello: echo hello $1 clean: rm -rf * The command 'mim' or 'mim hello' will echo 'hello'. Unlike 'make' arguments after the first are available to the script; they don't specify additional targets. mim isn't enabled by default. Enabling it increases the size of the binary by about 500 bytes. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix build failure when command built-in is disabledRon Yorston2020-04-301-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 7eb8eecbb (ash: eval: Add assignment built-in support again) building BusyBox with the 'command' built-in disabled fails. parse_command_args() only needs to be called when the 'command' built-in is run. Which it won't be if it's disabled. v2: Avoiding infinite loops is good, too. Thanks, Harald van Dijk. Reported-by: Deweloper <deweloper@wp.pl> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * 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>
| * grep: add proper support for pattern_listSören Tempel2020-04-302-6/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From POSIX.1-2008: The pattern_list's value shall consist of one or more patterns separated by <newline> characters; As such, given patterns need to be split at newline characters. Without doing so, busybox grep will interpret the newline as part of the pattern which is not in accordance with POSIX. See also: https://bugs.busybox.net/show_bug.cgi?id=12721 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * grep: Fix -f FILE when FILE is empty and -x providedGray Wolf2020-04-292-2/+9
| | | | | | | | | | | | | | | | | | | | Grep currently special-cased empty pattern file to be the same as pattern file with one empty line (empty pattern). That does mirror how GNU grep behaves, except when -x is provided. In that case .* pattern needs to be used instead. Signed-off-by: Gray Wolf <wolf@wolfsden.cz> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * xargs: restore correct behaviour of -n optionRon Yorston2020-04-292-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 1ff7002b1 (xargs: fix handling of quoted arguments, closes 11441) the -n option hasn't worked properly: $ echo 1 2 3 | xargs -n 1 echo 1 2 3 $ Because state is now remembered between calls to process_stdin() it's necessary to update the state before any premature return. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * build system: remove KBUILD_STR()Jean-Philippe Brucker2020-04-295-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using GNU Make >=4.3, the KBUILD_STR() definition interferes badly with dependency checks during build, and forces a complete rebuild every time Make runs. In if_changed_rule, Kconfig checks if the command used to build a file has changed since last execution. The previous command is stored in the generated .<file>.o.cmd file. For example applets/.applets.o.cmd defines a "cmd_applets/applets.o" variable: cmd_applets/applets.o := gcc ... -D"KBUILD_STR(s)=#s" ... Here the '#' should be escaped with a backslash, otherwise GNU Make interprets it as starting a comment, and ignore the rest of the variable. As a result of this truncation, the previous command doesn't equal the new command and Make rebuilds each target. The problem started to appear when GNU Make 4.3 (released January 2020), introduced a backward-incompatible fix to macros containing a '#'. While the above use of '#', a simple Make variable, still needs to be escaped, a '#' within a function invocation doesn't need to be escaped anymore. As Martin Dorey explained on the GNU Make discussion [1], the above declaration is generated from make-cmd, defined as: make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))) Since GNU Make 4.3, the first argument of subst should not have a backslash. make-cmd now looks for literally \# and doesn't find it, and as a result doesn't add the backslash when generating .o.cmd files. [1] http://savannah.gnu.org/bugs/?20513 We could fix it by changing make-cmd to "$(subst #,\#,...)", but to avoid compatibility headaches, simply get rid of the KBUILD_STR definition, as done in Linux by b42841b7bb62 ("kbuild: Get rid of KBUILD_STR"). Quote the string arguments directly rather than asking the preprocessor to quote them. Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * unzip: -d should create the dirLauri Kasanen2020-04-291-1/+7
| | | | | | | | | | | | | | The official Info-Zip unzip creates the dir if it doesn't exist. Signed-off-by: Lauri Kasanen <cand@gmx.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shells: fix exitcode_trapN tests to avoid racesDenys Vlasenko2020-02-264-8/+4
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | vi: enable regex search in default buildRon Yorston2020-05-282-4/+4
| |
* | Clarify build requirementsRon Yorston2020-05-271-1/+7
| |
* | Update README.mdRon Yorston2020-05-261-2/+2
| | | | | | | | MinGW is no longer supported in EPEL.
* | win32: changes to '#!' supportRon Yorston2020-05-242-12/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | Since the earliest days of busybox-w32 '#!' has searched PATH for the interpreter. This doesn't seem to be supported by precedent. In testing I also found that additional code was needed for the case where PATH has been altered in the current shell or is modified on the command line: PATH has to be extracted from envp rather than getenv("PATH"). Drop this non-standard feature. *NIX implementations disagree on whether the interpreter can itself be a script. Follow Linux and allow this with a limit of four levels of nesting.
* | dd: fix handling of 'conv=notrunc seek=N'Ron Yorston2020-05-203-7/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit e6680912a (dd: create a sparse file when seek=N is used) broke the use of 'conv=notrunc seek=N' to modify existing files. Rename seek_sparse() to make_sparse() and: - add an argument to specify the start of the sparse region; - call make_sparse() before ftruncate(); - call make_sparse() only if: * we can determine the size of the file; * the file is not open in append mode; * the file is being extended. This should fix GitHub issue #186.
* | ash: proper accounting for backspaces in the read builtinRon Yorston2020-05-141-0/+1
| | | | | | | | | | | | When the '-n' option of the 'read' builtin is used we need to account for backspaces: increase 'nchars' when backspace removes a character from the buffer.
* | inotifyd: WIN32 portRon Yorston2020-04-154-2/+213
| | | | | | | | | | | | | | | | | | | | | | | | Use ReadDirectoryChangesW to implement inotifyd for WIN32. There are limitations: - It's only possible to watch directories, not files. - The notification doesn't distinguish between different changes to file state. All changes other than creation, deletion and renaming are reported as 'c'.
* | winansi: more fine-grained control of ANSI emulationRon Yorston2020-04-131-2/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change the meaning of the BB_SKIP_ANSI_EMULATION variable: - if it isn't set or if it has any value other than 1 or 2, use ANSI emulation; - if it's set to 1, always emit ANSI escape codes; - if it's set to 2, attempt to enable virtual terminal processing in the current console. If that works emit ANSI escape codes, if not revert to ANSI emulation. On all platforms I've tested (Windows 10, Windows 8.1, ReactOS 0.4.13, plus ConEmu) BB_SKIP_ANSI_EMULATION=2 does the right thing.
* | ash: reset ANSI emulation when BB_SKIP_ANSI_EMULATION changesRon Yorston2020-04-135-10/+22
| | | | | | | | | | Update the skip status on the first call to skip_ansi_emulation() and whenever the BB_SKIP_ANSI_EMULATION variable changes.
* | Fix POSIX buildFRP-3445-g10e14d5ebRon Yorston2020-04-112-2/+2
| |
* | 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-073-11/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | time: WIN32 portRon Yorston2020-04-066-12/+106
| | | | | | | | | | | | | | | | Port the time applet to WIN32. This requires the implemntation of a replacement for wait3(2). Only elapsed, user and system times are supported, not the memory and i/o statistics reported by GNU time.
* | httpd: enable in default configurationsRon Yorston2020-04-053-13/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enable the httpd applet in WIN32 default configurations. Some additional features have also been enabled: 'Ranges:' header Basic HTTP authentication Custom error pages GZIP content encoding Common Gateway Interface (CGI) and related features are not enabled. Basic HTTP authentication requires bb_simplify_abs_path_inplace(). This function shouldn't be used for WIN32 paths. In this case it's processing a URL which is OK.
* | 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).
* | win32: new functions: getpeername(2), mingw_spawn_detach()Ron Yorston2020-04-053-3/+30
| | | | | | | | | | | | | | Implement getpeername(2). Add mingw_spawn_detach() to allow the spawned process to detach from the console.
* | libbb: rearrange command line processingRon Yorston2020-04-051-13/+11
| | | | | | | | Process the '--busybox' flag before checking argv[0].
* | xargs: restore correct behaviour of -n optionRon Yorston2020-03-292-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 1ff7002b1 (xargs: fix handling of quoted arguments, closes 11441) the -n option hasn't worked properly: $ echo 1 2 3 | xargs -n 1 echo 1 2 3 $ Because state is now remembered between calls to process_stdin() it's necessary to update the state before any premature return.
* | win32: more improvements to 'c:file' pathsRon Yorston2020-03-292-3/+4
| | | | | | | | | | | | | | | | Tab-completion of 'c:file' paths was leaking memory and incorrectly included BusyBox applets and shell built-ins. Fix handling of 'c:file' paths used as arguments to spawn functions. Otherwise things like 'timeout 5 c:busybox sleep 99' don't work.
* | timeout: fix utter brokennessRon Yorston2020-03-291-0/+1
| | | | | | | | | | The merge from upstream (commit d89ced75b, 2018-09-10) completely broke timeout. Apply a belated fix.
* | dd: create a sparse file when seek=N is usedRon Yorston2020-03-243-0/+21
| | | | | | | | | | | | | | When the seek=N argument is used mark the file as sparse and set the range that is sparse. See https://stackoverflow.com/questions/4011508/how-to-create-a-sparse-file-on-ntfs
* | win32: stat(2): return correct st_blocks for compressed/sparse filesRon Yorston2020-03-241-1/+13
| | | | | | | | | | | | Use GetCompressedFileSize to obtain the actual number of blocks for compressed or sparse files. Use this to return a more accurate value for st_blocks.
* | win32: improve handling of 'c:file' paths for executablesRon Yorston2020-03-182-3/+11
| | | | | | | | | | | | | | | | bb_basename() didn't properly handle paths of the form 'c:file'. Attempting to run 'c:busybox' resulted in 'c:busybox: applet not found'. The shell had a similar problem: trying to run 'c:busybox' reported 'sh: c:busybox: not found'.