Author: dchapyshev
Date: Wed Apr 22 18:11:17 2009
New Revision: 40648
URL:
http://svn.reactos.org/svn/reactos?rev=40648&view=rev
Log:
- Implement GetUserNameExA/W (code from Wine)
Modified:
trunk/reactos/dll/win32/secur32/secext.c
Modified: trunk/reactos/dll/win32/secur32/secext.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/secur32/secext.c…
==============================================================================
--- trunk/reactos/dll/win32/secur32/secext.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/secur32/secext.c [iso-8859-1] Wed Apr 22 18:11:17 2009
@@ -20,6 +20,8 @@
#define NDEBUG
#include <debug.h>
+
+#define UNLEN 256
/***********************************************************************
@@ -189,27 +191,99 @@
}
-BOOLEAN
-WINAPI
-GetUserNameExA (
- EXTENDED_NAME_FORMAT extended_exe_format,
- LPSTR lpstr,
- PULONG pulong
- )
-{
- UNIMPLEMENTED;
- return ERROR_CALL_NOT_IMPLEMENTED;
-}
-
-
-BOOLEAN
-WINAPI
-GetUserNameExW (
- EXTENDED_NAME_FORMAT extended_exe_format,
- LPWSTR lpstr,
- PULONG pulong
- )
-{
- UNIMPLEMENTED;
- return ERROR_CALL_NOT_IMPLEMENTED;
-}
+BOOLEAN WINAPI GetUserNameExA(
+ EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG nSize)
+{
+ BOOLEAN rc;
+ LPWSTR bufferW = NULL;
+ ULONG sizeW = *nSize;
+ DPRINT("(%d %p %p)\n", NameFormat, lpNameBuffer, nSize);
+ if (lpNameBuffer) {
+ bufferW = HeapAlloc(GetProcessHeap(), 0, sizeW * sizeof(WCHAR));
+ if (bufferW == NULL) {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
+ }
+ rc = GetUserNameExW(NameFormat, bufferW, &sizeW);
+ if (rc) {
+ ULONG len = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL);
+ if (len <= *nSize)
+ {
+ WideCharToMultiByte(CP_ACP, 0, bufferW, -1, lpNameBuffer, *nSize, NULL,
NULL);
+ *nSize = len - 1;
+ }
+ else
+ {
+ *nSize = len;
+ rc = FALSE;
+ SetLastError(ERROR_MORE_DATA);
+ }
+ }
+ else
+ *nSize = sizeW;
+ HeapFree(GetProcessHeap(), 0, bufferW);
+ return rc;
+}
+
+
+BOOLEAN WINAPI GetUserNameExW(
+ EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize)
+{
+ BOOLEAN status;
+ WCHAR samname[UNLEN + 1 + MAX_COMPUTERNAME_LENGTH + 1];
+ LPWSTR out;
+ DWORD len;
+ DPRINT("(%d %p %p)\n", NameFormat, lpNameBuffer, nSize);
+
+ switch (NameFormat)
+ {
+ case NameSamCompatible:
+ {
+ /* This assumes the current user is always a local account */
+ len = MAX_COMPUTERNAME_LENGTH + 1;
+ if (GetComputerNameW(samname, &len))
+ {
+ out = samname + lstrlenW(samname);
+ *out++ = '\\';
+ len = UNLEN + 1;
+ if (GetUserNameW(out, &len))
+ {
+ status = (lstrlenW(samname) < *nSize);
+ if (status)
+ {
+ lstrcpyW(lpNameBuffer, samname);
+ *nSize = lstrlenW(samname);
+ }
+ else
+ {
+ SetLastError(ERROR_MORE_DATA);
+ *nSize = lstrlenW(samname) + 1;
+ }
+ }
+ else
+ status = FALSE;
+ }
+ else
+ status = FALSE;
+ }
+ break;
+ case NameUnknown:
+ case NameFullyQualifiedDN:
+ case NameDisplay:
+ case NameUniqueId:
+ case NameCanonical:
+ case NameUserPrincipal:
+ case NameCanonicalEx:
+ case NameServicePrincipal:
+ case NameDnsDomain:
+ SetLastError(ERROR_NONE_MAPPED);
+ status = FALSE;
+ break;
+ default:
+ SetLastError(ERROR_INVALID_PARAMETER);
+ status = FALSE;
+ }
+
+ return status;
+}