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
34 #include "wine/test.h"
36 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
38 static HMODULE hadvapi32
;
39 static NTSTATUS (WINAPI
*pLsaClose
)(LSA_HANDLE
);
40 static NTSTATUS (WINAPI
*pLsaFreeMemory
)(PVOID
);
41 static NTSTATUS (WINAPI
*pLsaOpenPolicy
)(PLSA_UNICODE_STRING
,PLSA_OBJECT_ATTRIBUTES
,ACCESS_MASK
,PLSA_HANDLE
);
42 static NTSTATUS (WINAPI
*pLsaQueryInformationPolicy
)(LSA_HANDLE
,POLICY_INFORMATION_CLASS
,PVOID
*);
43 static BOOL (WINAPI
*pConvertSidToStringSidA
)(PSID pSid
, LPSTR
*str
);
45 static BOOL
init(void)
47 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
)
61 static void test_lsa(void)
65 LSA_OBJECT_ATTRIBUTES object_attributes
;
67 ZeroMemory(&object_attributes
, sizeof(object_attributes
));
68 object_attributes
.Length
= sizeof(object_attributes
);
70 status
= pLsaOpenPolicy( NULL
, &object_attributes
, POLICY_ALL_ACCESS
, &handle
);
71 ok(status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_DENIED
,
72 "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status
);
74 /* try a more restricted access mask if necessary */
75 if (status
== STATUS_ACCESS_DENIED
) {
76 trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
77 status
= pLsaOpenPolicy( NULL
, &object_attributes
, POLICY_VIEW_LOCAL_INFORMATION
, &handle
);
78 ok(status
== STATUS_SUCCESS
, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08x\n", status
);
81 if (status
== STATUS_SUCCESS
) {
82 PPOLICY_AUDIT_EVENTS_INFO audit_events_info
;
83 PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info
;
84 PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info
;
85 PPOLICY_DNS_DOMAIN_INFO dns_domain_info
;
87 status
= pLsaQueryInformationPolicy(handle
, PolicyAuditEventsInformation
, (PVOID
*)&audit_events_info
);
88 if (status
== STATUS_ACCESS_DENIED
)
89 skip("Not enough rights to retrieve PolicyAuditEventsInformation\n");
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 if (primary_domain_info
->Sid
) {
101 if (pConvertSidToStringSidA(primary_domain_info
->Sid
, &strsid
))
103 if (primary_domain_info
->Name
.Buffer
) {
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
);
112 trace(" name: NULL sid: %s\n", strsid
);
116 trace("invalid sid\n");
119 trace("Running on a standalone system.\n");
120 pLsaFreeMemory((LPVOID
)primary_domain_info
);
123 status
= pLsaQueryInformationPolicy(handle
, PolicyAccountDomainInformation
, (PVOID
*)&account_domain_info
);
124 ok(status
== STATUS_SUCCESS
, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status
);
125 if (status
== STATUS_SUCCESS
) {
126 pLsaFreeMemory((LPVOID
)account_domain_info
);
129 /* This isn't supported in NT4 */
130 status
= pLsaQueryInformationPolicy(handle
, PolicyDnsDomainInformation
, (PVOID
*)&dns_domain_info
);
131 ok(status
== STATUS_SUCCESS
|| status
== STATUS_INVALID_PARAMETER
,
132 "LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08x\n", status
);
133 if (status
== STATUS_SUCCESS
) {
134 if (dns_domain_info
->Sid
|| !IsEqualGUID(&dns_domain_info
->DomainGuid
, &GUID_NULL
)) {
139 LPSTR guidstr
= NULL
;
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");
169 LocalFree( guidstr
);
173 trace("Running on a standalone system.\n");
174 pLsaFreeMemory((LPVOID
)dns_domain_info
);
177 status
= pLsaClose(handle
);
178 ok(status
== STATUS_SUCCESS
, "LsaClose() failed, returned 0x%08x\n", status
);
185 skip("Needed functions are not available\n");