Blame src/pty/ntapi_pty_query.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dde53a
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_port.h>
dd89bb
#include <ntapi/nt_tty.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
#include "ntapi_pty.h"
dd89bb
dd89bb
int32_t	__stdcall __ntapi_pty_query(
dd89bb
	nt_pty *		pty,
dd89bb
	nt_io_status_block *	iosb,
dd89bb
	void *			pty_info,
dd89bb
	uint32_t		pty_info_length,
dd89bb
	nt_pty_info_class	pty_info_class)
dd89bb
{
dd89bb
	int32_t			status;
efc01e
	void * 			hport;
dd89bb
	nt_pty_sigctl_msg	msg;
dd89bb
	uintptr_t *		info;
efc01e
	nt_pty_inherit_info * 	inherit;
dd89bb
858b95
	if (pty_info_class>=NT_PTY_INFORMATION_CAP)
dd89bb
		return NT_STATUS_INVALID_INFO_CLASS;
dd89bb
	else if (pty_info_class == NT_PTY_BASIC_INFORMATION)
dd89bb
		return NT_STATUS_NOT_IMPLEMENTED;
dd89bb
	else if ((pty_info_class == NT_PTY_CLIENT_INFORMATION) && (pty_info_length != sizeof(nt_pty_client_info)))
dd89bb
		return NT_STATUS_INVALID_PARAMETER;
efc01e
	else if ((pty_info_class == NT_PTY_INHERIT_INFORMATION) && (pty_info_length != sizeof(nt_pty_inherit_info)))
efc01e
		return NT_STATUS_INVALID_PARAMETER;
dd89bb
dd89bb
	__ntapi->tt_aligned_block_memset(
dd89bb
		&msg,0,sizeof(msg));
dd89bb
dd89bb
	msg.header.msg_type		= NT_LPC_NEW_MESSAGE;
dd89bb
	msg.header.data_size		= sizeof(msg.data);
dd89bb
	msg.header.msg_size		= sizeof(msg);
dd89bb
	msg.data.ttyinfo.opcode		= NT_TTY_PTY_QUERY;
dd89bb
efc01e
	if (pty_info_class == NT_PTY_CLIENT_INFORMATION) {
efc01e
		hport 				= pty->hport;
efc01e
		msg.data.ctlinfo.hpty		= pty->hpty;
efc01e
		msg.data.ctlinfo.luid.high	= pty->luid.high;
efc01e
		msg.data.ctlinfo.luid.low	= pty->luid.low;
efc01e
		msg.data.ctlinfo.ctlcode	= pty_info_class;
efc01e
efc01e
		__ntapi->tt_guid_copy(
efc01e
			&msg.data.ctlinfo.guid,
efc01e
			&pty->guid);
efc01e
efc01e
	} else if (pty_info_class == NT_PTY_INHERIT_INFORMATION) {
efc01e
		msg.data.ctlinfo.hpty		= NT_INVALID_HANDLE_VALUE;
efc01e
		msg.data.ctlinfo.ctlcode	= pty_info_class;
efc01e
efc01e
		inherit = (nt_pty_inherit_info *)pty_info;
efc01e
		msg.data.ctlinfo.ctxarg[0] = inherit->any[0];
efc01e
		msg.data.ctlinfo.ctxarg[1] = inherit->any[1];
efc01e
		msg.data.ctlinfo.ctxarg[2] = inherit->any[2];
efc01e
		msg.data.ctlinfo.ctxarg[3] = inherit->any[3];
dd89bb
efc01e
		hport = pty ? pty : __ntapi_internals()->hport_tty_session;
db8062
	} else {
db8062
		return NT_STATUS_INVALID_INFO_CLASS;
efc01e
	}
dd89bb
efc01e
	if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
dd89bb
		return status;
dd89bb
	else if (msg.data.ttyinfo.status)
dd89bb
		return msg.data.ttyinfo.status;
dd89bb
dd89bb
	iosb->info   = msg.data.ctlinfo.iosb.info;
dd89bb
	iosb->status = msg.data.ctlinfo.iosb.status;
dd89bb
efc01e
	if (pty_info_class == NT_PTY_CLIENT_INFORMATION) {
efc01e
		info = (uintptr_t *)pty_info;
efc01e
		info[0] = msg.data.ctlinfo.ctxarg[0];
efc01e
		info[1] = msg.data.ctlinfo.ctxarg[1];
efc01e
		info[2] = msg.data.ctlinfo.ctxarg[2];
efc01e
		info[3] = msg.data.ctlinfo.ctxarg[3];
efc01e
efc01e
	} else if (pty_info_class == NT_PTY_INHERIT_INFORMATION) {
efc01e
		inherit = (nt_pty_inherit_info *)pty_info;
efc01e
		inherit->hpty 		= msg.data.ctlinfo.hpty;
efc01e
		inherit->luid.low 	= msg.data.ctlinfo.luid.low;
efc01e
		inherit->luid.high 	= msg.data.ctlinfo.luid.high;
efc01e
e6f6f2
		inherit->access		= (uint32_t)msg.data.ctlinfo.ctxarg[0];
e6f6f2
		inherit->flags 		= (uint32_t)msg.data.ctlinfo.ctxarg[1];
e6f6f2
		inherit->share 		= (uint32_t)msg.data.ctlinfo.ctxarg[2];
e6f6f2
		inherit->options 	= (uint32_t)msg.data.ctlinfo.ctxarg[3];
efc01e
efc01e
		__ntapi->tt_guid_copy(
efc01e
			&inherit->guid,
efc01e
			&msg.data.ctlinfo.guid);
efc01e
	}
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}