From ccb5ed5e7191a083da52998df4c880f693451144 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Thu, 31 Mar 2016 14:30:53 +0200 Subject: [PATCH] ssh_filter_btrbk: allow "realpath" and "cat /proc/self/mounts" on targets --- ssh_filter_btrbk.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ssh_filter_btrbk.sh b/ssh_filter_btrbk.sh index 6547f54..99949e5 100755 --- a/ssh_filter_btrbk.sh +++ b/ssh_filter_btrbk.sh @@ -9,6 +9,7 @@ enable_log= use_sudo= restrict_path_list= allow_list= +allow_exact_list= log_cmd() { @@ -22,6 +23,11 @@ allow_cmd() allow_list="${allow_list}|$1" } +allow_exact_cmd() +{ + allow_exact_list="${allow_exact_list}|$1" +} + reject_and_die() { local reason=$1 @@ -54,9 +60,16 @@ reject_filtered_cmd() # allow multiple paths (e.g. "btrfs subvolume snapshot ") btrfs_cmd_match="^(${allow_list})( ${option_match})*( $path_match)+$" - if [[ ! $SSH_ORIGINAL_COMMAND =~ $btrfs_cmd_match ]] ; then - reject_and_die "disallowed command${restrict_path_list:+ (restrict-path: \"${restrict_path_list//|/\", \"}\")}" + if [[ $SSH_ORIGINAL_COMMAND =~ $btrfs_cmd_match ]] ; then + return 0 fi + + exact_cmd_match="^${allow_exact_list}$"; + if [[ $SSH_ORIGINAL_COMMAND =~ $exact_cmd_match ]] ; then + return 0 + fi + + reject_and_die "disallowed command${restrict_path_list:+ (restrict-path: \"${restrict_path_list//|/\", \"}\")}" } @@ -88,6 +101,9 @@ while [[ "$#" -ge 1 ]]; do -t|--target) allow_cmd "btrfs receive" + # the following are needed if targets point to a directory + allow_cmd "realpath" + allow_exact_cmd "cat /proc/self/mounts" ;; -d|--delete) @@ -121,6 +137,7 @@ done # remove leading "|" on alternation lists allow_list=${allow_list#\|} +allow_exact_list=${allow_exact_list#\|} restrict_path_list=${restrict_path_list#\|}