update for HEAD-2003091401
[reactos.git] / lib / 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:         Registry 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  *                  Added a few new stubs 6/27/03
12  *                  Added stubs for GetSecurityInfo/Ex 8/18/03
13  */
14
15 #define NTOS_MODE_USER
16 #include <windows.h>
17 // #include <accctrl.h>
18 #include <ntos.h>
19
20
21 /*
22  * @implemented
23  */
24 BOOL
25 STDCALL
26 GetSecurityDescriptorControl (
27         PSECURITY_DESCRIPTOR            pSecurityDescriptor,
28         PSECURITY_DESCRIPTOR_CONTROL    pControl,
29         LPDWORD                         lpdwRevision
30         )
31 {
32         NTSTATUS Status;
33
34         Status = RtlGetControlSecurityDescriptor (pSecurityDescriptor,
35                                                   pControl,
36                                                   (PULONG)lpdwRevision);
37         if (!NT_SUCCESS(Status))
38         {
39                 SetLastError (RtlNtStatusToDosError (Status));
40                 return FALSE;
41         }
42
43         return TRUE;
44 }
45
46
47 /*
48  * @implemented
49  */
50 BOOL
51 STDCALL
52 GetSecurityDescriptorDacl (
53         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
54         LPBOOL                  lpbDaclPresent,
55         PACL                    *pDacl,
56         LPBOOL                  lpbDaclDefaulted
57         )
58 {
59         BOOLEAN DaclPresent;
60         BOOLEAN DaclDefaulted;
61         NTSTATUS Status;
62
63         Status = RtlGetDaclSecurityDescriptor (pSecurityDescriptor,
64                                                &DaclPresent,
65                                                pDacl,
66                                                &DaclDefaulted);
67         *lpbDaclPresent = (BOOL)DaclPresent;
68         *lpbDaclDefaulted = (BOOL)DaclDefaulted;
69
70         if (!NT_SUCCESS(Status))
71         {
72                 SetLastError (RtlNtStatusToDosError (Status));
73                 return FALSE;
74         }
75
76         return TRUE;
77 }
78
79
80 /*
81  * @implemented
82  */
83 BOOL
84 STDCALL
85 GetSecurityDescriptorGroup (
86         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
87         PSID                    *pGroup,
88         LPBOOL                  lpbGroupDefaulted
89         )
90 {
91         BOOLEAN GroupDefaulted;
92         NTSTATUS Status;
93
94         Status = RtlGetGroupSecurityDescriptor (pSecurityDescriptor,
95                                                 pGroup,
96                                                 &GroupDefaulted);
97         *lpbGroupDefaulted = (BOOL)GroupDefaulted;
98
99         if (!NT_SUCCESS(Status))
100         {
101                 SetLastError (RtlNtStatusToDosError (Status));
102                 return FALSE;
103         }
104
105         return TRUE;
106 }
107
108
109 /*
110  * @implemented
111  */
112 DWORD
113 STDCALL
114 GetSecurityDescriptorLength (
115         PSECURITY_DESCRIPTOR    pSecurityDescriptor
116         )
117 {
118         return RtlLengthSecurityDescriptor(pSecurityDescriptor);
119 }
120
121
122 /*
123  * @implemented
124  */
125 BOOL
126 STDCALL
127 GetSecurityDescriptorOwner (
128         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
129         PSID                    *pOwner,
130         LPBOOL                  lpbOwnerDefaulted
131 )
132 {
133         BOOLEAN OwnerDefaulted;
134         NTSTATUS Status;
135
136         Status = RtlGetOwnerSecurityDescriptor (pSecurityDescriptor,
137                                                 pOwner,
138                                                 &OwnerDefaulted);
139         *lpbOwnerDefaulted = (BOOL)OwnerDefaulted;
140
141         if (!NT_SUCCESS(Status))
142         {
143                 SetLastError (RtlNtStatusToDosError (Status));
144                 return FALSE;
145         }
146
147         return TRUE;
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 WINBOOL
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 WINBOOL
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 SetSecurityDescriptorDacl (
301         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
302         BOOL                    bDaclPresent,
303         PACL                    pDacl,
304         BOOL                    bDaclDefaulted
305         )
306 {
307         NTSTATUS Status;
308
309         Status = RtlSetDaclSecurityDescriptor (pSecurityDescriptor,
310                                                bDaclPresent,
311                                                pDacl,
312                                                bDaclDefaulted);
313         if (!NT_SUCCESS(Status))
314         {
315                 SetLastError (RtlNtStatusToDosError (Status));
316                 return FALSE;
317         }
318
319         return TRUE;
320 }
321
322
323 /*
324  * @implemented
325  */
326 BOOL
327 STDCALL
328 SetSecurityDescriptorGroup (
329         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
330         PSID                    pGroup,
331         BOOL                    bGroupDefaulted
332         )
333 {
334         NTSTATUS Status;
335
336         Status = RtlSetGroupSecurityDescriptor (pSecurityDescriptor,
337                                                 pGroup,
338                                                 bGroupDefaulted);
339         if (!NT_SUCCESS(Status))
340         {
341                 SetLastError (RtlNtStatusToDosError (Status));
342                 return FALSE;
343         }
344
345         return TRUE;
346 }
347
348
349 /*
350  * @implemented
351  */
352 BOOL
353 STDCALL
354 SetSecurityDescriptorOwner (
355         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
356         PSID                    pOwner,
357         BOOL                    bOwnerDefaulted
358         )
359 {
360         NTSTATUS Status;
361
362         Status = RtlSetGroupSecurityDescriptor (pSecurityDescriptor,
363                                                 pOwner,
364                                                 bOwnerDefaulted);
365         if (!NT_SUCCESS(Status))
366         {
367                 SetLastError (RtlNtStatusToDosError (Status));
368                 return FALSE;
369         }
370
371         return TRUE;
372 }
373
374
375 /*
376  * @implemented
377  */
378 BOOL
379 STDCALL
380 SetSecurityDescriptorSacl (
381         PSECURITY_DESCRIPTOR    pSecurityDescriptor,
382         BOOL                    bSaclPresent,
383         PACL                    pSacl,
384         BOOL                    bSaclDefaulted
385         )
386 {
387         NTSTATUS Status;
388
389         Status = RtlSetSaclSecurityDescriptor (pSecurityDescriptor,
390                                                bSaclPresent,
391                                                pSacl,
392                                                bSaclDefaulted);
393         if (!NT_SUCCESS(Status))
394         {
395                 SetLastError (RtlNtStatusToDosError (Status));
396                 return FALSE;
397         }
398
399         return TRUE;
400 }
401
402
403 /*
404  * @unimplemented
405  */
406 BOOL STDCALL
407 GetUserNameA(LPSTR lpBuffer, LPDWORD nSize)
408 {
409   return(FALSE);
410 }
411
412
413 /*
414  * @unimplemented
415  */
416 BOOL STDCALL
417 GetUserNameW(LPWSTR lpBuffer, LPDWORD nSize)
418 {
419   return(FALSE);
420 }
421
422
423 /*
424  * @unimplemented
425  */
426 WINBOOL
427 STDCALL
428 GetFileSecurityA (
429     LPCSTR lpFileName,
430     SECURITY_INFORMATION RequestedInformation,
431     PSECURITY_DESCRIPTOR pSecurityDescriptor,
432     DWORD nLength,
433     LPDWORD lpnLengthNeeded
434     )
435 {
436   return(FALSE);
437 }
438
439
440 /*
441  * @unimplemented
442  */
443 WINBOOL
444 STDCALL
445 GetFileSecurityW (
446     LPCWSTR lpFileName,
447     SECURITY_INFORMATION RequestedInformation,
448     PSECURITY_DESCRIPTOR pSecurityDescriptor,
449     DWORD nLength,
450     LPDWORD lpnLengthNeeded
451     )
452 {
453   return(FALSE);
454 }
455
456
457 /*
458  * @unimplemented
459  */
460 WINBOOL
461 STDCALL
462 SetFileSecurityA (
463     LPCSTR lpFileName,
464     SECURITY_INFORMATION SecurityInformation,
465     PSECURITY_DESCRIPTOR pSecurityDescriptor
466     )
467 {
468   return(FALSE);
469 }
470
471
472 /*
473  * @unimplemented
474  */
475 STDCALL DWORD GetSecurityInfo (
476     HANDLE handle,
477     UINT ObjectType,        // SE_OBJECT_TYPE
478     SECURITY_INFORMATION SecurityInfo,
479     PSID *ppsidOwner,
480     PSID *ppsidGroup,
481     PACL *ppDacl,
482     PACL *ppSacl,
483     PSECURITY_DESCRIPTOR *ppSecurityDescriptor
484     )
485 {
486     return FALSE;
487 }
488
489
490 /*
491  * @unimplemented
492  */
493 STDCALL DWORD GetSecurityInfoExA(
494     HANDLE hObject,
495     UINT ObjectType,        // SE_OBJECT_TYPE
496     SECURITY_INFORMATION SecurityInfo,
497     LPCSTR lpProvider,
498     LPCSTR lpProperty,
499     VOID *ppAccessList,     // PACTRL_ACCESS
500     VOID *ppAuditList,      // PACTRL_AUDIT
501     LPCSTR *lppOwner,
502     LPCSTR *lppGroup
503     )
504 {
505     return FALSE;
506 }
507
508
509 /*
510  * @unimplemented
511  */
512 STDCALL DWORD GetSecurityInfoExW(
513     HANDLE hObject,
514     UINT ObjectType,        // SE_OBJECT_TYPE
515     SECURITY_INFORMATION SecurityInfo,
516     LPCWSTR lpProvider,
517     LPCWSTR lpProperty,
518     VOID *ppAccessList,     // PACTRL_ACCESS
519     VOID *ppAuditList,      // PACTRL_AUDIT
520     LPWSTR *lppOwner,
521     LPWSTR *lppGroup
522     )
523 {
524     return FALSE;
525 }
526
527
528 /* EOF */