Skip to content

Commit

Permalink
Revert "code shrinkage"
Browse files Browse the repository at this point in the history
This reverts commit 148cfce.
  • Loading branch information
danielrobbins committed Oct 22, 2009
1 parent c93d927 commit 1fef077
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 47 deletions.
8 changes: 2 additions & 6 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ChangeLog for Keychain; http://www.funtoo.org

#
# Copyright 2002-2006 Gentoo Foundation http://www.gentoo.org/
# Copyright 2007 Aron Griffis <agriffis@n01se.net>
# Copyright 2009-2010 Funtoo Technolgies, LLC.
Expand All @@ -12,11 +12,7 @@
# Maintained and rewritten April 2004 - July 2007 by Aron Griffis <agriffis@n01se.net>
# Maintained July 2009 - present by Daniel Robbins <drobbins@funtoo.org>

* keychain 2.7.0 (18 Oct 2009) ??? Maybe not

18 Oct 2009; Daniel Robbins <drobbins@funtoo.org>: making "inherit all" the
default. Additional code size reduction. Breaking Solaris 9 compatibility
(I'm using "[ -e foo ]")
* keychain 2.7.0 (18 Oct 2009)

18 Oct 2009; Daniel Robbins <drobbins@funtoo.org>: lockfile() replacement
from Parallels Inc. OpenVZ code, takelock() rewrite, resulting in ~100 line
Expand Down
5 changes: 3 additions & 2 deletions keychain.pod
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ agent.

=back

By default, keychain-2.6.10 and later will behave as if "--inherit
all" is specified.
By default, keychain-2.5.0 and later will behave as if "--inherit
local-once" is specified. You should specify "--noinherit" if you
want the older behavior.

=item B<--lockwait> I<seconds>

Expand Down
122 changes: 83 additions & 39 deletions keychain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ quickopt=false
quietopt=false
clearopt=false
color=true
inheritwhich=any
inheritwhich=local-once
unset stopwhich
unset timeout
unset ssh_timeout
Expand Down Expand Up @@ -347,7 +347,8 @@ stopagent() {
# Save agent variables from the environment before they get wiped out
inheritagents() {
# Verify these global vars are null
unset inherit_ssh_auth_sock inherit_ssh_agent_pid inherit_ssh_sockname
unset inherit_ssh_auth_sock inherit_ssh_agent_pid
unset inherit_ssh2_auth_sock inherit_ssh2_agent_sock
unset inherit_gpg_agent_info inherit_gpg_agent_pid

# Save variables so we can inherit a running agent
Expand All @@ -356,14 +357,14 @@ inheritagents() {
if [ -n "$SSH_AUTH_SOCK" ]; then
inherit_ssh_auth_sock="$SSH_AUTH_SOCK"
inherit_ssh_agent_pid="$SSH_AGENT_PID"
ssh_sockname=SSH
fi

if [ -n "$SSH2_AUTH_SOCK" ]; then
inherit_ssh_auth_sock="$SSH2_AUTH_SOCK"
inherit_ssh_agent_pid="$SSH2_AGENT_PID"
ssh_sockname=SSH2
inherit_ssh2_auth_sock="$SSH2_AUTH_SOCK"
inherit_ssh2_agent_pid="$SSH2_AGENT_PID"
fi
fi

if wantagent gpg; then
if [ -n "$GPG_AGENT_INFO" ]; then
inherit_gpg_agent_info="$GPG_AGENT_INFO"
Expand All @@ -376,24 +377,40 @@ inheritagents() {
# synopsis: validinherit
# Test inherit_* variables for validity
validinherit() {
vi_agent="$1"
vi_status=0

# Now incompatible with Solaris 9 thanks to use of -e in conditionals
if [ "$vi_agent" = ssh ]; then
if [ -n "$inherit_ssh_auth_sock" ]; then
ls "$inherit_ssh_auth_sock" >/dev/null 2>&1
if [ $? != 0 ]; then
warn "SSH_AUTH_SOCK in environment is invalid; ignoring it"
unset inherit_ssh_auth_sock inherit_ssh_agent_pid
vi_status=1
fi
fi

if [ "$1" = ssh ]
then
if [ -n "$inherit_ssh_auth_sock" ] && [ ! -e "$inherit_ssh_auth_sock" ]
then
unset inherit_ssh_auth_sock inherit_ssh_agent_pid; fail=1
fi
elif [ "$1" = gpg ]
then
if [ -n "$inherit_gpg_agent_pid" ] && kill -0 "$inherit_gpg_agent_pid" 2>/dev/null
then
unset inherit_gpg_agent_pid inherit_gpg_agent_info; fail=1
fi
if [ -n "$inherit_ssh2_auth_sock" ]; then
ls "$inherit_ssh2_auth_sock" >/dev/null 2>&1
if [ $? != 0 ]; then
warn "SSH2_AUTH_SOCK in environment is invalid; ignoring it"
unset inherit_ssh2_auth_sock inherit_ssh2_agent_pid
vi_status=1
fi
fi
[ "$fail" = "1" ] && warn "$fail environment variables invalid; ignoring" && return 1
return 0

elif [ "$vi_agent" = gpg ]; then
if [ -n "$inherit_gpg_agent_pid" ]; then
kill -0 "$inherit_gpg_agent_pid" >/dev/null 2>&1
if [ $? != 0 ]; then
unset inherit_gpg_agent_pid inherit_gpg_agent_info
warn "GPG_AGENT_INFO in environment is invalid; ignoring it"
vi_status=1
fi
fi
fi

return $vi_status
}

# synopsis: catpidf_shell shell agents...
Expand Down Expand Up @@ -483,11 +500,14 @@ startagent() {
start_cshpidf="$cshpidf"
start_fishpidf="$fishpidf"
start_pid="$ssh_agent_pid"
if [ -n "$inherit_ssh_auth_sock" -a -n "$inherit_ssh_agent_pid" ]
then
start_inherit_pid="$inherit_ssh_agent_pid"
else
if [ -n "$inherit_ssh_auth_sock" -o -n "$inherit_ssh2_auth_sock" ]; then
if [ -n "$inherit_ssh_agent_pid" ]; then
start_inherit_pid="$inherit_ssh_agent_pid"
elif [ -n "$inherit_ssh2_agent_pid" ]; then
start_inherit_pid="$inherit_ssh2_agent_pid"
else
start_inherit_pid="forwarded"
fi
fi
else
start_pidf="${pidf}-$start_prog"
Expand Down Expand Up @@ -591,10 +611,19 @@ startagent() {
fi

elif [ "$start_prog" = ssh -a -n "$inherit_ssh_auth_sock" ]; then
start_out="${ssh_sockname}_AUTH_SOCK=$inherit_ssh_auth_sock; export ${ssh_sockname}_AUTH_SOCK;"
start_out="SSH_AUTH_SOCK=$inherit_ssh_auth_sock; export SSH_AUTH_SOCK;"
if [ "$inherit_ssh_agent_pid" -gt 0 ] 2>/dev/null; then
start_out="$start_out ${ssh_sockname}_AGENT_PID=$inherit_ssh_agent_pid; export ${ssh_sockname}_AGENT_PID;"
start_out="$start_out
SSH_AGENT_PID=$inherit_ssh_agent_pid; export SSH_AGENT_PID;"
fi
elif [ "$start_prog" = ssh -a -n "$inherit_ssh2_auth_sock" ]; then
start_out="SSH2_AUTH_SOCK=$inherit_ssh2_auth_sock; export SSH2_AUTH_SOCK;
SSH2_AGENT_PID=$inherit_ssh2_agent_pid; export SSH2_AGENT_PID;"
if [ "$inherit_ssh2_agent_pid" -gt 0 ] 2>/dev/null; then
start_out="$start_out
SSH2_AGENT_PID=$inherit_ssh2_agent_pid; export SSH2_AGENT_PID;"
fi

elif [ "$start_prog" = gpg -a -n "$inherit_gpg_agent_info" ]; then
start_out="GPG_AGENT_INFO=$inherit_gpg_agent_info; export GPG_AGENT_INFO;"

Expand Down Expand Up @@ -893,16 +922,31 @@ in_path() {

return 1
}

detect_agents() {
local realopt=""
for a in ${agentsopt:=ssh gpg}; do
in_path ${a}-agent >/dev/null && realopt="${realopt} ${a}" && continue
done
if [ -z "$realopt" ]; then
die "no agents available to start"
fi
agentsopt="$realopt"

# synopsis: setagents
# Check validity of agentsopt
setagents() {
if [ -n "$agentsopt" ]; then
agentsopt=`echo "$agentsopt" | sed 's/,/ /g'`
unset new_agentsopt
for a in $agentsopt; do
if in_path ${a}-agent >/dev/null; then
new_agentsopt="${new_agentsopt+$new_agentsopt }${a}"
else
warn "can't find ${a}-agent, removing from list"
fi
done
agentsopt="${new_agentsopt}"
else
for a in ssh gpg; do
in_path ${a}-agent >/dev/null || continue
agentsopt="${agentsopt+$agentsopt }${a}"
done
fi

if [ -z "$agentsopt" ]; then
die "no agents available to start"
fi
}

# synopsis: wantagent prog
Expand Down Expand Up @@ -946,7 +990,7 @@ while [ -n "$1" ]; do
;;
--agents)
shift
detect_agents `echo $1 | sed 's/,/ /g'`
agentsopt="$1"
;;
--attempts)
shift
Expand Down Expand Up @@ -1114,7 +1158,7 @@ else
trap 'droplock; exit 0' 0 # drop the lock on exit
fi

[ -z "$agentsopt" ] && detect_agents
setagents # verify/set $agentsopt
verifykeydir # sets up $keydir
wantagent ssh && testssh # sets $openssh and $sunssh
getuser # sets $me
Expand Down

0 comments on commit 1fef077

Please sign in to comment.