diff options
author | Ron Yorston <rmy@pobox.com> | 2023-05-02 11:01:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-05-02 11:01:10 +0100 |
commit | a0ed5a7ceaf4636eab0bb66b523a9eaf437acbe8 (patch) | |
tree | 3e0cc20a5c4e83954302ff41cc8e87c6c69636ee /loginutils | |
parent | 61be00816a0c09379b4b3f2655c70e9e14bc0841 (diff) | |
download | busybox-w32-a0ed5a7ceaf4636eab0bb66b523a9eaf437acbe8.tar.gz busybox-w32-a0ed5a7ceaf4636eab0bb66b523a9eaf437acbe8.tar.bz2 busybox-w32-a0ed5a7ceaf4636eab0bb66b523a9eaf437acbe8.zip |
su: add option to keep console open on shell exit
The '-N' option keeps the console window open after the elevated
shell exits.
Previously this was achieved by passing the '-s' option along with
'-c'. Recent changes allow scripts to be run without using '-c'
so a new mechanism is required.
su passes the '-N' flag to the shell. This causes the shell to
issue a prompt and wait for user input when it exits.
Costs 200-204 bytes.
Diffstat (limited to 'loginutils')
-rw-r--r-- | loginutils/suw32.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c index b0fb26442..236d36a77 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c | |||
@@ -16,12 +16,13 @@ | |||
16 | //kbuild:lib-$(CONFIG_SUW32) += suw32.o | 16 | //kbuild:lib-$(CONFIG_SUW32) += suw32.o |
17 | 17 | ||
18 | //usage:#define suw32_trivial_usage | 18 | //usage:#define suw32_trivial_usage |
19 | //usage: "[-W] [root]\n" | 19 | //usage: "[-NW] [root]\n" |
20 | //usage: "or: su [-W] -c CMD_STRING [[--] root [ARG0 [ARG...]]\n" | 20 | //usage: "or: su [-NW] -c CMD_STRING [[--] root [ARG0 [ARG...]]\n" |
21 | //usage: "or: su [-W] [--] root [arbitrary sh arguments]" | 21 | //usage: "or: su [-NW] [--] root [arbitrary sh arguments]" |
22 | //usage:#define suw32_full_usage "\n\n" | 22 | //usage:#define suw32_full_usage "\n\n" |
23 | //usage: "Run shell with elevated privileges\n" | 23 | //usage: "Run shell with elevated privileges\n" |
24 | //usage: "\n -c CMD Command to pass to 'sh -c'" | 24 | //usage: "\n -c CMD Command to pass to 'sh -c'" |
25 | //usage: "\n -N Don't close console when shell exits" | ||
25 | //usage: "\n -W Wait for shell exit code" | 26 | //usage: "\n -W Wait for shell exit code" |
26 | 27 | ||
27 | #include "libbb.h" | 28 | #include "libbb.h" |
@@ -29,7 +30,8 @@ | |||
29 | 30 | ||
30 | enum { | 31 | enum { |
31 | OPT_c = (1 << 0), | 32 | OPT_c = (1 << 0), |
32 | OPT_W = (1 << 1) | 33 | OPT_N = (1 << 1), |
34 | OPT_W = (1 << 2) | ||
33 | }; | 35 | }; |
34 | 36 | ||
35 | int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 37 | int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -41,7 +43,7 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
41 | char *bb_path, *cwd, *q, *args; | 43 | char *bb_path, *cwd, *q, *args; |
42 | DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); | 44 | DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); |
43 | 45 | ||
44 | opt = getopt32(argv, "c:W", &opt_command); | 46 | opt = getopt32(argv, "c:NW", &opt_command); |
45 | argv += optind; | 47 | argv += optind; |
46 | if (argv[0]) { | 48 | if (argv[0]) { |
47 | if (strcmp(argv[0], "root") != 0) { | 49 | if (strcmp(argv[0], "root") != 0) { |
@@ -78,8 +80,11 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
78 | free(q); | 80 | free(q); |
79 | free(cwd); | 81 | free(cwd); |
80 | 82 | ||
83 | if (opt & OPT_N) | ||
84 | args = xappendword(args, "-N"); | ||
85 | |||
81 | if (opt_command) { | 86 | if (opt_command) { |
82 | args = xappendword(args, "-s -c"); | 87 | args = xappendword(args, "-c"); |
83 | q = quote_arg(opt_command); | 88 | q = quote_arg(opt_command); |
84 | args = xappendword(args, q); | 89 | args = xappendword(args, q); |
85 | free(q); | 90 | free(q); |