2 * Object management functions
8 #include "debugtools.h"
11 #include "ntdll_misc.h"
14 DEFAULT_DEBUG_CHANNEL(ntdll);
16 /* move to somewhere */
17 typedef void * POBJDIR_INFORMATION;
20 * Generic object functions
23 /******************************************************************************
24 * NtQueryObject [NTDLL.161]
26 NTSTATUS WINAPI NtQueryObject(
27 IN HANDLE ObjectHandle,
28 IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
29 OUT PVOID ObjectInformation,
31 OUT PULONG ResultLength)
33 FIXME("(0x%08x,0x%08x,%p,0x%08lx,%p): stub\n",
34 ObjectHandle, ObjectInformationClass, ObjectInformation, Length, ResultLength);
38 /******************************************************************************
39 * NtQuerySecurityObject [NTDLL]
41 * analogue to GetKernelObjectSecurity
44 * only the lowest 4 bit of SecurityObjectInformationClass are used
45 * 0x7-0xf returns STATUS_ACCESS_DENIED (even running with system priviledges)
47 * FIXME: we are constructing a fake sid
48 * (Administrators:Full, System:Full, Everyone:Read)
51 NtQuerySecurityObject(
53 IN SECURITY_INFORMATION RequestedInformation,
54 OUT PSECURITY_DESCRIPTOR pSecurityDesriptor,
56 OUT PULONG ResultLength)
58 static SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
59 static SID_IDENTIFIER_AUTHORITY worldSidAuthority = {SECURITY_WORLD_SID_AUTHORITY};
61 PISECURITY_DESCRIPTOR_RELATIVE psd = (PISECURITY_DESCRIPTOR_RELATIVE)Buffer;
62 UINT BufferIndex = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
64 FIXME("(0x%08x,0x%08lx,%p,0x%08lx,%p) stub!\n",
65 Object, RequestedInformation, pSecurityDesriptor, Length, ResultLength);
67 RequestedInformation &= 0x0000000f;
69 if (RequestedInformation & SACL_SECURITY_INFORMATION) return STATUS_ACCESS_DENIED;
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);
76 /* owner: administrator S-1-5-20-220*/
77 if (OWNER_SECURITY_INFORMATION & RequestedInformation)
79 PSID psid = (PSID)&(Buffer[BufferIndex]);
81 psd->Owner = BufferIndex;
82 BufferIndex += RtlLengthRequiredSid(2);
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;
91 /* group: built in domain S-1-5-12 */
92 if (GROUP_SECURITY_INFORMATION & RequestedInformation)
94 PSID psid = (PSID) &(Buffer[BufferIndex]);
96 psd->Group = BufferIndex;
97 BufferIndex += RtlLengthRequiredSid(1);
99 psid->Revision = SID_REVISION;
100 psid->SubAuthorityCount = 1;
101 psid->IdentifierAuthority = localSidAuthority;
102 psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
105 /* discretionary ACL */
106 if (DACL_SECURITY_INFORMATION & RequestedInformation)
109 PACL pacl = (PACL)&(Buffer[BufferIndex]);
110 PACCESS_ALLOWED_ACE pace;
113 psd->Dacl = BufferIndex;
115 pacl->AclRevision = MIN_ACL_REVISION;
117 pacl->AclSize = BufferIndex; /* storing the start index temporary */
119 BufferIndex += sizeof(ACL);
121 /* ACE System - full access */
122 pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
123 BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
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;
131 /* SID S-1-5-12 (System) */
132 psid = (PSID)&(Buffer[BufferIndex]);
134 BufferIndex += RtlLengthRequiredSid(1);
136 psid->Revision = SID_REVISION;
137 psid->SubAuthorityCount = 1;
138 psid->IdentifierAuthority = localSidAuthority;
139 psid->SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
141 /* ACE Administrators - full access*/
142 pace = (PACCESS_ALLOWED_ACE) &(Buffer[BufferIndex]);
143 BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
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;
151 /* S-1-5-12 (Administrators) */
152 psid = (PSID)&(Buffer[BufferIndex]);
154 BufferIndex += RtlLengthRequiredSid(2);
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;
162 /* ACE Everyone - read access */
163 pace = (PACCESS_ALLOWED_ACE)&(Buffer[BufferIndex]);
164 BufferIndex += sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD);
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;
172 /* SID S-1-1-0 (Everyone) */
173 psid = (PSID)&(Buffer[BufferIndex]);
175 BufferIndex += RtlLengthRequiredSid(1);
177 psid->Revision = SID_REVISION;
178 psid->SubAuthorityCount = 1;
179 psid->IdentifierAuthority = worldSidAuthority;
180 psid->SubAuthority[0] = 0;
182 /* calculate used bytes */
183 pacl->AclSize = BufferIndex - pacl->AclSize;
185 *ResultLength = BufferIndex;
186 TRACE("len=%lu\n", *ResultLength);
187 if (Length < *ResultLength) return STATUS_BUFFER_TOO_SMALL;
188 memcpy(pSecurityDesriptor, Buffer, *ResultLength);
190 return STATUS_SUCCESS;
192 /******************************************************************************
193 * NtDuplicateObject [NTDLL]
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,
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);
211 /**************************************************************************
213 * FUNCTION: Closes a handle reference to an object
215 * Handle handle to close
217 NTSTATUS WINAPI NtClose( HANDLE Handle )
220 SERVER_START_REQ( close_handle )
222 req->handle = Handle;
224 if (!ret && req->fd != -1) close( req->fd );
230 /******************************************************************************
231 * NtWaitForSingleObject [NTDLL]
233 NTSTATUS WINAPI NtWaitForSingleObject(
235 IN BOOLEAN Alertable,
236 IN PLARGE_INTEGER Time)
238 FIXME("(%p,0x%08x,%p),stub!\n",Object,Alertable,Time);
243 * Directory functions
246 /**************************************************************************
247 * NtOpenDirectoryObject [NTDLL.124]
248 * FUNCTION: Opens a namespace directory object
250 * DirectoryHandle Variable which receives the directory handle
251 * DesiredAccess Desired access to the directory
252 * ObjectAttributes Structure describing the directory
255 NTSTATUS WINAPI NtOpenDirectoryObject(
256 PHANDLE DirectoryHandle,
257 ACCESS_MASK DesiredAccess,
258 POBJECT_ATTRIBUTES ObjectAttributes)
260 FIXME("(%p,0x%08lx,%p): stub\n",
261 DirectoryHandle, DesiredAccess, ObjectAttributes);
262 dump_ObjectAttributes(ObjectAttributes);
266 /******************************************************************************
267 * NtCreateDirectoryObject [NTDLL]
269 NTSTATUS WINAPI NtCreateDirectoryObject(
270 PHANDLE DirectoryHandle,
271 ACCESS_MASK DesiredAccess,
272 POBJECT_ATTRIBUTES ObjectAttributes)
274 FIXME("(%p,0x%08lx,%p),stub!\n",
275 DirectoryHandle,DesiredAccess,ObjectAttributes);
276 dump_ObjectAttributes(ObjectAttributes);
280 /******************************************************************************
281 * NtQueryDirectoryObject [NTDLL.149]
282 * FUNCTION: Reads information from a namespace directory
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)
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)
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.) */
312 /******************************************************************************
313 * NtOpenSymbolicLinkObject [NTDLL]
315 NTSTATUS WINAPI NtOpenSymbolicLinkObject(
316 OUT PHANDLE LinkHandle,
317 IN ACCESS_MASK DesiredAccess,
318 IN POBJECT_ATTRIBUTES ObjectAttributes)
320 FIXME("(%p,0x%08lx,%p) stub\n",
321 LinkHandle, DesiredAccess, ObjectAttributes);
322 dump_ObjectAttributes(ObjectAttributes);
326 /******************************************************************************
327 * NtCreateSymbolicLinkObject [NTDLL]
329 NTSTATUS WINAPI NtCreateSymbolicLinkObject(
330 OUT PHANDLE SymbolicLinkHandle,
331 IN ACCESS_MASK DesiredAccess,
332 IN POBJECT_ATTRIBUTES ObjectAttributes,
333 IN PUNICODE_STRING Name)
335 FIXME("(%p,0x%08lx,%p, %p) stub\n",
336 SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_us(Name));
337 dump_ObjectAttributes(ObjectAttributes);
341 /******************************************************************************
342 * NtQuerySymbolicLinkObject [NTDLL]
344 NTSTATUS WINAPI NtQuerySymbolicLinkObject(
345 IN HANDLE LinkHandle,
346 IN OUT PUNICODE_STRING LinkTarget,
347 OUT PULONG ReturnedLength OPTIONAL)
349 FIXME("(0x%08x,%p,%p) stub\n",
350 LinkHandle, debugstr_us(LinkTarget), ReturnedLength);
355 /******************************************************************************
356 * NtAllocateUuids [NTDLL]
358 * I have seen lpdwCount pointing to a pointer once...
360 NTSTATUS WINAPI NtAllocateUuids(LPDWORD lpdwCount, LPDWORD *p2, LPDWORD *p3)
362 FIXME("(%p[%ld],%p,%p), stub.\n", lpdwCount,
363 lpdwCount ? *lpdwCount : 0,