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); ...@@ -53,21 +53,26 @@ WINE_DEFAULT_DEBUG_CHANNEL(advapi);
BOOL WINAPI BOOL WINAPI
GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
{ {
size_t len; WCHAR *buffer;
const char *name = wine_get_user_name(); BOOL ret;
/* 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;
}
*lpSize = len; if (!(buffer = HeapAlloc( GetProcessHeap(), 0, *lpSize * 2 * sizeof(WCHAR) )))
strcpy(lpszName, name); {
return 1; 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 ...@@ -79,7 +84,7 @@ BOOL WINAPI
GetUserNameW( LPWSTR lpszName, LPDWORD lpSize ) GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
{ {
const char *name = wine_get_user_name(); 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) if (len > *lpSize)
{ {
...@@ -89,7 +94,7 @@ GetUserNameW( LPWSTR lpszName, LPDWORD lpSize ) ...@@ -89,7 +94,7 @@ GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
} }
*lpSize = len; *lpSize = len;
MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, len ); MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
return TRUE; return TRUE;
} }
......
...@@ -728,20 +728,17 @@ NTSTATUS WINAPI NtUnloadKey( ...@@ -728,20 +728,17 @@ NTSTATUS WINAPI NtUnloadKey(
*/ */
NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath) 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(); const char *user = wine_get_user_name();
char *buffer; int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 );
ANSI_STRING AnsiPath;
NTSTATUS ret;
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; return STATUS_NO_MEMORY;
memcpy( KeyPath->Buffer, pathW, sizeof(pathW) );
strcpy( buffer, "\\Registry\\User\\" ); ntdll_umbstowcs( 0, user, strlen(user)+1, KeyPath->Buffer + sizeof(pathW)/sizeof(WCHAR), len );
strcat( buffer, user ); return STATUS_SUCCESS;
RtlInitAnsiString( &AnsiPath, buffer );
ret = RtlAnsiStringToUnicodeString(KeyPath, &AnsiPath, TRUE);
RtlFreeAnsiString( &AnsiPath );
return ret;
} }
/****************************************************************************** /******************************************************************************
......
...@@ -1178,17 +1178,22 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString( ...@@ -1178,17 +1178,22 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString(
PSID Sid, PSID Sid,
BOOLEAN AllocateString) BOOLEAN AllocateString)
{ {
const char *p = wine_get_user_name(); const char *user = wine_get_user_name();
NTSTATUS status; int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 ) * sizeof(WCHAR);
ANSI_STRING AnsiStr;
FIXME("(%p %p %u)\n", String, Sid, AllocateString); FIXME("(%p %p %u)\n", String, Sid, AllocateString);
RtlInitAnsiString(&AnsiStr, p); String->Length = len - sizeof(WCHAR);
status = RtlAnsiStringToUnicodeString(String, &AnsiStr, AllocateString); 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); ntdll_umbstowcs( 0, user, strlen(user)+1, String->Buffer, len/sizeof(WCHAR) );
return status; 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