Skip to content

Commit

Permalink
wolfSSHd Terminal
Browse files Browse the repository at this point in the history
1. Prep the SHELL variable inherited by the new shell to be equal to the
   user's shell.
2. Prep the new shell's $0 variable to be equal to the shell name
   prefixed with a '-', ie "/bin/bash" becomes "-bash".
  • Loading branch information
ejohnstown committed Dec 28, 2023
1 parent 711fee2 commit 92c4242
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
/* Child process */
const char *args[] = {"-sh", NULL, NULL, NULL};
char cmd[MAX_COMMAND_SZ];
char shell[MAX_COMMAND_SZ];
int ret;

signal(SIGINT, SIG_DFL);
Expand Down Expand Up @@ -1258,6 +1259,25 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,

setenv("HOME", pPasswd->pw_dir, 1);
setenv("LOGNAME", pPasswd->pw_name, 1);
setenv("SHELL", pPasswd->pw_shell, 1);

if (pPasswd->pw_shell) {
word32 shellSz = (word32)WSTRLEN(pPasswd->pw_shell);

if (shellSz < sizeof(shell)) {
char* cursor;
char* start;

WSTRNCPY(shell, pPasswd->pw_shell, sizeof(shell));
cursor = shell;
do {
start = cursor;
*cursor = '-';
cursor = WSTRCHR(start, '/');
} while (cursor && *cursor != '\0');
args[0] = start;
}
}

rc = chdir(pPasswd->pw_dir);
if (rc != 0) {
Expand Down

0 comments on commit 92c4242

Please sign in to comment.