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