@@ -491,17 +491,64 @@ do_authenticated1(Authctxt *authctxt)
491
491
#ifdef WINDOWS
492
492
493
493
int do_exec_windows (Session * s , const char * command , int pty ) {
494
+ int pipein [2 ], pipeout [2 ], pipeerr [2 ], r ;
495
+ char * exec_command = NULL , * progdir = w32_programdir ();
496
+ wchar_t * exec_command_w = NULL ;
494
497
498
+ if (s -> is_subsystem >= SUBSYSTEM_INT_SFTP_ERROR )
499
+ {
500
+ error ("sub system not supported, exiting\n" );
501
+ fflush (NULL );
502
+ exit (1 );
503
+ }
504
+
505
+ /* Create three pipes for stdin, stdout and stderr */
506
+ if (pipe (pipein ) == -1 || pipe (pipeout ) == -1 || pipe (pipeerr ) == -1 ) {
507
+ error ("%s: cannot create pipe: %.100s" , __func__ , strerror (errno ));
508
+ return -1 ;
509
+ }
510
+
511
+ set_nonblock (pipein [0 ]);
512
+ set_nonblock (pipein [1 ]);
513
+ set_nonblock (pipeout [0 ]);
514
+ set_nonblock (pipeout [1 ]);
515
+ set_nonblock (pipeerr [0 ]);
516
+ set_nonblock (pipeerr [1 ]);
517
+
518
+ fcntl (pipein [1 ], F_SETFD , FD_CLOEXEC );
519
+ fcntl (pipeout [0 ], F_SETFD , FD_CLOEXEC );
520
+ fcntl (pipeerr [0 ], F_SETFD , FD_CLOEXEC );
521
+
522
+ /* prepare exec - path used with CreateProcess() */
523
+ if (s -> is_subsystem ) {
524
+ /* relative or absolute */
525
+ if (command == NULL || command [0 ] == '\0' )
526
+ fatal ("expecting command for a subsystem" );
527
+
528
+ if (command [1 ] != ':' ) /* absolute */
529
+ exec_command = xstrdup (command );
530
+ else {/*relative*/
531
+ exec_command = malloc (strlen (progdir ) + 1 + strlen (command ));
532
+ if (exec_command == NULL )
533
+ fatal ("%s, out of memory" );
534
+ memcpy (exec_command , progdir , strlen (progdir ));
535
+ exec_command [strlen (progdir )] = '\\' ;
536
+ memcpy (exec_command + strlen (progdir ) + 1 , command , strlen (command ) + 1 );
537
+ }
538
+ } else {
539
+ char * shell_host = pty ? "ssh-shellhost.exe -t " : "ssh-shellhost.exe " ;
540
+ exec_command = malloc (strlen (progdir ) + strlen (shell_host ) + (command ? strlen (command ) : 0 ));
541
+ if (exec_command == NULL )
542
+ fatal ("%s, out of memory" );
543
+
544
+ }
545
+
495
546
wchar_t * pw_dir_utf16 = utf8_to_utf16 (s -> pw -> pw_dir );
496
547
extern int debug_flag ;
497
548
498
549
PROCESS_INFORMATION pi ;
499
550
STARTUPINFOW si ;
500
551
501
- int pipein [2 ];
502
- int pipeout [2 ];
503
- int pipeerr [2 ];
504
-
505
552
BOOL b ;
506
553
507
554
HANDLE hToken = INVALID_HANDLE_VALUE ;
@@ -512,12 +559,6 @@ int do_exec_windows(Session *s, const char *command, int pty) {
512
559
char * laddr ;
513
560
char buf [256 ];
514
561
515
- if (s -> is_subsystem >= SUBSYSTEM_INT_SFTP_ERROR )
516
- {
517
- error ("sub system not supported, exiting\n" );
518
- fflush (NULL );
519
- exit (1 );
520
- }
521
562
522
563
523
564
if (!command )
@@ -529,27 +570,12 @@ int do_exec_windows(Session *s, const char *command, int pty) {
529
570
exec_command = command ;
530
571
}
531
572
532
- /*
533
- * Create three socket pairs for stdin, stdout and stderr
534
- */
535
- pipe (pipein );
536
- pipe (pipeout );
537
- pipe (pipeerr );
538
573
539
574
int retcode = -1 ;
540
575
if ((!s -> is_subsystem ) && (s -> ttyfd != -1 ))
541
576
{
542
577
}
543
578
544
- debug3 ("sockin[0]: %d sockin[1]: %d" , pipein [0 ], pipein [1 ]);
545
- debug3 ("sockout[0]: %d sockout[1]: %d" , pipeout [0 ], pipeout [1 ]);
546
- debug3 ("sockerr[0]: %d sockerr[1]: %d" , pipeerr [0 ], pipeerr [1 ]);
547
-
548
-
549
- SetHandleInformation (sfd_to_handle (pipein [1 ]), HANDLE_FLAG_INHERIT , 0 );
550
- SetHandleInformation (sfd_to_handle (pipeout [0 ]), HANDLE_FLAG_INHERIT , 0 );
551
- SetHandleInformation (sfd_to_handle (pipeerr [0 ]), HANDLE_FLAG_INHERIT , 0 );
552
-
553
579
/*
554
580
* Assign sockets to StartupInfo
555
581
*/
@@ -580,13 +606,6 @@ int do_exec_windows(Session *s, const char *command, int pty) {
580
606
SetEnvironmentVariable ("USERNAME" , s -> pw -> pw_name );
581
607
SetEnvironmentVariable ("LOGNAME" , s -> pw -> pw_name );
582
608
583
- set_nonblock (pipein [0 ]);
584
- set_nonblock (pipein [1 ]);
585
- set_nonblock (pipeout [0 ]);
586
- set_nonblock (pipeout [1 ]);
587
- set_nonblock (pipeerr [0 ]);
588
- set_nonblock (pipeerr [1 ]);
589
-
590
609
/*
591
610
* If we get this far, the user has already been authenticated
592
611
* We should either have a user token in authctxt -> methoddata
0 commit comments