advapi32: Skip token attribute testing if OpenProcessToken() is not implemented.
[wine] / dlls / advapi32 / tests / lsa.c
1 /*
2  * Unit tests for lsa functions
3  *
4  * Copyright (c) 2006 Robert Reif
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "ntstatus.h"
25 #define WIN32_NO_STATUS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winternl.h"
30 #include "ntsecapi.h"
31
32 #include "wine/test.h"
33
34 static HMODULE hadvapi32;
35 static NTSTATUS (WINAPI *pLsaClose)(LSA_HANDLE);
36 static NTSTATUS (WINAPI *pLsaFreeMemory)(PVOID);
37 static NTSTATUS (WINAPI *pLsaOpenPolicy)(PLSA_UNICODE_STRING,PLSA_OBJECT_ATTRIBUTES,ACCESS_MASK,PLSA_HANDLE);
38 static NTSTATUS (WINAPI *pLsaQueryInformationPolicy)(LSA_HANDLE,POLICY_INFORMATION_CLASS,PVOID*);
39
40 static BOOL init(void)
41 {
42     hadvapi32 = GetModuleHandle("advapi32.dll");
43
44     if (hadvapi32) {
45         pLsaClose = (void*)GetProcAddress(hadvapi32, "LsaClose");
46         pLsaFreeMemory = (void*)GetProcAddress(hadvapi32, "LsaFreeMemory");
47         pLsaOpenPolicy = (void*)GetProcAddress(hadvapi32, "LsaOpenPolicy");
48         pLsaQueryInformationPolicy = (void*)GetProcAddress(hadvapi32, "LsaQueryInformationPolicy");
49
50         if (pLsaClose && pLsaFreeMemory && pLsaOpenPolicy && pLsaQueryInformationPolicy)
51             return TRUE;
52     }
53
54     return FALSE;
55 }
56
57 static void test_lsa(void)
58 {
59     NTSTATUS status;
60     LSA_HANDLE handle;
61     LSA_OBJECT_ATTRIBUTES object_attributes;
62
63     ZeroMemory(&object_attributes, sizeof(object_attributes));
64
65     status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle);
66     ok(status == STATUS_SUCCESS, "LsaOpenPolicy() returned 0x%08lx\n", status);
67
68     if (status == STATUS_SUCCESS) {
69         PPOLICY_PRIMARY_DOMAIN_INFO domain_info;
70
71         status = pLsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (PVOID*)&domain_info);
72         ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy() failed, returned 0x%08lx\n", status);
73         if (status == STATUS_SUCCESS)
74             pLsaFreeMemory((LPVOID)domain_info);
75
76         status = pLsaClose(handle);
77         ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08lx\n", status);
78     }
79 }
80
81 START_TEST(lsa)
82 {
83     if (!init())
84         return;
85
86     test_lsa();
87 }