ReactOS 0.4.16-dev-2332-g4cba65d
lsa.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "ntsecapi.h"
#include "sddl.h"
#include "winnls.h"
#include "objbase.h"
#include "initguid.h"
#include "wine/test.h"
#include "winternl.h"
#include "ntlsa.h"
Include dependency graph for lsa.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define check_unicode_string(a, b)   check_unicode_string_(__LINE__, a, b)
 

Functions

 DEFINE_GUID (GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 
static BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD
 
static ULONG WCHAR ULONG *static NTSTATUS (WINAPI *pLsaGetUserName)(PUNICODE_STRING *user
 
static void test_lsa (void)
 
static void get_sid_info (PSID psid, LPSTR *user, LPSTR *dom)
 
static void test_LsaLookupNames2 (void)
 
static void check_unicode_string_ (int line, const LSA_UNICODE_STRING *string, const WCHAR *expect)
 
static void test_LsaLookupSids (void)
 
static void test_LsaLookupPrivilegeName (void)
 
static void test_LsaGetUserName (void)
 
 START_TEST (lsa)
 

Variables

static ULONG WCHAR ULONG *static PUNICODE_STRINGdomain
 

Macro Definition Documentation

◆ check_unicode_string

#define check_unicode_string (   a,
  b 
)    check_unicode_string_(__LINE__, a, b)

Definition at line 327 of file lsa.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 26 of file lsa.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pGetSystemPreferredUILanguages)
static

◆ check_unicode_string_()

static void check_unicode_string_ ( int  line,
const LSA_UNICODE_STRING string,
const WCHAR expect 
)
static

Definition at line 318 of file lsa.c.

319{
320 ok_(__FILE__, line)(string->Length == wcslen(string->Buffer) * sizeof(WCHAR),
321 "expected %Iu, got %u\n", wcslen(string->Buffer) * sizeof(WCHAR), string->Length);
322 ok_(__FILE__, line)(string->MaximumLength == string->Length + sizeof(WCHAR),
323 "expected %Iu, got %u\n", string->Length + sizeof(WCHAR), string->MaximumLength);
324 ok_(__FILE__, line)(!wcsicmp(string->Buffer, expect), "expected %s, got %s\n",
326}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define ok_(x1, x2)
Definition: atltest.h:61
#define wcsicmp
Definition: compat.h:15
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define debugstr_w
Definition: kernel32.h:32
Definition: parser.c:49
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ DEFINE_GUID()

DEFINE_GUID ( GUID_NULL  ,
,
,
,
,
,
,
,
,
,
,
 
)

◆ get_sid_info()

static void get_sid_info ( PSID  psid,
LPSTR user,
LPSTR dom 
)
static

Definition at line 190 of file lsa.c.

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}
#define ok(value,...)
Definition: atltest.h:57
void account(int argc, const char *argv[])
Definition: cmds.c:1690
void user(int argc, const char *argv[])
Definition: cmds.c:1350
#define NULL
Definition: types.h:112
BOOL WINAPI LookupAccountSidA(LPCSTR lpSystemName, PSID lpSid, LPSTR lpName, LPDWORD cchName, LPSTR lpReferencedDomainName, LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse)
Definition: misc.c:405
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
enum _SID_NAME_USE SID_NAME_USE
static ULONG WCHAR ULONG *static PUNICODE_STRING * domain
Definition: lsa.c:42
Definition: cookie.c:42
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by test_LsaLookupNames2().

◆ NTSTATUS()

static ULONG WCHAR ULONG *static NTSTATUS ( WINAPI pLsaGetUserName)
static

◆ START_TEST()

START_TEST ( lsa  )

Definition at line 518 of file lsa.c.

519{
520 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
521 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
522
523 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
524 pLsaGetUserName = (void *)GetProcAddress(hadvapi32, "LsaGetUserName");
525
526 test_lsa();
531}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static void test_LsaLookupSids(void)
Definition: lsa.c:329
static void test_LsaLookupPrivilegeName(void)
Definition: lsa.c:437
static void test_LsaGetUserName(void)
Definition: lsa.c:470
static void test_lsa(void)
Definition: lsa.c:44
static void test_LsaLookupNames2(void)
Definition: lsa.c:206
static HINSTANCE hkernel32
Definition: process.c:68

◆ test_lsa()

static void test_lsa ( void  )
static

Definition at line 44 of file lsa.c.

45{
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);
55 "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08lx\n", status);
56
57 /* try a more restricted access mask if necessary */
59 trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION|POLICY_LOOKUP_NAMES\n");
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;
70 BOOL ret;
71
74 skip("Not enough rights to retrieve PolicyAuditEventsInformation\n");
75 else
76 ok(status == STATUS_SUCCESS, "LsaQueryInformationPolicy(PolicyAuditEventsInformation) failed, returned 0x%08lx\n", status);
78 LsaFreeMemory(audit_events_info);
79
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
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 */
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",
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 */
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( ));
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 );
183 }
184
186 ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08lx\n", status);
187 }
188}
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1183
NTSTATUS WINAPI LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, OUT PVOID *Buffer)
Definition: lsa.c:1473
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:701
NTSTATUS WINAPI LsaEnumerateAccountRights(IN LSA_HANDLE PolicyHandle, IN PSID AccountSid, OUT PLSA_UNICODE_STRING *UserRights, OUT PULONG CountOfRights)
Definition: lsa.c:406
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:194
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
BOOL WINAPI ConvertSidToStringSidA(PSID Sid, LPSTR *StringSid)
Definition: security.c:3637
#define CloseHandle
Definition: compat.h:739
#define CP_ACP
Definition: compat.h:109
#define GetCurrentProcess()
Definition: compat.h:759
#define WideCharToMultiByte
Definition: compat.h:111
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_a
Definition: kernel32.h:31
#define GUID_NULL
Definition: ks.h:106
#define ZeroMemory
Definition: minwinbase.h:31
unsigned int UINT
Definition: ndis.h:50
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
@ PolicyAuditEventsInformation
Definition: ntsecapi.h:244
@ PolicyDnsDomainInformation
Definition: ntsecapi.h:254
@ PolicyPrimaryDomainInformation
Definition: ntsecapi.h:245
@ PolicyAccountDomainInformation
Definition: ntsecapi.h:247
struct _LSA_UNICODE_STRING * PLSA_UNICODE_STRING
#define POLICY_VIEW_LOCAL_INFORMATION
Definition: ntsecapi.h:61
#define POLICY_ALL_ACCESS
Definition: ntsecapi.h:77
#define POLICY_LOOKUP_NAMES
Definition: ntsecapi.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65
LSA_UNICODE_STRING Name
Definition: ntsecapi.h:574
LSA_UNICODE_STRING DnsDomainName
Definition: ntsecapi.h:575
LSA_UNICODE_STRING DnsForestName
Definition: ntsecapi.h:576
LSA_UNICODE_STRING Name
Definition: ntsecapi.h:570
Definition: name.c:39
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define TOKEN_QUERY
Definition: setypes.h:940
@ TokenUser
Definition: setypes.h:978
char * LPSTR
Definition: xmlstorage.h:182

Referenced by START_TEST().

◆ test_LsaGetUserName()

static void test_LsaGetUserName ( void  )
static

Definition at line 470 of file lsa.c.

471{
473 BOOL ret;
474 UNICODE_STRING *lsa_user, *lsa_domain;
475 WCHAR user[256], computer[256];
476 DWORD size;
477
478 if (!pLsaGetUserName)
479 {
480 skip("LsaGetUserName is not available on this platform\n");
481 return;
482 }
483
486 ok(ret, "GetUserName error %lu\n", GetLastError());
487
488 size = ARRAY_SIZE(computer);
489 ret = GetComputerNameW(computer, &size);
490 ok(ret, "GetComputerName error %lu\n", GetLastError());
491
492 if (0) /* crashes under Windows */
493 status = pLsaGetUserName(NULL, NULL);
494
495 if (0) /* crashes under Windows */
496 status = pLsaGetUserName(NULL, &lsa_domain);
497
498 status = pLsaGetUserName(&lsa_user, NULL);
499 ok(!status, "got %#lx\n", status);
500#ifdef __REACTOS__
502 skip("FIXME: LsaGetUserName not implemented on ReactOS!\n");
503 return;
504 }
505#endif
506 check_unicode_string(lsa_user, user);
507 LsaFreeMemory(lsa_user);
508
509 status = pLsaGetUserName(&lsa_user, &lsa_domain);
510 ok(!status, "got %#lx\n", status);
511 ok(!lstrcmpW(user, lsa_user->Buffer), "%s != %s\n", wine_dbgstr_w(user), wine_dbgstr_wn(lsa_user->Buffer, lsa_user->Length/sizeof(WCHAR)));
512 check_unicode_string(lsa_user, user);
513 check_unicode_string(lsa_domain, computer);
514 LsaFreeMemory(lsa_user);
515 LsaFreeMemory(lsa_domain);
516}
#define ARRAY_SIZE(A)
Definition: main.h:20
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
GLsizeiptr size
Definition: glext.h:5919
#define wine_dbgstr_w
Definition: kernel32.h:34
#define check_unicode_string(a, b)
Definition: lsa.c:327
#define wine_dbgstr_wn
Definition: testlist.c:2

Referenced by START_TEST().

◆ test_LsaLookupNames2()

static void test_LsaLookupNames2 ( void  )
static

Definition at line 206 of file lsa.c.

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
217 LPSTR account, sid_dom;
218
221 {
222 skip("Non-English locale (skipping LsaLookupNames2 tests)\n");
223 return;
224 }
225
226 memset(&attrs, 0, sizeof(attrs));
227 attrs.Length = sizeof(attrs);
228
231 "LsaOpenPolicy(POLICY_ALL_ACCESS) returned 0x%08lx\n", status);
232
233 /* try a more restricted access mask if necessary */
235 {
236 trace("LsaOpenPolicy(POLICY_ALL_ACCESS) failed, trying POLICY_VIEW_LOCAL_INFORMATION\n");
238 ok(status == STATUS_SUCCESS, "LsaOpenPolicy(POLICY_VIEW_LOCAL_INFORMATION) returned 0x%08lx\n", status);
239 }
240 if (status != STATUS_SUCCESS)
241 {
242 skip("Cannot acquire policy handle\n");
243 return;
244 }
245
246 name[0].Buffer = malloc(sizeof(n1));
247 name[0].Length = name[0].MaximumLength = sizeof(n1);
248 memcpy(name[0].Buffer, n1, sizeof(n1));
249
250 name[1].Buffer = malloc(sizeof(n1));
251 name[1].Length = name[1].MaximumLength = sizeof(n1) - sizeof(WCHAR);
252 memcpy(name[1].Buffer, n1, sizeof(n1) - sizeof(WCHAR));
253
254 name[2].Buffer = malloc(sizeof(n2));
255 name[2].Length = name[2].MaximumLength = sizeof(n2);
256 memcpy(name[2].Buffer, n2, sizeof(n2));
257
258 /* account name only */
259 sids = NULL;
260 domains = NULL;
261 status = LsaLookupNames2(handle, 0, 1, &name[0], &domains, &sids);
262 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %lx)\n", status);
263 ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
264 ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
265 ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
266 get_sid_info(sids[0].Sid, &account, &sid_dom);
267 ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
268 ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
269 LsaFreeMemory(sids);
270 LsaFreeMemory(domains);
271
272 /* unknown account name */
273 sids = NULL;
274 domains = NULL;
275 status = LsaLookupNames2(handle, 0, 1, &name[1], &domains, &sids);
276 ok(status == STATUS_NONE_MAPPED, "expected STATUS_NONE_MAPPED, got %lx)\n", status);
277 ok(sids[0].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[0].Use);
278 ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
279 ok(domains->Entries == 0, "expected 0, got %lu\n", domains->Entries);
280 LsaFreeMemory(sids);
281 LsaFreeMemory(domains);
282
283 /* account + domain */
284 sids = NULL;
285 domains = NULL;
286 status = LsaLookupNames2(handle, 0, 1, &name[2], &domains, &sids);
287 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %lx)\n", status);
288 ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
289 ok(sids[0].Flags == 0, "expected 0, got 0x%08lx\n", sids[0].Flags);
290 ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
291 get_sid_info(sids[0].Sid, &account, &sid_dom);
292 ok(!strcmp(account, "LOCAL SERVICE"), "expected \"LOCAL SERVICE\", got \"%s\"\n", account);
293 ok(!strcmp(sid_dom, "NT AUTHORITY"), "expected \"NT AUTHORITY\", got \"%s\"\n", sid_dom);
294 LsaFreeMemory(sids);
295 LsaFreeMemory(domains);
296
297 /* all three */
298 sids = NULL;
299 domains = NULL;
300 status = LsaLookupNames2(handle, 0, 3, name, &domains, &sids);
301 ok(status == STATUS_SOME_NOT_MAPPED, "expected STATUS_SOME_NOT_MAPPED, got %lx)\n", status);
302 ok(sids[0].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[0].Use);
303 ok(sids[1].Use == SidTypeUnknown, "expected SidTypeUnknown, got %u\n", sids[1].Use);
304 ok(sids[2].Use == SidTypeWellKnownGroup, "expected SidTypeWellKnownGroup, got %u\n", sids[2].Use);
305 ok(sids[0].DomainIndex == 0, "expected 0, got %lu\n", sids[0].DomainIndex);
306 ok(domains->Entries == 1, "expected 1, got %lu\n", domains->Entries);
307 LsaFreeMemory(sids);
308 LsaFreeMemory(domains);
309
310 free(name[0].Buffer);
311 free(name[1].Buffer);
312 free(name[2].Buffer);
313
315 ok(status == STATUS_SUCCESS, "LsaClose() failed, returned 0x%08lx\n", status);
316}
Definition: bufpool.h:45
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
NTSTATUS WINAPI LsaLookupNames2(IN LSA_HANDLE PolicyHandle, IN ULONG Flags, IN ULONG Count, IN PLSA_UNICODE_STRING Names, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_SID2 *Sids)
Definition: lsa.c:906
LCID WINAPI GetThreadLocale(void)
Definition: locale.c:2803
LCID WINAPI GetSystemDefaultLCID(void)
Definition: locale.c:1235
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
@ SidTypeUnknown
Definition: lsa.idl:125
@ SidTypeWellKnownGroup
Definition: lsa.idl:122
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void get_sid_info(PSID psid, LPSTR *user, LPSTR *dom)
Definition: lsa.c:190
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1165
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:445
#define STATUS_SOME_NOT_MAPPED
Definition: ntstatus.h:139
int n2
Definition: dwarfget.c:147
int n1
Definition: dwarfget.c:147
#define LANG_ENGLISH
Definition: nls.h:52
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define memset(x, y, z)
Definition: compat.h:39
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by START_TEST().

◆ test_LsaLookupPrivilegeName()

static void test_LsaLookupPrivilegeName ( void  )
static

Definition at line 437 of file lsa.c.

438{
443 LUID luid;
444
445 memset(&attrs, 0, sizeof(attrs));
446 attrs.Length = sizeof(attrs);
447
449 ok(status == STATUS_SUCCESS, "Failed to open policy, %#lx.\n", status);
450
451 name = (void *)0xdeadbeef;
453 ok(status != STATUS_SUCCESS, "Unexpected status %#lx.\n", status);
454 ok(name == (void *)0xdeadbeef, "Unexpected name pointer.\n");
455
456 name = (void *)0xdeadbeef;
457 luid.HighPart = 1;
460 ok(status == STATUS_NO_SUCH_PRIVILEGE, "Unexpected status %#lx.\n", status);
461 ok(name == NULL, "Unexpected name pointer.\n");
462
463 luid.HighPart = 0;
466 ok(status == 0, "got %#lx.\n", status);
468}
WINBASEAPI _Check_return_ _Out_ AppPolicyProcessTerminationMethod * policy
Definition: appmodel.h:73
NTSTATUS WINAPI LsaLookupPrivilegeName(IN LSA_HANDLE PolicyHandle, IN PLUID Value, OUT PUNICODE_STRING *Name)
Definition: lsa.c:1000
#define SE_CREATE_TOKEN_PRIVILEGE
Definition: security.c:586
#define STATUS_NO_SUCH_PRIVILEGE
Definition: ntstatus.h:426
LONG HighPart
DWORD LowPart

Referenced by START_TEST().

◆ test_LsaLookupSids()

static void test_LsaLookupSids ( void  )
static

Definition at line 329 of file lsa.c.

330{
331 WCHAR langW[32];
332 char user_buffer[64];
333 LSA_OBJECT_ATTRIBUTES attrs = {sizeof(attrs)};
334 TOKEN_USER *user = (TOKEN_USER *)user_buffer;
341 DWORD num, size;
342 BOOL ret;
343 PSID sid;
344
346 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
347
349 ok(ret, "OpenProcessToken() failed, error %lu\n", GetLastError());
350
351 ret = GetTokenInformation(token, TokenUser, user, sizeof(user_buffer), &size);
352 ok(ret, "GetTokenInformation() failed, error %lu\n", GetLastError());
353
356 ok(ret, "GetComputerName() failed, error %lu\n", GetLastError());
357
360 ok(ret, "GetUserName() failed, error %lu\n", GetLastError());
361
362 status = LsaLookupSids(policy, 1, &user->User.Sid, &list, &names);
363 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
364
365 ok(list->Entries == 1, "got %ld\n", list->Entries);
366 check_unicode_string(&list->Domains[0].Name, computer_name);
367
368 ok(names[0].Use == SidTypeUser, "got type %u\n", names[0].Use);
369 ok(!names[0].DomainIndex, "got index %lu\n", names[0].DomainIndex);
371
375
376 ret = ConvertStringSidToSidA("S-1-1-0", &sid);
377 ok(ret, "ConvertStringSidToSidA() failed, error %lu\n", GetLastError());
378
380 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
381
382 ok(list->Entries == 1, "got %ld\n", list->Entries);
383 check_unicode_string(&list->Domains[0].Name, L"");
384
385 ok(names[0].Use == SidTypeWellKnownGroup, "got type %u\n", names[0].Use);
386 ok(!names[0].DomainIndex, "got index %lu\n", names[0].DomainIndex);
387
388 /* The group name gets translated... but not in all locales */
389 size = ARRAY_SIZE(langW);
390 if (!pGetSystemPreferredUILanguages ||
391 !pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
392 langW[0] = 0;
393 if (wcscmp(langW, L"0409") == 0 || wcscmp(langW, L"0411") == 0)
394 /* English and Japanese */
395 check_unicode_string(&names[0].Name, L"Everyone");
396 else if (wcscmp(langW, L"0407") == 0) /* German */
397 todo_wine ok(!wcsicmp(names[0].Name.Buffer, L"Jeder"), "missing translation %s\n",
398 debugstr_w(names[0].Name.Buffer));
399 else if (wcscmp(langW, L"040C") == 0) /* French */
400 todo_wine ok(!wcsicmp(names[0].Name.Buffer, L"Tout le monde"), "missing translation %s\n",
401 debugstr_w(names[0].Name.Buffer));
402 else
403 trace("<Everyone-group>.Name=%s\n", debugstr_w(names[0].Name.Buffer));
404
407 FreeSid(sid);
408
409 ret = ConvertStringSidToSidA("S-1-1234-5678-1234-5678", &sid);
410 ok(ret, "ConvertStringSidToSidA() failed, error %lu\n", GetLastError());
411
413 ok(status == STATUS_NONE_MAPPED, "got 0x%08lx\n", status);
414
415 ok(!list->Entries, "got %ld\n", list->Entries);
416
417#ifdef __REACTOS__
418 if (!names) {
419 ok(FALSE, "names should not be null!\n");
420 } else {
421#endif
422 ok(names[0].Use == SidTypeUnknown, "got type %u\n", names[0].Use);
423 ok(names[0].DomainIndex == -1, "got index %lu\n", names[0].DomainIndex);
424 check_unicode_string(&names[0].Name, L"S-1-1234-5678-1234-5678");
425#ifdef __REACTOS__
426 }
427#endif
428
431 FreeSid(sid);
432
434 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
435}
FT_UInt sid
Definition: cffcmap.c:138
Definition: list.h:37
LPWSTR Name
Definition: desk.c:124
#define FALSE
Definition: types.h:117
NTSTATUS WINAPI LsaLookupSids(IN LSA_HANDLE PolicyHandle, IN ULONG Count, IN PSID *Sids, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_NAME *Names)
Definition: lsa.c:1069
BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID *Sid)
Definition: security.c:3560
PVOID WINAPI FreeSid(PSID pSid)
Definition: security.c:698
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
#define L(x)
Definition: resources.c:13
GLuint GLuint * names
Definition: glext.h:11545
GLuint GLuint num
Definition: glext.h:9618
@ SidTypeUser
Definition: lsa.idl:118
#define todo_wine
Definition: minitest.h:80
static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH+1]
Definition: access.c:33
static WCHAR user_name[UNLEN+1]
Definition: access.c:32
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define list
Definition: rosglue.h:35

Referenced by START_TEST().

Variable Documentation

◆ domain

Definition at line 42 of file lsa.c.

Referenced by get_sid_info().