Blame src/fs/ntapi_tt_open_physical_parent_directory.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include <ntapi/nt_file.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_open_physical_parent_directory(
dd89bb
	__out	void **		hparent,
dd89bb
	__in	void *		hdir,
dd89bb
	__out	uintptr_t *	buffer,
dd89bb
	__in	uint32_t	buffer_size,
dd89bb
	__in	uint32_t	desired_access,
dd89bb
	__in	uint32_t	open_options,
dd89bb
	__out	int32_t *	type)
dd89bb
{
dd89bb
	int32_t				status;
dd89bb
	nt_oa				oa;
dd89bb
	nt_iosb				iosb;
dd89bb
	wchar16_t *			wch;
dd89bb
	nt_unicode_string *		path;
dd89bb
	uint32_t			len;
dd89bb
c713d8
	(void)type;
c713d8
dd89bb
	path = (nt_unicode_string *)buffer;
dd89bb
dd89bb
	if ((status = __ntapi->zw_query_object(
dd89bb
			hdir,
dd89bb
			NT_OBJECT_NAME_INFORMATION,
dd89bb
			path,
dd89bb
			buffer_size,
dd89bb
			&len)))
dd89bb
		return status;
dd89bb
	else if (len == sizeof(nt_unicode_string))
dd89bb
		return NT_STATUS_BAD_FILE_TYPE;
dd89bb
dd89bb
	wch = path->buffer + (path->strlen / sizeof(uint16_t));
dd89bb
4fdb5b
	for (; (wch > path->buffer) && (wch[-1] != '\\'); wch--)
4fdb5b
		(void)0;
4fdb5b
4fdb5b
	if (wch == path->buffer)
dd89bb
		return NT_STATUS_MORE_PROCESSING_REQUIRED;
dd89bb
dd89bb
	path->strlen = sizeof(uint16_t) * (uint16_t)(wch-path->buffer);
dd89bb
	path->maxlen = 0;
dd89bb
dd89bb
	/* oa */
dd89bb
	oa.len = sizeof(nt_oa);
dd89bb
	oa.root_dir = 0;
dd89bb
	oa.obj_name = path;
dd89bb
	oa.obj_attr = 0;
dd89bb
	oa.sec_desc = 0;
dd89bb
	oa.sec_qos  = 0;
dd89bb
dd89bb
	/* default access */
dd89bb
	desired_access = desired_access
dd89bb
		? desired_access
dd89bb
		: NT_SEC_SYNCHRONIZE | NT_FILE_READ_ATTRIBUTES | NT_FILE_READ_ACCESS;
dd89bb
dd89bb
	/* open parent directory */
dd89bb
	return __ntapi->zw_open_file(
dd89bb
		hparent,
dd89bb
		desired_access,
dd89bb
		&oa,
dd89bb
		&iosb,
dd89bb
		NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
dd89bb
		open_options | NT_FILE_DIRECTORY_FILE);
dd89bb
}