- Synchronize up to trunk's revision r57864.
[reactos.git] / dll / win32 / 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 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
16
17 /*
18 * @implemented
19 */
20 BOOL
21 WINAPI
22 GetSecurityDescriptorControl(PSECURITY_DESCRIPTOR pSecurityDescriptor,
23 PSECURITY_DESCRIPTOR_CONTROL pControl,
24 LPDWORD lpdwRevision)
25 {
26 NTSTATUS Status;
27
28 Status = RtlGetControlSecurityDescriptor(pSecurityDescriptor,
29 pControl,
30 (PULONG)lpdwRevision);
31 if (!NT_SUCCESS(Status))
32 {
33 SetLastError(RtlNtStatusToDosError(Status));
34 return FALSE;
35 }
36
37 return TRUE;
38 }
39
40
41 /*
42 * @implemented
43 */
44 BOOL
45 WINAPI
46 GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,
47 LPBOOL lpbDaclPresent,
48 PACL *pDacl,
49 LPBOOL lpbDaclDefaulted)
50 {
51 BOOLEAN DaclPresent;
52 BOOLEAN DaclDefaulted;
53 NTSTATUS Status;
54
55 Status = RtlGetDaclSecurityDescriptor(pSecurityDescriptor,
56 &DaclPresent,
57 pDacl,
58 &DaclDefaulted);
59 *lpbDaclPresent = (BOOL)DaclPresent;
60 *lpbDaclDefaulted = (BOOL)DaclDefaulted;
61
62 if (!NT_SUCCESS(Status))
63 {
64 SetLastError(RtlNtStatusToDosError(Status));
65 return FALSE;
66 }
67
68 return TRUE;
69 }
70
71
72 /*
73 * @implemented
74 */
75 BOOL
76 WINAPI
77 GetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor,
78 PSID *pGroup,
79 LPBOOL lpbGroupDefaulted)
80 {
81 BOOLEAN GroupDefaulted;
82 NTSTATUS Status;
83
84 Status = RtlGetGroupSecurityDescriptor(pSecurityDescriptor,
85 pGroup,
86 &GroupDefaulted);
87 *lpbGroupDefaulted = (BOOL)GroupDefaulted;
88
89 if (!NT_SUCCESS(Status))
90 {
91 SetLastError(RtlNtStatusToDosError(Status));
92 return FALSE;
93 }
94
95 return TRUE;
96 }
97
98
99 /*
100 * @implemented
101 */
102 BOOL
103 WINAPI
104 GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor,
105 PSID *pOwner,
106 LPBOOL lpbOwnerDefaulted)
107 {
108 BOOLEAN OwnerDefaulted;
109 NTSTATUS Status;
110
111 Status = RtlGetOwnerSecurityDescriptor(pSecurityDescriptor,
112 pOwner,
113 &OwnerDefaulted);
114 *lpbOwnerDefaulted = (BOOL)OwnerDefaulted;
115
116 if (!NT_SUCCESS(Status))
117 {
118 SetLastError(RtlNtStatusToDosError(Status));
119 return FALSE;
120 }
121
122 return TRUE;
123 }
124
125
126 /*
127 * @implemented
128 */
129 DWORD
130 WINAPI
131 GetSecurityDescriptorRMControl(PSECURITY_DESCRIPTOR SecurityDescriptor,
132 PUCHAR RMControl)
133 {
134 if (!RtlGetSecurityDescriptorRMControl(SecurityDescriptor,
135 RMControl))
136 return ERROR_INVALID_DATA;
137
138 return ERROR_SUCCESS;
139 }
140
141
142 /*
143 * @implemented
144 */
145 BOOL
146 WINAPI
147 GetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,
148 LPBOOL lpbSaclPresent,
149 PACL *pSacl,
150 LPBOOL lpbSaclDefaulted)
151 {
152 BOOLEAN SaclPresent;
153 BOOLEAN SaclDefaulted;
154 NTSTATUS Status;
155
156 Status = RtlGetSaclSecurityDescriptor(pSecurityDescriptor,
157 &SaclPresent,
158 pSacl,
159 &SaclDefaulted);
160 *lpbSaclPresent = (BOOL)SaclPresent;
161 *lpbSaclDefaulted = (BOOL)SaclDefaulted;
162
163 if (!NT_SUCCESS(Status))
164 {
165 SetLastError(RtlNtStatusToDosError(Status));
166 return FALSE;
167 }
168
169 return TRUE;
170 }
171
172
173 /*
174 * @implemented
175 */
176 BOOL
177 WINAPI
178 InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor,
179 DWORD dwRevision)
180 {
181 NTSTATUS Status;
182
183 Status = RtlCreateSecurityDescriptor(pSecurityDescriptor,
184 dwRevision);
185 if (!NT_SUCCESS(Status))
186 {
187 SetLastError(RtlNtStatusToDosError(Status));
188 return FALSE;
189 }
190
191 return TRUE;
192 }
193
194
195 /*
196 * @implemented
197 */
198 BOOL
199 WINAPI
200 IsValidSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor)
201 {
202 BOOLEAN Result;
203
204 Result = RtlValidSecurityDescriptor (pSecurityDescriptor);
205 if (Result == FALSE)
206 SetLastError(RtlNtStatusToDosError(STATUS_INVALID_SECURITY_DESCR));
207
208 return (BOOL)Result;
209 }
210
211
212 /*
213 * @implemented
214 */
215 BOOL
216 WINAPI
217 MakeAbsoluteSD(PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
218 PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
219 LPDWORD lpdwAbsoluteSecurityDescriptorSize,
220 PACL pDacl,
221 LPDWORD lpdwDaclSize,
222 PACL pSacl,
223 LPDWORD lpdwSaclSize,
224 PSID pOwner,
225 LPDWORD lpdwOwnerSize,
226 PSID pPrimaryGroup,
227 LPDWORD lpdwPrimaryGroupSize)
228 {
229 NTSTATUS Status;
230
231 Status = RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
232 pAbsoluteSecurityDescriptor,
233 lpdwAbsoluteSecurityDescriptorSize,
234 pDacl,
235 lpdwDaclSize,
236 pSacl,
237 lpdwSaclSize,
238 pOwner,
239 lpdwOwnerSize,
240 pPrimaryGroup,
241 lpdwPrimaryGroupSize);
242 if (!NT_SUCCESS(Status))
243 {
244 SetLastError(RtlNtStatusToDosError(Status));
245 return FALSE;
246 }
247
248 return TRUE;
249 }
250
251
252 /*
253 * @implemented
254 */
255 BOOL
256 WINAPI
257 MakeAbsoluteSD2(IN OUT PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
258 OUT LPDWORD lpdwBufferSize)
259 {
260 NTSTATUS Status;
261
262 Status = RtlSelfRelativeToAbsoluteSD2(pSelfRelativeSecurityDescriptor,
263 lpdwBufferSize);
264 if (!NT_SUCCESS(Status))
265 {
266 SetLastError(RtlNtStatusToDosError(Status));
267 return FALSE;
268 }
269
270 return TRUE;
271 }
272
273
274 /*
275 * @implemented
276 */
277 BOOL
278 WINAPI
279 MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
280 PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
281 LPDWORD lpdwBufferLength)
282 {
283 NTSTATUS Status;
284
285 Status = RtlAbsoluteToSelfRelativeSD(pAbsoluteSecurityDescriptor,
286 pSelfRelativeSecurityDescriptor,
287 (PULONG)lpdwBufferLength);
288 if (!NT_SUCCESS(Status))
289 {
290 SetLastError(RtlNtStatusToDosError(Status));
291 return FALSE;
292 }
293
294 return TRUE;
295 }
296
297
298 /*
299 * @implemented
300 */
301 BOOL
302 WINAPI
303 SetSecurityDescriptorControl(PSECURITY_DESCRIPTOR pSecurityDescriptor,
304 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
305 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet)
306 {
307 NTSTATUS Status;
308
309 Status = RtlSetControlSecurityDescriptor(pSecurityDescriptor,
310 ControlBitsOfInterest,
311 ControlBitsToSet);
312 if (!NT_SUCCESS(Status))
313 {
314 SetLastError(RtlNtStatusToDosError(Status));
315 return FALSE;
316 }
317
318 return TRUE;
319 }
320
321
322 /*
323 * @implemented
324 */
325 BOOL
326 WINAPI
327 SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,
328 BOOL bDaclPresent,
329 PACL pDacl,
330 BOOL bDaclDefaulted)
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 WINAPI
353 SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor,
354 PSID pGroup,
355 BOOL bGroupDefaulted)
356 {
357 NTSTATUS Status;
358
359 Status = RtlSetGroupSecurityDescriptor(pSecurityDescriptor,
360 pGroup,
361 bGroupDefaulted);
362 if (!NT_SUCCESS(Status))
363 {
364 SetLastError(RtlNtStatusToDosError(Status));
365 return FALSE;
366 }
367
368 return TRUE;
369 }
370
371
372 /*
373 * @implemented
374 */
375 BOOL
376 WINAPI
377 SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor,
378 PSID pOwner,
379 BOOL bOwnerDefaulted)
380 {
381 NTSTATUS Status;
382
383 Status = RtlSetOwnerSecurityDescriptor(pSecurityDescriptor,
384 pOwner,
385 bOwnerDefaulted);
386 if (!NT_SUCCESS(Status))
387 {
388 SetLastError(RtlNtStatusToDosError(Status));
389 return FALSE;
390 }
391
392 return TRUE;
393 }
394
395
396 /*
397 * @implemented
398 */
399 DWORD
400 WINAPI
401 SetSecurityDescriptorRMControl(PSECURITY_DESCRIPTOR SecurityDescriptor,
402 PUCHAR RMControl)
403 {
404 RtlSetSecurityDescriptorRMControl(SecurityDescriptor,
405 RMControl);
406
407 return ERROR_SUCCESS;
408 }
409
410
411 /*
412 * @implemented
413 */
414 BOOL
415 WINAPI
416 SetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,
417 BOOL bSaclPresent,
418 PACL pSacl,
419 BOOL bSaclDefaulted)
420 {
421 NTSTATUS Status;
422
423 Status = RtlSetSaclSecurityDescriptor(pSecurityDescriptor,
424 bSaclPresent,
425 pSacl,
426 bSaclDefaulted);
427 if (!NT_SUCCESS(Status))
428 {
429 SetLastError(RtlNtStatusToDosError(Status));
430 return FALSE;
431 }
432
433 return TRUE;
434 }
435
436
437 /*
438 * @implemented
439 */
440 VOID
441 WINAPI
442 QuerySecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation,
443 OUT LPDWORD DesiredAccess)
444 {
445 *DesiredAccess = 0;
446
447 if (SecurityInformation & (OWNER_SECURITY_INFORMATION |
448 GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION))
449 {
450 *DesiredAccess |= READ_CONTROL;
451 }
452
453 if (SecurityInformation & SACL_SECURITY_INFORMATION)
454 *DesiredAccess |= ACCESS_SYSTEM_SECURITY;
455 }
456
457
458 /*
459 * @implemented
460 */
461 VOID
462 WINAPI
463 SetSecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation,
464 OUT LPDWORD DesiredAccess)
465 {
466 *DesiredAccess = 0;
467
468 if (SecurityInformation & (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION))
469 *DesiredAccess |= WRITE_OWNER;
470
471 if (SecurityInformation & DACL_SECURITY_INFORMATION)
472 *DesiredAccess |= WRITE_DAC;
473
474 if (SecurityInformation & SACL_SECURITY_INFORMATION)
475 *DesiredAccess |= ACCESS_SYSTEM_SECURITY;
476 }
477
478
479 /*
480 * @unimplemented
481 */
482 BOOL
483 WINAPI
484 ConvertToAutoInheritPrivateObjectSecurity(IN PSECURITY_DESCRIPTOR ParentDescriptor,
485 IN PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
486 OUT PSECURITY_DESCRIPTOR* NewSecurityDescriptor,
487 IN GUID* ObjectType,
488 IN BOOLEAN IsDirectoryObject,
489 IN PGENERIC_MAPPING GenericMapping)
490 {
491 UNIMPLEMENTED;
492 return FALSE;
493 }
494
495
496 /*
497 * @unimplemented
498 */
499 DWORD
500 WINAPI
501 BuildSecurityDescriptorW(IN PTRUSTEE_W pOwner OPTIONAL,
502 IN PTRUSTEE_W pGroup OPTIONAL,
503 IN ULONG cCountOfAccessEntries,
504 IN PEXPLICIT_ACCESS_W pListOfAccessEntries OPTIONAL,
505 IN ULONG cCountOfAuditEntries,
506 IN PEXPLICIT_ACCESS_W pListOfAuditEntries OPTIONAL,
507 IN PSECURITY_DESCRIPTOR pOldSD OPTIONAL,
508 OUT PULONG pSizeNewSD,
509 OUT PSECURITY_DESCRIPTOR* pNewSD)
510 {
511 UNIMPLEMENTED;
512 return FALSE;
513 }
514
515
516 /*
517 * @unimplemented
518 */
519 DWORD
520 WINAPI
521 BuildSecurityDescriptorA(IN PTRUSTEE_A pOwner OPTIONAL,
522 IN PTRUSTEE_A pGroup OPTIONAL,
523 IN ULONG cCountOfAccessEntries,
524 IN PEXPLICIT_ACCESS_A pListOfAccessEntries OPTIONAL,
525 IN ULONG cCountOfAuditEntries,
526 IN PEXPLICIT_ACCESS_A pListOfAuditEntries OPTIONAL,
527 IN PSECURITY_DESCRIPTOR pOldSD OPTIONAL,
528 OUT PULONG pSizeNewSD,
529 OUT PSECURITY_DESCRIPTOR* pNewSD)
530 {
531 UNIMPLEMENTED;
532 return FALSE;
533 }
534
535 /* EOF */