export BuildSecurityDescriptorA/W and IsWellKnownSid
[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 BOOL
109 STDCALL
110 GetSecurityDescriptorOwner (
111 PSECURITY_DESCRIPTOR pSecurityDescriptor,
112 PSID *pOwner,
113 LPBOOL lpbOwnerDefaulted
114 )
115 {
116 BOOLEAN OwnerDefaulted;
117 NTSTATUS Status;
118
119 Status = RtlGetOwnerSecurityDescriptor (pSecurityDescriptor,
120 pOwner,
121 &OwnerDefaulted);
122 *lpbOwnerDefaulted = (BOOL)OwnerDefaulted;
123
124 if (!NT_SUCCESS(Status))
125 {
126 SetLastError (RtlNtStatusToDosError (Status));
127 return FALSE;
128 }
129
130 return TRUE;
131 }
132
133
134 /*
135 * @implemented
136 */
137 DWORD
138 STDCALL
139 GetSecurityDescriptorRMControl (
140 PSECURITY_DESCRIPTOR SecurityDescriptor,
141 PUCHAR RMControl)
142 {
143 if (!RtlGetSecurityDescriptorRMControl(SecurityDescriptor,
144 RMControl))
145 return ERROR_INVALID_DATA;
146
147 return ERROR_SUCCESS;
148 }
149
150
151 /*
152 * @implemented
153 */
154 BOOL
155 STDCALL
156 GetSecurityDescriptorSacl (
157 PSECURITY_DESCRIPTOR pSecurityDescriptor,
158 LPBOOL lpbSaclPresent,
159 PACL *pSacl,
160 LPBOOL lpbSaclDefaulted
161 )
162 {
163 BOOLEAN SaclPresent;
164 BOOLEAN SaclDefaulted;
165 NTSTATUS Status;
166
167 Status = RtlGetSaclSecurityDescriptor (pSecurityDescriptor,
168 &SaclPresent,
169 pSacl,
170 &SaclDefaulted);
171 *lpbSaclPresent = (BOOL)SaclPresent;
172 *lpbSaclDefaulted = (BOOL)SaclDefaulted;
173
174 if (!NT_SUCCESS(Status))
175 {
176 SetLastError (RtlNtStatusToDosError (Status));
177 return FALSE;
178 }
179
180 return TRUE;
181 }
182
183
184 /*
185 * @implemented
186 */
187 BOOL
188 STDCALL
189 InitializeSecurityDescriptor (
190 PSECURITY_DESCRIPTOR pSecurityDescriptor,
191 DWORD dwRevision
192 )
193 {
194 NTSTATUS Status;
195
196 Status = RtlCreateSecurityDescriptor (pSecurityDescriptor,
197 dwRevision);
198 if (!NT_SUCCESS(Status))
199 {
200 SetLastError (RtlNtStatusToDosError (Status));
201 return FALSE;
202 }
203
204 return TRUE;
205 }
206
207
208 /*
209 * @implemented
210 */
211 BOOL
212 STDCALL
213 IsValidSecurityDescriptor (
214 PSECURITY_DESCRIPTOR pSecurityDescriptor
215 )
216 {
217 BOOLEAN Result;
218
219 Result = RtlValidSecurityDescriptor (pSecurityDescriptor);
220 if (Result == FALSE)
221 SetLastError (RtlNtStatusToDosError (STATUS_INVALID_SECURITY_DESCR));
222
223 return (BOOL)Result;
224 }
225
226
227 /*
228 * @implemented
229 */
230 BOOL
231 STDCALL
232 MakeAbsoluteSD (
233 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
234 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
235 LPDWORD lpdwAbsoluteSecurityDescriptorSize,
236 PACL pDacl,
237 LPDWORD lpdwDaclSize,
238 PACL pSacl,
239 LPDWORD lpdwSaclSize,
240 PSID pOwner,
241 LPDWORD lpdwOwnerSize,
242 PSID pPrimaryGroup,
243 LPDWORD lpdwPrimaryGroupSize
244 )
245 {
246 NTSTATUS Status;
247
248 Status = RtlSelfRelativeToAbsoluteSD (pSelfRelativeSecurityDescriptor,
249 pAbsoluteSecurityDescriptor,
250 lpdwAbsoluteSecurityDescriptorSize,
251 pDacl,
252 lpdwDaclSize,
253 pSacl,
254 lpdwSaclSize,
255 pOwner,
256 lpdwOwnerSize,
257 pPrimaryGroup,
258 lpdwPrimaryGroupSize);
259 if (!NT_SUCCESS(Status))
260 {
261 SetLastError (RtlNtStatusToDosError (Status));
262 return FALSE;
263 }
264
265 return TRUE;
266 }
267
268
269 /*
270 * @implemented
271 */
272 BOOL
273 STDCALL
274 MakeSelfRelativeSD (
275 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
276 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
277 LPDWORD lpdwBufferLength
278 )
279 {
280 NTSTATUS Status;
281
282 Status = RtlAbsoluteToSelfRelativeSD (pAbsoluteSecurityDescriptor,
283 pSelfRelativeSecurityDescriptor,
284 (PULONG)lpdwBufferLength);
285 if (!NT_SUCCESS(Status))
286 {
287 SetLastError (RtlNtStatusToDosError (Status));
288 return FALSE;
289 }
290
291 return TRUE;
292 }
293
294
295 /*
296 * @implemented
297 */
298 BOOL
299 STDCALL
300 SetSecurityDescriptorControl (
301 PSECURITY_DESCRIPTOR pSecurityDescriptor,
302 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
303 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet)
304 {
305 NTSTATUS Status;
306
307 Status = RtlSetControlSecurityDescriptor(pSecurityDescriptor,
308 ControlBitsOfInterest,
309 ControlBitsToSet);
310 if (!NT_SUCCESS(Status))
311 {
312 SetLastError (RtlNtStatusToDosError (Status));
313 return FALSE;
314 }
315
316 return TRUE;
317 }
318
319
320 /*
321 * @implemented
322 */
323 BOOL
324 STDCALL
325 SetSecurityDescriptorDacl (
326 PSECURITY_DESCRIPTOR pSecurityDescriptor,
327 BOOL bDaclPresent,
328 PACL pDacl,
329 BOOL bDaclDefaulted
330 )
331 {
332 NTSTATUS Status;
333
334 Status = RtlSetDaclSecurityDescriptor (pSecurityDescriptor,
335 bDaclPresent,
336 pDacl,
337 bDaclDefaulted);
338 if (!NT_SUCCESS(Status))
339 {
340 SetLastError (RtlNtStatusToDosError (Status));
341 return FALSE;
342 }
343
344 return TRUE;
345 }
346
347
348 /*
349 * @implemented
350 */
351 BOOL
352 STDCALL
353 SetSecurityDescriptorGroup (
354 PSECURITY_DESCRIPTOR pSecurityDescriptor,
355 PSID pGroup,
356 BOOL bGroupDefaulted
357 )
358 {
359 NTSTATUS Status;
360
361 Status = RtlSetGroupSecurityDescriptor (pSecurityDescriptor,
362 pGroup,
363 bGroupDefaulted);
364 if (!NT_SUCCESS(Status))
365 {
366 SetLastError (RtlNtStatusToDosError (Status));
367 return FALSE;
368 }
369
370 return TRUE;
371 }
372
373
374 /*
375 * @implemented
376 */
377 BOOL
378 STDCALL
379 SetSecurityDescriptorOwner (
380 PSECURITY_DESCRIPTOR pSecurityDescriptor,
381 PSID pOwner,
382 BOOL bOwnerDefaulted
383 )
384 {
385 NTSTATUS Status;
386
387 Status = RtlSetOwnerSecurityDescriptor (pSecurityDescriptor,
388 pOwner,
389 bOwnerDefaulted);
390 if (!NT_SUCCESS(Status))
391 {
392 SetLastError (RtlNtStatusToDosError (Status));
393 return FALSE;
394 }
395
396 return TRUE;
397 }
398
399
400 /*
401 * @implemented
402 */
403 DWORD
404 STDCALL
405 SetSecurityDescriptorRMControl (
406 PSECURITY_DESCRIPTOR SecurityDescriptor,
407 PUCHAR RMControl)
408 {
409 RtlSetSecurityDescriptorRMControl(SecurityDescriptor,
410 RMControl);
411
412 return ERROR_SUCCESS;
413 }
414
415
416 /*
417 * @implemented
418 */
419 BOOL
420 STDCALL
421 SetSecurityDescriptorSacl (
422 PSECURITY_DESCRIPTOR pSecurityDescriptor,
423 BOOL bSaclPresent,
424 PACL pSacl,
425 BOOL bSaclDefaulted
426 )
427 {
428 NTSTATUS Status;
429
430 Status = RtlSetSaclSecurityDescriptor (pSecurityDescriptor,
431 bSaclPresent,
432 pSacl,
433 bSaclDefaulted);
434 if (!NT_SUCCESS(Status))
435 {
436 SetLastError (RtlNtStatusToDosError (Status));
437 return FALSE;
438 }
439
440 return TRUE;
441 }
442
443
444 /*
445 * @unimplemented
446 */
447 BOOL
448 STDCALL
449 ConvertToAutoInheritPrivateObjectSecurity(IN PSECURITY_DESCRIPTOR ParentDescriptor,
450 IN PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
451 OUT PSECURITY_DESCRIPTOR* NewSecurityDescriptor,
452 IN GUID* ObjectType,
453 IN BOOLEAN IsDirectoryObject,
454 IN PGENERIC_MAPPING GenericMapping)
455 {
456 UNIMPLEMENTED;
457 return FALSE;
458 }
459
460
461 /*
462 * @unimplemented
463 */
464 DWORD
465 STDCALL
466 BuildSecurityDescriptorW(IN PTRUSTEE_W pOwner OPTIONAL,
467 IN PTRUSTEE_W pGroup OPTIONAL,
468 IN ULONG cCountOfAccessEntries,
469 IN PEXPLICIT_ACCESS pListOfAccessEntries OPTIONAL,
470 IN ULONG cCountOfAuditEntries,
471 IN PEXPLICIT_ACCESS pListOfAuditEntries OPTIONAL,
472 IN PSECURITY_DESCRIPTOR pOldSD OPTIONAL,
473 OUT PULONG pSizeNewSD,
474 OUT PSECURITY_DESCRIPTOR* pNewSD)
475 {
476 UNIMPLEMENTED;
477 return FALSE;
478 }
479
480
481 /*
482 * @unimplemented
483 */
484 DWORD
485 STDCALL
486 BuildSecurityDescriptorA(IN PTRUSTEE_A pOwner OPTIONAL,
487 IN PTRUSTEE_A pGroup OPTIONAL,
488 IN ULONG cCountOfAccessEntries,
489 IN PEXPLICIT_ACCESS pListOfAccessEntries OPTIONAL,
490 IN ULONG cCountOfAuditEntries,
491 IN PEXPLICIT_ACCESS pListOfAuditEntries OPTIONAL,
492 IN PSECURITY_DESCRIPTOR pOldSD OPTIONAL,
493 OUT PULONG pSizeNewSD,
494 OUT PSECURITY_DESCRIPTOR* pNewSD)
495 {
496 UNIMPLEMENTED;
497 return FALSE;
498 }
499
500
501 /* EOF */