aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
| * find: implement -okDavid Leonard2023-03-282-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html -ok utility_name [argument ...] ; The -ok primary shall be equivalent to -exec, except that the use of a <plus-sign> to punctuate the end of the primary expression need not be supported, and find shall request affirmation of the invocation of utility_name using the current file as an argument by writing to standard error as described in the STDERR section. If the response on standard input is affirmative, the utility shall be invoked. Otherwise, the command shall not be invoked and the value of the -ok operand shall be false. function old new delta do_exec 438 517 +79 parse_params 1833 1845 +12 static.params 288 292 +4 .rodata 100771 100775 +4 packed_usage 34543 34541 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 99/-2) Total: 97 bytes Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * fixdep: avoid underflow when end of entry doesn't coincide with EOFArsen Arsenović2023-02-271-0/+5
| | | | | | | | | | | | | | Bug: https://bugs.gentoo.org/893776 Closes: https://bugs.busybox.net/show_bug.cgi?id=15326 Signed-off-by: Arsen Arsenović <arsen@gentoo.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * unzip: document some options we might supportDenys Vlasenko2023-02-231-0/+7
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * unzip: clear SUID/GID bits, implement -K to not clear themDenys Vlasenko2023-02-221-3/+12
| | | | | | | | | | | | | | | | | | | | | | function old new delta unzip_main 2656 2715 +59 packed_usage 34517 34552 +35 .rodata 105250 105251 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 95/0) Total: 95 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * top: stop using div() from libc, compilers now do it betterDenys Vlasenko2023-02-131-9/+16
| | | | | | | | | | | | | | | | | | | | function old new delta div 23 - -23 display_process_list 1237 1178 -59 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-82) Total: -82 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: remove ASH_IGNORE_CR config optionRon Yorston2023-04-096-33/+10
| | | | | | | | | | | | | | | | | | | | | | | | No further problems with CRLF handling have been reported. Remove the configuration option that allowed some recent changes to be turned off. Also, prevent some WIN32 code from being included in the POSIX build. The faulty code is from commit 64c8f5f3d (ash: add support for INT trap). These changes don't alter the default WIN32 build.
* | xargs: kill children when interrupted by Ctrl-CRon Yorston2023-04-071-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A user was running the following command in a clone of the busybox-w32 repo from a busybox-w32 shell using Git for Windows: git rev-list --all | xargs git grep main.c Using Ctrl-C to interrupt the command resulted in the familiar problem that two processes ended up competing for user input: in this case the busybox-w32 shell and the Git for Windows pager, less. Make the problem go away (in this particular case) by killing all the children of xargs when it's interrupted. This is probably a sensible thing to do for other circumstances too. Adds 64-100 bytes. (GitHub issue #306)
* | win32: ignore ctrl-c in parent of execve(2)Ron Yorston2023-04-051-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The execve(2) system call is emulated for Microsoft Windows. This requires the creation of a new process. The old process remains active, waiting for the "execed" child to exit so it can pass on its exit status. Previously this was achieved using P_WAIT mode in the call to spawnve(). However the parent of the execve(2) process may still be able to catch Ctrl-C interrupts. This can lead to unwanted behaviour, such as a shell and its children competing for input. Force the waiting process to ignore Ctrl-C interrupts. Costs 64-80 bytes. (GitHub issue #303)
* | ash: special treatment for read builtinRon Yorston2023-04-051-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When INT is being trapped the read builtin gets special treatment in bash. In a top-level interactive shell interrupting the read with Ctrl-C clears the input and allows the user to enter a new string. In a subshell Ctrl-C really does interrupt the read and the trap isn't executed. zsh works similarly, except that in the latter case the trap is executed. dash interrupts the read and executes the trap in both cases. ksh also interrupts the read in both cases but only executes the trap in the first. Implement the bash behaviour. (GitHub issue #303)
* | ash: reinstate fix for ctrl-c issueRon Yorston2023-04-051-1/+1
| | | | | | | | | | Reinstate the change introduced in commit 96c104a61c (ash: try harder to avoid ctrl-c issue). It was removed during recent work on traps.
* | ash: add support for INT trapRon Yorston2023-04-033-10/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The trap builtin now handles INT. As before, other signals (from a limited list) are accepted but their traps don't have any effect. There's some variability in how shells handle traps. This patch upholds that proud tradition. Various changes are needed to make this work: - Line editing has a new flag to ignore Ctrl-C. - If INT is being trapped or ignored don't call raise_interrupt(). - A minimal implementation of dotrap() is provided. - Call dotrap() when the read builtin or line input detect Ctrl-C. - Adjust Ctrl-C detection when the INT trap is changed. - Set may_have_traps when an INT trap is set. Costs 368-448 bytes. (GitHub issue #303)
* | win32: add fake HUP and QUIT signalsRon Yorston2023-04-032-2/+4
| | | | | | | | | | | | | | | | | | | | | | It's fairly common for shell scripts to trap this set of signals: EXIT HUP INT QUIT TERM (or the numeric equivalent: 0 1 2 3 15) Add definitions for SIGHUP and SIGQUIT. We don't take any action if traps are defined for them, but at least scripts won't fail. (GitHub issue #303)
* | ash: fix POSIX buildRon Yorston2023-04-031-0/+2
| | | | | | | | | | | | Commit 950b318a2 (ash: Unix-style paths, shell builtins and applets) added a call to stack_add_ext_space() which should only be included when building for Microsoft Windows.
* | ash: Unix-style paths, shell builtins and appletsRon Yorston2023-03-311-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some shell builtins also exist as applets: echo, printf, pwd and test, for example. If such an applet is referenced using a Unix- style path, e.g. /usr/bin/echo, the applet should be run rather than the builtin. Instead the current code says: sh: /usr/bin/echo: file not found Rearrange the tests in shellexec() so the correct behaviour occurs. Actually, the error message was also incorrect due to a separate bug. Commit d71cb67ff (win32: revert special treatment of Unix-style absolute paths) failed to allocate space on the stack so that the command passed to tryexec() could have an extension added if required.
* | ash: changes to evalsubshell()Ron Yorston2023-03-281-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When a spawn_forkshell() was required in evalsubshell() two calls to expredir() were being made: one in the parent and one in the child. Rearrange the code so there's only one call, in the child. The call to expredir() in the child is necessary because copynode() doesn't take a copy of expfname in the nfile node. Code could be added to do this but it's cheaper to call expredir(). Add code in forkshell_evalsubshell() to turn off the EV_TESTED flag for background processes. I haven't found a case where this makes a difference but no doubt somebody would have eventually.
* | drop: adjust environment on privilege changeRon Yorston2023-03-272-5/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some environment variables are subject to special treatment: USER, LOGNAME, HOME and SHELL are initialised when the shell starts if they don't already have a value. Some adjustments are necessary when changing privilege level: - USERNAME is added to the set of variables subject to special treatment. Unlike the others this is normally set on Windows. - The special variables are now also updated on shell start up if the current process is running with elevated privileges. This is necessary so USER, USERNAME and LOGNAME have the correct value. - USER, USERNAME and LOGNAME are set to the name of the unprivileged user when elevated privileges are dropped, though not if they've been changed from the expected value of "root". Costs 160-208 bytes. (GitHub issue #300)
* | win32: use CheckTokenMembership() to check privilegeRon Yorston2023-03-251-14/+16
| | | | | | | | | | | | | | Rewrite the test for the reduced-privilege token: check whether the BUILTIN\Administrators group is enabled. This seems more directly relevant than the previous check for restrictions on the token.
* | lineedit: fix matching of directories when searching PATHRon Yorston2023-03-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 8baa643a3 (lineedit: match local directories when searching PATH) included subdirectories of the current directory in the search when tab-completing commands. Unfortunately a short time later commit 1d180cd74 (lineedit: use strncmp instead of is_prefixed_with (we know the length)) broke this feature by returning an incorrect length for the array of paths. Fix the length and reinstate matching of subdirectories. Signed-off-by: Ron Yorston <rmy@pobox.com>
* | drop: cdrop and pdrop don't need shellRon Yorston2023-03-233-12/+38
| | | | | | | | | | | | | | | | | | The cdrop and pdrop variants don't require the binary to include a shell. Removing this dependency makes it possible to build cdrop/pdrop as a much smaller standalone binaries. Update the default configuration to build a standalone make binary to exclude drop/cdrop/pdrop.
* | drop: search PATH for cmd.exe/PowerShellRon Yorston2023-03-231-27/+25
| | | | | | | | | | | | | | | | | | Rather than hardcode the paths of cmd.exe and PowerShell find them by searching PATH. Saves 104-128 bytes. (GitHub issue #240)
* | drop: add cdrop and pdrop aliasesRon Yorston2023-03-194-4/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add cdrop and pdrop applets as aliases for drop. If a command isn't specified these use cmd.exe and PowerShell instead of the BusyBox shell. This makes it possible to choose the default shell used for SSH connections even in older versions of OpenSSH that don't support the DefaultShellArguments registry key. Note that to get cmd.exe to run a command rather than an interactive shell it's necessary to set the DefaultShellCommandOption registry key to '/c'. Costs 248-272 bytes.
* | runuser,drop: drop runuser, tweak dropRon Yorston2023-03-194-52/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the runuser applet, leaving only drop. Move drop from util-linux to miscutils. A command of the form 'drop -c command' causes the BusyBox shell to be used, just like 'drop' without any arguments. A simple OpenSSH configuration with 'drop.exe' as DefaultShell and no DefaultShellArguments now works both for interactive login and to run a command. This is useful for older versions of OpenSSH which don't support DefaultShellArguments. Saves 208-232 bytes.
* | runuser,drop: code shrinkRon Yorston2023-03-192-16/+9
| | | | | | | | | | | | | | | | | | Make quote_arg() always return an allocated string so we can free it unconditionally. Always use argv[1] as the first part of the command string. Saves 48 bytes.
* | win32: delay adjusting code pageRon Yorston2023-03-173-5/+13
| | | | | | | | | | | | | | | | | | | | | | Commit 93a63809f9 (win32: add support for the euro currency symbol) caused all invocations of busybox-w32 to change code page 850 to 858. This has been known to cause problems with fonts in PowerShell (GitHub issue #207). Delay changing the code page until an i/o operation is imminent. Instances of PowerShell started by the `drop` applet during ssh login thus no longer have their code page adjusted.
* | runuser: add 'drop' as an alias for runuserRon Yorston2023-03-164-24/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'drop' alias for 'runuser' relaxes a number of constraints that were introduced for compatibility: - It works even if the current process doesn't have elevated privileges. - It isn't necessary to specify the name of the user. - Any command can be invoked, not just the BusyBox shell. - If the command doesn't specify a path 'drop' will first look for a BusyBox applet then search PATH. Adds 320-336 when built along with runuser. (GitHub issue #240)
* | make: code shrinkRon Yorston2023-03-161-2/+2
| | | | | | | | | | | | Use alloc_ext_space() instead of a hand-coded equivalent. Saves 16-32 bytes.
* | win32: code shrink detection of executablesRon Yorston2023-03-165-28/+41
| | | | | | | | | | | | | | | | | | | | | | | | Add a function, file_is_win32_exe(), to detect if a path refers to an executable. It tries adding extensions if necessary. Use this in a number of places to replace common code of the form path = alloc_ext_space(cmd); if (add_win32_extension(path) || file_is_executable(path)) Saves 32-48 bytes.
* | runuser: new appletRon Yorston2023-03-136-15/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a cut down, Windows-specific implementation of `runuser` from util-linux. This allows elevated privileges to be dropped when running in an SSH session. It also works when using `su` or starting busybox-w32 'as administrator'. There are complications: - The method used to drop privileges leaves the access token in the TokenIsElevated state. Detecting this is likely to be fragile. - The unprivileged shell is started by CreateProcessAsUserA(). In older versions of Windows this has to be loaded dynamically. Adds about 900 bytes. (GitHub issue #240)
* | win32: more changes to console/terminal modesRon Yorston2023-03-072-32/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allowing virtual terminal input mode to be set if available proved to be unhelpful: cmd.exe doesn't understand such newfangled stuff (though PowerShell does). The allowed values of BB_TERMINAL_MODE are changed to: 0 Force console mode. 1 Force virtual terminal mode for output. 2 Force virtual terminal mode for input. 3 Force virtual terminal mode for input and output. 4 Support virtual terminal input if enabled. Don't alter mode. 5 Support virtual terminal input if enabled. Set virtual terminal mode for output, if possible. The default is 5.
* | win32: virtual terminal input fixesRon Yorston2023-03-065-11/+10
| | | | | | | | | | | | | | | | | | | | | | - Disable ENABLE_PROCESSED_INPUT in raw mode. Otherwise ^C isn't immediately detected during shell command line editing with virtual terminal input enabled. - Switch read_key()/unix_readkey() to windows_read_key()/read_key(). This allows the shell `read` builtin to use windows_read_key(). Without this change `read` fails when virtual terminal input is enabled.
* | win32: add support for virtual terminal inputRon Yorston2023-03-054-32/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Alter certain applets to support virtual terminal input, if enabled. In many places this is achieved by building previously excluded upstream terminal-handling code. The busybox-w32 implementation of termios(3) functions does nothing if virtual terminal input is disabled, so it can be invoked regardless. Some applet-specific terminal-handling code is also required. This affects less, more, vi and command line editing in the shell. (The `more` applet isn't enabled in the default configuration.) This series of patches adds about 1.7KB to the binaries.
* | win32: enable Unix read_key() for virtual terminalRon Yorston2023-03-054-5/+11
| | | | | | | | | | | | | | Until now busybox-w32 has used a native Windows implementation of read_key(). Build the upstream Unix implementation and use it instead of the native version when virtual terminal input mode is enabled.
* | win32: add virtual terminal support to termios(3)Ron Yorston2023-03-053-114/+50
| | | | | | | | | | | | | | | | | | | | | | | | Modify `struct termios` to support Windows virtual terminals. Native console mode flags replace the Unix `c_?flag` structure members. Remove unsupported flags from termios.h. Add implementations of tcgetattr(3)/tcsetattr(3) to get/set console flags when virtual terminal input mode is enabled. Add support for emulating raw mode to get_termios_and_make_raw(). This (and related functions) are exposed but not yet used.
* | win32: changes to console mode handlingRon Yorston2023-03-0511-43/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add the environment variable BB_TERMINAL_MODE as a more general way of controlling console/terminal mode setting. The default remains unchanged: use virtual terminal mode for output if possible but fall back to the console API with emulated ANSI escape sequences. Currently valid settings are: 0 Force use of console mode 1 Force use of virtual terminal mode for output 5 Prefer virtual terminal mode for output, fall back to console Other values won't do anything useful until code elsewhere has been updated. BB_SKIP_ANSI_EMULATION remains available for backwards compatibility. If both variables are set BB_TERMINAL_MODE takes precedence.
* | ash: drop workaround for 'read -t 0'Ron Yorston2023-03-051-12/+0
| | | | | | | | | | | | | | | | | | Commit 0eda390d6 (ash: improve handling of 'read -t 0') added code to work around the limitations of our poll(2) implementation. Now that poll(2) has been improved the workaround is unnecessary. Saves 64 bytes.
* | nc: switch to using poll(2)Ron Yorston2023-03-031-49/+2
| | | | | | | | | | | | | | | | | | | | | | | | Upstream started using poll(2) rather than select(2) in `nc` some time ago, in commit 5b3b468ec (nc: use poll() instead of select()). Now that poll(2) in busybox-w32 has been updated to work with `nc` switch to using the same code as upstream. As a result of this change nothing in busybox-w32 now uses the select(2) implementation. This reduces the size of the binaries by about 3.4KB.
* | win32: revise poll(2) for use in ncRon Yorston2023-03-031-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit 5b3b468ec (nc: use poll() instead of select()) changed `nc` to use poll(2) instead of select(2), obviously. In busybox-w32 select(2) had already been hacked to support `nc`. To avoid hacking poll(2) too the upstream change was reverted (c2002eae3). Later `nc` was altered to include the code for both poll and select (3c85cc0c4). Make the changes necessary for poll(2) to work with `nc` on Windows. These are all in the function windows_compute_revents(). Treat a character file that isn't a console as a normal file. Without this `nc 127.0.0.1 1234 </dev/null` doesn't work. Return 0 instead of POLLHUP if GetNumberOfConsoleInputEvents() indicates no events are available. Without this communication between two instances of `nc` which are both using keyboard input isn't as asynchronous as one would like. Only process key press events: key releases are ignored. Without this `nc 127.0.0.1 1234` won't receive anything from the server until the local user presses a key. In the default case, which now includes disk files and character files, detect polling for reads as well as writes. Without this `nc 127.0.0.1 1234 <local_file` doesn't work.
* | win32: update poll(2) to match latest gnulib versionRon Yorston2023-03-031-12/+37
| |
* | win32: try to recover from strange console modeRon Yorston2023-02-211-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Execute a remote command on a Windows server using ssh: ~$ ssh localhost 'echo hello' rmy@localhost's password: hello If such a command is run from a busybox-w32 shell the console enters a strange mode when the command completes. Attempt to recover by setting the console back to a default mode. - This doesn't work in a legacy console. - The new mode may not be _exactly_ correct, but it's better than how ssh leaves it. Costs 80-96 bytes. (GitHub issue #288)
* | ash: revised CRLF handling for scriptsRon Yorston2023-02-211-1/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in commit 2d848eba5 (ash: fix CRLF handling), removing CRs from CRLF pairs in preadbuffer() is complicated by the possibility that a CRLF pair might be split across the boundary between buffers. Add a wrapper around calls to nonblock_immune_read() to allow for this. Adds 104-128 bytes. (GitHub issue #280)
* | ash: revert changes to handle CRLF in scriptsRon Yorston2023-02-211-34/+4
| | | | | | | | | | | | | | Commit 4b894b60a doesn't seem to have worked out. Revert it and the fix in 6e0a6b7e5. We're now back to removing CRs unconditionally from shell scripts.
* | ash: really reset ANSI emulation in interactive modeRon Yorston2023-02-201-2/+2
| | | | | | | | | | | | | | | | | | Commit 329f907b2 (ash: only reset ANSI emulation in interactive loop) claimed to move resetting of ANSI emulation up into the main interactive loop. Unfortunately it *just* missed the if-block for interactive mode. Put the call to skip_ansi_emulation() in the right place.
* | win32: shuffle skip_ansi_emulation() codeRon Yorston2023-02-191-6/+8
| | | | | | | | | | Rearrange code to avoid unnecessary tests when the environment variable BB_SKIP_ANSI_EMULATION is set.
* | win32: work around problem with ConEmuRon Yorston2023-02-191-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running the busybox-w32 shell in ConEmu, if: - ANSI emulation is disabled (which it will be, by default) - a non-builtin command is run there is a window of a few seconds after the command completes during which ConEmu is in XTerm mode. During this time any attempt to use the arrows keys will result in [A[B[C[D appearing. This appears to be a common problem: https://github.com/Maximus5/ConEmu/issues/2316 Try to detect if we're running under ConEmu and alter the default behaviour to prefer ANSI emulation. The user can override this preference by setting BB_SKIP_ANSI_EMULATION if desired. By a quirk of fate, old MSYS2 programs (from 2021) which required a workaround in busybox-w32 (commit 54d2ea4b4) are immune to the problem with ConEmu. (GitHib issue #287)
* | win32: only change console mode if necessaryRon Yorston2023-02-191-7/+10
| | | | | | | | | | In skip_ansi_emulation() only call SetConsoleMode() if the new mode differs from the current mode.
* | ash: only reset ANSI emulation in interactive loopRon Yorston2023-02-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | Commit 54d2ea4b4 (ash: reset ANSI emulation at prompt) worked around a problem with MSYS2 applications. This seems to have been fixed in more recent versions of MSYS2 but there's still value in retaining the workaround for other such cases. However, the call to reset ANSI emulation is probably being made more often than necessary. Move it out of setprompt_if() and into the main shell interactive loop.
* | ash: skip CR when detecting end of here documentFRP-4882-g6e0a6b7e5Ron Yorston2023-02-151-1/+1
| | | | | | | | | | | | The change introduced by commit 4b894b60a (ash: change CRLF handling) failed to detect the end of a here document with a CRLF line ending. Add the necessary check.
* | win32: skip ACL check in stat(2) when running as rootFRP-4881-ga6c5fd4ebRon Yorston2023-02-131-1/+2
| | | | | | | | | | | | | | | | | | | | Commit 88965fe20 (win32: use ACL check to clarify write permission) added code to check if a file had write permission due to an ACL entry. When running with elevated privileges this check is unnecessary as "user" permissions will be sufficient. This also prevents write permission for "other" being set without respecting umask.
* | Merge branch 'busybox' into mergeRon Yorston2023-02-136-41/+77
|\|
| * hush: restore SIGHUP handling, this time explain why we do what we doDenys Vlasenko2023-01-301-20/+28
| | | | | | | | | | | | | | function old new delta check_and_run_traps 229 278 +49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>