Remove SYMBOLFILE and LDDLLFLAGS from Makefiles.
[wine] / dlls / ntdll / om.c
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 "config.h"
22
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #ifdef HAVE_IO_H
27 # include <io.h>
28 #endif
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include "wine/debug.h"
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
37 #include "winternl.h"
38 #include "ntdll_misc.h"
39 #include "wine/server.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
42
43 /* move to somewhere */
44 typedef void * POBJDIR_INFORMATION;
45
46 /*
47  *      Generic object functions
48  */
49
50 /******************************************************************************
51  * NtQueryObject [NTDLL.@]
52  * ZwQueryObject [NTDLL.@]
53  */
54 NTSTATUS WINAPI NtQueryObject(IN HANDLE handle,
55                               IN OBJECT_INFORMATION_CLASS info_class,
56                               OUT PVOID ptr, IN ULONG len, OUT PULONG used_len)
57 {
58     NTSTATUS status;
59
60     TRACE("(%p,0x%08x,%p,0x%08lx,%p): stub\n",
61           handle, info_class, ptr, len, used_len);
62
63     if (used_len) *used_len = 0;
64
65     switch (info_class)
66     {
67     case ObjectDataInformation:
68         {
69             OBJECT_DATA_INFORMATION* p = (OBJECT_DATA_INFORMATION*)ptr;
70
71             if (len < sizeof(*p)) return STATUS_INVALID_BUFFER_SIZE;
72
73             SERVER_START_REQ( set_handle_info )
74             {
75                 req->handle = handle;
76                 req->flags  = 0;
77                 req->mask   = 0;
78                 req->fd     = -1;
79                 status = wine_server_call( req );
80                 if (status == STATUS_SUCCESS)
81                 {
82                     p->InheritHandle = (reply->old_flags & HANDLE_FLAG_INHERIT) ? TRUE : FALSE;
83                     p->ProtectFromClose = (reply->old_flags & HANDLE_FLAG_PROTECT_FROM_CLOSE) ? TRUE : FALSE;
84                     if (used_len) *used_len = sizeof(*p);
85                 }
86             }
87             SERVER_END_REQ;
88         }
89         break;
90     default:
91         FIXME("Unsupported information class %u\n", info_class);
92         status = STATUS_NOT_IMPLEMENTED;
93         break;
94     }
95     return status;
96 }
97
98 /******************************************************************
99  *              NtSetInformationObject [NTDLL.@]
100  *              ZwSetInformationObject [NTDLL.@]
101  *
102  */
103 NTSTATUS WINAPI NtSetInformationObject(IN HANDLE handle,
104                                        IN OBJECT_INFORMATION_CLASS info_class,
105                                        IN PVOID ptr, IN ULONG len)
106 {
107     NTSTATUS status;
108
109     TRACE("(%p,0x%08x,%p,0x%08lx): stub\n",
110           handle, info_class, ptr, len);
111
112     switch (info_class)
113     {
114     case ObjectDataInformation:
115         {
116             OBJECT_DATA_INFORMATION* p = (OBJECT_DATA_INFORMATION*)ptr;
117
118             if (len < sizeof(*p)) return STATUS_INVALID_BUFFER_SIZE;
119
120             SERVER_START_REQ( set_handle_info )
121             {
122                 req->handle = handle;
123                 req->flags  = 0;
124                 req->mask   = HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE;
125                 req->fd     = -1;
126                 if (p->InheritHandle)    req->flags |= HANDLE_FLAG_INHERIT;
127                 if (p->ProtectFromClose) req->flags |= HANDLE_FLAG_PROTECT_FROM_CLOSE;
128                 status = wine_server_call( req );
129             }
130             SERVER_END_REQ;
131         }
132         break;
133     default:
134         FIXME("Unsupported information class %u\n", info_class);
135         status = STATUS_NOT_IMPLEMENTED;
136         break;
137     }
138     return status;
139 }
140
141 /******************************************************************************
142  *  NtQuerySecurityObject       [NTDLL.@]
143  *
144  * An ntdll analogue to GetKernelObjectSecurity().
145  *
146  * NOTES
147  *  only the lowest 4 bit of SecurityObjectInformationClass are used
148  *  0x7-0xf returns STATUS_ACCESS_DENIED (even running with system privileges)
149  *
150  * FIXME
151  *  We are constructing a fake sid (Administrators:Full, System:Full, Everyone:Read)
152  */
153 NTSTATUS WINAPI
154 NtQuerySecurityObject(
155         IN HANDLE Object,
156         IN SECURITY_INFORMATION RequestedInformation,
157         OUT PSECURITY_DESCRIPTOR pSecurityDesriptor,
158         IN ULONG Length,
159         OUT PULONG ResultLength)
160 {
161         static SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
162         static SID_IDENTIFIER_AUTHORITY worldSidAuthority = {SECURITY_WORLD_SID_AUTHORITY};
163         BYTE Buffer[256];
164         PISECURITY_DESCRIPTOR_RELATIVE psd = (PISECURITY_DESCRIPTOR_RELATIVE)Buffer;
165         UINT BufferIndex = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
166
167         FIXME("(%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
168         Object, RequestedInformation, pSecurityDesriptor, Length, ResultLength);
169
170         RequestedInformation &= 0x0000000f;
171
172         if (RequestedInformation & SACL_SECURITY_INFORMATION) return STATUS_ACCESS_DENIED;
173
174         ZeroMemory(Buffer, 256);
175         RtlCreateSecurityDescriptor((PSECURITY_DESCRIPTOR)psd, SECURITY_DESCRIPTOR_REVISION);
176         psd->Control = SE_SELF_RELATIVE |
177           ((RequestedInformation & DACL_SECURITY_INFORMATION) ? SE_DACL_PRESENT:0);
178
179         /* owner: administrator S-1-5-20-220*/
180         if (OWNER_SECURITY_INFORMATION & RequestedInformation)
181         {
182           PSID psid = (PSID)&(Buffer[BufferIndex]);
183
184           psd->Owner = BufferIndex;
185           BufferIndex += RtlLengthRequiredSid(2);
186
187           psid->Revision = SID_REVISION;
188           psid->SubAuthorityCount = 2;
189           psid->IdentifierAuthority = localSidAuthority;
190           psid->SubAuthority[0] = SECURITY_BUILTIN_DOMAIN_RID;
191           psid->SubAuthority[1] = DOMAIN_ALIAS_RID_ADMINS;
192         }
193
194         /* group: built in domain S-1-5-12 */
195         if (GROUP_SECURITY_INFORMATION & RequestedInformation)
196         {
197           PSID psid = (PSID) &(Buffer[BufferIndex]);
198
199           psd->Group = BufferIndex;
200           BufferIndex += RtlLengthRequiredSid(1);
201
202           psid->Revision = SID_REVISION;
203           psid->SubAuthorityCount = 1;
204           psid->IdentifierAuthority = localSidAuthority;
205           psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
206         }
207
208         /* discretionary ACL */
209         if (DACL_SECURITY_INFORMATION & RequestedInformation)
210         {
211           /* acl header */
212           PACL pacl = (PACL)&(Buffer[BufferIndex]);
213           PACCESS_ALLOWED_ACE pace;
214           PSID psid;
215
216           psd->Dacl = BufferIndex;
217
218           pacl->AclRevision = MIN_ACL_REVISION;
219           pacl->AceCount = 3;
220           pacl->AclSize = BufferIndex; /* storing the start index temporary */
221
222           BufferIndex += sizeof(ACL);
223
224           /* ACE System - full access */
225           pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
226           BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
227
228           pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
229           pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
230           pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(1);
231           pace->Mask = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER  | 0x3f;
232           pace->SidStart = BufferIndex;
233
234           /* SID S-1-5-12 (System) */
235           psid = (PSID)&(Buffer[BufferIndex]);
236
237           BufferIndex += RtlLengthRequiredSid(1);
238
239           psid->Revision = SID_REVISION;
240           psid->SubAuthorityCount = 1;
241           psid->IdentifierAuthority = localSidAuthority;
242           psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
243
244           /* ACE Administrators - full access*/
245           pace = (PACCESS_ALLOWED_ACE) &(Buffer[BufferIndex]);
246           BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
247
248           pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
249           pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
250           pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(2);
251           pace->Mask = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER  | 0x3f;
252           pace->SidStart = BufferIndex;
253
254           /* S-1-5-12 (Administrators) */
255           psid = (PSID)&(Buffer[BufferIndex]);
256
257           BufferIndex += RtlLengthRequiredSid(2);
258
259           psid->Revision = SID_REVISION;
260           psid->SubAuthorityCount = 2;
261           psid->IdentifierAuthority = localSidAuthority;
262           psid->SubAuthority[0] = SECURITY_BUILTIN_DOMAIN_RID;
263           psid->SubAuthority[1] = DOMAIN_ALIAS_RID_ADMINS;
264
265           /* ACE Everyone - read access */
266           pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
267           BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
268
269           pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
270           pace->Header.AceFlags = CONTAINER_INHERIT_ACE;
271           pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + RtlLengthRequiredSid(1);
272           pace->Mask = READ_CONTROL| 0x19;
273           pace->SidStart = BufferIndex;
274
275           /* SID S-1-1-0 (Everyone) */
276           psid = (PSID)&(Buffer[BufferIndex]);
277
278           BufferIndex += RtlLengthRequiredSid(1);
279
280           psid->Revision = SID_REVISION;
281           psid->SubAuthorityCount = 1;
282           psid->IdentifierAuthority = worldSidAuthority;
283           psid->SubAuthority[0] = 0;
284
285           /* calculate used bytes */
286           pacl->AclSize = BufferIndex - pacl->AclSize;
287         }
288         *ResultLength = BufferIndex;
289         TRACE("len=%lu\n", *ResultLength);
290         if (Length < *ResultLength) return STATUS_BUFFER_TOO_SMALL;
291         memcpy(pSecurityDesriptor, Buffer, *ResultLength);
292
293         return STATUS_SUCCESS;
294 }
295
296
297 /******************************************************************************
298  *  NtDuplicateObject           [NTDLL.@]
299  *  ZwDuplicateObject           [NTDLL.@]
300  */
301 NTSTATUS WINAPI NtDuplicateObject( HANDLE source_process, HANDLE source,
302                                    HANDLE dest_process, PHANDLE dest,
303                                    ACCESS_MASK access, ULONG attributes, ULONG options )
304 {
305     NTSTATUS ret;
306     SERVER_START_REQ( dup_handle )
307     {
308         req->src_process = source_process;
309         req->src_handle  = source;
310         req->dst_process = dest_process;
311         req->access      = access;
312         req->inherit     = (attributes & OBJ_INHERIT) != 0;
313         req->options     = options;
314
315         if (!(ret = wine_server_call( req )))
316         {
317             if (dest) *dest = reply->handle;
318             if (reply->fd != -1) close( reply->fd );
319         }
320     }
321     SERVER_END_REQ;
322     return ret;
323 }
324
325 /**************************************************************************
326  *                 NtClose                              [NTDLL.@]
327  *
328  * Close a handle reference to an object.
329  * 
330  * PARAMS
331  *  Handle [I] handle to close
332  *
333  * RETURNS
334  *  Success: ERROR_SUCCESS.
335  *  Failure: An NTSTATUS error code.
336  */
337 NTSTATUS WINAPI NtClose( HANDLE Handle )
338 {
339     NTSTATUS ret;
340     SERVER_START_REQ( close_handle )
341     {
342         req->handle = Handle;
343         ret = wine_server_call( req );
344         if (!ret && reply->fd != -1) close( reply->fd );
345     }
346     SERVER_END_REQ;
347     return ret;
348 }
349
350 /*
351  *      Directory functions
352  */
353
354 /**************************************************************************
355  * NtOpenDirectoryObject [NTDLL.@]
356  * ZwOpenDirectoryObject [NTDLL.@]
357  *
358  * Open a namespace directory object.
359  * 
360  * PARAMS
361  *  DirectoryHandle  [O] Destination for the new directory handle
362  *  DesiredAccess    [I] Desired access to the directory
363  *  ObjectAttributes [I] Structure describing the directory
364  *
365  * RETURNS
366  *  Success: ERROR_SUCCESS.
367  *  Failure: An NTSTATUS error code.
368  */
369 NTSTATUS WINAPI NtOpenDirectoryObject(
370         PHANDLE DirectoryHandle,
371         ACCESS_MASK DesiredAccess,
372         POBJECT_ATTRIBUTES ObjectAttributes)
373 {
374         FIXME("(%p,0x%08lx,%p): stub\n",
375         DirectoryHandle, DesiredAccess, ObjectAttributes);
376         dump_ObjectAttributes(ObjectAttributes);
377         return 0;
378 }
379
380 /******************************************************************************
381  *  NtCreateDirectoryObject     [NTDLL.@]
382  *  ZwCreateDirectoryObject     [NTDLL.@]
383  */
384 NTSTATUS WINAPI NtCreateDirectoryObject(
385         PHANDLE DirectoryHandle,
386         ACCESS_MASK DesiredAccess,
387         POBJECT_ATTRIBUTES ObjectAttributes)
388 {
389         FIXME("(%p,0x%08lx,%p),stub!\n",
390         DirectoryHandle,DesiredAccess,ObjectAttributes);
391         dump_ObjectAttributes(ObjectAttributes);
392         return 0;
393 }
394
395 /******************************************************************************
396  * NtQueryDirectoryObject [NTDLL.@]
397  * ZwQueryDirectoryObject [NTDLL.@]
398  *
399  * Read information from a namespace directory.
400  * 
401  * PARAMS
402  *  DirObjHandle      [I]   Object handle
403  *  DirObjInformation [O]   Buffer to hold the data read
404  *  BufferLength      [I]   Size of the buffer in bytes
405  *  GetNextIndex      [I]   Set ObjectIndex to TRUE=next object, FALSE=last object
406  *  IgnoreInputIndex  [I]   Start reading at index TRUE=0, FALSE=ObjectIndex
407  *  ObjectIndex       [I/O] 0 based index into the directory, see IgnoreInputIndex and GetNextIndex
408  *  DataWritten       [O]   Caller supplied storage for the number of bytes written (or NULL)
409  *
410  * RETURNS
411  *  Success: ERROR_SUCCESS.
412  *  Failure: An NTSTATUS error code.
413  */
414 NTSTATUS WINAPI NtQueryDirectoryObject(
415         IN HANDLE DirObjHandle,
416         OUT POBJDIR_INFORMATION DirObjInformation,
417         IN ULONG BufferLength,
418         IN BOOLEAN GetNextIndex,
419         IN BOOLEAN IgnoreInputIndex,
420         IN OUT PULONG ObjectIndex,
421         OUT PULONG DataWritten OPTIONAL)
422 {
423         FIXME("(%p,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
424                 DirObjHandle, DirObjInformation, BufferLength, GetNextIndex,
425                 IgnoreInputIndex, ObjectIndex, DataWritten);
426     return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
427 }
428
429 /*
430  *      Link objects
431  */
432
433 /******************************************************************************
434  *  NtOpenSymbolicLinkObject    [NTDLL.@]
435  */
436 NTSTATUS WINAPI NtOpenSymbolicLinkObject(
437         OUT PHANDLE LinkHandle,
438         IN ACCESS_MASK DesiredAccess,
439         IN POBJECT_ATTRIBUTES ObjectAttributes)
440 {
441         FIXME("(%p,0x%08lx,%p) stub\n",
442         LinkHandle, DesiredAccess, ObjectAttributes);
443         dump_ObjectAttributes(ObjectAttributes);
444         return 0;
445 }
446
447 /******************************************************************************
448  *  NtCreateSymbolicLinkObject  [NTDLL.@]
449  */
450 NTSTATUS WINAPI NtCreateSymbolicLinkObject(
451         OUT PHANDLE SymbolicLinkHandle,
452         IN ACCESS_MASK DesiredAccess,
453         IN POBJECT_ATTRIBUTES ObjectAttributes,
454         IN PUNICODE_STRING Name)
455 {
456         FIXME("(%p,0x%08lx,%p, %p) stub\n",
457         SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_us(Name));
458         dump_ObjectAttributes(ObjectAttributes);
459         return 0;
460 }
461
462 /******************************************************************************
463  *  NtQuerySymbolicLinkObject   [NTDLL.@]
464  */
465 NTSTATUS WINAPI NtQuerySymbolicLinkObject(
466         IN HANDLE LinkHandle,
467         IN OUT PUNICODE_STRING LinkTarget,
468         OUT PULONG ReturnedLength OPTIONAL)
469 {
470         FIXME("(%p,%p,%p) stub\n",
471         LinkHandle, debugstr_us(LinkTarget), ReturnedLength);
472
473         return 0;
474 }
475
476 /******************************************************************************
477  *  NtAllocateUuids   [NTDLL.@]
478  *
479  * NOTES
480  *  I have seen lpdwCount pointing to a pointer once...
481  */
482 NTSTATUS WINAPI NtAllocateUuids(LPDWORD lpdwCount, LPDWORD *p2, LPDWORD *p3)
483 {
484         FIXME("(%p[%ld],%p,%p), stub.\n", lpdwCount,
485                                          lpdwCount ? *lpdwCount : 0,
486                                          p2, p3);
487         return 0;
488 }