aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--loginutils/suw32.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c
index df6d07232..46196d14c 100644
--- a/loginutils/suw32.c
+++ b/loginutils/suw32.c
@@ -16,10 +16,10 @@
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: "[-c \"CMD\"]" 19//usage: "[-c \"CMD\" [ARG...]]"
20//usage:#define suw32_full_usage "\n\n" 20//usage:#define suw32_full_usage "\n\n"
21//usage: "Run shell with elevated privileges\n" 21//usage: "Run shell with elevated privileges\n"
22//usage: "\n -c CMD Command to pass to 'sh -c'" 22//usage: "\n -c CMD [ARG...] Command [args] to pass to 'sh -c'"
23 23
24#include "libbb.h" 24#include "libbb.h"
25#include "lazyload.h" 25#include "lazyload.h"
@@ -27,14 +27,15 @@
27int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 27int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int suw32_main(int argc UNUSED_PARAM, char **argv) 28int suw32_main(int argc UNUSED_PARAM, char **argv)
29{ 29{
30 char *opt_command = NULL;
31 SHELLEXECUTEINFO info; 30 SHELLEXECUTEINFO info;
31 unsigned opts, c_opt;
32 char *bb_path, *cwd; 32 char *bb_path, *cwd;
33 DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); 33 DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *);
34 34
35 getopt32(argv, "c:", &opt_command); 35 opts = getopt32(argv, "c");
36 if (argv[optind]) 36 c_opt = opts & 1;
37 bb_show_usage(); 37 if (!c_opt != !argv[optind])
38 bb_show_usage(); // -c without CMD, or operand without -c
38 39
39 /* ShellExecuteEx() needs backslash as separator in UNC paths. */ 40 /* ShellExecuteEx() needs backslash as separator in UNC paths. */
40 bb_path = xstrdup(bb_busybox_exec_path); 41 bb_path = xstrdup(bb_busybox_exec_path);
@@ -59,9 +60,16 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
59 cwd = xmalloc_realpath(getcwd(NULL, 0)); 60 cwd = xmalloc_realpath(getcwd(NULL, 0));
60 info.lpParameters = 61 info.lpParameters =
61 xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", cwd); 62 xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", cwd);
62 if (opt_command) 63
63 info.lpParameters = 64 if (c_opt) {
64 xasprintf("%s -s -c %s", info.lpParameters, quote_arg(opt_command)); 65 info.lpParameters = xappendword(info.lpParameters, "-s -c --");
66 while (argv[optind]) {
67 char *a = quote_arg(argv[optind++]);
68 info.lpParameters = xappendword(info.lpParameters, a);
69 free(a);
70 }
71 }
72
65 /* info.lpDirectory = NULL; */ 73 /* info.lpDirectory = NULL; */
66 info.nShow = SW_SHOWNORMAL; 74 info.nShow = SW_SHOWNORMAL;
67 75