72b4e715a3a2ea3d18e3dab9f5dfe6020cdcb2c4
[reactos.git] / lib / advapi32 / sec / sec.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS system libraries
4  * FILE:            lib/advapi32/sec/sec.c
5  * PURPOSE:         Registry functions
6  * PROGRAMMER:      Ariadne ( ariadne@xs4all.nl)
7  * UPDATE HISTORY:
8  *                  Created 01/11/98
9  */
10
11 #define NTOS_MODE_USER
12 #include <ntos.h>
13 #include <windows.h>
14
15
16 BOOL
17 STDCALL
18 GetSecurityDescriptorControl (
19         PSECURITY_DESCRIPTOR            pSecurityDescriptor,
20         PSECURITY_DESCRIPTOR_CONTROL    pControl,
21         LPDWORD                         lpdwRevision
22         )
23 {
24         NTSTATUS Status;
25
26         Status = RtlGetControlSecurityDescriptor (pSecurityDescriptor,
27                                                   pControl,
28                                                   (PULONG)lpdwRevision);
29         if (!NT_SUCCESS(Status))
30         {
31                 SetLastError (RtlNtStatusToDosError (Status));
32                 return FALSE;
33         }
34
35         return TRUE;
36 }
37
38
39 BOOL
40 STDCALL
41 GetSecurityDescriptorDacl (
42         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
43         LPBOOL                  lpbDaclPresent,
44         PACL                    *pDacl,
45         LPBOOL                  lpbDaclDefaulted
46         )
47 {
48         BOOLEAN DaclPresent;
49         BOOLEAN DaclDefaulted;
50         NTSTATUS Status;
51
52         Status = RtlGetDaclSecurityDescriptor (pSecurityDescriptor,
53                                                &DaclPresent,
54                                                pDacl,
55                                                &DaclDefaulted);
56         *lpbDaclPresent = (BOOL)DaclPresent;
57         *lpbDaclDefaulted = (BOOL)DaclDefaulted;
58
59         if (!NT_SUCCESS(Status))
60         {
61                 SetLastError (RtlNtStatusToDosError (Status));
62                 return FALSE;
63         }
64
65         return TRUE;
66 }
67
68
69 BOOL
70 STDCALL
71 GetSecurityDescriptorGroup (
72         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
73         PSID                    *pGroup,
74         LPBOOL                  lpbGroupDefaulted
75         )
76 {
77         BOOLEAN GroupDefaulted;
78         NTSTATUS Status;
79
80         Status = RtlGetGroupSecurityDescriptor (pSecurityDescriptor,
81                                                 pGroup,
82                                                 &GroupDefaulted);
83         *lpbGroupDefaulted = (BOOL)GroupDefaulted;
84
85         if (!NT_SUCCESS(Status))
86         {
87                 SetLastError (RtlNtStatusToDosError (Status));
88                 return FALSE;
89         }
90
91         return TRUE;
92 }
93
94
95 DWORD
96 STDCALL
97 GetSecurityDescriptorLength (
98         PSECURITY_DESCRIPTOR    pSecurityDescriptor
99         )
100 {
101         return RtlLengthSecurityDescriptor(pSecurityDescriptor);
102 }
103
104
105 BOOL
106 STDCALL
107 GetSecurityDescriptorOwner (
108         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
109         PSID                    *pOwner,
110         LPBOOL                  lpbOwnerDefaulted
111 )
112 {
113         BOOLEAN OwnerDefaulted;
114         NTSTATUS Status;
115
116         Status = RtlGetOwnerSecurityDescriptor (pSecurityDescriptor,
117                                                 pOwner,
118                                                 &OwnerDefaulted);
119         *lpbOwnerDefaulted = (BOOL)OwnerDefaulted;
120
121         if (!NT_SUCCESS(Status))
122         {
123                 SetLastError (RtlNtStatusToDosError (Status));
124                 return FALSE;
125         }
126
127         return TRUE;
128 }
129
130
131 BOOL
132 STDCALL
133 GetSecurityDescriptorSacl (
134         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
135         LPBOOL                  lpbSaclPresent,
136         PACL                    *pSacl,
137         LPBOOL                  lpbSaclDefaulted
138         )
139 {
140         BOOLEAN SaclPresent;
141         BOOLEAN SaclDefaulted;
142         NTSTATUS Status;
143
144         Status = RtlGetSaclSecurityDescriptor (pSecurityDescriptor,
145                                                &SaclPresent,
146                                                pSacl,
147                                                &SaclDefaulted);
148         *lpbSaclPresent = (BOOL)SaclPresent;
149         *lpbSaclDefaulted = (BOOL)SaclDefaulted;
150
151         if (!NT_SUCCESS(Status))
152         {
153                 SetLastError (RtlNtStatusToDosError (Status));
154                 return FALSE;
155         }
156
157         return TRUE;
158 }
159
160
161 BOOL
162 STDCALL
163 InitializeSecurityDescriptor (
164         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
165         DWORD                   dwRevision
166         )
167 {
168         NTSTATUS Status;
169
170         Status = RtlCreateSecurityDescriptor (pSecurityDescriptor,
171                                               dwRevision);
172         if (!NT_SUCCESS(Status))
173         {
174                 SetLastError (RtlNtStatusToDosError (Status));
175                 return FALSE;
176         }
177
178         return TRUE;
179 }
180
181 BOOL
182 STDCALL
183 IsValidSecurityDescriptor (
184         PSECURITY_DESCRIPTOR    pSecurityDescriptor
185         )
186 {
187         BOOLEAN Result;
188
189         Result = RtlValidSecurityDescriptor (pSecurityDescriptor);
190         if (Result == FALSE)
191                 SetLastError (RtlNtStatusToDosError (STATUS_INVALID_SECURITY_DESCR));
192
193         return (BOOL)Result;
194 }
195
196
197 WINBOOL
198 STDCALL
199 MakeAbsoluteSD (
200         PSECURITY_DESCRIPTOR    pSelfRelativeSecurityDescriptor,
201         PSECURITY_DESCRIPTOR    pAbsoluteSecurityDescriptor,
202         LPDWORD                 lpdwAbsoluteSecurityDescriptorSize,
203         PACL                    pDacl,
204         LPDWORD                 lpdwDaclSize,
205         PACL                    pSacl,
206         LPDWORD                 lpdwSaclSize,
207         PSID                    pOwner,
208         LPDWORD                 lpdwOwnerSize,
209         PSID                    pPrimaryGroup,
210         LPDWORD                 lpdwPrimaryGroupSize
211         )
212 {
213         NTSTATUS Status;
214
215         Status = RtlSelfRelativeToAbsoluteSD (pSelfRelativeSecurityDescriptor,
216                                               pAbsoluteSecurityDescriptor,
217                                               lpdwAbsoluteSecurityDescriptorSize,
218                                               pDacl,
219                                               lpdwDaclSize,
220                                               pSacl,
221                                               lpdwSaclSize,
222                                               pOwner,
223                                               lpdwOwnerSize,
224                                               pPrimaryGroup,
225                                               lpdwPrimaryGroupSize);
226         if (!NT_SUCCESS(Status))
227         {
228                 SetLastError (RtlNtStatusToDosError (Status));
229                 return FALSE;
230         }
231
232         return TRUE;
233 }
234
235
236 WINBOOL
237 STDCALL
238 MakeSelfRelativeSD (
239         PSECURITY_DESCRIPTOR    pAbsoluteSecurityDescriptor,
240         PSECURITY_DESCRIPTOR    pSelfRelativeSecurityDescriptor,
241         LPDWORD                 lpdwBufferLength
242         )
243 {
244         NTSTATUS Status;
245
246         Status = RtlAbsoluteToSelfRelativeSD (pAbsoluteSecurityDescriptor,
247                                               pSelfRelativeSecurityDescriptor,
248                                               (PULONG)lpdwBufferLength);
249         if (!NT_SUCCESS(Status))
250         {
251                 SetLastError (RtlNtStatusToDosError (Status));
252                 return FALSE;
253         }
254
255         return TRUE;
256 }
257
258
259 BOOL
260 STDCALL
261 SetSecurityDescriptorDacl (
262         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
263         BOOL                    bDaclPresent,
264         PACL                    pDacl,
265         BOOL                    bDaclDefaulted
266         )
267 {
268         NTSTATUS Status;
269
270         Status = RtlSetDaclSecurityDescriptor (pSecurityDescriptor,
271                                                bDaclPresent,
272                                                pDacl,
273                                                bDaclDefaulted);
274         if (!NT_SUCCESS(Status))
275         {
276                 SetLastError (RtlNtStatusToDosError (Status));
277                 return FALSE;
278         }
279
280         return TRUE;
281 }
282
283
284 BOOL
285 STDCALL
286 SetSecurityDescriptorGroup (
287         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
288         PSID                    pGroup,
289         BOOL                    bGroupDefaulted
290         )
291 {
292         NTSTATUS Status;
293
294         Status = RtlSetGroupSecurityDescriptor (pSecurityDescriptor,
295                                                 pGroup,
296                                                 bGroupDefaulted);
297         if (!NT_SUCCESS(Status))
298         {
299                 SetLastError (RtlNtStatusToDosError (Status));
300                 return FALSE;
301         }
302
303         return TRUE;
304 }
305
306
307 BOOL
308 STDCALL
309 SetSecurityDescriptorOwner (
310         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
311         PSID                    pOwner,
312         BOOL                    bOwnerDefaulted
313         )
314 {
315         NTSTATUS Status;
316
317         Status = RtlSetGroupSecurityDescriptor (pSecurityDescriptor,
318                                                 pOwner,
319                                                 bOwnerDefaulted);
320         if (!NT_SUCCESS(Status))
321         {
322                 SetLastError (RtlNtStatusToDosError (Status));
323                 return FALSE;
324         }
325
326         return TRUE;
327 }
328
329
330 BOOL
331 STDCALL
332 SetSecurityDescriptorSacl (
333         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
334         BOOL                    bSaclPresent,
335         PACL                    pSacl,
336         BOOL                    bSaclDefaulted
337         )
338 {
339         NTSTATUS Status;
340
341         Status = RtlSetSaclSecurityDescriptor (pSecurityDescriptor,
342                                                bSaclPresent,
343                                                pSacl,
344                                                bSaclDefaulted);
345         if (!NT_SUCCESS(Status))
346         {
347                 SetLastError (RtlNtStatusToDosError (Status));
348                 return FALSE;
349         }
350
351         return TRUE;
352 }
353
354 BOOL STDCALL
355 GetUserNameA(LPSTR lpBuffer, LPDWORD nSize)
356 {
357   return(FALSE);
358 }
359
360 BOOL STDCALL
361 GetUserNameW(LPWSTR lpBuffer, LPDWORD nSize)
362 {
363   return(FALSE);
364 }
365
366 /* EOF */