diff options
-rw-r--r-- | loginutils/suw32.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c index 3500c08db..9a81c9a06 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c | |||
@@ -16,7 +16,7 @@ | |||
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'] [root [FILE ARGS | ARG0 ARGS]" |
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 Command to pass to 'sh -c'" |
@@ -29,12 +29,17 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
29 | { | 29 | { |
30 | char *opt_command = NULL; | 30 | char *opt_command = NULL; |
31 | SHELLEXECUTEINFO info; | 31 | SHELLEXECUTEINFO info; |
32 | char *bb_path, *cwd; | 32 | char *bb_path, *cwd, *q, *args; |
33 | DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); | 33 | DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); |
34 | 34 | ||
35 | getopt32(argv, "c:", &opt_command); | 35 | getopt32(argv, "c:", &opt_command); |
36 | if (argv[optind]) | 36 | argv += optind; |
37 | bb_show_usage(); | 37 | if (argv[0]) { |
38 | if (strcmp(argv[0], "root") != 0) { | ||
39 | bb_error_msg_and_die("unknown user '%s'", argv[0]); | ||
40 | } | ||
41 | ++argv; | ||
42 | } | ||
38 | 43 | ||
39 | /* ShellExecuteEx() needs backslash as separator in UNC paths. */ | 44 | /* ShellExecuteEx() needs backslash as separator in UNC paths. */ |
40 | bb_path = xstrdup(bb_busybox_exec_path); | 45 | bb_path = xstrdup(bb_busybox_exec_path); |
@@ -57,11 +62,25 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
57 | * privileges. | 62 | * privileges. |
58 | */ | 63 | */ |
59 | cwd = xmalloc_realpath(getcwd(NULL, 0)); | 64 | cwd = xmalloc_realpath(getcwd(NULL, 0)); |
60 | info.lpParameters = | 65 | q = quote_arg(cwd); |
61 | xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", cwd); | 66 | args = xasprintf("--busybox ash -d %s -t \"BusyBox ash (Admin)\"", q); |
62 | if (opt_command) | 67 | free(q); |
63 | info.lpParameters = | 68 | free(cwd); |
64 | xasprintf("%s -s -c \"%s\"", info.lpParameters, opt_command); | 69 | |
70 | if (opt_command) { | ||
71 | args = xappendword(args, "-s -c"); | ||
72 | q = quote_arg(opt_command); | ||
73 | args = xappendword(args, q); | ||
74 | free(q); | ||
75 | } | ||
76 | |||
77 | while (*argv) { | ||
78 | q = quote_arg(*argv++); | ||
79 | args = xappendword(args, q); | ||
80 | free(q); | ||
81 | } | ||
82 | |||
83 | info.lpParameters = args; | ||
65 | /* info.lpDirectory = NULL; */ | 84 | /* info.lpDirectory = NULL; */ |
66 | info.nShow = SW_SHOWNORMAL; | 85 | info.nShow = SW_SHOWNORMAL; |
67 | 86 | ||