4 * Copyright 1996-1998 Marcus Meissner
15 #include "wine/winestring.h"
23 #include "stackframe.h"
28 DEFAULT_DEBUG_CHANNEL(ntdll
)
34 /******************************************************************************
35 * RtlAllocateAndInitializeSid [NTDLL.265]
38 BOOLEAN WINAPI
RtlAllocateAndInitializeSid (PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
39 DWORD nSubAuthorityCount
,DWORD x3
,DWORD x4
,DWORD x5
,DWORD x6
,DWORD x7
,DWORD x8
,DWORD x9
,DWORD x10
, PSID pSid
)
41 FIXME(ntdll
,"(%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p),stub!\n",
42 pIdentifierAuthority
,nSubAuthorityCount
,x3
,x4
,x5
,x6
,x7
,x8
,x9
,x10
,pSid
);
45 /******************************************************************************
46 * RtlEqualSid [NTDLL.352]
49 DWORD WINAPI
RtlEqualSid(DWORD x1
,DWORD x2
)
51 FIXME(ntdll
,"(0x%08lx,0x%08lx),stub!\n", x1
,x2
);
55 /******************************************************************************
56 * RtlFreeSid [NTDLL.376]
58 DWORD WINAPI
RtlFreeSid(DWORD x1
)
60 FIXME(ntdll
,"(0x%08lx),stub!\n", x1
);
64 /**************************************************************************
65 * RtlLengthRequiredSid [NTDLL.427]
67 DWORD WINAPI
RtlLengthRequiredSid(DWORD nrofsubauths
)
69 return sizeof(DWORD
)*nrofsubauths
+sizeof(SID
);
72 /**************************************************************************
73 * RtlLengthSid [NTDLL.429]
75 DWORD WINAPI
RtlLengthSid(PSID sid
)
77 TRACE(ntdll
,"sid=%p\n",sid
);
80 return sizeof(DWORD
)*sid
->SubAuthorityCount
+sizeof(SID
);
83 /**************************************************************************
84 * RtlInitializeSid [NTDLL.410]
86 DWORD WINAPI
RtlInitializeSid(PSID PSID
,PSID_IDENTIFIER_AUTHORITY PSIDauth
,
91 if (a
>=SID_MAX_SUB_AUTHORITIES
)
93 PSID
->SubAuthorityCount
= a
;
94 PSID
->Revision
= SID_REVISION
;
95 memcpy(&(PSID
->IdentifierAuthority
),PSIDauth
,sizeof(SID_IDENTIFIER_AUTHORITY
));
96 return STATUS_SUCCESS
;
99 /**************************************************************************
100 * RtlSubAuthoritySid [NTDLL.497]
102 LPDWORD WINAPI
RtlSubAuthoritySid(PSID PSID
,DWORD nr
)
104 return &(PSID
->SubAuthority
[nr
]);
107 /**************************************************************************
108 * RtlSubAuthorityCountSid [NTDLL.496]
111 LPBYTE WINAPI
RtlSubAuthorityCountSid(PSID PSID
)
113 return ((LPBYTE
)PSID
)+1;
116 /**************************************************************************
117 * RtlCopySid [NTDLL.302]
119 DWORD WINAPI
RtlCopySid(DWORD len
,PSID to
,PSID from
)
122 if (len
<(from
->SubAuthorityCount
*4+8))
123 return STATUS_BUFFER_TOO_SMALL
;
124 memmove(to
,from
,from
->SubAuthorityCount
*4+8);
125 return STATUS_SUCCESS
;
129 * security descriptor functions
132 /**************************************************************************
133 * RtlCreateSecurityDescriptor [NTDLL.313]
137 * STATUS_INVALID_OWNER, STATUS_PRIVILEGE_NOT_HELD, STATUS_NO_INHERITANCE,
140 NTSTATUS WINAPI
RtlCreateSecurityDescriptor(
141 PSECURITY_DESCRIPTOR lpsd
,
144 if (rev
!=SECURITY_DESCRIPTOR_REVISION
)
145 return STATUS_UNKNOWN_REVISION
;
146 memset(lpsd
,'\0',sizeof(*lpsd
));
147 lpsd
->Revision
= SECURITY_DESCRIPTOR_REVISION
;
148 return STATUS_SUCCESS
;
150 /**************************************************************************
151 * RtlValidSecurityDescriptor [NTDLL.313]
154 NTSTATUS WINAPI
RtlValidSecurityDescriptor(
155 PSECURITY_DESCRIPTOR SecurityDescriptor
)
157 if ( ! SecurityDescriptor
)
158 return STATUS_INVALID_SECURITY_DESCR
;
159 if ( SecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION
)
160 return STATUS_UNKNOWN_REVISION
;
162 return STATUS_SUCCESS
;
165 /**************************************************************************
166 * RtlLengthSecurityDescriptor [NTDLL]
168 ULONG WINAPI
RtlLengthSecurityDescriptor(
169 PSECURITY_DESCRIPTOR SecurityDescriptor
)
172 Size
= SECURITY_DESCRIPTOR_MIN_LENGTH
;
173 if ( SecurityDescriptor
== NULL
)
176 if ( SecurityDescriptor
->Owner
!= NULL
)
177 Size
+= SecurityDescriptor
->Owner
->SubAuthorityCount
;
178 if ( SecurityDescriptor
->Group
!= NULL
)
179 Size
+= SecurityDescriptor
->Group
->SubAuthorityCount
;
182 if ( SecurityDescriptor
->Sacl
!= NULL
)
183 Size
+= SecurityDescriptor
->Sacl
->AclSize
;
184 if ( SecurityDescriptor
->Dacl
!= NULL
)
185 Size
+= SecurityDescriptor
->Dacl
->AclSize
;
190 /******************************************************************************
191 * RtlGetDaclSecurityDescriptor [NTDLL]
194 NTSTATUS WINAPI
RtlGetDaclSecurityDescriptor(
195 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
196 OUT PBOOLEAN lpbDaclPresent
,
198 OUT PBOOLEAN lpbDaclDefaulted
)
200 TRACE(ntdll
,"(%p,%p,%p,%p)\n",
201 pSecurityDescriptor
, lpbDaclPresent
, *pDacl
, lpbDaclDefaulted
);
203 if (pSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION
)
204 return STATUS_UNKNOWN_REVISION
;
206 if ( (*lpbDaclPresent
= (SE_DACL_PRESENT
& pSecurityDescriptor
->Control
) ? 1 : 0) )
208 if ( SE_SELF_RELATIVE
& pSecurityDescriptor
->Control
)
209 { *pDacl
= (PACL
) ((LPBYTE
)pSecurityDescriptor
+ (DWORD
)pSecurityDescriptor
->Dacl
);
212 { *pDacl
= pSecurityDescriptor
->Dacl
;
216 *lpbDaclDefaulted
= (( SE_DACL_DEFAULTED
& pSecurityDescriptor
->Control
) ? 1 : 0);
218 return STATUS_SUCCESS
;
221 /**************************************************************************
222 * RtlSetDaclSecurityDescriptor [NTDLL.483]
224 NTSTATUS WINAPI
RtlSetDaclSecurityDescriptor (
225 PSECURITY_DESCRIPTOR lpsd
,
228 BOOLEAN dacldefaulted
)
230 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
231 return STATUS_UNKNOWN_REVISION
;
232 if (lpsd
->Control
& SE_SELF_RELATIVE
)
233 return STATUS_INVALID_SECURITY_DESCR
;
236 { lpsd
->Control
&= ~SE_DACL_PRESENT
;
240 lpsd
->Control
|= SE_DACL_PRESENT
;
244 lpsd
->Control
|= SE_DACL_DEFAULTED
;
246 lpsd
->Control
&= ~SE_DACL_DEFAULTED
;
248 return STATUS_SUCCESS
;
251 /******************************************************************************
252 * RtlGetSaclSecurityDescriptor [NTDLL]
255 NTSTATUS WINAPI
RtlGetSaclSecurityDescriptor(
256 IN PSECURITY_DESCRIPTOR pSecurityDescriptor
,
257 OUT PBOOLEAN lpbSaclPresent
,
259 OUT PBOOLEAN lpbSaclDefaulted
)
261 TRACE(ntdll
,"(%p,%p,%p,%p)\n",
262 pSecurityDescriptor
, lpbSaclPresent
, *pSacl
, lpbSaclDefaulted
);
264 if (pSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION
)
265 return STATUS_UNKNOWN_REVISION
;
267 if ( (*lpbSaclPresent
= (SE_SACL_PRESENT
& pSecurityDescriptor
->Control
) ? 1 : 0) )
269 if ( SE_SELF_RELATIVE
& pSecurityDescriptor
->Control
)
270 { *pSacl
= (PACL
) ((LPBYTE
)pSecurityDescriptor
+ (DWORD
)pSecurityDescriptor
->Sacl
);
273 { *pSacl
= pSecurityDescriptor
->Sacl
;
277 *lpbSaclDefaulted
= (( SE_SACL_DEFAULTED
& pSecurityDescriptor
->Control
) ? 1 : 0);
279 return STATUS_SUCCESS
;
282 /**************************************************************************
283 * RtlSetSaclSecurityDescriptor [NTDLL.488]
285 NTSTATUS WINAPI
RtlSetSaclSecurityDescriptor (
286 PSECURITY_DESCRIPTOR lpsd
,
289 BOOLEAN sacldefaulted
)
291 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
292 return STATUS_UNKNOWN_REVISION
;
293 if (lpsd
->Control
& SE_SELF_RELATIVE
)
294 return STATUS_INVALID_SECURITY_DESCR
;
296 lpsd
->Control
&= ~SE_SACL_PRESENT
;
299 lpsd
->Control
|= SE_SACL_PRESENT
;
302 lpsd
->Control
|= SE_SACL_DEFAULTED
;
304 lpsd
->Control
&= ~SE_SACL_DEFAULTED
;
305 return STATUS_SUCCESS
;
308 /**************************************************************************
309 * RtlGetOwnerSecurityDescriptor [NTDLL.488]
311 NTSTATUS WINAPI
RtlGetOwnerSecurityDescriptor(
312 PSECURITY_DESCRIPTOR SecurityDescriptor
,
314 PBOOLEAN OwnerDefaulted
)
316 if ( !SecurityDescriptor
|| !Owner
|| !OwnerDefaulted
)
317 return STATUS_INVALID_PARAMETER
;
319 *Owner
= SecurityDescriptor
->Owner
;
320 if ( *Owner
!= NULL
) {
321 if ( SecurityDescriptor
->Control
& SE_OWNER_DEFAULTED
)
322 *OwnerDefaulted
= TRUE
;
324 *OwnerDefaulted
= FALSE
;
326 return STATUS_SUCCESS
;
329 /**************************************************************************
330 * RtlSetOwnerSecurityDescriptor [NTDLL.487]
332 NTSTATUS WINAPI
RtlSetOwnerSecurityDescriptor(
333 PSECURITY_DESCRIPTOR lpsd
,
335 BOOLEAN ownerdefaulted
)
337 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
338 return STATUS_UNKNOWN_REVISION
;
339 if (lpsd
->Control
& SE_SELF_RELATIVE
)
340 return STATUS_INVALID_SECURITY_DESCR
;
344 lpsd
->Control
|= SE_OWNER_DEFAULTED
;
346 lpsd
->Control
&= ~SE_OWNER_DEFAULTED
;
347 return STATUS_SUCCESS
;
350 /**************************************************************************
351 * RtlSetGroupSecurityDescriptor [NTDLL.485]
353 NTSTATUS WINAPI
RtlSetGroupSecurityDescriptor (
354 PSECURITY_DESCRIPTOR lpsd
,
356 BOOLEAN groupdefaulted
)
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
;
365 lpsd
->Control
|= SE_GROUP_DEFAULTED
;
367 lpsd
->Control
&= ~SE_GROUP_DEFAULTED
;
368 return STATUS_SUCCESS
;
370 /**************************************************************************
371 * RtlGetGroupSecurityDescriptor [NTDLL]
373 NTSTATUS WINAPI
RtlGetGroupSecurityDescriptor(
374 PSECURITY_DESCRIPTOR SecurityDescriptor
,
376 PBOOLEAN GroupDefaulted
)
378 if ( !SecurityDescriptor
|| !Group
|| !GroupDefaulted
)
379 return STATUS_INVALID_PARAMETER
;
381 *Group
= SecurityDescriptor
->Group
;
382 if ( *Group
!= NULL
) {
383 if ( SecurityDescriptor
->Control
& SE_GROUP_DEFAULTED
)
384 *GroupDefaulted
= TRUE
;
386 *GroupDefaulted
= FALSE
;
388 return STATUS_SUCCESS
;
392 * access control list's
395 /**************************************************************************
396 * RtlCreateAcl [NTDLL.306]
399 * This should return NTSTATUS
401 DWORD WINAPI
RtlCreateAcl(PACL acl
,DWORD size
,DWORD rev
)
403 if (rev
!=ACL_REVISION
)
404 return STATUS_INVALID_PARAMETER
;
405 if (size
<sizeof(ACL
))
406 return STATUS_BUFFER_TOO_SMALL
;
408 return STATUS_INVALID_PARAMETER
;
410 memset(acl
,'\0',sizeof(ACL
));
411 acl
->AclRevision
= rev
;
417 /**************************************************************************
418 * RtlFirstFreeAce [NTDLL.370]
419 * looks for the AceCount+1 ACE, and if it is still within the alloced
420 * ACL, return a pointer to it
422 BOOLEAN WINAPI
RtlFirstFreeAce(
430 ace
= (PACE_HEADER
)(acl
+1);
431 for (i
=0;i
<acl
->AceCount
;i
++) {
432 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
434 ace
= (PACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
436 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
442 /**************************************************************************
443 * RtlAddAce [NTDLL.260]
445 NTSTATUS WINAPI
RtlAddAce(
449 PACE_HEADER acestart
,
452 PACE_HEADER ace
,targetace
;
455 if (acl
->AclRevision
!= ACL_REVISION
)
456 return STATUS_INVALID_PARAMETER
;
457 if (!RtlFirstFreeAce(acl
,&targetace
))
458 return STATUS_INVALID_PARAMETER
;
459 nrofaces
=0;ace
=acestart
;
460 while (((DWORD
)ace
-(DWORD
)acestart
)<acelen
) {
462 ace
= (PACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
464 if ((DWORD
)targetace
+acelen
>(DWORD
)acl
+acl
->AclSize
) /* too much aces */
465 return STATUS_INVALID_PARAMETER
;
466 memcpy((LPBYTE
)targetace
,acestart
,acelen
);
467 acl
->AceCount
+=nrofaces
;
468 return STATUS_SUCCESS
;
471 /******************************************************************************
472 * RtlAddAccessAllowedAce [NTDLL]
474 DWORD WINAPI
RtlAddAccessAllowedAce(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
)
476 FIXME(ntdll
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1
,x2
,x3
,x4
);
480 /******************************************************************************
483 DWORD WINAPI
RtlGetAce(PACL pAcl
,DWORD dwAceIndex
,LPVOID
*pAce
)
485 FIXME(ntdll
,"(%p,%ld,%p),stub!\n",pAcl
,dwAceIndex
,pAce
);
493 /******************************************************************************
494 * RtlAdjustPrivilege [NTDLL]
496 DWORD WINAPI
RtlAdjustPrivilege(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
)
498 FIXME(ntdll
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1
,x2
,x3
,x4
);