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