Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/advapi32/tests/lsa.c
4389 views
1
/*
2
* Unit tests for lsa functions
3
*
4
* Copyright (c) 2006 Robert Reif
5
* Copyright (c) 2020 Dmitry Timoshkov
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#include <stdarg.h>
23
#include <stdio.h>
24
25
#include "ntstatus.h"
26
#define WIN32_NO_STATUS
27
#include "windef.h"
28
#include "winbase.h"
29
#include "winreg.h"
30
#include "ntsecapi.h"
31
#include "sddl.h"
32
#include "winnls.h"
33
#include "objbase.h"
34
#include "initguid.h"
35
#include "wine/test.h"
36
#include "winternl.h"
37
#include "ntlsa.h"
38
39
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
40
41
static BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, ULONG*, WCHAR*, ULONG*);
42
static NTSTATUS (WINAPI *pLsaGetUserName)(PUNICODE_STRING *user, PUNICODE_STRING *domain);
43
44
static void test_lsa(void)
45
{
46
NTSTATUS status;
47
LSA_HANDLE handle;
48
LSA_OBJECT_ATTRIBUTES object_attributes;
49
50
ZeroMemory(&object_attributes, sizeof(object_attributes));
51
object_attributes.Length = sizeof(object_attributes);
52
53
status = LsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle);
54
ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
55
"LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08lx\n", status);
56
57
/* try a more restricted access mask if necessary */
58
if (status == STATUS_ACCESS_DENIED) {
59
trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES\n");
60
status = LsaOpenPolicy( NULL, &object_attributes, POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES, &handle);
61
ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES) returned 0x%08lx\n", status);
62
}
63
64
if (status == STATUS_SUCCESS) {
65
PPOLICY_AUDIT_EVENTS_INFO audit_events_info;
66
PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info;
67
PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info;
68
PPOLICY_DNS_DOMAIN_INFO dns_domain_info;
69
HANDLE token;
70
BOOL ret;
71
72
status = LsaQueryInformationPolicy(handle, PolicyAuditEventsInformation, (void **)&audit_events_info);
73
if (status == STATUS_ACCESS_DENIED)
74
skip("Not enough rights to retrieve PolicyAuditEventsInformation\n");
75
else
76
ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08lx\n", status);
77
if (status == STATUS_SUCCESS)
78
LsaFreeMemory(audit_events_info);
79
80
status = LsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (void **)&primary_domain_info);
81
ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08lx\n", status);
82
if (status == STATUS_SUCCESS) {
83
if (primary_domain_info->Sid) {
84
LPSTR strsid;
85
if (ConvertSidToStringSidA(primary_domain_info->Sid, &strsid))
86
{
87
if (primary_domain_info->Name.Buffer) {
88
LPSTR name = NULL;
89
UINT len;
90
len = WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
91
name = LocalAlloc( 0, len );
92
WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
93
trace(" name: %s sid: %s\n", name, strsid);
94
LocalFree( name );
95
} else
96
trace(" name: NULL sid: %s\n", strsid);
97
LocalFree( strsid );
98
}
99
else
100
trace("invalid sid\n");
101
}
102
else
103
trace("Running on a standalone system.\n");
104
LsaFreeMemory(primary_domain_info);
105
}
106
107
status = LsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (void **)&account_domain_info);
108
ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08lx\n", status);
109
if (status == STATUS_SUCCESS)
110
LsaFreeMemory(account_domain_info);
111
112
/* This isn't supported in NT4 */
113
status = LsaQueryInformationPolicy(handle, PolicyDnsDomainInformation, (void **)&dns_domain_info);
114
ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER,
115
"LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08lx\n", status);
116
if (status == STATUS_SUCCESS) {
117
if (dns_domain_info->Sid || !IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL)) {
118
LPSTR strsid = NULL;
119
LPSTR name = NULL;
120
LPSTR domain = NULL;
121
LPSTR forest = NULL;
122
UINT len;
123
ConvertSidToStringSidA(dns_domain_info->Sid, &strsid);
124
if (dns_domain_info->Name.Buffer) {
125
len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
126
name = LocalAlloc( 0, len );
127
WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
128
}
129
if (dns_domain_info->DnsDomainName.Buffer) {
130
len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL );
131
domain = LocalAlloc( 0, len );
132
WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL );
133
}
134
if (dns_domain_info->DnsForestName.Buffer) {
135
len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL );
136
forest = LocalAlloc( 0, len );
137
WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL );
138
}
139
trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n",
140
debugstr_a(name), debugstr_a(domain), debugstr_a(forest),
141
debugstr_guid(&dns_domain_info->DomainGuid), debugstr_a(strsid));
142
LocalFree( name );
143
LocalFree( forest );
144
LocalFree( domain );
145
LocalFree( strsid );
146
}
147
else
148
trace("Running on a standalone system.\n");
149
LsaFreeMemory(dns_domain_info);
150
}
151
152
/* We need a valid SID to pass to LsaEnumerateAccountRights */
153
ret = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token );
154
ok(ret, "Unable to obtain process token, error %lu\n", GetLastError( ));
155
if (ret) {
156
char buffer[64];
157
DWORD len;
158
TOKEN_USER *token_user = (TOKEN_USER *) buffer;
159
ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, sizeof(buffer), &len );
160
ok(ret || GetLastError( ) == ERROR_INSUFFICIENT_BUFFER, "Unable to obtain token information, error %lu\n", GetLastError( ));
161
if (! ret && GetLastError( ) == ERROR_INSUFFICIENT_BUFFER) {
162
trace("Resizing buffer to %lu.\n", len);
163
token_user = LocalAlloc( 0, len );
164
if (token_user != NULL)
165
ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, len, &len );
166
}
167
168
if (ret) {
169
PLSA_UNICODE_STRING rights;
170
ULONG rights_count;
171
rights = (PLSA_UNICODE_STRING) 0xdeadbeaf;
172
rights_count = 0xcafecafe;
173
status = LsaEnumerateAccountRights(handle, token_user->User.Sid, &rights, &rights_count);
174
ok(status == STATUS_SUCCESS || status == STATUS_OBJECT_NAME_NOT_FOUND, "Unexpected status 0x%lx\n", status);
175
if (status == STATUS_SUCCESS)
176
LsaFreeMemory( rights );
177
else
178
ok(rights == NULL && rights_count == 0, "Expected rights and rights_count to be set to 0 on failure\n");
179
}
180
if (token_user != NULL && token_user != (TOKEN_USER *) buffer)
181
LocalFree( token_user );
182
CloseHandle( token );
183
}
184
185
status = LsaClose(handle);
186
ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08lx\n", status);
187
}
188
}
189
190
static void get_sid_info(PSID psid, LPSTR *user, LPSTR *dom)
191
{
192
static char account[257], domain[257];
193
DWORD user_size, dom_size;
194
SID_NAME_USE use;
195
BOOL ret;
196
197
*user = account;
198
*dom = domain;
199
200
user_size = dom_size = 257;
201
account[0] = domain[0] = 0;
202
ret = LookupAccountSidA(NULL, psid, account, &user_size, domain, &dom_size, &use);
203
ok(ret, "LookupAccountSidA failed %lu\n", GetLastError());
204
}
205
206
static void test_LsaLookupNames2(void)
207
{
208
static const WCHAR n1[] = {'L','O','C','A','L',' ','S','E','R','V','I','C','E'};
209
static const WCHAR n2[] = {'N','T',' ','A','U','T','H','O','R','I','T','Y','\\','L','o','c','a','l','S','e','r','v','i','c','e'};
210
211
NTSTATUS status;
212
LSA_HANDLE handle;
213
LSA_OBJECT_ATTRIBUTES attrs;
214
PLSA_REFERENCED_DOMAIN_LIST domains;
215
PLSA_TRANSLATED_SID2 sids;
216
LSA_UNICODE_STRING name[4];
217
LPSTR account, sid_dom;
218
DWORD len = 0;
219
BOOL ret;
220
221
if ((PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())) != LANG_ENGLISH) ||
222
(PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH))
223
{
224
skip("Non-English locale (skipping LsaLookupNames2 tests)\n");
225
return;
226
}
227
228
memset(&attrs, 0, sizeof(attrs));
229
attrs.Length = sizeof(attrs);
230
231
status = LsaOpenPolicy(NULL, &attrs, POLICY_ALL_ACCESS, &handle);
232
ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
233
"LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08lx\n", status);
234
235
/* try a more restricted access mask if necessary */
236
if (status == STATUS_ACCESS_DENIED)
237
{
238
trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
239
status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &handle);
240
ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08lx\n", status);
241
}
242
if (status != STATUS_SUCCESS)
243
{
244
skip("Cannot acquire policy handle\n");
245
return;
246
}
247
248
name[0].Buffer = malloc(sizeof(n1));
249
name[0].Length = name[0].MaximumLength = sizeof(n1);
250
memcpy(name[0].Buffer, n1, sizeof(n1));
251
252
name[1].Buffer = malloc(sizeof(n1));
253
name[1].Length = name[1].MaximumLength = sizeof(n1) - sizeof(WCHAR);
254
memcpy(name[1].Buffer, n1, sizeof(n1) - sizeof(WCHAR));
255
256
name[2].Buffer = malloc(sizeof(n2));
257
name[2].Length = name[2].MaximumLength = sizeof(n2);
258
memcpy(name[2].Buffer, n2, sizeof(n2));
259
260
ret = GetUserNameW(NULL, &len);
261
ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
262
"GetUserNameW returned %x (%lu)\n", ret, GetLastError());
263
name[3].Buffer = malloc(len * sizeof(WCHAR));
264
name[3].Length = name[3].MaximumLength = (len - 1) * sizeof(WCHAR);
265
ret = GetUserNameW(name[3].Buffer, &len);
266
ok(ret, "GetUserNameW returned %x (%lu)\n", ret, GetLastError());
267
268
/* account name only */
269
sids = NULL;
270
domains = NULL;
271
status = LsaLookupNames2(handle, 0, 1, &name[0], &domains, &sids);
272
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %lx)\n", status);
273
ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
274
ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
275
ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
276
get_sid_info(sids[0].Sid, &account, &sid_dom);
277
ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
278
ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
279
LsaFreeMemory(sids);
280
LsaFreeMemory(domains);
281
282
/* unknown account name */
283
sids = NULL;
284
domains = NULL;
285
status = LsaLookupNames2(handle, 0, 1, &name[1], &domains, &sids);
286
ok(status == STATUS_NONE_MAPPED, "expected STATUS_NONE_MAPPED, got %lx)\n", status);
287
ok(sids[0].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[0].Use);
288
ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
289
ok(domains->Entries == 0, "expected 0, got %lu\n", domains->Entries);
290
LsaFreeMemory(sids);
291
LsaFreeMemory(domains);
292
293
/* account + domain */
294
sids = NULL;
295
domains = NULL;
296
status = LsaLookupNames2(handle, 0, 1, &name[2], &domains, &sids);
297
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %lx)\n", status);
298
ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
299
ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
300
ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
301
get_sid_info(sids[0].Sid, &account, &sid_dom);
302
ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
303
ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
304
LsaFreeMemory(sids);
305
LsaFreeMemory(domains);
306
307
/* all three */
308
sids = NULL;
309
domains = NULL;
310
status = LsaLookupNames2(handle, 0, 3, name, &domains, &sids);
311
ok(status == STATUS_SOME_NOT_MAPPED, "expected STATUS_SOME_NOT_MAPPED, got %lx)\n", status);
312
ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
313
ok(sids[1].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[1].Use);
314
ok(sids[2].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[2].Use);
315
ok(sids[0].DomainIndex == 0, "expected 0, got %lu\n", sids[0].DomainIndex);
316
ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
317
LsaFreeMemory(sids);
318
LsaFreeMemory(domains);
319
320
/* case mismatch */
321
name[3].Buffer[0] = iswlower(name[3].Buffer[0]) ?
322
towupper(name[3].Buffer[0]) : tolower(name[3].Buffer[0]);
323
sids = NULL;
324
domains = NULL;
325
status = LsaLookupNames2(handle, 0, 1, &name[3], &domains, &sids);
326
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %lx)\n", status);
327
ok(sids[0].Use == SidTypeUser, "expected SidTypeUser, got %u\n", sids[0].Use);
328
ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
329
ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
330
LsaFreeMemory(sids);
331
LsaFreeMemory(domains);
332
333
free(name[0].Buffer);
334
free(name[1].Buffer);
335
free(name[2].Buffer);
336
free(name[3].Buffer);
337
338
status = LsaClose(handle);
339
ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08lx\n", status);
340
}
341
342
static void check_unicode_string_(int line, const LSA_UNICODE_STRING *string, const WCHAR *expect)
343
{
344
ok_(__FILE__, line)(string->Length == wcslen(string->Buffer) * sizeof(WCHAR),
345
"expected %Iu, got %u\n", wcslen(string->Buffer) * sizeof(WCHAR), string->Length);
346
ok_(__FILE__, line)(string->MaximumLength == string->Length + sizeof(WCHAR),
347
"expected %Iu, got %u\n", string->Length + sizeof(WCHAR), string->MaximumLength);
348
ok_(__FILE__, line)(!wcsicmp(string->Buffer, expect), "expected %s, got %s\n",
349
debugstr_w(expect), debugstr_w(string->Buffer));
350
}
351
#define check_unicode_string(a, b) check_unicode_string_(__LINE__, a, b)
352
353
static void test_LsaLookupSids(void)
354
{
355
WCHAR langW[32];
356
char user_buffer[64];
357
LSA_OBJECT_ATTRIBUTES attrs = {sizeof(attrs)};
358
TOKEN_USER *user = (TOKEN_USER *)user_buffer;
359
WCHAR computer_name[64], user_name[64];
360
LSA_REFERENCED_DOMAIN_LIST *list;
361
LSA_TRANSLATED_NAME *names;
362
LSA_HANDLE policy;
363
NTSTATUS status;
364
HANDLE token;
365
DWORD num, size;
366
BOOL ret;
367
PSID sid;
368
369
status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
370
ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
371
372
ret = OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &token);
373
ok(ret, "OpenProcessToken() failed, error %lu\n", GetLastError());
374
375
ret = GetTokenInformation(token, TokenUser, user, sizeof(user_buffer), &size);
376
ok(ret, "GetTokenInformation() failed, error %lu\n", GetLastError());
377
378
size = ARRAY_SIZE(computer_name);
379
ret = GetComputerNameW(computer_name, &size);
380
ok(ret, "GetComputerName() failed, error %lu\n", GetLastError());
381
382
size = ARRAY_SIZE(user_name);
383
ret = GetUserNameW(user_name, &size);
384
ok(ret, "GetUserName() failed, error %lu\n", GetLastError());
385
386
status = LsaLookupSids(policy, 1, &user->User.Sid, &list, &names);
387
ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
388
389
ok(list->Entries == 1, "got %ld\n", list->Entries);
390
check_unicode_string(&list->Domains[0].Name, computer_name);
391
392
ok(names[0].Use == SidTypeUser, "got type %u\n", names[0].Use);
393
ok(!names[0].DomainIndex, "got index %lu\n", names[0].DomainIndex);
394
check_unicode_string(&names[0].Name, user_name);
395
396
LsaFreeMemory(names);
397
LsaFreeMemory(list);
398
CloseHandle(token);
399
400
ret = ConvertStringSidToSidA("S-1-1-0", &sid);
401
ok(ret, "ConvertStringSidToSidA() failed, error %lu\n", GetLastError());
402
403
status = LsaLookupSids(policy, 1, &sid, &list, &names);
404
ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
405
406
ok(list->Entries == 1, "got %ld\n", list->Entries);
407
check_unicode_string(&list->Domains[0].Name, L"");
408
409
ok(names[0].Use == SidTypeWellKnownGroup, "got type %u\n", names[0].Use);
410
ok(!names[0].DomainIndex, "got index %lu\n", names[0].DomainIndex);
411
412
/* The group name gets translated... but not in all locales */
413
size = ARRAY_SIZE(langW);
414
if (!pGetSystemPreferredUILanguages ||
415
!pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
416
langW[0] = 0;
417
if (wcscmp(langW, L"0409") == 0 || wcscmp(langW, L"0411") == 0)
418
/* English and Japanese */
419
check_unicode_string(&names[0].Name, L"Everyone");
420
else if (wcscmp(langW, L"0407") == 0) /* German */
421
todo_wine ok(!wcsicmp(names[0].Name.Buffer, L"Jeder"), "missing translation %s\n",
422
debugstr_w(names[0].Name.Buffer));
423
else if (wcscmp(langW, L"040C") == 0) /* French */
424
todo_wine ok(!wcsicmp(names[0].Name.Buffer, L"Tout le monde"), "missing translation %s\n",
425
debugstr_w(names[0].Name.Buffer));
426
else
427
trace("<Everyone-group>.Name=%s\n", debugstr_w(names[0].Name.Buffer));
428
429
LsaFreeMemory(names);
430
LsaFreeMemory(list);
431
FreeSid(sid);
432
433
ret = ConvertStringSidToSidA("S-1-1234-5678-1234-5678", &sid);
434
ok(ret, "ConvertStringSidToSidA() failed, error %lu\n", GetLastError());
435
436
status = LsaLookupSids(policy, 1, &sid, &list, &names);
437
ok(status == STATUS_NONE_MAPPED, "got 0x%08lx\n", status);
438
439
ok(!list->Entries, "got %ld\n", list->Entries);
440
441
ok(names[0].Use == SidTypeUnknown, "got type %u\n", names[0].Use);
442
ok(names[0].DomainIndex == -1, "got index %lu\n", names[0].DomainIndex);
443
check_unicode_string(&names[0].Name, L"S-1-1234-5678-1234-5678");
444
445
LsaFreeMemory(names);
446
LsaFreeMemory(list);
447
FreeSid(sid);
448
449
status = LsaClose(policy);
450
ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
451
}
452
453
static void test_LsaLookupPrivilegeName(void)
454
{
455
LSA_OBJECT_ATTRIBUTES attrs;
456
LSA_UNICODE_STRING *name;
457
LSA_HANDLE policy;
458
NTSTATUS status;
459
LUID luid;
460
461
memset(&attrs, 0, sizeof(attrs));
462
attrs.Length = sizeof(attrs);
463
464
status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
465
ok(status == STATUS_SUCCESS, "Failed to open policy, %#lx.\n", status);
466
467
name = (void *)0xdeadbeef;
468
status = LsaLookupPrivilegeName(policy, NULL, &name);
469
ok(status != STATUS_SUCCESS, "Unexpected status %#lx.\n", status);
470
ok(name == (void *)0xdeadbeef, "Unexpected name pointer.\n");
471
472
name = (void *)0xdeadbeef;
473
luid.HighPart = 1;
474
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
475
status = LsaLookupPrivilegeName(policy, &luid, &name);
476
ok(status == STATUS_NO_SUCH_PRIVILEGE, "Unexpected status %#lx.\n", status);
477
ok(name == NULL, "Unexpected name pointer.\n");
478
479
luid.HighPart = 0;
480
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
481
status = LsaLookupPrivilegeName(policy, &luid, &name);
482
ok(status == 0, "got %#lx.\n", status);
483
LsaFreeMemory(name);
484
}
485
486
static void test_LsaGetUserName(void)
487
{
488
NTSTATUS status;
489
BOOL ret;
490
UNICODE_STRING *lsa_user, *lsa_domain;
491
WCHAR user[256], computer[256];
492
DWORD size;
493
494
if (!pLsaGetUserName)
495
{
496
skip("LsaGetUserName is not available on this platform\n");
497
return;
498
}
499
500
size = ARRAY_SIZE(user);
501
ret = GetUserNameW(user, &size);
502
ok(ret, "GetUserName error %lu\n", GetLastError());
503
504
size = ARRAY_SIZE(computer);
505
ret = GetComputerNameW(computer, &size);
506
ok(ret, "GetComputerName error %lu\n", GetLastError());
507
508
if (0) /* crashes under Windows */
509
status = pLsaGetUserName(NULL, NULL);
510
511
if (0) /* crashes under Windows */
512
status = pLsaGetUserName(NULL, &lsa_domain);
513
514
status = pLsaGetUserName(&lsa_user, NULL);
515
ok(!status, "got %#lx\n", status);
516
check_unicode_string(lsa_user, user);
517
LsaFreeMemory(lsa_user);
518
519
status = pLsaGetUserName(&lsa_user, &lsa_domain);
520
ok(!status, "got %#lx\n", status);
521
ok(!lstrcmpW(user, lsa_user->Buffer), "%s != %s\n", wine_dbgstr_w(user), wine_dbgstr_wn(lsa_user->Buffer, lsa_user->Length/sizeof(WCHAR)));
522
check_unicode_string(lsa_user, user);
523
check_unicode_string(lsa_domain, computer);
524
LsaFreeMemory(lsa_user);
525
LsaFreeMemory(lsa_domain);
526
}
527
528
START_TEST(lsa)
529
{
530
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
531
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
532
533
pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
534
pLsaGetUserName = (void *)GetProcAddress(hadvapi32, "LsaGetUserName");
535
536
test_lsa();
537
test_LsaLookupNames2();
538
test_LsaLookupSids();
539
test_LsaLookupPrivilegeName();
540
test_LsaGetUserName();
541
}
542
543