mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-25 15:04:54 +02:00
Add pluggable access to shell session so that cmd & powershell runs like natively
#define WIN32_PRAGMA_REMCON in config.h.vs or in channels.c, session.c and sshpty.c files . cmdserver.exe runtime in Pragma Fortress SSH package needed to access shell session.
This commit is contained in:
parent
f43f33da8b
commit
829f799ad9
@ -42,6 +42,7 @@
|
|||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
|
//#define WIN32_PRAGMA_REMCON
|
||||||
#ifdef ECONNABORTED
|
#ifdef ECONNABORTED
|
||||||
#undef ECONNABORTED
|
#undef ECONNABORTED
|
||||||
#endif
|
#endif
|
||||||
@ -2482,6 +2483,9 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
|
|||||||
if ( c->client_tty )
|
if ( c->client_tty )
|
||||||
telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
|
telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
|
||||||
else {
|
else {
|
||||||
|
#ifdef WIN32_PRAGMA_REMCON
|
||||||
|
buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
|
||||||
|
#else
|
||||||
if ( ( c->isatty) && (data_len ==1) && (data[0] == '\003') ) {
|
if ( ( c->isatty) && (data_len ==1) && (data[0] == '\003') ) {
|
||||||
/* send control-c to the shell process */
|
/* send control-c to the shell process */
|
||||||
if ( GenerateConsoleCtrlEvent ( CTRL_C_EVENT, 0 ) ) {
|
if ( GenerateConsoleCtrlEvent ( CTRL_C_EVENT, 0 ) ) {
|
||||||
@ -2515,6 +2519,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
|
|||||||
charinline = 0; // a line has ended, begin char in line count again
|
charinline = 0; // a line has ended, begin char in line count again
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // WIN32_PRAGMA_REMCON
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1707,5 +1707,7 @@ struct iovec
|
|||||||
|
|
||||||
// define building with MS Visual Studio Compiler and runtime and not with MingW/gcc compiler
|
// define building with MS Visual Studio Compiler and runtime and not with MingW/gcc compiler
|
||||||
#define WIN32_VS 1
|
#define WIN32_VS 1
|
||||||
|
// Use Pragma Systems Remote Console modules for shell sessions so that cmd/powershell fully
|
||||||
|
// works remotely over SSH like they operate in a local machine
|
||||||
|
//#define WIN32_PRAGMA_REMCON
|
||||||
|
|
||||||
|
49
session.c
49
session.c
@ -42,6 +42,7 @@
|
|||||||
#undef GSSAPI
|
#undef GSSAPI
|
||||||
#undef KRB5
|
#undef KRB5
|
||||||
#define WIN32_USER_AUTH 1
|
#define WIN32_USER_AUTH 1
|
||||||
|
//#define WIN32_PRAGMA_REMCON
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -589,11 +590,20 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
char buf[256];
|
char buf[256];
|
||||||
int prot_scr_width = 80;
|
int prot_scr_width = 80;
|
||||||
int prot_scr_height = 25;
|
int prot_scr_height = 25;
|
||||||
|
#ifdef WIN32_PRAGMA_REMCON
|
||||||
|
char exec_command_str[512];
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!command)
|
if (!command)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
exec_command = s->pw->pw_shell;
|
exec_command = s->pw->pw_shell;
|
||||||
//exec_command = "c:\\tools\\echoit.exe"; // temp
|
#else
|
||||||
|
snprintf(exec_command_str, sizeof(exec_command_str),
|
||||||
|
"\\program files\\pragma\\shared files\\cmdserver.exe SSHD %d %d",
|
||||||
|
s->row, s->col );
|
||||||
|
exec_command = exec_command_str;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -606,6 +616,22 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
* Create three socket pairs for stdin, stdout and stderr
|
* Create three socket pairs for stdin, stdout and stderr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32_PRAGMA_REMCON
|
||||||
|
|
||||||
|
int retcode = -1;
|
||||||
|
if ( (!s -> is_subsystem) && (s ->ttyfd != -1))
|
||||||
|
{
|
||||||
|
prot_scr_width = s->col;
|
||||||
|
prot_scr_height = s->row;
|
||||||
|
extern HANDLE hConsole ;
|
||||||
|
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||||
|
ConSetScreenSize( s->col, s->row );
|
||||||
|
socketpair(sockin);
|
||||||
|
s->ptyfd = sockin[1]; // hConsole; // the pty is the Windows console output handle in our Win32 port
|
||||||
|
}
|
||||||
|
else
|
||||||
|
socketpair(sockin);
|
||||||
|
#else
|
||||||
HANDLE wfdtocmd = -1;
|
HANDLE wfdtocmd = -1;
|
||||||
int retcode = -1;
|
int retcode = -1;
|
||||||
if ((!s->is_subsystem) && (s->ttyfd != -1))
|
if ((!s->is_subsystem) && (s->ttyfd != -1))
|
||||||
@ -622,12 +648,10 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
|
|
||||||
wfdtocmd = GetStdHandle(STD_INPUT_HANDLE); // we use this console handle to feed input to Windows shell cmd.exe
|
wfdtocmd = GetStdHandle(STD_INPUT_HANDLE); // we use this console handle to feed input to Windows shell cmd.exe
|
||||||
sockin[1] = allocate_sfd((int)wfdtocmd); // put the std input handle in our global general handle table
|
sockin[1] = allocate_sfd((int)wfdtocmd); // put the std input handle in our global general handle table
|
||||||
//if (sockin[1] >= 0)
|
|
||||||
// sfd_set_to_console(sockin[1]); // mark it as Console type
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
socketpair(sockin);
|
socketpair(sockin);
|
||||||
|
#endif
|
||||||
|
|
||||||
socketpair(sockout);
|
socketpair(sockout);
|
||||||
socketpair(sockerr);
|
socketpair(sockerr);
|
||||||
@ -636,12 +660,14 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
debug3("sockout[0]: %d sockout[1]: %d", sockout[0], sockout[1]);
|
debug3("sockout[0]: %d sockout[1]: %d", sockout[0], sockout[1]);
|
||||||
debug3("sockerr[0]: %d sockerr[1]: %d", sockerr[0], sockerr[1]);
|
debug3("sockerr[0]: %d sockerr[1]: %d", sockerr[0], sockerr[1]);
|
||||||
|
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
||||||
crlf_sfd(sockin[1]);
|
crlf_sfd(sockin[1]);
|
||||||
|
|
||||||
crlf_sfd(sockout[1]);
|
crlf_sfd(sockout[1]);
|
||||||
|
|
||||||
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
||||||
|
#endif
|
||||||
SetHandleInformation(sfd_to_handle(sockin[1]), HANDLE_FLAG_INHERIT, 0);
|
SetHandleInformation(sfd_to_handle(sockin[1]), HANDLE_FLAG_INHERIT, 0);
|
||||||
|
|
||||||
SetHandleInformation(sfd_to_handle(sockout[1]), HANDLE_FLAG_INHERIT, 0);
|
SetHandleInformation(sfd_to_handle(sockout[1]), HANDLE_FLAG_INHERIT, 0);
|
||||||
@ -668,11 +694,16 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
si.cbReserved2 = 0;
|
si.cbReserved2 = 0;
|
||||||
si.lpReserved2 = 0;
|
si.lpReserved2 = 0;
|
||||||
|
|
||||||
|
#ifdef WIN32_PRAGMA_REMCON
|
||||||
|
if (0) {
|
||||||
|
#else
|
||||||
if ( (!s -> is_subsystem) && (s ->ttyfd != -1) ) {
|
if ( (!s -> is_subsystem) && (s ->ttyfd != -1) ) {
|
||||||
|
|
||||||
si.hStdInput = GetStdHandle (STD_INPUT_HANDLE) ; // shell tty interactive session gets a console input for Win32
|
si.hStdInput = GetStdHandle (STD_INPUT_HANDLE) ; // shell tty interactive session gets a console input for Win32
|
||||||
si.hStdOutput = (HANDLE) sfd_to_handle(sockout[0]);
|
si.hStdOutput = (HANDLE) sfd_to_handle(sockout[0]);
|
||||||
si.hStdError = (HANDLE) sfd_to_handle(sockerr[0]);
|
si.hStdError = (HANDLE) sfd_to_handle(sockerr[0]);
|
||||||
si.lpDesktop = NULL ; //winstadtname_w ;
|
si.lpDesktop = NULL ; //winstadtname_w ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
si.hStdInput = (HANDLE) sfd_to_handle(sockin[0]);
|
si.hStdInput = (HANDLE) sfd_to_handle(sockin[0]);
|
||||||
@ -889,6 +920,7 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
|
|
||||||
GetUserName(name, &size);
|
GetUserName(name, &size);
|
||||||
|
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) {
|
if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) {
|
||||||
// Send to the remote client ANSI/VT Sequence so that they send us CRLF in place of LF
|
// Send to the remote client ANSI/VT Sequence so that they send us CRLF in place of LF
|
||||||
char *inittermseq = "\033[20h\033[?7h\0" ; // LFtoCRLF AUTOWRAPON
|
char *inittermseq = "\033[20h\033[?7h\0" ; // LFtoCRLF AUTOWRAPON
|
||||||
@ -896,6 +928,7 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
buffer_append(&c->input, inittermseq, strlen(inittermseq));
|
buffer_append(&c->input, inittermseq, strlen(inittermseq));
|
||||||
channel_output_poll();
|
channel_output_poll();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//if (s ->ttyfd != -1) {
|
//if (s ->ttyfd != -1) {
|
||||||
// set the channel to tty interactive type
|
// set the channel to tty interactive type
|
||||||
@ -975,8 +1008,12 @@ do_exec_no_pty(Session *s, const char *command)
|
|||||||
/*
|
/*
|
||||||
* We are the parent. Close the child sides of the socket pairs.
|
* We are the parent. Close the child sides of the socket pairs.
|
||||||
*/
|
*/
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
||||||
close(sockin[0]);
|
close(sockin[0]);
|
||||||
|
#else
|
||||||
|
close(sockin[0]);
|
||||||
|
#endif
|
||||||
|
|
||||||
close(sockout[0]);
|
close(sockout[0]);
|
||||||
close(sockerr[0]);
|
close(sockerr[0]);
|
||||||
@ -2734,7 +2771,9 @@ session_pty_req(Session *s)
|
|||||||
/* for SSH1 the tty modes length is not given */
|
/* for SSH1 the tty modes length is not given */
|
||||||
if (!compat20)
|
if (!compat20)
|
||||||
n_bytes = packet_remaining();
|
n_bytes = packet_remaining();
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
tty_parse_modes(s->ttyfd, &n_bytes);
|
tty_parse_modes(s->ttyfd, &n_bytes);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!use_privsep)
|
if (!use_privsep)
|
||||||
pty_setowner(s->pw, s->tty);
|
pty_setowner(s->pw, s->tty);
|
||||||
@ -2744,7 +2783,9 @@ session_pty_req(Session *s)
|
|||||||
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
|
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
packet_check_eom();
|
packet_check_eom();
|
||||||
|
#endif
|
||||||
session_proctitle(s);
|
session_proctitle(s);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
32
sshpty.c
32
sshpty.c
@ -21,6 +21,7 @@
|
|||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
#undef GSSAPI
|
#undef GSSAPI
|
||||||
#undef KRB5
|
#undef KRB5
|
||||||
|
//#define WIN32_PRAGMA_REMCON
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -196,6 +197,32 @@ pty_make_controlling_tty(int *ttyfd, const char *tty)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32_PRAGMA_REMCON
|
||||||
|
/* Changes the window size associated with the pty. */
|
||||||
|
|
||||||
|
void pty_change_window_size_oob(int ptyfd, u_int row, u_int col, u_int xpixel, u_int ypixel)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
char unsigned data[16];
|
||||||
|
size_t data_len;
|
||||||
|
|
||||||
|
// IAC SB NAWS <16-bit value width> <16-bit value height> IAC
|
||||||
|
//sprintf (data,"%c%c%c%c%c%c%c%c", 255, 250, 31, 0, col, 0, row, 255 );
|
||||||
|
data[0] = 255; // IAC;
|
||||||
|
data[1] = 250; // SB
|
||||||
|
data[2] = 31; // NAWS
|
||||||
|
data[3] = 0;
|
||||||
|
data[4] = (unsigned char)col;
|
||||||
|
data[5] = 0;
|
||||||
|
data[6] = (unsigned char)row;
|
||||||
|
data[7] = 255; // IAC
|
||||||
|
data[8] = 240; // iac end
|
||||||
|
data_len = 9; //strlen (data);
|
||||||
|
rc = write(ptyfd, data, (DWORD)data_len);
|
||||||
|
//rc = AsyncWrite(c->hInputHandle, (char *)data, (DWORD)data_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/* Changes the window size associated with the pty. */
|
/* Changes the window size associated with the pty. */
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -214,7 +241,12 @@ pty_change_window_size(int ptyfd, u_int row, u_int col,
|
|||||||
#else
|
#else
|
||||||
extern HANDLE hConsole ;
|
extern HANDLE hConsole ;
|
||||||
hConsole = ptyfd;
|
hConsole = ptyfd;
|
||||||
|
#ifndef WIN32_PRAGMA_REMCON
|
||||||
ConSetScreenSize( col, row );
|
ConSetScreenSize( col, row );
|
||||||
|
#else
|
||||||
|
if (ptyfd > 0 )
|
||||||
|
pty_change_window_size_oob(ptyfd, row, col, xpixel, ypixel);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user