f6b5216fb95f3f03c0aad49b583945dbb778c568
[snippets/.git] / kerberos / kdo / bashrc
1 function kfindcache {
2         klist -A | grep -A1 'Kerberos 5 ticket cache' | grep -iB1 "principal: .*$1" | head -n 1 | cut -f 2 -d "'"
3 }
4
5 function kdo {
6         local princ="$1"
7         shift;
8         local kinit_args="-l15m -r60m -F"
9         local cache=`kfindcache "$princ"`
10         if [ -n "$cache" ] && ! (KRB5CCNAME="$cache" klist -s "$cache"); then
11                 KRB5CCNAME="$cache" kdestroy
12                 cache=""
13         fi
14         if [ -z "$cache" ]; then
15                 local oldcache=`klist | grep 'Kerberos 5 ticket cache' | cut -f 2 -d "'"`
16                 kinit $kinit_args "$princ" || return 1
17                 cache=`kfindcache "$princ"`
18                 kswitch -c "$oldcache"
19         fi
20         echo "Running $1 with cache $cache (for principal $princ)" >&2
21         KRB5CCNAME="$cache" "$@"
22 }
23
24 function krootssh {
25         kdo ${ATHENA_USER:-$USER}}/root@ATHENA.MIT.EDU ssh -o "GSSAPIDelegateCredentials no" "$@"
26 }