security.c 24.9 KB
Newer Older
1 2
/*
 * dlls/advapi32/security.c
3
 *  FIXME: for all functions thunking down to Rtl* functions:  implement SetLastError()
4
 */
5 6
#include <string.h>

7
#include "windef.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
8
#include "winerror.h"
9
#include "heap.h"
10
#include "ntddk.h"
11
#include "ntsecapi.h"
12
#include "debugtools.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
13

14
DEFAULT_DEBUG_CHANNEL(advapi);
15

16 17 18 19 20 21 22 23
#define CallWin32ToNt(func) \
	{ NTSTATUS ret; \
	  ret = (func); \
	  if (ret !=STATUS_SUCCESS) \
	  { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \
	  return TRUE; \
	}

24 25 26 27 28 29 30 31 32 33 34
static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa )
{
	if (oa)
	{
	  TRACE("\n\tlength=%lu, rootdir=0x%08x, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
		oa->Length, oa->RootDirectory,
		oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
     		oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
	}
}

35 36 37 38
/*	##############################
	######	TOKEN FUNCTIONS ######
	##############################
*/
39

40
/******************************************************************************
41
 * OpenProcessToken			[ADVAPI32.109]
42 43 44
 * Opens the access token associated with a process
 *
 * PARAMS
45 46 47
 *   ProcessHandle [I] Handle to process
 *   DesiredAccess [I] Desired access to process
 *   TokenHandle   [O] Pointer to handle of open access token
48 49 50
 *
 * RETURNS STD
 */
51 52 53
BOOL WINAPI
OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess, 
                  HANDLE *TokenHandle )
54
{
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	CallWin32ToNt(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
}

/******************************************************************************
 * OpenThreadToken [ADVAPI32.114]
 *
 * PARAMS
 *   thread        []
 *   desiredaccess []
 *   openasself    []
 *   thandle       []
 */
BOOL WINAPI
OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess, 
		 BOOL OpenAsSelf, HANDLE *TokenHandle)
{
	CallWin32ToNt (NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
72 73 74 75 76 77 78 79 80 81 82 83 84
}

/******************************************************************************
 * AdjustTokenPrivileges [ADVAPI32.10]
 *
 * PARAMS
 *   TokenHandle          []
 *   DisableAllPrivileges []
 *   NewState             []
 *   BufferLength         []
 *   PreviousState        []
 *   ReturnLength         []
 */
85 86
BOOL WINAPI
AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
87 88
                       LPVOID NewState, DWORD BufferLength, 
                       LPVOID PreviousState, LPDWORD ReturnLength )
89
{
90
	CallWin32ToNt(NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength));
91 92 93
}

/******************************************************************************
94
 * GetTokenInformation [ADVAPI32.66]
95 96
 *
 * PARAMS
97 98 99 100 101
 *   token           []
 *   tokeninfoclass  []
 *   tokeninfo       []
 *   tokeninfolength []
 *   retlen          []
102
 *
103
 */
104
BOOL WINAPI
105 106
GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass, 
		     LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
107
{
108
	CallWin32ToNt (NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen));
109 110
}

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
/*************************************************************************
 * SetThreadToken [ADVAPI32.231]
 *
 * Assigns an "impersonation token" to a thread so it can assume the
 * security privledges of another thread or process.  Can also remove
 * a previously assigned token.  Only supported on NT - it's a stub 
 * exactly like this one on Win9X.
 *
 */

BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
{
    FIXME("(%p, %x): stub\n", thread, token);

    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);

    return FALSE;
}

130 131 132 133 134
/*	##############################
	######	SID FUNCTIONS	######
	##############################
*/

135
/******************************************************************************
136
 * AllocateAndInitializeSid [ADVAPI32.11]
137 138
 *
 * PARAMS
139 140 141 142 143 144 145 146 147 148 149
 *   pIdentifierAuthority []
 *   nSubAuthorityCount   []
 *   nSubAuthority0       []
 *   nSubAuthority1       []
 *   nSubAuthority2       []
 *   nSubAuthority3       []
 *   nSubAuthority4       []
 *   nSubAuthority5       []
 *   nSubAuthority6       []
 *   nSubAuthority7       []
 *   pSid                 []
150
 */
151
BOOL WINAPI
152 153 154 155 156 157 158
AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
                          BYTE nSubAuthorityCount,
                          DWORD nSubAuthority0, DWORD nSubAuthority1,
                          DWORD nSubAuthority2, DWORD nSubAuthority3,
                          DWORD nSubAuthority4, DWORD nSubAuthority5,
                          DWORD nSubAuthority6, DWORD nSubAuthority7,
                          PSID *pSid )
159
{
160 161 162 163 164
	CallWin32ToNt (RtlAllocateAndInitializeSid(
		pIdentifierAuthority, nSubAuthorityCount, 
		nSubAuthority0, nSubAuthority1,	nSubAuthority2, nSubAuthority3,
		nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
		pSid ));
165
}
166

167
/******************************************************************************
168
 * FreeSid [ADVAPI32.42]
169 170
 *
 * PARAMS
171
 *   pSid []
172
 */
173
PVOID WINAPI
174 175
FreeSid( PSID pSid )
{
176 177
    	RtlFreeSid(pSid); 
	return NULL; /* is documented like this */
178 179
}

180 181 182 183 184 185 186
/******************************************************************************
 * CopySid [ADVAPI32.24]
 *
 * PARAMS
 *   nDestinationSidLength []
 *   pDestinationSid       []
 *   pSourceSid            []
187
 */
188
BOOL WINAPI
189
CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
190
{
191
	return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
192 193
}

194 195 196 197 198
/******************************************************************************
 * IsValidSid [ADVAPI32.80]
 *
 * PARAMS
 *   pSid []
Alexandre Julliard's avatar
Alexandre Julliard committed
199
 */
200
BOOL WINAPI
201
IsValidSid( PSID pSid )
202
{
203
	return RtlValidSid( pSid );
Alexandre Julliard's avatar
Alexandre Julliard committed
204 205
}

206 207 208 209 210 211
/******************************************************************************
 * EqualSid [ADVAPI32.40]
 *
 * PARAMS
 *   pSid1 []
 *   pSid2 []
Alexandre Julliard's avatar
Alexandre Julliard committed
212
 */
213
BOOL WINAPI
214
EqualSid( PSID pSid1, PSID pSid2 )
215
{
216
	return RtlEqualSid( pSid1, pSid2 );
Alexandre Julliard's avatar
Alexandre Julliard committed
217 218
}

219 220
/******************************************************************************
 * EqualPrefixSid [ADVAPI32.39]
Alexandre Julliard's avatar
Alexandre Julliard committed
221
 */
222 223 224
BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2) 
{
	return RtlEqualPrefixSid(pSid1, pSid2);
Alexandre Julliard's avatar
Alexandre Julliard committed
225 226
}

227 228 229 230 231
/******************************************************************************
 * GetSidLengthRequired [ADVAPI32.63]
 *
 * PARAMS
 *   nSubAuthorityCount []
Alexandre Julliard's avatar
Alexandre Julliard committed
232
 */
233 234 235
DWORD WINAPI
GetSidLengthRequired( BYTE nSubAuthorityCount )
{
236
	return RtlLengthRequiredSid(nSubAuthorityCount);
Alexandre Julliard's avatar
Alexandre Julliard committed
237 238
}

239
/******************************************************************************
240
 * InitializeSid [ADVAPI32.74]
241 242
 *
 * PARAMS
243
 *   pIdentifierAuthority []
244
 */
245
BOOL WINAPI
246 247 248 249
InitializeSid (
	PSID pSid,
	PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
	BYTE nSubAuthorityCount)
250
{
251
	return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
252 253
}

254
/******************************************************************************
255
 * GetSidIdentifierAuthority [ADVAPI32.62]
256 257
 *
 * PARAMS
258
 *   pSid []
259
 */
260 261
PSID_IDENTIFIER_AUTHORITY WINAPI
GetSidIdentifierAuthority( PSID pSid )
262
{
263
	return RtlIdentifierAuthoritySid(pSid);
264
}
Alexandre Julliard's avatar
Alexandre Julliard committed
265

266 267 268 269 270 271 272
/******************************************************************************
 * GetSidSubAuthority [ADVAPI32.64]
 *
 * PARAMS
 *   pSid          []
 *   nSubAuthority []
 */
273
PDWORD WINAPI
274 275
GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
{
276
	return RtlSubAuthoritySid(pSid, nSubAuthority);
277
}
Alexandre Julliard's avatar
Alexandre Julliard committed
278

279 280 281 282 283 284
/******************************************************************************
 * GetSidSubAuthorityCount [ADVAPI32.65]
 *
 * PARAMS
 *   pSid []
 */
285
PUCHAR WINAPI
286 287
GetSidSubAuthorityCount (PSID pSid)
{
288
	return RtlSubAuthorityCountSid(pSid);
Alexandre Julliard's avatar
Alexandre Julliard committed
289 290
}

Matthew Becker's avatar
Matthew Becker committed
291
/******************************************************************************
292
 * GetLengthSid [ADVAPI32.48]
Matthew Becker's avatar
Matthew Becker committed
293 294 295
 *
 * PARAMS
 *   pSid []
Alexandre Julliard's avatar
Alexandre Julliard committed
296
 */
297 298
DWORD WINAPI
GetLengthSid (PSID pSid)
Alexandre Julliard's avatar
Alexandre Julliard committed
299
{
300
	return RtlLengthSid(pSid);
Alexandre Julliard's avatar
Alexandre Julliard committed
301 302
}

303 304 305 306 307
/*	##############################################
	######	SECURITY DESCRIPTOR FUNCTIONS	######
	##############################################
*/
	
Matthew Becker's avatar
Matthew Becker committed
308 309 310 311 312 313
/******************************************************************************
 * InitializeSecurityDescriptor [ADVAPI32.73]
 *
 * PARAMS
 *   pDescr   []
 *   revision []
Alexandre Julliard's avatar
Alexandre Julliard committed
314
 */
315
BOOL WINAPI
316
InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr, DWORD revision )
Alexandre Julliard's avatar
Alexandre Julliard committed
317
{
318
	CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
Alexandre Julliard's avatar
Alexandre Julliard committed
319 320
}

Matthew Becker's avatar
Matthew Becker committed
321 322
/******************************************************************************
 * GetSecurityDescriptorLength [ADVAPI32.55]
323 324 325
 */
DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
{
326
	return (RtlLengthSecurityDescriptor(pDescr));
327 328
}

Matthew Becker's avatar
Matthew Becker committed
329 330 331 332 333 334
/******************************************************************************
 * GetSecurityDescriptorOwner [ADVAPI32.56]
 *
 * PARAMS
 *   pOwner            []
 *   lpbOwnerDefaulted []
335
 */
336
BOOL WINAPI
337
GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
338
			    LPBOOL lpbOwnerDefaulted )
339
{
340
	CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
341
}
342

Matthew Becker's avatar
Matthew Becker committed
343
/******************************************************************************
344
 * SetSecurityDescriptorOwner [ADVAPI32]
Matthew Becker's avatar
Matthew Becker committed
345 346
 *
 * PARAMS
347
 */
348
BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor, 
349
				   PSID pOwner, BOOL bOwnerDefaulted)
350 351 352 353 354 355
{
	CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
}
/******************************************************************************
 * GetSecurityDescriptorGroup			[ADVAPI32.54]
 */
356
BOOL WINAPI GetSecurityDescriptorGroup(
357 358
	PSECURITY_DESCRIPTOR SecurityDescriptor,
	PSID *Group,
359
	LPBOOL GroupDefaulted)
360 361 362 363 364 365
{
	CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
}	
/******************************************************************************
 * SetSecurityDescriptorGroup
 */
366 367
BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
					   PSID Group, BOOL GroupDefaulted)
368
{
369
	CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
370
}
Alexandre Julliard's avatar
Alexandre Julliard committed
371

Matthew Becker's avatar
Matthew Becker committed
372
/******************************************************************************
373
 * IsValidSecurityDescriptor [ADVAPI32.79]
Matthew Becker's avatar
Matthew Becker committed
374 375
 *
 * PARAMS
376
 *   lpsecdesc []
Alexandre Julliard's avatar
Alexandre Julliard committed
377
 */
378
BOOL WINAPI
379
IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
Alexandre Julliard's avatar
Alexandre Julliard committed
380
{
381 382
	CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
}
Alexandre Julliard's avatar
Alexandre Julliard committed
383

384 385 386
/******************************************************************************
 *  GetSecurityDescriptorDacl			[ADVAPI.91]
 */
387
BOOL WINAPI GetSecurityDescriptorDacl(
388
	IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
389
	OUT LPBOOL lpbDaclPresent,
390
	OUT PACL *pDacl,
391
	OUT LPBOOL lpbDaclDefaulted)
392 393 394 395
{
	CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
					       pDacl, (PBOOLEAN)lpbDaclDefaulted));
}	
Alexandre Julliard's avatar
Alexandre Julliard committed
396

397 398 399
/******************************************************************************
 *  SetSecurityDescriptorDacl			[ADVAPI.224]
 */
400
BOOL WINAPI 
401 402 403 404 405
SetSecurityDescriptorDacl (
	PSECURITY_DESCRIPTOR lpsd,
	BOOL daclpresent,
	PACL dacl,
	BOOL dacldefaulted )
406 407
{
	CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
408 409 410 411 412 413 414 415 416 417
}
/******************************************************************************
 *  GetSecurityDescriptorSacl			[ADVAPI.]
 */
BOOL WINAPI GetSecurityDescriptorSacl(
	IN PSECURITY_DESCRIPTOR lpsd,
	OUT LPBOOL lpbSaclPresent,
	OUT PACL *pSacl,
	OUT LPBOOL lpbSaclDefaulted)
{
418 419
	CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd,
	   (PBOOLEAN)lpbSaclPresent, pSacl, (PBOOLEAN)lpbSaclDefaulted));
420
}	
421

422 423 424
/**************************************************************************
 * SetSecurityDescriptorSacl			[NTDLL.488]
 */
425
BOOL WINAPI SetSecurityDescriptorSacl (
426
	PSECURITY_DESCRIPTOR lpsd,
427
	BOOL saclpresent,
428
	PACL lpsacl,
429
	BOOL sacldefaulted)
430
{
431
	CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
Alexandre Julliard's avatar
Alexandre Julliard committed
432
}
433
/******************************************************************************
434
 * MakeSelfRelativeSD [ADVAPI32.95]
435 436
 *
 * PARAMS
437 438 439
 *   lpabssecdesc  []
 *   lpselfsecdesc []
 *   lpbuflen      []
Alexandre Julliard's avatar
Alexandre Julliard committed
440
 */
441
BOOL WINAPI
442 443 444 445
MakeSelfRelativeSD(
	IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
	IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
	IN OUT LPDWORD lpdwBufferLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
446
{
447
	CallWin32ToNt (RtlMakeSelfRelativeSD(pAbsoluteSecurityDescriptor,pSelfRelativeSecurityDescriptor, lpdwBufferLength));
Alexandre Julliard's avatar
Alexandre Julliard committed
448 449
}

450
/******************************************************************************
451
 * GetSecurityDescriptorControl			[ADVAPI32]
452 453
 */

454 455
BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR  pSecurityDescriptor,
		 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
456 457
{
	CallWin32ToNt (RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
458 459
}		

460 461 462 463 464 465 466 467 468 469 470 471 472
/*	##############################
	######	ACL FUNCTIONS	######
	##############################
*/

/*************************************************************************
 * InitializeAcl [ADVAPI32.111]
 */
DWORD WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
{
	CallWin32ToNt (RtlCreateAcl(acl, size, rev));
}

473 474 475 476 477 478
/*	##############################
	######	MISC FUNCTIONS	######
	##############################
*/

/******************************************************************************
479
 * LookupPrivilegeValueW			[ADVAPI32.93]
480 481 482 483
 * Retrieves LUID used on a system to represent the privilege name.
 *
 * NOTES
 *   lpLuid should be PLUID
484 485
 *
 * PARAMS
486 487 488 489 490
 *   lpSystemName [I] Address of string specifying the system
 *   lpName       [I] Address of string specifying the privilege
 *   lpLuid       [I] Address of locally unique identifier
 *
 * RETURNS STD
Alexandre Julliard's avatar
Alexandre Julliard committed
491
 */
492 493
BOOL WINAPI
LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
Alexandre Julliard's avatar
Alexandre Julliard committed
494
{
495
    FIXME("(%s,%s,%p): stub\n",debugstr_w(lpSystemName), 
496
        debugstr_w(lpName), lpLuid);
497
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
498 499
}

500
/******************************************************************************
501
 * LookupPrivilegeValueA			[ADVAPI32.92]
Alexandre Julliard's avatar
Alexandre Julliard committed
502
 */
503 504
BOOL WINAPI
LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
Alexandre Julliard's avatar
Alexandre Julliard committed
505
{
506 507
    LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
    LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
508 509 510
    BOOL ret;

    ret = LookupPrivilegeValueW( lpSystemNameW, lpNameW, lpLuid);
511 512 513
    HeapFree(GetProcessHeap(), 0, lpNameW);
    HeapFree(GetProcessHeap(), 0, lpSystemNameW);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
514 515
}

516
/******************************************************************************
517
 * GetFileSecurityA [ADVAPI32.45]
518
 *
519 520 521
 * Obtains Specified information about the security of a file or directory
 * The information obtained is constrained by the callers access rights and
 * privileges
Alexandre Julliard's avatar
Alexandre Julliard committed
522
 */
523 524
BOOL WINAPI
GetFileSecurityA( LPCSTR lpFileName, 
525 526 527
                    SECURITY_INFORMATION RequestedInformation,
                    PSECURITY_DESCRIPTOR pSecurityDescriptor,
                    DWORD nLength, LPDWORD lpnLengthNeeded )
Alexandre Julliard's avatar
Alexandre Julliard committed
528
{
529
  FIXME("(%s) : stub\n", debugstr_a(lpFileName));
530
  return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
531 532
}

533
/******************************************************************************
534
 * GetFileSecurityW [ADVAPI32.46]
535 536 537 538
 *
 * Obtains Specified information about the security of a file or directory
 * The information obtained is constrained by the callers access rights and
 * privileges
539 540
 *
 * PARAMS
541 542 543 544 545
 *   lpFileName           []
 *   RequestedInformation []
 *   pSecurityDescriptor  []
 *   nLength              []
 *   lpnLengthNeeded      []
Alexandre Julliard's avatar
Alexandre Julliard committed
546
 */
547 548
BOOL WINAPI
GetFileSecurityW( LPCWSTR lpFileName, 
549 550 551
                    SECURITY_INFORMATION RequestedInformation,
                    PSECURITY_DESCRIPTOR pSecurityDescriptor,
                    DWORD nLength, LPDWORD lpnLengthNeeded )
552
{
553
  FIXME("(%s) : stub\n", debugstr_w(lpFileName) ); 
554
  return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
555
}
Alexandre Julliard's avatar
Alexandre Julliard committed
556

557

558
/******************************************************************************
559
 * LookupAccountSidA [ADVAPI32.86]
Alexandre Julliard's avatar
Alexandre Julliard committed
560
 */
561
BOOL WINAPI
562 563 564 565 566 567 568 569 570
LookupAccountSidA(
	IN LPCSTR system,
	IN PSID sid,
	OUT LPSTR account,
	IN OUT LPDWORD accountSize,
	OUT LPSTR domain,
	IN OUT LPDWORD domainSize,
	OUT PSID_NAME_USE name_use )
{
571 572
	static const char ac[] = "Administrator";
	static const char dm[] = "DOMAIN";
573
	FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
	      debugstr_a(system),sid,
	      account,accountSize,accountSize?*accountSize:0,
	      domain,domainSize,domainSize?*domainSize:0,
	      name_use);

	if (accountSize) *accountSize = strlen(ac)+1;
	if (account && (*accountSize > strlen(ac)))
	  strcpy(account, ac);

	if (domainSize) *domainSize = strlen(dm)+1;
	if (domain && (*domainSize > strlen(dm)))
	  strcpy(domain,dm);

	if (name_use) *name_use = SidTypeUser;
	return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
589 590
}

591
/******************************************************************************
592
 * LookupAccountSidW [ADVAPI32.87]
593 594 595 596 597 598 599 600 601 602
 *
 * PARAMS
 *   system      []
 *   sid         []
 *   account     []
 *   accountSize []
 *   domain      []
 *   domainSize  []
 *   name_use    []
 */
603
BOOL WINAPI
604 605 606 607 608 609 610 611 612
LookupAccountSidW(
	IN LPCWSTR system,
	IN PSID sid,
	OUT LPWSTR account,
	IN OUT LPDWORD accountSize,
	OUT LPWSTR domain,
	IN OUT LPDWORD domainSize,
	OUT PSID_NAME_USE name_use )
{
613 614
    static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
    static const WCHAR dm[] = {'D','O','M','A','I','N',0};
615
	FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
616 617 618 619 620
	      debugstr_w(system),sid,
	      account,accountSize,accountSize?*accountSize:0,
	      domain,domainSize,domainSize?*domainSize:0,
	      name_use);

621 622 623
	if (accountSize) *accountSize = strlenW(ac)+1;
	if (account && (*accountSize > strlenW(ac)))
            strcpyW(account, ac);
624

625 626 627
	if (domainSize) *domainSize = strlenW(dm)+1;
	if (domain && (*domainSize > strlenW(dm)))
            strcpyW(domain,dm);
628 629 630

	if (name_use) *name_use = SidTypeUser;
	return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
631 632
}

633
/******************************************************************************
634
 * SetFileSecurityA [ADVAPI32.182]
635 636
 * Sets the security of a file or directory
 */
637
BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
638
                                SECURITY_INFORMATION RequestedInformation,
639
                                PSECURITY_DESCRIPTOR pSecurityDescriptor)
640
{
641
  FIXME("(%s) : stub\n", debugstr_a(lpFileName));
642 643 644 645
  return TRUE;
}

/******************************************************************************
646
 * SetFileSecurityW [ADVAPI32.183]
647
 * Sets the security of a file or directory
648 649 650 651 652 653
 *
 * PARAMS
 *   lpFileName           []
 *   RequestedInformation []
 *   pSecurityDescriptor  []
 */
654 655
BOOL WINAPI
SetFileSecurityW( LPCWSTR lpFileName, 
656
                    SECURITY_INFORMATION RequestedInformation,
657
                    PSECURITY_DESCRIPTOR pSecurityDescriptor )
658
{
659
  FIXME("(%s) : stub\n", debugstr_w(lpFileName) ); 
660 661
  return TRUE;
}
662

663
/******************************************************************************
664 665 666 667
 * QueryWindows31FilesMigration [ADVAPI32.266]
 *
 * PARAMS
 *   x1 []
668
 */
669
BOOL WINAPI
670 671
QueryWindows31FilesMigration( DWORD x1 )
{
672
	FIXME("(%ld):stub\n",x1);
673 674 675 676
	return TRUE;
}

/******************************************************************************
677 678 679 680 681 682 683 684
 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.265]
 *
 * PARAMS
 *   x1 []
 *   x2 []
 *   x3 []
 *   x4 []
 */
685
BOOL WINAPI
686 687 688
SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
                                               DWORD x4 )
{
689
	FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
690 691 692 693
	return TRUE;
}

/******************************************************************************
694 695 696 697 698 699 700
 * LsaOpenPolicy [ADVAPI32.200]
 *
 * PARAMS
 *   x1 []
 *   x2 []
 *   x3 []
 *   x4 []
701
 */
702
NTSTATUS WINAPI
703 704 705 706 707 708 709 710 711 712 713 714
LsaOpenPolicy(
	IN PLSA_UNICODE_STRING SystemName,
	IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
	IN ACCESS_MASK DesiredAccess,
	IN OUT PLSA_HANDLE PolicyHandle)
{
	FIXME("(%s,%p,0x%08lx,%p):stub\n",
              SystemName?debugstr_w(SystemName->Buffer):"null",
	      ObjectAttributes, DesiredAccess, PolicyHandle);
	dumpLsaAttributes(ObjectAttributes);
	if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
	return TRUE;
715 716
}

717 718 719 720
/******************************************************************************
 * LsaQueryInformationPolicy [ADVAPI32.242]
 */
NTSTATUS WINAPI
721 722 723 724
LsaQueryInformationPolicy( 
	IN LSA_HANDLE PolicyHandle,
        IN POLICY_INFORMATION_CLASS InformationClass,
	OUT PVOID *Buffer)
725 726 727
{
	FIXME("(%p,0x%08x,%p):stub\n",
              PolicyHandle, InformationClass, Buffer);
728 729 730 731 732 733

	if(!Buffer) return FALSE;
	switch (InformationClass)
	{
	  case PolicyAuditEventsInformation: /* 2 */
	    {
734
	      PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
735 736 737 738 739 740 741 742 743 744 745 746 747
	      p->AuditingMode = FALSE; /* no auditing */
	      *Buffer = p;
	    }
	    break;
	  case PolicyPrimaryDomainInformation: /* 3 */
	  case PolicyAccountDomainInformation: /* 5 */
	    {
	      struct di
	      { POLICY_PRIMARY_DOMAIN_INFO ppdi;
		SID sid;
	      };
	      SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
		
748
	      struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
	      RtlInitUnicodeString(&(xdi->ppdi.Name), HEAP_strdupAtoW(GetProcessHeap(),0,"DOMAIN"));
	      xdi->ppdi.Sid = &(xdi->sid);
	      xdi->sid.Revision = SID_REVISION;
	      xdi->sid.SubAuthorityCount = 1;
	      xdi->sid.IdentifierAuthority = localSidAuthority;
	      xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
	      *Buffer = xdi;
	    }
	    break;
	  case 	PolicyAuditLogInformation:	
	  case 	PolicyPdAccountInformation:	
	  case 	PolicyLsaServerRoleInformation:
	  case 	PolicyReplicaSourceInformation:
	  case 	PolicyDefaultQuotaInformation:
	  case 	PolicyModificationInformation:
	  case 	PolicyAuditFullSetInformation:
	  case 	PolicyAuditFullQueryInformation:
	  case 	PolicyDnsDomainInformation:
	    {
	      FIXME("category not implemented\n");
	      return FALSE;
	    }
	}
	return TRUE; 
773 774
}			  

775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
/******************************************************************************
 * LsaLookupSids [ADVAPI32.240]
 */
typedef struct
{
	SID_NAME_USE Use;
	LSA_UNICODE_STRING Name;
	LONG DomainIndex;
} LSA_TRANSLATED_NAME, *PLSA_TRANSLATED_NAME;

typedef struct 
{
	LSA_UNICODE_STRING Name;
	PSID Sid;
} LSA_TRUST_INFORMATION, *PLSA_TRUST_INFORMATION;

typedef struct 
{
	ULONG Entries;
	PLSA_TRUST_INFORMATION Domains;
} LSA_REFERENCED_DOMAIN_LIST, *PLSA_REFERENCED_DOMAIN_LIST;

NTSTATUS WINAPI
LsaLookupSids(
	IN LSA_HANDLE PolicyHandle,
	IN ULONG Count,
	IN PSID *Sids,
	OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
	OUT PLSA_TRANSLATED_NAME *Names )
{
	FIXME("%p %lu %p %p %p\n",
	  PolicyHandle, Count, Sids, ReferencedDomains, Names);
	return FALSE;
}

810 811 812 813 814 815
/******************************************************************************
 * LsaFreeMemory [ADVAPI32.241]
 */
NTSTATUS WINAPI
LsaFreeMemory(IN PVOID Buffer)
{
816
	TRACE("(%p)\n",Buffer);
817
	return HeapFree(GetProcessHeap(), 0, Buffer);
818 819 820 821 822 823 824 825 826 827
}
/******************************************************************************
 * LsaClose [ADVAPI32.243]
 */
NTSTATUS WINAPI
LsaClose(IN LSA_HANDLE ObjectHandle)
{
	FIXME("(%p):stub\n",ObjectHandle);
	return 0xc0000000;
}
828
/******************************************************************************
829 830 831 832
 * NotifyBootConfigStatus [ADVAPI32.97]
 *
 * PARAMS
 *   x1 []
833
 */
834
BOOL WINAPI
835 836
NotifyBootConfigStatus( DWORD x1 )
{
837
	FIXME("(0x%08lx):stub\n",x1);
838 839
	return 1;
}
840 841

/******************************************************************************
Matthew Becker's avatar
Matthew Becker committed
842 843 844 845
 * RevertToSelf [ADVAPI32.180]
 *
 * PARAMS
 *   void []
846
 */
847
BOOL WINAPI
Matthew Becker's avatar
Matthew Becker committed
848 849
RevertToSelf( void )
{
850
	FIXME("(), stub\n");
851 852
	return TRUE;
}
853 854 855 856

/******************************************************************************
 * ImpersonateSelf [ADVAPI32.71]
 */
857
BOOL WINAPI
858
ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
859
{
860
	return RtlImpersonateSelf(ImpersonationLevel);
861 862
}

863
/******************************************************************************
864
 * AccessCheck [ADVAPI32.71]
865 866
 *
 * FIXME check cast LPBOOL to PBOOLEAN
867
 */
868
BOOL WINAPI
869 870 871 872 873 874 875 876 877 878 879 880
AccessCheck(
	PSECURITY_DESCRIPTOR SecurityDescriptor,
	HANDLE ClientToken,
	DWORD DesiredAccess,
	PGENERIC_MAPPING GenericMapping,
	PPRIVILEGE_SET PrivilegeSet,
	LPDWORD PrivilegeSetLength,
	LPDWORD GrantedAccess,
	LPBOOL AccessStatus)
{
	CallWin32ToNt (NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
	  GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, (PBOOLEAN)AccessStatus));
881
}
882 883

/*************************************************************************
884
 * SetKernelObjectSecurity [ADVAPI32.223]
885
 */
886 887 888 889
BOOL WINAPI SetKernelObjectSecurity (
	IN HANDLE Handle,
	IN SECURITY_INFORMATION SecurityInformation,
	IN PSECURITY_DESCRIPTOR SecurityDescriptor )
890
{
891
	CallWin32ToNt (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
892 893
}

894 895 896 897 898 899 900 901 902 903 904
/******************************************************************************
 *  AddAccessAllowedAce
 */
BOOL WINAPI AddAccessAllowedAce(
        IN OUT PACL pAcl,
        IN DWORD dwAceRevision,
        IN DWORD AccessMask,
        IN PSID pSid)
{
        return RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid);
}
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921

/******************************************************************************
 * LookupAccountNameA [ADVAPI32.@]
 */
BOOL WINAPI
LookupAccountNameA(
	IN LPCSTR system,
	IN LPCSTR account,
	OUT PSID sid,
	OUT LPDWORD cbSid,
	LPSTR ReferencedDomainName,
	IN OUT LPDWORD cbReferencedDomainName,
	OUT PSID_NAME_USE name_use )
{
    FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
    return FALSE;
}