4242 #undef GSSAPI
4343 #undef KRB5
4444 #define WIN32_USER_AUTH 1
45+ //#define WIN32_PRAGMA_REMCON
4546#endif
4647
4748#include <sys/types.h>
@@ -589,11 +590,20 @@ do_exec_no_pty(Session *s, const char *command)
589590 char buf [256 ];
590591 int prot_scr_width = 80 ;
591592 int prot_scr_height = 25 ;
593+ #ifdef WIN32_PRAGMA_REMCON
594+ char exec_command_str [512 ];
595+ #endif
592596
593597 if (!command )
594598 {
599+ #ifndef WIN32_PRAGMA_REMCON
595600 exec_command = s -> pw -> pw_shell ;
596- //exec_command = "c:\\tools\\echoit.exe"; // temp
601+ #else
602+ snprintf (exec_command_str , sizeof (exec_command_str ),
603+ "\\program files\\pragma\\shared files\\cmdserver.exe SSHD %d %d" ,
604+ s -> row , s -> col );
605+ exec_command = exec_command_str ;
606+ #endif
597607 }
598608 else
599609 {
@@ -606,28 +616,42 @@ do_exec_no_pty(Session *s, const char *command)
606616 * Create three socket pairs for stdin, stdout and stderr
607617 */
608618
609- HANDLE wfdtocmd = -1 ;
619+ #ifdef WIN32_PRAGMA_REMCON
620+
610621 int retcode = -1 ;
611622 if ( (!s -> is_subsystem ) && (s -> ttyfd != -1 ))
612623 {
613- //FreeConsole();
614- //AllocConsole();
615- MakeNewConsole ();
616624 prot_scr_width = s -> col ;
617625 prot_scr_height = s -> row ;
618626 extern HANDLE hConsole ;
619627 hConsole = GetStdHandle (STD_OUTPUT_HANDLE );
620628 ConSetScreenSize ( s -> col , s -> row );
621- s -> ptyfd = hConsole ; // the pty is the Windows console output handle in our Win32 port
622-
623- wfdtocmd = GetStdHandle (STD_INPUT_HANDLE ) ; // we use this console handle to feed input to Windows shell cmd.exe
624- sockin [1 ] = allocate_sfd ((int )wfdtocmd ); // put the std input handle in our global general handle table
625- //if (sockin[1] >= 0)
626- // sfd_set_to_console(sockin[1]); // mark it as Console type
627-
629+ socketpair (sockin );
630+ s -> ptyfd = sockin [1 ]; // hConsole; // the pty is the Windows console output handle in our Win32 port
628631 }
629632 else
630633 socketpair (sockin );
634+ #else
635+ HANDLE wfdtocmd = -1 ;
636+ int retcode = -1 ;
637+ if ((!s -> is_subsystem ) && (s -> ttyfd != -1 ))
638+ {
639+ //FreeConsole();
640+ //AllocConsole();
641+ MakeNewConsole ();
642+ prot_scr_width = s -> col ;
643+ prot_scr_height = s -> row ;
644+ extern HANDLE hConsole ;
645+ hConsole = GetStdHandle (STD_OUTPUT_HANDLE );
646+ ConSetScreenSize (s -> col , s -> row );
647+ s -> ptyfd = hConsole ; // the pty is the Windows console output handle in our Win32 port
648+
649+ wfdtocmd = GetStdHandle (STD_INPUT_HANDLE ); // we use this console handle to feed input to Windows shell cmd.exe
650+ sockin [1 ] = allocate_sfd ((int )wfdtocmd ); // put the std input handle in our global general handle table
651+ }
652+ else
653+ socketpair (sockin );
654+ #endif
631655
632656 socketpair (sockout );
633657 socketpair (sockerr );
@@ -636,12 +660,14 @@ do_exec_no_pty(Session *s, const char *command)
636660 debug3 ("sockout[0]: %d sockout[1]: %d" , sockout [0 ], sockout [1 ]);
637661 debug3 ("sockerr[0]: %d sockerr[1]: %d" , sockerr [0 ], sockerr [1 ]);
638662
663+ #ifndef WIN32_PRAGMA_REMCON
639664 if ( (s -> is_subsystem ) || (s -> ttyfd == -1 ))
640665 crlf_sfd (sockin [1 ]);
641666
642667 crlf_sfd (sockout [1 ]);
643668
644669 if ( (s -> is_subsystem ) || (s -> ttyfd == -1 ))
670+ #endif
645671 SetHandleInformation (sfd_to_handle (sockin [1 ]), HANDLE_FLAG_INHERIT , 0 );
646672
647673 SetHandleInformation (sfd_to_handle (sockout [1 ]), HANDLE_FLAG_INHERIT , 0 );
@@ -668,11 +694,16 @@ do_exec_no_pty(Session *s, const char *command)
668694 si .cbReserved2 = 0 ;
669695 si .lpReserved2 = 0 ;
670696
697+ #ifdef WIN32_PRAGMA_REMCON
698+ if (0 ) {
699+ #else
671700 if ( (!s -> is_subsystem ) && (s -> ttyfd != -1 ) ) {
701+
672702 si .hStdInput = GetStdHandle (STD_INPUT_HANDLE ) ; // shell tty interactive session gets a console input for Win32
673703 si .hStdOutput = (HANDLE ) sfd_to_handle (sockout [0 ]);
674704 si .hStdError = (HANDLE ) sfd_to_handle (sockerr [0 ]);
675705 si .lpDesktop = NULL ; //winstadtname_w ;
706+ #endif
676707 }
677708 else {
678709 si .hStdInput = (HANDLE ) sfd_to_handle (sockin [0 ]);
@@ -889,13 +920,15 @@ do_exec_no_pty(Session *s, const char *command)
889920
890921 GetUserName (name , & size );
891922
923+ #ifndef WIN32_PRAGMA_REMCON
892924 if ( (!s -> is_subsystem ) && (s -> ttyfd != -1 )) {
893925 // Send to the remote client ANSI/VT Sequence so that they send us CRLF in place of LF
894926 char * inittermseq = "\033[20h\033[?7h\0" ; // LFtoCRLF AUTOWRAPON
895927 Channel * c = channel_by_id ( s -> chanid );
896928 buffer_append (& c -> input , inittermseq , strlen (inittermseq ));
897929 channel_output_poll ();
898930 }
931+ #endif
899932
900933 //if (s ->ttyfd != -1) {
901934 // set the channel to tty interactive type
@@ -975,8 +1008,12 @@ do_exec_no_pty(Session *s, const char *command)
9751008 /*
9761009 * We are the parent. Close the child sides of the socket pairs.
9771010 */
1011+ #ifndef WIN32_PRAGMA_REMCON
9781012 if ( (s -> is_subsystem ) || (s -> ttyfd == -1 ))
9791013 close (sockin [0 ]);
1014+ #else
1015+ close (sockin [0 ]);
1016+ #endif
9801017
9811018 close (sockout [0 ]);
9821019 close (sockerr [0 ]);
@@ -2734,7 +2771,9 @@ session_pty_req(Session *s)
27342771 /* for SSH1 the tty modes length is not given */
27352772 if (!compat20 )
27362773 n_bytes = packet_remaining ();
2774+ #ifndef WIN32_PRAGMA_REMCON
27372775 tty_parse_modes (s -> ttyfd , & n_bytes );
2776+ #endif
27382777
27392778 if (!use_privsep )
27402779 pty_setowner (s -> pw , s -> tty );
@@ -2744,7 +2783,9 @@ session_pty_req(Session *s)
27442783 pty_change_window_size (s -> ptyfd , s -> row , s -> col , s -> xpixel , s -> ypixel );
27452784 #endif
27462785
2786+ #ifndef WIN32_PRAGMA_REMCON
27472787 packet_check_eom ();
2788+ #endif
27482789 session_proctitle (s );
27492790 return 1 ;
27502791}
0 commit comments