1aeff4d2612c39710386a3b7c19e246fdff63896
[reactos.git] / reactos / ntoskrnl / ob / security.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Security manager
5 * FILE: ntoskrnl/ob/security.c
6 * PROGRAMER: ?
7 * REVISION HISTORY:
8 * 26/07/98: Added stubs for security functions
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <internal/ob.h>
15
16 #include <internal/debug.h>
17
18 /* FUNCTIONS ***************************************************************/
19
20 /*
21 * @implemented
22 */
23 NTSTATUS STDCALL
24 ObAssignSecurity(IN PACCESS_STATE AccessState,
25 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
26 IN PVOID Object,
27 IN POBJECT_TYPE Type)
28 {
29 PSECURITY_DESCRIPTOR NewDescriptor;
30 NTSTATUS Status;
31
32 /* Build the new security descriptor */
33 Status = SeAssignSecurity(SecurityDescriptor,
34 AccessState->SecurityDescriptor,
35 &NewDescriptor,
36 (Type == ObDirectoryType),
37 &AccessState->SubjectSecurityContext,
38 Type->Mapping,
39 PagedPool);
40 if (!NT_SUCCESS(Status))
41 return Status;
42
43 if (Type->Security != NULL)
44 {
45 /* Call the security method */
46 Status = Type->Security(Object,
47 AssignSecurityDescriptor,
48 0,
49 NewDescriptor,
50 NULL);
51 }
52 else
53 {
54 /* Assign the security descriptor to the object header */
55 Status = ObpAddSecurityDescriptor(NewDescriptor,
56 &(BODY_TO_HEADER(Object)->SecurityDescriptor));
57 }
58
59 /* Release the new security descriptor */
60 SeDeassignSecurity(&NewDescriptor);
61
62 return Status;
63 }
64
65
66 /*
67 * @unimplemented
68 */
69 NTSTATUS STDCALL
70 ObGetObjectSecurity(IN PVOID Object,
71 OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
72 OUT PBOOLEAN MemoryAllocated)
73 {
74 UNIMPLEMENTED;
75 return(STATUS_NOT_IMPLEMENTED);
76 }
77
78
79 /*
80 * @unimplemented
81 */
82 VOID STDCALL
83 ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
84 IN BOOLEAN MemoryAllocated)
85 {
86 UNIMPLEMENTED;
87 }
88
89
90 /*
91 * @implemented
92 */
93 NTSTATUS STDCALL
94 NtQuerySecurityObject(IN HANDLE Handle,
95 IN SECURITY_INFORMATION SecurityInformation,
96 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
97 IN ULONG Length,
98 OUT PULONG ResultLength)
99 {
100 POBJECT_HEADER Header;
101 PVOID Object;
102 NTSTATUS Status;
103
104 Status = ObReferenceObjectByHandle(Handle,
105 0,
106 NULL,
107 KeGetPreviousMode(),
108 &Object,
109 NULL);
110 if (!NT_SUCCESS(Status))
111 {
112 return(Status);
113 }
114
115 Header = BODY_TO_HEADER(Object);
116 if (Header->ObjectType == NULL &&
117 Header->ObjectType->Security != NULL)
118 {
119 Status = Header->ObjectType->Security(Object,
120 QuerySecurityDescriptor,
121 SecurityInformation,
122 SecurityDescriptor,
123 &Length);
124 *ResultLength = Length;
125 }
126 else
127 {
128 if (Header->SecurityDescriptor != NULL)
129 {
130 /* FIXME: Use SecurityInformation */
131 *ResultLength = RtlLengthSecurityDescriptor(Header->SecurityDescriptor);
132 if (Length >= *ResultLength)
133 {
134 RtlCopyMemory(SecurityDescriptor,
135 Header->SecurityDescriptor,
136 *ResultLength);
137
138 Status = STATUS_SUCCESS;
139 }
140 else
141 {
142 Status = STATUS_BUFFER_TOO_SMALL;
143 }
144 }
145 else
146 {
147 *ResultLength = 0;
148 Status = STATUS_UNSUCCESSFUL;
149 }
150 }
151
152 ObDereferenceObject(Object);
153
154 return Status;
155 }
156
157
158 /*
159 * @unimplemented
160 */
161 NTSTATUS STDCALL
162 NtSetSecurityObject(IN HANDLE Handle,
163 IN SECURITY_INFORMATION SecurityInformation,
164 IN PSECURITY_DESCRIPTOR SecurityDescriptor)
165 {
166 POBJECT_HEADER Header;
167 PVOID Object;
168 NTSTATUS Status;
169
170 Status = ObReferenceObjectByHandle(Handle,
171 0,
172 NULL,
173 KeGetPreviousMode(),
174 &Object,
175 NULL);
176 if (!NT_SUCCESS(Status))
177 {
178 return(Status);
179 }
180
181 Header = BODY_TO_HEADER(Object);
182 if (Header->ObjectType != NULL &&
183 Header->ObjectType->Security != NULL)
184 {
185 Status = Header->ObjectType->Security(Object,
186 SetSecurityDescriptor,
187 SecurityInformation,
188 SecurityDescriptor,
189 NULL);
190 }
191 else
192 {
193 Status = STATUS_NOT_IMPLEMENTED;
194 }
195
196 ObDereferenceObject(Object);
197
198 return(Status);
199 }
200
201 /* EOF */