3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/sec/sec.c
6 * PURPOSE: Security descriptor functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * Steven Edwards ( Steven_Ed4153@yahoo.com )
9 * Andrew Greenwood ( silverblade_uk@hotmail.com )
15 #include "wine/debug.h"
17 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
24 GetSecurityDescriptorControl (
25 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
26 PSECURITY_DESCRIPTOR_CONTROL pControl
,
32 Status
= RtlGetControlSecurityDescriptor (pSecurityDescriptor
,
34 (PULONG
)lpdwRevision
);
35 if (!NT_SUCCESS(Status
))
37 SetLastError (RtlNtStatusToDosError (Status
));
50 GetSecurityDescriptorDacl (
51 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
52 LPBOOL lpbDaclPresent
,
54 LPBOOL lpbDaclDefaulted
58 BOOLEAN DaclDefaulted
;
61 Status
= RtlGetDaclSecurityDescriptor (pSecurityDescriptor
,
65 *lpbDaclPresent
= (BOOL
)DaclPresent
;
66 *lpbDaclDefaulted
= (BOOL
)DaclDefaulted
;
68 if (!NT_SUCCESS(Status
))
70 SetLastError (RtlNtStatusToDosError (Status
));
83 GetSecurityDescriptorGroup (
84 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
86 LPBOOL lpbGroupDefaulted
89 BOOLEAN GroupDefaulted
;
92 Status
= RtlGetGroupSecurityDescriptor (pSecurityDescriptor
,
95 *lpbGroupDefaulted
= (BOOL
)GroupDefaulted
;
97 if (!NT_SUCCESS(Status
))
99 SetLastError (RtlNtStatusToDosError (Status
));
112 GetSecurityDescriptorOwner (
113 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
115 LPBOOL lpbOwnerDefaulted
118 BOOLEAN OwnerDefaulted
;
121 Status
= RtlGetOwnerSecurityDescriptor (pSecurityDescriptor
,
124 *lpbOwnerDefaulted
= (BOOL
)OwnerDefaulted
;
126 if (!NT_SUCCESS(Status
))
128 SetLastError (RtlNtStatusToDosError (Status
));
141 GetSecurityDescriptorRMControl (
142 PSECURITY_DESCRIPTOR SecurityDescriptor
,
145 if (!RtlGetSecurityDescriptorRMControl(SecurityDescriptor
,
147 return ERROR_INVALID_DATA
;
149 return ERROR_SUCCESS
;
158 GetSecurityDescriptorSacl (
159 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
160 LPBOOL lpbSaclPresent
,
162 LPBOOL lpbSaclDefaulted
166 BOOLEAN SaclDefaulted
;
169 Status
= RtlGetSaclSecurityDescriptor (pSecurityDescriptor
,
173 *lpbSaclPresent
= (BOOL
)SaclPresent
;
174 *lpbSaclDefaulted
= (BOOL
)SaclDefaulted
;
176 if (!NT_SUCCESS(Status
))
178 SetLastError (RtlNtStatusToDosError (Status
));
191 InitializeSecurityDescriptor (
192 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
198 Status
= RtlCreateSecurityDescriptor (pSecurityDescriptor
,
200 if (!NT_SUCCESS(Status
))
202 SetLastError (RtlNtStatusToDosError (Status
));
215 IsValidSecurityDescriptor (
216 PSECURITY_DESCRIPTOR pSecurityDescriptor
221 Result
= RtlValidSecurityDescriptor (pSecurityDescriptor
);
223 SetLastError (RtlNtStatusToDosError (STATUS_INVALID_SECURITY_DESCR
));
235 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
236 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
237 LPDWORD lpdwAbsoluteSecurityDescriptorSize
,
239 LPDWORD lpdwDaclSize
,
241 LPDWORD lpdwSaclSize
,
243 LPDWORD lpdwOwnerSize
,
245 LPDWORD lpdwPrimaryGroupSize
250 Status
= RtlSelfRelativeToAbsoluteSD (pSelfRelativeSecurityDescriptor
,
251 pAbsoluteSecurityDescriptor
,
252 lpdwAbsoluteSecurityDescriptorSize
,
260 lpdwPrimaryGroupSize
);
261 if (!NT_SUCCESS(Status
))
263 SetLastError (RtlNtStatusToDosError (Status
));
276 MakeAbsoluteSD2(IN OUT PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
277 OUT LPDWORD lpdwBufferSize
)
281 Status
= RtlSelfRelativeToAbsoluteSD2(pSelfRelativeSecurityDescriptor
,
283 if (!NT_SUCCESS(Status
))
285 SetLastError (RtlNtStatusToDosError (Status
));
299 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor
,
300 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor
,
301 LPDWORD lpdwBufferLength
306 Status
= RtlAbsoluteToSelfRelativeSD (pAbsoluteSecurityDescriptor
,
307 pSelfRelativeSecurityDescriptor
,
308 (PULONG
)lpdwBufferLength
);
309 if (!NT_SUCCESS(Status
))
311 SetLastError (RtlNtStatusToDosError (Status
));
324 SetSecurityDescriptorControl (
325 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
326 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest
,
327 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
)
331 Status
= RtlSetControlSecurityDescriptor(pSecurityDescriptor
,
332 ControlBitsOfInterest
,
334 if (!NT_SUCCESS(Status
))
336 SetLastError (RtlNtStatusToDosError (Status
));
349 SetSecurityDescriptorDacl (
350 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
358 Status
= RtlSetDaclSecurityDescriptor (pSecurityDescriptor
,
362 if (!NT_SUCCESS(Status
))
364 SetLastError (RtlNtStatusToDosError (Status
));
377 SetSecurityDescriptorGroup (
378 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
385 Status
= RtlSetGroupSecurityDescriptor (pSecurityDescriptor
,
388 if (!NT_SUCCESS(Status
))
390 SetLastError (RtlNtStatusToDosError (Status
));
403 SetSecurityDescriptorOwner (
404 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
411 Status
= RtlSetOwnerSecurityDescriptor (pSecurityDescriptor
,
414 if (!NT_SUCCESS(Status
))
416 SetLastError (RtlNtStatusToDosError (Status
));
429 SetSecurityDescriptorRMControl (
430 PSECURITY_DESCRIPTOR SecurityDescriptor
,
433 RtlSetSecurityDescriptorRMControl(SecurityDescriptor
,
436 return ERROR_SUCCESS
;
445 SetSecurityDescriptorSacl (
446 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
454 Status
= RtlSetSaclSecurityDescriptor (pSecurityDescriptor
,
458 if (!NT_SUCCESS(Status
))
460 SetLastError (RtlNtStatusToDosError (Status
));
473 QuerySecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
474 OUT LPDWORD DesiredAccess
)
478 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
|
479 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
))
481 *DesiredAccess
|= READ_CONTROL
;
484 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
485 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
494 SetSecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
495 OUT LPDWORD DesiredAccess
)
499 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
))
500 *DesiredAccess
|= WRITE_OWNER
;
502 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
503 *DesiredAccess
|= WRITE_DAC
;
505 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
506 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
515 ConvertToAutoInheritPrivateObjectSecurity(IN PSECURITY_DESCRIPTOR ParentDescriptor
,
516 IN PSECURITY_DESCRIPTOR CurrentSecurityDescriptor
,
517 OUT PSECURITY_DESCRIPTOR
* NewSecurityDescriptor
,
519 IN BOOLEAN IsDirectoryObject
,
520 IN PGENERIC_MAPPING GenericMapping
)
532 BuildSecurityDescriptorW(IN PTRUSTEE_W pOwner OPTIONAL
,
533 IN PTRUSTEE_W pGroup OPTIONAL
,
534 IN ULONG cCountOfAccessEntries
,
535 IN PEXPLICIT_ACCESS_W pListOfAccessEntries OPTIONAL
,
536 IN ULONG cCountOfAuditEntries
,
537 IN PEXPLICIT_ACCESS_W pListOfAuditEntries OPTIONAL
,
538 IN PSECURITY_DESCRIPTOR pOldSD OPTIONAL
,
539 OUT PULONG pSizeNewSD
,
540 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
552 BuildSecurityDescriptorA(IN PTRUSTEE_A pOwner OPTIONAL
,
553 IN PTRUSTEE_A pGroup OPTIONAL
,
554 IN ULONG cCountOfAccessEntries
,
555 IN PEXPLICIT_ACCESS_A pListOfAccessEntries OPTIONAL
,
556 IN ULONG cCountOfAuditEntries
,
557 IN PEXPLICIT_ACCESS_A pListOfAuditEntries OPTIONAL
,
558 IN PSECURITY_DESCRIPTOR pOldSD OPTIONAL
,
559 OUT PULONG pSizeNewSD
,
560 OUT PSECURITY_DESCRIPTOR
* pNewSD
)
570 BOOL WINAPI
DecryptFileW(LPCWSTR lpFileName
, DWORD dwReserved
)
572 FIXME("%s(%S) not implemented!\n", __FUNCTION__
, lpFileName
);
573 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
580 BOOL WINAPI
DecryptFileA(LPCSTR lpFileName
, DWORD dwReserved
)
582 UNICODE_STRING FileName
;
586 Status
= RtlCreateUnicodeStringFromAsciiz(&FileName
, lpFileName
);
587 if (!NT_SUCCESS(Status
))
589 SetLastError(RtlNtStatusToDosError(Status
));
593 ret
= DecryptFileW(FileName
.Buffer
, dwReserved
);
595 if (FileName
.Buffer
!= NULL
)
596 RtlFreeUnicodeString(&FileName
);
603 BOOL WINAPI
EncryptFileW(LPCWSTR lpFileName
)
605 FIXME("%s() not implemented!\n", __FUNCTION__
);
606 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
613 BOOL WINAPI
EncryptFileA(LPCSTR lpFileName
)
615 UNICODE_STRING FileName
;
619 Status
= RtlCreateUnicodeStringFromAsciiz(&FileName
, lpFileName
);
620 if (!NT_SUCCESS(Status
))
622 SetLastError(RtlNtStatusToDosError(Status
));
626 ret
= EncryptFileW(FileName
.Buffer
);
628 if (FileName
.Buffer
!= NULL
)
629 RtlFreeUnicodeString(&FileName
);
633 BOOL WINAPI
ConvertSecurityDescriptorToStringSecurityDescriptorW(
634 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
636 SECURITY_INFORMATION SecurityInformation
,
640 FIXME("%s() not implemented!\n", __FUNCTION__
);
641 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
645 BOOL WINAPI
ConvertSecurityDescriptorToStringSecurityDescriptorA(
646 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
648 SECURITY_INFORMATION SecurityInformation
,
652 FIXME("%s() not implemented!\n", __FUNCTION__
);
653 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);