Added missing string.h include.
[wine.git] / dlls / advapi32 / security.c
blobde7b42a3121b6b83bec05cc8ad1dcb9b51916362
1 /*
2 * dlls/advapi32/security.c
3 */
4 #include <string.h>
6 #include "wintypes.h"
7 #include "winreg.h"
8 #include "winerror.h"
9 #include "heap.h"
10 #include "ntdll.h"
11 #include "debug.h"
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
32 * PARAMS
33 * ProcessHandle [I] Handle to process
34 * DesiredAccess [I] Desired access to process
35 * TokenHandle [O] Pointer to handle of open access token
37 * RETURNS STD
39 BOOL32 WINAPI
40 OpenProcessToken( HANDLE32 ProcessHandle, DWORD DesiredAccess,
41 HANDLE32 *TokenHandle )
43 FIXME(advapi,"(%08x,%08lx,%p): stub\n",ProcessHandle,DesiredAccess,
44 TokenHandle);
45 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
46 return FALSE;
49 /******************************************************************************
50 * OpenThreadToken [ADVAPI32.114]
52 * PARAMS
53 * thread []
54 * desiredaccess []
55 * openasself []
56 * thandle []
58 BOOL32 WINAPI
59 OpenThreadToken( HANDLE32 thread, DWORD desiredaccess, BOOL32 openasself,
60 HANDLE32 *thandle )
62 FIXME(advapi,"(%08x,%08lx,%d,%p): stub!\n",
63 thread,desiredaccess,openasself,thandle);
64 *thandle = 0; /* FIXME ... well, store something in there ;) */
65 return TRUE;
69 /******************************************************************************
70 * LookupPrivilegeValue32A [ADVAPI32.92]
72 BOOL32 WINAPI
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);
80 return ret;
83 /******************************************************************************
84 * LookupPrivilegeValue32W [ADVAPI32.93]
85 * Retrieves LUID used on a system to represent the privilege name.
87 * NOTES
88 * lpLuid should be PLUID
90 * PARAMS
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
95 * RETURNS STD
97 BOOL32 WINAPI
98 LookupPrivilegeValue32W( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
100 FIXME(advapi,"(%s,%s,%p): stub\n",debugstr_w(lpSystemName),
101 debugstr_w(lpName), lpLuid);
102 return TRUE;
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
109 * privileges
111 BOOL32 WINAPI
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));
118 return TRUE;
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
126 * privileges
128 * PARAMS
129 * lpFileName []
130 * RequestedInformation []
131 * pSecurityDescriptor []
132 * nLength []
133 * lpnLengthNeeded []
135 BOOL32 WINAPI
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) );
142 return TRUE;
146 /******************************************************************************
147 * AdjustTokenPrivileges [ADVAPI32.10]
149 * PARAMS
150 * TokenHandle []
151 * DisableAllPrivileges []
152 * NewState []
153 * BufferLength []
154 * PreviousState []
155 * ReturnLength []
157 BOOL32 WINAPI
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);
163 return FALSE;
166 /******************************************************************************
167 * CopySid [ADVAPI32.24]
169 * PARAMS
170 * nDestinationSidLength []
171 * pDestinationSid []
172 * pSourceSid []
174 BOOL32 WINAPI
175 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
178 if (!IsValidSid(pSourceSid))
179 return FALSE;
181 if (nDestinationSidLength < GetLengthSid(pSourceSid))
182 return FALSE;
184 memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
186 return TRUE;
189 /******************************************************************************
190 * IsValidSid [ADVAPI32.80]
192 * PARAMS
193 * pSid []
195 BOOL32 WINAPI
196 IsValidSid( PSID pSid )
198 if (!pSid || pSid->Revision != SID_REVISION)
199 return FALSE;
201 return TRUE;
204 /******************************************************************************
205 * EqualSid [ADVAPI32.40]
207 * PARAMS
208 * pSid1 []
209 * pSid2 []
211 BOOL32 WINAPI
212 EqualSid( PSID pSid1, PSID pSid2 )
214 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
215 return FALSE;
217 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
218 return FALSE;
220 if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
221 return FALSE;
223 return TRUE;
226 /******************************************************************************
227 * EqualPrefixSid [ADVAPI32.39]
229 BOOL32 WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2) {
230 if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
231 return FALSE;
233 if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
234 return FALSE;
236 if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
237 != 0)
238 return FALSE;
240 return TRUE;
243 /******************************************************************************
244 * GetSidLengthRequired [ADVAPI32.63]
246 * PARAMS
247 * nSubAuthorityCount []
249 DWORD WINAPI
250 GetSidLengthRequired( BYTE nSubAuthorityCount )
252 return sizeof (SID) + (nSubAuthorityCount - 1) * sizeof (DWORD);
255 /******************************************************************************
256 * GetTokenInformation [ADVAPI32.66]
258 * PARAMS
259 * token []
260 * tokeninfoclass []
261 * tokeninfo []
262 * tokeninfolength []
263 * retlen []
265 * FIXME
266 * tokeninfoclas should be TOKEN_INFORMATION_CLASS
268 BOOL32 WINAPI
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);
274 return FALSE;
277 /******************************************************************************
278 * AllocateAndInitializeSid [ADVAPI32.11]
280 * PARAMS
281 * pIdentifierAuthority []
282 * nSubAuthorityCount []
283 * nSubAuthority0 []
284 * nSubAuthority1 []
285 * nSubAuthority2 []
286 * nSubAuthority3 []
287 * nSubAuthority4 []
288 * nSubAuthority5 []
289 * nSubAuthority6 []
290 * nSubAuthority7 []
291 * pSid []
293 BOOL32 WINAPI
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,
300 PSID *pSid )
302 if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
303 GetSidLengthRequired(nSubAuthorityCount))))
304 return FALSE;
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;
328 return TRUE;
331 /******************************************************************************
332 * FreeSid [ADVAPI32.42]
334 * PARAMS
335 * pSid []
337 VOID* WINAPI
338 FreeSid( PSID pSid )
340 HeapFree( GetProcessHeap(), 0, pSid );
341 return NULL;
344 /******************************************************************************
345 * InitializeSecurityDescriptor [ADVAPI32.73]
347 * PARAMS
348 * pDescr []
349 * revision []
351 BOOL32 WINAPI
352 InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
353 DWORD revision )
355 TRACE (security, "(%p,%lx): stub\n", pDescr, revision);
356 ZeroMemory (pDescr, sizeof (SECURITY_DESCRIPTOR));
357 pDescr->Revision = revision;
358 return TRUE;
361 /******************************************************************************
362 * GetSecurityDescriptorLength [ADVAPI32.55]
364 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
366 FIXME(security, "(%p), stub\n", pDescr);
367 return 0;
370 /******************************************************************************
371 * GetSecurityDescriptorOwner [ADVAPI32.56]
373 * PARAMS
374 * pOwner []
375 * lpbOwnerDefaulted []
377 BOOL32 WINAPI
378 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
379 LPBOOL32 lpbOwnerDefaulted )
381 FIXME(security, "(%p,%p,%p), stub\n", pDescr,pOwner,lpbOwnerDefaulted);
382 *lpbOwnerDefaulted = TRUE;
383 return 0;
386 /******************************************************************************
387 * GetSecurityDescriptorGroup [ADVAPI32.54]
389 * PARAMS
390 * pGroup []
391 * lpbOwnerDefaulted []
393 BOOL32 WINAPI
394 GetSecurityDescriptorGroup( SECURITY_DESCRIPTOR *pDescr, PSID *pGroup,
395 LPBOOL32 lpbOwnerDefaulted )
397 FIXME(security, "(%p,%p,%p), stub\n", pDescr,pGroup,lpbOwnerDefaulted);
398 *lpbOwnerDefaulted = TRUE;
399 return 0;
402 /******************************************************************************
403 * InitializeSid [ADVAPI32.74]
405 * PARAMS
406 * pIdentifierAuthority []
408 BOOL32 WINAPI
409 InitializeSid (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
410 BYTE nSubAuthorityCount)
412 int i;
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;
423 return TRUE;
426 /******************************************************************************
427 * GetSidIdentifierAuthority [ADVAPI32.62]
429 * PARAMS
430 * pSid []
432 PSID_IDENTIFIER_AUTHORITY WINAPI
433 GetSidIdentifierAuthority( PSID pSid )
435 return &pSid->IdentifierAuthority;
438 /******************************************************************************
439 * GetSidSubAuthority [ADVAPI32.64]
441 * PARAMS
442 * pSid []
443 * nSubAuthority []
445 DWORD * WINAPI
446 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
448 return &pSid->SubAuthority[nSubAuthority];
451 /******************************************************************************
452 * GetSidSubAuthorityCount [ADVAPI32.65]
454 * PARAMS
455 * pSid []
457 BYTE * WINAPI
458 GetSidSubAuthorityCount (PSID pSid)
460 return &pSid->SubAuthorityCount;
463 /******************************************************************************
464 * GetLengthSid [ADVAPI32.48]
466 * PARAMS
467 * pSid []
469 DWORD WINAPI
470 GetLengthSid (PSID pSid)
472 return GetSidLengthRequired( * GetSidSubAuthorityCount(pSid) );
475 /******************************************************************************
476 * IsValidSecurityDescriptor [ADVAPI32.79]
478 * PARAMS
479 * lpsecdesc []
481 BOOL32 WINAPI
482 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR lpsecdesc )
484 FIXME(advapi,"(%p):stub\n",lpsecdesc);
485 return TRUE;
488 /******************************************************************************
489 * LookupAccountSid32A [ADVAPI32.86]
491 BOOL32 WINAPI
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);
499 return FALSE;
502 /******************************************************************************
503 * LookupAccountSid32W [ADVAPI32.87]
505 * PARAMS
506 * system []
507 * sid []
508 * account []
509 * accountSize []
510 * domain []
511 * domainSize []
512 * name_use []
514 BOOL32 WINAPI
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);
522 return FALSE;
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));
534 return TRUE;
537 /******************************************************************************
538 * SetFileSecurity32W [ADVAPI32.183]
539 * Sets the security of a file or directory
541 * PARAMS
542 * lpFileName []
543 * RequestedInformation []
544 * pSecurityDescriptor []
546 BOOL32 WINAPI
547 SetFileSecurity32W( LPCWSTR lpFileName,
548 SECURITY_INFORMATION RequestedInformation,
549 PSECURITY_DESCRIPTOR pSecurityDescriptor )
551 FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) );
552 return TRUE;
555 /******************************************************************************
556 * MakeSelfRelativeSD [ADVAPI32.95]
558 * PARAMS
559 * lpabssecdesc []
560 * lpselfsecdesc []
561 * lpbuflen []
563 BOOL32 WINAPI
564 MakeSelfRelativeSD( PSECURITY_DESCRIPTOR lpabssecdesc,
565 PSECURITY_DESCRIPTOR lpselfsecdesc, LPDWORD lpbuflen )
567 FIXME(advapi,"(%p,%p,%p),stub!\n",lpabssecdesc,lpselfsecdesc,lpbuflen);
568 return TRUE;
571 /******************************************************************************
572 * QueryWindows31FilesMigration [ADVAPI32.266]
574 * PARAMS
575 * x1 []
577 BOOL32 WINAPI
578 QueryWindows31FilesMigration( DWORD x1 )
580 FIXME(advapi,"(%ld):stub\n",x1);
581 return TRUE;
584 /******************************************************************************
585 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.265]
587 * PARAMS
588 * x1 []
589 * x2 []
590 * x3 []
591 * x4 []
593 BOOL32 WINAPI
594 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
595 DWORD x4 )
597 FIXME(advapi,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
598 return TRUE;
601 /******************************************************************************
602 * LsaOpenPolicy [ADVAPI32.200]
604 * PARAMS
605 * x1 []
606 * x2 []
607 * x3 []
608 * x4 []
610 BOOL32 WINAPI
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]
620 * PARAMS
621 * x1 []
623 BOOL32 WINAPI
624 NotifyBootConfigStatus( DWORD x1 )
626 FIXME(advapi,"(0x%08lx):stub\n",x1);
627 return 1;
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);
637 return 1;
640 /******************************************************************************
641 * RevertToSelf [ADVAPI32.180]
643 * PARAMS
644 * void []
646 BOOL32 WINAPI
647 RevertToSelf( void )
649 FIXME(advapi,"(), stub\n");
650 return TRUE;
653 /******************************************************************************
654 * ImpersonateSelf [ADVAPI32.71]
656 BOOL32 WINAPI
657 ImpersonateSelf32(DWORD/*SECURITY_IMPERSONATION_LEVEL*/ ImpersonationLevel)
659 FIXME(advapi, "(%08lx), stub\n", ImpersonationLevel);
660 return TRUE;
663 BOOL32 WINAPI
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;
668 return TRUE;