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