diff --git a/include/ntapi/nt_process.h b/include/ntapi/nt_process.h index a1ef3a2..e03dec0 100644 --- a/include/ntapi/nt_process.h +++ b/include/ntapi/nt_process.h @@ -451,9 +451,9 @@ typedef struct _nt_runtime_data { void * hstdin; void * hstdout; void * hstderr; + void * hctty; void * hjob; void * hsession; - void * hpty; void * hdebug; void * hlog; void * hready; @@ -498,7 +498,10 @@ typedef struct _nt_runtime_data { int32_t peb_argc; wchar16_t ** peb_wargv; wchar16_t ** peb_wenvp; - uintptr_t ptyany[4]; + uintptr_t ptyin [4]; + uintptr_t ptyout[4]; + uintptr_t ptyerr[4]; + uintptr_t ptyctl[4]; uint32_t sa_queue [2]; uint32_t sa_block [2]; void * sa_handler[64]; diff --git a/include/ntapi/nt_tty.h b/include/ntapi/nt_tty.h index 16fd43b..7dd3baf 100644 --- a/include/ntapi/nt_tty.h +++ b/include/ntapi/nt_tty.h @@ -11,6 +11,7 @@ #include #include "nt_object.h" +#include "nt_process.h" #include "nt_port.h" #include "nt_termios.h" @@ -394,6 +395,11 @@ typedef int32_t __stdcall ntapi_pty_inherit( __in nt_pty_client_info * client_info); +typedef int32_t __stdcall ntapi_pty_inherit_runtime_ctty( + __in void * hport, + __in_out nt_runtime_data * rtdata); + + typedef int32_t __stdcall ntapi_pty_close( __in nt_pty * pty); diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h index 0af598a..22db615 100644 --- a/include/ntapi/ntapi.h +++ b/include/ntapi/ntapi.h @@ -535,6 +535,7 @@ typedef struct _ntapi_vtbl { ntapi_pty_open * pty_open; ntapi_pty_reopen * pty_reopen; ntapi_pty_inherit * pty_inherit; + ntapi_pty_inherit_runtime_ctty * pty_inherit_runtime_ctty; ntapi_pty_close * pty_close; ntapi_pty_read * pty_read; ntapi_pty_write * pty_write; diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index 7080089..8ebdf22 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -300,6 +300,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) __ntapi->pty_open = __ntapi_pty_open; __ntapi->pty_reopen = __ntapi_pty_reopen; __ntapi->pty_inherit = __ntapi_pty_inherit; + __ntapi->pty_inherit_runtime_ctty = __ntapi_pty_inherit_runtime_ctty; __ntapi->pty_close = __ntapi_pty_close; __ntapi->pty_read = __ntapi_pty_read; __ntapi->pty_write = __ntapi_pty_write; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 9db0560..ee291ff 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -188,6 +188,7 @@ ntapi_tty_vms_request __ntapi_tty_vms_request; ntapi_pty_open __ntapi_pty_open; ntapi_pty_reopen __ntapi_pty_reopen; ntapi_pty_inherit __ntapi_pty_inherit; +ntapi_pty_inherit_runtime_ctty __ntapi_pty_inherit_runtime_ctty; ntapi_pty_close __ntapi_pty_close; ntapi_pty_read __ntapi_pty_read; ntapi_pty_write __ntapi_pty_write; diff --git a/src/pty/ntapi_pty_fd.c b/src/pty/ntapi_pty_fd.c index ed97418..3071482 100644 --- a/src/pty/ntapi_pty_fd.c +++ b/src/pty/ntapi_pty_fd.c @@ -309,3 +309,112 @@ int32_t __stdcall __ntapi_pty_close(nt_pty * pty) return __ntapi_pty_free(pty); } + +int32_t __stdcall __ntapi_pty_inherit_runtime_ctty( + __in void * hport, + __in_out nt_runtime_data * rtdata) +{ + int32_t status; + nt_pty_client_info client_info; + + if (rtdata->stdin_type == NT_FILE_TYPE_PTY) { + client_info.any[0] = rtdata->ptyin[0]; + client_info.any[1] = rtdata->ptyin[1]; + client_info.any[2] = rtdata->ptyin[2]; + client_info.any[3] = rtdata->ptyin[3]; + + if ((status = __ntapi_pty_inherit( + hport, + (nt_pty **)&rtdata->hstdin, + &client_info))) + return status; + } + + if (rtdata->stdout_type == NT_FILE_TYPE_PTY) { + if ((rtdata->stdin_type == NT_FILE_TYPE_PTY) + && (rtdata->ptyout[0] == rtdata->ptyin[0]) + && (rtdata->ptyout[1] == rtdata->ptyin[1]) + && (rtdata->ptyout[2] == rtdata->ptyin[2]) + && (rtdata->ptyout[3] == rtdata->ptyin[3])) { + rtdata->hstdout = rtdata->hstdin; + + } else { + client_info.any[0] = rtdata->ptyout[0]; + client_info.any[1] = rtdata->ptyout[1]; + client_info.any[2] = rtdata->ptyout[2]; + client_info.any[3] = rtdata->ptyout[3]; + + if ((status = __ntapi_pty_inherit( + hport, + (nt_pty **)&rtdata->hstdout, + &client_info))) + return status; + } + } + + if (rtdata->stderr_type == NT_FILE_TYPE_PTY) { + if ((rtdata->stdin_type == NT_FILE_TYPE_PTY) + && (rtdata->ptyerr[0] == rtdata->ptyin[0]) + && (rtdata->ptyerr[1] == rtdata->ptyin[1]) + && (rtdata->ptyerr[2] == rtdata->ptyin[2]) + && (rtdata->ptyerr[3] == rtdata->ptyin[3])) { + rtdata->hstderr = rtdata->hstdin; + + } else if ((rtdata->stdout_type == NT_FILE_TYPE_PTY) + && (rtdata->ptyerr[0] == rtdata->ptyout[0]) + && (rtdata->ptyerr[1] == rtdata->ptyout[1]) + && (rtdata->ptyerr[2] == rtdata->ptyout[2]) + && (rtdata->ptyerr[3] == rtdata->ptyout[3])) { + rtdata->hstderr = rtdata->hstdout; + + } else { + client_info.any[0] = rtdata->ptyerr[0]; + client_info.any[1] = rtdata->ptyerr[1]; + client_info.any[2] = rtdata->ptyerr[2]; + client_info.any[3] = rtdata->ptyerr[3]; + + if ((status = __ntapi_pty_inherit( + hport, + (nt_pty **)&rtdata->hstderr, + &client_info))) + return status; + } + } + + /* hctty */ + if ((rtdata->stdin_type == NT_FILE_TYPE_PTY) + && (rtdata->ptyctl[0] == rtdata->ptyin[0]) + && (rtdata->ptyctl[1] == rtdata->ptyin[1]) + && (rtdata->ptyctl[2] == rtdata->ptyin[2]) + && (rtdata->ptyctl[3] == rtdata->ptyin[3])) { + rtdata->hctty = rtdata->hstdin; + + } else if ((rtdata->stdout_type == NT_FILE_TYPE_PTY) + && (rtdata->ptyctl[0] == rtdata->ptyout[0]) + && (rtdata->ptyctl[1] == rtdata->ptyout[1]) + && (rtdata->ptyctl[2] == rtdata->ptyout[2]) + && (rtdata->ptyctl[3] == rtdata->ptyout[3])) { + rtdata->hctty = rtdata->hstdout; + + } else if ((rtdata->stderr_type == NT_FILE_TYPE_PTY) + && (rtdata->ptyctl[0] == rtdata->ptyerr[0]) + && (rtdata->ptyctl[1] == rtdata->ptyerr[1]) + && (rtdata->ptyctl[2] == rtdata->ptyerr[2]) + && (rtdata->ptyctl[3] == rtdata->ptyerr[3])) { + rtdata->hctty = rtdata->hstderr; + + } else { + client_info.any[0] = rtdata->ptyctl[0]; + client_info.any[1] = rtdata->ptyctl[1]; + client_info.any[2] = rtdata->ptyctl[2]; + client_info.any[3] = rtdata->ptyctl[3]; + + if ((status = __ntapi_pty_inherit( + hport, + (nt_pty **)&rtdata->hctty, + &client_info))) + rtdata->hctty = 0; + } + + return NT_STATUS_SUCCESS; +}