Hello,

I get a unit test failure for getUserIdent when trying to build under Windows 7 (Professional, 64-bit), logged in as a domain user.

Output for error:
C:/sources/libo-core/sal/qa/osl/security/osl_Security.cxx:135:osl_Security::getUserIdent::getUserIdent_001
assertion failed
- Expression: strUserID.equals(strID) && bRes
- strUserID: S-1-5-21-3685578860-4172030127-4274943249-1000, strID: S-1-5-21-2709487531-110703884-4059662957-1146, bRes: true

strID equals the SID for the domain user (NOVENTUS.NOVENTUS.COM\peter.grimtell), but strID equals the SID for a local account by the same name (peter.grimtell).

I did a little testing, and found that GetUserNameA() returns the name without the domain part, and therefore returns the same for the domain account as for the local account. When this name is sent on LookupAccountNameW() it returns the SID for the local account. To get the full user name, one seems to need to call GetUserNameExA(NameDnsDomain, ...). I patched the unit test as below, and then the build went through. But is it the unit test that is wrong, or is it the code under test, or is my account setup not supported by design?

diff --git a/sal/qa/osl/security/osl_Security.cxx b/sal/qa/osl/security/osl_Security.cxx
index b675ab1..8e07836 100644
--- a/sal/qa/osl/security/osl_Security.cxx
+++ b/sal/qa/osl/security/osl_Security.cxx
@@ -19,6 +19,9 @@

 #ifdef WNT
 #include <windows.h>
+#define SECURITY_WIN32
+#include <Security.h>
+#pragma comment( lib, "Secur32" )
 #undef min
 #endif
 #include <osl_Security_Const.h>
@@ -403,8 +406,11 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *,
     SID_NAME_USE eSidType;
     DWORD dwErrorCode = 0;

-    LPCWSTR wszAccName = ( LPWSTR ) strUserName.getStr( );
-
+    WCHAR wchAccName[BUFSIZE];
+    DWORD cchAccName = sizeof wchAccName / sizeof(WCHAR);
+    if( !GetUserNameExW(NameDnsDomain, wchAccName, &cchAccName) )
+        wchAccName[0] = L'\0';
+
     // Create buffers for the SID and the domain name.
     PSID pSid = (PSID) new BYTE[dwSidBufferSize];
CPPUNIT_ASSERT_MESSAGE("# creating SID buffer failed.\n", pSid!= NULL ); @@ -422,7 +428,7 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *,
         cchDomainName = dwDomainBufferSize;
         if (LookupAccountNameW(
NULL, // Computer name. NULL for the local computer
-                           wszAccName,
+                           wchAccName,
pSid, // Pointer to the SID buffer. Use NULL to get the size needed, &cbSid, // Size of the SID buffer needed.
                            wszDomainName,   // wszDomainName,
@@ -431,7 +437,7 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *,
                            ))
         {
             if (IsValidSid( pSid) == FALSE)
-                wprintf(L"# The SID for %s is invalid.\n", wszAccName);
+                wprintf(L"# The SID for %s is invalid.\n", wchAccName);
             break;
         }
         dwErrorCode = GetLastError();

Thanks,
Peter

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to