@@ -15,7 +15,6 @@ versinfo() {
15
15
16
16
NEWLINE="
17
17
"
18
- IFS=" $NEWLINE "
19
18
version=# #VERSION##
20
19
PATH=" ${PATH}${PATH: +: } /usr/bin:/bin:/sbin:/usr/sbin:/usr/ucb"
21
20
unset pidfile_out
@@ -304,8 +303,7 @@ catpidf_shell() {
304
303
* csh) cp_pidf=" $cshpidf " ;;
305
304
* ) cp_pidf=" $pidf " ;;
306
305
esac
307
- shift
308
- [ ! -f " $cp_pidf " ] && return 1
306
+ [ ! -f " $cp_pidf " ] && debug " pidfile doesn't exist" && return 1
309
307
[ -f " $cp_pidf " ] && cat " ${cp_pidf} " && echo && return 0
310
308
}
311
309
@@ -315,8 +313,9 @@ startagent_gpg() {
315
313
else
316
314
gpg_started=true
317
315
fi
318
- if gpg_agent_sock=" $( echo " GETINFO socket_name" | gpg-connect-agent --no-autostart 2> /dev/null | head -n1 | sed -n ' s/^D //;1p' ) " && [ -S " $gpg_agent_sock " ]; then
316
+ if gpg_agent_sock=" $( echo " GETINFO socket_name" | gpg-connect-agent --no-autostart | head -n1 | sed -n ' s/^D //;1p' ) " && [ -S " $gpg_agent_sock " ]; then
319
317
mesg " Using existing gpg-agent: ${CYANN} $gpg_agent_sock ${OFF} "
318
+ pidfile_out=" SSH_AUTH_SOCK=\" $gpg_agent_sock \" ; export SSH_AUTH_SOCK" # make sure we adopt it
320
319
else
321
320
gpg_opts=" --daemon"
322
321
[ -n " ${timeout} " ] && gpg_opts=" $gpg_opts --default-cache-ttl $(( timeout * 60 )) --max-cache-ttl $(( timeout * 60 )) "
@@ -352,7 +351,7 @@ ssh_envcheck() {
352
351
353
352
# There are some cases where we can accept a socket without an associated SSH_AGENT_PID:
354
353
355
- if gpg_socket=" $( echo " GETINFO ssh_socket_name" | gpg-connect-agent --no-autostart 2> /dev/null | head -n1 | sed -n ' s/^D //;1p' ) " ; then
354
+ if gpg_socket=" $( echo " GETINFO ssh_socket_name" | gpg-connect-agent --no-autostart 2> /dev/null | head -n1 | sed -n ' s/^D //;1p' ) " ; then
356
355
if [ " $gpg_socket " = " $SSH_AUTH_SOCK " ]; then
357
356
if $ssh_allow_gpg ; then
358
357
mesg " Using ssh-agent ($1 ): ${CYANN} $gpg_socket ${OFF} (GnuPG)" && return 0
@@ -405,6 +404,7 @@ SSH_AGENT_PID=$SSH_AGENT_PID; export SSH_AGENT_PID"
405
404
fi
406
405
fi
407
406
else # spawn, we must...
407
+ rm -f " ${pidf} " " ${cshpidf} " " ${fishpidf} " 2> /dev/null # pidfile is either non-existant or invalid
408
408
if $ssh_spawn_gpg ; then
409
409
startagent_gpg ssh # this function will set pidfile_out itself
410
410
return $?
@@ -589,14 +589,9 @@ $glm_k"
589
589
echo " $glm_missing "
590
590
}
591
591
592
- # synopsis: ssh_listmissing
593
- # Reads stdin for newline-separated list of keyfiles. Returns a newline-separated list of keys found to be missing.
594
592
ssh_listmissing () {
595
593
unset slm_missing
596
- # Update the list of missing keys
597
594
sshavail=$( ssh_l)
598
- # || die "problem running ssh-add -l"
599
-
600
595
while IFS= read -r slm_k; do
601
596
[ -z " $slm_k " ] && continue
602
597
# Fingerprint current user-specified key
@@ -609,8 +604,6 @@ ssh_listmissing() {
609
604
warn " Unable to extract exactly one key fingerprint from keyfile ${slm_k} .pub, got $slm_wordcount instead, skipping"
610
605
continue
611
606
fi
612
-
613
- # Check if it needs to be added
614
607
# shellcheck disable=SC2031
615
608
case " $sshavail " in
616
609
* " $slm_finger " * )
@@ -734,8 +727,6 @@ get_all_extkeys() {
734
727
fi
735
728
}
736
729
737
- # synopsis: setaction
738
- # Sets $myaction or dies if $myaction is already set
739
730
setaction () {
740
731
if [ -n " $myaction " ]; then
741
732
die " you can't specify --$myaction and $1 at the same time"
@@ -1010,29 +1001,30 @@ fi
1010
1001
$noaskopt && { qprint; exit 0; }
1011
1002
$quickopt && { qprint; exit 0; }
1012
1003
1013
- # This is where we load keys as needed:
1014
-
1015
1004
load_ssh_keys () {
1016
1005
missing=" $( echo " ${sshkeys} " | ssh_listmissing) "
1017
1006
savedisplay=" $DISPLAY "
1018
- # --confirm translates to ssh-add -c
1019
1007
if $confirmopt ; then
1020
1008
if $openssh || $sunssh ; then
1021
1009
ssh_confirm=-c
1022
1010
else
1023
1011
warn " --confirm only works with OpenSSH"
1024
1012
fi
1025
1013
fi
1026
- # shellcheck disable=SC2086 # put $missing into args to access $# and other goodies. IFS is set to newline globally:
1014
+ # Put $missing into args to access $# and other goodies. Since $missing is a line-delimited
1015
+ # list of files with (potentially) spaces, we must do an IFS hack to get each file in
1016
+ # $1, $2, $3, etc. For Bourne-shell compatibility, we don't have another good option:
1017
+ IFS_BAK=" $IFS " ; IFS=" $NEWLINE "
1018
+ # shellcheck disable=SC2086
1027
1019
set -- $missing
1020
+ IFS=" $IFS_BAK "
1028
1021
[ $# -eq 0 ] && return
1029
1022
mesg " Adding ${CYANN} $# ${OFF} ssh key(s): ${CYANN} $* ${OFF} "
1030
-
1031
1023
if $noguiopt || [ -z " $SSH_ASKPASS " ] || [ -z " $DISPLAY " ]; then
1032
1024
unset DISPLAY # DISPLAY="" can cause problems
1033
1025
unset SSH_ASKPASS # make sure ssh-add doesn't try SSH_ASKPASS
1034
1026
fi
1035
- # shellcheck disable=SC2086 # this is intentional:
1027
+ # shellcheck disable=SC2086
1036
1028
sshout=$( ssh-add ${ssh_timeout} ${ssh_confirm} " $@ " 2>&1 )
1037
1029
ret=$?
1038
1030
if [ $ret = 0 ]; then
0 commit comments