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