From 6aacf4b3ca8f4ce6b0bcf1e39a871d212dcc8aa3 Mon Sep 17 00:00:00 2001 From: Timothe Litt Date: Sun, 25 Jul 2021 09:12:13 -0400 Subject: [PATCH] Fix copy_file_to_location failures with ssh When a suffix is applied to a filename lacking an extension, a '.' in the host name is treated as the extension, and the extension is inserted there instead of being appended to the filename. Inspect the basename of the destination, and append only the suffix if no extension is present. Thus ssh:host.example.net:/etc/ssl/private/foo will now be copied to host.example.net/etc/ssl/private/foo.suffix instead of host.example.suffix.net/etc./ssl/private/foo (which usually would fail). Note that a local file, such as /etc/ssl/private/foo will be copied to /etc/ssl/private/foo.suffix. (Not /etc/ssl/private/foo.suffix. as before, which was incorrect). --- getssl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/getssl b/getssl index fecbc7c..3061415 100755 --- a/getssl +++ b/getssl @@ -264,6 +264,7 @@ # 2021-07-12 Do not redirect outputs on remote commands when the debug option is used (atisne) # 2021-07-20 Use +noidnout to enable certificates for IDN domains (#679)(2.37) # 2021-07-22 Only pass +noidnout param to dig/drill(#682)(2.38) +# 2021-07-25 Fix copy_file_to_location failures with ssh when suffix applied to file lacking an extension (2.39) # ---------------------------------------------------------------------------------------- case :$SHELLOPTS: in @@ -272,7 +273,7 @@ esac PROGNAME=${0##*/} PROGDIR="$(cd "$(dirname "$0")" || exit; pwd -P;)" -VERSION="2.38" +VERSION="2.39" # defaults ACCOUNT_KEY_LENGTH=4096 @@ -850,7 +851,12 @@ copy_file_to_location() { # copies a file, using scp, sftp or ftp if required. IFS=\; read -r -a copy_locations <<<"$3" for to in "${copy_locations[@]}"; do if [[ -n "$suffix" ]]; then - to="${to%.*}.${suffix}.${to##*.}" + bname="`basename $to`" + if [[ "${bname##*.}" == "$bname" ]]; then + to="${to}.${suffix}" + else + to="${to%.*}.${suffix}.${to##*.}" + fi fi info "copying $cert to $to" if [[ "${to:0:4}" == "ssh:" ]] ; then