summaryrefslogtreecommitdiff
path: root/keyutils-1.5.6/tests/keyctl/link/valid/runtest.sh
blob: 242a495a9720c64355c27d9af34381f798115e52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh

. ../../../prepare.inc.sh
. ../../../toolbox.inc.sh


# ---- do the actual testing ----

result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE

# create a keyring and attach it to the session keyring
marker "ADD KEYRING"
create_keyring wibble @s
expect_keyid keyringid

# validate the new keyring's name and type
marker "VALIDATE KEYRING"
describe_key $keyringid
expect_key_rdesc rdesc 'keyring@.*@wibble'

# check that we can list it
marker "LIST KEYRING"
list_keyring $keyringid
expect_keyring_rlist rlist empty

# stick a key in the keyring
marker "ADD KEY"
create_key user lizard gizzard $keyringid
expect_keyid keyid

# check that we can list it
marker "LIST KEYRING WITH ONE"
list_keyring $keyringid
expect_keyring_rlist rlist $keyid

# link the key across to the session keyring
marker "LINK KEY 1"
link_key $keyid @s

marker "CHECK KEY LINKAGE"
list_keyring @s
expect_keyring_rlist srlist $keyid

# link the key across to the session keyring again and again
marker "LINK KEY 2"
link_key $keyid @s

marker "LINK KEY 3"
link_key $keyid @s

# subsequent links should displace earlier links, giving us a maximum of 1 link
marker "COUNT LINKS"
list_keyring @s
expect_keyring_rlist srlist

nlinks=0
for i in $srlist
  do
  if [ "x$i" = "x$keyid" ]
  then
      nlinks=$(($nlinks + 1))
  fi
done

if [ $nlinks != 1 ]
then
    failed
fi

# remove the links
marker "UNLINK KEY FROM SESSION"
unlink_key $keyid @s

# removing again should fail
unlink_key --fail $keyid @s
expect_error ENOENT

# remove that key from the keyring (the key should be destroyed)
marker "UNLINK KEY FROM KEYRING"
unlink_key --wait $keyid $keyringid

# and a second time should fail, but now the key doesn't exist
unlink_key --fail $keyid $keyringid
expect_error ENOKEY

# create a second keyring in the first
create_keyring "zebra" $keyringid
expect_keyid keyring2id

# link thrice across to the session keyring
marker "LINK 2ND KEYRING TO SESSION"
link_key $keyring2id @s
link_key $keyring2id @s
link_key $keyring2id @s

# subsequent links should displace earlier links, giving us a maximum of 1 link
marker "COUNT KEYRING LINKS"
list_keyring @s
expect_keyring_rlist srlist

nlinks=0
for i in $srlist
  do
  if [ "x$i" = "x$keyring2id" ]
  then
      nlinks=$(($nlinks + 1))
  fi
done

if [ $nlinks != 1 ]
then
    failed
fi

# remove the keyring links
marker "UNLINK 2ND KEYRING FROM SESSION"
unlink_key $keyring2id @s

# removing again should fail
unlink_key --fail $keyring2id @s
expect_error ENOENT

# make another keyring link
marker "LINK 2ND KEYRING TO SESSION"
link_key $keyring2id @s

# remove the first keyring we added
marker "UNLINK KEYRING"
unlink_key --wait $keyringid @s

# remove the second keyring we added
marker "UNLINK 2ND KEYRING"
unlink_key --wait $keyring2id @s

echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE

# --- then report the results in the database ---
toolbox_report_result $TEST $result