Blame src/pty/ntapi_pty_xquery.c

e62c29
/********************************************************/
e62c29
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
e62c29
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
e62c29
/********************************************************/
e62c29
e62c29
#include <psxtypes/psxtypes.h>
e62c29
#include <ntapi/nt_port.h>
e62c29
#include <ntapi/nt_tty.h>
e62c29
#include <ntapi/ntapi.h>
e62c29
#include "ntapi_impl.h"
e62c29
#include "ntapi_pty.h"
e62c29
e62c29
e62c29
static int32_t __pty_xquery_inherit_info(
e62c29
	void *			hport,
e62c29
	nt_io_status_block *	iosb,
e62c29
	void *			pty_info,
e62c29
	uint32_t		pty_info_length,
e62c29
	nt_pty_client_info *	pty_client_info)
e62c29
{
e62c29
	int32_t			status;
e62c29
	nt_pty_sigctl_msg	msg;
e62c29
	nt_pty_inherit_info * 	inherit;
e62c29
e62c29
	if (pty_info_length < sizeof(nt_pty_inherit_info))
e62c29
		return NT_STATUS_INVALID_PARAMETER;
e62c29
e62c29
	__ntapi->tt_aligned_block_memset(
e62c29
		&msg,0,sizeof(msg));
e62c29
e62c29
	msg.header.msg_type        = NT_LPC_NEW_MESSAGE;
e62c29
	msg.header.data_size       = sizeof(msg.data);
e62c29
	msg.header.msg_size        = sizeof(msg);
e62c29
	msg.data.ttyinfo.opcode    = NT_TTY_PTY_QUERY;
e62c29
e62c29
	msg.data.ctlinfo.hpty      = NT_INVALID_HANDLE_VALUE;
e62c29
	msg.data.ctlinfo.ctlcode   = NT_PTY_INHERIT_INFORMATION;
e62c29
e62c29
	msg.data.ctlinfo.ctxarg[0] = pty_client_info->any[0];
e62c29
	msg.data.ctlinfo.ctxarg[1] = pty_client_info->any[1];
e62c29
	msg.data.ctlinfo.ctxarg[2] = pty_client_info->any[2];
e62c29
	msg.data.ctlinfo.ctxarg[3] = pty_client_info->any[3];
e62c29
e62c29
	if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
e62c29
		return status;
e62c29
e62c29
	else if (msg.data.ttyinfo.status)
e62c29
		return msg.data.ttyinfo.status;
e62c29
e62c29
	inherit            = (nt_pty_inherit_info *)pty_info;
e62c29
	inherit->hpty      = msg.data.ctlinfo.hpty;
e62c29
	inherit->luid.low  = msg.data.ctlinfo.luid.low;
e62c29
	inherit->luid.high = msg.data.ctlinfo.luid.high;
e62c29
e62c29
	inherit->access    = (uint32_t)msg.data.ctlinfo.ctxarg[0];
e62c29
	inherit->flags     = (uint32_t)msg.data.ctlinfo.ctxarg[1];
e62c29
	inherit->share     = (uint32_t)msg.data.ctlinfo.ctxarg[2];
e62c29
	inherit->options   = (uint32_t)msg.data.ctlinfo.ctxarg[3];
e62c29
e62c29
	__ntapi->tt_guid_copy(
e62c29
		&inherit->guid,
e62c29
		&msg.data.ctlinfo.guid);
e62c29
576364
	iosb->status = NT_STATUS_SUCCESS;
576364
	iosb->info   = sizeof(*inherit);
576364
576364
	return NT_STATUS_SUCCESS;
576364
}
576364
576364
576364
static int32_t __pty_xquery_context_info(
576364
	void *			hport,
576364
	nt_io_status_block *	iosb,
576364
	void *			pty_info,
576364
	uint32_t		pty_info_length,
576364
	nt_pty_client_info *	pty_client_info)
576364
{
576364
	int32_t			status;
576364
	nt_pty_sigctl_msg	msg;
576364
	nt_pty_context_info * 	context;
576364
576364
	if (pty_info_length < sizeof(nt_pty_inherit_info))
576364
		return NT_STATUS_INVALID_PARAMETER;
576364
576364
	__ntapi->tt_aligned_block_memset(
576364
		&msg,0,sizeof(msg));
576364
576364
	msg.header.msg_type        = NT_LPC_NEW_MESSAGE;
576364
	msg.header.data_size       = sizeof(msg.data);
576364
	msg.header.msg_size        = sizeof(msg);
576364
	msg.data.ttyinfo.opcode    = NT_TTY_PTY_QUERY;
576364
576364
	msg.data.ctlinfo.hpty      = NT_INVALID_HANDLE_VALUE;
576364
	msg.data.ctlinfo.ctlcode   = NT_PTY_CONTEXT_INFORMATION;
576364
576364
	msg.data.ctlinfo.ctxarg[0] = pty_client_info->any[0];
576364
	msg.data.ctlinfo.ctxarg[1] = pty_client_info->any[1];
576364
	msg.data.ctlinfo.ctxarg[2] = pty_client_info->any[2];
576364
	msg.data.ctlinfo.ctxarg[3] = pty_client_info->any[3];
576364
576364
	__ntapi->tt_guid_copy(
576364
		&msg.data.ctlinfo.guid,
576364
		&(nt_guid)TTY_PTS_GUID);
576364
576364
	if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
576364
		return status;
576364
576364
	else if (msg.data.ttyinfo.status)
576364
		return msg.data.ttyinfo.status;
576364
576364
	context            = (nt_pty_context_info *)pty_info;
576364
	context->hpty      = msg.data.ctlinfo.hpty;
576364
	context->luid.low  = msg.data.ctlinfo.luid.low;
576364
	context->luid.high = msg.data.ctlinfo.luid.high;
576364
576364
	context->ctxarg[0] = msg.data.ctlinfo.ctxarg[0];
576364
	context->ctxarg[1] = msg.data.ctlinfo.ctxarg[1];
576364
	context->ctxarg[2] = msg.data.ctlinfo.ctxarg[2];
576364
	context->ctxarg[3] = msg.data.ctlinfo.ctxarg[3];
576364
576364
	__ntapi->tt_guid_copy(
576364
		&context->guid,
576364
		&msg.data.ctlinfo.guid);
576364
576364
	iosb->status = NT_STATUS_SUCCESS;
576364
	iosb->info   = sizeof(*context);
576364
e62c29
	return NT_STATUS_SUCCESS;
e62c29
}
e62c29
e62c29
e62c29
int32_t	__stdcall __ntapi_pty_xquery(
e62c29
	void *			hport,
e62c29
	nt_io_status_block *	iosb,
e62c29
	void *			pty_info,
e62c29
	uint32_t		pty_info_length,
e62c29
	nt_pty_info_class	pty_info_class,
e62c29
	nt_pty_client_info *	pty_client_info)
e62c29
{
e62c29
	if (pty_info_class == NT_PTY_INHERIT_INFORMATION)
e62c29
		return __pty_xquery_inherit_info(
e62c29
			hport,iosb,pty_info,
e62c29
			pty_info_length,
e62c29
			pty_client_info);
e62c29
576364
	else if (pty_info_class == NT_PTY_CONTEXT_INFORMATION)
576364
		return __pty_xquery_context_info(
576364
			hport,iosb,pty_info,
576364
			pty_info_length,
576364
			pty_client_info);
576364
e62c29
	return NT_STATUS_WRONG_COMPARTMENT;
e62c29
}