aboutsummaryrefslogtreecommitdiff
path: root/loginutils/suw32.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* su: allow additional arguments after su -csu_cmdRon Yorston2023-04-211-9/+17
| | | | | | | | | | | | | | | | | | | | | | The syntax becomes: su [-c CMD [ARG...]] This makes it a lot easier to use values from the current shell, instead of shell-quoting them for re-input and embedding at CMD. Also, previously -c expected an option-argument, and now it's a flag which requires a CMD operand, just like 'sh', so that both these forms now error the same way (as they should): sh -c -- su -c -- (previously su -c -- did not error because '--' was assumed CMD) Adds 64 bytes. (Based on GitHub PR #317)
* su: escape quotes and backslashes in commandRon Yorston2023-04-211-1/+1
| | | | | | | | | | | | | | In 'su -c "CMD"' CMD should become a single argument to busybox sh -c ... But previously, the parameter string to ShellExecute was constructed by placing the literal value of CMD inside double quotes, which could result in incorrect and/or more than one parameter seen by the program, because double-quotes and (some) backslashes in CMD should be escaped while constructing the string, but they weren't. Now they're escaped so that the WIN32 CommandLineToArgv[W] parses it into a single argument with value identical to the original CMD.
* win32: use lazy loading for certain DLLsRon Yorston2020-06-021-1/+6
| | | | | | | | | 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: add function to convert slashes to backslashesRon Yorston2019-03-151-6/+3
| | | | | | | | | There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs().
* su: canonicalise directory before elevating privilegesRon Yorston2019-03-141-5/+11
| | | | | | If the current directory is in a drive mapped to a network share we may not be able to access it once we have elevated privileges. Avoid this by canonicalising the path before calling ShellExecuteEx().
* win32: changes to user idsRon Yorston2019-03-101-3/+5
| | | | | | | | | | | | | | | | Formalise the use of 0 as the uid of a process running with elevated privileges: - Rewrite getuid(2) to return DEFAULT_UID by default and 0 if the process has elevated privileges. - geteuid(2) and the corresponding functions for groups are aliases for getuid(2). - Change root's home directory to be whatever GetSystemDirectory() returns, probably C:/Windows/System32 in most cases. - Remove the special handling of geteuid(2) in the line editing code. With these changes the shell started by 'su' is a lot more like a *nix root shell.
* su: change title of console windowRon Yorston2019-03-091-1/+3
|
* su: work when binary has a UNC pathRon Yorston2019-03-091-1/+11
| | | | | | ShellExecuteEx() requires backslashes as the file separator if the binary to be executed has a UNC path. Convert separators unconditionally.
* su, wget: use magic '--busybox' flagRon Yorston2019-03-081-5/+2
| | | | | | I've been a bit lax about ensuring the --busybox flag is passed in command lines. It's needed to avoid problems if the binary is called something like sh.exe.
* ash, su: add -d flag to set directory in ash, use it in suRon Yorston2019-03-081-2/+5
| | | | | | | | When busybox-w32 is installed in C:/Windows/System32 su doesn't run in the same directory as its parent as intended. Work around this by adding a flag to the shell to set the working directory.
* su: add a basic implementation for WIN32Ron Yorston2019-03-071-0/+50
Use the undocumented 'runas' verb in a call to ShellExecuteEx() to run a shell with elevated privileges. Because of the way ShellExecuteEx() works this: - requires that you acknowledge a User Account Control prompt (if you're an Administrator); - requires that you enter an Administrator's password (if you aren't an Administrator); - creates a separate console window for the privileged shell. Variables from the parent shell aren't passed to its privileged child, only variables from the environment. It's possible to specify a command to run when the shell starts. This can be used to pass shell variables: su -c "HELLO='hello world'; GOODBYE=$GOODBYE" Or do fancy things like: su -c "ls -l; read -p 'Hit return to exit: '; exit" It's probably best to put double quotes around the command and use single quotes inside it. Apparently ShellExecuteEx() requires double quotes to be entered in triplicate: su -c 'HELLO="""hello world"""'