diff options
-rw-r--r-- | loginutils/suw32.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c index 79637dd77..f8440b93e 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c | |||
@@ -11,9 +11,18 @@ | |||
11 | //config: help | 11 | //config: help |
12 | //config: su runs a shell with elevated privileges. | 12 | //config: su runs a shell with elevated privileges. |
13 | 13 | ||
14 | //config:config SUSH | ||
15 | //config: bool "sush" | ||
16 | //config: default y | ||
17 | //config: depends on PLATFORM_MINGW32 && ASH | ||
18 | //config: help | ||
19 | //config: Run a shell with elevated privileges | ||
20 | |||
14 | //applet:IF_SUW32(APPLET_ODDNAME(su, suw32, BB_DIR_BIN, BB_SUID_DROP, suw32)) | 21 | //applet:IF_SUW32(APPLET_ODDNAME(su, suw32, BB_DIR_BIN, BB_SUID_DROP, suw32)) |
22 | //applet:IF_SUSH(APPLET_ODDNAME(sush, suw32, BB_DIR_USR_BIN, BB_SUID_DROP, sush)) | ||
15 | 23 | ||
16 | //kbuild:lib-$(CONFIG_SUW32) += suw32.o | 24 | //kbuild:lib-$(CONFIG_SUW32) += suw32.o |
25 | //kbuild:lib-$(CONFIG_SUSH) += suw32.o | ||
17 | 26 | ||
18 | //usage:#define suw32_trivial_usage | 27 | //usage:#define suw32_trivial_usage |
19 | //usage: "[-c \"CMD\"]" | 28 | //usage: "[-c \"CMD\"]" |
@@ -21,6 +30,13 @@ | |||
21 | //usage: "Run shell with elevated privileges\n" | 30 | //usage: "Run shell with elevated privileges\n" |
22 | //usage: "\n -c CMD Command to pass to 'sh -c'" | 31 | //usage: "\n -c CMD Command to pass to 'sh -c'" |
23 | 32 | ||
33 | //usage:#define sush_trivial_usage | ||
34 | //usage: "[-c \"CMD\" [ARG...] | FILE [ARG...]]" | ||
35 | //usage:#define sush_full_usage "\n\n" | ||
36 | //usage: "Run shell with elevated privileges\n" | ||
37 | //usage: "\n -c CMD [ARG...] Script [args] to pass to 'sh -c'" | ||
38 | //usage: "\n FILE [ARG...] Command file [args] to pass to 'sh'" | ||
39 | |||
24 | #include "libbb.h" | 40 | #include "libbb.h" |
25 | #include "lazyload.h" | 41 | #include "lazyload.h" |
26 | 42 | ||
@@ -31,12 +47,17 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
31 | unsigned opts, c_opt; | 47 | unsigned opts, c_opt; |
32 | char *command, *bb_path, *cwd; | 48 | char *command, *bb_path, *cwd; |
33 | DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); | 49 | DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); |
50 | #if ENABLE_SUSH | ||
51 | int is_sush = applet_name[2]; | ||
52 | #else | ||
53 | const int is_sush = 0; | ||
54 | #endif | ||
34 | 55 | ||
35 | opts = getopt32(argv, "c"); | 56 | opts = getopt32(argv, "c"); |
36 | c_opt = opts & 1; | 57 | c_opt = opts & 1; |
37 | argv += optind; | 58 | argv += optind; |
38 | command = c_opt ? *argv++ : NULL; | 59 | command = c_opt ? *argv++ : NULL; |
39 | if ((c_opt && !command) || (!c_opt && command) || *argv) { | 60 | if ((c_opt && !command) || (!c_opt && command) || (!is_sush && *argv)) { |
40 | // -c without CMD, operand without -c , or surplus arguments | 61 | // -c without CMD, operand without -c , or surplus arguments |
41 | bb_show_usage(); | 62 | bb_show_usage(); |
42 | } | 63 | } |
@@ -69,6 +90,13 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
69 | info.lpParameters = xappendword(info.lpParameters, "-s -c --"); | 90 | info.lpParameters = xappendword(info.lpParameters, "-s -c --"); |
70 | info.lpParameters = xappendword(info.lpParameters, quote_arg(command)); | 91 | info.lpParameters = xappendword(info.lpParameters, quote_arg(command)); |
71 | } | 92 | } |
93 | #if ENABLE_SUSH | ||
94 | while (*argv) { | ||
95 | char *a = quote_arg(*argv++); | ||
96 | info.lpParameters = xappendword(info.lpParameters, a); | ||
97 | free(a); | ||
98 | } | ||
99 | #endif | ||
72 | /* info.lpDirectory = NULL; */ | 100 | /* info.lpDirectory = NULL; */ |
73 | info.nShow = SW_SHOWNORMAL; | 101 | info.nShow = SW_SHOWNORMAL; |
74 | 102 | ||