@@ -1193,6 +1193,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
11931193 int wantWrite = 0 ;
11941194 int peerConnected = 1 ;
11951195 int stdoutEmpty = 0 ;
1196+ int ptyReq = 0 ;
11961197
11971198 childFd = -1 ;
11981199 stdoutPipe [0 ] = -1 ;
@@ -1203,6 +1204,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
12031204 stdinPipe [1 ] = -1 ;
12041205
12051206 forcedCmd = wolfSSHD_ConfigGetForcedCmd (usrConf );
1207+ ptyReq = wolfSSH_ReceivedPtyReq (ssh );
12061208
12071209 /* do not overwrite a forced command with 'exec' sub shell. Only set the
12081210 * 'exec' command when no forced command is set */
@@ -1223,8 +1225,9 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
12231225 return WS_FATAL_ERROR ;
12241226 }
12251227
1228+
12261229 /* create pipes for stdout and stderr */
1227- if (forcedCmd ) {
1230+ if (ptyReq == 0 || forcedCmd ) {
12281231 if (pipe (stdoutPipe ) != 0 ) {
12291232 wolfSSH_Log (WS_LOG_ERROR , "[SSHD] Issue creating stdout pipe" );
12301233 return WS_FATAL_ERROR ;
@@ -1263,7 +1266,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
12631266 signal (SIGINT , SIG_DFL );
12641267 signal (SIGCHLD , SIG_DFL );
12651268
1266- if (forcedCmd ) {
1269+ if (ptyReq == 0 || forcedCmd ) {
12671270 close (stdoutPipe [0 ]);
12681271 close (stderrPipe [0 ]);
12691272 close (stdinPipe [1 ]);
@@ -1390,7 +1393,13 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
13901393 close (stderrPipe [1 ]);
13911394 close (stdinPipe [1 ]);
13921395 }
1393- else {
1396+ else if (ptyReq == 0 ) {
1397+ ret = execv (cmd , (char * * )args );
1398+ close (stdoutPipe [1 ]);
1399+ close (stderrPipe [1 ]);
1400+ close (stdinPipe [1 ]);
1401+ }
1402+ else { /* open interactive shell */
13941403 ret = execv (cmd , (char * * )args );
13951404 }
13961405 if (ret && errno ) {
@@ -1443,7 +1452,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14431452#endif
14441453
14451454 wolfSSH_SetTerminalResizeCtx (ssh , (void * )& childFd );
1446- if (forcedCmd ) {
1455+ if (ptyReq == 0 || forcedCmd ) {
14471456 close (stdoutPipe [1 ]);
14481457 close (stderrPipe [1 ]);
14491458 close (stdinPipe [0 ]);
@@ -1469,7 +1478,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14691478
14701479 if (wolfSSH_stream_peek (ssh , tmp , 1 ) <= 0 ) {
14711480 /* select on stdout/stderr pipes with forced commands */
1472- if (forcedCmd ) {
1481+ if (ptyReq == 0 || forcedCmd ) {
14731482 FD_SET (stdoutPipe [0 ], & readFds );
14741483 if (stdoutPipe [0 ] > maxFd )
14751484 maxFd = stdoutPipe [0 ];
@@ -1515,7 +1524,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15151524 if (cnt_r <= 0 )
15161525 break ;
15171526
1518- if (forcedCmd ) {
1527+ if (ptyReq == 0 || forcedCmd ) {
15191528 cnt_w = (int )write (stdinPipe [1 ], channelBuffer ,
15201529 cnt_r );
15211530 }
@@ -1555,7 +1564,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15551564 current = wolfSSH_ChannelFind (ssh , lastChannel ,
15561565 WS_CHANNEL_ID_SELF );
15571566 eof = wolfSSH_ChannelGetEof (current );
1558- if (eof && forcedCmd ) {
1567+ if (eof && ( ptyReq == 0 || forcedCmd ) ) {
15591568 /* SSH is done, close stdin pipe to child process */
15601569 close (stdinPipe [1 ]);
15611570 stdinPipe [1 ] = -1 ;
@@ -1585,7 +1594,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15851594 }
15861595 }
15871596
1588- if (forcedCmd ) {
1597+ if (ptyReq == 0 || forcedCmd ) {
15891598 if (FD_ISSET (stderrPipe [0 ], & readFds )) {
15901599 cnt_r = (int )read (stderrPipe [0 ], shellBuffer ,
15911600 sizeof shellBuffer );
@@ -1725,7 +1734,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
17251734 }
17261735
17271736 /* check for any left over data in pipes then close them */
1728- if (forcedCmd ) {
1737+ if (ptyReq == 0 || forcedCmd ) {
17291738 int readSz ;
17301739
17311740 fcntl (stdoutPipe [0 ], F_SETFL , fcntl (stdoutPipe [0 ], F_GETFL )
0 commit comments