From: Philip Hands Date: Wed, 31 Jul 2024 21:19:03 +0000 (+0200) Subject: assert that SCRATCH_DIR is a writable directory X-Git-Tag: V_9_9_P1~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb5aafa1ffaeee75799141ec5ded406a65ec7d18;p=thirdparty%2Fopenssh-portable.git assert that SCRATCH_DIR is a writable directory SSH-Copy-ID-Upstream: ecb2b9d10883b9a16df56c83896c9bb47a80cde2 --- diff --git a/contrib/ssh-copy-id b/contrib/ssh-copy-id index ceadcca88..dfecc744d 100644 --- a/contrib/ssh-copy-id +++ b/contrib/ssh-copy-id @@ -182,10 +182,20 @@ if [ -z "$(eval $GET_ID)" ] ; then exit 1 fi +# assert_scratch_ok() +# ensures that $SCRATCH_DIR is setup. +assert_scratch_ok() { + [ "$SCRATCH_DIR" ] && [ -d "$SCRATCH_DIR" ] && [ -w "$SCRATCH_DIR" ] && return 0 + + printf 'ERROR: Assertion failure: in %s(): scratch_dir was not correctly set up (SCRATCH_DIR = "%s")\n' "$1" "$SCRATCH_DIR" >&2 + return 1 +} + # filter_ids() # tries to log in using the keys piped to it, and filters out any that work filter_ids() { L_SUCCESS="$1" + assert_scratch_ok filter_ids || return L_TMP_ID_FILE="$SCRATCH_DIR"/popids_tmp_id L_OUTPUT_FILE="$SCRATCH_DIR"/popids_output @@ -288,6 +298,7 @@ installkeys_via_sftp() { # repopulate "$@" inside this function eval set -- "$SSH_OPTS" + assert_scratch_ok installkeys_via_sftp || return 1 L_KEYS="$SCRATCH_DIR"/authorized_keys L_SHARED_CON="$SCRATCH_DIR"/master-conn $SSH -f -N -M -S "$L_SHARED_CON" "$@"