From d84472a2777f1b5c8c8cd2502ed750d149d52fd0 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 8 May 2021 11:03:24 +0200 Subject: [PATCH] new: [rsync-backup-target] add ``ssh-key get-type IDENT`` to get backup type info Signed-off-by: Valentin Lab --- .../src/usr/local/sbin/ssh-admin-cmd-validate | 9 +++++++++ .../build/src/usr/local/sbin/ssh-key | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/rsync-backup-target/build/src/usr/local/sbin/ssh-admin-cmd-validate b/rsync-backup-target/build/src/usr/local/sbin/ssh-admin-cmd-validate index 15e79f5..11c937d 100755 --- a/rsync-backup-target/build/src/usr/local/sbin/ssh-admin-cmd-validate +++ b/rsync-backup-target/build/src/usr/local/sbin/ssh-admin-cmd-validate @@ -71,6 +71,15 @@ elif [[ "$SSH_ORIGINAL_COMMAND" =~ ^"ssh-key rm "[a-zA-Z0-9._-]+$ ]]; then # echo "Would accept: $SSH_ORIGINAL_COMMAND" >&2 exec sudo /usr/local/sbin/ssh-key rm "$label" "${ssh_args[@]:2}" +elif [[ "$SSH_ORIGINAL_COMMAND" =~ ^"ssh-key get-type "[a-zA-Z0-9._-]+$ ]]; then + log "ACCEPTED: $SSH_ORIGINAL_COMMAND" + + ## Interpret \ to allow passing spaces (want to avoid possible issue with \n) + #read -a ssh_args <<< "${SSH_ORIGINAL_COMMAND}" + ssh_args=(${SSH_ORIGINAL_COMMAND}) + + # echo "Would accept: $SSH_ORIGINAL_COMMAND" >&2 + exec sudo /usr/local/sbin/ssh-key get-type "$label" "${ssh_args[@]:2}" elif [[ "$SSH_ORIGINAL_COMMAND" =~ ^"request-recovery-key "[a-zA-Z0-9._-]+$ ]]; then log "ACCEPTED: $SSH_ORIGINAL_COMMAND" diff --git a/rsync-backup-target/build/src/usr/local/sbin/ssh-key b/rsync-backup-target/build/src/usr/local/sbin/ssh-key index 5588919..1eff620 100755 --- a/rsync-backup-target/build/src/usr/local/sbin/ssh-key +++ b/rsync-backup-target/build/src/usr/local/sbin/ssh-key @@ -54,6 +54,20 @@ ssh-key-rm() { } +ssh-key-get-type() { + local label="$1" ident="$2" key content commentary + + key="${RSYNC_KEY_PATH}/backup/$label/$ident.pub" + if ! [ -e "$key" ]; then + echo "Error: key '$ident' not found." >&2 + return 1 + fi + content=$(cat "$key") || return 1 + commentary=${content##* } + printf "%s\n" "${commentary%%@*}" +} + + ssh-key-add() { local label="$1" type="$2" key="$3" email="$4" @@ -127,6 +141,10 @@ case "$1" in shift ssh-key-ls "$@" ;; + "get-type") + shift + ssh-key-get-type "$@" + ;; *) echo "Unknown command '$1'." ;;