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
)
222 struct close_handle_request
*req
= server_alloc_req( sizeof(*req
), 0 );
223 req
->handle
= Handle
;
224 ret
= server_call_noerr( REQ_CLOSE_HANDLE
);
225 if (!ret
&& req
->fd
!= -1) close( req
->fd
);
231 /******************************************************************************
232 * NtWaitForSingleObject [NTDLL]
234 NTSTATUS WINAPI
NtWaitForSingleObject(
236 IN BOOLEAN Alertable
,
237 IN PLARGE_INTEGER Time
)
239 FIXME("(%p,0x%08x,%p),stub!\n",Object
,Alertable
,Time
);
244 * Directory functions
247 /**************************************************************************
248 * NtOpenDirectoryObject [NTDLL.124]
249 * FUNCTION: Opens a namespace directory object
251 * DirectoryHandle Variable which receives the directory handle
252 * DesiredAccess Desired access to the directory
253 * ObjectAttributes Structure describing the directory
256 NTSTATUS WINAPI
NtOpenDirectoryObject(
257 PHANDLE DirectoryHandle
,
258 ACCESS_MASK DesiredAccess
,
259 POBJECT_ATTRIBUTES ObjectAttributes
)
261 FIXME("(%p,0x%08lx,%p): stub\n",
262 DirectoryHandle
, DesiredAccess
, ObjectAttributes
);
263 dump_ObjectAttributes(ObjectAttributes
);
267 /******************************************************************************
268 * NtCreateDirectoryObject [NTDLL]
270 NTSTATUS WINAPI
NtCreateDirectoryObject(
271 PHANDLE DirectoryHandle
,
272 ACCESS_MASK DesiredAccess
,
273 POBJECT_ATTRIBUTES ObjectAttributes
)
275 FIXME("(%p,0x%08lx,%p),stub!\n",
276 DirectoryHandle
,DesiredAccess
,ObjectAttributes
);
277 dump_ObjectAttributes(ObjectAttributes
);
281 /******************************************************************************
282 * NtQueryDirectoryObject [NTDLL.149]
283 * FUNCTION: Reads information from a namespace directory
285 * DirObjInformation Buffer to hold the data read
286 * BufferLength Size of the buffer in bytes
287 * GetNextIndex If TRUE then set ObjectIndex to the index of the next object
288 * If FALSE then set ObjectIndex to the number of objects in the directory
289 * IgnoreInputIndex If TRUE start reading at index 0
290 * If FALSE start reading at the index specified by object index
291 * ObjectIndex Zero based index into the directory, interpretation depends on IgnoreInputIndex and GetNextIndex
292 * DataWritten Caller supplied storage for the number of bytes written (or NULL)
294 NTSTATUS WINAPI
NtQueryDirectoryObject(
295 IN HANDLE DirObjHandle
,
296 OUT POBJDIR_INFORMATION DirObjInformation
,
297 IN ULONG BufferLength
,
298 IN BOOLEAN GetNextIndex
,
299 IN BOOLEAN IgnoreInputIndex
,
300 IN OUT PULONG ObjectIndex
,
301 OUT PULONG DataWritten OPTIONAL
)
303 FIXME("(0x%08x,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
304 DirObjHandle
, DirObjInformation
, BufferLength
, GetNextIndex
,
305 IgnoreInputIndex
, ObjectIndex
, DataWritten
);
306 return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
313 /******************************************************************************
314 * NtOpenSymbolicLinkObject [NTDLL]
316 NTSTATUS WINAPI
NtOpenSymbolicLinkObject(
317 OUT PHANDLE LinkHandle
,
318 IN ACCESS_MASK DesiredAccess
,
319 IN POBJECT_ATTRIBUTES ObjectAttributes
)
321 FIXME("(%p,0x%08lx,%p) stub\n",
322 LinkHandle
, DesiredAccess
, ObjectAttributes
);
323 dump_ObjectAttributes(ObjectAttributes
);
327 /******************************************************************************
328 * NtCreateSymbolicLinkObject [NTDLL]
330 NTSTATUS WINAPI
NtCreateSymbolicLinkObject(
331 OUT PHANDLE SymbolicLinkHandle
,
332 IN ACCESS_MASK DesiredAccess
,
333 IN POBJECT_ATTRIBUTES ObjectAttributes
,
334 IN PUNICODE_STRING Name
)
336 FIXME("(%p,0x%08lx,%p, %p) stub\n",
337 SymbolicLinkHandle
, DesiredAccess
, ObjectAttributes
, debugstr_us(Name
));
338 dump_ObjectAttributes(ObjectAttributes
);
342 /******************************************************************************
343 * NtQuerySymbolicLinkObject [NTDLL]
345 NTSTATUS WINAPI
NtQuerySymbolicLinkObject(
346 IN HANDLE LinkHandle
,
347 IN OUT PUNICODE_STRING LinkTarget
,
348 OUT PULONG ReturnedLength OPTIONAL
)
350 FIXME("(0x%08x,%p,%p) stub\n",
351 LinkHandle
, debugstr_us(LinkTarget
), ReturnedLength
);
356 /******************************************************************************
357 * NtAllocateUuids [NTDLL]
359 * I have seen lpdwCount pointing to a pointer once...
361 NTSTATUS WINAPI
NtAllocateUuids(LPDWORD lpdwCount
, LPDWORD
*p2
, LPDWORD
*p3
)
363 FIXME("(%p[%ld],%p,%p), stub.\n", lpdwCount
,
364 lpdwCount
? *lpdwCount
: 0,