From 33e89a52bbbf10cc2294c7589711b17d7470dfcc Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Fri, 20 May 2016 16:45:28 +0100 Subject: [PATCH] Copy became script to target directory. Ensure the became script can be run when the source user's home directory is not readable, by copying the script itself to the target directory if the -D flag is used instead of -d. --- opt/bin/become | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/opt/bin/become b/opt/bin/become index ea4926d..07801c3 100755 --- a/opt/bin/become +++ b/opt/bin/become @@ -3,9 +3,14 @@ chdir=0 kerberos=0 x11=0 +copy=0 dir= -while getopts ":cd:kx" opt; do +while getopts ":D:cd:kx" opt; do case $opt in + D) + copy=1 + dir=$OPTARG + ;; c) chdir=1;; d) dir=$OPTARG;; k) kerberos=1;; @@ -14,9 +19,17 @@ while getopts ":cd:kx" opt; do done shift $((OPTIND-1)) -if [ -z "$dir" ]; then - dir=${0%/*} - [ "$dir" = "$0" -o "$dir" = "." ] && dir=$PWD +srcdir=${0%/*} +[ "$srcdir" = "$0" -o "$srcdir" = "." ] && srcdir=$PWD +if [ -n "$dir" ]; then + if [ $copy = 1 ]; then + if ! cp "$srcdir/became" "$dir/became"; then + echo >&2 "Failed to copy $srcdir/became to $dir!" + exit 100 + fi + fi +else + dir=$srcdir fi user="$1"; shift -- 2.20.1