Updated debug channels.
[wine] / dlls / ntdll / sec.c
1 /*
2  *      Security functions
3  *
4  *      Copyright 1996-1998 Marcus Meissner
5  */
6
7 #include <stdlib.h>
8 #include <string.h>
9 #include <time.h>
10 #include <ctype.h>
11 #include <math.h>
12 #include "windef.h"
13 #include "winbase.h"
14 #include "wine/exception.h"
15 #include "file.h"
16 #include "winnls.h"
17 #include "debugtools.h"
18 #include "winerror.h"
19 #include "stackframe.h"
20
21 #include "ntddk.h"
22 #include "winreg.h"
23 #include "ntdll_misc.h"
24
25 DEFAULT_DEBUG_CHANNEL(ntdll);
26
27 #define NT_SUCCESS(status) (status == STATUS_SUCCESS)
28
29 /* filter for page-fault exceptions */
30 static WINE_EXCEPTION_FILTER(page_fault)
31 {
32     if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
33         return EXCEPTION_EXECUTE_HANDLER;
34     return EXCEPTION_CONTINUE_SEARCH;
35 }
36
37 /*
38  *      SID FUNCTIONS
39  */
40
41 /******************************************************************************
42  *  RtlAllocateAndInitializeSid         [NTDLL.@]
43  *
44  */
45 BOOLEAN WINAPI RtlAllocateAndInitializeSid (
46         PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
47         BYTE nSubAuthorityCount,
48         DWORD nSubAuthority0, DWORD nSubAuthority1,
49         DWORD nSubAuthority2, DWORD nSubAuthority3,
50         DWORD nSubAuthority4, DWORD nSubAuthority5,
51         DWORD nSubAuthority6, DWORD nSubAuthority7,
52         PSID *pSid )
53 {
54         TRACE("(%p, 0x%04x,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p)\n",
55                 pIdentifierAuthority,nSubAuthorityCount,
56                 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
57                 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid);
58
59         if (!(*pSid = RtlAllocateHeap( GetProcessHeap(), 0, RtlLengthRequiredSid(nSubAuthorityCount))))
60           return FALSE;
61
62         (*pSid)->Revision = SID_REVISION;
63
64         if (pIdentifierAuthority)
65           memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority, sizeof (SID_IDENTIFIER_AUTHORITY));
66         *RtlSubAuthorityCountSid(*pSid) = nSubAuthorityCount;
67
68         if (nSubAuthorityCount > 0)
69           *RtlSubAuthoritySid(*pSid, 0) = nSubAuthority0;
70         if (nSubAuthorityCount > 1)
71           *RtlSubAuthoritySid(*pSid, 1) = nSubAuthority1;
72         if (nSubAuthorityCount > 2)
73           *RtlSubAuthoritySid(*pSid, 2) = nSubAuthority2;
74         if (nSubAuthorityCount > 3)
75           *RtlSubAuthoritySid(*pSid, 3) = nSubAuthority3;
76         if (nSubAuthorityCount > 4)
77           *RtlSubAuthoritySid(*pSid, 4) = nSubAuthority4;
78         if (nSubAuthorityCount > 5)
79           *RtlSubAuthoritySid(*pSid, 5) = nSubAuthority5;
80         if (nSubAuthorityCount > 6)
81           *RtlSubAuthoritySid(*pSid, 6) = nSubAuthority6;
82         if (nSubAuthorityCount > 7)
83           *RtlSubAuthoritySid(*pSid, 7) = nSubAuthority7;
84
85         return STATUS_SUCCESS;
86 }
87 /******************************************************************************
88  *  RtlEqualSid         [NTDLL.@]
89  *
90  */
91 BOOL WINAPI RtlEqualSid( PSID pSid1, PSID pSid2 )
92 {
93     if (!RtlValidSid(pSid1) || !RtlValidSid(pSid2))
94         return FALSE;
95
96     if (*RtlSubAuthorityCountSid(pSid1) != *RtlSubAuthorityCountSid(pSid2))
97         return FALSE;
98
99     if (memcmp(pSid1, pSid2, RtlLengthSid(pSid1)) != 0)
100         return FALSE;
101
102     return TRUE;
103 }
104
105 /******************************************************************************
106  * RtlEqualPrefixSid    [NTDLL.@]
107  */
108 BOOL WINAPI RtlEqualPrefixSid (PSID pSid1, PSID pSid2) 
109 {
110     if (!RtlValidSid(pSid1) || !RtlValidSid(pSid2))
111         return FALSE;
112
113     if (*RtlSubAuthorityCountSid(pSid1) != *RtlSubAuthorityCountSid(pSid2))
114         return FALSE;
115
116     if (memcmp(pSid1, pSid2, RtlLengthRequiredSid(pSid1->SubAuthorityCount - 1)) != 0)
117         return FALSE;
118
119     return TRUE;
120 }
121
122
123 /******************************************************************************
124  *  RtlFreeSid          [NTDLL.@]
125  */
126 DWORD WINAPI RtlFreeSid(PSID pSid) 
127 {
128         TRACE("(%p)\n", pSid);
129         RtlFreeHeap( GetProcessHeap(), 0, pSid );
130         return STATUS_SUCCESS;
131 }
132
133 /**************************************************************************
134  * RtlLengthRequiredSid [NTDLL.@]
135  *
136  * PARAMS
137  *   nSubAuthorityCount []
138  */
139 DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
140 {
141         return (nrofsubauths-1)*sizeof(DWORD) + sizeof(SID);
142 }
143
144 /**************************************************************************
145  *                 RtlLengthSid                         [NTDLL.@]
146  */
147 DWORD WINAPI RtlLengthSid(PSID pSid)
148 {
149         TRACE("sid=%p\n",pSid);
150         if (!pSid) return 0; 
151         return RtlLengthRequiredSid(*RtlSubAuthorityCountSid(pSid));
152 }
153
154 /**************************************************************************
155  *                 RtlInitializeSid                     [NTDLL.@]
156  */
157 BOOL WINAPI RtlInitializeSid(
158         PSID pSid,
159         PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
160         BYTE nSubAuthorityCount)
161 {
162         int i;
163         if (nSubAuthorityCount >= SID_MAX_SUB_AUTHORITIES)
164           return FALSE;
165
166         pSid->Revision = SID_REVISION;
167         pSid->SubAuthorityCount = nSubAuthorityCount;
168         if (pIdentifierAuthority)
169           memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority, sizeof (SID_IDENTIFIER_AUTHORITY));
170
171         for (i = 0; i < nSubAuthorityCount; i++)
172           *RtlSubAuthoritySid(pSid, i) = 0;
173
174         return TRUE;
175 }
176
177 /**************************************************************************
178  *                 RtlSubAuthoritySid                   [NTDLL.@]
179  *
180  * PARAMS
181  *   pSid          []
182  *   nSubAuthority []
183  */
184 LPDWORD WINAPI RtlSubAuthoritySid( PSID pSid, DWORD nSubAuthority )
185 {
186         return &(pSid->SubAuthority[nSubAuthority]);
187 }
188
189 /**************************************************************************
190  * RtlIdentifierAuthoritySid    [NTDLL.@]
191  *
192  * PARAMS
193  *   pSid []
194  */
195 PSID_IDENTIFIER_AUTHORITY WINAPI RtlIdentifierAuthoritySid( PSID pSid )
196 {
197         return &(pSid->IdentifierAuthority);
198 }
199
200 /**************************************************************************
201  *                 RtlSubAuthorityCountSid              [NTDLL.@]
202  *
203  * PARAMS
204  *   pSid          []
205  *   nSubAuthority []
206  */
207 LPBYTE WINAPI RtlSubAuthorityCountSid(PSID pSid)
208 {
209         return &(pSid->SubAuthorityCount);
210 }
211
212 /**************************************************************************
213  *                 RtlCopySid                           [NTDLL.@]
214  */
215 DWORD WINAPI RtlCopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
216 {
217         if (!pSourceSid || !RtlValidSid(pSourceSid) ||
218             (nDestinationSidLength < RtlLengthSid(pSourceSid)))
219           return FALSE;
220
221         if (nDestinationSidLength < (pSourceSid->SubAuthorityCount*4+8))
222           return FALSE;
223
224         memmove(pDestinationSid, pSourceSid, pSourceSid->SubAuthorityCount*4+8);
225         return TRUE;
226 }
227 /******************************************************************************
228  * RtlValidSid [NTDLL.@]
229  *
230  * PARAMS
231  *   pSid []
232  */
233 BOOL WINAPI
234 RtlValidSid( PSID pSid )
235 {
236     BOOL ret;
237     __TRY
238     {
239         ret = TRUE;
240         if (!pSid || pSid->Revision != SID_REVISION ||
241             pSid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES)
242         {
243             ret = FALSE;
244         }
245     }
246     __EXCEPT(page_fault)
247     {
248         WARN("(%p): invalid pointer!\n", pSid);
249         return FALSE;
250     }
251     __ENDTRY
252     return ret;
253 }
254
255
256 /*
257  *      security descriptor functions
258  */
259
260 /**************************************************************************
261  * RtlCreateSecurityDescriptor                  [NTDLL.@]
262  *
263  * RETURNS:
264  *  0 success, 
265  *  STATUS_INVALID_OWNER, STATUS_PRIVILEGE_NOT_HELD, STATUS_NO_INHERITANCE,
266  *  STATUS_NO_MEMORY 
267  */
268 NTSTATUS WINAPI RtlCreateSecurityDescriptor(
269         PSECURITY_DESCRIPTOR lpsd,
270         DWORD rev)
271 {
272         if (rev!=SECURITY_DESCRIPTOR_REVISION)
273                 return STATUS_UNKNOWN_REVISION;
274         memset(lpsd,'\0',sizeof(*lpsd));
275         lpsd->Revision = SECURITY_DESCRIPTOR_REVISION;
276         return STATUS_SUCCESS;
277 }
278 /**************************************************************************
279  * RtlValidSecurityDescriptor                   [NTDLL.@]
280  *
281  */
282 NTSTATUS WINAPI RtlValidSecurityDescriptor(
283         PSECURITY_DESCRIPTOR SecurityDescriptor)
284 {
285         if ( ! SecurityDescriptor )
286                 return STATUS_INVALID_SECURITY_DESCR;
287         if ( SecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION )
288                 return STATUS_UNKNOWN_REVISION;
289
290         return STATUS_SUCCESS;
291 }
292
293 /**************************************************************************
294  *  RtlLengthSecurityDescriptor                 [NTDLL.@]
295  */
296 ULONG WINAPI RtlLengthSecurityDescriptor(
297         PSECURITY_DESCRIPTOR SecurityDescriptor)
298 {
299         ULONG Size;
300         Size = SECURITY_DESCRIPTOR_MIN_LENGTH;
301         if ( SecurityDescriptor == NULL )
302                 return 0;
303
304         if ( SecurityDescriptor->Owner != NULL )
305                 Size += SecurityDescriptor->Owner->SubAuthorityCount;
306         if ( SecurityDescriptor->Group != NULL )
307                 Size += SecurityDescriptor->Group->SubAuthorityCount;
308
309
310         if ( SecurityDescriptor->Sacl != NULL )
311                 Size += SecurityDescriptor->Sacl->AclSize;
312         if ( SecurityDescriptor->Dacl != NULL )
313                 Size += SecurityDescriptor->Dacl->AclSize;
314
315         return Size;
316 }
317
318 /******************************************************************************
319  *  RtlGetDaclSecurityDescriptor                [NTDLL.@]
320  *
321  */
322 NTSTATUS WINAPI RtlGetDaclSecurityDescriptor(
323         IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
324         OUT PBOOLEAN lpbDaclPresent,
325         OUT PACL *pDacl,
326         OUT PBOOLEAN lpbDaclDefaulted)
327 {
328         TRACE("(%p,%p,%p,%p)\n",
329         pSecurityDescriptor, lpbDaclPresent, *pDacl, lpbDaclDefaulted);
330
331         if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
332           return STATUS_UNKNOWN_REVISION ;
333
334         if ( (*lpbDaclPresent = (SE_DACL_PRESENT & pSecurityDescriptor->Control) ? 1 : 0) )
335         {
336           if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
337           { *pDacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Dacl);
338           }
339           else
340           { *pDacl = pSecurityDescriptor->Dacl;
341           }
342         }
343
344         *lpbDaclDefaulted = (( SE_DACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
345         
346         return STATUS_SUCCESS;
347 }
348
349 /**************************************************************************
350  *  RtlSetDaclSecurityDescriptor                [NTDLL.@]
351  */
352 NTSTATUS WINAPI RtlSetDaclSecurityDescriptor (
353         PSECURITY_DESCRIPTOR lpsd,
354         BOOLEAN daclpresent,
355         PACL dacl,
356         BOOLEAN dacldefaulted )
357 {
358         if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
359                 return STATUS_UNKNOWN_REVISION;
360         if (lpsd->Control & SE_SELF_RELATIVE)
361                 return STATUS_INVALID_SECURITY_DESCR;
362
363         if (!daclpresent) 
364         {       lpsd->Control &= ~SE_DACL_PRESENT;
365                 return TRUE;
366         }
367
368         lpsd->Control |= SE_DACL_PRESENT;
369         lpsd->Dacl = dacl;
370
371         if (dacldefaulted)
372                 lpsd->Control |= SE_DACL_DEFAULTED;
373         else
374                 lpsd->Control &= ~SE_DACL_DEFAULTED;
375
376         return STATUS_SUCCESS;
377 }
378
379 /******************************************************************************
380  *  RtlGetSaclSecurityDescriptor                [NTDLL.@]
381  *
382  */
383 NTSTATUS WINAPI RtlGetSaclSecurityDescriptor(
384         IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
385         OUT PBOOLEAN lpbSaclPresent,
386         OUT PACL *pSacl,
387         OUT PBOOLEAN lpbSaclDefaulted)
388 {
389         TRACE("(%p,%p,%p,%p)\n",
390         pSecurityDescriptor, lpbSaclPresent, *pSacl, lpbSaclDefaulted);
391
392         if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
393           return STATUS_UNKNOWN_REVISION ;
394
395         if ( (*lpbSaclPresent = (SE_SACL_PRESENT & pSecurityDescriptor->Control) ? 1 : 0) )
396         {
397           if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
398           { *pSacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Sacl);
399           }
400           else
401           { *pSacl = pSecurityDescriptor->Sacl;
402           }
403         }
404
405         *lpbSaclDefaulted = (( SE_SACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
406         
407         return STATUS_SUCCESS;
408 }
409
410 /**************************************************************************
411  * RtlSetSaclSecurityDescriptor                 [NTDLL.@]
412  */
413 NTSTATUS WINAPI RtlSetSaclSecurityDescriptor (
414         PSECURITY_DESCRIPTOR lpsd,
415         BOOLEAN saclpresent,
416         PACL sacl,
417         BOOLEAN sacldefaulted)
418 {
419         if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
420                 return STATUS_UNKNOWN_REVISION;
421         if (lpsd->Control & SE_SELF_RELATIVE)
422                 return STATUS_INVALID_SECURITY_DESCR;
423         if (!saclpresent) {
424                 lpsd->Control &= ~SE_SACL_PRESENT;
425                 return 0;
426         }
427         lpsd->Control |= SE_SACL_PRESENT;
428         lpsd->Sacl = sacl;
429         if (sacldefaulted)
430                 lpsd->Control |= SE_SACL_DEFAULTED;
431         else
432                 lpsd->Control &= ~SE_SACL_DEFAULTED;
433         return STATUS_SUCCESS;
434 }
435
436 /**************************************************************************
437  * RtlGetOwnerSecurityDescriptor                [NTDLL.@]
438  */
439 NTSTATUS WINAPI RtlGetOwnerSecurityDescriptor(
440         PSECURITY_DESCRIPTOR SecurityDescriptor,
441         PSID *Owner,
442         PBOOLEAN OwnerDefaulted)
443 {
444         if ( !SecurityDescriptor  || !Owner || !OwnerDefaulted )
445                 return STATUS_INVALID_PARAMETER;
446
447         *Owner = SecurityDescriptor->Owner;
448         if ( *Owner != NULL )  {
449                 if ( SecurityDescriptor->Control & SE_OWNER_DEFAULTED )
450                         *OwnerDefaulted = TRUE;
451                 else
452                         *OwnerDefaulted = FALSE;
453         }
454         return STATUS_SUCCESS;
455 }
456
457 /**************************************************************************
458  *                 RtlSetOwnerSecurityDescriptor                [NTDLL.@]
459  */
460 NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(
461         PSECURITY_DESCRIPTOR lpsd,
462         PSID owner,
463         BOOLEAN ownerdefaulted)
464 {
465         if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
466                 return STATUS_UNKNOWN_REVISION;
467         if (lpsd->Control & SE_SELF_RELATIVE)
468                 return STATUS_INVALID_SECURITY_DESCR;
469
470         lpsd->Owner = owner;
471         if (ownerdefaulted)
472                 lpsd->Control |= SE_OWNER_DEFAULTED;
473         else
474                 lpsd->Control &= ~SE_OWNER_DEFAULTED;
475         return STATUS_SUCCESS;
476 }
477
478 /**************************************************************************
479  *                 RtlSetGroupSecurityDescriptor                [NTDLL.@]
480  */
481 NTSTATUS WINAPI RtlSetGroupSecurityDescriptor (
482         PSECURITY_DESCRIPTOR lpsd,
483         PSID group,
484         BOOLEAN groupdefaulted)
485 {
486         if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
487                 return STATUS_UNKNOWN_REVISION;
488         if (lpsd->Control & SE_SELF_RELATIVE)
489                 return STATUS_INVALID_SECURITY_DESCR;
490
491         lpsd->Group = group;
492         if (groupdefaulted)
493                 lpsd->Control |= SE_GROUP_DEFAULTED;
494         else
495                 lpsd->Control &= ~SE_GROUP_DEFAULTED;
496         return STATUS_SUCCESS;
497 }
498 /**************************************************************************
499  *                 RtlGetGroupSecurityDescriptor                [NTDLL.@]
500  */
501 NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(
502         PSECURITY_DESCRIPTOR SecurityDescriptor,
503         PSID *Group,
504         PBOOLEAN GroupDefaulted)
505 {
506         if ( !SecurityDescriptor || !Group || !GroupDefaulted )
507                 return STATUS_INVALID_PARAMETER;
508
509         *Group = SecurityDescriptor->Group;
510         if ( *Group != NULL )  {
511                 if ( SecurityDescriptor->Control & SE_GROUP_DEFAULTED )
512                         *GroupDefaulted = TRUE;
513                 else
514                         *GroupDefaulted = FALSE;
515         }
516         return STATUS_SUCCESS;
517
518
519 /**************************************************************************
520  *                 RtlMakeSelfRelativeSD                [NTDLL.@]
521  */
522 NTSTATUS WINAPI RtlMakeSelfRelativeSD(
523         IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
524         IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
525         IN OUT LPDWORD lpdwBufferLength)
526 {
527         FIXME("(%p,%p,%p(%lu))\n", pAbsoluteSecurityDescriptor,
528         pSelfRelativeSecurityDescriptor, lpdwBufferLength,*lpdwBufferLength);
529         return STATUS_SUCCESS;
530 }
531
532 /*
533  *      access control list's
534  */
535
536 /**************************************************************************
537  *                 RtlCreateAcl                         [NTDLL.@]
538  *
539  * NOTES
540  *    This should return NTSTATUS
541  */
542 NTSTATUS WINAPI RtlCreateAcl(PACL acl,DWORD size,DWORD rev)
543 {
544         TRACE("%p 0x%08lx 0x%08lx\n", acl, size, rev);
545
546         if (rev!=ACL_REVISION)
547                 return STATUS_INVALID_PARAMETER;
548         if (size<sizeof(ACL))
549                 return STATUS_BUFFER_TOO_SMALL;
550         if (size>0xFFFF)
551                 return STATUS_INVALID_PARAMETER;
552
553         memset(acl,'\0',sizeof(ACL));
554         acl->AclRevision        = rev;
555         acl->AclSize            = size;
556         acl->AceCount           = 0;
557         return 0;
558 }
559
560 /**************************************************************************
561  *                 RtlFirstFreeAce                      [NTDLL.@]
562  * looks for the AceCount+1 ACE, and if it is still within the alloced
563  * ACL, return a pointer to it
564  */
565 BOOLEAN WINAPI RtlFirstFreeAce(
566         PACL acl,
567         PACE_HEADER *x)
568 {
569         PACE_HEADER     ace;
570         int             i;
571
572         *x = 0;
573         ace = (PACE_HEADER)(acl+1);
574         for (i=0;i<acl->AceCount;i++) {
575                 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
576                         return 0;
577                 ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
578         }
579         if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
580                 return 0;
581         *x = ace;
582         return 1;
583 }
584
585 /**************************************************************************
586  *                 RtlAddAce                            [NTDLL.@]
587  */
588 NTSTATUS WINAPI RtlAddAce(
589         PACL acl,
590         DWORD rev,
591         DWORD xnrofaces,
592         PACE_HEADER acestart,
593         DWORD acelen)
594 {
595         PACE_HEADER     ace,targetace;
596         int             nrofaces;
597
598         if (acl->AclRevision != ACL_REVISION)
599                 return STATUS_INVALID_PARAMETER;
600         if (!RtlFirstFreeAce(acl,&targetace))
601                 return STATUS_INVALID_PARAMETER;
602         nrofaces=0;ace=acestart;
603         while (((DWORD)ace-(DWORD)acestart)<acelen) {
604                 nrofaces++;
605                 ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
606         }
607         if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
608                 return STATUS_INVALID_PARAMETER;
609         memcpy((LPBYTE)targetace,acestart,acelen);
610         acl->AceCount+=nrofaces;
611         return STATUS_SUCCESS;
612 }
613
614 /******************************************************************************
615  *  RtlAddAccessAllowedAce              [NTDLL.@]
616  */
617 BOOL WINAPI RtlAddAccessAllowedAce(
618         IN OUT PACL pAcl,
619         IN DWORD dwAceRevision,
620         IN DWORD AccessMask,
621         IN PSID pSid)
622 {
623         FIXME("(%p,0x%08lx,0x%08lx,%p),stub!\n",
624         pAcl, dwAceRevision, AccessMask, pSid);
625         return 0;
626 }
627
628 /******************************************************************************
629  *  RtlGetAce           [NTDLL.@]
630  */
631 DWORD WINAPI RtlGetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce ) 
632 {
633         FIXME("(%p,%ld,%p),stub!\n",pAcl,dwAceIndex,pAce);
634         return 0;
635 }
636
637 /*
638  *      misc
639  */
640
641 /******************************************************************************
642  *  RtlAdjustPrivilege          [NTDLL.@]
643  */
644 DWORD WINAPI RtlAdjustPrivilege(DWORD x1,DWORD x2,DWORD x3,DWORD x4) 
645 {
646         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
647         return 0;
648 }
649
650 /******************************************************************************
651  *  RtlImpersonateSelf          [NTDLL.@]
652  */
653 BOOL WINAPI
654 RtlImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
655 {
656         FIXME("(%08x), stub\n", ImpersonationLevel);
657         return TRUE;
658 }
659
660 /******************************************************************************
661  *  NtAccessCheck               [NTDLL.@]
662  */
663 NTSTATUS WINAPI 
664 NtAccessCheck(
665         IN PSECURITY_DESCRIPTOR SecurityDescriptor,
666         IN HANDLE ClientToken,
667         IN ACCESS_MASK DesiredAccess,
668         IN PGENERIC_MAPPING GenericMapping,
669         OUT PPRIVILEGE_SET PrivilegeSet,
670         OUT PULONG ReturnLength,
671         OUT PULONG GrantedAccess,
672         OUT PBOOLEAN AccessStatus)
673 {
674         FIXME("(%p, %04x, %08lx, %p, %p, %p, %p, %p), stub\n",
675           SecurityDescriptor, ClientToken, DesiredAccess, GenericMapping, 
676           PrivilegeSet, ReturnLength, GrantedAccess, AccessStatus);
677         *AccessStatus = TRUE;
678         return STATUS_SUCCESS;
679 }
680
681 /******************************************************************************
682  *  NtSetSecurityObject         [NTDLL.@]
683  */
684 NTSTATUS WINAPI
685 NtSetSecurityObject(
686         IN HANDLE Handle,
687         IN SECURITY_INFORMATION SecurityInformation,
688         IN PSECURITY_DESCRIPTOR SecurityDescriptor) 
689 {
690         FIXME("0x%08x 0x%08lx %p\n", Handle, SecurityInformation, SecurityDescriptor);
691         return STATUS_SUCCESS;
692 }
693
694 /******************************************************************************
695  * RtlGetControlSecurityDescriptor (NTDLL.@)
696  */
697
698 NTSTATUS WINAPI RtlGetControlSecurityDescriptor(
699         PSECURITY_DESCRIPTOR  pSecurityDescriptor,
700         PSECURITY_DESCRIPTOR_CONTROL pControl,
701         LPDWORD lpdwRevision)
702 {
703         FIXME("(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
704         return STATUS_SUCCESS;
705 }               
706
707 /******************************************************************************
708  * RtlConvertSidToUnicodeString (NTDLL.@)
709  */
710 NTSTATUS WINAPI RtlConvertSidToUnicodeString(
711        PUNICODE_STRING UnicodeSID,
712        PSID *pSid)
713 {
714 /*      LPSTR GenSID = "S-1-5-21-0000000000-000000000-0000000000-500"; */
715
716         LPSTR GenSID = ".Default";      /* usually the returned SID is used to */
717                                         /* access  "\\REGISTRY\\USER\\.DEFAULT" */
718
719         ANSI_STRING AnsiStr;
720
721         FIXME("(%p %p)\n", UnicodeSID, pSid);
722         if (UnicodeSID)
723             TRACE("%p(<OUT>) (%u %u)\n",
724                   UnicodeSID->Buffer, UnicodeSID->Length, UnicodeSID->MaximumLength);
725
726         RtlInitAnsiString(&AnsiStr, GenSID);
727         return RtlAnsiStringToUnicodeString(UnicodeSID, &AnsiStr, TRUE);
728 }