summaryrefslogtreecommitdiffhomepage
path: root/src/fs/ntapi_tt_open_physical_parent_directory.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-07-27 04:01:18 -0400
committermidipix <writeonce@midipix.org>2015-07-27 04:01:18 -0400
commitdd89bb8ad4fe184a34b5dbdda237e640fc82121b (patch)
tree5e80d2da35f5892f92be29f57982b2708e6bd99b /src/fs/ntapi_tt_open_physical_parent_directory.c
parentdcdadc2702712fa750ed255ed1dfa354522797a0 (diff)
downloadntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2
ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz
entered advanced internal development stage.
Diffstat (limited to 'src/fs/ntapi_tt_open_physical_parent_directory.c')
-rw-r--r--src/fs/ntapi_tt_open_physical_parent_directory.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/fs/ntapi_tt_open_physical_parent_directory.c b/src/fs/ntapi_tt_open_physical_parent_directory.c
new file mode 100644
index 0000000..68d282b
--- /dev/null
+++ b/src/fs/ntapi_tt_open_physical_parent_directory.c
@@ -0,0 +1,69 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013,2014,2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
+/********************************************************/
+
+#include <ntapi/ntapi.h>
+#include <ntapi/nt_file.h>
+#include "ntapi_impl.h"
+
+int32_t __stdcall __ntapi_tt_open_physical_parent_directory(
+ __out void ** hparent,
+ __in void * hdir,
+ __out uintptr_t * buffer,
+ __in uint32_t buffer_size,
+ __in uint32_t desired_access,
+ __in uint32_t open_options,
+ __out int32_t * type)
+{
+ int32_t status;
+ nt_oa oa;
+ nt_iosb iosb;
+ wchar16_t * wch;
+ nt_unicode_string * path;
+ uint32_t len;
+
+ path = (nt_unicode_string *)buffer;
+
+ if ((status = __ntapi->zw_query_object(
+ hdir,
+ NT_OBJECT_NAME_INFORMATION,
+ path,
+ buffer_size,
+ &len)))
+ return status;
+ else if (len == sizeof(nt_unicode_string))
+ return NT_STATUS_BAD_FILE_TYPE;
+
+ wch = path->buffer + (path->strlen / sizeof(uint16_t));
+ while ((--wch >= path->buffer) && (*wch != '\\'));
+
+ if (wch == path->buffer )
+ return NT_STATUS_MORE_PROCESSING_REQUIRED;
+
+ path->strlen = sizeof(uint16_t) * (uint16_t)(wch-path->buffer);
+ path->maxlen = 0;
+
+ /* oa */
+ oa.len = sizeof(nt_oa);
+ oa.root_dir = 0;
+ oa.obj_name = path;
+ oa.obj_attr = 0;
+ oa.sec_desc = 0;
+ oa.sec_qos = 0;
+
+ /* default access */
+ desired_access = desired_access
+ ? desired_access
+ : NT_SEC_SYNCHRONIZE | NT_FILE_READ_ATTRIBUTES | NT_FILE_READ_ACCESS;
+
+ /* open parent directory */
+ return __ntapi->zw_open_file(
+ hparent,
+ desired_access,
+ &oa,
+ &iosb,
+ NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
+ open_options | NT_FILE_DIRECTORY_FILE);
+}