Blame src/ipc/ntapi_tt_create_pipe_v2.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dd89bb
/*  Copyright (C) 2013,2014,2015  Z. Gilboa             */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_file.h>
dd89bb
#include <ntapi/nt_string.h>
dd89bb
#include <ntapi/nt_tty.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
int32_t __stdcall	__ntapi_ipc_create_pipe_v2(
dd89bb
	__out		void **			hpipe_read,
dd89bb
	__out		void **			hpipe_write,
dd89bb
	__in		uint32_t		advisory_buffer_size	__optional)
dd89bb
{
dd89bb
	int32_t			status;
dd89bb
dd89bb
	void *			hdevpipes;
dd89bb
	void *			hwrite;
dd89bb
	void *			hread;
dd89bb
dd89bb
	nt_object_attributes	oa;
dd89bb
	nt_io_status_block	iosb;
dd89bb
	nt_sqos			sqos;
dd89bb
	nt_unicode_string	nt_name;
dd89bb
	nt_large_integer	timeout;
dd89bb
dd89bb
	const wchar16_t pipe_dir[] =  {
dd89bb
		'\\','D','e','v','i','c','e',
dd89bb
		'\\','N','a','m','e','d','P','i','p','e','\\',0
dd89bb
	};
dd89bb
dd89bb
	/* nt_name: pipe device directory */
dd89bb
	nt_name.strlen = (uint16_t)(sizeof(pipe_dir) - sizeof(wchar16_t));
dd89bb
	nt_name.maxlen = 0;
dd89bb
	nt_name.buffer = (uint16_t *)pipe_dir;
dd89bb
dd89bb
	/* init security structure */
dd89bb
	sqos.length 			= sizeof(sqos);
dd89bb
	sqos.impersonation_level	= NT_SECURITY_IMPERSONATION;
dd89bb
	sqos.context_tracking_mode	= NT_SECURITY_TRACKING_DYNAMIC;
dd89bb
	sqos.effective_only		= 1;
dd89bb
dd89bb
	/* oa */
dd89bb
	oa.len		= sizeof(oa);
dd89bb
	oa.root_dir	= (void *)0;
dd89bb
	oa.obj_name	= &nt_name;
dd89bb
	oa.obj_attr	= NT_OBJ_CASE_INSENSITIVE | NT_OBJ_INHERIT;
dd89bb
	oa.sec_desc	= (nt_security_descriptor *)0;
dd89bb
	oa.sec_qos	= &sqo;;
dd89bb
dd89bb
	status = __ntapi->zw_open_file(
dd89bb
		&hdevpipes,
dd89bb
		NT_GENERIC_READ | NT_SEC_SYNCHRONIZE,
dd89bb
		&oa,
dd89bb
		&iosb,
dd89bb
		NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
dd89bb
		NT_FILE_DIRECTORY_FILE);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
dd89bb
	timeout.ihigh = 0xffffffff;
dd89bb
	timeout.ulow  = 0x0;
dd89bb
dd89bb
	oa.root_dir = hdevpipes;
dd89bb
dd89bb
	nt_name.strlen=0;
dd89bb
	nt_name.buffer = (uint16_t *)0;
dd89bb
dd89bb
	status = __ntapi->zw_create_named_pipe_file(
dd89bb
		&hread,
dd89bb
		NT_GENERIC_READ | NT_SEC_SYNCHRONIZE | NT_FILE_WRITE_ATTRIBUTES,
dd89bb
		&oa,
dd89bb
		&iosb,
dd89bb
		NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
dd89bb
		NT_FILE_CREATE,
dd89bb
		NT_FILE_ASYNCHRONOUS_IO,
dd89bb
		0,
dd89bb
		0,
dd89bb
		0,
dd89bb
		1,
dd89bb
		0X2000,
dd89bb
		0x2000,
dd89bb
		&timeout);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS) {
dd89bb
		__ntapi->zw_close(hdevpipes);
dd89bb
		return status;
dd89bb
	}
dd89bb
dd89bb
	/* the pipe is now our root directory */
dd89bb
	oa.root_dir = hread;
dd89bb
dd89bb
	status = __ntapi->zw_open_file(
dd89bb
		&hwrite,
dd89bb
		NT_GENERIC_WRITE | NT_SEC_SYNCHRONIZE | NT_FILE_READ_ATTRIBUTES,
dd89bb
		&oa,
dd89bb
		&iosb,
dd89bb
		NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
dd89bb
		NT_FILE_WRITE_THROUGH | NT_FILE_ASYNCHRONOUS_IO | NT_FILE_NON_DIRECTORY_FILE);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS) {
dd89bb
		__ntapi->zw_close(hdevpipes);
dd89bb
		__ntapi->zw_close(hread);
dd89bb
		return status;
dd89bb
	}
dd89bb
dd89bb
	*hpipe_read  = hread;
dd89bb
	*hpipe_write = hwrite;
dd89bb
dd89bb
	return status;
dd89bb
}