comdlg32: Added Dutch translations.
[wine/winequartzdrv.git] / dlls / advapi32 / tests / lsa.c
blob4035416cdc5dd14957ccf4893face47b3ab58013
1 /*
2 * Unit tests for lsa functions
4 * Copyright (c) 2006 Robert Reif
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "ntstatus.h"
25 #define WIN32_NO_STATUS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "ntsecapi.h"
30 #include "sddl.h"
31 #include "winnls.h"
32 #include "objbase.h"
33 #define INITGUID
34 #include "guiddef.h"
35 #include "wine/test.h"
37 static HMODULE hadvapi32;
38 static NTSTATUS (WINAPI *pLsaClose)(LSA_HANDLE);
39 static NTSTATUS (WINAPI *pLsaFreeMemory)(PVOID);
40 static NTSTATUS (WINAPI *pLsaOpenPolicy)(PLSA_UNICODE_STRING,PLSA_OBJECT_ATTRIBUTES,ACCESS_MASK,PLSA_HANDLE);
41 static NTSTATUS (WINAPI *pLsaQueryInformationPolicy)(LSA_HANDLE,POLICY_INFORMATION_CLASS,PVOID*);
42 static BOOL (WINAPI *pConvertSidToStringSidA)(PSID pSid, LPSTR *str);
44 static BOOL init(void)
46 hadvapi32 = GetModuleHandle("advapi32.dll");
48 pLsaClose = (void*)GetProcAddress(hadvapi32, "LsaClose");
49 pLsaFreeMemory = (void*)GetProcAddress(hadvapi32, "LsaFreeMemory");
50 pLsaOpenPolicy = (void*)GetProcAddress(hadvapi32, "LsaOpenPolicy");
51 pLsaQueryInformationPolicy = (void*)GetProcAddress(hadvapi32, "LsaQueryInformationPolicy");
52 pConvertSidToStringSidA = (void*)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
54 if (pLsaClose && pLsaFreeMemory && pLsaOpenPolicy && pLsaQueryInformationPolicy && pConvertSidToStringSidA)
55 return TRUE;
57 return FALSE;
60 static void test_lsa(void)
62 NTSTATUS status;
63 LSA_HANDLE handle;
64 LSA_OBJECT_ATTRIBUTES object_attributes;
66 ZeroMemory(&object_attributes, sizeof(object_attributes));
67 object_attributes.Length = sizeof(object_attributes);
69 status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle);
70 ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
71 "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status);
73 /* try a more restricted access mask if necessary */
74 if (status == STATUS_ACCESS_DENIED) {
75 trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
76 status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_VIEW_LOCAL_INFORMATION, &handle);
77 ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08x\n", status);
80 if (status == STATUS_SUCCESS) {
81 PPOLICY_AUDIT_EVENTS_INFO audit_events_info;
82 PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info;
83 PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info;
84 PPOLICY_DNS_DOMAIN_INFO dns_domain_info;
86 status = pLsaQueryInformationPolicy(handle, PolicyAuditEventsInformation, (PVOID*)&audit_events_info);
87 if (status == STATUS_ACCESS_DENIED)
88 skip("Not enough rights to retrieve PolicyAuditEventsInformation\n");
89 else
90 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08x\n", status);
91 if (status == STATUS_SUCCESS) {
92 pLsaFreeMemory((LPVOID)audit_events_info);
95 status = pLsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (PVOID*)&primary_domain_info);
96 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08x\n", status);
97 if (status == STATUS_SUCCESS) {
98 ok(primary_domain_info->Sid==0,"Sid should be NULL on the local computer\n");
99 if (primary_domain_info->Sid) {
100 LPSTR strsid;
101 if (pConvertSidToStringSidA(primary_domain_info->Sid, &strsid))
103 if (primary_domain_info->Name.Buffer) {
104 LPSTR name = NULL;
105 UINT len;
106 len = WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
107 name = LocalAlloc( 0, len );
108 WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
109 trace(" name: %s sid: %s\n", name, strsid);
110 LocalFree( name );
111 } else
112 trace(" name: NULL sid: %s\n", strsid);
113 LocalFree( strsid );
115 else
116 trace("invalid sid\n");
118 pLsaFreeMemory((LPVOID)primary_domain_info);
121 status = pLsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (PVOID*)&account_domain_info);
122 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status);
123 if (status == STATUS_SUCCESS) {
124 pLsaFreeMemory((LPVOID)account_domain_info);
127 /* This isn't supported in NT4 */
128 status = pLsaQueryInformationPolicy(handle, PolicyDnsDomainInformation, (PVOID*)&dns_domain_info);
129 ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER,
130 "LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08x\n", status);
131 if (status == STATUS_SUCCESS) {
132 ok(IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL), "DomainGUID should be GUID_NULL on local computer\n");
133 ok(dns_domain_info->Sid==0,"Sid should be NULL on the local computer\n");
134 if (dns_domain_info->Sid || !IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL)) {
135 LPSTR strsid = NULL;
136 LPSTR name = NULL;
137 LPSTR domain = NULL;
138 LPSTR forest = NULL;
139 LPSTR guidstr = NULL;
140 WCHAR guidstrW[64];
141 UINT len;
142 guidstrW[0] = '\0';
143 pConvertSidToStringSidA(dns_domain_info->Sid, &strsid);
144 StringFromGUID2(&dns_domain_info->DomainGuid, guidstrW, sizeof(guidstrW)/sizeof(WCHAR));
145 len = WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, NULL, 0, NULL, NULL );
146 guidstr = LocalAlloc( 0, len );
147 WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, guidstr, len, NULL, NULL );
148 if (dns_domain_info->Name.Buffer) {
149 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
150 name = LocalAlloc( 0, len );
151 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
153 if (dns_domain_info->DnsDomainName.Buffer) {
154 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL );
155 domain = LocalAlloc( 0, len );
156 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL );
158 if (dns_domain_info->DnsForestName.Buffer) {
159 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL );
160 forest = LocalAlloc( 0, len );
161 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL );
163 trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n",
164 name ? name : "NULL", domain ? domain : "NULL",
165 forest ? forest : "NULL", guidstr, strsid ? strsid : "NULL");
166 LocalFree( name );
167 LocalFree( forest );
168 LocalFree( domain );
169 LocalFree( guidstr );
170 LocalFree( strsid );
172 pLsaFreeMemory((LPVOID)dns_domain_info);
175 status = pLsaClose(handle);
176 ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status);
180 START_TEST(lsa)
182 if (!init()) {
183 skip("Needed functions are not available\n");
184 return;
187 test_lsa();