From 1544b2316257d9851ef96169a0ad9676db8a175d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 11 Apr 2017 12:56:54 +0200 Subject: [ssh-auth-keys] Try to filter invalid data from authkeys.d, don't break on no newline --- .../data/opt/openslx/scripts/systemd-ssh_auth_keys | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'core/modules/ssh-auth-keys') diff --git a/core/modules/ssh-auth-keys/data/opt/openslx/scripts/systemd-ssh_auth_keys b/core/modules/ssh-auth-keys/data/opt/openslx/scripts/systemd-ssh_auth_keys index 9a64b83a..d08e78a0 100755 --- a/core/modules/ssh-auth-keys/data/opt/openslx/scripts/systemd-ssh_auth_keys +++ b/core/modules/ssh-auth-keys/data/opt/openslx/scripts/systemd-ssh_auth_keys @@ -7,14 +7,18 @@ AUTH_KEYS_FILE="/root/.ssh/authorized_keys" [ ! -d "$AUTH_KEYS_DIR" ] && echo "No such directory: $AUTH_KEYS_DIR" && exit 0 mkdir -m 700 $(dirname "$AUTH_KEYS_FILE") 2>/dev/null +TMP=$(mktemp) + +[ -s "$AUTH_KEYS_FILE" ] && cat "$AUTH_KEYS_FILE" >> "$TMP" # ok, lets cat them in the real file for KEY in "$AUTH_KEYS_DIR"/* ; do - if ! cat $KEY >> "$AUTH_KEYS_FILE" ; then - echo "Could not add '$KEY' to '$AUTH_KEYS_FILE'" - exit 1 - fi + grep -E '(^#|\bssh-.*\sAAA)' "$KEY" >> "$TMP" done +sort -u "$TMP" > "$AUTH_KEYS_FILE" || cp -f "$TMP" "$AUTH_KEYS_FILE" + +rm -f -- "$TMP" + # all done, all good exit 0 -- cgit v1.2.3-55-g7522