Merge branch 'ssh_authorized_key_group' of https://github.com/contradict/cdist

This commit is contained in:
Nico Schottelius 2012-05-31 19:23:53 +02:00
commit 029dc4c387
2 changed files with 29 additions and 2 deletions

View File

@ -0,0 +1,15 @@
#!/bin/sh
# Get option dstuser if defined
if [ -f "$__object/parameter/dstuser" ]; then
dstuser=`cat "$__object/parameter/dstuser"`
else
dstuser="root"
fi
if id $dstuser >/dev/null 2>&1 ; then
id -ng $dstuser
else
echo "$__object_id: Destination user $dstuser does not exist" >&2
exit 1
fi

View File

@ -29,8 +29,13 @@ fi
# Get option dstuser if defined
if [ -f "$__object/parameter/dstuser" ]; then
dstuser=`cat "$__object/parameter/dstuser"`
else
dstuser="root"
fi
# retrieve destination group
dstgroup=$(cat "$__object/explorer/dstuser_group")
# if a source user is defined, use it's public key
if [ "$srcuser" ]; then
srcrsa="/home/${srcuser}/.ssh/id_rsa.pub"
@ -46,9 +51,16 @@ else
sshpath="/root/.ssh"
fi
rsa=`cat $srcrsa`
__directory $sshpath
__directory $sshpath \
--owner $dstuser \
--group $dstgroup \
--mode 700
# the file authorized_keys depends on the .ssh folder
require="__directory${sshpath}" __file "$sshpath/authorized_keys" --mode 640
require="__directory${sshpath}" \
__file "$sshpath/authorized_keys" \
--mode 640 \
--owner $dstuser \
--group $dstgroup
# the line added depends on authorized_keys existence
require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \
"$sshpath/authorized_keys" --line "$rsa"