diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-14 08:42:17 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-14 08:42:17 +0000 |
commit | 1b0ac9fc815fd308057f253397723330e6fea376 (patch) | |
tree | b85584ec3851b9064111da61f3d6a377f46f80c4 | |
parent | 0693dedb3ed8a54e5747249b772682910690935b (diff) | |
download | busybox-w32-1b0ac9fc815fd308057f253397723330e6fea376.tar.gz busybox-w32-1b0ac9fc815fd308057f253397723330e6fea376.tar.bz2 busybox-w32-1b0ac9fc815fd308057f253397723330e6fea376.zip |
su: canonicalise directory before elevating privileges
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().
-rw-r--r-- | loginutils/suw32.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c index 6396a7b88..e3c6d8744 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c | |||
@@ -28,7 +28,7 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
28 | { | 28 | { |
29 | char *opt_command = NULL; | 29 | char *opt_command = NULL; |
30 | SHELLEXECUTEINFO info; | 30 | SHELLEXECUTEINFO info; |
31 | char *bb_path, *s; | 31 | char *bb_path, *cwd, *s; |
32 | 32 | ||
33 | getopt32(argv, "c:", &opt_command); | 33 | getopt32(argv, "c:", &opt_command); |
34 | if (argv[optind]) | 34 | if (argv[optind]) |
@@ -47,13 +47,19 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
47 | /* info.hwnd = NULL; */ | 47 | /* info.hwnd = NULL; */ |
48 | info.lpVerb = "runas"; | 48 | info.lpVerb = "runas"; |
49 | info.lpFile = bb_path; | 49 | info.lpFile = bb_path; |
50 | /* It seems that when ShellExecuteEx() runs binaries residing in | 50 | /* |
51 | * It seems that when ShellExecuteEx() runs binaries residing in | ||
51 | * certain 'system' directories it sets the current directory of | 52 | * certain 'system' directories it sets the current directory of |
52 | * the process to %SYSTEMROOT%\System32. Override this by passing | 53 | * the process to %SYSTEMROOT%\System32. Override this by passing |
53 | * the directory we want to the shell. */ | 54 | * the directory we want to the shell. |
55 | * | ||
56 | * Canonicalise the directory now: if it's in a drive mapped to | ||
57 | * a network share it may not be available once we have elevated | ||
58 | * privileges. | ||
59 | */ | ||
60 | cwd = xmalloc_realpath(getcwd(NULL, 0)); | ||
54 | info.lpParameters = | 61 | info.lpParameters = |
55 | xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", | 62 | xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", cwd); |
56 | getcwd(NULL, 0)); | ||
57 | if (opt_command) | 63 | if (opt_command) |
58 | info.lpParameters = | 64 | info.lpParameters = |
59 | xasprintf("%s -s -c \"%s\"", info.lpParameters, opt_command); | 65 | xasprintf("%s -s -c \"%s\"", info.lpParameters, opt_command); |