From a249e9be001bd34fd6c5950e9f66dc0350b73897 Mon Sep 17 00:00:00 2001 From: iliajie Date: Sat, 12 Nov 2022 19:32:56 +0200 Subject: [PATCH] Fix to correctly support setting login shell mixed with params There is no way to make it work correctly across all shell, i.e. param sequence which work with `bash` will fail with `csh`, as `-l` (login shell) can be the only flag specified --- proc/proc-lib.pl | 4 ++-- xterm/shellserver.pl | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/proc/proc-lib.pl b/proc/proc-lib.pl index 9a6a5ad32..703fb3de2 100755 --- a/proc/proc-lib.pl +++ b/proc/proc-lib.pl @@ -295,7 +295,7 @@ if (!$@) { open(STDERR, ">&".fileno($ttyfh)); close($ttyfh); # Already dup'd if ($binary) { - exec "$cmd $binary"; + exec $cmd $binary; } else { exec($cmd); @@ -350,7 +350,7 @@ else { open(STDERR, ">&STDOUT"); close($ptyfh); if ($binary) { - exec "$cmd $binary"; + exec $cmd $binary; } else { exec($cmd); diff --git a/xterm/shellserver.pl b/xterm/shellserver.pl index 9a3352a33..a3499d16d 100755 --- a/xterm/shellserver.pl +++ b/xterm/shellserver.pl @@ -33,10 +33,10 @@ $ENV{'TERM'} = 'xterm-256color'; $ENV{'HOME'} = $uinfo[7]; chdir($dir || $uinfo[7] || "/"); my $shellcmd = $uinfo[8]; -my $shell = $uinfo[8]; -$shell =~ s/^.*\///; -my $shellname = $shell; -$shell = "-".$shell; +my $shellname = $shellcmd; +$shellname =~ s/^.*\///; +my $shellexec = $shellcmd; +my $shelllogin = "-".$shellname; # Check for initialization file if ($config{'rcfile'}) { @@ -51,17 +51,21 @@ if ($config{'rcfile'}) { } if (-r $rcfile) { # Bash - if ($shellcmd =~ /\/bash$/) { - $shellcmd .= " --rcfile $rcfile"; + if ($shellname eq 'bash') { + $shellexec = "$shellcmd --rcfile $rcfile"; } # Sh - elsif ($shellcmd =~ /\/sh$/) { - $shellcmd = "ENV=$rcfile; export ENV ; $shellcmd"; + elsif ($shellname eq 'sh') { + $shellexec = "ENV=$rcfile; export ENV ; $shellexec"; } - print STDERR "using alternative shell init file $rcfile\n"; + + # Cannot use login shell while passing other parameters, + # and it is not necessary as we already add init files + $shelllogin = undef; } } -my ($shellfh, $pid) = &proc::pty_process_exec($shellcmd, $uid, $gid, $shell); +my ($shellfh, $pid) = &proc::pty_process_exec($shellexec, $uid, $gid, $shelllogin); +print STDERR "using shell command '$shellexec".($shelllogin ? " $shelllogin" : undef)."'\n"; &reset_environment(); if (!$pid) { &cleanup_miniserv();