From 0f9bc90f097e2d3d4162757cd42941afb9358552 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 9 Mar 2019 07:53:03 +0000 Subject: su: work when binary has a UNC path ShellExecuteEx() requires backslashes as the file separator if the binary to be executed has a UNC path. Convert separators unconditionally. --- loginutils/suw32.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/loginutils/suw32.c b/loginutils/suw32.c index d51a7f58c..93fd145f1 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c @@ -28,17 +28,27 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) { char *opt_command = NULL; SHELLEXECUTEINFO info; + char *bb_path, *s; getopt32(argv, "c:", &opt_command); if (argv[optind]) bb_show_usage(); + /* ShellExecuteEx() needs backslash as separator in UNC paths. */ + bb_path = s = xstrdup(bb_busybox_exec_path); + for ( ; *s; ++s) { + if (*s == '/') + *s = '\\'; + } + memset(&info, 0, sizeof(SHELLEXECUTEINFO)); info.cbSize = sizeof(SHELLEXECUTEINFO); /* info.fMask = SEE_MASK_DEFAULT; */ /* info.hwnd = NULL; */ info.lpVerb = "runas"; - info.lpFile = bb_busybox_exec_path; + info.lpFile = bb_path; + /* ShellExecuteEx() always runs system binaries in C:\Windows\System32. + * Pass the directory we want to the shell. */ info.lpParameters = xasprintf("--busybox ash -d \"%s\"", getcwd(NULL, 0)); if (opt_command) info.lpParameters = -- cgit v1.2.3-55-g6feb