mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / advapi32 / tests / lsa.c
blobf8c822a7de2fa017b7a039b592eb5091285486b0
1 /*
2 * Unit tests for lsa functions
4 * Copyright (c) 2006 Robert Reif
5 * Copyright (c) 2020 Dmitry Timoshkov
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.
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.
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
22 #include <stdarg.h>
23 #include <stdio.h>
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"
39 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
41 static BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, ULONG*, WCHAR*, ULONG*);
42 static NTSTATUS (WINAPI *pLsaGetUserName)(PUNICODE_STRING *user, PUNICODE_STRING *domain);
44 static void test_lsa(void)
46 NTSTATUS status;
47 LSA_HANDLE handle;
48 LSA_OBJECT_ATTRIBUTES object_attributes;
50 ZeroMemory(&object_attributes, sizeof(object_attributes));
51 object_attributes.Length = sizeof(object_attributes);
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%08x\n", status);
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%08x\n", status);
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;
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%08x\n", status);
77 if (status == STATUS_SUCCESS)
78 LsaFreeMemory(audit_events_info);
80 status = LsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (void **)&primary_domain_info);
81 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08x\n", status);
82 if (status == STATUS_SUCCESS) {
83 if (primary_domain_info->Sid) {
84 LPSTR strsid;
85 if (ConvertSidToStringSidA(primary_domain_info->Sid, &strsid))
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 );
99 else
100 trace("invalid sid\n");
102 else
103 trace("Running on a standalone system.\n");
104 LsaFreeMemory(primary_domain_info);
107 status = LsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (void **)&account_domain_info);
108 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status);
109 if (status == STATUS_SUCCESS)
110 LsaFreeMemory(account_domain_info);
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%08x\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 LPSTR guidstr = NULL;
123 WCHAR guidstrW[64];
124 UINT len;
125 guidstrW[0] = '\0';
126 ConvertSidToStringSidA(dns_domain_info->Sid, &strsid);
127 StringFromGUID2(&dns_domain_info->DomainGuid, guidstrW, ARRAY_SIZE(guidstrW));
128 len = WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, NULL, 0, NULL, NULL );
129 guidstr = LocalAlloc( 0, len );
130 WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, guidstr, len, NULL, NULL );
131 if (dns_domain_info->Name.Buffer) {
132 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
133 name = LocalAlloc( 0, len );
134 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
136 if (dns_domain_info->DnsDomainName.Buffer) {
137 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL );
138 domain = LocalAlloc( 0, len );
139 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL );
141 if (dns_domain_info->DnsForestName.Buffer) {
142 len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL );
143 forest = LocalAlloc( 0, len );
144 WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL );
146 trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n",
147 name ? name : "NULL", domain ? domain : "NULL",
148 forest ? forest : "NULL", guidstr, strsid ? strsid : "NULL");
149 LocalFree( name );
150 LocalFree( forest );
151 LocalFree( domain );
152 LocalFree( guidstr );
153 LocalFree( strsid );
155 else
156 trace("Running on a standalone system.\n");
157 LsaFreeMemory(dns_domain_info);
160 /* We need a valid SID to pass to LsaEnumerateAccountRights */
161 ret = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token );
162 ok(ret, "Unable to obtain process token, error %u\n", GetLastError( ));
163 if (ret) {
164 char buffer[64];
165 DWORD len;
166 TOKEN_USER *token_user = (TOKEN_USER *) buffer;
167 ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, sizeof(buffer), &len );
168 ok(ret || GetLastError( ) == ERROR_INSUFFICIENT_BUFFER, "Unable to obtain token information, error %u\n", GetLastError( ));
169 if (! ret && GetLastError( ) == ERROR_INSUFFICIENT_BUFFER) {
170 trace("Resizing buffer to %u.\n", len);
171 token_user = LocalAlloc( 0, len );
172 if (token_user != NULL)
173 ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, len, &len );
176 if (ret) {
177 PLSA_UNICODE_STRING rights;
178 ULONG rights_count;
179 rights = (PLSA_UNICODE_STRING) 0xdeadbeaf;
180 rights_count = 0xcafecafe;
181 status = LsaEnumerateAccountRights(handle, token_user->User.Sid, &rights, &rights_count);
182 ok(status == STATUS_SUCCESS || status == STATUS_OBJECT_NAME_NOT_FOUND, "Unexpected status 0x%x\n", status);
183 if (status == STATUS_SUCCESS)
184 LsaFreeMemory( rights );
185 else
186 ok(rights == NULL && rights_count == 0, "Expected rights and rights_count to be set to 0 on failure\n");
188 if (token_user != NULL && token_user != (TOKEN_USER *) buffer)
189 LocalFree( token_user );
190 CloseHandle( token );
193 status = LsaClose(handle);
194 ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status);
198 static void get_sid_info(PSID psid, LPSTR *user, LPSTR *dom)
200 static char account[257], domain[257];
201 DWORD user_size, dom_size;
202 SID_NAME_USE use;
203 BOOL ret;
205 *user = account;
206 *dom = domain;
208 user_size = dom_size = 257;
209 account[0] = domain[0] = 0;
210 ret = LookupAccountSidA(NULL, psid, account, &user_size, domain, &dom_size, &use);
211 ok(ret, "LookupAccountSidA failed %u\n", GetLastError());
214 static void test_LsaLookupNames2(void)
216 static const WCHAR n1[] = {'L','O','C','A','L',' ','S','E','R','V','I','C','E'};
217 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'};
219 NTSTATUS status;
220 LSA_HANDLE handle;
221 LSA_OBJECT_ATTRIBUTES attrs;
222 PLSA_REFERENCED_DOMAIN_LIST domains;
223 PLSA_TRANSLATED_SID2 sids;
224 LSA_UNICODE_STRING name[3];
225 LPSTR account, sid_dom;
227 if ((PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())) != LANG_ENGLISH) ||
228 (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH))
230 skip("Non-English locale (skipping LsaLookupNames2 tests)\n");
231 return;
234 memset(&attrs, 0, sizeof(attrs));
235 attrs.Length = sizeof(attrs);
237 status = LsaOpenPolicy(NULL, &attrs, POLICY_ALL_ACCESS, &handle);
238 ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
239 "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status);
241 /* try a more restricted access mask if necessary */
242 if (status == STATUS_ACCESS_DENIED)
244 trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
245 status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &handle);
246 ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08x\n", status);
248 if (status != STATUS_SUCCESS)
250 skip("Cannot acquire policy handle\n");
251 return;
254 name[0].Buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(n1));
255 name[0].Length = name[0].MaximumLength = sizeof(n1);
256 memcpy(name[0].Buffer, n1, sizeof(n1));
258 name[1].Buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(n1));
259 name[1].Length = name[1].MaximumLength = sizeof(n1) - sizeof(WCHAR);
260 memcpy(name[1].Buffer, n1, sizeof(n1) - sizeof(WCHAR));
262 name[2].Buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(n2));
263 name[2].Length = name[2].MaximumLength = sizeof(n2);
264 memcpy(name[2].Buffer, n2, sizeof(n2));
266 /* account name only */
267 sids = NULL;
268 domains = NULL;
269 status = LsaLookupNames2(handle, 0, 1, &name[0], &domains, &sids);
270 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %x)\n", status);
271 ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
272 ok(sids[0].Flags == 0, "expected 0, got 0x%08x\n", sids[0].Flags);
273 ok(domains->Entries == 1, "expected 1, got %u\n", domains->Entries);
274 get_sid_info(sids[0].Sid, &account, &sid_dom);
275 ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
276 ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
277 LsaFreeMemory(sids);
278 LsaFreeMemory(domains);
280 /* unknown account name */
281 sids = NULL;
282 domains = NULL;
283 status = LsaLookupNames2(handle, 0, 1, &name[1], &domains, &sids);
284 ok(status == STATUS_NONE_MAPPED, "expected STATUS_NONE_MAPPED, got %x)\n", status);
285 ok(sids[0].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[0].Use);
286 ok(sids[0].Flags == 0, "expected 0, got 0x%08x\n", sids[0].Flags);
287 ok(domains->Entries == 0, "expected 0, got %u\n", domains->Entries);
288 LsaFreeMemory(sids);
289 LsaFreeMemory(domains);
291 /* account + domain */
292 sids = NULL;
293 domains = NULL;
294 status = LsaLookupNames2(handle, 0, 1, &name[2], &domains, &sids);
295 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %x)\n", status);
296 ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
297 ok(sids[0].Flags == 0, "expected 0, got 0x%08x\n", sids[0].Flags);
298 ok(domains->Entries == 1, "expected 1, got %u\n", domains->Entries);
299 get_sid_info(sids[0].Sid, &account, &sid_dom);
300 ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
301 ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
302 LsaFreeMemory(sids);
303 LsaFreeMemory(domains);
305 /* all three */
306 sids = NULL;
307 domains = NULL;
308 status = LsaLookupNames2(handle, 0, 3, name, &domains, &sids);
309 ok(status == STATUS_SOME_NOT_MAPPED, "expected STATUS_SOME_NOT_MAPPED, got %x)\n", status);
310 ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
311 ok(sids[1].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[1].Use);
312 ok(sids[2].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[2].Use);
313 ok(sids[0].DomainIndex == 0, "expected 0, got %u\n", sids[0].DomainIndex);
314 ok(domains->Entries == 1, "expected 1, got %u\n", domains->Entries);
315 LsaFreeMemory(sids);
316 LsaFreeMemory(domains);
318 HeapFree(GetProcessHeap(), 0, name[0].Buffer);
319 HeapFree(GetProcessHeap(), 0, name[1].Buffer);
320 HeapFree(GetProcessHeap(), 0, name[2].Buffer);
322 status = LsaClose(handle);
323 ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status);
326 static void check_unicode_string_(int line, const LSA_UNICODE_STRING *string, const WCHAR *expect)
328 ok_(__FILE__, line)(string->Length == wcslen(string->Buffer) * sizeof(WCHAR),
329 "expected %u, got %u\n", wcslen(string->Buffer) * sizeof(WCHAR), string->Length);
330 ok_(__FILE__, line)(string->MaximumLength == string->Length + sizeof(WCHAR),
331 "expected %u, got %u\n", string->Length + sizeof(WCHAR), string->MaximumLength);
332 ok_(__FILE__, line)(!wcsicmp(string->Buffer, expect), "expected %s, got %s\n",
333 debugstr_w(expect), debugstr_w(string->Buffer));
335 #define check_unicode_string(a, b) check_unicode_string_(__LINE__, a, b)
337 static void test_LsaLookupSids(void)
339 WCHAR langW[32];
340 char user_buffer[64];
341 LSA_OBJECT_ATTRIBUTES attrs = {sizeof(attrs)};
342 TOKEN_USER *user = (TOKEN_USER *)user_buffer;
343 WCHAR computer_name[64], user_name[64];
344 LSA_REFERENCED_DOMAIN_LIST *list;
345 LSA_TRANSLATED_NAME *names;
346 LSA_HANDLE policy;
347 NTSTATUS status;
348 HANDLE token;
349 DWORD num, size;
350 BOOL ret;
351 PSID sid;
353 status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
354 ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
356 ret = OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &token);
357 ok(ret, "OpenProcessToken() failed, error %u\n", GetLastError());
359 ret = GetTokenInformation(token, TokenUser, user, sizeof(user_buffer), &size);
360 ok(ret, "GetTokenInformation() failed, error %u\n", GetLastError());
362 size = ARRAY_SIZE(computer_name);
363 ret = GetComputerNameW(computer_name, &size);
364 ok(ret, "GetComputerName() failed, error %u\n", GetLastError());
366 size = ARRAY_SIZE(user_name);
367 ret = GetUserNameW(user_name, &size);
368 ok(ret, "GetUserName() failed, error %u\n", GetLastError());
370 status = LsaLookupSids(policy, 1, &user->User.Sid, &list, &names);
371 ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
373 ok(list->Entries == 1, "got %d\n", list->Entries);
374 check_unicode_string(&list->Domains[0].Name, computer_name);
376 ok(names[0].Use == SidTypeUser, "got type %u\n", names[0].Use);
377 ok(!names[0].DomainIndex, "got index %u\n", names[0].DomainIndex);
378 check_unicode_string(&names[0].Name, user_name);
380 LsaFreeMemory(names);
381 LsaFreeMemory(list);
382 CloseHandle(token);
384 ret = ConvertStringSidToSidA("S-1-1-0", &sid);
385 ok(ret, "ConvertStringSidToSidA() failed, error %u\n", GetLastError());
387 status = LsaLookupSids(policy, 1, &sid, &list, &names);
388 ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
390 ok(list->Entries == 1, "got %d\n", list->Entries);
391 check_unicode_string(&list->Domains[0].Name, L"");
393 ok(names[0].Use == SidTypeWellKnownGroup, "got type %u\n", names[0].Use);
394 ok(!names[0].DomainIndex, "got index %u\n", names[0].DomainIndex);
396 /* The group name gets translated... but not in all locales */
397 size = ARRAY_SIZE(langW);
398 if (!pGetSystemPreferredUILanguages ||
399 !pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
400 langW[0] = 0;
401 if (wcscmp(langW, L"0409") == 0 || wcscmp(langW, L"0411") == 0)
402 /* English and Japanese */
403 check_unicode_string(&names[0].Name, L"Everyone");
404 else if (wcscmp(langW, L"0407") == 0) /* German */
405 check_unicode_string(&names[0].Name, L"Jeder");
406 else if (wcscmp(langW, L"040C") == 0) /* French */
407 check_unicode_string(&names[0].Name, L"Tout le monde");
408 else
409 trace("<Everyone-group>.Name=%s\n", debugstr_w(names[0].Name.Buffer));
411 LsaFreeMemory(names);
412 LsaFreeMemory(list);
413 FreeSid(sid);
415 ret = ConvertStringSidToSidA("S-1-1234-5678-1234-5678", &sid);
416 ok(ret, "ConvertStringSidToSidA() failed, error %u\n", GetLastError());
418 status = LsaLookupSids(policy, 1, &sid, &list, &names);
419 ok(status == STATUS_NONE_MAPPED, "got 0x%08x\n", status);
421 ok(!list->Entries, "got %d\n", list->Entries);
423 ok(names[0].Use == SidTypeUnknown, "got type %u\n", names[0].Use);
424 ok(names[0].DomainIndex == -1, "got index %u\n", names[0].DomainIndex);
425 check_unicode_string(&names[0].Name, L"S-1-1234-5678-1234-5678");
427 LsaFreeMemory(names);
428 LsaFreeMemory(list);
429 FreeSid(sid);
431 status = LsaClose(policy);
432 ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
435 static void test_LsaLookupPrivilegeName(void)
437 LSA_OBJECT_ATTRIBUTES attrs;
438 LSA_UNICODE_STRING *name;
439 LSA_HANDLE policy;
440 NTSTATUS status;
441 LUID luid;
443 memset(&attrs, 0, sizeof(attrs));
444 attrs.Length = sizeof(attrs);
446 status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
447 ok(status == STATUS_SUCCESS, "Failed to open policy, %#x.\n", status);
449 name = (void *)0xdeadbeef;
450 status = LsaLookupPrivilegeName(policy, NULL, &name);
451 ok(status != STATUS_SUCCESS, "Unexpected status %#x.\n", status);
452 ok(name == (void *)0xdeadbeef, "Unexpected name pointer.\n");
454 name = (void *)0xdeadbeef;
455 luid.HighPart = 1;
456 luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
457 status = LsaLookupPrivilegeName(policy, &luid, &name);
458 ok(status == STATUS_NO_SUCH_PRIVILEGE, "Unexpected status %#x.\n", status);
459 ok(name == NULL, "Unexpected name pointer.\n");
461 luid.HighPart = 0;
462 luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
463 status = LsaLookupPrivilegeName(policy, &luid, &name);
464 ok(status == 0, "got %#x.\n", status);
465 LsaFreeMemory(name);
468 static void test_LsaGetUserName(void)
470 NTSTATUS status;
471 BOOL ret;
472 UNICODE_STRING *lsa_user, *lsa_domain;
473 WCHAR user[256], computer[256];
474 DWORD size;
476 if (!pLsaGetUserName)
478 skip("LsaGetUserName is not available on this platform\n");
479 return;
482 size = ARRAY_SIZE(user);
483 ret = GetUserNameW(user, &size);
484 ok(ret, "GetUserName error %u\n", GetLastError());
486 size = ARRAY_SIZE(computer);
487 ret = GetComputerNameW(computer, &size);
488 ok(ret, "GetComputerName error %u\n", GetLastError());
490 if (0) /* crashes under Windows */
491 status = pLsaGetUserName(NULL, NULL);
493 if (0) /* crashes under Windows */
494 status = pLsaGetUserName(NULL, &lsa_domain);
496 status = pLsaGetUserName(&lsa_user, NULL);
497 ok(!status, "got %#x\n", status);
498 check_unicode_string(lsa_user, user);
499 LsaFreeMemory(lsa_user);
501 status = pLsaGetUserName(&lsa_user, &lsa_domain);
502 ok(!status, "got %#x\n", status);
503 ok(!lstrcmpW(user, lsa_user->Buffer), "%s != %s\n", wine_dbgstr_w(user), wine_dbgstr_wn(lsa_user->Buffer, lsa_user->Length/sizeof(WCHAR)));
504 check_unicode_string(lsa_user, user);
505 check_unicode_string(lsa_domain, computer);
506 LsaFreeMemory(lsa_user);
507 LsaFreeMemory(lsa_domain);
510 START_TEST(lsa)
512 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
513 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
515 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
516 pLsaGetUserName = (void *)GetProcAddress(hadvapi32, "LsaGetUserName");
518 test_lsa();
519 test_LsaLookupNames2();
520 test_LsaLookupSids();
521 test_LsaLookupPrivilegeName();
522 test_LsaGetUserName();