1 | /*
|
---|
2 | * Object management functions
|
---|
3 | *
|
---|
4 | * Copyright 1999, 2000 Juergen Schmied
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <string.h>
|
---|
23 | #include <unistd.h>
|
---|
24 | #include "wine/debug.h"
|
---|
25 |
|
---|
26 | #include "ntddk.h"
|
---|
27 | #include "ntdll_misc.h"
|
---|
28 | #include "wine/server.h"
|
---|
29 |
|
---|
30 | WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
---|
31 |
|
---|
32 | /* move to somewhere */
|
---|
33 | typedef void * POBJDIR_INFORMATION;
|
---|
34 |
|
---|
35 | /*
|
---|
36 | * Generic object functions
|
---|
37 | */
|
---|
38 |
|
---|
39 | /******************************************************************************
|
---|
40 | * NtQueryObject [NTDLL.@]
|
---|
41 | * ZwQueryObject [NTDLL.@]
|
---|
42 | */
|
---|
43 | NTSTATUS WINAPI NtQueryObject(
|
---|
44 | IN HANDLE ObjectHandle,
|
---|
45 | IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
|
---|
46 | OUT PVOID ObjectInformation,
|
---|
47 | IN ULONG Length,
|
---|
48 | OUT PULONG ResultLength)
|
---|
49 | {
|
---|
50 | FIXME("(0x%08x,0x%08x,%p,0x%08lx,%p): stub\n",
|
---|
51 | ObjectHandle, ObjectInformationClass, ObjectInformation, Length, ResultLength);
|
---|
52 | return 0;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /******************************************************************************
|
---|
56 | * NtQuerySecurityObject [NTDLL.@]
|
---|
57 | *
|
---|
58 | * analogue to GetKernelObjectSecurity
|
---|
59 | *
|
---|
60 | * NOTES
|
---|
61 | * only the lowest 4 bit of SecurityObjectInformationClass are used
|
---|
62 | * 0x7-0xf returns STATUS_ACCESS_DENIED (even running with system privileges)
|
---|
63 | *
|
---|
64 | * FIXME: we are constructing a fake sid
|
---|
65 | * (Administrators:Full, System:Full, Everyone:Read)
|
---|
66 | */
|
---|
67 | NTSTATUS WINAPI
|
---|
68 | NtQuerySecurityObject(
|
---|
69 | IN HANDLE Object,
|
---|
70 | IN SECURITY_INFORMATION RequestedInformation,
|
---|
71 | OUT PSECURITY_DESCRIPTOR pSecurityDesriptor,
|
---|
72 | IN ULONG Length,
|
---|
73 | OUT PULONG ResultLength)
|
---|
74 | {
|
---|
75 | static SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
|
---|
76 | static SID_IDENTIFIER_AUTHORITY worldSidAuthority = {SECURITY_WORLD_SID_AUTHORITY};
|
---|
77 | BYTE Buffer[256];
|
---|
78 | PISECURITY_DESCRIPTOR_RELATIVE psd = (PISECURITY_DESCRIPTOR_RELATIVE)Buffer;
|
---|
79 | UINT BufferIndex = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
---|
80 |
|
---|
81 | FIXME("(0x%08x,0x%08lx,%p,0x%08lx,%p) stub!\n",
|
---|
82 | Object, RequestedInformation, pSecurityDesriptor, Length, ResultLength);
|
---|
83 |
|
---|
84 | RequestedInformation &= 0x0000000f;
|
---|
85 |
|
---|
86 | if (RequestedInformation & SACL_SECURITY_INFORMATION) return STATUS_ACCESS_DENIED;
|
---|
87 |
|
---|
88 | ZeroMemory(Buffer, 256);
|
---|
89 | RtlCreateSecurityDescriptor((PSECURITY_DESCRIPTOR)psd, SECURITY_DESCRIPTOR_REVISION);
|
---|
90 | psd->Control = SE_SELF_RELATIVE |
|
---|
91 | ((RequestedInformation & DACL_SECURITY_INFORMATION) ? SE_DACL_PRESENT:0);
|
---|
92 |
|
---|
93 | /* owner: administrator S-1-5-20-220*/
|
---|
94 | if (OWNER_SECURITY_INFORMATION & RequestedInformation)
|
---|
95 | {
|
---|
96 | PSID psid = (PSID)&(Buffer[BufferIndex]);
|
---|
97 |
|
---|
98 | psd->Owner = BufferIndex;
|
---|
99 | BufferIndex += RtlLengthRequiredSid(2);
|
---|
100 |
|
---|
101 | psid->Revision = SID_REVISION;
|
---|
102 | psid->SubAuthorityCount = 2;
|
---|
103 | psid->IdentifierAuthority = localSidAuthority;
|
---|
104 | psid->SubAuthority[0] = SECURITY_BUILTIN_DOMAIN_RID;
|
---|
105 | psid->SubAuthority[1] = DOMAIN_ALIAS_RID_ADMINS;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* group: built in domain S-1-5-12 */
|
---|
109 | if (GROUP_SECURITY_INFORMATION & RequestedInformation)
|
---|
110 | {
|
---|
111 | PSID psid = (PSID) &(Buffer[BufferIndex]);
|
---|
112 |
|
---|
113 | psd->Group = BufferIndex;
|
---|
114 | BufferIndex += RtlLengthRequiredSid(1);
|
---|
115 |
|
---|
116 | psid->Revision = SID_REVISION;
|
---|
117 | psid->SubAuthorityCount = 1;
|
---|
118 | psid->IdentifierAuthority = localSidAuthority;
|
---|
119 | psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* discretionary ACL */
|
---|
123 | if (DACL_SECURITY_INFORMATION & RequestedInformation)
|
---|
124 | {
|
---|
125 | /* acl header */
|
---|
126 | PACL pacl = (PACL)&(Buffer[BufferIndex]);
|
---|
127 | PACCESS_ALLOWED_ACE pace;
|
---|
128 | PSID psid;
|
---|
129 |
|
---|
130 | psd->Dacl = BufferIndex;
|
---|
131 |
|
---|
132 | pacl->AclRevision = MIN_ACL_REVISION;
|
---|
133 | pacl->AceCount = 3;
|
---|
134 | pacl->AclSize = BufferIndex; /* storing the start index temporary */
|
---|
135 |
|
---|
136 | BufferIndex += sizeof(ACL);
|
---|
137 |
|
---|
138 | /* ACE System - full access */
|
---|
139 | pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
|
---|
140 | BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
|
---|
141 |
|
---|
142 | pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
|
---|
143 | pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
|
---|
144 | pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(1);
|
---|
145 | pace->Mask = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | 0x3f;
|
---|
146 | pace->SidStart = BufferIndex;
|
---|
147 |
|
---|
148 | /* SID S-1-5-12 (System) */
|
---|
149 | psid = (PSID)&(Buffer[BufferIndex]);
|
---|
150 |
|
---|
151 | BufferIndex += RtlLengthRequiredSid(1);
|
---|
152 |
|
---|
153 | psid->Revision = SID_REVISION;
|
---|
154 | psid->SubAuthorityCount = 1;
|
---|
155 | psid->IdentifierAuthority = localSidAuthority;
|
---|
156 | psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
|
---|
157 |
|
---|
158 | /* ACE Administrators - full access*/
|
---|
159 | pace = (PACCESS_ALLOWED_ACE) &(Buffer[BufferIndex]);
|
---|
160 | BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
|
---|
161 |
|
---|
162 | pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
|
---|
163 | pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
|
---|
164 | pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(2);
|
---|
165 | pace->Mask = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | 0x3f;
|
---|
166 | pace->SidStart = BufferIndex;
|
---|
167 |
|
---|
168 | /* S-1-5-12 (Administrators) */
|
---|
169 | psid = (PSID)&(Buffer[BufferIndex]);
|
---|
170 |
|
---|
171 | BufferIndex += RtlLengthRequiredSid(2);
|
---|
172 |
|
---|
173 | psid->Revision = SID_REVISION;
|
---|
174 | psid->SubAuthorityCount = 2;
|
---|
175 | psid->IdentifierAuthority = localSidAuthority;
|
---|
176 | psid->SubAuthority[0] = SECURITY_BUILTIN_DOMAIN_RID;
|
---|
177 | psid->SubAuthority[1] = DOMAIN_ALIAS_RID_ADMINS;
|
---|
178 |
|
---|
179 | /* ACE Everyone - read access */
|
---|
180 | pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
|
---|
181 | BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
|
---|
182 |
|
---|
183 | pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
|
---|
184 | pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
|
---|
185 | pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(1);
|
---|
186 | pace->Mask = READ_CONTROL| 0x19;
|
---|
187 | pace->SidStart = BufferIndex;
|
---|
188 |
|
---|
189 | /* SID S-1-1-0 (Everyone) */
|
---|
190 | psid = (PSID)&(Buffer[BufferIndex]);
|
---|
191 |
|
---|
192 | BufferIndex += RtlLengthRequiredSid(1);
|
---|
193 |
|
---|
194 | psid->Revision = SID_REVISION;
|
---|
195 | psid->SubAuthorityCount = 1;
|
---|
196 | psid->IdentifierAuthority = worldSidAuthority;
|
---|
197 | psid->SubAuthority[0] = 0;
|
---|
198 |
|
---|
199 | /* calculate used bytes */
|
---|
200 | pacl->AclSize = BufferIndex - pacl->AclSize;
|
---|
201 | }
|
---|
202 | *ResultLength = BufferIndex;
|
---|
203 | TRACE("len=%lu\n", *ResultLength);
|
---|
204 | if (Length < *ResultLength) return STATUS_BUFFER_TOO_SMALL;
|
---|
205 | memcpy(pSecurityDesriptor, Buffer, *ResultLength);
|
---|
206 |
|
---|
207 | return STATUS_SUCCESS;
|
---|
208 | }
|
---|
209 | /******************************************************************************
|
---|
210 | * NtDuplicateObject [NTDLL.@]
|
---|
211 | * ZwDuplicateObject [NTDLL.@]
|
---|
212 | */
|
---|
213 | NTSTATUS WINAPI NtDuplicateObject(
|
---|
214 | IN HANDLE SourceProcessHandle,
|
---|
215 | IN PHANDLE SourceHandle,
|
---|
216 | IN HANDLE TargetProcessHandle,
|
---|
217 | OUT PHANDLE TargetHandle,
|
---|
218 | IN ACCESS_MASK DesiredAccess,
|
---|
219 | IN BOOLEAN InheritHandle,
|
---|
220 | ULONG Options)
|
---|
221 | {
|
---|
222 | FIXME("(0x%08x,%p,0x%08x,%p,0x%08lx,0x%08x,0x%08lx) stub!\n",
|
---|
223 | SourceProcessHandle,SourceHandle,TargetProcessHandle,TargetHandle,
|
---|
224 | DesiredAccess,InheritHandle,Options);
|
---|
225 | *TargetHandle = 0;
|
---|
226 | return 0;
|
---|
227 | }
|
---|
228 |
|
---|
229 | /**************************************************************************
|
---|
230 | * NtClose [NTDLL.@]
|
---|
231 | * FUNCTION: Closes a handle reference to an object
|
---|
232 | * ARGUMENTS:
|
---|
233 | * Handle handle to close
|
---|
234 | */
|
---|
235 | NTSTATUS WINAPI NtClose( HANDLE Handle )
|
---|
236 | {
|
---|
237 | #ifdef __WIN32OS2__
|
---|
238 | if (CloseHandle(Handle))
|
---|
239 | return STATUS_SUCCESS;
|
---|
240 | return STATUS_UNSUCCESSFUL; /*fixme*/
|
---|
241 | #else
|
---|
242 | NTSTATUS ret;
|
---|
243 | SERVER_START_REQ( close_handle )
|
---|
244 | {
|
---|
245 | req->handle = Handle;
|
---|
246 | ret = wine_server_call( req );
|
---|
247 | if (!ret && reply->fd != -1) close( reply->fd );
|
---|
248 | }
|
---|
249 | SERVER_END_REQ;
|
---|
250 | return ret;
|
---|
251 | #endif
|
---|
252 | }
|
---|
253 |
|
---|
254 | /******************************************************************************
|
---|
255 | * NtWaitForSingleObject [NTDLL.@]
|
---|
256 | * ZwWaitForSingleObject [NTDLL.@]
|
---|
257 | */
|
---|
258 | NTSTATUS WINAPI NtWaitForSingleObject(
|
---|
259 | IN PHANDLE Object,
|
---|
260 | IN BOOLEAN Alertable,
|
---|
261 | IN PLARGE_INTEGER Time)
|
---|
262 | {
|
---|
263 | FIXME("(%p,0x%08x,%p),stub!\n",Object,Alertable,Time);
|
---|
264 | return 0;
|
---|
265 | }
|
---|
266 |
|
---|
267 | /*
|
---|
268 | * Directory functions
|
---|
269 | */
|
---|
270 |
|
---|
271 | /**************************************************************************
|
---|
272 | * NtOpenDirectoryObject [NTDLL.@]
|
---|
273 | * ZwOpenDirectoryObject [NTDLL.@]
|
---|
274 | * FUNCTION: Opens a namespace directory object
|
---|
275 | * ARGUMENTS:
|
---|
276 | * DirectoryHandle Variable which receives the directory handle
|
---|
277 | * DesiredAccess Desired access to the directory
|
---|
278 | * ObjectAttributes Structure describing the directory
|
---|
279 | * RETURNS: Status
|
---|
280 | */
|
---|
281 | NTSTATUS WINAPI NtOpenDirectoryObject(
|
---|
282 | PHANDLE DirectoryHandle,
|
---|
283 | ACCESS_MASK DesiredAccess,
|
---|
284 | POBJECT_ATTRIBUTES ObjectAttributes)
|
---|
285 | {
|
---|
286 | FIXME("(%p,0x%08lx,%p): stub\n",
|
---|
287 | DirectoryHandle, DesiredAccess, ObjectAttributes);
|
---|
288 | dump_ObjectAttributes(ObjectAttributes);
|
---|
289 | return 0;
|
---|
290 | }
|
---|
291 |
|
---|
292 | /******************************************************************************
|
---|
293 | * NtCreateDirectoryObject [NTDLL.@]
|
---|
294 | * ZwCreateDirectoryObject [NTDLL.@]
|
---|
295 | */
|
---|
296 | NTSTATUS WINAPI NtCreateDirectoryObject(
|
---|
297 | PHANDLE DirectoryHandle,
|
---|
298 | ACCESS_MASK DesiredAccess,
|
---|
299 | POBJECT_ATTRIBUTES ObjectAttributes)
|
---|
300 | {
|
---|
301 | FIXME("(%p,0x%08lx,%p),stub!\n",
|
---|
302 | DirectoryHandle,DesiredAccess,ObjectAttributes);
|
---|
303 | dump_ObjectAttributes(ObjectAttributes);
|
---|
304 | return 0;
|
---|
305 | }
|
---|
306 |
|
---|
307 | /******************************************************************************
|
---|
308 | * NtQueryDirectoryObject [NTDLL.@]
|
---|
309 | * ZwQueryDirectoryObject [NTDLL.@]
|
---|
310 | * FUNCTION: Reads information from a namespace directory
|
---|
311 | * ARGUMENTS:
|
---|
312 | * DirObjInformation Buffer to hold the data read
|
---|
313 | * BufferLength Size of the buffer in bytes
|
---|
314 | * GetNextIndex If TRUE then set ObjectIndex to the index of the next object
|
---|
315 | * If FALSE then set ObjectIndex to the number of objects in the directory
|
---|
316 | * IgnoreInputIndex If TRUE start reading at index 0
|
---|
317 | * If FALSE start reading at the index specified by object index
|
---|
318 | * ObjectIndex Zero based index into the directory, interpretation depends on IgnoreInputIndex and GetNextIndex
|
---|
319 | * DataWritten Caller supplied storage for the number of bytes written (or NULL)
|
---|
320 | */
|
---|
321 | NTSTATUS WINAPI NtQueryDirectoryObject(
|
---|
322 | IN HANDLE DirObjHandle,
|
---|
323 | OUT POBJDIR_INFORMATION DirObjInformation,
|
---|
324 | IN ULONG BufferLength,
|
---|
325 | IN BOOLEAN GetNextIndex,
|
---|
326 | IN BOOLEAN IgnoreInputIndex,
|
---|
327 | IN OUT PULONG ObjectIndex,
|
---|
328 | OUT PULONG DataWritten OPTIONAL)
|
---|
329 | {
|
---|
330 | FIXME("(0x%08x,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
|
---|
331 | DirObjHandle, DirObjInformation, BufferLength, GetNextIndex,
|
---|
332 | IgnoreInputIndex, ObjectIndex, DataWritten);
|
---|
333 | return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
|
---|
334 | }
|
---|
335 |
|
---|
336 | /*
|
---|
337 | * Link objects
|
---|
338 | */
|
---|
339 |
|
---|
340 | /******************************************************************************
|
---|
341 | * NtOpenSymbolicLinkObject [NTDLL.@]
|
---|
342 | */
|
---|
343 | NTSTATUS WINAPI NtOpenSymbolicLinkObject(
|
---|
344 | OUT PHANDLE LinkHandle,
|
---|
345 | IN ACCESS_MASK DesiredAccess,
|
---|
346 | IN POBJECT_ATTRIBUTES ObjectAttributes)
|
---|
347 | {
|
---|
348 | FIXME("(%p,0x%08lx,%p) stub\n",
|
---|
349 | LinkHandle, DesiredAccess, ObjectAttributes);
|
---|
350 | dump_ObjectAttributes(ObjectAttributes);
|
---|
351 | return 0;
|
---|
352 | }
|
---|
353 |
|
---|
354 | /******************************************************************************
|
---|
355 | * NtCreateSymbolicLinkObject [NTDLL.@]
|
---|
356 | */
|
---|
357 | NTSTATUS WINAPI NtCreateSymbolicLinkObject(
|
---|
358 | OUT PHANDLE SymbolicLinkHandle,
|
---|
359 | IN ACCESS_MASK DesiredAccess,
|
---|
360 | IN POBJECT_ATTRIBUTES ObjectAttributes,
|
---|
361 | IN PUNICODE_STRING Name)
|
---|
362 | {
|
---|
363 | FIXME("(%p,0x%08lx,%p, %p) stub\n",
|
---|
364 | SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_us(Name));
|
---|
365 | dump_ObjectAttributes(ObjectAttributes);
|
---|
366 | return 0;
|
---|
367 | }
|
---|
368 |
|
---|
369 | /******************************************************************************
|
---|
370 | * NtQuerySymbolicLinkObject [NTDLL.@]
|
---|
371 | */
|
---|
372 | NTSTATUS WINAPI NtQuerySymbolicLinkObject(
|
---|
373 | IN HANDLE LinkHandle,
|
---|
374 | IN OUT PUNICODE_STRING LinkTarget,
|
---|
375 | OUT PULONG ReturnedLength OPTIONAL)
|
---|
376 | {
|
---|
377 | FIXME("(0x%08x,%p,%p) stub\n",
|
---|
378 | LinkHandle, debugstr_us(LinkTarget), ReturnedLength);
|
---|
379 |
|
---|
380 | return 0;
|
---|
381 | }
|
---|
382 |
|
---|