summaryrefslogtreecommitdiffhomepage
path: root/src/pty/ntapi_pty_xquery.c
blob: 165c0c35485823e185a8a9954f80a9b7b1d7146e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_port.h>
#include <ntapi/nt_tty.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"
#include "ntapi_pty.h"


static int32_t __pty_xquery_inherit_info(
	void *			hport,
	nt_io_status_block *	iosb,
	void *			pty_info,
	uint32_t		pty_info_length,
	nt_pty_client_info *	pty_client_info)
{
	int32_t			status;
	nt_pty_sigctl_msg	msg;
	nt_pty_inherit_info * 	inherit;

	if (pty_info_length < sizeof(nt_pty_inherit_info))
		return NT_STATUS_INVALID_PARAMETER;

	__ntapi->tt_aligned_block_memset(
		&msg,0,sizeof(msg));

	msg.header.msg_type        = NT_LPC_NEW_MESSAGE;
	msg.header.data_size       = sizeof(msg.data);
	msg.header.msg_size        = sizeof(msg);
	msg.data.ttyinfo.opcode    = NT_TTY_PTY_QUERY;

	msg.data.ctlinfo.hpty      = NT_INVALID_HANDLE_VALUE;
	msg.data.ctlinfo.ctlcode   = NT_PTY_INHERIT_INFORMATION;

	msg.data.ctlinfo.ctxarg[0] = pty_client_info->any[0];
	msg.data.ctlinfo.ctxarg[1] = pty_client_info->any[1];
	msg.data.ctlinfo.ctxarg[2] = pty_client_info->any[2];
	msg.data.ctlinfo.ctxarg[3] = pty_client_info->any[3];

	if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
		return status;

	else if (msg.data.ttyinfo.status)
		return msg.data.ttyinfo.status;

	inherit            = (nt_pty_inherit_info *)pty_info;
	inherit->hpty      = msg.data.ctlinfo.hpty;
	inherit->luid.low  = msg.data.ctlinfo.luid.low;
	inherit->luid.high = msg.data.ctlinfo.luid.high;

	inherit->access    = (uint32_t)msg.data.ctlinfo.ctxarg[0];
	inherit->flags     = (uint32_t)msg.data.ctlinfo.ctxarg[1];
	inherit->share     = (uint32_t)msg.data.ctlinfo.ctxarg[2];
	inherit->options   = (uint32_t)msg.data.ctlinfo.ctxarg[3];

	__ntapi->tt_guid_copy(
		&inherit->guid,
		&msg.data.ctlinfo.guid);

	iosb->status = NT_STATUS_SUCCESS;
	iosb->info   = sizeof(*inherit);

	return NT_STATUS_SUCCESS;
}


static int32_t __pty_xquery_context_info(
	void *			hport,
	nt_io_status_block *	iosb,
	void *			pty_info,
	uint32_t		pty_info_length,
	nt_pty_client_info *	pty_client_info)
{
	int32_t			status;
	nt_pty_sigctl_msg	msg;
	nt_pty_context_info * 	context;

	if (pty_info_length < sizeof(nt_pty_inherit_info))
		return NT_STATUS_INVALID_PARAMETER;

	__ntapi->tt_aligned_block_memset(
		&msg,0,sizeof(msg));

	msg.header.msg_type        = NT_LPC_NEW_MESSAGE;
	msg.header.data_size       = sizeof(msg.data);
	msg.header.msg_size        = sizeof(msg);
	msg.data.ttyinfo.opcode    = NT_TTY_PTY_QUERY;

	msg.data.ctlinfo.hpty      = NT_INVALID_HANDLE_VALUE;
	msg.data.ctlinfo.ctlcode   = NT_PTY_CONTEXT_INFORMATION;

	msg.data.ctlinfo.ctxarg[0] = pty_client_info->any[0];
	msg.data.ctlinfo.ctxarg[1] = pty_client_info->any[1];
	msg.data.ctlinfo.ctxarg[2] = pty_client_info->any[2];
	msg.data.ctlinfo.ctxarg[3] = pty_client_info->any[3];

	__ntapi->tt_guid_copy(
		&msg.data.ctlinfo.guid,
		&(nt_guid)TTY_PTS_GUID);

	if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
		return status;

	else if (msg.data.ttyinfo.status)
		return msg.data.ttyinfo.status;

	context            = (nt_pty_context_info *)pty_info;
	context->hpty      = msg.data.ctlinfo.hpty;
	context->luid.low  = msg.data.ctlinfo.luid.low;
	context->luid.high = msg.data.ctlinfo.luid.high;

	context->ctxarg[0] = msg.data.ctlinfo.ctxarg[0];
	context->ctxarg[1] = msg.data.ctlinfo.ctxarg[1];
	context->ctxarg[2] = msg.data.ctlinfo.ctxarg[2];
	context->ctxarg[3] = msg.data.ctlinfo.ctxarg[3];

	__ntapi->tt_guid_copy(
		&context->guid,
		&msg.data.ctlinfo.guid);

	iosb->status = NT_STATUS_SUCCESS;
	iosb->info   = sizeof(*context);

	return NT_STATUS_SUCCESS;
}


int32_t	__stdcall __ntapi_pty_xquery(
	void *			hport,
	nt_io_status_block *	iosb,
	void *			pty_info,
	uint32_t		pty_info_length,
	nt_pty_info_class	pty_info_class,
	nt_pty_client_info *	pty_client_info)
{
	if (pty_info_class == NT_PTY_INHERIT_INFORMATION)
		return __pty_xquery_inherit_info(
			hport,iosb,pty_info,
			pty_info_length,
			pty_client_info);

	else if (pty_info_class == NT_PTY_CONTEXT_INFORMATION)
		return __pty_xquery_context_info(
			hport,iosb,pty_info,
			pty_info_length,
			pty_client_info);

	return NT_STATUS_WRONG_COMPARTMENT;
}