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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
#! /bin/sh
# PCP QA Test No. 083
# Test pmlogger access control stuff and pmlc
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"
. ./common.product
. ./common.check
. ./common.filter
. ./localconfig
trap "rm -rf $tmp $tmp.*; exit" 0 1 2 3 15
# real QA test starts here
echo "this tests access control for pmlogger and exercises pmlc"
# Remember that we cd into $tmp
#
here=`pwd`
signal=$PCP_BINADM_DIR/pmsignal
tmp=/var/tmp/qa083.$$
config=$tmp/pmlogger.conf
log=$tmp/pmlogger.log
me=`_get_fqdn`
shortme=`hostname`
errors=$tmp/errors.pmlc
echo "me=$me" >$here/$seq.full
echo "shortme=$shortme" >>$here/$seq.full
_filter()
{
# for Linux sometimes see "Connection reset by peer" ... this is believed
# to be a timing issue, and the results are semantically equivalent for
# the purposes of this test, so ...
# and the "receiving response from pmlogger" part of the no permission
# error message may not be there for older pmlc versions, so ...
#
tee -a $here/$seq.full \
| sed -e "s/$me/ME/" \
-e "s/local:/ME/" \
-e "s/$shortme/ME/" \
-e "s/$other1/OTHER1/" \
-e "s/$other2/OTHER2/" \
-e 's/Connection reset by peer/Address already in use/' \
-e '/No permission to perform/s/ receiving response from pmlogger//'
}
# Wait for appearance ($1 is true) or disappearance ($1 is false) of primary
# pmlogger
#
_await_logger()
{
for i in 1 2 3 4 5
do
if $PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep '[p]mlogger.*-P' | grep -v sudo >/dev/null
then
# if it's there and we're waiting for it, break
$1 && break
else
# if it's not there and we're waiting for it to disappear, break
$1 || break
fi
sleep 2
done
logger_pid=`$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep '[p]mlogger.*-P' | grep -v sudo | $PCP_AWK_PROG '{ print $2 }'`
if [ ! -z "$logger_pid" ]
then
# it's alive...
if $1
then
echo "primary pmlogger alive"
else
# ...but meant to die
echo
echo "primary pmlogger won't die, can't do QA test, ...giving up!"
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | egrep '[p]m|[P]PID'
exit 1
fi
else
# it's not alive...
if $1
then
# ...but should be
echo
echo "primary pmlogger won't start, can't do QA test, ...giving up!"
echo "pmlogger log file:"
cat $log
echo "pmlogger sh log:"
cat $tmp/sh.log
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | egrep '[p]m|[P]PID'
exit 1
else
echo "primary pmlogger terminated"
fi
fi
}
interrupt()
{
echo "Interrupted"
exit
}
cleanup()
{
cd $here
rm -rf $tmp $tmp.*
echo "Restarting pmcd and friends..."
$sudo $PCP_RC_DIR/pcp restart | _filter_pcp_start
_wait_for_pmcd
_wait_for_pmlogger
}
trap interrupt 1 2 3 15
trap cleanup 0
# real QA test starts here
echo
echo "Running the access tests"
# ideally want a host with only 1 network interface ... getpmcdhosts
# cannot express this, so we used to go for 1 CPU as a likely co-condition,
# but even that has been dropped now that single CPU systems are so
# rare
#
eval `./getpmcdhosts -L -n2 -v 'pcp>=2' | sed -e 's/^/other1=/' -e 's/ / other2=/'`
if [ -z "$other1" ]
then
echo "Cannot find first remote host running pmcd v2.x" >$seq.notrun
status=1
exit
fi
if [ -z "$other2" ]
then
echo "Cannot find second remote host running pmcd v2.x" >$seq.notrun
status=1
exit
fi
echo "other1=$other1" >>$here/$seq.full
echo "other2=$other2" >>$here/$seq.full
# kill off any existing primary pmlogger
#
$sudo $signal -a -s TERM pmlogger
_await_logger false
if mkdir $tmp
then
cd $tmp
# since we now run pmlogger as user/group pcp/pcp when -P is
# specified, need to make this directory writeable
#
chmod 777 .
else
echo "Unable to create working directory $tmp, ...giving up!"
exit 1
fi
cat >$config <<End-Of-File
# test various "all" commands
log mandatory on 1 hour {
kernel.all.load [ "1 minute" ]
}
log mandatory maybe sample.bin["bin-100","bin-200","bin-300","bin-400"]
log mandatory off sample.bin["bin-600","bin-700","bin-800","bin-900"]
[access]
allow $other1 : all except mandatory;
disallow $other2 : all;
allow $me : all;
allow localhost : all;
End-Of-File
echo >>$here/$seq.full
cat $config >>$here/$seq.full
echo "starting test pmlogger..."
#
# extra parentheses and I/O redirection so that shell doesn't print pid
#
( sh -c "$sudo $PCP_BINADM_DIR/pmlogger -P -c $config -l $log TEST" >$tmp/sh.log 2>&1 & ) >/dev/null 2>&1
_await_logger true
_wait_for_pmlogger $logger_pid $log
# Check connect and enquire access
echo | tee -a $here/$seq.full
echo "================" | tee -a $here/$seq.full
echo "checking enquire access for this host..." | tee -a $here/$seq.full
pmlc -P <<End-Of-File 2>$errors \
| _filter
query kernel.all.load[1,5,15]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $here/$seq.full
_filter < $errors
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | egrep '[p]m|[P]PID'
exit 1
fi
echo | tee -a $here/$seq.full
echo "================" | tee -a $here/$seq.full
echo "checking enquire access for other1..." | tee -a $here/$seq.full
ssh -q pcpqa@$other1 "sh -c 'PMCD_CONNECT_TIMEOUT=60 PMCD_REQUEST_TIMEOUT=60 pmlc -h $me -P'" <<End-Of-File 2>$errors \
| _filter
query kernel.all.load[1,5,15]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $here/$seq.full
_filter < $errors
echo FAILED ... sleeping
sleep 300
exit 1
fi
echo | tee -a $here/$seq.full
echo "================" | tee -a $here/$seq.full
echo "checking enquire access for other2 (should fail)..." | tee -a $here/$seq.full
ssh -q pcpqa@$other2 "sh -c 'PMCD_CONNECT_TIMEOUT=60 PMCD_REQUEST_TIMEOUT=60 pmlc -h $me -P'" <<End-Of-File 2>$errors \
| _filter
query kernel.all.load[1,5,15]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $here/$seq.full
_filter < $errors
fi
echo | tee -a $here/$seq.full
echo "================" | tee -a $here/$seq.full
echo "re-checking enquire access for this host..." | tee -a $here/$seq.full
pmlc -P <<End-Of-File 2>$errors \
| _filter
query kernel.all.load[1,5,15]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $here/$seq.full
_filter < $errors
exit 1
fi
# Now check advisory access using sample.bin
cat >$config <<End-Of-File
# test various explicit access commands
log mandatory maybe sample.bin["bin-100","bin-200","bin-300"]
log mandatory off sample.bin["bin-700","bin-800","bin-900"]
[access]
allow $me : enquire, advisory, mandatory;
allow localhost : enquire, advisory, mandatory;
allow $other1 : enquire, advisory;
allow $other2 : enquire;
disallow *: all;
End-Of-File
echo >>$here/$seq.full
cat $config >>$here/$seq.full
echo "killing pmlogger used for enquire tests..."
$sudo $signal -a -s TERM pmlogger
_await_logger false
echo
echo "starting new pmlogger for advisory & mandatory tests..."
#
# extra parentheses and I/O redirection so that shell doesn't print pid
#
( sh -c "$sudo $PCP_BINADM_DIR/pmlogger -P -c $config -l $log TEST2" >$tmp/sh.log 2>&1 & ) >/dev/null 2>&1
_await_logger true
_wait_for_pmlogger $logger_pid $log
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking advisory access for this host..." | tee -a $seq.full
echo "(100,400 will change, 700 will not)" | tee -a $seq.full
pmlc -P <<End-Of-File 2>$errors \
| _filter
query sample.bin[100,200,300,400,500,600,700,800,900]
advisory on 1 hour sample.bin[100]
advisory on 2 hour sample.bin[400]
advisory on 3 hour sample.bin[700]
query sample.bin[100,200,300,400,500,600,700,800,900]
quit
End-Of-File
if [ -s $errors ]
then
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep pmlc
cat $log
echo Errors: | tee -a $seq.full
_filter < $errors
echo "pmlogger sh log:"
cat $tmp/sh.log
exit 1
fi
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking advisory access for other1..." | tee -a $seq.full
echo "(200,500 will change, 800 will not)" | tee -a $seq.full
ssh -q pcpqa@$other1 "sh -c 'PMCD_CONNECT_TIMEOUT=60 PMCD_REQUEST_TIMEOUT=60 pmlc -h $me -P'" <<End-Of-File 2>$errors \
| _filter
query sample.bin[100,200,300,400,500,600,700,800,900]
advisory on 1 hour sample.bin[200]
advisory on 2 hour sample.bin[500]
advisory on 3 hour sample.bin[800]
query sample.bin[100,200,300,400,500,600,700,800,900]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $seq.full
_filter < $errors
fi
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking advisory access for other2..." | tee -a $seq.full
echo "(expect 3 permission errors)" | tee -a $seq.full
ssh -q pcpqa@$other2 "sh -c 'PMCD_CONNECT_TIMEOUT=60 PMCD_REQUEST_TIMEOUT=60 pmlc -h $me -P'" <<End-Of-File 2>$errors \
| _filter
query sample.bin[100,200,300,400,500,600,700,800,900]
advisory on 1 hour sample.bin[300]
advisory on 2 hour sample.bin[600]
advisory on 3 hour sample.bin[900]
query sample.bin[100,200,300,400,500,600,700,800,900]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $seq.full
_filter < $errors
fi
# Now check mandatory access using sample.bin (same config file as for advisory
# access)
echo "killing pmlogger used for advisory tests..."
$sudo $signal -a -s TERM pmlogger
_await_logger false
echo
echo "starting new pmlogger for mandatory tests..."
#
# extra parentheses and I/O redirection so that shell doesn't print pid
#
( sh -c "$sudo $PCP_BINADM_DIR/pmlogger -P -c $config -l $log TEST3" >$tmp/sh.log 2>&1 & ) >/dev/null 2>&1
_await_logger true
_wait_for_pmlogger $logger_pid $log
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking mandatory access for this host..." | tee -a $seq.full
echo "(100,400,700 will change)" | tee -a $seq.full
pmlc -P <<End-Of-File 2>$errors \
| _filter
query sample.bin[100,200,300,400,500,600,700,800,900]
mandatory on 3 hour sample.bin[100]
mandatory on 4 hour sample.bin[400]
mandatory on 5 hour sample.bin[700]
query sample.bin[100,200,300,400,500,600,700,800,900]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $seq.full
_filter < $errors
fi
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking mandatory access for other1..." | tee -a $seq.full
echo "Expect 3 permission errors" | tee -a $seq.full
ssh -q pcpqa@$other1 "sh -c 'PMCD_CONNECT_TIMEOUT=60 PMCD_REQUEST_TIMEOUT=60 pmlc -h $me -P'" <<End-Of-File 2>$errors \
| _filter
query sample.bin[100,200,300,400,500,600,700,800,900]
mandatory on 3 hour sample.bin[200]
mandatory on 4 hour sample.bin[500]
mandatory on 5 hour sample.bin[800]
query sample.bin[100,200,300,400,500,600,700,800,900]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $seq.full
_filter < $errors
fi
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking mandatory access for other2..." | tee -a $seq.full
echo "Expect 3 permission errors" | tee -a $seq.full
ssh -q pcpqa@$other2 "sh -c 'PMCD_CONNECT_TIMEOUT=60 PMCD_REQUEST_TIMEOUT=60 pmlc -h $me -P'" <<End-Of-File 2>$errors \
| _filter
query sample.bin[100,200,300,400,500,600,700,800,900]
mandatory on 3 hour sample.bin[300]
mandatory on 4 hour sample.bin[600]
mandatory on 5 hour sample.bin[900]
query sample.bin[100,200,300,400,500,600,700,800,900]
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $seq.full
_filter < $errors
fi
# Check that each pmlogger only accepts one pmlc connection at a time
echo | tee -a $seq.full
echo "================" | tee -a $seq.full
echo "checking 2nd pmlc for pmlogger (should fail)..." | tee -a $seq.full
( ( sleep 5 | pmlc -P ) & ) >/dev/null 2>&1
sleep 3
pmlc -P <<End-Of-File 2>$errors \
| _filter
quit
End-Of-File
if [ -s $errors ]
then
echo Errors: | tee -a $seq.full
_filter < $errors
fi
wait
|