From a4036f708300077d1408ba9b6b930b79b06247c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Tobias=20Skjong-B=C3=B8rsting?= Date: Mon, 18 Sep 2017 08:45:36 +0200 Subject: [PATCH] CLOUDSTACK-10067: Fix a case where a user 'ro' or 'roo' exists on the system, or other variants. (#2252) If one sets user=roo, this will return two directories and then it will fail. --- setup/bindir/cloud-set-guest-sshkey-configdrive.in | 2 +- setup/bindir/cloud-set-guest-sshkey.in | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/bindir/cloud-set-guest-sshkey-configdrive.in b/setup/bindir/cloud-set-guest-sshkey-configdrive.in index df10b436035..e8466e8f56a 100644 --- a/setup/bindir/cloud-set-guest-sshkey-configdrive.in +++ b/setup/bindir/cloud-set-guest-sshkey-configdrive.in @@ -84,7 +84,7 @@ else exit 1 fi -homedir=$(grep ^$user /etc/passwd|awk -F ":" '{print $6}') +homedir=$(getent passwd $user|awk -F ":" '{print $6}') sshdir=$homedir/.ssh authorized=$sshdir/authorized_keys diff --git a/setup/bindir/cloud-set-guest-sshkey.in b/setup/bindir/cloud-set-guest-sshkey.in index 80e40646ad3..321c8dd2fec 100755 --- a/setup/bindir/cloud-set-guest-sshkey.in +++ b/setup/bindir/cloud-set-guest-sshkey.in @@ -49,7 +49,7 @@ if [ -z "$SSHKEY_SERVER_IP" ]; then logger -t "cloud" "Unable to determine the password server, falling back to data-server" SSHKEY_SERVER_IP=data-server fi - + logger -t "cloud" "Sending request to ssh key server at $SSHKEY_SERVER_IP" publickey=$(wget -q -t 3 -T 20 -O - http://$SSHKEY_SERVER_IP/latest/public-keys) if [ $? -eq 0 ]; then @@ -67,7 +67,7 @@ if [ -z "$publickey" ]; then exit 1 fi -homedir=$(grep ^$user /etc/passwd|awk -F ":" '{print $6}') +homedir=$(getent passwd $user|awk -F ":" '{print $6}') sshdir=$homedir/.ssh authorized=$sshdir/authorized_keys