2 * Object management functions
7 #include "debugtools.h"
10 #include "ntdll_misc.h"
12 DEFAULT_DEBUG_CHANNEL(ntdll
)
14 /* move to somewhere */
15 typedef void * POBJDIR_INFORMATION
;
18 * Generic object functions
21 /******************************************************************************
22 * NtQueryObject [NTDLL.161]
24 NTSTATUS WINAPI
NtQueryObject(
25 IN HANDLE ObjectHandle
,
26 IN OBJECT_INFORMATION_CLASS ObjectInformationClass
,
27 OUT PVOID ObjectInformation
,
29 OUT PULONG ResultLength
)
31 FIXME("(0x%08x,0x%08x,%p,0x%08lx,%p): stub\n",
32 ObjectHandle
, ObjectInformationClass
, ObjectInformation
, Length
, ResultLength
);
36 /******************************************************************************
37 * NtQuerySecurityObject [NTDLL]
39 * analogue to GetKernelObjectSecurity
42 * only the lowest 4 bit of SecurityObjectInformationClass are used
43 * 0x7-0xf returns STATUS_ACCESS_DENIED (even running with system priviledges)
45 * FIXME: we are constructing a fake sid
46 * (Administrators:Full, System:Full, Everyone:Read)
49 NtQuerySecurityObject(
51 IN SECURITY_INFORMATION RequestedInformation
,
52 OUT PSECURITY_DESCRIPTOR pSecurityDesriptor
,
54 OUT PULONG ResultLength
)
56 static SID_IDENTIFIER_AUTHORITY localSidAuthority
= {SECURITY_NT_AUTHORITY
};
57 static SID_IDENTIFIER_AUTHORITY worldSidAuthority
= {SECURITY_WORLD_SID_AUTHORITY
};
59 PISECURITY_DESCRIPTOR_RELATIVE psd
= (PISECURITY_DESCRIPTOR_RELATIVE
)Buffer
;
60 UINT BufferIndex
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
62 FIXME("(0x%08x,0x%08lx,%p,0x%08lx,%p) stub!\n",
63 Object
, RequestedInformation
, pSecurityDesriptor
, Length
, ResultLength
);
65 RequestedInformation
&= 0x0000000f;
67 if (RequestedInformation
& SACL_SECURITY_INFORMATION
) return STATUS_ACCESS_DENIED
;
69 ZeroMemory(Buffer
, 256);
70 RtlCreateSecurityDescriptor((PSECURITY_DESCRIPTOR
)psd
, SECURITY_DESCRIPTOR_REVISION
);
71 psd
->Control
= SE_SELF_RELATIVE
|
72 ((RequestedInformation
& DACL_SECURITY_INFORMATION
) ? SE_DACL_PRESENT
:0);
74 /* owner: administrator S-1-5-20-220*/
75 if (OWNER_SECURITY_INFORMATION
& RequestedInformation
)
77 PSID psid
= (PSID
)&(Buffer
[BufferIndex
]);
79 psd
->Owner
= BufferIndex
;
80 BufferIndex
+= RtlLengthRequiredSid(2);
82 psid
->Revision
= SID_REVISION
;
83 psid
->SubAuthorityCount
= 2;
84 psid
->IdentifierAuthority
= localSidAuthority
;
85 psid
->SubAuthority
[0] = SECURITY_BUILTIN_DOMAIN_RID
;
86 psid
->SubAuthority
[1] = DOMAIN_ALIAS_RID_ADMINS
;
89 /* group: built in domain S-1-5-12 */
90 if (GROUP_SECURITY_INFORMATION
& RequestedInformation
)
92 PSID psid
= (PSID
) &(Buffer
[BufferIndex
]);
94 psd
->Group
= BufferIndex
;
95 BufferIndex
+= RtlLengthRequiredSid(1);
97 psid
->Revision
= SID_REVISION
;
98 psid
->SubAuthorityCount
= 1;
99 psid
->IdentifierAuthority
= localSidAuthority
;
100 psid
->SubAuthority
[0] = SECURITY_LOCAL_SYSTEM_RID
;
103 /* discretionary ACL */
104 if (DACL_SECURITY_INFORMATION
& RequestedInformation
)
107 PACL pacl
= (PACL
)&(Buffer
[BufferIndex
]);
108 PACCESS_ALLOWED_ACE pace
;
111 psd
->Dacl
= BufferIndex
;
113 pacl
->AclRevision
= MIN_ACL_REVISION
;
115 pacl
->AclSize
= BufferIndex
; /* storing the start index temporary */
117 BufferIndex
+= sizeof(ACL
);
119 /* ACE System - full access */
120 pace
= (PACCESS_ALLOWED_ACE
)&(Buffer
[BufferIndex
]);
121 BufferIndex
+= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
);
123 pace
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
124 pace
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
125 pace
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
) + RtlLengthRequiredSid(1);
126 pace
->Mask
= DELETE
| READ_CONTROL
| WRITE_DAC
| WRITE_OWNER
| 0x3f;
127 pace
->SidStart
= BufferIndex
;
129 /* SID S-1-5-12 (System) */
130 psid
= (PSID
)&(Buffer
[BufferIndex
]);
132 BufferIndex
+= RtlLengthRequiredSid(1);
134 psid
->Revision
= SID_REVISION
;
135 psid
->SubAuthorityCount
= 1;
136 psid
->IdentifierAuthority
= localSidAuthority
;
137 psid
->SubAuthority
[0] = SECURITY_LOCAL_SYSTEM_RID
;
139 /* ACE Administrators - full access*/
140 pace
= (PACCESS_ALLOWED_ACE
) &(Buffer
[BufferIndex
]);
141 BufferIndex
+= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
);
143 pace
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
144 pace
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
145 pace
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
) + RtlLengthRequiredSid(2);
146 pace
->Mask
= DELETE
| READ_CONTROL
| WRITE_DAC
| WRITE_OWNER
| 0x3f;
147 pace
->SidStart
= BufferIndex
;
149 /* S-1-5-12 (Administrators) */
150 psid
= (PSID
)&(Buffer
[BufferIndex
]);
152 BufferIndex
+= RtlLengthRequiredSid(2);
154 psid
->Revision
= SID_REVISION
;
155 psid
->SubAuthorityCount
= 2;
156 psid
->IdentifierAuthority
= localSidAuthority
;
157 psid
->SubAuthority
[0] = SECURITY_BUILTIN_DOMAIN_RID
;
158 psid
->SubAuthority
[1] = DOMAIN_ALIAS_RID_ADMINS
;
160 /* ACE Everyone - read access */
161 pace
= (PACCESS_ALLOWED_ACE
)&(Buffer
[BufferIndex
]);
162 BufferIndex
+= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
);
164 pace
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
165 pace
->Header
.AceFlags
= CONTAINER_INHERIT_ACE
;
166 pace
->Header
.AceSize
= sizeof(ACCESS_ALLOWED_ACE
)-sizeof(DWORD
) + RtlLengthRequiredSid(1);
167 pace
->Mask
= READ_CONTROL
| 0x19;
168 pace
->SidStart
= BufferIndex
;
170 /* SID S-1-1-0 (Everyone) */
171 psid
= (PSID
)&(Buffer
[BufferIndex
]);
173 BufferIndex
+= RtlLengthRequiredSid(1);
175 psid
->Revision
= SID_REVISION
;
176 psid
->SubAuthorityCount
= 1;
177 psid
->IdentifierAuthority
= worldSidAuthority
;
178 psid
->SubAuthority
[0] = 0;
180 /* calculate used bytes */
181 pacl
->AclSize
= BufferIndex
- pacl
->AclSize
;
183 *ResultLength
= BufferIndex
;
184 TRACE("len=%lu\n", *ResultLength
);
185 if (Length
< *ResultLength
) return STATUS_BUFFER_TOO_SMALL
;
186 memcpy(pSecurityDesriptor
, Buffer
, *ResultLength
);
188 return STATUS_SUCCESS
;
190 /******************************************************************************
191 * NtDuplicateObject [NTDLL]
193 NTSTATUS WINAPI
NtDuplicateObject(
194 IN HANDLE SourceProcessHandle
,
195 IN PHANDLE SourceHandle
,
196 IN HANDLE TargetProcessHandle
,
197 OUT PHANDLE TargetHandle
,
198 IN ACCESS_MASK DesiredAccess
,
199 IN BOOLEAN InheritHandle
,
202 FIXME("(0x%08x,%p,0x%08x,%p,0x%08lx,0x%08x,0x%08lx) stub!\n",
203 SourceProcessHandle
,SourceHandle
,TargetProcessHandle
,TargetHandle
,
204 DesiredAccess
,InheritHandle
,Options
);
209 /**************************************************************************
211 * FUNCTION: Closes a handle reference to an object
213 * Handle handle to close
215 NTSTATUS WINAPI
NtClose(
218 TRACE("(0x%08x)\n",Handle
);
219 if (CloseHandle(Handle
))
220 return STATUS_SUCCESS
;
221 return STATUS_UNSUCCESSFUL
; /*fixme*/
224 /******************************************************************************
225 * NtWaitForSingleObject [NTDLL]
227 NTSTATUS WINAPI
NtWaitForSingleObject(
229 IN BOOLEAN Alertable
,
230 IN PLARGE_INTEGER Time
)
232 FIXME("(%p,0x%08x,%p),stub!\n",Object
,Alertable
,Time
);
237 * Directory functions
240 /**************************************************************************
241 * NtOpenDirectoryObject [NTDLL.124]
242 * FUNCTION: Opens a namespace directory object
244 * DirectoryHandle Variable which receives the directory handle
245 * DesiredAccess Desired access to the directory
246 * ObjectAttributes Structure describing the directory
249 NTSTATUS WINAPI
NtOpenDirectoryObject(
250 PHANDLE DirectoryHandle
,
251 ACCESS_MASK DesiredAccess
,
252 POBJECT_ATTRIBUTES ObjectAttributes
)
254 FIXME("(%p,0x%08lx,%p): stub\n",
255 DirectoryHandle
, DesiredAccess
, ObjectAttributes
);
256 dump_ObjectAttributes(ObjectAttributes
);
260 /******************************************************************************
261 * NtCreateDirectoryObject [NTDLL]
263 NTSTATUS WINAPI
NtCreateDirectoryObject(
264 PHANDLE DirectoryHandle
,
265 ACCESS_MASK DesiredAccess
,
266 POBJECT_ATTRIBUTES ObjectAttributes
)
268 FIXME("(%p,0x%08lx,%p),stub!\n",
269 DirectoryHandle
,DesiredAccess
,ObjectAttributes
);
270 dump_ObjectAttributes(ObjectAttributes
);
274 /******************************************************************************
275 * NtQueryDirectoryObject [NTDLL.149]
276 * FUNCTION: Reads information from a namespace directory
278 * DirObjInformation Buffer to hold the data read
279 * BufferLength Size of the buffer in bytes
280 * GetNextIndex If TRUE then set ObjectIndex to the index of the next object
281 * If FALSE then set ObjectIndex to the number of objects in the directory
282 * IgnoreInputIndex If TRUE start reading at index 0
283 * If FALSE start reading at the index specified by object index
284 * ObjectIndex Zero based index into the directory, interpretation depends on IgnoreInputIndex and GetNextIndex
285 * DataWritten Caller supplied storage for the number of bytes written (or NULL)
287 NTSTATUS WINAPI
NtQueryDirectoryObject(
288 IN HANDLE DirObjHandle
,
289 OUT POBJDIR_INFORMATION DirObjInformation
,
290 IN ULONG BufferLength
,
291 IN BOOLEAN GetNextIndex
,
292 IN BOOLEAN IgnoreInputIndex
,
293 IN OUT PULONG ObjectIndex
,
294 OUT PULONG DataWritten OPTIONAL
)
296 FIXME("(0x%08x,%p,0x%08lx,0x%08x,0x%08x,%p,%p) stub\n",
297 DirObjHandle
, DirObjInformation
, BufferLength
, GetNextIndex
,
298 IgnoreInputIndex
, ObjectIndex
, DataWritten
);
299 return 0xc0000000; /* We don't have any. Whatever. (Yet.) */
306 /******************************************************************************
307 * NtOpenSymbolicLinkObject [NTDLL]
309 NTSTATUS WINAPI
NtOpenSymbolicLinkObject(
310 OUT PHANDLE LinkHandle
,
311 IN ACCESS_MASK DesiredAccess
,
312 IN POBJECT_ATTRIBUTES ObjectAttributes
)
314 FIXME("(%p,0x%08lx,%p) stub\n",
315 LinkHandle
, DesiredAccess
, ObjectAttributes
);
316 dump_ObjectAttributes(ObjectAttributes
);
320 /******************************************************************************
321 * NtCreateSymbolicLinkObject [NTDLL]
323 NTSTATUS WINAPI
NtCreateSymbolicLinkObject(
324 OUT PHANDLE SymbolicLinkHandle
,
325 IN ACCESS_MASK DesiredAccess
,
326 IN POBJECT_ATTRIBUTES ObjectAttributes
,
327 IN PUNICODE_STRING Name
)
329 FIXME("(%p,0x%08lx,%p, %p) stub\n",
330 SymbolicLinkHandle
, DesiredAccess
, ObjectAttributes
, debugstr_us(Name
));
331 dump_ObjectAttributes(ObjectAttributes
);
335 /******************************************************************************
336 * NtQuerySymbolicLinkObject [NTDLL]
338 NTSTATUS WINAPI
NtQuerySymbolicLinkObject(
339 IN HANDLE LinkHandle
,
340 IN OUT PUNICODE_STRING LinkTarget
,
341 OUT PULONG ReturnedLength OPTIONAL
)
343 FIXME("(0x%08x,%p,%p) stub\n",
344 LinkHandle
, debugstr_us(LinkTarget
), ReturnedLength
);
349 /******************************************************************************
350 * NtAllocateUuids [NTDLL]
352 * I have seen lpdwCount pointing to a pointer once...
354 NTSTATUS WINAPI
NtAllocateUuids(LPDWORD lpdwCount
, LPDWORD
*p2
, LPDWORD
*p3
)
356 FIXME("(%p[%ld],%p,%p), stub.\n", lpdwCount
,
357 lpdwCount
? *lpdwCount
: 0,