From owner-svn-src-all@FreeBSD.ORG Sat Nov 10 03:44:09 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 499B5CF; Sat, 10 Nov 2012 03:44:09 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 140FF8FC08; Sat, 10 Nov 2012 03:44:09 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qAA3i8tk019659; Sat, 10 Nov 2012 03:44:08 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qAA3i8dk019658; Sat, 10 Nov 2012 03:44:08 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201211100344.qAA3i8dk019658@svn.freebsd.org> From: Eitan Adler Date: Sat, 10 Nov 2012 03:44:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242848 - head/usr.bin/ssh-copy-id X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Nov 2012 03:44:09 -0000 Author: eadler Date: Sat Nov 10 03:44:08 2012 New Revision: 242848 URL: http://svnweb.freebsd.org/changeset/base/242848 Log: 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 Modified: head/usr.bin/ssh-copy-id/ssh-copy-id.sh Modified: head/usr.bin/ssh-copy-id/ssh-copy-id.sh ============================================================================== --- head/usr.bin/ssh-copy-id/ssh-copy-id.sh Sat Nov 10 02:08:40 2012 (r242847) +++ head/usr.bin/ssh-copy-id/ssh-copy-id.sh Sat Nov 10 03:44:08 2012 (r242848) @@ -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