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

This commit is contained in:
Alexandre Julliard 2004-05-07 04:01:28 +00:00
parent b37eab4ec8
commit c4effa39e6
3 changed files with 42 additions and 35 deletions

View File

@ -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. */ if (!(buffer = HeapAlloc( GetProcessHeap(), 0, *lpSize * 2 * sizeof(WCHAR) )))
len = strlen(name) + 1; {
if (len > *lpSize) SetLastError( ERROR_NOT_ENOUGH_MEMORY );
{ return FALSE;
SetLastError(ERROR_MORE_DATA); }
*lpSize = len; ret = GetUserNameW( buffer, *lpSize * 2 );
return 0; if (ret)
} {
if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
*lpSize = len; {
strcpy(lpszName, name); *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
return 1; SetLastError( ERROR_MORE_DATA );
ret = FALSE;
}
}
HeapFree( GetProcessHeap(), 0, buffer );
return ret;
} }
/****************************************************************************** /******************************************************************************
@ -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 )
} }
*lpSize = len; *lpSize = len;
MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, len ); MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
return TRUE; return TRUE;
} }

View File

@ -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;
} }
/****************************************************************************** /******************************************************************************

View File

@ -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;
} }
/****************************************************************************** /******************************************************************************