2 * dlls/advapi32/security.c
13 /* FIXME: move it to a header */
14 BOOL32 WINAPI
IsValidSid (PSID pSid
);
15 BOOL32 WINAPI
EqualSid (PSID pSid1
, PSID pSid2
);
16 BOOL32 WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
);
17 DWORD WINAPI
GetSidLengthRequired (BYTE nSubAuthorityCount
);
18 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
);
19 VOID
* WINAPI
FreeSid(PSID pSid
);
20 BOOL32 WINAPI
InitializeSid (PSID pSid
, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
, BYTE nSubAuthorityCount
);
21 PSID_IDENTIFIER_AUTHORITY WINAPI
GetSidIdentifierAuthority(PSID pSid
);
22 DWORD
* WINAPI
GetSidSubAuthority(PSID pSid
, DWORD nSubAuthority
);
23 BYTE
* WINAPI
GetSidSubAuthorityCount(PSID pSid
);
24 DWORD WINAPI
GetLengthSid(PSID pSid
);
25 BOOL32 WINAPI
CopySid(DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
);
28 /******************************************************************************
29 * OpenProcessToken [ADVAPI32.109]
30 * Opens the access token associated with a process
33 * ProcessHandle [I] Handle to process
34 * DesiredAccess [I] Desired access to process
35 * TokenHandle [O] Pointer to handle of open access token
40 OpenProcessToken( HANDLE32 ProcessHandle
, DWORD DesiredAccess
,
41 HANDLE32
*TokenHandle
)
43 FIXME(advapi
,"(%08x,%08lx,%p): stub\n",ProcessHandle
,DesiredAccess
,
45 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
49 /******************************************************************************
50 * OpenThreadToken [ADVAPI32.114]
59 OpenThreadToken( HANDLE32 thread
, DWORD desiredaccess
, BOOL32 openasself
,
62 FIXME(advapi
,"(%08x,%08lx,%d,%p): stub!\n",
63 thread
,desiredaccess
,openasself
,thandle
);
64 *thandle
= 0; /* FIXME ... well, store something in there ;) */
69 /******************************************************************************
70 * LookupPrivilegeValue32A [ADVAPI32.92]
73 LookupPrivilegeValue32A( LPCSTR lpSystemName
, LPCSTR lpName
, LPVOID lpLuid
)
75 LPWSTR lpSystemNameW
= HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName
);
76 LPWSTR lpNameW
= HEAP_strdupAtoW(GetProcessHeap(), 0, lpName
);
77 BOOL32 ret
= LookupPrivilegeValue32W( lpSystemNameW
, lpNameW
, lpLuid
);
78 HeapFree(GetProcessHeap(), 0, lpNameW
);
79 HeapFree(GetProcessHeap(), 0, lpSystemNameW
);
83 /******************************************************************************
84 * LookupPrivilegeValue32W [ADVAPI32.93]
85 * Retrieves LUID used on a system to represent the privilege name.
88 * lpLuid should be PLUID
91 * lpSystemName [I] Address of string specifying the system
92 * lpName [I] Address of string specifying the privilege
93 * lpLuid [I] Address of locally unique identifier
98 LookupPrivilegeValue32W( LPCWSTR lpSystemName
, LPCWSTR lpName
, LPVOID lpLuid
)
100 FIXME(advapi
,"(%s,%s,%p): stub\n",debugstr_w(lpSystemName
),
101 debugstr_w(lpName
), lpLuid
);
104 /******************************************************************************
105 * GetFileSecurity32A [ADVAPI32.45]
107 * Obtains Specified information about the security of a file or directory
108 * The information obtained is constrained by the callers access rights and
112 GetFileSecurity32A( LPCSTR lpFileName
,
113 SECURITY_INFORMATION RequestedInformation
,
114 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
115 DWORD nLength
, LPDWORD lpnLengthNeeded
)
117 FIXME(advapi
, "(%s) : stub\n", debugstr_a(lpFileName
));
121 /******************************************************************************
122 * GetFileSecurity32W [ADVAPI32.46]
124 * Obtains Specified information about the security of a file or directory
125 * The information obtained is constrained by the callers access rights and
130 * RequestedInformation []
131 * pSecurityDescriptor []
136 GetFileSecurity32W( LPCWSTR lpFileName
,
137 SECURITY_INFORMATION RequestedInformation
,
138 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
139 DWORD nLength
, LPDWORD lpnLengthNeeded
)
141 FIXME(advapi
, "(%s) : stub\n", debugstr_w(lpFileName
) );
146 /******************************************************************************
147 * AdjustTokenPrivileges [ADVAPI32.10]
151 * DisableAllPrivileges []
158 AdjustTokenPrivileges( HANDLE32 TokenHandle
, BOOL32 DisableAllPrivileges
,
159 LPVOID NewState
, DWORD BufferLength
,
160 LPVOID PreviousState
, LPDWORD ReturnLength
)
161 { FIXME(advapi
, "stub\n");
162 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
166 /******************************************************************************
167 * CopySid [ADVAPI32.24]
170 * nDestinationSidLength []
175 CopySid( DWORD nDestinationSidLength
, PSID pDestinationSid
, PSID pSourceSid
)
178 if (!IsValidSid(pSourceSid
))
181 if (nDestinationSidLength
< GetLengthSid(pSourceSid
))
184 memcpy(pDestinationSid
, pSourceSid
, GetLengthSid(pSourceSid
));
189 /******************************************************************************
190 * IsValidSid [ADVAPI32.80]
196 IsValidSid( PSID pSid
)
198 if (!pSid
|| pSid
->Revision
!= SID_REVISION
)
204 /******************************************************************************
205 * EqualSid [ADVAPI32.40]
212 EqualSid( PSID pSid1
, PSID pSid2
)
214 if (!IsValidSid(pSid1
) || !IsValidSid(pSid2
))
217 if (*GetSidSubAuthorityCount(pSid1
) != *GetSidSubAuthorityCount(pSid2
))
220 if (memcmp(pSid1
, pSid2
, GetLengthSid(pSid1
)) != 0)
226 /******************************************************************************
227 * EqualPrefixSid [ADVAPI32.39]
229 BOOL32 WINAPI
EqualPrefixSid (PSID pSid1
, PSID pSid2
) {
230 if (!IsValidSid(pSid1
) || !IsValidSid(pSid2
))
233 if (*GetSidSubAuthorityCount(pSid1
) != *GetSidSubAuthorityCount(pSid2
))
236 if (memcmp(pSid1
, pSid2
, GetSidLengthRequired(pSid1
->SubAuthorityCount
- 1))
243 /******************************************************************************
244 * GetSidLengthRequired [ADVAPI32.63]
247 * nSubAuthorityCount []
250 GetSidLengthRequired( BYTE nSubAuthorityCount
)
252 return sizeof (SID
) + (nSubAuthorityCount
- 1) * sizeof (DWORD
);
255 /******************************************************************************
256 * GetTokenInformation [ADVAPI32.66]
266 * tokeninfoclas should be TOKEN_INFORMATION_CLASS
269 GetTokenInformation( HANDLE32 token
, DWORD tokeninfoclass
, LPVOID tokeninfo
,
270 DWORD tokeninfolength
, LPDWORD retlen
)
272 FIXME(advapi
,"(%08x,%ld,%p,%ld,%p): stub\n",
273 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
277 /******************************************************************************
278 * AllocateAndInitializeSid [ADVAPI32.11]
281 * pIdentifierAuthority []
282 * nSubAuthorityCount []
294 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
295 BYTE nSubAuthorityCount
,
296 DWORD nSubAuthority0
, DWORD nSubAuthority1
,
297 DWORD nSubAuthority2
, DWORD nSubAuthority3
,
298 DWORD nSubAuthority4
, DWORD nSubAuthority5
,
299 DWORD nSubAuthority6
, DWORD nSubAuthority7
,
302 if (!(*pSid
= HeapAlloc( GetProcessHeap(), 0,
303 GetSidLengthRequired(nSubAuthorityCount
))))
305 (*pSid
)->Revision
= SID_REVISION
;
306 if (pIdentifierAuthority
)
307 memcpy(&(*pSid
)->IdentifierAuthority
, pIdentifierAuthority
,
308 sizeof (SID_IDENTIFIER_AUTHORITY
));
309 *GetSidSubAuthorityCount(*pSid
) = nSubAuthorityCount
;
311 if (nSubAuthorityCount
> 0)
312 *GetSidSubAuthority(*pSid
, 0) = nSubAuthority0
;
313 if (nSubAuthorityCount
> 1)
314 *GetSidSubAuthority(*pSid
, 1) = nSubAuthority1
;
315 if (nSubAuthorityCount
> 2)
316 *GetSidSubAuthority(*pSid
, 2) = nSubAuthority2
;
317 if (nSubAuthorityCount
> 3)
318 *GetSidSubAuthority(*pSid
, 3) = nSubAuthority3
;
319 if (nSubAuthorityCount
> 4)
320 *GetSidSubAuthority(*pSid
, 4) = nSubAuthority4
;
321 if (nSubAuthorityCount
> 5)
322 *GetSidSubAuthority(*pSid
, 5) = nSubAuthority5
;
323 if (nSubAuthorityCount
> 6)
324 *GetSidSubAuthority(*pSid
, 6) = nSubAuthority6
;
325 if (nSubAuthorityCount
> 7)
326 *GetSidSubAuthority(*pSid
, 7) = nSubAuthority7
;
331 /******************************************************************************
332 * FreeSid [ADVAPI32.42]
340 HeapFree( GetProcessHeap(), 0, pSid
);
344 /******************************************************************************
345 * InitializeSecurityDescriptor [ADVAPI32.73]
352 InitializeSecurityDescriptor( SECURITY_DESCRIPTOR
*pDescr
,
355 TRACE (security
, "(%p,%lx): stub\n", pDescr
, revision
);
356 ZeroMemory (pDescr
, sizeof (SECURITY_DESCRIPTOR
));
357 pDescr
->Revision
= revision
;
361 /******************************************************************************
362 * GetSecurityDescriptorLength [ADVAPI32.55]
364 DWORD WINAPI
GetSecurityDescriptorLength( SECURITY_DESCRIPTOR
*pDescr
)
366 FIXME(security
, "(%p), stub\n", pDescr
);
370 /******************************************************************************
371 * GetSecurityDescriptorOwner [ADVAPI32.56]
375 * lpbOwnerDefaulted []
378 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR
*pDescr
, PSID
*pOwner
,
379 LPBOOL32 lpbOwnerDefaulted
)
381 FIXME(security
, "(%p,%p,%p), stub\n", pDescr
,pOwner
,lpbOwnerDefaulted
);
382 *lpbOwnerDefaulted
= TRUE
;
386 /******************************************************************************
387 * GetSecurityDescriptorGroup [ADVAPI32.54]
391 * lpbOwnerDefaulted []
394 GetSecurityDescriptorGroup( SECURITY_DESCRIPTOR
*pDescr
, PSID
*pGroup
,
395 LPBOOL32 lpbOwnerDefaulted
)
397 FIXME(security
, "(%p,%p,%p), stub\n", pDescr
,pGroup
,lpbOwnerDefaulted
);
398 *lpbOwnerDefaulted
= TRUE
;
402 /******************************************************************************
403 * InitializeSid [ADVAPI32.74]
406 * pIdentifierAuthority []
409 InitializeSid (PSID pSid
, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
410 BYTE nSubAuthorityCount
)
414 pSid
->Revision
= SID_REVISION
;
415 if (pIdentifierAuthority
)
416 memcpy(&pSid
->IdentifierAuthority
, pIdentifierAuthority
,
417 sizeof (SID_IDENTIFIER_AUTHORITY
));
418 *GetSidSubAuthorityCount(pSid
) = nSubAuthorityCount
;
420 for (i
= 0; i
< nSubAuthorityCount
; i
++)
421 *GetSidSubAuthority(pSid
, i
) = 0;
426 /******************************************************************************
427 * GetSidIdentifierAuthority [ADVAPI32.62]
432 PSID_IDENTIFIER_AUTHORITY WINAPI
433 GetSidIdentifierAuthority( PSID pSid
)
435 return &pSid
->IdentifierAuthority
;
438 /******************************************************************************
439 * GetSidSubAuthority [ADVAPI32.64]
446 GetSidSubAuthority( PSID pSid
, DWORD nSubAuthority
)
448 return &pSid
->SubAuthority
[nSubAuthority
];
451 /******************************************************************************
452 * GetSidSubAuthorityCount [ADVAPI32.65]
458 GetSidSubAuthorityCount (PSID pSid
)
460 return &pSid
->SubAuthorityCount
;
463 /******************************************************************************
464 * GetLengthSid [ADVAPI32.48]
470 GetLengthSid (PSID pSid
)
472 return GetSidLengthRequired( * GetSidSubAuthorityCount(pSid
) );
475 /******************************************************************************
476 * IsValidSecurityDescriptor [ADVAPI32.79]
482 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR lpsecdesc
)
484 FIXME(advapi
,"(%p):stub\n",lpsecdesc
);
488 /******************************************************************************
489 * LookupAccountSid32A [ADVAPI32.86]
492 LookupAccountSid32A( LPCSTR system
, PSID sid
, LPCSTR account
,
493 LPDWORD accountSize
, LPCSTR domain
, LPDWORD domainSize
,
494 PSID_NAME_USE name_use
)
496 FIXME(security
,"(%s,%p,%p,%p,%p,%p,%p): stub\n",
497 system
,sid
,account
,accountSize
,domain
,domainSize
,name_use
);
498 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
502 /******************************************************************************
503 * LookupAccountSid32W [ADVAPI32.87]
515 LookupAccountSid32W( LPCWSTR system
, PSID sid
, LPCWSTR account
,
516 LPDWORD accountSize
, LPCWSTR domain
, LPDWORD domainSize
,
517 PSID_NAME_USE name_use
)
519 FIXME(security
,"(%p,%p,%p,%p,%p,%p,%p): stub\n",
520 system
,sid
,account
,accountSize
,domain
,domainSize
,name_use
);
521 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
525 /******************************************************************************
526 * SetFileSecurity32A [ADVAPI32.182]
527 * Sets the security of a file or directory
529 BOOL32 WINAPI
SetFileSecurity32A( LPCSTR lpFileName
,
530 SECURITY_INFORMATION RequestedInformation
,
531 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
533 FIXME(advapi
, "(%s) : stub\n", debugstr_a(lpFileName
));
537 /******************************************************************************
538 * SetFileSecurity32W [ADVAPI32.183]
539 * Sets the security of a file or directory
543 * RequestedInformation []
544 * pSecurityDescriptor []
547 SetFileSecurity32W( LPCWSTR lpFileName
,
548 SECURITY_INFORMATION RequestedInformation
,
549 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
551 FIXME(advapi
, "(%s) : stub\n", debugstr_w(lpFileName
) );
555 /******************************************************************************
556 * MakeSelfRelativeSD [ADVAPI32.95]
564 MakeSelfRelativeSD( PSECURITY_DESCRIPTOR lpabssecdesc
,
565 PSECURITY_DESCRIPTOR lpselfsecdesc
, LPDWORD lpbuflen
)
567 FIXME(advapi
,"(%p,%p,%p),stub!\n",lpabssecdesc
,lpselfsecdesc
,lpbuflen
);
571 /******************************************************************************
572 * QueryWindows31FilesMigration [ADVAPI32.266]
578 QueryWindows31FilesMigration( DWORD x1
)
580 FIXME(advapi
,"(%ld):stub\n",x1
);
584 /******************************************************************************
585 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.265]
594 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1
, DWORD x2
, DWORD x3
,
597 FIXME(advapi
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1
,x2
,x3
,x4
);
601 /******************************************************************************
602 * LsaOpenPolicy [ADVAPI32.200]
611 LsaOpenPolicy( DWORD x1
, DWORD x2
, DWORD x3
, DWORD x4
)
613 FIXME(advapi
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1
,x2
,x3
,x4
);
614 return 0xc0000000; /* generic error */
617 /******************************************************************************
618 * NotifyBootConfigStatus [ADVAPI32.97]
624 NotifyBootConfigStatus( DWORD x1
)
626 FIXME(advapi
,"(0x%08lx):stub\n",x1
);
630 /******************************************************************************
631 * GetSecurityDescriptorControl32 [ADVAPI32]
634 BOOL32
GetSecurityDescriptorControl32 ( PSECURITY_DESCRIPTOR pSecurityDescriptor
,
635 /* fixme: PSECURITY_DESCRIPTOR_CONTROL*/ LPVOID pControl
, LPDWORD lpdwRevision
)
636 { FIXME(advapi
,"(%p,%p,%p),stub!\n",pSecurityDescriptor
,pControl
,lpdwRevision
);
640 /******************************************************************************
641 * RevertToSelf [ADVAPI32.180]
649 FIXME(advapi
,"(), stub\n");
653 /******************************************************************************
654 * ImpersonateSelf [ADVAPI32.71]
657 ImpersonateSelf32(DWORD
/*SECURITY_IMPERSONATION_LEVEL*/ ImpersonationLevel
)
659 FIXME(advapi
, "(%08lx), stub\n", ImpersonationLevel
);
664 AccessCheck32(PSECURITY_DESCRIPTOR pSecurityDescriptor
, HANDLE32 ClientToken
, DWORD DesiredAccess
, LPVOID
/*LPGENERIC_MAPPING*/ GenericMapping
, LPVOID
/*LPPRIVILEGE_SET*/ PrivilegeSet
, LPDWORD PrivilegeSetLength
, LPDWORD GrantedAccess
, LPBOOL32 AccessStatus
)
666 FIXME(advapi
, "(%p, %04x, %08lx, %p, %p, %p, %p, %p), stub\n", pSecurityDescriptor
, ClientToken
, DesiredAccess
, GenericMapping
, PrivilegeSet
, PrivilegeSetLength
, GrantedAccess
, AccessStatus
);
667 *AccessStatus
= TRUE
;