@@ -497,6 +497,10 @@ do_authenticated1(Authctxt *authctxt)
497497#define USE_PIPES 1
498498#endif
499499
500+ #ifdef WIN32_FIXME
501+ extern int debug_flag ;
502+ #endif
503+
500504/*
501505 * This is called to fork and execute a command when we have no tty. This
502506 * will call do_child from the child, and server_loop from the parent after
@@ -548,8 +552,6 @@ do_exec_no_pty(Session *s, const char *command)
548552 char * exec_command ;
549553 char * laddr ;
550554 char buf [256 ];
551- int prot_scr_width = 80 ;
552- int prot_scr_height = 25 ;
553555 #ifdef WIN32_PRAGMA_REMCON
554556 char exec_command_str [512 ];
555557 #endif
@@ -590,8 +592,6 @@ do_exec_no_pty(Session *s, const char *command)
590592 int retcode = -1 ;
591593 if ( (!s -> is_subsystem ) && (s -> ttyfd != -1 ))
592594 {
593- prot_scr_width = s -> col ;
594- prot_scr_height = s -> row ;
595595 extern HANDLE hInputConsole ;
596596 extern HANDLE hOutputConsole ;
597597 hInputConsole = GetConsoleInputHandle ();
@@ -620,10 +620,10 @@ do_exec_no_pty(Session *s, const char *command)
620620 si .lpTitle = NULL ; /* NULL means use exe name as title */
621621 si .dwX = 0 ;
622622 si .dwY = 0 ;
623- si .dwXSize = 640 ;
624- si .dwYSize = 480 ;
625- si .dwXCountChars = prot_scr_width ;
626- si .dwYCountChars = prot_scr_height ;
623+ si .dwXSize = 5 ;
624+ si .dwYSize = 5 ;
625+ si .dwXCountChars = s -> col ;
626+ si .dwYCountChars = s -> row ;
627627 si .dwFillAttribute = 0 ;
628628 si .dwFlags = STARTF_USESTDHANDLES | STARTF_USESIZE | STARTF_USECOUNTCHARS ;
629629 si .wShowWindow = 0 ; // FALSE ;
@@ -794,32 +794,35 @@ do_exec_no_pty(Session *s, const char *command)
794794 wchar_t exec_command_w [MAX_PATH ];
795795
796796 MultiByteToWideChar (CP_UTF8 , 0 , exec_command , -1 , exec_command_w , MAX_PATH );
797- DWORD dwStartupFlags = 0 ;// CREATE_SUSPENDED; // 0
797+ DWORD dwStartupFlags = DETACHED_PROCESS ;// CREATE_SUSPENDED; // 0
798798
799799 SetConsoleCtrlHandler (NULL , FALSE);
800- b = CreateProcessAsUserW (hToken , NULL , exec_command_w , NULL , NULL , TRUE,
800+ if (debug_flag )
801+ b = CreateProcessW (NULL , exec_command_w , NULL , NULL , TRUE,
802+ /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags , NULL , s -> pw -> pw_dir ,
803+ & si , & pi );
804+ else
805+ b = CreateProcessAsUserW (hToken , NULL , exec_command_w , NULL , NULL , TRUE,
801806 /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags , NULL , s -> pw -> pw_dir ,
802807 & si , & pi );
803- /*
804- * If CreateProcessAsUser() fails we will try CreateProcess()
805- * but only if current user and login user are the same.
806- */
807-
808- if ((!b ) && (strcmp (name , s -> pw -> pw_name ) == 0 ))
809- {
810- b = CreateProcessW (NULL , exec_command_w , NULL , NULL , TRUE,
811- /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags , NULL , s -> pw -> pw_dir ,
812- & si , & pi );
813- }
814-
815808 if (!b )
816809 {
817- debug ("ERROR. Cannot create process as new user (%u).\n" , GetLastError ());
810+ debug ("ERROR. Cannot create process (%u).\n" , GetLastError ());
818811
819812 CloseHandle (hToken );
820813
821814 exit (1 );
822815 }
816+ else {
817+ FreeConsole ();
818+ if (!debug_flag )
819+ ImpersonateLoggedOnUser (hToken );
820+ while (AttachConsole (pi .dwProcessId ) == FALSE) {
821+ Sleep (200 );
822+ }
823+ if (!debug_flag )
824+ RevertToSelf ();
825+ }
823826
824827 /*
825828 * Save token used for create child process. We'll need it on cleanup
0 commit comments