advapi32: add computer sid tests

Robert Reif reif at earthlink.net
Mon Jul 31 19:42:34 CDT 2006


-------------- next part --------------
diff -p -u -r1.34 security.c
--- dlls/advapi32/tests/security.c	31 Jul 2006 09:33:04 -0000	1.34
+++ dlls/advapi32/tests/security.c	1 Aug 2006 00:40:28 -0000
@@ -18,15 +18,21 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <stdarg.h>
 #include <stdio.h>
 
-#include "wine/test.h"
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
 #include "windef.h"
 #include "winbase.h"
 #include "winerror.h"
 #include "aclapi.h"
 #include "winnt.h"
+#include "winternl.h"
 #include "sddl.h"
+#include "ntsecapi.h"
+
+#include "wine/test.h"
 
 typedef VOID (WINAPI *fnBuildTrusteeWithSidA)( PTRUSTEEA pTrustee, PSID pSid );
 typedef VOID (WINAPI *fnBuildTrusteeWithNameA)( PTRUSTEEA pTrustee, LPSTR pName );
@@ -49,6 +55,11 @@ typedef BOOL (WINAPI *fnGetFileSecurityA
 typedef DWORD (WINAPI *fnRtlAdjustPrivilege)(ULONG,BOOLEAN,BOOLEAN,PBOOLEAN);
 typedef BOOL (WINAPI *fnCreateWellKnownSid)(WELL_KNOWN_SID_TYPE,PSID,PSID,DWORD*);
 
+typedef NTSTATUS (WINAPI *fnLsaQueryInformationPolicy)(LSA_HANDLE,POLICY_INFORMATION_CLASS,PVOID*);
+typedef NTSTATUS (WINAPI *fnLsaClose)(LSA_HANDLE);
+typedef NTSTATUS (WINAPI *fnLsaFreeMemory)(PVOID);
+typedef NTSTATUS (WINAPI *fnLsaOpenPolicy)(PLSA_UNICODE_STRING,PLSA_OBJECT_ATTRIBUTES,ACCESS_MASK,PLSA_HANDLE);
+
 static HMODULE hmod;
 
 fnBuildTrusteeWithSidA   pBuildTrusteeWithSidA;
@@ -61,6 +72,10 @@ fnConvertStringSidToSidA pConvertStringS
 fnGetFileSecurityA pGetFileSecurityA;
 fnRtlAdjustPrivilege pRtlAdjustPrivilege;
 fnCreateWellKnownSid pCreateWellKnownSid;
+fnLsaQueryInformationPolicy pLsaQueryInformationPolicy;
+fnLsaClose pLsaClose;
+fnLsaFreeMemory pLsaFreeMemory;
+fnLsaOpenPolicy pLsaOpenPolicy;
 
 struct sidRef
 {
@@ -852,7 +867,7 @@ static void test_LookupAccountSid(void)
 
     ret = AllocateAndInitializeSid(&SIDAuthNT, 2, SECURITY_BUILTIN_DOMAIN_RID,
         DOMAIN_ALIAS_RID_USERS, 0, 0, 0, 0, 0, 0, &pUsersSid);
-    ok(ret, "AllocateAndInitializeSid failed with error %ld\n", GetLastError());    
+    ok(ret, "AllocateAndInitializeSid failed with error %ld\n", GetLastError());
 
     /* try NULL account */
     acc_size = MAX_PATH;
@@ -882,11 +897,114 @@ static void test_LookupAccountSid(void)
                     dom_size = MAX_PATH;
                     if (LookupAccountSid(NULL, &max_sid.sid, account, &acc_size, domain, &dom_size, &use))
                         trace(" %d: %s %s\\%s %d\n", i, str_sid, domain, account, use);
-                    LocalFree(str_sid); 
+                    LocalFree(str_sid);
                 }
             }
             else
-                trace(" CreateWellKnownSid(%d) failed: %ld\n", i, GetLastError()); 
+                trace(" CreateWellKnownSid(%d) failed: %ld\n", i, GetLastError());
+        }
+
+        pLsaQueryInformationPolicy = (fnLsaQueryInformationPolicy)GetProcAddress( hmod, "LsaQueryInformationPolicy");
+        pLsaOpenPolicy = (fnLsaOpenPolicy)GetProcAddress( hmod, "LsaOpenPolicy");
+        pLsaFreeMemory = (fnLsaFreeMemory)GetProcAddress( hmod, "LsaFreeMemory");
+        pLsaClose = (fnLsaClose)GetProcAddress( hmod, "LsaClose");
+
+        if (pLsaQueryInformationPolicy && pLsaOpenPolicy && pLsaFreeMemory && pLsaClose)
+        {
+            NTSTATUS status;
+            LSA_HANDLE handle;
+            LSA_OBJECT_ATTRIBUTES object_attributes;
+
+            ZeroMemory(&object_attributes, sizeof(object_attributes));
+
+            status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle);
+            ok(status == STATUS_SUCCESS, "LsaOpenPolicy() returned 0x%08lx\n", status);
+
+            if (status == STATUS_SUCCESS)
+            {
+                PPOLICY_ACCOUNT_DOMAIN_INFO info;
+                status = pLsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (PVOID*)&info);
+                ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy() failed, returned 0x%08lx\n", status);
+                if (status == STATUS_SUCCESS)
+                {
+                    ok(info->DomainSid!=0, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) missing SID\n");
+                    if (info->DomainSid)
+                    {
+                        int count = *GetSidSubAuthorityCount(info->DomainSid);
+                        int len = GetSidLengthRequired(count);
+
+                        CopySid(len, &max_sid, info->DomainSid);
+
+                        ret = pConvertSidToStringSidA(&max_sid.sid, &str_sid);
+                        ok(ret, "ConvertSidToStringSidA() failed: %ld\n", GetLastError());
+                        if (ret)
+                        {
+                            acc_size = MAX_PATH;
+                            dom_size = MAX_PATH;
+                            ret = LookupAccountSid(NULL, &max_sid.sid, account, &acc_size, domain, &dom_size, &use);
+                            ok(ret, "LookupAccountSid(%s) failed: %ld\n", str_sid, GetLastError());
+                            if (ret)
+                                trace(" %s %s\\%s %d\n", str_sid, domain, account, use);
+                            LocalFree(str_sid);
+                        }
+
+                        max_sid.sid.SubAuthority[count] = DOMAIN_USER_RID_ADMIN;
+                        max_sid.sid.SubAuthorityCount = count + 1;
+
+                        ret = pConvertSidToStringSidA(&max_sid.sid, &str_sid);
+                        ok(ret, "ConvertSidToStringSidA() failed: %ld\n", GetLastError());
+                        if (ret)
+                        {
+                            acc_size = MAX_PATH;
+                            dom_size = MAX_PATH;
+                            ret = LookupAccountSid(NULL, &max_sid.sid, account, &acc_size, domain, &dom_size, &use);
+                            ok(ret, "LookupAccountSid(%s) failed: %ld\n", str_sid, GetLastError());
+                            if (ret)
+                                trace(" %s %s\\%s %d\n", str_sid, domain, account, use);
+                            LocalFree(str_sid);
+                        }
+
+                        max_sid.sid.SubAuthority[count] = DOMAIN_USER_RID_GUEST;
+                        max_sid.sid.SubAuthorityCount = count + 1;
+
+                        ret = pConvertSidToStringSidA(&max_sid.sid, &str_sid);
+                        ok(ret, "ConvertSidToStringSidA() failed: %ld\n", GetLastError());
+                        if (ret)
+                        {
+                            acc_size = MAX_PATH;
+                            dom_size = MAX_PATH;
+                            ret = LookupAccountSid(NULL, &max_sid.sid, account, &acc_size, domain, &dom_size, &use);
+                            ok(ret, "LookupAccountSid(%s) failed: %ld\n", str_sid, GetLastError());
+                            if (ret)
+                                trace(" %s %s\\%s %d\n", str_sid, domain, account, use);
+                            LocalFree(str_sid);
+                        }
+
+                        max_sid.sid.SubAuthority[count] = 1000;
+                        max_sid.sid.SubAuthorityCount = count + 1;
+
+                        ret = pConvertSidToStringSidA(&max_sid.sid, &str_sid);
+                        ok(ret, "ConvertSidToStringSidA() failed: %ld\n", GetLastError());
+                        if (ret)
+                        {
+                            acc_size = MAX_PATH;
+                            dom_size = MAX_PATH;
+                            ret = LookupAccountSid(NULL, &max_sid.sid, account, &acc_size, domain, &dom_size, &use);
+                            /* this can fail if no user accounts exist */
+                            if (ret)
+                                trace(" %s %s\\%s %d\n", str_sid, domain, account, use);
+                            else
+                                trace("LookupAccountSid(%s) failed: %ld\n", str_sid, GetLastError());
+                            LocalFree(str_sid);
+                        }
+                    }
+
+                    pLsaFreeMemory((LPVOID)info);
+                }
+
+                status = pLsaClose(handle);
+                ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08lx\n", status);
+            }
         }
     }
 }


More information about the wine-patches mailing list