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