Module: wine Branch: master Commit: f8fb43aaba499c6d0da05b0ee3a09c349a753cf8 URL: https://source.winehq.org/git/wine.git/?a=commit;h=f8fb43aaba499c6d0da05b0ee...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Apr 16 15:15:21 2020 +0200
advapi32: Use WINEUSERNAME variable to implement GetUserNameA/W.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/advapi32/advapi.c | 79 +++++++++----------------------------------------- 1 file changed, 14 insertions(+), 65 deletions(-)
diff --git a/dlls/advapi32/advapi.c b/dlls/advapi32/advapi.c index 433c25820d..cfd79e02af 100644 --- a/dlls/advapi32/advapi.c +++ b/dlls/advapi32/advapi.c @@ -32,7 +32,6 @@ #include "wincred.h" #include "wct.h"
-#include "wine/library.h" #include "wine/unicode.h" #include "wine/debug.h"
@@ -42,81 +41,31 @@ WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/****************************************************************************** * GetUserNameA [ADVAPI32.@] - * - * Get the current user name. - * - * PARAMS - * lpszName [O] Destination for the user name. - * lpSize [I/O] Size of lpszName. - * - * RETURNS - * Success: The length of the user name, including terminating NUL. - * Failure: ERROR_MORE_DATA if *lpSize is too small. */ -BOOL WINAPI -GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) +BOOL WINAPI GetUserNameA( LPSTR name, LPDWORD size ) { - WCHAR *buffer; + DWORD len = GetEnvironmentVariableA( "WINEUSERNAME", name, *size ); BOOL ret; - DWORD sizeW = *lpSize; - - if (!(buffer = heap_alloc( sizeW * sizeof(WCHAR) ))) - { - SetLastError( ERROR_NOT_ENOUGH_MEMORY ); - return FALSE; - }
- ret = GetUserNameW( buffer, &sizeW ); - if (ret) - *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL ); - else - *lpSize = sizeW; - - heap_free( buffer ); + if (!len) return FALSE; + if ((ret = (len < *size))) len++; + *size = len; return ret; }
/****************************************************************************** * GetUserNameW [ADVAPI32.@] - * - * See GetUserNameA. */ -BOOL WINAPI -GetUserNameW( LPWSTR lpszName, LPDWORD lpSize ) +BOOL WINAPI GetUserNameW( LPWSTR name, LPDWORD size ) { - const char *name = wine_get_user_name(); - DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 ); - LPWSTR backslash; - - if (len > *lpSize) - { - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - *lpSize = len; - return FALSE; - } - - *lpSize = len; - MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len ); - - /* Word uses the user name to create named mutexes and file mappings, - * and backslashes in the name cause the creation to fail. - * Also, Windows doesn't return the domain name in the user name even when - * joined to a domain. A Unix box joined to a domain using winbindd will - * contain the domain name in the username. So we need to cut this off. - * FIXME: Only replaces forward and backslashes for now, should get the - * winbind separator char from winbindd and replace that. - */ - for (i = 0; lpszName[i]; i++) - if (lpszName[i] == '/') lpszName[i] = '\'; - - backslash = strrchrW(lpszName, '\'); - if (backslash == NULL) - return TRUE; - - len = lstrlenW(backslash); - memmove(lpszName, backslash + 1, len * sizeof(WCHAR)); - *lpSize = len; - return TRUE; + static const WCHAR wineusernameW[] = {'W','I','N','E','U','S','E','R','N','A','M','E',0}; + DWORD len = GetEnvironmentVariableW( wineusernameW, name, *size ); + BOOL ret; + + if (!len) return FALSE; + if ((ret = (len < *size))) len++; + *size = len; + return ret; }
/******************************************************************************