Commit c4effa39 authored by Alexandre Julliard's avatar Alexandre Julliard

Use the Unix codepage to convert the user name to Unicode.

parent b37eab4e
......@@ -53,21 +53,26 @@ WINE_DEFAULT_DEBUG_CHANNEL(advapi);
BOOL WINAPI
GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
{
size_t len;
const char *name = wine_get_user_name();
/* We need to include the null character when determining the size of the buffer. */
len = strlen(name) + 1;
if (len > *lpSize)
{
SetLastError(ERROR_MORE_DATA);
*lpSize = len;
return 0;
}
WCHAR *buffer;
BOOL ret;
*lpSize = len;
strcpy(lpszName, name);
return 1;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, *lpSize * 2 * sizeof(WCHAR) )))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return FALSE;
}
ret = GetUserNameW( buffer, *lpSize * 2 );
if (ret)
{
if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
{
*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
SetLastError( ERROR_MORE_DATA );
ret = FALSE;
}
}
HeapFree( GetProcessHeap(), 0, buffer );
return ret;
}
/******************************************************************************
......@@ -79,7 +84,7 @@ BOOL WINAPI
GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
{
const char *name = wine_get_user_name();
DWORD len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
DWORD len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
if (len > *lpSize)
{
......@@ -89,7 +94,7 @@ GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
}
*lpSize = len;
MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, len );
MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
return TRUE;
}
......
......@@ -728,20 +728,17 @@ NTSTATUS WINAPI NtUnloadKey(
*/
NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
{
static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
const char *user = wine_get_user_name();
char *buffer;
ANSI_STRING AnsiPath;
NTSTATUS ret;
int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 );
if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, strlen(user)+16 )))
KeyPath->MaximumLength = sizeof(pathW) + len * sizeof(WCHAR);
KeyPath->Length = KeyPath->MaximumLength - sizeof(WCHAR);
if (!(KeyPath->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, KeyPath->MaximumLength )))
return STATUS_NO_MEMORY;
strcpy( buffer, "\\Registry\\User\\" );
strcat( buffer, user );
RtlInitAnsiString( &AnsiPath, buffer );
ret = RtlAnsiStringToUnicodeString(KeyPath, &AnsiPath, TRUE);
RtlFreeAnsiString( &AnsiPath );
return ret;
memcpy( KeyPath->Buffer, pathW, sizeof(pathW) );
ntdll_umbstowcs( 0, user, strlen(user)+1, KeyPath->Buffer + sizeof(pathW)/sizeof(WCHAR), len );
return STATUS_SUCCESS;
}
/******************************************************************************
......
......@@ -1178,17 +1178,22 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString(
PSID Sid,
BOOLEAN AllocateString)
{
const char *p = wine_get_user_name();
NTSTATUS status;
ANSI_STRING AnsiStr;
const char *user = wine_get_user_name();
int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 ) * sizeof(WCHAR);
FIXME("(%p %p %u)\n", String, Sid, AllocateString);
FIXME("(%p %p %u)\n", String, Sid, AllocateString);
RtlInitAnsiString(&AnsiStr, p);
status = RtlAnsiStringToUnicodeString(String, &AnsiStr, AllocateString);
String->Length = len - sizeof(WCHAR);
if (AllocateString)
{
String->MaximumLength = len;
if (!(String->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
return STATUS_NO_MEMORY;
}
else if (len > String->MaximumLength) return STATUS_BUFFER_OVERFLOW;
TRACE("%s (%u %u)\n",debugstr_w(String->Buffer),String->Length,String->MaximumLength);
return status;
ntdll_umbstowcs( 0, user, strlen(user)+1, String->Buffer, len/sizeof(WCHAR) );
return STATUS_SUCCESS;
}
/******************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment