Kai Blin : advapi32: Fix output of GetUserNameW when joined to a domain.

Alexandre Julliard julliard at winehq.org
Wed Jun 3 09:31:16 CDT 2009


Module: wine
Branch: master
Commit: faf6f3f299a520480546c686ba6fa2178ea571e8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=faf6f3f299a520480546c686ba6fa2178ea571e8

Author: Kai Blin <kai.blin at gmail.com>
Date:   Wed Jun  3 09:35:49 2009 +0200

advapi32: Fix output of GetUserNameW when joined to a domain.

On a Windows box joined to a domain, GetUserName will not return the domain
part. On a Unix box joined to a domain via winbindd, wine_get_user_name will.
So we need to cut off the domain instead of just replacing the \ character.

---

 dlls/advapi32/advapi.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/dlls/advapi32/advapi.c b/dlls/advapi32/advapi.c
index 1be3a17..47286a1 100644
--- a/dlls/advapi32/advapi.c
+++ b/dlls/advapi32/advapi.c
@@ -32,6 +32,7 @@
 #include "wincred.h"
 
 #include "wine/library.h"
+#include "wine/unicode.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
@@ -86,6 +87,7 @@ GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
 {
     const char *name = wine_get_user_name();
     DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
+    LPWSTR backslash;
 
     if (len > *lpSize)
     {
@@ -99,9 +101,22 @@ GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
 
     /* 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] == '/') lpszName[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;
 }
 




More information about the wine-cvs mailing list