2006-04-21 16:06:38 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for lsa functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Robert Reif
|
2020-11-10 18:53:08 +01:00
|
|
|
* Copyright (c) 2020 Dmitry Timoshkov
|
2006-04-21 16:06:38 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-04-21 16:06:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "ntsecapi.h"
|
2006-08-17 21:26:40 +02:00
|
|
|
#include "sddl.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "objbase.h"
|
2008-07-08 16:17:17 +02:00
|
|
|
#include "initguid.h"
|
2006-04-21 16:06:38 +02:00
|
|
|
#include "wine/test.h"
|
2017-11-02 21:56:19 +01:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "ntlsa.h"
|
2006-04-21 16:06:38 +02:00
|
|
|
|
2008-07-08 16:17:17 +02:00
|
|
|
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
|
|
|
|
2020-03-22 18:59:32 +01:00
|
|
|
static BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, ULONG*, WCHAR*, ULONG*);
|
2020-11-10 18:53:08 +01:00
|
|
|
static NTSTATUS (WINAPI *pLsaGetUserName)(PUNICODE_STRING *user, PUNICODE_STRING *domain);
|
2020-03-22 18:59:32 +01:00
|
|
|
|
2006-04-21 16:06:38 +02:00
|
|
|
static void test_lsa(void)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
LSA_HANDLE handle;
|
|
|
|
LSA_OBJECT_ATTRIBUTES object_attributes;
|
|
|
|
|
|
|
|
ZeroMemory(&object_attributes, sizeof(object_attributes));
|
2006-08-14 13:17:55 +02:00
|
|
|
object_attributes.Length = sizeof(object_attributes);
|
2006-04-21 16:06:38 +02:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaOpenPolicy( NULL, &object_attributes, POLICY_ALL_ACCESS, &handle);
|
2006-08-14 13:17:55 +02:00
|
|
|
ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
|
2006-10-04 12:37:30 +02:00
|
|
|
"LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status);
|
2006-08-14 13:17:55 +02:00
|
|
|
|
|
|
|
/* try a more restricted access mask if necessary */
|
|
|
|
if (status == STATUS_ACCESS_DENIED) {
|
2009-06-16 13:00:35 +02:00
|
|
|
trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES\n");
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaOpenPolicy( NULL, &object_attributes, POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES, &handle);
|
2009-06-16 13:00:35 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES) returned 0x%08x\n", status);
|
2006-08-14 13:17:55 +02:00
|
|
|
}
|
2006-04-21 16:06:38 +02:00
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS) {
|
2006-08-01 13:35:54 +02:00
|
|
|
PPOLICY_AUDIT_EVENTS_INFO audit_events_info;
|
|
|
|
PPOLICY_PRIMARY_DOMAIN_INFO primary_domain_info;
|
|
|
|
PPOLICY_ACCOUNT_DOMAIN_INFO account_domain_info;
|
|
|
|
PPOLICY_DNS_DOMAIN_INFO dns_domain_info;
|
2009-06-16 13:00:35 +02:00
|
|
|
HANDLE token;
|
|
|
|
BOOL ret;
|
2006-08-01 13:35:54 +02:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaQueryInformationPolicy(handle, PolicyAuditEventsInformation, (void **)&audit_events_info);
|
2007-07-03 17:13:07 +02:00
|
|
|
if (status == STATUS_ACCESS_DENIED)
|
2007-07-05 16:10:30 +02:00
|
|
|
skip("Not enough rights to retrieve PolicyAuditEventsInformation\n");
|
2007-07-03 17:13:07 +02:00
|
|
|
else
|
|
|
|
ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08x\n", status);
|
2017-11-02 21:56:17 +01:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
LsaFreeMemory(audit_events_info);
|
2006-08-01 13:35:54 +02:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaQueryInformationPolicy(handle, PolicyPrimaryDomainInformation, (void **)&primary_domain_info);
|
2006-10-04 12:37:30 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyPrimaryDomainInformation) failed, returned 0x%08x\n", status);
|
2006-08-01 13:35:54 +02:00
|
|
|
if (status == STATUS_SUCCESS) {
|
2006-08-17 21:26:40 +02:00
|
|
|
if (primary_domain_info->Sid) {
|
|
|
|
LPSTR strsid;
|
2017-11-02 21:56:17 +01:00
|
|
|
if (ConvertSidToStringSidA(primary_domain_info->Sid, &strsid))
|
2006-08-17 21:26:40 +02:00
|
|
|
{
|
|
|
|
if (primary_domain_info->Name.Buffer) {
|
|
|
|
LPSTR name = NULL;
|
|
|
|
UINT len;
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
|
|
|
|
name = LocalAlloc( 0, len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, primary_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
|
|
|
|
trace(" name: %s sid: %s\n", name, strsid);
|
|
|
|
LocalFree( name );
|
|
|
|
} else
|
|
|
|
trace(" name: NULL sid: %s\n", strsid);
|
|
|
|
LocalFree( strsid );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trace("invalid sid\n");
|
|
|
|
}
|
2008-06-24 15:32:34 +02:00
|
|
|
else
|
|
|
|
trace("Running on a standalone system.\n");
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(primary_domain_info);
|
2006-08-01 13:35:54 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaQueryInformationPolicy(handle, PolicyAccountDomainInformation, (void **)&account_domain_info);
|
2006-10-04 12:37:30 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAccountDomainInformation) failed, returned 0x%08x\n", status);
|
2017-11-02 21:56:17 +01:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
LsaFreeMemory(account_domain_info);
|
2006-08-01 13:35:54 +02:00
|
|
|
|
2006-08-16 01:05:18 +02:00
|
|
|
/* This isn't supported in NT4 */
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaQueryInformationPolicy(handle, PolicyDnsDomainInformation, (void **)&dns_domain_info);
|
2006-08-16 01:05:18 +02:00
|
|
|
ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER,
|
2006-10-04 12:37:30 +02:00
|
|
|
"LsaQueryInformationPolicy(PolicyDnsDomainInformation) failed, returned 0x%08x\n", status);
|
2006-08-01 13:35:54 +02:00
|
|
|
if (status == STATUS_SUCCESS) {
|
2006-08-17 21:26:40 +02:00
|
|
|
if (dns_domain_info->Sid || !IsEqualGUID(&dns_domain_info->DomainGuid, &GUID_NULL)) {
|
|
|
|
LPSTR strsid = NULL;
|
|
|
|
LPSTR name = NULL;
|
|
|
|
LPSTR domain = NULL;
|
|
|
|
LPSTR forest = NULL;
|
|
|
|
LPSTR guidstr = NULL;
|
|
|
|
WCHAR guidstrW[64];
|
|
|
|
UINT len;
|
2006-08-26 01:24:23 +02:00
|
|
|
guidstrW[0] = '\0';
|
2017-11-02 21:56:17 +01:00
|
|
|
ConvertSidToStringSidA(dns_domain_info->Sid, &strsid);
|
2018-05-29 01:05:20 +02:00
|
|
|
StringFromGUID2(&dns_domain_info->DomainGuid, guidstrW, ARRAY_SIZE(guidstrW));
|
2006-08-17 21:26:40 +02:00
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, NULL, 0, NULL, NULL );
|
|
|
|
guidstr = LocalAlloc( 0, len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, guidstrW, -1, guidstr, len, NULL, NULL );
|
|
|
|
if (dns_domain_info->Name.Buffer) {
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, NULL, 0, NULL, NULL );
|
|
|
|
name = LocalAlloc( 0, len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, dns_domain_info->Name.Buffer, -1, name, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
if (dns_domain_info->DnsDomainName.Buffer) {
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, NULL, 0, NULL, NULL );
|
|
|
|
domain = LocalAlloc( 0, len );
|
2006-08-26 01:24:23 +02:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsDomainName.Buffer, -1, domain, len, NULL, NULL );
|
2006-08-17 21:26:40 +02:00
|
|
|
}
|
|
|
|
if (dns_domain_info->DnsForestName.Buffer) {
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, NULL, 0, NULL, NULL );
|
|
|
|
forest = LocalAlloc( 0, len );
|
2006-08-26 01:24:23 +02:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, dns_domain_info->DnsForestName.Buffer, -1, forest, len, NULL, NULL );
|
2006-08-17 21:26:40 +02:00
|
|
|
}
|
|
|
|
trace(" name: %s domain: %s forest: %s guid: %s sid: %s\n",
|
|
|
|
name ? name : "NULL", domain ? domain : "NULL",
|
|
|
|
forest ? forest : "NULL", guidstr, strsid ? strsid : "NULL");
|
|
|
|
LocalFree( name );
|
|
|
|
LocalFree( forest );
|
|
|
|
LocalFree( domain );
|
|
|
|
LocalFree( guidstr );
|
|
|
|
LocalFree( strsid );
|
|
|
|
}
|
2008-06-24 15:32:34 +02:00
|
|
|
else
|
|
|
|
trace("Running on a standalone system.\n");
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(dns_domain_info);
|
2006-08-01 13:35:54 +02:00
|
|
|
}
|
2006-04-21 16:06:38 +02:00
|
|
|
|
2009-06-16 13:00:35 +02:00
|
|
|
/* We need a valid SID to pass to LsaEnumerateAccountRights */
|
|
|
|
ret = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token );
|
|
|
|
ok(ret, "Unable to obtain process token, error %u\n", GetLastError( ));
|
|
|
|
if (ret) {
|
|
|
|
char buffer[64];
|
|
|
|
DWORD len;
|
|
|
|
TOKEN_USER *token_user = (TOKEN_USER *) buffer;
|
|
|
|
ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, sizeof(buffer), &len );
|
|
|
|
ok(ret || GetLastError( ) == ERROR_INSUFFICIENT_BUFFER, "Unable to obtain token information, error %u\n", GetLastError( ));
|
|
|
|
if (! ret && GetLastError( ) == ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
trace("Resizing buffer to %u.\n", len);
|
|
|
|
token_user = LocalAlloc( 0, len );
|
|
|
|
if (token_user != NULL)
|
|
|
|
ret = GetTokenInformation( token, TokenUser, (LPVOID) token_user, len, &len );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
PLSA_UNICODE_STRING rights;
|
|
|
|
ULONG rights_count;
|
|
|
|
rights = (PLSA_UNICODE_STRING) 0xdeadbeaf;
|
|
|
|
rights_count = 0xcafecafe;
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaEnumerateAccountRights(handle, token_user->User.Sid, &rights, &rights_count);
|
2009-06-16 13:00:35 +02:00
|
|
|
ok(status == STATUS_SUCCESS || status == STATUS_OBJECT_NAME_NOT_FOUND, "Unexpected status 0x%x\n", status);
|
|
|
|
if (status == STATUS_SUCCESS)
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory( rights );
|
2009-06-16 13:00:35 +02:00
|
|
|
else
|
|
|
|
ok(rights == NULL && rights_count == 0, "Expected rights and rights_count to be set to 0 on failure\n");
|
|
|
|
}
|
|
|
|
if (token_user != NULL && token_user != (TOKEN_USER *) buffer)
|
|
|
|
LocalFree( token_user );
|
|
|
|
CloseHandle( token );
|
|
|
|
}
|
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaClose(handle);
|
2006-10-04 12:37:30 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status);
|
2006-04-21 16:06:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-07 08:36:51 +02:00
|
|
|
static void get_sid_info(PSID psid, LPSTR *user, LPSTR *dom)
|
|
|
|
{
|
|
|
|
static char account[257], domain[257];
|
|
|
|
DWORD user_size, dom_size;
|
|
|
|
SID_NAME_USE use;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
*user = account;
|
|
|
|
*dom = domain;
|
|
|
|
|
|
|
|
user_size = dom_size = 257;
|
|
|
|
account[0] = domain[0] = 0;
|
|
|
|
ret = LookupAccountSidA(NULL, psid, account, &user_size, domain, &dom_size, &use);
|
|
|
|
ok(ret, "LookupAccountSidA failed %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_LsaLookupNames2(void)
|
|
|
|
{
|
|
|
|
static const WCHAR n1[] = {'L','O','C','A','L',' ','S','E','R','V','I','C','E'};
|
|
|
|
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'};
|
|
|
|
|
|
|
|
NTSTATUS status;
|
|
|
|
LSA_HANDLE handle;
|
|
|
|
LSA_OBJECT_ATTRIBUTES attrs;
|
|
|
|
PLSA_REFERENCED_DOMAIN_LIST domains;
|
|
|
|
PLSA_TRANSLATED_SID2 sids;
|
|
|
|
LSA_UNICODE_STRING name[3];
|
|
|
|
LPSTR account, sid_dom;
|
|
|
|
|
2013-02-10 23:19:47 +01:00
|
|
|
if ((PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())) != LANG_ENGLISH) ||
|
|
|
|
(PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH))
|
2009-08-07 08:36:51 +02:00
|
|
|
{
|
2011-08-03 23:50:18 +02:00
|
|
|
skip("Non-English locale (skipping LsaLookupNames2 tests)\n");
|
2009-08-07 08:36:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&attrs, 0, sizeof(attrs));
|
|
|
|
attrs.Length = sizeof(attrs);
|
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaOpenPolicy(NULL, &attrs, POLICY_ALL_ACCESS, &handle);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED,
|
|
|
|
"LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08x\n", status);
|
|
|
|
|
|
|
|
/* try a more restricted access mask if necessary */
|
|
|
|
if (status == STATUS_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &handle);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08x\n", status);
|
|
|
|
}
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
skip("Cannot acquire policy handle\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name[0].Buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(n1));
|
|
|
|
name[0].Length = name[0].MaximumLength = sizeof(n1);
|
|
|
|
memcpy(name[0].Buffer, n1, sizeof(n1));
|
|
|
|
|
|
|
|
name[1].Buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(n1));
|
|
|
|
name[1].Length = name[1].MaximumLength = sizeof(n1) - sizeof(WCHAR);
|
|
|
|
memcpy(name[1].Buffer, n1, sizeof(n1) - sizeof(WCHAR));
|
|
|
|
|
|
|
|
name[2].Buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(n2));
|
|
|
|
name[2].Length = name[2].MaximumLength = sizeof(n2);
|
|
|
|
memcpy(name[2].Buffer, n2, sizeof(n2));
|
|
|
|
|
|
|
|
/* account name only */
|
|
|
|
sids = NULL;
|
|
|
|
domains = NULL;
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaLookupNames2(handle, 0, 1, &name[0], &domains, &sids);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %x)\n", status);
|
|
|
|
ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
|
|
|
|
ok(sids[0].Flags == 0, "expected 0, got 0x%08x\n", sids[0].Flags);
|
2009-09-30 19:56:23 +02:00
|
|
|
ok(domains->Entries == 1, "expected 1, got %u\n", domains->Entries);
|
2009-08-07 08:36:51 +02:00
|
|
|
get_sid_info(sids[0].Sid, &account, &sid_dom);
|
|
|
|
ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
|
|
|
|
ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(sids);
|
|
|
|
LsaFreeMemory(domains);
|
2009-08-07 08:36:51 +02:00
|
|
|
|
|
|
|
/* unknown account name */
|
|
|
|
sids = NULL;
|
|
|
|
domains = NULL;
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaLookupNames2(handle, 0, 1, &name[1], &domains, &sids);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_NONE_MAPPED, "expected STATUS_NONE_MAPPED, got %x)\n", status);
|
|
|
|
ok(sids[0].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[0].Use);
|
|
|
|
ok(sids[0].Flags == 0, "expected 0, got 0x%08x\n", sids[0].Flags);
|
|
|
|
ok(domains->Entries == 0, "expected 0, got %u\n", domains->Entries);
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(sids);
|
|
|
|
LsaFreeMemory(domains);
|
2009-08-07 08:36:51 +02:00
|
|
|
|
|
|
|
/* account + domain */
|
|
|
|
sids = NULL;
|
|
|
|
domains = NULL;
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaLookupNames2(handle, 0, 1, &name[2], &domains, &sids);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %x)\n", status);
|
|
|
|
ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
|
|
|
|
ok(sids[0].Flags == 0, "expected 0, got 0x%08x\n", sids[0].Flags);
|
2009-09-30 19:56:23 +02:00
|
|
|
ok(domains->Entries == 1, "expected 1, got %u\n", domains->Entries);
|
2009-08-07 08:36:51 +02:00
|
|
|
get_sid_info(sids[0].Sid, &account, &sid_dom);
|
|
|
|
ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
|
|
|
|
ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(sids);
|
|
|
|
LsaFreeMemory(domains);
|
2009-08-07 08:36:51 +02:00
|
|
|
|
|
|
|
/* all three */
|
|
|
|
sids = NULL;
|
|
|
|
domains = NULL;
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaLookupNames2(handle, 0, 3, name, &domains, &sids);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_SOME_NOT_MAPPED, "expected STATUS_SOME_NOT_MAPPED, got %x)\n", status);
|
|
|
|
ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
|
2014-09-16 21:02:48 +02:00
|
|
|
ok(sids[1].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[1].Use);
|
|
|
|
ok(sids[2].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[2].Use);
|
2009-09-30 19:56:23 +02:00
|
|
|
ok(sids[0].DomainIndex == 0, "expected 0, got %u\n", sids[0].DomainIndex);
|
|
|
|
ok(domains->Entries == 1, "expected 1, got %u\n", domains->Entries);
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(sids);
|
|
|
|
LsaFreeMemory(domains);
|
2009-08-07 08:36:51 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, name[0].Buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name[1].Buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name[2].Buffer);
|
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaClose(handle);
|
2009-08-07 08:36:51 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08x\n", status);
|
|
|
|
}
|
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
static void check_unicode_string_(int line, const LSA_UNICODE_STRING *string, const WCHAR *expect)
|
|
|
|
{
|
|
|
|
ok_(__FILE__, line)(string->Length == wcslen(string->Buffer) * sizeof(WCHAR),
|
|
|
|
"expected %u, got %u\n", wcslen(string->Buffer) * sizeof(WCHAR), string->Length);
|
|
|
|
ok_(__FILE__, line)(string->MaximumLength == string->Length + sizeof(WCHAR),
|
|
|
|
"expected %u, got %u\n", string->Length + sizeof(WCHAR), string->MaximumLength);
|
|
|
|
ok_(__FILE__, line)(!wcsicmp(string->Buffer, expect), "expected %s, got %s\n",
|
|
|
|
debugstr_w(expect), debugstr_w(string->Buffer));
|
|
|
|
}
|
|
|
|
#define check_unicode_string(a, b) check_unicode_string_(__LINE__, a, b)
|
|
|
|
|
2013-01-19 20:26:05 +01:00
|
|
|
static void test_LsaLookupSids(void)
|
|
|
|
{
|
2020-03-22 18:59:32 +01:00
|
|
|
WCHAR langW[32];
|
2020-02-01 19:10:16 +01:00
|
|
|
char user_buffer[64];
|
2020-11-10 18:53:05 +01:00
|
|
|
LSA_OBJECT_ATTRIBUTES attrs = {sizeof(attrs)};
|
2020-02-01 19:10:16 +01:00
|
|
|
TOKEN_USER *user = (TOKEN_USER *)user_buffer;
|
|
|
|
WCHAR computer_name[64], user_name[64];
|
2013-01-19 20:26:05 +01:00
|
|
|
LSA_REFERENCED_DOMAIN_LIST *list;
|
|
|
|
LSA_TRANSLATED_NAME *names;
|
|
|
|
LSA_HANDLE policy;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE token;
|
2020-03-22 18:59:32 +01:00
|
|
|
DWORD num, size;
|
2013-01-19 20:26:05 +01:00
|
|
|
BOOL ret;
|
2017-11-02 21:56:18 +01:00
|
|
|
PSID sid;
|
2013-01-19 20:26:05 +01:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
|
2013-01-19 20:26:05 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
|
|
|
|
|
|
|
|
ret = OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &token);
|
2020-02-01 19:10:16 +01:00
|
|
|
ok(ret, "OpenProcessToken() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = GetTokenInformation(token, TokenUser, user, sizeof(user_buffer), &size);
|
|
|
|
ok(ret, "GetTokenInformation() failed, error %u\n", GetLastError());
|
2013-01-19 20:26:05 +01:00
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
size = ARRAY_SIZE(computer_name);
|
|
|
|
ret = GetComputerNameW(computer_name, &size);
|
|
|
|
ok(ret, "GetComputerName() failed, error %u\n", GetLastError());
|
2013-01-19 20:26:05 +01:00
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
size = ARRAY_SIZE(user_name);
|
|
|
|
ret = GetUserNameW(user_name, &size);
|
|
|
|
ok(ret, "GetUserName() failed, error %u\n", GetLastError());
|
2013-01-19 20:26:05 +01:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaLookupSids(policy, 1, &user->User.Sid, &list, &names);
|
2013-01-19 20:26:05 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
|
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
ok(list->Entries == 1, "got %d\n", list->Entries);
|
|
|
|
check_unicode_string(&list->Domains[0].Name, computer_name);
|
|
|
|
|
|
|
|
ok(names[0].Use == SidTypeUser, "got type %u\n", names[0].Use);
|
|
|
|
ok(!names[0].DomainIndex, "got index %u\n", names[0].DomainIndex);
|
|
|
|
check_unicode_string(&names[0].Name, user_name);
|
2013-01-19 20:26:05 +01:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(names);
|
|
|
|
LsaFreeMemory(list);
|
2013-01-19 20:26:05 +01:00
|
|
|
CloseHandle(token);
|
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
ret = ConvertStringSidToSidA("S-1-1-0", &sid);
|
2020-02-01 19:10:16 +01:00
|
|
|
ok(ret, "ConvertStringSidToSidA() failed, error %u\n", GetLastError());
|
2017-02-02 11:30:55 +01:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaLookupSids(policy, 1, &sid, &list, &names);
|
2017-02-02 11:30:55 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
|
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
ok(list->Entries == 1, "got %d\n", list->Entries);
|
|
|
|
check_unicode_string(&list->Domains[0].Name, L"");
|
2017-02-02 11:30:55 +01:00
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
ok(names[0].Use == SidTypeWellKnownGroup, "got type %u\n", names[0].Use);
|
|
|
|
ok(!names[0].DomainIndex, "got index %u\n", names[0].DomainIndex);
|
2020-03-22 18:59:32 +01:00
|
|
|
|
|
|
|
/* The group name gets translated... but not in all locales */
|
|
|
|
size = ARRAY_SIZE(langW);
|
|
|
|
if (!pGetSystemPreferredUILanguages ||
|
|
|
|
!pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
|
|
|
|
langW[0] = 0;
|
|
|
|
if (wcscmp(langW, L"0409") == 0 || wcscmp(langW, L"0411") == 0)
|
|
|
|
/* English and Japanese */
|
|
|
|
check_unicode_string(&names[0].Name, L"Everyone");
|
|
|
|
else if (wcscmp(langW, L"0407") == 0) /* German */
|
|
|
|
check_unicode_string(&names[0].Name, L"Jeder");
|
|
|
|
else if (wcscmp(langW, L"040C") == 0) /* French */
|
|
|
|
check_unicode_string(&names[0].Name, L"Tout le monde");
|
|
|
|
else
|
|
|
|
trace("<Everyone-group>.Name=%s\n", debugstr_w(names[0].Name.Buffer));
|
2017-02-02 11:30:55 +01:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
LsaFreeMemory(names);
|
|
|
|
LsaFreeMemory(list);
|
2020-02-01 19:10:16 +01:00
|
|
|
FreeSid(sid);
|
|
|
|
|
|
|
|
ret = ConvertStringSidToSidA("S-1-1234-5678-1234-5678", &sid);
|
|
|
|
ok(ret, "ConvertStringSidToSidA() failed, error %u\n", GetLastError());
|
2017-02-02 11:30:55 +01:00
|
|
|
|
2020-02-01 19:10:16 +01:00
|
|
|
status = LsaLookupSids(policy, 1, &sid, &list, &names);
|
|
|
|
ok(status == STATUS_NONE_MAPPED, "got 0x%08x\n", status);
|
|
|
|
|
|
|
|
ok(!list->Entries, "got %d\n", list->Entries);
|
|
|
|
|
|
|
|
ok(names[0].Use == SidTypeUnknown, "got type %u\n", names[0].Use);
|
|
|
|
ok(names[0].DomainIndex == -1, "got index %u\n", names[0].DomainIndex);
|
2020-02-01 19:10:17 +01:00
|
|
|
check_unicode_string(&names[0].Name, L"S-1-1234-5678-1234-5678");
|
2020-02-01 19:10:16 +01:00
|
|
|
|
|
|
|
LsaFreeMemory(names);
|
|
|
|
LsaFreeMemory(list);
|
2017-11-02 21:56:17 +01:00
|
|
|
FreeSid(sid);
|
2017-02-02 11:30:55 +01:00
|
|
|
|
2017-11-02 21:56:17 +01:00
|
|
|
status = LsaClose(policy);
|
2017-02-02 11:30:55 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
|
|
|
|
}
|
|
|
|
|
2017-11-02 21:56:19 +01:00
|
|
|
static void test_LsaLookupPrivilegeName(void)
|
|
|
|
{
|
|
|
|
LSA_OBJECT_ATTRIBUTES attrs;
|
|
|
|
LSA_UNICODE_STRING *name;
|
|
|
|
LSA_HANDLE policy;
|
|
|
|
NTSTATUS status;
|
|
|
|
LUID luid;
|
|
|
|
|
|
|
|
memset(&attrs, 0, sizeof(attrs));
|
|
|
|
attrs.Length = sizeof(attrs);
|
|
|
|
|
|
|
|
status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
|
|
|
|
ok(status == STATUS_SUCCESS, "Failed to open policy, %#x.\n", status);
|
|
|
|
|
|
|
|
name = (void *)0xdeadbeef;
|
|
|
|
status = LsaLookupPrivilegeName(policy, NULL, &name);
|
|
|
|
ok(status != STATUS_SUCCESS, "Unexpected status %#x.\n", status);
|
|
|
|
ok(name == (void *)0xdeadbeef, "Unexpected name pointer.\n");
|
|
|
|
|
|
|
|
name = (void *)0xdeadbeef;
|
|
|
|
luid.HighPart = 1;
|
|
|
|
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
|
|
|
|
status = LsaLookupPrivilegeName(policy, &luid, &name);
|
|
|
|
ok(status == STATUS_NO_SUCH_PRIVILEGE, "Unexpected status %#x.\n", status);
|
|
|
|
ok(name == NULL, "Unexpected name pointer.\n");
|
|
|
|
|
|
|
|
luid.HighPart = 0;
|
|
|
|
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
|
|
|
|
status = LsaLookupPrivilegeName(policy, &luid, &name);
|
|
|
|
ok(status == 0, "got %#x.\n", status);
|
|
|
|
LsaFreeMemory(name);
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:53:08 +01:00
|
|
|
static void test_LsaGetUserName(void)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
BOOL ret;
|
|
|
|
UNICODE_STRING *lsa_user, *lsa_domain;
|
|
|
|
WCHAR user[256], computer[256];
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!pLsaGetUserName)
|
|
|
|
{
|
|
|
|
skip("LsaGetUserName is not available on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = ARRAY_SIZE(user);
|
|
|
|
ret = GetUserNameW(user, &size);
|
|
|
|
ok(ret, "GetUserName error %u\n", GetLastError());
|
|
|
|
|
|
|
|
size = ARRAY_SIZE(computer);
|
|
|
|
ret = GetComputerNameW(computer, &size);
|
|
|
|
ok(ret, "GetComputerName error %u\n", GetLastError());
|
|
|
|
|
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
status = pLsaGetUserName(NULL, NULL);
|
|
|
|
|
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
status = pLsaGetUserName(NULL, &lsa_domain);
|
|
|
|
|
|
|
|
status = pLsaGetUserName(&lsa_user, NULL);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
check_unicode_string(lsa_user, user);
|
|
|
|
LsaFreeMemory(lsa_user);
|
|
|
|
|
|
|
|
status = pLsaGetUserName(&lsa_user, &lsa_domain);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(!lstrcmpW(user, lsa_user->Buffer), "%s != %s\n", wine_dbgstr_w(user), wine_dbgstr_wn(lsa_user->Buffer, lsa_user->Length/sizeof(WCHAR)));
|
|
|
|
check_unicode_string(lsa_user, user);
|
|
|
|
check_unicode_string(lsa_domain, computer);
|
|
|
|
LsaFreeMemory(lsa_user);
|
|
|
|
LsaFreeMemory(lsa_domain);
|
|
|
|
}
|
|
|
|
|
2006-04-21 16:06:38 +02:00
|
|
|
START_TEST(lsa)
|
|
|
|
{
|
2020-11-10 18:53:08 +01:00
|
|
|
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
|
|
|
|
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
|
|
|
|
|
2020-03-22 18:59:32 +01:00
|
|
|
pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
|
2020-11-10 18:53:08 +01:00
|
|
|
pLsaGetUserName = (void *)GetProcAddress(hadvapi32, "LsaGetUserName");
|
2020-03-22 18:59:32 +01:00
|
|
|
|
2006-04-21 16:06:38 +02:00
|
|
|
test_lsa();
|
2009-08-07 08:36:51 +02:00
|
|
|
test_LsaLookupNames2();
|
2013-01-19 20:26:05 +01:00
|
|
|
test_LsaLookupSids();
|
2017-11-02 21:56:19 +01:00
|
|
|
test_LsaLookupPrivilegeName();
|
2020-11-10 18:53:08 +01:00
|
|
|
test_LsaGetUserName();
|
2006-04-21 16:06:38 +02:00
|
|
|
}
|