From ad70a474d910a4509e17a8786ed2923c5e711d50 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 10 Nov 2022 21:38:05 -0800 Subject: [PATCH] Run shell as a login shell --- proc/proc-lib.pl | 18 ++++++++++++++---- xterm/shellserver.pl | 5 ++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/proc/proc-lib.pl b/proc/proc-lib.pl index fe35357b2..703fb3de2 100755 --- a/proc/proc-lib.pl +++ b/proc/proc-lib.pl @@ -248,11 +248,11 @@ do { local $oldexit = $?; } while($xp > 0); } -# pty_process_exec(command, [uid, gid]) +# pty_process_exec(command, [uid, gid], [force-binary-name]) # Starts the given command in a new pty and returns the pty filehandle and PID sub pty_process_exec { -local ($cmd, $uid, $gid) = @_; +local ($cmd, $uid, $gid, $binary) = @_; if (&is_readonly_mode()) { # When in readonly mode, don't run the command $cmd = "/bin/true"; @@ -294,7 +294,12 @@ if (!$@) { open(STDOUT, ">&".fileno($ttyfh)); open(STDERR, ">&".fileno($ttyfh)); close($ttyfh); # Already dup'd - exec($cmd); + if ($binary) { + exec $cmd $binary; + } + else { + exec($cmd); + } print "Exec failed : $!\n"; exit 1; } @@ -344,7 +349,12 @@ else { open(STDOUT, ">&$ttyfh"); open(STDERR, ">&STDOUT"); close($ptyfh); - exec($cmd); + if ($binary) { + exec $cmd $binary; + } + else { + exec($cmd); + } print "Exec failed : $!\n"; exit 1; } diff --git a/xterm/shellserver.pl b/xterm/shellserver.pl index 473bbe9b1..f32d3eb51 100755 --- a/xterm/shellserver.pl +++ b/xterm/shellserver.pl @@ -53,7 +53,10 @@ if ($config{'flavors'} == 1 || # Set terminal $ENV{'TERM'} = 'xterm-256color'; chdir($dir || $uinfo[7] || "/"); -my ($shellfh, $pid) = &proc::pty_process_exec($uinfo[8], $uid, $gid); +my $shell = $uinfo[8]; +$shell =~ s/^.*\///; +$shell = "-".$shell; +my ($shellfh, $pid) = &proc::pty_process_exec($uinfo[8], $uid, $gid, $shell); &reset_environment(); if (!$pid) { &cleanup_miniserv();