Skip to content

Commit 91c9279

Browse files
simplify wolfSSH_ChannelIsPty to only take a pointer to a channel
1 parent 7c9f8f1 commit 91c9279

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

apps/wolfsshd/wolfsshd.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,23 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
11641164
#include <sys/ioctl.h>
11651165
#endif
11661166

1167+
static int SHELL_IsPty(WOLFSSH* ssh)
1168+
{
1169+
WOLFSSH_CHANNEL* channel;
1170+
int ret = WS_SUCCESS;
1171+
word32 channelId = 0;
1172+
1173+
ret = wolfSSH_GetLastRxId(ssh, &channelId);
1174+
if (ret == WS_SUCCESS) {
1175+
channel = wolfSSH_ChannelFind(ssh, channelId, WS_CHANNEL_ID_SELF);
1176+
}
1177+
1178+
if (ret == WS_SUCCESS) {
1179+
ret = wolfSSH_ChannelIsPty(channel);
1180+
}
1181+
return ret;
1182+
}
1183+
11671184
/* handles creating a new shell env. and maintains SSH connection for incoming
11681185
* user input as well as output of the shell.
11691186
* return WS_SUCCESS on success */
@@ -1205,7 +1222,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
12051222

12061223
forcedCmd = wolfSSHD_ConfigGetForcedCmd(usrConf);
12071224

1208-
ptyReq = wolfSSH_ChannelIsPty(ssh, NULL);
1225+
ptyReq = SHELL_IsPty(ssh);
12091226
if (ptyReq < 0) {
12101227
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failure get channel PTY state");
12111228
return WS_FATAL_ERROR;

src/ssh.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,27 +3235,12 @@ WS_SessionType wolfSSH_ChannelGetSessionType(const WOLFSSH_CHANNEL* channel)
32353235

32363236
#if defined(WOLFSSH_TERM)
32373237
/* returns 1 if a PTY was requested, 0 if not, and negative on failure */
3238-
int wolfSSH_ChannelIsPty(WOLFSSH* ssh, WOLFSSH_CHANNEL* channel)
3238+
int wolfSSH_ChannelIsPty(const WOLFSSH_CHANNEL* channel)
32393239
{
3240-
WOLFSSH_CHANNEL* channelPtr;
3241-
int ret = WS_SUCCESS;
3242-
3243-
channelPtr = channel;
3244-
3245-
/* if channel is NULL than use the last rxtx channel */
3246-
if (channelPtr == NULL) {
3247-
word32 channelId = 0;
3248-
3249-
ret = wolfSSH_GetLastRxId(ssh, &channelId);
3250-
if (ret == WS_SUCCESS) {
3251-
channelPtr = ChannelFind(ssh, channelId, WS_CHANNEL_ID_SELF);
3252-
}
3253-
}
3254-
3255-
if (ret == WS_SUCCESS) {
3256-
ret = channelPtr->ptyReq;
3240+
if (channel == NULL) {
3241+
return WS_BAD_ARGUMENT;
32573242
}
3258-
return ret;
3243+
return channel->ptyReq;
32593244
}
32603245
#endif
32613246

wolfssh/ssh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ WOLFSSH_API WS_SessionType wolfSSH_ChannelGetSessionType(
233233
const WOLFSSH_CHANNEL* channel);
234234
WOLFSSH_API const char* wolfSSH_ChannelGetSessionCommand(
235235
const WOLFSSH_CHANNEL* channel);
236-
WOLFSSH_API int wolfSSH_ChannelIsPty(WOLFSSH* ssh, WOLFSSH_CHANNEL* channel);
236+
WOLFSSH_API int wolfSSH_ChannelIsPty(const WOLFSSH_CHANNEL* channel);
237237

238238
/* Channel callbacks */
239239
typedef int (*WS_CallbackChannelOpen)(WOLFSSH_CHANNEL* channel, void* ctx);

0 commit comments

Comments
 (0)