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