From: Dmitry Timoshkov dmitry@baikal.ru
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- configure | 3 ++ configure.ac | 2 ++ programs/runas/Makefile.in | 7 +++++ programs/runas/runas.c | 56 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 programs/runas/Makefile.in create mode 100644 programs/runas/runas.c
diff --git a/configure b/configure index 17c35504ac3..a34d67fe456 100755 --- a/configure +++ b/configure @@ -1728,6 +1728,7 @@ enable_regsvcs enable_regsvr32 enable_robocopy enable_rpcss +enable_runas enable_rundll32 enable_sc enable_schtasks @@ -22120,6 +22121,7 @@ fi enable_conhost=${enable_conhost:-$HOST_ARCH} enable_plugplay=${enable_plugplay:-$HOST_ARCH} enable_rpcss=${enable_rpcss:-$HOST_ARCH} +enable_runas=${enable_runas:-$HOST_ARCH} enable_services=${enable_services:-$HOST_ARCH} enable_spoolsv=${enable_spoolsv:-$HOST_ARCH} enable_termsv=${enable_termsv:-$HOST_ARCH} @@ -23299,6 +23301,7 @@ wine_fn_config_makefile programs/regsvcs enable_regsvcs wine_fn_config_makefile programs/regsvr32 enable_regsvr32 wine_fn_config_makefile programs/robocopy enable_robocopy wine_fn_config_makefile programs/rpcss enable_rpcss +wine_fn_config_makefile programs/runas enable_runas wine_fn_config_makefile programs/rundll.exe16 enable_win16 wine_fn_config_makefile programs/rundll32 enable_rundll32 wine_fn_config_makefile programs/sc enable_sc diff --git a/configure.ac b/configure.ac index 1e842f33880..e713bc69dd6 100644 --- a/configure.ac +++ b/configure.ac @@ -2392,6 +2392,7 @@ dnl Disable some programs for other PE archs enable_conhost=${enable_conhost:-$HOST_ARCH} enable_plugplay=${enable_plugplay:-$HOST_ARCH} enable_rpcss=${enable_rpcss:-$HOST_ARCH} +enable_runas=${enable_runas:-$HOST_ARCH} enable_services=${enable_services:-$HOST_ARCH} enable_spoolsv=${enable_spoolsv:-$HOST_ARCH} enable_termsv=${enable_termsv:-$HOST_ARCH} @@ -3575,6 +3576,7 @@ WINE_CONFIG_MAKEFILE(programs/regsvcs) WINE_CONFIG_MAKEFILE(programs/regsvr32) WINE_CONFIG_MAKEFILE(programs/robocopy) WINE_CONFIG_MAKEFILE(programs/rpcss) +WINE_CONFIG_MAKEFILE(programs/runas) WINE_CONFIG_MAKEFILE(programs/rundll.exe16) WINE_CONFIG_MAKEFILE(programs/rundll32) WINE_CONFIG_MAKEFILE(programs/sc) diff --git a/programs/runas/Makefile.in b/programs/runas/Makefile.in new file mode 100644 index 00000000000..4363f124198 --- /dev/null +++ b/programs/runas/Makefile.in @@ -0,0 +1,7 @@ +MODULE = runas.exe +IMPORTS = kernel32 advapi32 + +EXTRADLLFLAGS = -mconsole -municode + +SOURCES = \ + runas.c diff --git a/programs/runas/runas.c b/programs/runas/runas.c new file mode 100644 index 00000000000..3f4d28e3c81 --- /dev/null +++ b/programs/runas/runas.c @@ -0,0 +1,56 @@ +/* + * Copyright 2023 Dmitry Timoshkov + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> + +#include "windef.h" +#include "winbase.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(runas); + +int __cdecl wmain(int argc, WCHAR *argv[]) +{ + WCHAR *user, *domain; + STARTUPINFOW si = { sizeof(si) }; + PROCESS_INFORMATION pi; + BOOL ret; + + if (argc < 3 || wcsncmp(argv[1], L"/user:", 5) != 0) + { + printf("Syntax: runas.exe /user:user@domain.com program.exe\n"); + return -1; + } + + user = argv[1] + 6; + domain = wcschr(user, '@'); + if (!*user || !domain || !*domain) + { + ERR("Invalid user/domain specified\n"); + return -1; + } + + *domain++ = 0; + TRACE("Running as %s@%s\n", debugstr_w(user), debugstr_w(domain)); + + ret = CreateProcessWithLogonW(user, domain, NULL, 0, NULL, argv[2], 0, NULL, NULL, &si, &pi); + if (!ret) ERR("CreateProcessWithLogon error %lu\n", GetLastError()); + + return 0; +}