aboutsummaryrefslogtreecommitdiff
path: root/win32 (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* win32: make support for euro input a separate optionRon Yorston2023-06-221-4/+4
| | | | | | | | | | | | | | | | | Commit 93a63809f (win32: add support for the euro currency symbol) made various changes to enable support for the euro symbol. One of these changes allows the euro to be entered from the console even if the current code page doesn't support it. This is probably of limited use: the symbol can be entered but won't be displayed correctly. Move this capability into a separate configuration option, FEATURE_EURO_INPUT, which is disabled by default. Saves 48-64 bytes in the new default case. (GitHub issue #335)
* win32: include UTF-8 manifestRon Yorston2023-06-203-0/+14
| | | | | | | | Include a manifest in the binary to set the process code page to UTF-8. This only has an effect from Windows 10 version 1903. Controlled by the FEATURE_UTF8_MANIFEST config setting, disabled by default.
* Fix for old mingw-w64 (32-bit)Ron Yorston2023-06-151-0/+3
| | | | | | It appears that RtlGenRandom() wasn't supported in 32-bit builds using mingw-w64 until version 7.0.0 (Fedora 33). Use the time to initialise the PRNG in earlier versions.
* Fixes for old mingw-w64Ron Yorston2023-06-141-0/+4
| | | | | | | | | | | | | Allow current busybox-w32 to build with the CentOS 6 version of mingw-w64. - Fix declaration of setlinebuf(). (GitLab issue 116) - Define ENABLE_VIRTUAL_TERMINAL_INPUT. (GitLab issue 117) - Define IO_REPARSE_TAG_APPEXECLINK. - Avoid a compiler warning in coreutils/shuf.c.
* win32: code shrinkRon Yorston2023-06-041-7/+2
| | | | | | | | | | | | | | | | | | | getsysdir() wasn't used in get_proc_addr() because the former called realpath() which in turn called the latter. (Commit 4c6c8d61bc) realpath() was used to adjust the case of the path name as it was visible to the user as root's home directory. (Commit b04bbc0109) Later the home directory for "root" was changed so it no longer needed getsysdir(). (Commit 385decd6bf) The remaining uses of getsysdir() don't require the path to be canonicalised, so realpath() can be removed from getsysdir() and getsysdir() can be used in get_proc_addr(). Saves 32-64 bytes
* win32: change interpretation of BB_OVERRIDE_APPLETSRon Yorston2023-06-021-10/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Make the following changes to BB_OVERRIDE_APPLETS: - Applet names in the list can be separated by spaces, commas or semicolons. - Applets before the first semicolon are disabled unconditionally. - Applets after the first semicolon are overridden if a matching external command exists. - '-' alone disables all applets. - '+' alone overrides every applet for which a matching external command exists. This doesn't change the existing documented behaviour. It adds the ability to have applets overridden if an external command exists but to remain available if not. Adds 80-88 bytes. (GitHub issue #329)
* win32: fix euro symbol handlingRon Yorston2023-06-021-3/+1
| | | | | | | | | | | | Commit 2b4dbe5fa (libbb: speed up bb_get_chunk_from_file()) speeded up grep by a factor of two. However, it introduced a call to OemToCharBuff() in bb_get_chunk_from_file() which didn't have the fix for the euro symbol from commit 93a63809f9 (win32: add support for the euro currency symbol). Export the fixed version of OemToCharBuff() and use it. Saves 8 bytes (64-bit), adds 28 bytes (32-bit)
* win32: skip test for non-console apps if necessaryRon Yorston2023-06-021-0/+4
| | | | | | | | | Commit 20b6a57af (win32: crtl-c interrupts non-console applications) introduced a test for non-console apps in the Ctrl-C handler. Skip this if GetConsoleProcessList() isn't available. Costs 68-88 bytes.
* ash: enable 'set -/+o noconsole'Ron Yorston2023-06-011-8/+6
| | | | | | | | | | | | | | Previously the 'noconsole' shell option could only be set as a shell command line option. Allow it to be changed from within the shell by 'set -o noconsole' or 'set +o noconsole'. The console window is now minimised rather than hidden. This makes it easier for the user to access the console when 'noconsole' is in effect. Adds 8-32 bytes. (GitHub issue #325)
* win32: support "app exec link" reparse pointsRon Yorston2023-05-271-1/+36
| | | | | | | | | | | | | | | | | | Reparse points with the tag IO_REPARSE_TAG_APPEXECLINK are present in ~/AppData/Local/Microsoft/WindowsApps in Windows 10 and 11. They are: Used by Universal Windows Platform (UWP) packages to encode information that allows the application to be launched by CreateProcess. Modify readlink(2) and lsattr(1) to treat them as symbolic links, in much the same way as was done previously for junctions. They aren't really symbolic links but they're similar. Costs 128-160 bytes. (GitHub issue #327)
* win32: crtl-c interrupts non-console applicationsRon Yorston2023-05-231-1/+36
| | | | | | | | | | | | | | | | | | | Commit 9db9b34ad (win32: ignore ctrl-c in parent of execve(2)) prevented a parent process from reacting to Ctrl-C while it was waiting for its child to complete. This avoids the problem where a shell and an interactive child end up competing for input after a Ctrl-C. However, a child process which isn't attached to the console (a GUI application, for example) can't then be killed by Ctrl-C. Instead of completely ignoring Ctrl-C give the parent a handler which detects if its child is attached to the console. If so it's left to handle Ctrl-C itself and the parent ignores the interrupt. If not the parent terminates the child and all its children as if by SIGINT. Costs 200 bytes.
* win32: changes to signal handlingRon Yorston2023-05-231-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | Use an exit code of the form (signal << 24) when a process exits due to a signal. This replaces the previous use of (signal + 128). This makes it easier to distinguish exit codes from signals. Allow kill(2) to handle all defined signals, not just EXIT, TERM and KILL. The kill and timeout applets now accept any defined signals. Convert certain Windows status codes Unix-style signal codes. In ash: - Exit as if with SIGINT in raise_interrupt() rather than call raise(SIGINT). The latter returns an exit code of 3. - Detect if a child process exits as if with SIGINT. If not and if the parent is an interactive top-level shell, reset pending_int. This prevents the parent from seeing an INT if the child hasn't reported it exited due to INT. (Probably due to it being an interactive shell.) Costs 132-136 bytes.
* win32: further code shrink quote_args()Ron Yorston2023-04-281-19/+3
| | | | | | | | Squeeze a few more bytes out of quote_args(). (Thanks to GitHub user avih.) Saves 16 bytes.
* win32: code shrink copying of argvRon Yorston2023-04-281-4/+14
| | | | | | | There are two places where a copy of an argv array is made with extra space at the start. Move this code into a function. Saves 56-64 bytes.
* win32: improved error for overlong command lineRon Yorston2023-04-271-1/+6
| | | | | | | | Report 'Arg list too long' rather than 'Invalid argument' when spawnveq() detects that the EINVAL return from spawnve() is due to the command line being too long. Costs 48-64 bytes.
* win32: code shrink quote_args()Ron Yorston2023-04-271-58/+20
| | | | | | | | | | | | | | | Replace parts of quote_args() with code from avih's GitHub PR #317. This overestimates the size of the buffer to avoid having to calculate the exact size. Retain the code to determine whether the argument needs to be quoted. Quoting arguments unconditionally wastes space on the command line and causes the test "xargs argument line too long" to fail. Saves 144-176 bytes.
* win32: export xappendword()Ron Yorston2023-04-231-0/+12
| | | | | | | Export the function xappendword() from make. Use it in drop and watch. Saves 8-80 bytes, an unusually large disparity.
* win32: further fix incorrect path search in spawnvpRon Yorston2023-04-161-1/+3
| | | | | | | | Commit 9581d2396 (win32: fix incorrect path search in spawnvp) fixed the unwanted PATH search for relative or absolute paths but broke the desired PATH search for Unix-style paths. (GitHub issue #310)
* win32: fix incorrect path search in spawnvpRon Yorston2023-04-141-3/+1
| | | | | | | | | Commit 26ba73098e (win32: search PATH for missing Unix-style executables) rearranged the code of mingw_spawnvp(). As a result commands with a relative or absolute path could be incorrectly searched for on PATH. (GitHub issue #310)
* 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)
* 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.
* drop: add cdrop and pdrop aliasesRon Yorston2023-03-191-1/+1
| | | | | | | | | | | | | | | | 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-191-1/+1
| | | | | | | | | | | | | | 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-191-3/+2
| | | | | | | | | 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-171-1/+12
| | | | | | | | | | | 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-162-2/+2
| | | | | | | | | | | | | | | | | | | 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)
* win32: code shrink detection of executablesRon Yorston2023-03-162-16/+29
| | | | | | | | | | | | 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-132-13/+32
| | | | | | | | | | | | | | | | | | | | | 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-071-19/+19
| | | | | | | | | | | | | | | | | | 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-061-4/+1
| | | | | | | | | | | - 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: enable Unix read_key() for virtual terminalRon Yorston2023-03-051-1/+4
| | | | | | | 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-052-111/+45
| | | | | | | | | | | | 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-051-20/+56
| | | | | | | | | | | | | | | | | | | 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.
* 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)
* 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.
* 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.
* ash,make: fix CRLF handlingRon Yorston2023-01-301-2/+3
| | | | | | | Fix remove_cr() so it only removes CRs which are part of a CRLF pair, not every CR. Add a test case for the shell.
* win32: provide a default value for HOMERon Yorston2023-01-291-5/+11
| | | | | | | | | | | | | | | | The busybox-w32 shell initialises HOME when it starts. However, if applets are run outside the environment provided by the shell they may find HOME is unset. This caused a problem for 'vi' as it was unable to locate its .exrc. If HOME isn't available in the environment make getenv(3) provide a sensible default value. The shell must use the *real* getenv(3) when determining if HOME is already set. Also, unrelated to the above, the shell shouldn't treat failure of getpwuid(3) as a fatal error. Costs 72-80 bytes.
* win32: another stat(2) + access time fixRon Yorston2023-01-261-1/+1
| | | | | | | | Use FILE_SHARE_READ when opening a file to check if it's an executable. Without that other processes running in parallel might be unable to access the file. (GitHub issue #284)
* make: allow building as pdpmake onlyRon Yorston2023-01-241-0/+1
| | | | | | | | | Commit f261d2d27 (make: make + sh configuration) added 'pdpmake' as an alias for 'make'. It should have been possible to include 'pdpmake' in a build without also including 'make'. Adjust the build configuration so this works as intended.
* win32: only count subdirectories if necessaryRon Yorston2023-01-231-3/+15
| | | | | | | | | | | | | | | | | Commit 7fb95a2a5 (win32: try to get link count for directories) allowed stat(2) to report accurate values of st_nlink for directories. There are only a couple of places in busybox-w32 where these values are required. Disable counting of subdirectories by default and only enable it when necessary. Microsoft kindly provide directories to test edge cases like this: C:/Windows/WinSxS (contains many subdirectories) C:/Windows/WinSxS/Manifests (contains many files) Adds 84-112 bytes.
* win32: limit setting of errno when lazy loading failsRon Yorston2023-01-221-3/+3
| | | | | | | | | | | | The function get_proc_addr() facilitates dynamic loading of functions from DLLs. In the event of failure it set errno to ENOSYS. This is sometimes useful, such as in the implementations of link(2), symlink(2) and realpath(3). However, many other uses of lazy loading can recover from failure or simply don't care. In these cases setting errno is unnecessary and may be counterproductive. (GitHub issue #283)
* win32: reset errno in read_key()Ron Yorston2023-01-221-0/+1
| | | | | | | | | | | | | The WIN32 implementation of read_key() didn't reset errno to zero, unlike the upstream version. This could result in invalid non-zero errno values after calls to lineedit_read_key(). For example, after an attempt to run a non-existent command in the shell errno is set to ENOENT. If the shell had vi line edit mode enabled any command that reads an additional character (e.g. 'c' or 'd') would see the non-zero errno and report EOF. (GitHub issue #283)
* win32: more minor improvements to stat(2)Ron Yorston2023-01-181-29/+26
| | | | | | | | | | | | | | | | The previous commit incorrectly stated that preventing the access time of a file from being updated only required it to be opened with GENERIC_READ access. In fact, even though we don't want to update the access time, SetFileTime() also requires the file to have been opened with FILE_WRITE_ATTRIBUTES access. There's no need to explicitly avoid device files when checking for execute mode: since device files are now 'character special' they are excluded by the test that the file is 'regular'. Device files should be excluded when trying to obtain extra file data using GetFileInformationByHandle(). It shouldn't be possible for CreateFile() to open then, so there's no point in trying.
* win32: minor improvements to stat(2)Ron Yorston2023-01-171-9/+9
| | | | | | | | | | | Commit b11352dcb (win32: prevent stat(2) from updating access times) requested GENERIC_ALL access when opening files. It appears that GENERIC_READ is sufficient and also faster. The code to find the actual size of compressed or sparse files only needs to be invoked for regular files. Avoiding unnecessary calls to GetCompressedFileSize() makes stat(2) slightly faster and gives a more accurate number of blocks for symbolic links.
* win32: use ACL check to clarify write permissionRon Yorston2023-01-161-27/+30
| | | | | | | | | | | | | | | | | On Microsoft Windows a user's home directory doesn't belong to them: it actually belongs to the 'system' user. stat(2) was only using ownership to determine write permissions, so it seemed that the user was unable to write to their own home directory. Use a call to AccessCheck() to determine if files can be accessed due to an entry in their ACL. User home directories and a few other files (e.g. C:/Users/Public) now have the correct write permission. This feature is enabled by FEATURE_EXTRA_FILE_DATA. Costs 220-256 bytes. (GitHub issue #280)