efc01e pty inheritance: client-side implementation.

Authored and Committed by midipix 9 years ago
    pty inheritance: client-side implementation.
    
        
file modified
+28 -1
include/ntapi/nt_tty.h CHANGED
@@ -68,10 +68,15 @@ typedef enum _nt_tty_info_class {
68
68
typedef enum _nt_pty_info_class {
69
69
NT_PTY_BASIC_INFORMATION,
70
70
NT_PTY_CLIENT_INFORMATION,
71
+ NT_PTY_INHERIT_INFORMATION,
71
72
NT_PTY_INFORMATION_CAP
72
73
} nt_pty_info_class;
73
74
74
75
76
+ /* client process registration flags */
77
+ #define NT_TTY_INHERIT_HANDLES 0x0001
78
+
79
+
75
80
typedef struct __attr_ptr_size_aligned__ _nt_tty_msg_info {
76
81
uintptr_t msg_id;
77
82
uint32_t opcode;
@@ -166,6 +171,23 @@ typedef struct __attr_ptr_size_aligned__ _nt_pty_client_info {
166
171
} nt_pty_client_info;
167
172
168
173
174
+ typedef struct __attr_ptr_size_aligned__ _nt_pty_inherit_info {
175
+ void * hpty;
176
+ nt_guid guid;
177
+ nt_luid luid;
178
+
179
+ union {
180
+ struct {
181
+ uint32_t access;
182
+ uint32_t flags;
183
+ uint32_t share;
184
+ uint32_t options;
185
+ };
186
+
187
+ uintptr_t any[4];
188
+ };
189
+ } nt_pty_inherit_info;
190
+
169
191
typedef struct __attr_ptr_size_aligned__ _nt_tty_session_info {
170
192
int32_t pid;
171
193
int32_t pgid;
@@ -173,7 +195,6 @@ typedef struct __attr_ptr_size_aligned__ _nt_tty_session_info {
173
195
int32_t reserved;
174
196
} nt_tty_session_info;
175
197
176
-
177
198
typedef struct __attr_ptr_size_aligned__ _nt_tty_register_msg {
178
199
nt_port_message header;
179
200
struct {
@@ -341,6 +362,12 @@ typedef int32_t __stdcall ntapi_pty_reopen(
341
362
__in nt_pty * pty);
342
363
343
364
365
+ typedef int32_t __stdcall ntapi_pty_inherit(
366
+ __in void * hport,
367
+ __out nt_pty ** pty,
368
+ __in nt_pty_client_info * client_info);
369
+
370
+
344
371
typedef int32_t __stdcall ntapi_pty_close(
345
372
__in nt_pty * pty);
346
373
file modified
+1 -0
include/ntapi/ntapi.h CHANGED
@@ -524,6 +524,7 @@ typedef struct _ntapi_vtbl {
524
524
ntapi_tty_vms_request * tty_vms_request;
525
525
ntapi_pty_open * pty_open;
526
526
ntapi_pty_reopen * pty_reopen;
527
+ ntapi_pty_inherit * pty_inherit;
527
528
ntapi_pty_close * pty_close;
528
529
ntapi_pty_read * pty_read;
529
530
ntapi_pty_write * pty_write;
file modified
+1 -0
src/internal/ntapi.c CHANGED
@@ -288,6 +288,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl)
288
288
__ntapi->tty_vms_request = __ntapi_tty_vms_request;
289
289
__ntapi->pty_open = __ntapi_pty_open;
290
290
__ntapi->pty_reopen = __ntapi_pty_reopen;
291
+ __ntapi->pty_inherit = __ntapi_pty_inherit;
291
292
__ntapi->pty_close = __ntapi_pty_close;
292
293
__ntapi->pty_read = __ntapi_pty_read;
293
294
__ntapi->pty_write = __ntapi_pty_write;
file modified
+1 -0
src/internal/ntapi_fnapi.h CHANGED
@@ -180,6 +180,7 @@ ntapi_tty_vms_query __ntapi_tty_vms_query;
180
180
ntapi_tty_vms_request __ntapi_tty_vms_request;
181
181
ntapi_pty_open __ntapi_pty_open;
182
182
ntapi_pty_reopen __ntapi_pty_reopen;
183
+ ntapi_pty_inherit __ntapi_pty_inherit;
183
184
ntapi_pty_close __ntapi_pty_close;
184
185
ntapi_pty_read __ntapi_pty_read;
185
186
ntapi_pty_write __ntapi_pty_write;
file modified
+45 -0
src/pty/ntapi_pty_fd.c CHANGED
@@ -213,6 +213,51 @@ int32_t __stdcall __ntapi_pty_open(
213
213
return NT_STATUS_SUCCESS;
214
214
}
215
215
216
+ int32_t __stdcall __ntapi_pty_inherit(
217
+ __in void * hport,
218
+ __out nt_pty ** pty,
219
+ __in nt_pty_client_info * client_info)
220
+ {
221
+ int32_t status;
222
+ nt_iosb iosb;
223
+ nt_pty_inherit_info inherit;
224
+ nt_pty * ctx;
225
+
226
+ inherit.any[0] = client_info->any[0];
227
+ inherit.any[1] = client_info->any[1];
228
+ inherit.any[2] = client_info->any[2];
229
+ inherit.any[3] = client_info->any[3];
230
+
231
+ if ((status = __ntapi_pty_query(
232
+ hport,&iosb,
233
+ &inherit,sizeof(inherit),
234
+ NT_PTY_INHERIT_INFORMATION)))
235
+ return status;
236
+
237
+ /* control block */
238
+ if ((status = __ntapi_pty_alloc(&ctx)))
239
+ return status;
240
+
241
+ __ntapi_tt_guid_copy(
242
+ &ctx->guid,
243
+ &inherit.guid);
244
+
245
+ ctx->access = inherit.access;
246
+ ctx->flags = inherit.flags;
247
+ ctx->share = inherit.share;
248
+ ctx->options = inherit.options;
249
+
250
+ ctx->luid.low = inherit.luid.low;
251
+ ctx->luid.high = inherit.luid.high;
252
+
253
+ if ((status = __ntapi_pty_connect(hport,ctx,&iosb)))
254
+ return status;
255
+
256
+ *pty = ctx;
257
+
258
+ return NT_STATUS_SUCCESS;
259
+ }
260
+
216
261
int32_t __stdcall __ntapi_pty_reopen(
217
262
__in void * hport,
218
263
__in nt_pty * pty)
file modified
+49 -13
src/pty/ntapi_pty_query.c CHANGED
@@ -19,8 +19,10 @@ int32_t __stdcall __ntapi_pty_query(
19
19
nt_pty_info_class pty_info_class)
20
20
{
21
21
int32_t status;
22
+ void * hport;
22
23
nt_pty_sigctl_msg msg;
23
24
uintptr_t * info;
25
+ nt_pty_inherit_info * inherit;
24
26
25
27
if ((pty_info_class<NT_PTY_BASIC_INFORMATION) || (pty_info_class>=NT_PTY_INFORMATION_CAP))
26
28
return NT_STATUS_INVALID_INFO_CLASS;
@@ -28,6 +30,8 @@ int32_t __stdcall __ntapi_pty_query(
28
30
return NT_STATUS_NOT_IMPLEMENTED;
29
31
else if ((pty_info_class == NT_PTY_CLIENT_INFORMATION) && (pty_info_length != sizeof(nt_pty_client_info)))
30
32
return NT_STATUS_INVALID_PARAMETER;
33
+ else if ((pty_info_class == NT_PTY_INHERIT_INFORMATION) && (pty_info_length != sizeof(nt_pty_inherit_info)))
34
+ return NT_STATUS_INVALID_PARAMETER;
31
35
32
36
__ntapi->tt_aligned_block_memset(
33
37
&msg,0,sizeof(msg));
@@ -37,16 +41,31 @@ int32_t __stdcall __ntapi_pty_query(
37
41
msg.header.msg_size = sizeof(msg);
38
42
msg.data.ttyinfo.opcode = NT_TTY_PTY_QUERY;
39
43
40
- msg.data.ctlinfo.hpty = pty->hpty;
41
- msg.data.ctlinfo.luid.high = pty->luid.high;
42
- msg.data.ctlinfo.luid.low = pty->luid.low;
43
- msg.data.ctlinfo.ctlcode = pty_info_class;
44
+ if (pty_info_class == NT_PTY_CLIENT_INFORMATION) {
45
+ hport = pty->hport;
46
+ msg.data.ctlinfo.hpty = pty->hpty;
47
+ msg.data.ctlinfo.luid.high = pty->luid.high;
48
+ msg.data.ctlinfo.luid.low = pty->luid.low;
49
+ msg.data.ctlinfo.ctlcode = pty_info_class;
50
+
51
+ __ntapi->tt_guid_copy(
52
+ &msg.data.ctlinfo.guid,
53
+ &pty->guid);
54
+
55
+ } else if (pty_info_class == NT_PTY_INHERIT_INFORMATION) {
56
+ msg.data.ctlinfo.hpty = NT_INVALID_HANDLE_VALUE;
57
+ msg.data.ctlinfo.ctlcode = pty_info_class;
58
+
59
+ inherit = (nt_pty_inherit_info *)pty_info;
60
+ msg.data.ctlinfo.ctxarg[0] = inherit->any[0];
61
+ msg.data.ctlinfo.ctxarg[1] = inherit->any[1];
62
+ msg.data.ctlinfo.ctxarg[2] = inherit->any[2];
63
+ msg.data.ctlinfo.ctxarg[3] = inherit->any[3];
44
64
45
- __ntapi->tt_guid_copy(
46
- &msg.data.ctlinfo.guid,
65
+ hport = pty ? pty : __ntapi_internals()->hport_tty_session;
66
+ }
47
- &pty->guid);
48
67
49
- if ((status = __ntapi->zw_request_wait_reply_port(pty->hport,&msg,&msg)))
68
+ if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
50
69
return status;
51
70
else if (msg.data.ttyinfo.status)
52
71
return msg.data.ttyinfo.status;
@@ -54,11 +73,28 @@ int32_t __stdcall __ntapi_pty_query(
54
73
iosb->info = msg.data.ctlinfo.iosb.info;
55
74
iosb->status = msg.data.ctlinfo.iosb.status;
56
75
57
- info = (uintptr_t *)pty_info;
58
- info[0] = msg.data.ctlinfo.ctxarg[0];
59
- info[1] = msg.data.ctlinfo.ctxarg[1];
60
- info[2] = msg.data.ctlinfo.ctxarg[2];
61
- info[3] = msg.data.ctlinfo.ctxarg[3];
76
+ if (pty_info_class == NT_PTY_CLIENT_INFORMATION) {
77
+ info = (uintptr_t *)pty_info;
78
+ info[0] = msg.data.ctlinfo.ctxarg[0];
79
+ info[1] = msg.data.ctlinfo.ctxarg[1];
80
+ info[2] = msg.data.ctlinfo.ctxarg[2];
81
+ info[3] = msg.data.ctlinfo.ctxarg[3];
82
+
83
+ } else if (pty_info_class == NT_PTY_INHERIT_INFORMATION) {
84
+ inherit = (nt_pty_inherit_info *)pty_info;
85
+ inherit->hpty = msg.data.ctlinfo.hpty;
86
+ inherit->luid.low = msg.data.ctlinfo.luid.low;
87
+ inherit->luid.high = msg.data.ctlinfo.luid.high;
88
+
89
+ inherit->access = msg.data.ctlinfo.ctxarg[0];
90
+ inherit->flags = msg.data.ctlinfo.ctxarg[1];
91
+ inherit->share = msg.data.ctlinfo.ctxarg[2];
92
+ inherit->options = msg.data.ctlinfo.ctxarg[3];
93
+
94
+ __ntapi->tt_guid_copy(
95
+ &inherit->guid,
96
+ &msg.data.ctlinfo.guid);
97
+ }
62
98
63
99
return NT_STATUS_SUCCESS;
64
100
}
file modified
+2 -0
src/pty/ntapi_pty_set.c CHANGED
@@ -26,6 +26,8 @@ int32_t __stdcall __ntapi_pty_set(
26
26
return NT_STATUS_INVALID_INFO_CLASS;
27
27
else if (pty_info_class == NT_PTY_BASIC_INFORMATION)
28
28
return NT_STATUS_NOT_IMPLEMENTED;
29
+ else if (pty_info_class == NT_PTY_INHERIT_INFORMATION)
30
+ return NT_STATUS_INVALID_INFO_CLASS;
29
31
else if ((pty_info_class == NT_PTY_CLIENT_INFORMATION) && (pty_info_length != sizeof(nt_pty_client_info)))
30
32
return NT_STATUS_INVALID_PARAMETER;
31
33