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
25 #define WIN32_NO_STATUS
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");
49 pLsaClose = (void*)GetProcAddress(hadvapi32, "LsaClose");
50 pLsaFreeMemory = (void*)GetProcAddress(hadvapi32, "LsaFreeMemory");
51 pLsaOpenPolicy = (void*)GetProcAddress(hadvapi32, "LsaOpenPolicy");
52 pLsaQueryInformationPolicy = (void*)GetProcAddress(hadvapi32, "LsaQueryInformationPolicy");
53 pConvertSidToStringSidA = (void*)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
55 if (pLsaClose && pLsaFreeMemory && pLsaOpenPolicy && pLsaQueryInformationPolicy && pConvertSidToStringSidA)
58 skip("Needed functions are not available\n");
64 static void test_lsa(void)
68 LSA_OBJECT_ATTRIBUTES object_attributes;
70 ZeroMemory(&object_attributes, sizeof(object_attributes));
71 object_attributes.Length = sizeof(object_attributes);
73 status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle);
74 ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
75 "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status);
77 /* try a more restricted access mask if necessary */
78 if (status == STATUS_ACCESS_DENIED) {
79 trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
80 status = pLsaOpenPolicy( NULL, &object_attributes, POLICY_VIEW_LOCAL_INFORMATION, &handle);
81 ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08x\n", status);
84 if (status == STATUS_SUCCESS) {
85 PPOLICY_AUDIT_EVENTS_INFO audit_events_info;
86 PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info;
87 PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info;
88 PPOLICY_DNS_DOMAIN_INFO dns_domain_info;
90 status = pLsaQueryInformationPolicy(handle, PolicyAuditEventsInformation, (PVOID*)&audit_events_info);
91 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08x\n", status);
92 if (status == STATUS_SUCCESS) {
93 pLsaFreeMemory((LPVOID)audit_events_info);
96 status = pLsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (PVOID*)&primary_domain_info);
97 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08x\n", status);
98 if (status == STATUS_SUCCESS) {
99 ok(primary_domain_info->Sid==0,"Sid should be NULL on the local computer\n");
100 if (primary_domain_info->Sid) {
102 if (pConvertSidToStringSidA(primary_domain_info->Sid, &strsid))
104 if (primary_domain_info->Name.Buffer) {
107 len = WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
108 name = LocalAlloc( 0, len );
109 WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
110 trace(" name: %s sid: %s\n", name, strsid);
113 trace(" name: NULL sid: %s\n", strsid);
117 trace("invalid sid\n");
119 pLsaFreeMemory((LPVOID)primary_domain_info);
122 status = pLsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (PVOID*)&account_domain_info);
123 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status);
124 if (status == STATUS_SUCCESS) {
125 pLsaFreeMemory((LPVOID)account_domain_info);
128 /* This isn't supported in NT4 */
129 status = pLsaQueryInformationPolicy(handle, PolicyDnsDomainInformation, (PVOID*)&dns_domain_info);
130 ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER,
131 "LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08x\n", status);
132 if (status == STATUS_SUCCESS) {
133 ok(IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL), "DomainGUID should be GUID_NULL on local computer\n");
134 ok(dns_domain_info->Sid==0,"Sid should be NULL on the local computer\n");
135 if (dns_domain_info->Sid || !IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL)) {
140 LPSTR guidstr = NULL;
144 pConvertSidToStringSidA(dns_domain_info->Sid, &strsid);
145 StringFromGUID2(&dns_domain_info->DomainGuid, guidstrW, sizeof(guidstrW)/sizeof(WCHAR));
146 len = WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, NULL, 0, NULL, NULL );
147 guidstr = LocalAlloc( 0, len );
148 WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, guidstr, len, NULL, NULL );
149 if (dns_domain_info->Name.Buffer) {
150 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
151 name = LocalAlloc( 0, len );
152 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
154 if (dns_domain_info->DnsDomainName.Buffer) {
155 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL );
156 domain = LocalAlloc( 0, len );
157 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL );
159 if (dns_domain_info->DnsForestName.Buffer) {
160 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL );
161 forest = LocalAlloc( 0, len );
162 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL );
164 trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n",
165 name ? name : "NULL", domain ? domain : "NULL",
166 forest ? forest : "NULL", guidstr, strsid ? strsid : "NULL");
170 LocalFree( guidstr );
173 pLsaFreeMemory((LPVOID)dns_domain_info);
176 status = pLsaClose(handle);
177 ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status);