https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c14440ee5789445f38e0c7cf327b0200947c8965

commit c14440ee5789445f38e0c7cf327b0200947c8965
Author:     Eric Kohl <[email protected]>
AuthorDate: Sat Feb 19 19:50:46 2022 +0100
Commit:     Eric Kohl <[email protected]>
CommitDate: Sat Feb 19 19:50:46 2022 +0100

    [RUNAS] Add password input and improve help text
    
    Now it works on windows xp and 10.
---
 base/applications/runas/lang/de-DE.rc | 15 ++++++-
 base/applications/runas/lang/en-US.rc | 15 ++++++-
 base/applications/runas/resource.h    | 25 ++++++++----
 base/applications/runas/runas.c       | 73 +++++++++++++++++++++++++++++------
 4 files changed, 106 insertions(+), 22 deletions(-)

diff --git a/base/applications/runas/lang/de-DE.rc 
b/base/applications/runas/lang/de-DE.rc
index 53f50974495..c9e3e159030 100644
--- a/base/applications/runas/lang/de-DE.rc
+++ b/base/applications/runas/lang/de-DE.rc
@@ -7,6 +7,17 @@ BEGIN
     IDS_USAGE03 "      /user:<Benutzername> Programm\n\n"
     IDS_USAGE04 "RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] 
]\n"
     IDS_USAGE05 "      /smartcard [/user:<Benutzername>] Programm\n\n"
-    IDS_USAGE06 "/noprofile"
-    IDS_USAGE07 "/profile"
+    IDS_USAGE06 "   /noprofile      Legt fest, dass das Benutzerprofil nicht 
geladen werden\n"
+    IDS_USAGE07 "                   soll. Führt dazu, dass die Anwendung 
schneller geladen\n"
+    IDS_USAGE08 "                   wird. Dies kann bei einigen Anwendungen zu 
Fehlern führen.\n"
+    IDS_USAGE09 "   /profile        Legt fest, dass das Benutzerprofil geladen 
werden soll.\n"
+    IDS_USAGE10 "                   Dies ist die Standardeinstellung.\n" 
+    IDS_USAGE11 "   /env            Verwendet die aktuelle Umgebung statt der 
des Benutzers.\n"
+    IDS_USAGE12 "   /user           <Benutzername> muss in der Form 
Benutzer@Domäne oder\n                   Domäne\\Benutzer angegeben werden\n"
+    IDS_USAGE13 "   Programm        Befehlszeile einer ausführbaren Datei. 
Siehe unten\n                   aufgeführte Beispiele.\n\n"
+
+    IDS_START     "Es wird versucht, %s als Benutzer ""%s\\%s"" zu 
starten...\n"
+    IDS_RUN_ERROR "RUNAS-FEHLER: %s kann nicht ausgeführt werden\n"
+
+    IDS_PASSWORD "Geben Sie das Kennwort für ""%s\\%s"" ein: "
 END
diff --git a/base/applications/runas/lang/en-US.rc 
b/base/applications/runas/lang/en-US.rc
index 815319ea936..f3f478b67f6 100644
--- a/base/applications/runas/lang/en-US.rc
+++ b/base/applications/runas/lang/en-US.rc
@@ -7,6 +7,17 @@ BEGIN
     IDS_USAGE03 "      /user:<UserName> program\n\n"
     IDS_USAGE04 "RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] 
]\n"
     IDS_USAGE05 "      /smartcard [/user:<UserName>] program\n\n"
-    IDS_USAGE06 "/noprofile"
-    IDS_USAGE07 "/profile"
+    IDS_USAGE06 "   /noprofile      specifies that the user's profile should 
not be loaded.\n"
+    IDS_USAGE07 "                   This causes the application to load more 
quickly, but\n"
+    IDS_USAGE08 "                   can cause some applications to 
malfunction.\n"
+    IDS_USAGE09 "   /profile        specifies that the user's profile should 
be loaded.\n"
+    IDS_USAGE10 "                   This is the default.\n" 
+    IDS_USAGE11 "   /env            to use current environment instead of 
user's.\n"
+    IDS_USAGE12 "   /user           <UserName> should be in form USER@DOMAIN 
or DOMAIN\\USER\n"
+    IDS_USAGE13 "   program         command line for EXE.  See below for 
examples\n\n"
+
+    IDS_START     "Attempting to start %s as user ""%s\\%s""...\n"
+    IDS_RUN_ERROR "RUNAS ERROR: Unable to run %s\n"
+
+    IDS_PASSWORD  "Enter the password for ""%s\\%s"": "
 END
diff --git a/base/applications/runas/resource.h 
b/base/applications/runas/resource.h
index 11ad5ad8fa3..a2288467f14 100644
--- a/base/applications/runas/resource.h
+++ b/base/applications/runas/resource.h
@@ -1,7 +1,18 @@
-#define IDS_USAGE01 7000
-#define IDS_USAGE02 7001
-#define IDS_USAGE03 7002
-#define IDS_USAGE04 7003
-#define IDS_USAGE05 7004
-#define IDS_USAGE06 7005
-#define IDS_USAGE07 7006
+#define IDS_USAGE01   7000
+#define IDS_USAGE02   7001
+#define IDS_USAGE03   7002
+#define IDS_USAGE04   7003
+#define IDS_USAGE05   7004
+#define IDS_USAGE06   7005
+#define IDS_USAGE07   7006
+#define IDS_USAGE08   7007
+#define IDS_USAGE09   7008
+#define IDS_USAGE10   7009
+#define IDS_USAGE11   7010
+#define IDS_USAGE12   7011
+#define IDS_USAGE13   7012
+#define IDS_USAGE_MAX IDS_USAGE13
+
+#define IDS_START     7100
+#define IDS_RUN_ERROR 7101
+#define IDS_PASSWORD  7500
diff --git a/base/applications/runas/runas.c b/base/applications/runas/runas.c
index 581f24e2d00..8adbe8d2894 100644
--- a/base/applications/runas/runas.c
+++ b/base/applications/runas/runas.c
@@ -23,17 +23,52 @@
 #define NDEBUG
 #include <debug.h>
 
+#define MAX_PASSWORD_LENGTH 64
+
 static
-void
-Usage(void)
+VOID
+Usage(VOID)
 {
-    ConResPuts(StdOut, IDS_USAGE01);
-    ConResPuts(StdOut, IDS_USAGE02);
-    ConResPuts(StdOut, IDS_USAGE03);
-    ConResPuts(StdOut, IDS_USAGE04);
-    ConResPuts(StdOut, IDS_USAGE05);
-    ConResPuts(StdOut, IDS_USAGE06);
-    ConResPuts(StdOut, IDS_USAGE07);
+    int i;
+    for (i = IDS_USAGE01; i <= IDS_USAGE_MAX; i++)
+        ConResPuts(StdOut, i);
+}
+
+
+static
+VOID
+ConInString(
+    _In_ PWSTR pInput,
+    _In_ DWORD dwLength)
+{
+    DWORD dwOldMode;
+    DWORD dwRead = 0;
+    HANDLE hFile;
+    PWSTR p;
+    PCHAR pBuf;
+
+    pBuf = (PCHAR)HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
+    ZeroMemory(pInput, dwLength * sizeof(WCHAR));
+    hFile = GetStdHandle(STD_INPUT_HANDLE);
+    GetConsoleMode(hFile, &dwOldMode);
+
+    SetConsoleMode(hFile, ENABLE_LINE_INPUT /*| ENABLE_ECHO_INPUT*/);
+
+    ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
+
+    MultiByteToWideChar(GetConsoleCP(), 0, pBuf, dwRead, pInput, dwLength - 1);
+    HeapFree(GetProcessHeap(), 0, pBuf);
+
+    for (p = pInput; *p; p++)
+    {
+        if (*p == L'\x0d')
+        {
+            *p = UNICODE_NULL;
+            break;
+        }
+    }
+
+    SetConsoleMode(hFile, dwOldMode);
 }
 
 
@@ -169,7 +204,22 @@ wmain(
     DPRINT("Domain: %S\n", pszDomain);
     DPRINT("CommandLine: %S\n", pszCommandLine);
 
-    /* FIXME: Query the password: */
+    if (pszDomain == NULL)
+    {
+        DWORD dwLength = MAX_COMPUTERNAME_LENGTH + 1;
+        pszDomain = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength * 
sizeof(WCHAR));
+        if (pszDomain)
+            GetComputerNameW(pszDomain, &dwLength);
+    }
+
+    pszPassword = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
(MAX_PASSWORD_LENGTH + 1) * sizeof(WCHAR));
+
+    /* Query the password */
+    ConResPrintf(StdOut, IDS_PASSWORD, pszDomain, pszUserName);
+    ConInString(pszPassword, MAX_PASSWORD_LENGTH + 1);
+    ConPuts(StdOut, L"\n");
+
+    ConResPrintf(StdOut, IDS_START, pszCommandLine, pszDomain, pszUserName);
 
     rc = CreateProcessWithLogonW(pszUserName,
                                  pszDomain,
@@ -184,7 +234,8 @@ wmain(
                                  &ProcessInfo);
     if (rc == FALSE)
     {
-        DPRINT("Error: %lu\n", GetLastError());
+        ConResPrintf(StdOut, IDS_RUN_ERROR, pszCommandLine);
+        ConPrintf(StdOut, L"Error: %lu\n", GetLastError());
     }
 
 done:

Reply via email to