[openssh-commits] [openssh] 11/13: restore optionality of -i's argument

git+noreply at mindrot.org git+noreply at mindrot.org
Sat Aug 17 11:22:29 AEST 2024


This is an automated email from the git hooks/post-receive script.

dtucker pushed a commit to branch master
in repository openssh.

commit 7fc9ccdce18841ebd0a97e31e43258512ab32a32
Author: Philip Hands <phil at hands.com>
AuthorDate: Sun Aug 4 20:45:00 2024 +0200

    restore optionality of -i's argument
    
    SSH-Copy-ID-Upstream: f70e3abb510e4eeb040b47894e41828246c1b720
---
 contrib/ssh-copy-id   | 18 +++++++++++++++++-
 contrib/ssh-copy-id.1 |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/contrib/ssh-copy-id b/contrib/ssh-copy-id
index 4798a4db..6251201b 100644
--- a/contrib/ssh-copy-id
+++ b/contrib/ssh-copy-id
@@ -114,7 +114,9 @@ if [ -n "$SSH_AUTH_SOCK" ] && ssh-add -L >/dev/null 2>&1 ; then
   GET_ID="ssh-add -L"
 fi
 
-while getopts "i:o:p:F:t:fnsxh?" OPT
+OPTS="io:p:F:t:fnsxh?"
+
+while getopts "$OPTS" OPT
 do
   case "$OPT" in
     i)
@@ -123,6 +125,20 @@ do
         usage
       }
       SEEN_OPT_I="yes"
+
+      # Check for -i's optional parameter
+      eval "nextarg=\${$OPTIND}"
+      # shellcheck disable=SC2154
+      if [ $OPTIND = $# ]; then
+        if [ -r "$nextarg" ] && grep -iq ssh "$nextarg"; then
+          printf '\n%s: ERROR: Missing hostname. Use "-i -- %s" if you really mean to use this as the hostname\n\n' "$0" "$nextarg" >&2
+          usage
+        fi
+      elif ! expr -- "$nextarg" : "-[$(echo "$OPTS" | tr -d :)-]" >/dev/null ; then
+        # when not at the last arg, and not followed by an option, -i has an argument
+        OPTARG="$nextarg"
+        OPTIND=$((OPTIND + 1))
+      fi
       use_id_file "${OPTARG:-$DEFAULT_PUB_ID_FILE}"
       ;;
     o|F)
diff --git a/contrib/ssh-copy-id.1 b/contrib/ssh-copy-id.1
index 74eec2f8..cc74e432 100644
--- a/contrib/ssh-copy-id.1
+++ b/contrib/ssh-copy-id.1
@@ -67,7 +67,7 @@ command instead.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
-.It Fl i Ar identity_file
+.It Fl i Op Ar identity_file
 Use only the key(s) contained in
 .Ar identity_file
 (rather than looking for identities via

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list