Reactos

[RUNAS] Initial version of the runas utility

- Work in progress
- Please do not translate it yet because the resources will change significantly

+274
+1
base/applications/CMakeLists.txt
··· 33 33 add_subdirectory(rapps_com) 34 34 add_subdirectory(regedit) 35 35 add_subdirectory(regedt32) 36 + add_subdirectory(runas) 36 37 add_subdirectory(sc) 37 38 add_subdirectory(screensavers) 38 39 add_subdirectory(sdbinst)
+8
base/applications/runas/CMakeLists.txt
··· 1 + 2 + include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) 3 + 4 + add_executable(runas runas.c runas.rc) 5 + set_module_type(runas win32cui UNICODE) 6 + target_link_libraries(runas conutils ${PSEH_LIB}) 7 + add_importlibs(runas advapi32 msvcrt kernel32 ntdll) 8 + add_cd_file(TARGET runas DESTINATION reactos/system32 FOR all)
+12
base/applications/runas/lang/de-DE.rc
··· 1 + LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL 2 + 3 + STRINGTABLE 4 + BEGIN 5 + IDS_USAGE01 "Syntax für RUNAS:\n\n" 6 + IDS_USAGE02 "RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]\n" 7 + IDS_USAGE03 " /user:<Benutzername> Programm\n\n" 8 + IDS_USAGE04 "RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]\n" 9 + IDS_USAGE05 " /smartcard [/user:<Benutzername>] Programm\n\n" 10 + IDS_USAGE06 "/noprofile" 11 + IDS_USAGE07 "/profile" 12 + END
+12
base/applications/runas/lang/en-US.rc
··· 1 + LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 2 + 3 + STRINGTABLE 4 + BEGIN 5 + IDS_USAGE01 "RUNAS USAGE\n\n" 6 + IDS_USAGE02 "RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]\n" 7 + IDS_USAGE03 " /user:<UserName> program\n\n" 8 + IDS_USAGE04 "RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]\n" 9 + IDS_USAGE05 " /smartcard [/user:<UserName>] program\n\n" 10 + IDS_USAGE06 "/noprofile" 11 + IDS_USAGE07 "/profile" 12 + END
+7
base/applications/runas/resource.h
··· 1 + #define IDS_USAGE01 7000 2 + #define IDS_USAGE02 7001 3 + #define IDS_USAGE03 7002 4 + #define IDS_USAGE04 7003 5 + #define IDS_USAGE05 7004 6 + #define IDS_USAGE06 7005 7 + #define IDS_USAGE07 7006
+210
base/applications/runas/runas.c
··· 1 + /* 2 + * PROJECT: ReactOS runas utility 3 + * LICENSE: GPL - See COPYING in the top level directory 4 + * FILE: base/applications/runas/runas.c 5 + * COPYRIGHT: Copyright 2022 Eric Kohl <eric.kohl@reactos.org> 6 + */ 7 + 8 + #include <stdio.h> 9 + #include <stdlib.h> 10 + #include <limits.h> 11 + #include <stdarg.h> 12 + 13 + #define WIN32_NO_STATUS 14 + #include <windef.h> 15 + #include <winbase.h> 16 + #include <winnls.h> 17 + #include <wincon.h> 18 + #include <winsvc.h> 19 + #include <conutils.h> 20 + 21 + #include "resource.h" 22 + 23 + #define NDEBUG 24 + #include <debug.h> 25 + 26 + static 27 + void 28 + Usage(void) 29 + { 30 + ConResPuts(StdOut, IDS_USAGE01); 31 + ConResPuts(StdOut, IDS_USAGE02); 32 + ConResPuts(StdOut, IDS_USAGE03); 33 + ConResPuts(StdOut, IDS_USAGE04); 34 + ConResPuts(StdOut, IDS_USAGE05); 35 + ConResPuts(StdOut, IDS_USAGE06); 36 + ConResPuts(StdOut, IDS_USAGE07); 37 + } 38 + 39 + 40 + int 41 + wmain( 42 + int argc, 43 + LPCWSTR argv[]) 44 + { 45 + LPCWSTR pszArg; 46 + int i, result = 0; 47 + BOOL bProfile = FALSE, bNoProfile = FALSE; 48 + BOOL bEnv = FALSE; 49 + PWSTR pszUserName = NULL; 50 + PWSTR pszDomain = NULL; 51 + PWSTR pszCommandLine = NULL; 52 + PWSTR pszPassword = NULL; 53 + PWSTR ptr; 54 + STARTUPINFOW StartupInfo; 55 + PROCESS_INFORMATION ProcessInfo; 56 + DWORD dwLogonFlags = 0; 57 + BOOL rc; 58 + 59 + /* Initialize the Console Standard Streams */ 60 + ConInitStdStreams(); 61 + 62 + if (argc == 1) 63 + { 64 + Usage(); 65 + return 0; 66 + } 67 + 68 + ZeroMemory(&StartupInfo, sizeof(StartupInfo)); 69 + ZeroMemory(&ProcessInfo, sizeof(ProcessInfo)); 70 + 71 + for (i = 1; i < argc; i++) 72 + { 73 + pszArg = argv[i]; 74 + if (*pszArg == L'-' || *pszArg == L'/') 75 + { 76 + pszArg++; 77 + if (wcscmp(pszArg, L"?") == 0) 78 + { 79 + Usage(); 80 + } 81 + else if (wcsicmp(pszArg, L"profile") == 0) 82 + { 83 + bProfile = TRUE; 84 + } 85 + else if (wcsicmp(pszArg, L"noprofile") == 0) 86 + { 87 + bNoProfile = TRUE; 88 + } 89 + else if (wcsicmp(pszArg, L"env") == 0) 90 + { 91 + bEnv = TRUE; 92 + } 93 + else if (_wcsnicmp(pszArg, L"user:", 5) == 0) 94 + { 95 + pszArg += 5; 96 + ptr = wcschr(pszArg, L'@'); 97 + if (ptr != NULL) 98 + { 99 + /* User@Domain */ 100 + pszUserName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((ptr - pszArg) + 1) * sizeof(WCHAR)); 101 + if (pszUserName) 102 + wcsncpy(pszUserName, pszArg, (ptr - pszArg)); 103 + 104 + ptr++; 105 + pszDomain = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(ptr) + 1) * sizeof(WCHAR)); 106 + if (pszDomain) 107 + wcscpy(pszDomain, ptr); 108 + } 109 + else 110 + { 111 + ptr = wcschr(pszArg, L'\\'); 112 + if (ptr != NULL) 113 + { 114 + /* Domain\User */ 115 + pszUserName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(ptr + 1) + 1)* sizeof(WCHAR)); 116 + if (pszUserName) 117 + wcscpy(pszUserName, (ptr + 1)); 118 + 119 + pszDomain = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((ptr - pszArg) + 1) * sizeof(WCHAR)); 120 + if (pszDomain) 121 + wcsncpy(pszDomain, pszArg, (ptr - pszArg)); 122 + } 123 + else 124 + { 125 + /* User */ 126 + pszUserName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(pszArg) + 1) * sizeof(WCHAR)); 127 + if (pszUserName) 128 + wcscpy(pszUserName, pszArg); 129 + } 130 + } 131 + } 132 + else 133 + { 134 + Usage(); 135 + result = -1; 136 + } 137 + } 138 + else 139 + { 140 + if (pszCommandLine == NULL) 141 + { 142 + pszCommandLine = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(pszArg) + 1) * sizeof(WCHAR)); 143 + if (pszCommandLine != NULL) 144 + wcscpy(pszCommandLine, pszArg); 145 + break; 146 + } 147 + } 148 + } 149 + 150 + if (bProfile && bNoProfile) 151 + { 152 + Usage(); 153 + result = -1; 154 + goto done; 155 + } 156 + 157 + if (bProfile) 158 + dwLogonFlags |= LOGON_WITH_PROFILE; 159 + 160 + if (bNoProfile) 161 + dwLogonFlags &= ~LOGON_WITH_PROFILE; 162 + 163 + if (bEnv) 164 + { 165 + DPRINT("env\n"); 166 + } 167 + 168 + DPRINT("User: %S\n", pszUserName); 169 + DPRINT("Domain: %S\n", pszDomain); 170 + DPRINT("CommandLine: %S\n", pszCommandLine); 171 + 172 + /* FIXME: Query the password: */ 173 + 174 + rc = CreateProcessWithLogonW(pszUserName, 175 + pszDomain, 176 + pszPassword, 177 + dwLogonFlags, 178 + NULL, //[in, optional] LPCWSTR lpApplicationName, 179 + pszCommandLine, 180 + 0, //[in] DWORD dwCreationFlags, 181 + bEnv ? GetEnvironmentStringsW() : NULL, 182 + NULL, //[in, optional] LPCWSTR lpCurrentDirectory, 183 + &StartupInfo, 184 + &ProcessInfo); 185 + if (rc == FALSE) 186 + { 187 + DPRINT("Error: %lu\n", GetLastError()); 188 + } 189 + 190 + done: 191 + if (ProcessInfo.hThread) 192 + CloseHandle(ProcessInfo.hThread); 193 + 194 + if (ProcessInfo.hProcess) 195 + CloseHandle(ProcessInfo.hProcess); 196 + 197 + if (pszPassword) 198 + HeapFree(GetProcessHeap(), 0, pszPassword); 199 + 200 + if (pszCommandLine) 201 + HeapFree(GetProcessHeap(), 0, pszCommandLine); 202 + 203 + if (pszUserName) 204 + HeapFree(GetProcessHeap(), 0, pszUserName); 205 + 206 + if (pszDomain) 207 + HeapFree(GetProcessHeap(), 0, pszDomain); 208 + 209 + return result; 210 + }
+24
base/applications/runas/runas.rc
··· 1 + #include <windef.h> 2 + #include <winuser.h> 3 + 4 + #include "resource.h" 5 + 6 + /* Define language neutral resources */ 7 + LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 8 + 9 + #define REACTOS_STR_FILE_DESCRIPTION "Run As Utility" 10 + #define REACTOS_STR_INTERNAL_NAME "runas" 11 + #define REACTOS_STR_ORIGINAL_FILENAME "runas.exe" 12 + #include <reactos/version.rc> 13 + 14 + #include <reactos/manifest_exe.rc> 15 + 16 + /* UTF-8 */ 17 + #pragma code_page(65001) 18 + 19 + #ifdef LANGUAGE_DE_DE 20 + #include "lang/de-DE.rc" 21 + #endif 22 + #ifdef LANGUAGE_EN_US 23 + #include "lang/en-US.rc" 24 + #endif