Index: base/applications/cmdutils/whoami/whoami.c =================================================================== --- base/applications/cmdutils/whoami/whoami.c (revision 65811) +++ base/applications/cmdutils/whoami/whoami.c (working copy) @@ -1,4 +1,4 @@ -/* +/* * PROJECT: ReactOS Whoami * LICENSE: GPL - See COPYING in the top level directory * FILE: base/applications/cmdutils/whoami/whoami.c @@ -6,7 +6,6 @@ * PROGRAMMERS: Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com) */ - #define SECURITY_WIN32 #include #include @@ -15,6 +14,61 @@ #include "resource.h" + +/* Unicode (W) to ANSI OEM wrapper function, as console and Unicode don't mix well, sigh */ +static void WhoamiLameOemConversion_printf(const WCHAR *lpSourceFormatW, ...) +{ + CHAR *lpBufferA = NULL; + WCHAR *lpBufferW = NULL; + + UINT Size; + va_list Args; + + /* first let's find out the final output'ed length of the wprintf routine */ + va_start(Args, lpSourceFormatW); + + Size = _vscwprintf(lpSourceFormatW, Args); + + va_end(Args); + + /* allocate a proportional memory chunk taking into account the char width */ + lpBufferW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size * sizeof(WCHAR)); + + if (!lpBufferW) + return; + + /* do wprintf to this newly allocated buffer of ours */ + va_start(Args, lpSourceFormatW); + + _vsnwprintf(lpBufferW, Size, lpSourceFormatW, Args); + + va_end(Args); + + /* allocate a similarly sized buffer for the ANSI/OEM version of our string */ + lpBufferA = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (Size + 1) * sizeof(CHAR)); + + if (!lpBufferA) + { + LocalFree(lpBufferW); + return; + } + + /* convert our Unicode/Wide char string into a proper ANSI/OEM + string that our console may understand, at least in theory */ + CharToOemBuffW(lpBufferW, + lpBufferA, + Size); + + /* print the converted OEM string into the console's output and call it a day */ + printf(lpBufferA); + + /* clean everything up */ + HeapFree(GetProcessHeap(), 0, lpBufferW); + HeapFree(GetProcessHeap(), 0, lpBufferA); +} + +#define wprintf WhoamiLameOemConversion_printf + BOOL NoHeader = FALSE; UINT NoHeaderArgCount = 0; UINT PrintFormatArgCount = 0; @@ -139,7 +193,8 @@ while (Length--) wprintf(L"-"); - _putws(L"\n"); + /* _putws seems to be broken in ReactOS' CRT ??? */ + wprintf(L"\n\n"); } typedef struct @@ -614,21 +669,27 @@ WhoamiSetTableDyn(PrivTable, PrivName, dwIndex + 1, 0); - ret = LookupPrivilegeDisplayNameW(NULL, PrivName, NULL, &DispNameSize, &dwResult); - if (!ret || GetLastError() == ERROR_NO_SUCH_PRIVILEGE) - { - DispName = HeapAlloc(GetProcessHeap(), 0, ++DispNameSize * sizeof(WCHAR)); + /* try to grab the size of the string, also, beware, as this call is + unimplemented in ReactOS/Wine at the moment */ - LookupPrivilegeDisplayNameW(NULL, PrivName, DispName, &DispNameSize, &dwResult); + LookupPrivilegeDisplayNameW(NULL, PrivName, NULL, &DispNameSize, &dwResult); - //wprintf(L"DispName: %d %x '%s'\n", DispNameSize, GetLastError(), DispName); + DispName = HeapAlloc(GetProcessHeap(), 0, ++DispNameSize * sizeof(WCHAR)); + ret = LookupPrivilegeDisplayNameW(NULL, PrivName, DispName, &DispNameSize, &dwResult); + + if (ret && DispName) + { + // wprintf(L"DispName: %d %x '%s'\n", DispNameSize, GetLastError(), DispName); WhoamiSetTableDyn(PrivTable, DispName, dwIndex + 1, 1); } else { WhoamiSetTable(PrivTable, WhoamiLoadRcString(IDS_UNKNOWN_DESCRIPTION), dwIndex + 1, 1); + + if (DispName != NULL) + WhoamiFree(DispName); } if (pPrivInfo->Privileges[dwIndex].Attributes & SE_PRIVILEGE_ENABLED)