Spelling stuff.
[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 <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     NTSTATUS ret;
238     SERVER_START_REQ( close_handle )
239     {
240         req->handle = Handle;
241         ret = wine_server_call( req );
242         if (!ret && reply->fd != -1) close( reply->fd );
243     }
244     SERVER_END_REQ;
245     return ret;
246 }
247
248 /******************************************************************************
249  *  NtWaitForSingleObject               [NTDLL.@]
250  *  ZwWaitForSingleObject               [NTDLL.@]
251  */
252 NTSTATUS WINAPI NtWaitForSingleObject(
253         IN PHANDLE Object,
254         IN BOOLEAN Alertable,
255         IN PLARGE_INTEGER Time)
256 {
257         FIXME("(%p,0x%08x,%p),stub!\n",Object,Alertable,Time);
258         return 0;
259 }
260
261 /*
262  *      Directory functions
263  */
264
265 /**************************************************************************
266  * NtOpenDirectoryObject [NTDLL.@]
267  * ZwOpenDirectoryObject [NTDLL.@]
268  * FUNCTION: Opens a namespace directory object
269  * ARGUMENTS:
270  *  DirectoryHandle     Variable which receives the directory handle
271  *  DesiredAccess       Desired access to the directory
272  *  ObjectAttributes    Structure describing the directory
273  * RETURNS: Status
274  */
275 NTSTATUS WINAPI NtOpenDirectoryObject(
276         PHANDLE DirectoryHandle,
277         ACCESS_MASK DesiredAccess,
278         POBJECT_ATTRIBUTES ObjectAttributes)
279 {
280         FIXME("(%p,0x%08lx,%p): stub\n", 
281         DirectoryHandle, DesiredAccess, ObjectAttributes);
282         dump_ObjectAttributes(ObjectAttributes);
283         return 0;
284 }
285
286 /******************************************************************************
287  *  NtCreateDirectoryObject     [NTDLL.@]
288  *  ZwCreateDirectoryObject     [NTDLL.@]
289  */
290 NTSTATUS WINAPI NtCreateDirectoryObject(
291         PHANDLE DirectoryHandle,
292         ACCESS_MASK DesiredAccess,
293         POBJECT_ATTRIBUTES ObjectAttributes) 
294 {
295         FIXME("(%p,0x%08lx,%p),stub!\n",
296         DirectoryHandle,DesiredAccess,ObjectAttributes);
297         dump_ObjectAttributes(ObjectAttributes);
298         return 0;
299 }
300
301 /******************************************************************************
302  * NtQueryDirectoryObject [NTDLL.@]
303  * ZwQueryDirectoryObject [NTDLL.@]
304  * FUNCTION: Reads information from a namespace directory
305  * ARGUMENTS:
306  *  DirObjInformation   Buffer to hold the data read
307  *  BufferLength        Size of the buffer in bytes
308  *  GetNextIndex        If TRUE then set ObjectIndex to the index of the next object
309  *                      If FALSE then set ObjectIndex to the number of objects in the directory
310  *  IgnoreInputIndex    If TRUE start reading at index 0
311  *                      If FALSE start reading at the index specified by object index
312  *  ObjectIndex         Zero based index into the directory, interpretation depends on IgnoreInputIndex and GetNextIndex
313  *  DataWritten         Caller supplied storage for the number of bytes written (or NULL)
314  */
315 NTSTATUS WINAPI NtQueryDirectoryObject(
316         IN HANDLE DirObjHandle,
317         OUT POBJDIR_INFORMATION DirObjInformation,
318         IN ULONG BufferLength,
319         IN BOOLEAN GetNextIndex,
320         IN BOOLEAN IgnoreInputIndex,
321         IN OUT PULONG ObjectIndex,
322         OUT PULONG DataWritten OPTIONAL)
323 {
324         FIXME("(0x%08x,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
325                 DirObjHandle, DirObjInformation, BufferLength, GetNextIndex,
326                 IgnoreInputIndex, ObjectIndex, DataWritten);
327     return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
328 }
329
330 /*
331  *      Link objects
332  */
333  
334 /******************************************************************************
335  *  NtOpenSymbolicLinkObject    [NTDLL.@]
336  */
337 NTSTATUS WINAPI NtOpenSymbolicLinkObject(
338         OUT PHANDLE LinkHandle,
339         IN ACCESS_MASK DesiredAccess,
340         IN POBJECT_ATTRIBUTES ObjectAttributes)
341 {
342         FIXME("(%p,0x%08lx,%p) stub\n",
343         LinkHandle, DesiredAccess, ObjectAttributes);
344         dump_ObjectAttributes(ObjectAttributes);
345         return 0;
346 }
347
348 /******************************************************************************
349  *  NtCreateSymbolicLinkObject  [NTDLL.@]
350  */
351 NTSTATUS WINAPI NtCreateSymbolicLinkObject(
352         OUT PHANDLE SymbolicLinkHandle,
353         IN ACCESS_MASK DesiredAccess,
354         IN POBJECT_ATTRIBUTES ObjectAttributes,
355         IN PUNICODE_STRING Name)
356 {
357         FIXME("(%p,0x%08lx,%p, %p) stub\n",
358         SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_us(Name));
359         dump_ObjectAttributes(ObjectAttributes);
360         return 0;
361 }
362
363 /******************************************************************************
364  *  NtQuerySymbolicLinkObject   [NTDLL.@]
365  */
366 NTSTATUS WINAPI NtQuerySymbolicLinkObject(
367         IN HANDLE LinkHandle,
368         IN OUT PUNICODE_STRING LinkTarget,
369         OUT PULONG ReturnedLength OPTIONAL)
370 {
371         FIXME("(0x%08x,%p,%p) stub\n",
372         LinkHandle, debugstr_us(LinkTarget), ReturnedLength);
373
374         return 0;
375 }
376
377 /******************************************************************************
378  *  NtAllocateUuids   [NTDLL.@]
379  *
380  * I have seen lpdwCount pointing to a pointer once...
381  */
382 NTSTATUS WINAPI NtAllocateUuids(LPDWORD lpdwCount, LPDWORD *p2, LPDWORD *p3)
383 {
384         FIXME("(%p[%ld],%p,%p), stub.\n", lpdwCount,
385                                          lpdwCount ? *lpdwCount : 0,
386                                          p2, p3);
387         return 0;
388 }