The structure layout of self-relative security descriptors may be different from...
[reactos.git] / reactos / lib / advapi32 / sec / sec.c
1 /* $Id$
2 *
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 )
10 * UPDATE HISTORY:
11 * Created 01/11/98
12 */
13
14 #include "advapi32.h"
15 #include <debug.h>
16
17 /*
18 * @implemented
19 */
20 BOOL
21 STDCALL
22 GetSecurityDescriptorControl (
23 PSECURITY_DESCRIPTOR pSecurityDescriptor,
24 PSECURITY_DESCRIPTOR_CONTROL pControl,
25 LPDWORD lpdwRevision
26 )
27 {
28 NTSTATUS Status;
29
30 Status = RtlGetControlSecurityDescriptor (pSecurityDescriptor,
31 pControl,
32 (PULONG)lpdwRevision);
33 if (!NT_SUCCESS(Status))
34 {
35 SetLastError (RtlNtStatusToDosError (Status));
36 return FALSE;
37 }
38
39 return TRUE;
40 }
41
42
43 /*
44 * @implemented
45 */
46 BOOL
47 STDCALL
48 GetSecurityDescriptorDacl (
49 PSECURITY_DESCRIPTOR pSecurityDescriptor,
50 LPBOOL lpbDaclPresent,
51 PACL *pDacl,
52 LPBOOL lpbDaclDefaulted
53 )
54 {
55 BOOLEAN DaclPresent;
56 BOOLEAN DaclDefaulted;
57 NTSTATUS Status;
58
59 Status = RtlGetDaclSecurityDescriptor (pSecurityDescriptor,
60 &DaclPresent,
61 pDacl,
62 &DaclDefaulted);
63 *lpbDaclPresent = (BOOL)DaclPresent;
64 *lpbDaclDefaulted = (BOOL)DaclDefaulted;
65
66 if (!NT_SUCCESS(Status))
67 {
68 SetLastError (RtlNtStatusToDosError (Status));
69 return FALSE;
70 }
71
72 return TRUE;
73 }
74
75
76 /*
77 * @implemented
78 */
79 BOOL
80 STDCALL
81 GetSecurityDescriptorGroup (
82 PSECURITY_DESCRIPTOR pSecurityDescriptor,
83 PSID *pGroup,
84 LPBOOL lpbGroupDefaulted
85 )
86 {
87 BOOLEAN GroupDefaulted;
88 NTSTATUS Status;
89
90 Status = RtlGetGroupSecurityDescriptor (pSecurityDescriptor,
91 pGroup,
92 &GroupDefaulted);
93 *lpbGroupDefaulted = (BOOL)GroupDefaulted;
94
95 if (!NT_SUCCESS(Status))
96 {
97 SetLastError (RtlNtStatusToDosError (Status));
98 return FALSE;
99 }
100
101 return TRUE;
102 }
103
104
105 /*
106 * @implemented
107 */
108 DWORD
109 STDCALL
110 GetSecurityDescriptorLength (
111 PSECURITY_DESCRIPTOR pSecurityDescriptor
112 )
113 {
114 return RtlLengthSecurityDescriptor(pSecurityDescriptor);
115 }
116
117
118 /*
119 * @implemented
120 */
121 BOOL
122 STDCALL
123 GetSecurityDescriptorOwner (
124 PSECURITY_DESCRIPTOR pSecurityDescriptor,
125 PSID *pOwner,
126 LPBOOL lpbOwnerDefaulted
127 )
128 {
129 BOOLEAN OwnerDefaulted;
130 NTSTATUS Status;
131
132 Status = RtlGetOwnerSecurityDescriptor (pSecurityDescriptor,
133 pOwner,
134 &OwnerDefaulted);
135 *lpbOwnerDefaulted = (BOOL)OwnerDefaulted;
136
137 if (!NT_SUCCESS(Status))
138 {
139 SetLastError (RtlNtStatusToDosError (Status));
140 return FALSE;
141 }
142
143 return TRUE;
144 }
145
146
147 /*
148 * @implemented
149 */
150 DWORD
151 STDCALL
152 GetSecurityDescriptorRMControl (
153 PSECURITY_DESCRIPTOR SecurityDescriptor,
154 PUCHAR RMControl)
155 {
156 if (!RtlGetSecurityDescriptorRMControl(SecurityDescriptor,
157 RMControl))
158 return ERROR_INVALID_DATA;
159
160 return ERROR_SUCCESS;
161 }
162
163
164 /*
165 * @implemented
166 */
167 BOOL
168 STDCALL
169 GetSecurityDescriptorSacl (
170 PSECURITY_DESCRIPTOR pSecurityDescriptor,
171 LPBOOL lpbSaclPresent,
172 PACL *pSacl,
173 LPBOOL lpbSaclDefaulted
174 )
175 {
176 BOOLEAN SaclPresent;
177 BOOLEAN SaclDefaulted;
178 NTSTATUS Status;
179
180 Status = RtlGetSaclSecurityDescriptor (pSecurityDescriptor,
181 &SaclPresent,
182 pSacl,
183 &SaclDefaulted);
184 *lpbSaclPresent = (BOOL)SaclPresent;
185 *lpbSaclDefaulted = (BOOL)SaclDefaulted;
186
187 if (!NT_SUCCESS(Status))
188 {
189 SetLastError (RtlNtStatusToDosError (Status));
190 return FALSE;
191 }
192
193 return TRUE;
194 }
195
196
197 /*
198 * @implemented
199 */
200 BOOL
201 STDCALL
202 InitializeSecurityDescriptor (
203 PSECURITY_DESCRIPTOR pSecurityDescriptor,
204 DWORD dwRevision
205 )
206 {
207 NTSTATUS Status;
208
209 Status = RtlCreateSecurityDescriptor (pSecurityDescriptor,
210 dwRevision);
211 if (!NT_SUCCESS(Status))
212 {
213 SetLastError (RtlNtStatusToDosError (Status));
214 return FALSE;
215 }
216
217 return TRUE;
218 }
219
220
221 /*
222 * @implemented
223 */
224 BOOL
225 STDCALL
226 IsValidSecurityDescriptor (
227 PSECURITY_DESCRIPTOR pSecurityDescriptor
228 )
229 {
230 BOOLEAN Result;
231
232 Result = RtlValidSecurityDescriptor (pSecurityDescriptor);
233 if (Result == FALSE)
234 SetLastError (RtlNtStatusToDosError (STATUS_INVALID_SECURITY_DESCR));
235
236 return (BOOL)Result;
237 }
238
239
240 /*
241 * @implemented
242 */
243 BOOL
244 STDCALL
245 MakeAbsoluteSD (
246 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
247 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
248 LPDWORD lpdwAbsoluteSecurityDescriptorSize,
249 PACL pDacl,
250 LPDWORD lpdwDaclSize,
251 PACL pSacl,
252 LPDWORD lpdwSaclSize,
253 PSID pOwner,
254 LPDWORD lpdwOwnerSize,
255 PSID pPrimaryGroup,
256 LPDWORD lpdwPrimaryGroupSize
257 )
258 {
259 NTSTATUS Status;
260
261 Status = RtlSelfRelativeToAbsoluteSD ((PSECURITY_DESCRIPTOR_RELATIVE)pSelfRelativeSecurityDescriptor,
262 pAbsoluteSecurityDescriptor,
263 lpdwAbsoluteSecurityDescriptorSize,
264 pDacl,
265 lpdwDaclSize,
266 pSacl,
267 lpdwSaclSize,
268 pOwner,
269 lpdwOwnerSize,
270 pPrimaryGroup,
271 lpdwPrimaryGroupSize);
272 if (!NT_SUCCESS(Status))
273 {
274 SetLastError (RtlNtStatusToDosError (Status));
275 return FALSE;
276 }
277
278 return TRUE;
279 }
280
281
282 /*
283 * @implemented
284 */
285 BOOL
286 STDCALL
287 MakeSelfRelativeSD (
288 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
289 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
290 LPDWORD lpdwBufferLength
291 )
292 {
293 NTSTATUS Status;
294
295 Status = RtlAbsoluteToSelfRelativeSD (pAbsoluteSecurityDescriptor,
296 (PSECURITY_DESCRIPTOR_RELATIVE)pSelfRelativeSecurityDescriptor,
297 (PULONG)lpdwBufferLength);
298 if (!NT_SUCCESS(Status))
299 {
300 SetLastError (RtlNtStatusToDosError (Status));
301 return FALSE;
302 }
303
304 return TRUE;
305 }
306
307
308 /*
309 * @implemented
310 */
311 BOOL
312 STDCALL
313 SetSecurityDescriptorControl (
314 PSECURITY_DESCRIPTOR pSecurityDescriptor,
315 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
316 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet)
317 {
318 NTSTATUS Status;
319
320 Status = RtlSetControlSecurityDescriptor(pSecurityDescriptor,
321 ControlBitsOfInterest,
322 ControlBitsToSet);
323 if (!NT_SUCCESS(Status))
324 {
325 SetLastError (RtlNtStatusToDosError (Status));
326 return FALSE;
327 }
328
329 return TRUE;
330 }
331
332
333 /*
334 * @implemented
335 */
336 BOOL
337 STDCALL
338 SetSecurityDescriptorDacl (
339 PSECURITY_DESCRIPTOR pSecurityDescriptor,
340 BOOL bDaclPresent,
341 PACL pDacl,
342 BOOL bDaclDefaulted
343 )
344 {
345 NTSTATUS Status;
346
347 Status = RtlSetDaclSecurityDescriptor (pSecurityDescriptor,
348 bDaclPresent,
349 pDacl,
350 bDaclDefaulted);
351 if (!NT_SUCCESS(Status))
352 {
353 SetLastError (RtlNtStatusToDosError (Status));
354 return FALSE;
355 }
356
357 return TRUE;
358 }
359
360
361 /*
362 * @implemented
363 */
364 BOOL
365 STDCALL
366 SetSecurityDescriptorGroup (
367 PSECURITY_DESCRIPTOR pSecurityDescriptor,
368 PSID pGroup,
369 BOOL bGroupDefaulted
370 )
371 {
372 NTSTATUS Status;
373
374 Status = RtlSetGroupSecurityDescriptor (pSecurityDescriptor,
375 pGroup,
376 bGroupDefaulted);
377 if (!NT_SUCCESS(Status))
378 {
379 SetLastError (RtlNtStatusToDosError (Status));
380 return FALSE;
381 }
382
383 return TRUE;
384 }
385
386
387 /*
388 * @implemented
389 */
390 BOOL
391 STDCALL
392 SetSecurityDescriptorOwner (
393 PSECURITY_DESCRIPTOR pSecurityDescriptor,
394 PSID pOwner,
395 BOOL bOwnerDefaulted
396 )
397 {
398 NTSTATUS Status;
399
400 Status = RtlSetOwnerSecurityDescriptor (pSecurityDescriptor,
401 pOwner,
402 bOwnerDefaulted);
403 if (!NT_SUCCESS(Status))
404 {
405 SetLastError (RtlNtStatusToDosError (Status));
406 return FALSE;
407 }
408
409 return TRUE;
410 }
411
412
413 /*
414 * @implemented
415 */
416 DWORD
417 STDCALL
418 SetSecurityDescriptorRMControl (
419 PSECURITY_DESCRIPTOR SecurityDescriptor,
420 PUCHAR RMControl)
421 {
422 RtlSetSecurityDescriptorRMControl(SecurityDescriptor,
423 RMControl);
424
425 return ERROR_SUCCESS;
426 }
427
428
429 /*
430 * @implemented
431 */
432 BOOL
433 STDCALL
434 SetSecurityDescriptorSacl (
435 PSECURITY_DESCRIPTOR pSecurityDescriptor,
436 BOOL bSaclPresent,
437 PACL pSacl,
438 BOOL bSaclDefaulted
439 )
440 {
441 NTSTATUS Status;
442
443 Status = RtlSetSaclSecurityDescriptor (pSecurityDescriptor,
444 bSaclPresent,
445 pSacl,
446 bSaclDefaulted);
447 if (!NT_SUCCESS(Status))
448 {
449 SetLastError (RtlNtStatusToDosError (Status));
450 return FALSE;
451 }
452
453 return TRUE;
454 }
455
456 /* EOF */