summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh-copy-id
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2012-11-10 03:44:08 +0000
committereadler <eadler@FreeBSD.org>2012-11-10 03:44:08 +0000
commita6ec07ce831d056b9a2e17bd31831c4055741b5d (patch)
tree13bfeda8cde9a7b082b57e306cf30bfb7bb4aedf /usr.bin/ssh-copy-id
parent7beb738c8a72cc197d3e898784afe3fba28f1834 (diff)
downloadFreeBSD-src-a6ec07ce831d056b9a2e17bd31831c4055741b5d.zip
FreeBSD-src-a6ec07ce831d056b9a2e17bd31831c4055741b5d.tar.gz
Be a bit more paranoid.
Use more portable constructs in order to allow upstream adoption Add per-file error messages Reviewed by: jilles Approved by: cperciva MFC after: 1 week
Diffstat (limited to 'usr.bin/ssh-copy-id')
-rwxr-xr-xusr.bin/ssh-copy-id/ssh-copy-id.sh42
1 files changed, 23 insertions, 19 deletions
diff --git a/usr.bin/ssh-copy-id/ssh-copy-id.sh b/usr.bin/ssh-copy-id/ssh-copy-id.sh
index 8f087d3..94429de 100755
--- a/usr.bin/ssh-copy-id/ssh-copy-id.sh
+++ b/usr.bin/ssh-copy-id/ssh-copy-id.sh
@@ -34,19 +34,18 @@ usage() {
sendkey() {
local h="$1"
- shift 1
- local k="$@"
- echo "$k" | ssh $port -S none $options "$user$h" /bin/sh -c \''
- set -e;
- umask 077;
- keyfile=$HOME/.ssh/authorized_keys ;
- mkdir -p $HOME/.ssh/ ;
- while read alg key comment ; do
- if ! grep -sqwF "$key" "$keyfile"; then
- echo "$alg $key $comment" |
- tee -a "$keyfile" >/dev/null ;
- fi ;
- done
+ local k="$2"
+ printf "%s\n" "$k" | ssh $port -S none $options "$user$h" /bin/sh -c \'' \
+ set -e; \
+ umask 077; \
+ keyfile=$HOME/.ssh/authorized_keys ; \
+ mkdir -p -- "$HOME/.ssh/" ; \
+ while read alg key comment ; do \
+ [ -n "$key" ] || continue; \
+ if ! grep -sqwF "$key" "$keyfile"; then \
+ printf "$alg $key $comment\n" >> "$keyfile" ; \
+ fi ; \
+ done \
'\'
}
@@ -63,12 +62,17 @@ nl="
"
options=""
+IFS=$nl
+
while getopts 'i:lo:p:' arg; do
case $arg in
i)
hasarg="x"
- if [ -f "$OPTARG" ]; then
- keys="$(cat $OPTARG)$nl$keys"
+ if [ -r "$OPTARG" ]; then
+ keys="$(cat -- "$OPTARG")$nl$keys"
+ else
+ echo "File $OPTARG not found" >&2
+ exit 1
fi
;;
l)
@@ -76,10 +80,10 @@ while getopts 'i:lo:p:' arg; do
agentKeys
;;
p)
- port="-p $OPTARG"
+ port=-p$nl$OPTARG
;;
o)
- options="$options -o '$OPTARG'"
+ options=$options$nl-o$nl$OPTARG
;;
*)
usage
@@ -92,11 +96,11 @@ shift $((OPTIND-1))
if [ -z "$hasarg" ]; then
agentKeys
fi
-if [ -z "$keys" -o "$keys" = "$nl" ]; then
+if [ -z "$keys" ] || [ "$keys" = "$nl" ]; then
echo "no keys found" >&2
exit 1
fi
-if [ -z "$@" ]; then
+if [ "$#" -eq 0 ]; then
usage
fi
OpenPOWER on IntegriCloud