2 * dlls/advapi32/security.c
11 /* FIXME: move it to a header */
12 BOOL32 WINAPI IsValidSid (PSID pSid);
13 BOOL32 WINAPI EqualSid (PSID pSid1, PSID pSid2);
14 BOOL32 WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2);
15 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount);
16 BOOL32 WINAPI 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);
17 VOID* WINAPI FreeSid(PSID pSid);
18 BOOL32 WINAPI InitializeSid (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
19 PSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(PSID pSid);
20 DWORD* WINAPI GetSidSubAuthority(PSID pSid, DWORD nSubAuthority);
21 BYTE* WINAPI GetSidSubAuthorityCount(PSID pSid);
22 DWORD WINAPI GetLengthSid(PSID pSid);
23 BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid);
26 /******************************************************************************
27 * OpenProcessToken [ADVAPI32.109]
28 * Opens the access token associated with a process
31 * ProcessHandle [I] Handle to process
32 * DesiredAccess [I] Desired access to process
33 * TokenHandle [O] Pointer to handle of open access token
38 OpenProcessToken( HANDLE32 ProcessHandle, DWORD DesiredAccess,
39 HANDLE32 *TokenHandle )
41 FIXME(advapi,"(%08x,%08lx,%p): stub\n",ProcessHandle,DesiredAccess,
43 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
47 /******************************************************************************
48 * OpenThreadToken [ADVAPI32.114]
57 OpenThreadToken( HANDLE32 thread, DWORD desiredaccess, BOOL32 openasself,
60 FIXME(advapi,"(%08x,%08lx,%d,%p): stub!\n",
61 thread,desiredaccess,openasself,thandle);
62 *thandle = 0; /* FIXME ... well, store something in there ;) */
67 /******************************************************************************
68 * LookupPrivilegeValue32A [ADVAPI32.92]
71 LookupPrivilegeValue32A( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
73 LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
74 LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
75 BOOL32 ret = LookupPrivilegeValue32W( lpSystemNameW, lpNameW, lpLuid);
76 HeapFree(GetProcessHeap(), 0, lpNameW);
77 HeapFree(GetProcessHeap(), 0, lpSystemNameW);
81 /******************************************************************************
82 * LookupPrivilegeValue32W [ADVAPI32.93]
83 * Retrieves LUID used on a system to represent the privilege name.
86 * lpLuid should be PLUID
89 * lpSystemName [I] Address of string specifying the system
90 * lpName [I] Address of string specifying the privilege
91 * lpLuid [I] Address of locally unique identifier
96 LookupPrivilegeValue32W( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
98 FIXME(advapi,"(%s,%s,%p): stub\n",debugstr_w(lpSystemName),
99 debugstr_w(lpName), lpLuid);
102 /******************************************************************************
103 * GetFileSecurity32A [ADVAPI32.45]
105 * Obtains Specified information about the security of a file or directory
106 * The information obtained is constrained by the callers access rights and
110 GetFileSecurity32A( LPCSTR lpFileName,
111 SECURITY_INFORMATION RequestedInformation,
112 PSECURITY_DESCRIPTOR pSecurityDescriptor,
113 DWORD nLength, LPDWORD lpnLengthNeeded )
115 FIXME(advapi, "(%s) : stub\n", debugstr_a(lpFileName));
119 /******************************************************************************
120 * GetFileSecurity32W [ADVAPI32.46]
122 * Obtains Specified information about the security of a file or directory
123 * The information obtained is constrained by the callers access rights and
128 * RequestedInformation []
129 * pSecurityDescriptor []
134 GetFileSecurity32W( LPCWSTR lpFileName,
135 SECURITY_INFORMATION RequestedInformation,
136 PSECURITY_DESCRIPTOR pSecurityDescriptor,
137 DWORD nLength, LPDWORD lpnLengthNeeded )
139 FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) );
144 /******************************************************************************
145 * AdjustTokenPrivileges [ADVAPI32.10]
149 * DisableAllPrivileges []
156 AdjustTokenPrivileges( HANDLE32 TokenHandle, BOOL32 DisableAllPrivileges,
157 LPVOID NewState, DWORD BufferLength,
158 LPVOID PreviousState, LPDWORD ReturnLength )
159 { FIXME(advapi, "stub\n");
160 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
164 /******************************************************************************
165 * CopySid [ADVAPI32.24]
168 * nDestinationSidLength []
173 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
176 if (!IsValidSid(pSourceSid))
179 if (nDestinationSidLength < GetLengthSid(pSourceSid))
182 memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
187 /******************************************************************************
188 * IsValidSid [ADVAPI32.80]
194 IsValidSid( PSID pSid )
196 if (!pSid || pSid->Revision != SID_REVISION)
202 /******************************************************************************
203 * EqualSid [ADVAPI32.40]
210 EqualSid( PSID pSid1, PSID pSid2 )
212 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
215 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
218 if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
224 /******************************************************************************
225 * EqualPrefixSid [ADVAPI32.39]
227 BOOL32 WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2) {
228 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
231 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
234 if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
241 /******************************************************************************
242 * GetSidLengthRequired [ADVAPI32.63]
245 * nSubAuthorityCount []
248 GetSidLengthRequired( BYTE nSubAuthorityCount )
250 return sizeof (SID) + (nSubAuthorityCount - 1) * sizeof (DWORD);
253 /******************************************************************************
254 * GetTokenInformation [ADVAPI32.66]
264 * tokeninfoclas should be TOKEN_INFORMATION_CLASS
267 GetTokenInformation( HANDLE32 token, DWORD tokeninfoclass, LPVOID tokeninfo,
268 DWORD tokeninfolength, LPDWORD retlen )
270 FIXME(advapi,"(%08x,%ld,%p,%ld,%p): stub\n",
271 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
275 /******************************************************************************
276 * AllocateAndInitializeSid [ADVAPI32.11]
279 * pIdentifierAuthority []
280 * nSubAuthorityCount []
292 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
293 BYTE nSubAuthorityCount,
294 DWORD nSubAuthority0, DWORD nSubAuthority1,
295 DWORD nSubAuthority2, DWORD nSubAuthority3,
296 DWORD nSubAuthority4, DWORD nSubAuthority5,
297 DWORD nSubAuthority6, DWORD nSubAuthority7,
300 if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
301 GetSidLengthRequired(nSubAuthorityCount))))
303 (*pSid)->Revision = SID_REVISION;
304 if (pIdentifierAuthority)
305 memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
306 sizeof (SID_IDENTIFIER_AUTHORITY));
307 *GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
309 if (nSubAuthorityCount > 0)
310 *GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
311 if (nSubAuthorityCount > 1)
312 *GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
313 if (nSubAuthorityCount > 2)
314 *GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
315 if (nSubAuthorityCount > 3)
316 *GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
317 if (nSubAuthorityCount > 4)
318 *GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
319 if (nSubAuthorityCount > 5)
320 *GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
321 if (nSubAuthorityCount > 6)
322 *GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
323 if (nSubAuthorityCount > 7)
324 *GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
329 /******************************************************************************
330 * FreeSid [ADVAPI32.42]
338 HeapFree( GetProcessHeap(), 0, pSid );
342 /******************************************************************************
343 * InitializeSecurityDescriptor [ADVAPI32.73]
350 InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
353 TRACE (security, "(%p,%lx): stub\n", pDescr, revision);
354 ZeroMemory (pDescr, sizeof (SECURITY_DESCRIPTOR));
355 pDescr->Revision = revision;
359 /******************************************************************************
360 * GetSecurityDescriptorLength [ADVAPI32.55]
362 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
364 FIXME(security, "(%p), stub\n", pDescr);
368 /******************************************************************************
369 * GetSecurityDescriptorOwner [ADVAPI32.56]
373 * lpbOwnerDefaulted []
376 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
377 LPBOOL32 lpbOwnerDefaulted )
379 FIXME(security, "(%p,%p,%p), stub\n", pDescr,pOwner,lpbOwnerDefaulted);
380 *lpbOwnerDefaulted = TRUE;
384 /******************************************************************************
385 * GetSecurityDescriptorGroup [ADVAPI32.54]
389 * lpbOwnerDefaulted []
392 GetSecurityDescriptorGroup( SECURITY_DESCRIPTOR *pDescr, PSID *pGroup,
393 LPBOOL32 lpbOwnerDefaulted )
395 FIXME(security, "(%p,%p,%p), stub\n", pDescr,pGroup,lpbOwnerDefaulted);
396 *lpbOwnerDefaulted = TRUE;
400 /******************************************************************************
401 * InitializeSid [ADVAPI32.74]
404 * pIdentifierAuthority []
407 InitializeSid (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
408 BYTE nSubAuthorityCount)
412 pSid->Revision = SID_REVISION;
413 if (pIdentifierAuthority)
414 memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
415 sizeof (SID_IDENTIFIER_AUTHORITY));
416 *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
418 for (i = 0; i < nSubAuthorityCount; i++)
419 *GetSidSubAuthority(pSid, i) = 0;
424 /******************************************************************************
425 * GetSidIdentifierAuthority [ADVAPI32.62]
430 PSID_IDENTIFIER_AUTHORITY WINAPI
431 GetSidIdentifierAuthority( PSID pSid )
433 return &pSid->IdentifierAuthority;
436 /******************************************************************************
437 * GetSidSubAuthority [ADVAPI32.64]
444 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
446 return &pSid->SubAuthority[nSubAuthority];
449 /******************************************************************************
450 * GetSidSubAuthorityCount [ADVAPI32.65]
456 GetSidSubAuthorityCount (PSID pSid)
458 return &pSid->SubAuthorityCount;
461 /******************************************************************************
462 * GetLengthSid [ADVAPI32.48]
468 GetLengthSid (PSID pSid)
470 return GetSidLengthRequired( * GetSidSubAuthorityCount(pSid) );
473 /******************************************************************************
474 * IsValidSecurityDescriptor [ADVAPI32.79]
480 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR lpsecdesc )
482 FIXME(advapi,"(%p):stub\n",lpsecdesc);
486 /******************************************************************************
487 * LookupAccountSid32A [ADVAPI32.86]
490 LookupAccountSid32A( LPCSTR system, PSID sid, LPCSTR account,
491 LPDWORD accountSize, LPCSTR domain, LPDWORD domainSize,
492 PSID_NAME_USE name_use )
494 FIXME(security,"(%s,%p,%p,%p,%p,%p,%p): stub\n",
495 system,sid,account,accountSize,domain,domainSize,name_use);
496 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
500 /******************************************************************************
501 * LookupAccountSid32W [ADVAPI32.87]
513 LookupAccountSid32W( LPCWSTR system, PSID sid, LPCWSTR account,
514 LPDWORD accountSize, LPCWSTR domain, LPDWORD domainSize,
515 PSID_NAME_USE name_use )
517 FIXME(security,"(%p,%p,%p,%p,%p,%p,%p): stub\n",
518 system,sid,account,accountSize,domain,domainSize,name_use);
519 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
523 /******************************************************************************
524 * SetFileSecurity32A [ADVAPI32.182]
525 * Sets the security of a file or directory
527 BOOL32 WINAPI SetFileSecurity32A( LPCSTR lpFileName,
528 SECURITY_INFORMATION RequestedInformation,
529 PSECURITY_DESCRIPTOR pSecurityDescriptor)
531 FIXME(advapi, "(%s) : stub\n", debugstr_a(lpFileName));
535 /******************************************************************************
536 * SetFileSecurity32W [ADVAPI32.183]
537 * Sets the security of a file or directory
541 * RequestedInformation []
542 * pSecurityDescriptor []
545 SetFileSecurity32W( LPCWSTR lpFileName,
546 SECURITY_INFORMATION RequestedInformation,
547 PSECURITY_DESCRIPTOR pSecurityDescriptor )
549 FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) );
553 /******************************************************************************
554 * MakeSelfRelativeSD [ADVAPI32.95]
562 MakeSelfRelativeSD( PSECURITY_DESCRIPTOR lpabssecdesc,
563 PSECURITY_DESCRIPTOR lpselfsecdesc, LPDWORD lpbuflen )
565 FIXME(advapi,"(%p,%p,%p),stub!\n",lpabssecdesc,lpselfsecdesc,lpbuflen);
569 /******************************************************************************
570 * QueryWindows31FilesMigration [ADVAPI32.266]
576 QueryWindows31FilesMigration( DWORD x1 )
578 FIXME(advapi,"(%ld):stub\n",x1);
582 /******************************************************************************
583 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.265]
592 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
595 FIXME(advapi,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
599 /******************************************************************************
600 * LsaOpenPolicy [ADVAPI32.200]
609 LsaOpenPolicy( DWORD x1, DWORD x2, DWORD x3, DWORD x4 )
611 FIXME(advapi,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
612 return 0xc0000000; /* generic error */
615 /******************************************************************************
616 * NotifyBootConfigStatus [ADVAPI32.97]
622 NotifyBootConfigStatus( DWORD x1 )
624 FIXME(advapi,"(0x%08lx):stub\n",x1);
628 /******************************************************************************
629 * GetSecurityDescriptorControl32 [ADVAPI32]
632 BOOL32 GetSecurityDescriptorControl32 ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
633 /* fixme: PSECURITY_DESCRIPTOR_CONTROL*/ LPVOID pControl, LPDWORD lpdwRevision)
634 { FIXME(advapi,"(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
638 /******************************************************************************
639 * RevertToSelf [ADVAPI32.180]
647 FIXME(advapi,"(), stub\n");
651 /******************************************************************************
652 * ImpersonateSelf [ADVAPI32.71]
655 ImpersonateSelf32(DWORD/*SECURITY_IMPERSONATION_LEVEL*/ ImpersonationLevel)
657 FIXME(advapi, "(%08lx), stub\n", ImpersonationLevel);
662 AccessCheck32(PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE32 ClientToken, DWORD DesiredAccess, LPVOID/*LPGENERIC_MAPPING*/ GenericMapping, LPVOID/*LPPRIVILEGE_SET*/ PrivilegeSet, LPDWORD PrivilegeSetLength, LPDWORD GrantedAccess, LPBOOL32 AccessStatus)
664 FIXME(advapi, "(%p, %04x, %08lx, %p, %p, %p, %p, %p), stub\n", pSecurityDescriptor, ClientToken, DesiredAccess, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus);
665 *AccessStatus = TRUE;