Blame src/object/ntapi_tt_keyed_object_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 <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_object.h>
dd89bb
#include <ntapi/nt_guid.h>
dd89bb
#include <ntapi/nt_string.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
typedef ntapi_zw_open_directory_object objdir_open_fn;
dd89bb
1219be
static  nt_keyed_objdir_name __template_name = {__NT_BASED_NAMED_OBJECTS,
1219be
						0,
1219be
						{0,0,0,0,0,0},
1219be
						{0,{0},0},
1219be
						{0}};
af6bd7
dd89bb
static int32_t __stdcall __tt_create_keyed_object_directory(
dd89bb
	__out	void **			hdir,
dd89bb
	__in	uint32_t		desired_access,
dd89bb
	__in	const wchar16_t		prefix[6],
dd89bb
	__in	nt_guid *		guid,
dd89bb
	__in	uint32_t		key,
dd89bb
	__in	objdir_open_fn *	openfn)
dd89bb
{
af6bd7
	nt_keyed_objdir_name	objdir_name;
dd89bb
	nt_unicode_string	name;
dd89bb
	nt_oa			oa;
dd89bb
	nt_sqos			sqos = {
dd89bb
					sizeof(sqos),
dd89bb
					NT_SECURITY_IMPERSONATION,
dd89bb
					NT_SECURITY_TRACKING_DYNAMIC,
dd89bb
					1};
dd89bb
af6bd7
	__ntapi->tt_generic_memcpy(
af6bd7
		&objdir_name,
af6bd7
		&__template_name,
af6bd7
		sizeof(__template_name));
af6bd7
dd89bb
	__ntapi->tt_memcpy_utf16(
dd89bb
		objdir_name.prefix,
dd89bb
		prefix,
dd89bb
		sizeof(objdir_name.prefix));
dd89bb
dd89bb
	__ntapi->tt_guid_to_utf16_string(
dd89bb
		guid,
dd89bb
		(nt_guid_str_utf16 *)&objdir_name.objdir_guid);
dd89bb
dd89bb
	__ntapi->tt_uint32_to_hex_utf16(
dd89bb
		key,objdir_name.key);
dd89bb
dd89bb
	objdir_name.backslash = '\\';
dd89bb
	objdir_name.objdir_guid.uscore_guid = '_';
dd89bb
	objdir_name.objdir_guid.uscore_key  = '_';
dd89bb
dd89bb
	name.strlen	= sizeof(objdir_name);
dd89bb
	name.maxlen	= 0;
dd89bb
	name.buffer	= (uint16_t *)&objdir_name;
dd89bb
dd89bb
	oa.len		= sizeof(oa);
dd89bb
	oa.root_dir	= 0;
dd89bb
	oa.obj_name	= &nam;;
dd89bb
	oa.obj_attr	= NT_OBJ_INHERIT;
dd89bb
	oa.sec_desc	= 0;
dd89bb
	oa.sec_qos	= &sqo;;
dd89bb
dd89bb
	return openfn(hdir,desired_access,&oa);
dd89bb
}
dd89bb
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_create_keyed_object_directory_entry(
dd89bb
	__out	void **			hentry,
dd89bb
	__in	uint32_t		desired_access,
dd89bb
	__in	void *			hdir,
dd89bb
	__in	void *			htarget,
dd89bb
	__in	nt_unicode_string *	target_name,
dd89bb
	__in	uint32_t		key)
dd89bb
{
dd89bb
	int32_t			status;
dd89bb
	nt_oa			oa;
dd89bb
	nt_unicode_string	name;
dd89bb
	wchar16_t		keystr[8];
dd89bb
	uintptr_t		buffer[2048/sizeof(uintptr_t)];
dd89bb
	nt_sqos			sqos = {
dd89bb
					sizeof(sqos),
dd89bb
					NT_SECURITY_IMPERSONATION,
dd89bb
					NT_SECURITY_TRACKING_DYNAMIC,
dd89bb
					1};
dd89bb
dd89bb
	if (!target_name) {
dd89bb
		if ((status = __ntapi->zw_query_object(
dd89bb
				htarget,
dd89bb
				NT_OBJECT_NAME_INFORMATION,
dd89bb
				buffer,sizeof(buffer),0)))
dd89bb
			return status;
dd89bb
		target_name = (nt_unicode_string *)buffer;
dd89bb
	}
dd89bb
dd89bb
	__ntapi->tt_uint32_to_hex_utf16(key,keystr);
dd89bb
dd89bb
	name.strlen = sizeof(keystr);
dd89bb
	name.maxlen = 0;
dd89bb
	name.buffer = keystr;
dd89bb
dd89bb
	oa.len		= sizeof(oa);
dd89bb
	oa.root_dir	= hdir;
dd89bb
	oa.obj_name	= &nam;;
dd89bb
	oa.obj_attr	= 0;
dd89bb
	oa.sec_desc	= 0;
dd89bb
	oa.sec_qos	= &sqo;;
dd89bb
dd89bb
	return __ntapi->zw_create_symbolic_link_object(
dd89bb
		hentry,
dd89bb
		desired_access,
dd89bb
		&oa,target_name);
dd89bb
}
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_create_keyed_object_directory(
dd89bb
	__out	void **			hdir,
dd89bb
	__in	uint32_t		desired_access,
dd89bb
	__in	const wchar16_t		prefix[6],
dd89bb
	__in	nt_guid *		guid,
dd89bb
	__in	uint32_t		key)
dd89bb
{
dd89bb
	return __tt_create_keyed_object_directory(
dd89bb
		hdir,desired_access,
dd89bb
		prefix,guid,key,
dd89bb
		__ntapi->zw_create_directory_object);
dd89bb
}
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_open_keyed_object_directory(
dd89bb
	__out	void **			hdir,
dd89bb
	__in	uint32_t		desired_access,
dd89bb
	__in	const wchar16_t		prefix[6],
dd89bb
	__in	nt_guid *		guid,
dd89bb
	__in	uint32_t		key)
dd89bb
{
dd89bb
	return __tt_create_keyed_object_directory(
dd89bb
		hdir,desired_access,
dd89bb
		prefix,guid,key,
dd89bb
		__ntapi->zw_open_directory_object);
dd89bb
}