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