From eaf63ebc48071c82b76637fbbe05a91c32bc66b1 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 19 Apr 2017 13:54:16 -0700 Subject: [PATCH] chroot options for shell module --- shell/acl_security.pl | 4 ++++ shell/defaultacl | 1 + shell/index.cgi | 10 ++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/shell/acl_security.pl b/shell/acl_security.pl index 04e95c73d..593802afe 100755 --- a/shell/acl_security.pl +++ b/shell/acl_security.pl @@ -8,6 +8,9 @@ sub acl_security_form print &ui_table_row($text{'acl_user'}, &ui_opt_textbox("user", $_[0]->{'user'}, 20, $text{'acl_user_def'})." ". &user_chooser_button("user")); + +print &ui_table_row($text{'acl_chroot'}, + &ui_filebox("chroot", $_[0]->{'chroot'}, 30, 0, 0, undef, 1)); } # acl_security_save(&options) @@ -15,5 +18,6 @@ print &ui_table_row($text{'acl_user'}, sub acl_security_save { $_[0]->{'user'} = $in{'user_def'} ? undef : $in{'user'}; +$_[0]->{'chroot'} = $in{'chroot'}; } diff --git a/shell/defaultacl b/shell/defaultacl index 5202c67ed..8775f00f2 100644 --- a/shell/defaultacl +++ b/shell/defaultacl @@ -1 +1,2 @@ user=root +chroot=/ diff --git a/shell/index.cgi b/shell/index.cgi index 663647ed8..7fc128170 100755 --- a/shell/index.cgi +++ b/shell/index.cgi @@ -43,19 +43,21 @@ if (!$in{'clear'}) { $history = &un_urlize($in{'history'}); if ($cmd) { # Execute the latest command + $chroot = $access{'chroot'} eq '/' ? '' : $access{'chroot'}; $fullcmd = $cmd; - $ok = chdir($pwd); + $ok = chdir($chroot.$pwd); $history .= "> ".&html_escape($cmd, 1)."\n"; if ($cmd =~ /^cd\s+"([^"]+)"\s*(;?\s*(.*))$/ || $cmd =~ /^cd\s+'([^']+)'\s*(;?\s*(.*))$/ || $cmd =~ /^cd\s+([^; ]*)\s*(;?\s*(.*))$/) { $cmd = undef; - if (!chdir($1)) { + if (!chdir($chroot.$1)) { $history .= &html_escape("$1: $!\n", 1); } else { $cmd = $3 if ($2); $pwd = &get_current_dir(); + $pwd =~ s/^\Q$chroot\E//g; } } if ($cmd) { @@ -70,6 +72,10 @@ if (!$in{'clear'}) { else { $cmd = "($cmd)"; } + if ($chroot) { + $cmd = "chroot ".quotemeta($access{'chroot'}). + "sh -c ".quotemeta($cmd); + } $pid = &open_execute_command(OUTPUT, $cmd, 2, 0); $out = ""; $trunc = 0;