2014-10-29 18:33:36 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
|
|
|
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
2015-04-05 13:29:56 +00:00
|
|
|
export GIT_SSH="/usr/sbin/foodoor-ssh-wrapper"
|
2014-10-29 18:33:36 +00:00
|
|
|
|
|
|
|
dest=/var/run/foodoor-keys
|
|
|
|
|
|
|
|
if [ ! -e "${dest}/.git/config" ]
|
|
|
|
then
|
2015-04-05 11:48:07 +00:00
|
|
|
#echo "Repo does not exist, trying to clone..."
|
|
|
|
( cd /var/run && git clone --quiet --single-branch --depth=1 luftschleuse@nordstern.chaospott.de:/home/luftschleuse/foodoor-keys "${dest}" )
|
2014-10-29 18:33:36 +00:00
|
|
|
else
|
2015-04-05 11:48:07 +00:00
|
|
|
#echo "Repo exists, updating..."
|
|
|
|
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
|
2014-10-29 18:33:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
for action in open close
|
|
|
|
do
|
2015-04-05 11:48:07 +00:00
|
|
|
outfile="${dest}/authorized_keys.${action}"
|
|
|
|
rm -f ${outfile}
|
|
|
|
find "${dest}/keys" -name '*.pub' | sort | \
|
|
|
|
while read keyfile
|
|
|
|
do
|
|
|
|
valid_key=$(ssh-keygen -l -f ${keyfile})
|
|
|
|
if [ "$?" -eq "0" ]; then
|
2015-04-13 15:11:53 +00:00
|
|
|
if [ $(echo "${valid_key}" | cut -d" " -f1) -lt "4096" ]; then
|
|
|
|
echo "Size of key ${keyfile} is less than 4096. Not adding it to key database." >&2
|
2015-04-05 11:48:07 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
2015-04-05 13:03:45 +00:00
|
|
|
printf "command=\"/usr/sbin/foodoor ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile}
|
2015-04-05 11:48:07 +00:00
|
|
|
cat "${keyfile}" >> ${outfile}
|
2015-07-17 17:34:22 +00:00
|
|
|
echo >> ${outfile}
|
2015-04-05 11:48:07 +00:00
|
|
|
done
|
|
|
|
install -d -o ${action} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
|
|
|
|
install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
|
2014-10-29 18:33:36 +00:00
|
|
|
done
|