a0fdd521d38e8d7ded3591d17b8672f1fbc73e69
[profile.git] / .profile.d / krb5.bashrc
1 # $Id$
2 alias kssh='ssh -o preferredauthentications=gssapi-with-mic'
3 alias pssh='ssh -o preferredauthentications=password,keyboard-interactive'
4
5 if [ $UID -gt 0 -a -z "$OLDSOLARIS" -a -z "$OLDREDHAT" ]; then
6   if tty -s; then
7     if klist -s 2>/dev/null; then
8       # We already have a ticket cache.  Renew it.
9       kinit -R &>/dev/null
10     else
11       # Try to find an existing cache but only if we are using FILE: caches.
12       default=$((unset KRB5CCNAME; klist 2>&1) | sed -n 's/.*FILE:\([^)]*\).*/\1/p')
13       if [ ! -z "$default" ]; then
14         # Check for bogus FILE: KRB5CCNAME.
15         if [ ! -z "$KRB5CCNAME" -a "${KRB5CCNAME##*:}" = "$KRB5CCNAME" ]; then 
16           export KRB5CCNAME="FILE:$KRB5CCNAME"
17         fi
18
19         # Find the file.
20         ccname="${KRB5CCNAME##FILE:}"
21         if [ "$ccname" = "$KRB5CCNAME" ]; then
22           # Our cache isn't a file cache.  Throw it away.
23           ccname="$default"
24           unset KRB5CCNAME
25         fi
26
27         # Remember if nullglob was on.
28         shopt -q nullglob
29         ng=$?
30         # Turn it on so we can look for caches safely.
31         shopt -s nullglob
32
33         for cache in $default*; do
34           if klist -s -c "$cache"; then
35             if [ ! "$cache" = "$ccname" ]; then
36               # It may not be safe to simply point the environment to this 
37               # cache as it may belong to a session which is about to end.  
38               # Therefore we copy it.
39               cp -p "$cache" "$ccname" || continue
40             fi
41             kinit -R &>/dev/null
42             break
43           fi
44         done
45
46         # Maybe turn nocaseglob back off.
47         [ $ng = 0 ] || shopt -u nullglob
48       fi
49     fi
50
51     # By now we should have found a cache if there's one to find.
52     klist -s 2>/dev/null || kinit
53   fi
54 fi
55
56 unset cache ccname default ng