Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / tests / krb5_login.sh
1 #!/bin/bash
2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
3
4 #
5 # krb5_login.sh - obtain and cache Kerberos ticket-granting ticket
6 #
7 ###############################################################################
8
9 #
10 # nothing need for root
11 #
12 [ $UID -eq 0 ] && exit 0
13
14 #
15 # list Kerberos 5 credentials silently
16 # exit status:
17 # 0 - klist finds a credentials cache
18 # 1 - klist does not find a credentials cache or the tickets are expired
19 #
20 klist -5 -s && exit 0
21
22 # get the user name for uid $UID
23 GSS_USER=$(getent passwd $UID | cut -d: -f1)
24
25 GSS_PASS=${GSS_PASS:-"$GSS_USER"}
26
27 echo "***** refresh Kerberos V5 TGT for uid $UID *****"
28 if [ -z "$GSS_PASS" ]; then
29     kinit
30 else
31     expect <<EOF
32 set timeout 30 
33
34 log_user 1 
35
36 set spawnid [spawn /bin/bash]
37 send "export PS1=\"user@host $ \" \r"
38 expect {
39     timeout {puts "timeout" ;exit 1}
40     "user@host $ "
41 }
42
43 send "kinit\r"
44 expect {
45     timeout {puts "timeout" ;exit 1}
46     "Password for "
47 }
48
49 send "$GSS_PASS\r"
50 expect {
51     timeout {puts "timeout" ;exit 1}
52     "user@host $ "
53 }
54
55 exit 0
56 EOF
57 fi
58 ret=$?
59 exit $ret