Added generic signal handling mechanism based on pipes to synchronize
[wine/multimedia.git] / dlls / ntdll / om.c
blobbbd371d2aabc9627b914d5e5acb2385561e60215
1 /*
2 * Object management functions
4 * Copyright 1999, 2000 Juergen Schmied
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.
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.
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_IO_H
26 # include <io.h>
27 #endif
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
31 #include "wine/debug.h"
33 #include "winternl.h"
34 #include "ntdll_misc.h"
35 #include "wine/server.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
39 /* move to somewhere */
40 typedef void * POBJDIR_INFORMATION;
43 * Generic object functions
46 /******************************************************************************
47 * NtQueryObject [NTDLL.@]
48 * ZwQueryObject [NTDLL.@]
50 NTSTATUS WINAPI NtQueryObject(
51 IN HANDLE ObjectHandle,
52 IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
53 OUT PVOID ObjectInformation,
54 IN ULONG Length,
55 OUT PULONG ResultLength)
57 FIXME("(%p,0x%08x,%p,0x%08lx,%p): stub\n",
58 ObjectHandle, ObjectInformationClass, ObjectInformation, Length, ResultLength);
59 return 0;
62 /******************************************************************************
63 * NtQuerySecurityObject [NTDLL.@]
65 * An ntdll analogue to GetKernelObjectSecurity().
67 * NOTES
68 * only the lowest 4 bit of SecurityObjectInformationClass are used
69 * 0x7-0xf returns STATUS_ACCESS_DENIED (even running with system privileges)
71 * FIXME
72 * We are constructing a fake sid (Administrators:Full, System:Full, Everyone:Read)
74 NTSTATUS WINAPI
75 NtQuerySecurityObject(
76 IN HANDLE Object,
77 IN SECURITY_INFORMATION RequestedInformation,
78 OUT PSECURITY_DESCRIPTOR pSecurityDesriptor,
79 IN ULONG Length,
80 OUT PULONG ResultLength)
82 static SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
83 static SID_IDENTIFIER_AUTHORITY worldSidAuthority = {SECURITY_WORLD_SID_AUTHORITY};
84 BYTE Buffer[256];
85 PISECURITY_DESCRIPTOR_RELATIVE psd = (PISECURITY_DESCRIPTOR_RELATIVE)Buffer;
86 UINT BufferIndex = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
88 FIXME("(%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
89 Object, RequestedInformation, pSecurityDesriptor, Length, ResultLength);
91 RequestedInformation &= 0x0000000f;
93 if (RequestedInformation & SACL_SECURITY_INFORMATION) return STATUS_ACCESS_DENIED;
95 ZeroMemory(Buffer, 256);
96 RtlCreateSecurityDescriptor((PSECURITY_DESCRIPTOR)psd, SECURITY_DESCRIPTOR_REVISION);
97 psd->Control = SE_SELF_RELATIVE |
98 ((RequestedInformation & DACL_SECURITY_INFORMATION) ? SE_DACL_PRESENT:0);
100 /* owner: administrator S-1-5-20-220*/
101 if (OWNER_SECURITY_INFORMATION & RequestedInformation)
103 PSID psid = (PSID)&(Buffer[BufferIndex]);
105 psd->Owner = BufferIndex;
106 BufferIndex += RtlLengthRequiredSid(2);
108 psid->Revision = SID_REVISION;
109 psid->SubAuthorityCount = 2;
110 psid->IdentifierAuthority = localSidAuthority;
111 psid->SubAuthority[0] = SECURITY_BUILTIN_DOMAIN_RID;
112 psid->SubAuthority[1] = DOMAIN_ALIAS_RID_ADMINS;
115 /* group: built in domain S-1-5-12 */
116 if (GROUP_SECURITY_INFORMATION & RequestedInformation)
118 PSID psid = (PSID) &(Buffer[BufferIndex]);
120 psd->Group = BufferIndex;
121 BufferIndex += RtlLengthRequiredSid(1);
123 psid->Revision = SID_REVISION;
124 psid->SubAuthorityCount = 1;
125 psid->IdentifierAuthority = localSidAuthority;
126 psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
129 /* discretionary ACL */
130 if (DACL_SECURITY_INFORMATION & RequestedInformation)
132 /* acl header */
133 PACL pacl = (PACL)&(Buffer[BufferIndex]);
134 PACCESS_ALLOWED_ACE pace;
135 PSID psid;
137 psd->Dacl = BufferIndex;
139 pacl->AclRevision = MIN_ACL_REVISION;
140 pacl->AceCount = 3;
141 pacl->AclSize = BufferIndex; /* storing the start index temporary */
143 BufferIndex += sizeof(ACL);
145 /* ACE System - full access */
146 pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
147 BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
149 pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
150 pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
151 pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(1);
152 pace->Mask = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | 0x3f;
153 pace->SidStart = BufferIndex;
155 /* SID S-1-5-12 (System) */
156 psid = (PSID)&(Buffer[BufferIndex]);
158 BufferIndex += RtlLengthRequiredSid(1);
160 psid->Revision = SID_REVISION;
161 psid->SubAuthorityCount = 1;
162 psid->IdentifierAuthority = localSidAuthority;
163 psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
165 /* ACE Administrators - full access*/
166 pace = (PACCESS_ALLOWED_ACE) &(Buffer[BufferIndex]);
167 BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
169 pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
170 pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
171 pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(2);
172 pace->Mask = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | 0x3f;
173 pace->SidStart = BufferIndex;
175 /* S-1-5-12 (Administrators) */
176 psid = (PSID)&(Buffer[BufferIndex]);
178 BufferIndex += RtlLengthRequiredSid(2);
180 psid->Revision = SID_REVISION;
181 psid->SubAuthorityCount = 2;
182 psid->IdentifierAuthority = localSidAuthority;
183 psid->SubAuthority[0] = SECURITY_BUILTIN_DOMAIN_RID;
184 psid->SubAuthority[1] = DOMAIN_ALIAS_RID_ADMINS;
186 /* ACE Everyone - read access */
187 pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
188 BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
190 pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
191 pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
192 pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(1);
193 pace->Mask = READ_CONTROL| 0x19;
194 pace->SidStart = BufferIndex;
196 /* SID S-1-1-0 (Everyone) */
197 psid = (PSID)&(Buffer[BufferIndex]);
199 BufferIndex += RtlLengthRequiredSid(1);
201 psid->Revision = SID_REVISION;
202 psid->SubAuthorityCount = 1;
203 psid->IdentifierAuthority = worldSidAuthority;
204 psid->SubAuthority[0] = 0;
206 /* calculate used bytes */
207 pacl->AclSize = BufferIndex - pacl->AclSize;
209 *ResultLength = BufferIndex;
210 TRACE("len=%lu\n", *ResultLength);
211 if (Length < *ResultLength) return STATUS_BUFFER_TOO_SMALL;
212 memcpy(pSecurityDesriptor, Buffer, *ResultLength);
214 return STATUS_SUCCESS;
218 /******************************************************************************
219 * NtDuplicateObject [NTDLL.@]
220 * ZwDuplicateObject [NTDLL.@]
222 NTSTATUS WINAPI NtDuplicateObject( HANDLE source_process, HANDLE source,
223 HANDLE dest_process, PHANDLE dest,
224 ACCESS_MASK access, ULONG attributes, ULONG options )
226 NTSTATUS ret;
227 SERVER_START_REQ( dup_handle )
229 req->src_process = source_process;
230 req->src_handle = source;
231 req->dst_process = dest_process;
232 req->access = access;
233 req->inherit = (attributes & OBJ_INHERIT) != 0;
234 req->options = options;
236 if (!(ret = wine_server_call( req )))
238 if (dest) *dest = reply->handle;
239 if (reply->fd != -1) close( reply->fd );
242 SERVER_END_REQ;
243 return ret;
246 /**************************************************************************
247 * NtClose [NTDLL.@]
249 * Close a handle reference to an object.
251 * PARAMS
252 * Handle [I] handle to close
254 * RETURNS
255 * Success: ERROR_SUCCESS.
256 * Failure: An NTSTATUS error code.
258 NTSTATUS WINAPI NtClose( HANDLE Handle )
260 NTSTATUS ret;
261 SERVER_START_REQ( close_handle )
263 req->handle = Handle;
264 ret = wine_server_call( req );
265 if (!ret && reply->fd != -1) close( reply->fd );
267 SERVER_END_REQ;
268 return ret;
271 /******************************************************************************
272 * NtWaitForSingleObject [NTDLL.@]
273 * ZwWaitForSingleObject [NTDLL.@]
275 NTSTATUS WINAPI NtWaitForSingleObject(
276 IN HANDLE Object,
277 IN BOOLEAN Alertable,
278 IN PLARGE_INTEGER Time)
280 FIXME("(%p,0x%08x,%p),stub!\n",Object,Alertable,Time);
281 return 0;
285 * Directory functions
288 /**************************************************************************
289 * NtOpenDirectoryObject [NTDLL.@]
290 * ZwOpenDirectoryObject [NTDLL.@]
292 * Open a namespace directory object.
294 * PARAMS
295 * DirectoryHandle [O] Destination for the new directory handle
296 * DesiredAccess [I] Desired access to the directory
297 * ObjectAttributes [I] Structure describing the directory
299 * RETURNS
300 * Success: ERROR_SUCCESS.
301 * Failure: An NTSTATUS error code.
303 NTSTATUS WINAPI NtOpenDirectoryObject(
304 PHANDLE DirectoryHandle,
305 ACCESS_MASK DesiredAccess,
306 POBJECT_ATTRIBUTES ObjectAttributes)
308 FIXME("(%p,0x%08lx,%p): stub\n",
309 DirectoryHandle, DesiredAccess, ObjectAttributes);
310 dump_ObjectAttributes(ObjectAttributes);
311 return 0;
314 /******************************************************************************
315 * NtCreateDirectoryObject [NTDLL.@]
316 * ZwCreateDirectoryObject [NTDLL.@]
318 NTSTATUS WINAPI NtCreateDirectoryObject(
319 PHANDLE DirectoryHandle,
320 ACCESS_MASK DesiredAccess,
321 POBJECT_ATTRIBUTES ObjectAttributes)
323 FIXME("(%p,0x%08lx,%p),stub!\n",
324 DirectoryHandle,DesiredAccess,ObjectAttributes);
325 dump_ObjectAttributes(ObjectAttributes);
326 return 0;
329 /******************************************************************************
330 * NtQueryDirectoryObject [NTDLL.@]
331 * ZwQueryDirectoryObject [NTDLL.@]
333 * Read information from a namespace directory.
335 * PARAMS
336 * DirObjHandle [I] Object handle
337 * DirObjInformation [O] Buffer to hold the data read
338 * BufferLength [I] Size of the buffer in bytes
339 * GetNextIndex [I] Set ObjectIndex to TRUE=next object, FALSE=last object
340 * IgnoreInputIndex [I] Start reading at index TRUE=0, FALSE=ObjectIndex
341 * ObjectIndex [I/O] 0 based index into the directory, see IgnoreInputIndex and GetNextIndex
342 * DataWritten [O] Caller supplied storage for the number of bytes written (or NULL)
344 * RETURNS
345 * Success: ERROR_SUCCESS.
346 * Failure: An NTSTATUS error code.
348 NTSTATUS WINAPI NtQueryDirectoryObject(
349 IN HANDLE DirObjHandle,
350 OUT POBJDIR_INFORMATION DirObjInformation,
351 IN ULONG BufferLength,
352 IN BOOLEAN GetNextIndex,
353 IN BOOLEAN IgnoreInputIndex,
354 IN OUT PULONG ObjectIndex,
355 OUT PULONG DataWritten OPTIONAL)
357 FIXME("(%p,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
358 DirObjHandle, DirObjInformation, BufferLength, GetNextIndex,
359 IgnoreInputIndex, ObjectIndex, DataWritten);
360 return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
364 * Link objects
367 /******************************************************************************
368 * NtOpenSymbolicLinkObject [NTDLL.@]
370 NTSTATUS WINAPI NtOpenSymbolicLinkObject(
371 OUT PHANDLE LinkHandle,
372 IN ACCESS_MASK DesiredAccess,
373 IN POBJECT_ATTRIBUTES ObjectAttributes)
375 FIXME("(%p,0x%08lx,%p) stub\n",
376 LinkHandle, DesiredAccess, ObjectAttributes);
377 dump_ObjectAttributes(ObjectAttributes);
378 return 0;
381 /******************************************************************************
382 * NtCreateSymbolicLinkObject [NTDLL.@]
384 NTSTATUS WINAPI NtCreateSymbolicLinkObject(
385 OUT PHANDLE SymbolicLinkHandle,
386 IN ACCESS_MASK DesiredAccess,
387 IN POBJECT_ATTRIBUTES ObjectAttributes,
388 IN PUNICODE_STRING Name)
390 FIXME("(%p,0x%08lx,%p, %p) stub\n",
391 SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_us(Name));
392 dump_ObjectAttributes(ObjectAttributes);
393 return 0;
396 /******************************************************************************
397 * NtQuerySymbolicLinkObject [NTDLL.@]
399 NTSTATUS WINAPI NtQuerySymbolicLinkObject(
400 IN HANDLE LinkHandle,
401 IN OUT PUNICODE_STRING LinkTarget,
402 OUT PULONG ReturnedLength OPTIONAL)
404 FIXME("(%p,%p,%p) stub\n",
405 LinkHandle, debugstr_us(LinkTarget), ReturnedLength);
407 return 0;
410 /******************************************************************************
411 * NtAllocateUuids [NTDLL.@]
413 * NOTES
414 * I have seen lpdwCount pointing to a pointer once...
416 NTSTATUS WINAPI NtAllocateUuids(LPDWORD lpdwCount, LPDWORD *p2, LPDWORD *p3)
418 FIXME("(%p[%ld],%p,%p), stub.\n", lpdwCount,
419 lpdwCount ? *lpdwCount : 0,
420 p2, p3);
421 return 0;