4 * Copyright 1996-1998 Marcus Meissner
15 #include "wine/winestring.h"
23 #include "stackframe.h"
32 /******************************************************************************
33 * RtlAllocateAndInitializeSid [NTDLL.265]
36 BOOLEAN WINAPI
RtlAllocateAndInitializeSid (PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
37 DWORD nSubAuthorityCount
,DWORD x3
,DWORD x4
,DWORD x5
,DWORD x6
,DWORD x7
,DWORD x8
,DWORD x9
,DWORD x10
, PSID pSid
)
39 FIXME(ntdll
,"(%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p),stub!\n",
40 pIdentifierAuthority
,nSubAuthorityCount
,x3
,x4
,x5
,x6
,x7
,x8
,x9
,x10
,pSid
);
43 /******************************************************************************
44 * RtlEqualSid [NTDLL.352]
47 DWORD WINAPI
RtlEqualSid(DWORD x1
,DWORD x2
)
49 FIXME(ntdll
,"(0x%08lx,0x%08lx),stub!\n", x1
,x2
);
53 /******************************************************************************
54 * RtlFreeSid [NTDLL.376]
56 DWORD WINAPI
RtlFreeSid(DWORD x1
)
58 FIXME(ntdll
,"(0x%08lx),stub!\n", x1
);
62 /**************************************************************************
63 * RtlLengthRequiredSid [NTDLL.427]
65 DWORD WINAPI
RtlLengthRequiredSid(DWORD nrofsubauths
)
67 return sizeof(DWORD
)*nrofsubauths
+sizeof(SID
);
70 /**************************************************************************
71 * RtlLengthSid [NTDLL.429]
73 DWORD WINAPI
RtlLengthSid(PSID sid
)
75 TRACE(ntdll
,"sid=%p\n",sid
);
78 return sizeof(DWORD
)*sid
->SubAuthorityCount
+sizeof(SID
);
81 /**************************************************************************
82 * RtlInitializeSid [NTDLL.410]
84 DWORD WINAPI
RtlInitializeSid(PSID PSID
,PSID_IDENTIFIER_AUTHORITY PSIDauth
,
89 if (a
>=SID_MAX_SUB_AUTHORITIES
)
91 PSID
->SubAuthorityCount
= a
;
92 PSID
->Revision
= SID_REVISION
;
93 memcpy(&(PSID
->IdentifierAuthority
),PSIDauth
,sizeof(SID_IDENTIFIER_AUTHORITY
));
94 return STATUS_SUCCESS
;
97 /**************************************************************************
98 * RtlSubAuthoritySid [NTDLL.497]
100 LPDWORD WINAPI
RtlSubAuthoritySid(PSID PSID
,DWORD nr
)
102 return &(PSID
->SubAuthority
[nr
]);
105 /**************************************************************************
106 * RtlSubAuthorityCountSid [NTDLL.496]
109 LPBYTE WINAPI
RtlSubAuthorityCountSid(PSID PSID
)
111 return ((LPBYTE
)PSID
)+1;
114 /**************************************************************************
115 * RtlCopySid [NTDLL.302]
117 DWORD WINAPI
RtlCopySid(DWORD len
,PSID to
,PSID from
)
120 if (len
<(from
->SubAuthorityCount
*4+8))
121 return STATUS_BUFFER_TOO_SMALL
;
122 memmove(to
,from
,from
->SubAuthorityCount
*4+8);
123 return STATUS_SUCCESS
;
127 * security descriptor functions
130 /**************************************************************************
131 * RtlCreateSecurityDescriptor [NTDLL.313]
135 * STATUS_INVALID_OWNER, STATUS_PRIVILEGE_NOT_HELD, STATUS_NO_INHERITANCE,
138 NTSTATUS WINAPI
RtlCreateSecurityDescriptor(
139 PSECURITY_DESCRIPTOR lpsd
,
142 if (rev
!=SECURITY_DESCRIPTOR_REVISION
)
143 return STATUS_UNKNOWN_REVISION
;
144 memset(lpsd
,'\0',sizeof(*lpsd
));
145 lpsd
->Revision
= SECURITY_DESCRIPTOR_REVISION
;
146 return STATUS_SUCCESS
;
148 /**************************************************************************
149 * RtlValidSecurityDescriptor [NTDLL.313]
152 NTSTATUS WINAPI
RtlValidSecurityDescriptor(
153 PSECURITY_DESCRIPTOR SecurityDescriptor
)
155 if ( ! SecurityDescriptor
)
156 return STATUS_INVALID_SECURITY_DESCR
;
157 if ( SecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION
)
158 return STATUS_UNKNOWN_REVISION
;
160 return STATUS_SUCCESS
;
163 /**************************************************************************
164 * RtlLengthSecurityDescriptor [NTDLL]
166 ULONG WINAPI
RtlLengthSecurityDescriptor(
167 PSECURITY_DESCRIPTOR SecurityDescriptor
)
170 Size
= SECURITY_DESCRIPTOR_MIN_LENGTH
;
171 if ( SecurityDescriptor
== NULL
)
174 if ( SecurityDescriptor
->Owner
!= NULL
)
175 Size
+= SecurityDescriptor
->Owner
->SubAuthorityCount
;
176 if ( SecurityDescriptor
->Group
!= NULL
)
177 Size
+= SecurityDescriptor
->Group
->SubAuthorityCount
;
180 if ( SecurityDescriptor
->Sacl
!= NULL
)
181 Size
+= SecurityDescriptor
->Sacl
->AclSize
;
182 if ( SecurityDescriptor
->Dacl
!= NULL
)
183 Size
+= SecurityDescriptor
->Dacl
->AclSize
;
188 /******************************************************************************
189 * RtlGetDaclSecurityDescriptor [NTDLL]
192 NTSTATUS WINAPI
RtlGetDaclSecurityDescriptor(
193 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
194 OUT PBOOLEAN lpbDaclPresent
,
196 OUT PBOOLEAN lpbDaclDefaulted
)
198 TRACE(ntdll
,"(%p,%p,%p,%p)\n",
199 pSecurityDescriptor
, lpbDaclPresent
, *pDacl
, lpbDaclDefaulted
);
201 if (pSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION
)
202 return STATUS_UNKNOWN_REVISION
;
204 if ( (*lpbDaclPresent
= (SE_DACL_PRESENT
& pSecurityDescriptor
->Control
) ? 1 : 0) )
206 if ( SE_SELF_RELATIVE
& pSecurityDescriptor
->Control
)
207 { *pDacl
= (PACL
) ((LPBYTE
)pSecurityDescriptor
+ (DWORD
)pSecurityDescriptor
->Dacl
);
210 { *pDacl
= pSecurityDescriptor
->Dacl
;
214 *lpbDaclDefaulted
= (( SE_DACL_DEFAULTED
& pSecurityDescriptor
->Control
) ? 1 : 0);
216 return STATUS_SUCCESS
;
219 /**************************************************************************
220 * RtlSetDaclSecurityDescriptor [NTDLL.483]
222 NTSTATUS WINAPI
RtlSetDaclSecurityDescriptor (
223 PSECURITY_DESCRIPTOR lpsd
,
226 BOOLEAN dacldefaulted
)
228 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
229 return STATUS_UNKNOWN_REVISION
;
230 if (lpsd
->Control
& SE_SELF_RELATIVE
)
231 return STATUS_INVALID_SECURITY_DESCR
;
234 { lpsd
->Control
&= ~SE_DACL_PRESENT
;
238 lpsd
->Control
|= SE_DACL_PRESENT
;
242 lpsd
->Control
|= SE_DACL_DEFAULTED
;
244 lpsd
->Control
&= ~SE_DACL_DEFAULTED
;
246 return STATUS_SUCCESS
;
249 /******************************************************************************
250 * RtlGetSaclSecurityDescriptor [NTDLL]
253 NTSTATUS WINAPI
RtlGetSaclSecurityDescriptor(
254 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
255 OUT PBOOLEAN lpbSaclPresent
,
257 OUT PBOOLEAN lpbSaclDefaulted
)
259 TRACE(ntdll
,"(%p,%p,%p,%p)\n",
260 pSecurityDescriptor
, lpbSaclPresent
, *pSacl
, lpbSaclDefaulted
);
262 if (pSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION
)
263 return STATUS_UNKNOWN_REVISION
;
265 if ( (*lpbSaclPresent
= (SE_SACL_PRESENT
& pSecurityDescriptor
->Control
) ? 1 : 0) )
267 if ( SE_SELF_RELATIVE
& pSecurityDescriptor
->Control
)
268 { *pSacl
= (PACL
) ((LPBYTE
)pSecurityDescriptor
+ (DWORD
)pSecurityDescriptor
->Sacl
);
271 { *pSacl
= pSecurityDescriptor
->Sacl
;
275 *lpbSaclDefaulted
= (( SE_SACL_DEFAULTED
& pSecurityDescriptor
->Control
) ? 1 : 0);
277 return STATUS_SUCCESS
;
280 /**************************************************************************
281 * RtlSetSaclSecurityDescriptor [NTDLL.488]
283 NTSTATUS WINAPI
RtlSetSaclSecurityDescriptor (
284 PSECURITY_DESCRIPTOR lpsd
,
287 BOOLEAN sacldefaulted
)
289 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
290 return STATUS_UNKNOWN_REVISION
;
291 if (lpsd
->Control
& SE_SELF_RELATIVE
)
292 return STATUS_INVALID_SECURITY_DESCR
;
294 lpsd
->Control
&= ~SE_SACL_PRESENT
;
297 lpsd
->Control
|= SE_SACL_PRESENT
;
300 lpsd
->Control
|= SE_SACL_DEFAULTED
;
302 lpsd
->Control
&= ~SE_SACL_DEFAULTED
;
303 return STATUS_SUCCESS
;
306 /**************************************************************************
307 * RtlGetOwnerSecurityDescriptor [NTDLL.488]
309 NTSTATUS WINAPI
RtlGetOwnerSecurityDescriptor(
310 PSECURITY_DESCRIPTOR SecurityDescriptor
,
312 PBOOLEAN OwnerDefaulted
)
314 if ( !SecurityDescriptor
|| !Owner
|| !OwnerDefaulted
)
315 return STATUS_INVALID_PARAMETER
;
317 *Owner
= SecurityDescriptor
->Owner
;
318 if ( *Owner
!= NULL
) {
319 if ( SecurityDescriptor
->Control
& SE_OWNER_DEFAULTED
)
320 *OwnerDefaulted
= TRUE
;
322 *OwnerDefaulted
= FALSE
;
324 return STATUS_SUCCESS
;
327 /**************************************************************************
328 * RtlSetOwnerSecurityDescriptor [NTDLL.487]
330 NTSTATUS WINAPI
RtlSetOwnerSecurityDescriptor(
331 PSECURITY_DESCRIPTOR lpsd
,
333 BOOLEAN ownerdefaulted
)
335 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
336 return STATUS_UNKNOWN_REVISION
;
337 if (lpsd
->Control
& SE_SELF_RELATIVE
)
338 return STATUS_INVALID_SECURITY_DESCR
;
342 lpsd
->Control
|= SE_OWNER_DEFAULTED
;
344 lpsd
->Control
&= ~SE_OWNER_DEFAULTED
;
345 return STATUS_SUCCESS
;
348 /**************************************************************************
349 * RtlSetGroupSecurityDescriptor [NTDLL.485]
351 NTSTATUS WINAPI
RtlSetGroupSecurityDescriptor (
352 PSECURITY_DESCRIPTOR lpsd
,
354 BOOLEAN groupdefaulted
)
356 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
357 return STATUS_UNKNOWN_REVISION
;
358 if (lpsd
->Control
& SE_SELF_RELATIVE
)
359 return STATUS_INVALID_SECURITY_DESCR
;
363 lpsd
->Control
|= SE_GROUP_DEFAULTED
;
365 lpsd
->Control
&= ~SE_GROUP_DEFAULTED
;
366 return STATUS_SUCCESS
;
368 /**************************************************************************
369 * RtlGetGroupSecurityDescriptor [NTDLL]
371 NTSTATUS WINAPI
RtlGetGroupSecurityDescriptor(
372 PSECURITY_DESCRIPTOR SecurityDescriptor
,
374 PBOOLEAN GroupDefaulted
)
376 if ( !SecurityDescriptor
|| !Group
|| !GroupDefaulted
)
377 return STATUS_INVALID_PARAMETER
;
379 *Group
= SecurityDescriptor
->Group
;
380 if ( *Group
!= NULL
) {
381 if ( SecurityDescriptor
->Control
& SE_GROUP_DEFAULTED
)
382 *GroupDefaulted
= TRUE
;
384 *GroupDefaulted
= FALSE
;
386 return STATUS_SUCCESS
;
390 * access control list's
393 /**************************************************************************
394 * RtlCreateAcl [NTDLL.306]
397 * This should return NTSTATUS
399 DWORD WINAPI
RtlCreateAcl(PACL acl
,DWORD size
,DWORD rev
)
401 if (rev
!=ACL_REVISION
)
402 return STATUS_INVALID_PARAMETER
;
403 if (size
<sizeof(ACL
))
404 return STATUS_BUFFER_TOO_SMALL
;
406 return STATUS_INVALID_PARAMETER
;
408 memset(acl
,'\0',sizeof(ACL
));
409 acl
->AclRevision
= rev
;
415 /**************************************************************************
416 * RtlFirstFreeAce [NTDLL.370]
417 * looks for the AceCount+1 ACE, and if it is still within the alloced
418 * ACL, return a pointer to it
420 BOOLEAN WINAPI
RtlFirstFreeAce(
428 ace
= (PACE_HEADER
)(acl
+1);
429 for (i
=0;i
<acl
->AceCount
;i
++) {
430 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
432 ace
= (PACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
434 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
440 /**************************************************************************
441 * RtlAddAce [NTDLL.260]
443 NTSTATUS WINAPI
RtlAddAce(
447 PACE_HEADER acestart
,
450 PACE_HEADER ace
,targetace
;
453 if (acl
->AclRevision
!= ACL_REVISION
)
454 return STATUS_INVALID_PARAMETER
;
455 if (!RtlFirstFreeAce(acl
,&targetace
))
456 return STATUS_INVALID_PARAMETER
;
457 nrofaces
=0;ace
=acestart
;
458 while (((DWORD
)ace
-(DWORD
)acestart
)<acelen
) {
460 ace
= (PACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
462 if ((DWORD
)targetace
+acelen
>(DWORD
)acl
+acl
->AclSize
) /* too much aces */
463 return STATUS_INVALID_PARAMETER
;
464 memcpy((LPBYTE
)targetace
,acestart
,acelen
);
465 acl
->AceCount
+=nrofaces
;
466 return STATUS_SUCCESS
;
469 /******************************************************************************
470 * RtlAddAccessAllowedAce [NTDLL]
472 DWORD WINAPI
RtlAddAccessAllowedAce(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
)
474 FIXME(ntdll
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1
,x2
,x3
,x4
);
478 /******************************************************************************
481 DWORD WINAPI
RtlGetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
483 FIXME(ntdll
,"(%p,%ld,%p),stub!\n",pAcl
,dwAceIndex
,pAce
);
491 /******************************************************************************
492 * RtlAdjustPrivilege [NTDLL]
494 DWORD WINAPI
RtlAdjustPrivilege(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
)
496 FIXME(ntdll
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1
,x2
,x3
,x4
);