2 * Object management functions
4 * Copyright 1999, 2000 Juergen Schmied
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.
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.
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
32 #include "wine/debug.h"
36 #include "ntdll_misc.h"
37 #include "wine/server.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
43 * Generic object functions
46 /******************************************************************************
47 * NtQueryObject [NTDLL.@]
48 * ZwQueryObject [NTDLL.@]
50 NTSTATUS WINAPI
NtQueryObject(IN HANDLE handle
,
51 IN OBJECT_INFORMATION_CLASS info_class
,
52 OUT PVOID ptr
, IN ULONG len
, OUT PULONG used_len
)
56 TRACE("(%p,0x%08x,%p,0x%08lx,%p): stub\n",
57 handle
, info_class
, ptr
, len
, used_len
);
59 if (used_len
) *used_len
= 0;
63 case ObjectDataInformation
:
65 OBJECT_DATA_INFORMATION
* p
= (OBJECT_DATA_INFORMATION
*)ptr
;
67 if (len
< sizeof(*p
)) return STATUS_INVALID_BUFFER_SIZE
;
69 SERVER_START_REQ( set_handle_info
)
74 status
= wine_server_call( req
);
75 if (status
== STATUS_SUCCESS
)
77 p
->InheritHandle
= (reply
->old_flags
& HANDLE_FLAG_INHERIT
) ? TRUE
: FALSE
;
78 p
->ProtectFromClose
= (reply
->old_flags
& HANDLE_FLAG_PROTECT_FROM_CLOSE
) ? TRUE
: FALSE
;
79 if (used_len
) *used_len
= sizeof(*p
);
86 FIXME("Unsupported information class %u\n", info_class
);
87 status
= STATUS_NOT_IMPLEMENTED
;
93 /******************************************************************
94 * NtSetInformationObject [NTDLL.@]
95 * ZwSetInformationObject [NTDLL.@]
98 NTSTATUS WINAPI
NtSetInformationObject(IN HANDLE handle
,
99 IN OBJECT_INFORMATION_CLASS info_class
,
100 IN PVOID ptr
, IN ULONG len
)
104 TRACE("(%p,0x%08x,%p,0x%08lx): stub\n",
105 handle
, info_class
, ptr
, len
);
109 case ObjectDataInformation
:
111 OBJECT_DATA_INFORMATION
* p
= (OBJECT_DATA_INFORMATION
*)ptr
;
113 if (len
< sizeof(*p
)) return STATUS_INVALID_BUFFER_SIZE
;
115 SERVER_START_REQ( set_handle_info
)
117 req
->handle
= handle
;
119 req
->mask
= HANDLE_FLAG_INHERIT
| HANDLE_FLAG_PROTECT_FROM_CLOSE
;
120 if (p
->InheritHandle
) req
->flags
|= HANDLE_FLAG_INHERIT
;
121 if (p
->ProtectFromClose
) req
->flags
|= HANDLE_FLAG_PROTECT_FROM_CLOSE
;
122 status
= wine_server_call( req
);
128 FIXME("Unsupported information class %u\n", info_class
);
129 status
= STATUS_NOT_IMPLEMENTED
;
135 /******************************************************************************
136 * NtQuerySecurityObject [NTDLL.@]
138 * An ntdll analogue to GetKernelObjectSecurity().
141 * only the lowest 4 bit of SecurityObjectInformationClass are used
142 * 0x7-0xf returns STATUS_ACCESS_DENIED (even running with system privileges)
145 * We are constructing a fake sid (Administrators:Full, System:Full, Everyone:Read)
148 NtQuerySecurityObject(
150 IN SECURITY_INFORMATION RequestedInformation
,
151 OUT PSECURITY_DESCRIPTOR pSecurityDesriptor
,
153 OUT PULONG ResultLength
)
155 static SID_IDENTIFIER_AUTHORITY localSidAuthority
= {SECURITY_NT_AUTHORITY
};
156 static SID_IDENTIFIER_AUTHORITY worldSidAuthority
= {SECURITY_WORLD_SID_AUTHORITY
};
158 PISECURITY_DESCRIPTOR_RELATIVE psd
= (PISECURITY_DESCRIPTOR_RELATIVE
)Buffer
;
159 UINT BufferIndex
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
161 FIXME("(%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
162 Object
, RequestedInformation
, pSecurityDesriptor
, Length
, ResultLength
);
164 RequestedInformation
&= 0x0000000f;
166 if (RequestedInformation
& SACL_SECURITY_INFORMATION
) return STATUS_ACCESS_DENIED
;
168 ZeroMemory(Buffer
, 256);
169 RtlCreateSecurityDescriptor((PSECURITY_DESCRIPTOR
)psd
, SECURITY_DESCRIPTOR_REVISION
);
170 psd
->Control
= SE_SELF_RELATIVE
|
171 ((RequestedInformation
& DACL_SECURITY_INFORMATION
) ? SE_DACL_PRESENT
:0);
173 /* owner: administrator S-1-5-20-220*/
174 if (OWNER_SECURITY_INFORMATION
& RequestedInformation
)
176 SID
* psid
= (SID
*)&(Buffer
[BufferIndex
]);
178 psd
->Owner
= BufferIndex
;
179 BufferIndex
+= RtlLengthRequiredSid(2);
181 psid
->Revision
= SID_REVISION
;
182 psid
->SubAuthorityCount
= 2;
183 psid
->IdentifierAuthority
= localSidAuthority
;
184 psid
->SubAuthority
[0] = SECURITY_BUILTIN_DOMAIN_RID
;
185 psid
->SubAuthority
[1] = DOMAIN_ALIAS_RID_ADMINS
;
188 /* group: built in domain S-1-5-12 */
189 if (GROUP_SECURITY_INFORMATION
& RequestedInformation
)
191 SID
* psid
= (SID
*) &(Buffer
[BufferIndex
]);
193 psd
->Group
= BufferIndex
;
194 BufferIndex
+= RtlLengthRequiredSid(1);
196 psid
->Revision
= SID_REVISION
;
197 psid
->SubAuthorityCount
= 1;
198 psid
->IdentifierAuthority
= localSidAuthority
;
199 psid
->SubAuthority
[0] = SECURITY_LOCAL_SYSTEM_RID
;
202 /* discretionary ACL */
203 if (DACL_SECURITY_INFORMATION
& RequestedInformation
)
206 PACL pacl
= (PACL
)&(Buffer
[BufferIndex
]);
207 PACCESS_ALLOWED_ACE pace
;
210 psd
->Dacl
= BufferIndex
;
212 pacl
->AclRevision
= MIN_ACL_REVISION
;
214 pacl
->AclSize
= BufferIndex
; /* storing the start index temporary */
216 BufferIndex
+= sizeof(ACL
);
218 /* ACE System - full access */
219 pace
= (PACCESS_ALLOWED_ACE
)&(Buffer
[BufferIndex
]);
220 BufferIndex
+= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
);
222 pace
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
223 pace
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
224 pace
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
) + RtlLengthRequiredSid(1);
225 pace
->Mask
= DELETE
| READ_CONTROL
| WRITE_DAC
| WRITE_OWNER
| 0x3f;
226 pace
->SidStart
= BufferIndex
;
228 /* SID S-1-5-12 (System) */
229 psid
= (SID
*)&(Buffer
[BufferIndex
]);
231 BufferIndex
+= RtlLengthRequiredSid(1);
233 psid
->Revision
= SID_REVISION
;
234 psid
->SubAuthorityCount
= 1;
235 psid
->IdentifierAuthority
= localSidAuthority
;
236 psid
->SubAuthority
[0] = SECURITY_LOCAL_SYSTEM_RID
;
238 /* ACE Administrators - full access*/
239 pace
= (PACCESS_ALLOWED_ACE
) &(Buffer
[BufferIndex
]);
240 BufferIndex
+= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
);
242 pace
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
243 pace
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
244 pace
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
) + RtlLengthRequiredSid(2);
245 pace
->Mask
= DELETE
| READ_CONTROL
| WRITE_DAC
| WRITE_OWNER
| 0x3f;
246 pace
->SidStart
= BufferIndex
;
248 /* S-1-5-12 (Administrators) */
249 psid
= (SID
*)&(Buffer
[BufferIndex
]);
251 BufferIndex
+= RtlLengthRequiredSid(2);
253 psid
->Revision
= SID_REVISION
;
254 psid
->SubAuthorityCount
= 2;
255 psid
->IdentifierAuthority
= localSidAuthority
;
256 psid
->SubAuthority
[0] = SECURITY_BUILTIN_DOMAIN_RID
;
257 psid
->SubAuthority
[1] = DOMAIN_ALIAS_RID_ADMINS
;
259 /* ACE Everyone - read access */
260 pace
= (PACCESS_ALLOWED_ACE
)&(Buffer
[BufferIndex
]);
261 BufferIndex
+= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
);
263 pace
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
264 pace
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
265 pace
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
) + RtlLengthRequiredSid(1);
266 pace
->Mask
= READ_CONTROL
| 0x19;
267 pace
->SidStart
= BufferIndex
;
269 /* SID S-1-1-0 (Everyone) */
270 psid
= (SID
*)&(Buffer
[BufferIndex
]);
272 BufferIndex
+= RtlLengthRequiredSid(1);
274 psid
->Revision
= SID_REVISION
;
275 psid
->SubAuthorityCount
= 1;
276 psid
->IdentifierAuthority
= worldSidAuthority
;
277 psid
->SubAuthority
[0] = 0;
279 /* calculate used bytes */
280 pacl
->AclSize
= BufferIndex
- pacl
->AclSize
;
282 *ResultLength
= BufferIndex
;
283 TRACE("len=%lu\n", *ResultLength
);
284 if (Length
< *ResultLength
) return STATUS_BUFFER_TOO_SMALL
;
285 memcpy(pSecurityDesriptor
, Buffer
, *ResultLength
);
287 return STATUS_SUCCESS
;
291 /******************************************************************************
292 * NtDuplicateObject [NTDLL.@]
293 * ZwDuplicateObject [NTDLL.@]
295 NTSTATUS WINAPI
NtDuplicateObject( HANDLE source_process
, HANDLE source
,
296 HANDLE dest_process
, PHANDLE dest
,
297 ACCESS_MASK access
, ULONG attributes
, ULONG options
)
300 SERVER_START_REQ( dup_handle
)
302 req
->src_process
= source_process
;
303 req
->src_handle
= source
;
304 req
->dst_process
= dest_process
;
305 req
->access
= access
;
306 req
->inherit
= (attributes
& OBJ_INHERIT
) != 0;
307 req
->options
= options
;
309 if (!(ret
= wine_server_call( req
)))
311 if (dest
) *dest
= reply
->handle
;
312 if (reply
->fd
!= -1) close( reply
->fd
);
319 /**************************************************************************
322 * Close a handle reference to an object.
325 * Handle [I] handle to close
328 * Success: ERROR_SUCCESS.
329 * Failure: An NTSTATUS error code.
331 NTSTATUS WINAPI
NtClose( HANDLE Handle
)
334 SERVER_START_REQ( close_handle
)
336 req
->handle
= Handle
;
337 ret
= wine_server_call( req
);
338 if (!ret
&& reply
->fd
!= -1) close( reply
->fd
);
345 * Directory functions
348 /**************************************************************************
349 * NtOpenDirectoryObject [NTDLL.@]
350 * ZwOpenDirectoryObject [NTDLL.@]
352 * Open a namespace directory object.
355 * DirectoryHandle [O] Destination for the new directory handle
356 * DesiredAccess [I] Desired access to the directory
357 * ObjectAttributes [I] Structure describing the directory
360 * Success: ERROR_SUCCESS.
361 * Failure: An NTSTATUS error code.
363 NTSTATUS WINAPI
NtOpenDirectoryObject(
364 PHANDLE DirectoryHandle
,
365 ACCESS_MASK DesiredAccess
,
366 POBJECT_ATTRIBUTES ObjectAttributes
)
368 FIXME("(%p,0x%08lx,%p): stub\n",
369 DirectoryHandle
, DesiredAccess
, ObjectAttributes
);
370 dump_ObjectAttributes(ObjectAttributes
);
374 /******************************************************************************
375 * NtCreateDirectoryObject [NTDLL.@]
376 * ZwCreateDirectoryObject [NTDLL.@]
378 NTSTATUS WINAPI
NtCreateDirectoryObject(
379 PHANDLE DirectoryHandle
,
380 ACCESS_MASK DesiredAccess
,
381 POBJECT_ATTRIBUTES ObjectAttributes
)
383 FIXME("(%p,0x%08lx,%p),stub!\n",
384 DirectoryHandle
,DesiredAccess
,ObjectAttributes
);
385 dump_ObjectAttributes(ObjectAttributes
);
389 /******************************************************************************
390 * NtQueryDirectoryObject [NTDLL.@]
391 * ZwQueryDirectoryObject [NTDLL.@]
393 * Read information from a namespace directory.
396 * DirObjHandle [I] Object handle
397 * DirObjInformation [O] Buffer to hold the data read
398 * BufferLength [I] Size of the buffer in bytes
399 * GetNextIndex [I] Set ObjectIndex to TRUE=next object, FALSE=last object
400 * IgnoreInputIndex [I] Start reading at index TRUE=0, FALSE=ObjectIndex
401 * ObjectIndex [I/O] 0 based index into the directory, see IgnoreInputIndex and GetNextIndex
402 * DataWritten [O] Caller supplied storage for the number of bytes written (or NULL)
405 * Success: ERROR_SUCCESS.
406 * Failure: An NTSTATUS error code.
408 NTSTATUS WINAPI
NtQueryDirectoryObject(
409 IN HANDLE DirObjHandle
,
410 OUT POBJDIR_INFORMATION DirObjInformation
,
411 IN ULONG BufferLength
,
412 IN BOOLEAN GetNextIndex
,
413 IN BOOLEAN IgnoreInputIndex
,
414 IN OUT PULONG ObjectIndex
,
415 OUT PULONG DataWritten OPTIONAL
)
417 FIXME("(%p,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
418 DirObjHandle
, DirObjInformation
, BufferLength
, GetNextIndex
,
419 IgnoreInputIndex
, ObjectIndex
, DataWritten
);
420 return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
427 /******************************************************************************
428 * NtOpenSymbolicLinkObject [NTDLL.@]
430 NTSTATUS WINAPI
NtOpenSymbolicLinkObject(
431 OUT PHANDLE LinkHandle
,
432 IN ACCESS_MASK DesiredAccess
,
433 IN POBJECT_ATTRIBUTES ObjectAttributes
)
435 FIXME("(%p,0x%08lx,%p) stub\n",
436 LinkHandle
, DesiredAccess
, ObjectAttributes
);
437 dump_ObjectAttributes(ObjectAttributes
);
438 return STATUS_OBJECT_NAME_NOT_FOUND
;
441 /******************************************************************************
442 * NtCreateSymbolicLinkObject [NTDLL.@]
444 NTSTATUS WINAPI
NtCreateSymbolicLinkObject(
445 OUT PHANDLE SymbolicLinkHandle
,
446 IN ACCESS_MASK DesiredAccess
,
447 IN POBJECT_ATTRIBUTES ObjectAttributes
,
448 IN PUNICODE_STRING Name
)
450 FIXME("(%p,0x%08lx,%p, %p) stub\n",
451 SymbolicLinkHandle
, DesiredAccess
, ObjectAttributes
, debugstr_us(Name
));
452 dump_ObjectAttributes(ObjectAttributes
);
456 /******************************************************************************
457 * NtQuerySymbolicLinkObject [NTDLL.@]
459 NTSTATUS WINAPI
NtQuerySymbolicLinkObject(
460 IN HANDLE LinkHandle
,
461 IN OUT PUNICODE_STRING LinkTarget
,
462 OUT PULONG ReturnedLength OPTIONAL
)
464 FIXME("(%p,%p,%p) stub\n",
465 LinkHandle
, debugstr_us(LinkTarget
), ReturnedLength
);
470 /******************************************************************************
471 * NtAllocateUuids [NTDLL.@]
473 NTSTATUS WINAPI
NtAllocateUuids(
474 PULARGE_INTEGER Time
,
478 FIXME("(%p,%p,%p), stub.\n", Time
, Range
, Sequence
);