:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / advapi32 / sec / misc.c
1 /*
2  */
3
4 #include <ddk/ntddk.h>
5 #include <ntdll/rtl.h>
6 #include <windows.h>
7
8
9 WINBOOL STDCALL
10 AreAllAccessesGranted(DWORD GrantedAccess,
11                       DWORD DesiredAccess)
12 {
13   return((BOOL)RtlAreAllAccessesGranted(GrantedAccess,
14                                         DesiredAccess));
15 }
16
17
18 WINBOOL STDCALL
19 AreAnyAccessesGranted(DWORD GrantedAccess,
20                       DWORD DesiredAccess)
21 {
22   return((BOOL)RtlAreAnyAccessesGranted(GrantedAccess,
23                                         DesiredAccess));
24 }
25
26
27 WINBOOL STDCALL
28 GetKernelObjectSecurity(HANDLE Handle,
29                         SECURITY_INFORMATION RequestedInformation,
30                         PSECURITY_DESCRIPTOR pSecurityDescriptor,
31                         DWORD nLength,
32                         LPDWORD lpnLengthNeeded)
33 {
34   NTSTATUS Status;
35
36   Status = NtQuerySecurityObject(Handle,
37                                  RequestedInformation,
38                                  pSecurityDescriptor,
39                                  nLength,
40                                  lpnLengthNeeded);
41   if (!NT_SUCCESS(Status))
42     {
43       SetLastError(RtlNtStatusToDosError(Status));
44       return(FALSE);
45     }
46   return(TRUE);
47 }
48
49
50 BOOL STDCALL
51 SetKernelObjectSecurity(HANDLE Handle,
52                         SECURITY_INFORMATION SecurityInformation,
53                         PSECURITY_DESCRIPTOR SecurityDescriptor)
54 {
55   NTSTATUS Status;
56
57   Status = NtSetSecurityObject(Handle,
58                                SecurityInformation,
59                                SecurityDescriptor);
60   if (!NT_SUCCESS(Status))
61     {
62       SetLastError(RtlNtStatusToDosError(Status));
63       return(FALSE);
64     }
65   return(TRUE);
66 }
67
68
69 VOID STDCALL
70 MapGenericMask(PDWORD AccessMask,
71                PGENERIC_MAPPING GenericMapping)
72 {
73   RtlMapGenericMask(AccessMask,
74                     GenericMapping);
75 }
76
77
78 BOOL STDCALL
79 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
80 {
81   NTSTATUS Status;
82
83   Status = RtlImpersonateSelf(ImpersonationLevel);
84   if (!NT_SUCCESS(Status))
85     {
86       SetLastError(RtlNtStatusToDosError(Status));
87       return(FALSE);
88     }
89   return(TRUE);
90 }
91
92
93 BOOL STDCALL
94 RevertToSelf(VOID)
95 {
96   NTSTATUS Status;
97   HANDLE Token = NULL;
98
99   Status = NtSetInformationThread(NtCurrentThread(),
100                                   ThreadImpersonationToken,
101                                   &Token,
102                                   sizeof(HANDLE));
103   if (!NT_SUCCESS(Status))
104     {
105       SetLastError(RtlNtStatusToDosError(Status));
106       return(FALSE);
107     }
108   return(TRUE);
109 }
110
111 /* EOF */
112