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