File: rts.tests

package info (click to toggle)
ucspi-tcp-src 0.88-15
  • links: PTS
  • area: non-free
  • in suites: lenny, squeeze
  • size: 1,380 kB
  • ctags: 761
  • sloc: ansic: 6,758; makefile: 854; sh: 312
file content (347 lines) | stat: -rw-r--r-- 12,482 bytes parent folder | download | duplicates (8)
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
# Assumptions:
# We're not running with uid 0 or 1.
# We're not running with gid 0 or 2.
# supervise is installed.
# The DNS cache translates 127.0.0.1<->localhost.
# There is no listener for TCP port 16.
# There is no listener for TCP port 50016.
# There is no use of TCP ports 50017, 50018, 50019, 50020.


rm -rf rts-tmp
mkdir rts-tmp
cd rts-tmp


echo '#!/bin/sh
  trap "" 13
  echo PROTO="$PROTO"
  echo TCPLOCALHOST="${TCPLOCALHOST-unset}"
  echo TCPLOCALIP="${TCPLOCALIP-unset}"
  echo TCPLOCALPORT="${TCPLOCALPORT-unset}"
  echo TCPREMOTEHOST="${TCPREMOTEHOST-unset}"
  echo TCPREMOTEIP="${TCPREMOTEIP-unset}"
  echo TCPREMOTEPORT="${TCPREMOTEPORT-unset}"
  echo TCPREMOTEINFO="${TCPREMOTEINFO-unset}"
' > print
chmod 755 print

mkdir 50016
echo '#!/bin/sh
exec tcpserver \
-c 2 -Bbanner -vo -D -1 -Xx rules.cdb -Rt5 -hp -l Local -b 2 \
127.0.0.1 50016 ../print
' > 50016/run
chmod 755 50016/run

supervise 50016 >log 2>&1 &

echo '--- tcpclient prints usage message without enough arguments'
tcpclient 0 0; echo $?

echo '--- tcpclient prints error message with unknown port name'
tcpclient 0 nonexistentport echo wrong; echo $?

echo '--- tcpclient prints error message when connection fails'
tcpclient 0 016 echo wrong; echo $?

echo '--- tcpclient -q does not print error message when connection fails'
tcpclient -q 0 016 echo wrong; echo $?

echo '--- tcpclient understands empty host name as synonym for 0'
tcpclient '' 016 echo wrong; echo $?

echo '--- tcpclient understands unbracketed IP address'
tcpclient '127.000.000.001' 016 echo wrong; echo $?

echo '--- tcpclient understands bracketed IP address'
tcpclient '[127.000.000.001]' 016 echo wrong; echo $?

echo '--- tcpclient prints error message with unknown host name'
tcpclient nonexistent.local. 016 echo wrong; echo $?

echo '--- tcpclient prints error message with unresolvable host name'
tcpclient thislabelistoolongbecausednshasalimitof63charactersinasinglelabel. 016 echo wrong; echo $?

echo '--- tcpserver prints usage message without enough arguments'
tcpserver 0 0; echo $?

echo '--- tcpserver -u 1 attempts to set uid to 1'
tcpserver -u 1 0 0 echo wrong; echo $?

echo '--- tcpserver -U reads $UID'
env UID=1 tcpserver -U 0 0 echo wrong; echo $?

echo '--- tcpserver -g 2 attempts to set gid to 2'
tcpserver -g 2 0 0 echo wrong; echo $?

echo '--- tcpserver -U reads $GID'
env GID=2 tcpserver -U 0 0 echo wrong; echo $?

echo '--- tcpserver prints error message with unknown port name'
tcpserver 0 nonexistentport echo wrong; echo $?

echo '--- tcpserver prints error message with unknown host name'
tcpserver nonexistent.local. 016 echo wrong; echo $?

echo '--- tcpserver prints error message with unresolvable host name'
tcpserver thislabelistoolongbecausednshasalimitof63charactersinasinglelabel. 016 echo wrong; echo $?

echo '--- tcpserver prints error message with non-local host name'
tcpserver 1.2.3.4 016 echo wrong; echo $?

echo '--- tcpserver sets basic environment variables' 
tcpclient -p 50017 -R -H -T 10 -l Local 0 50016 sh -c 'cat <&6'
echo $?

echo '--- tcpclient recognizes -D, -i, -r, -h, -t'
tcpclient -Di 127.0.0.1 -p 50018 -hrt1 -l Local \
127.0.0.1 50016 sh -c 'cat <&6'
echo $?

echo '--- tcpclient sets basic environment variables' 
tcpclient -p 50019 -R -H -l Local 0 50016 ./print
echo $?

echo '--- tcpclient looks up host names properly'
tcpclient -p 50020 -R 0 50016 ./print
echo $?

echo '--- tcpclient -v works' 
tcpclient -v -R -H -l Local 0 50016 echo ok
echo $?

echo '--- tcpserver prints error message with used port'
tcpserver -R -H -l Local 127.0.0.1 50016 echo wrong
echo $?

echo '--- tcpcat works'
tcpcat 0 50016 | grep -v TCPREMOTEPORT
echo $?

echo '--- mconnect works'
mconnect 0 50016 </dev/null | grep -v TCPREMOTEPORT
echo $?

echo '--- tcprules prints usage message without enough arguments'
tcprules test.cdb; echo $?

echo '--- tcprules prints error message if it cannot create tmp'
echo 1.2.3.4:deny | tcprules test.cdb /dev/nonexistent/tmp; echo $?

echo '--- tcprules prints error message if it cannot move tmp to cdb'
echo 1.2.3.4:deny | tcprules /dev/nonexistent/cdb test.tmp; echo $?

echo '--- tcprules creates a cdb file'
echo 1.2.3.4:deny | tcprules test.cdb test.tmp; echo $?

echo '--- tcprulescheck sees deny'
env TCPREMOTEIP=1.2.3.4 tcprulescheck test.cdb; echo $?

echo '--- tcprulescheck does not apply deny to another host'
env TCPREMOTEIP=1.2.3.5 tcprulescheck test.cdb; echo $?

echo '--- tcprules replaces a cdb file'
echo 'joe@127.0.0.1:allow,which=/first/
18.23.0.32:allow,which="second"
127.:allow,which=+third+
:allow,which==fourth=' | tcprules test.cdb test.tmp; echo $?

echo '--- tcprulescheck finds rule with address and info'
env TCPREMOTEIP=127.0.0.1 TCPREMOTEINFO=joe tcprulescheck test.cdb; echo $?

echo '--- tcprulescheck finds rule with address'
env TCPREMOTEIP=18.23.0.32 TCPREMOTEINFO=joe tcprulescheck test.cdb; echo $?

echo '--- tcprulescheck finds one-dot wildcard'
env TCPREMOTEIP=127.0.0.1 TCPREMOTEINFO=bill tcprulescheck test.cdb; echo $?

echo '--- tcprulescheck finds zero-dot wildcard'
env TCPREMOTEIP=10.119.75.39 TCPREMOTEINFO=bill tcprulescheck test.cdb; echo $?

echo '--- tcprules handles comments, address ranges, multiple variables'
echo '127.0-5.:allow,which=/first/,where=/whatever/
# comment' | tcprules test.cdb test.tmp; echo $?
env TCPREMOTEIP=127.0.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.1.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.2.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.3.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.4.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.5.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.6.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.7.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.8.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.9.0.1 tcprulescheck test.cdb
env TCPREMOTEIP=127.10.0.1 tcprulescheck test.cdb

echo '--- tcprules handles host names'
echo '=known.edu:allow,which=/known/
=.abuser.edu:deny
:allow,which=/anybody/' | tcprules test.cdb test.tmp; echo $?
env TCPREMOTEIP=1.2.3.4 TCPREMOTEHOST=known.edu tcprulescheck test.cdb
env TCPREMOTEIP=1.2.3.4 TCPREMOTEHOST=random.edu tcprulescheck test.cdb
env TCPREMOTEIP=1.2.3.4 TCPREMOTEHOST=abuser.edu tcprulescheck test.cdb
env TCPREMOTEIP=1.2.3.4 TCPREMOTEHOST=x.abuser.edu tcprulescheck test.cdb
env TCPREMOTEIP=1.2.3.4 TCPREMOTEHOST=x.y.abuser.edu tcprulescheck test.cdb

echo '--- tcprulescheck searches for rules in the proper order'
echo 'xyz@86.75.30.9:allow,which=/first/
xyz@=one.two.three:allow,which=/second/
86.75.30.9:allow,which=/third/
=one.two.three:allow,which=/fourth/
86.75.30.:allow,which=/fifth/
86.75.:allow,which=/sixth/
86.:allow,which=/seventh/
=.two.three:allow,which=/eighth/
=.three:allow,which=/ninth/
=:allow,which=/tenth/
:allow,which=/eleventh/
' | tcprules test.cdb test.tmp; echo $?
env TCPREMOTEIP=86.75.30.9 TCPREMOTEHOST=one.two.three TCPREMOTEINFO=xyz tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.9 TCPREMOTEINFO=xyz tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.10 TCPREMOTEHOST=one.two.three TCPREMOTEINFO=xyz tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.9 TCPREMOTEHOST=one.two.three TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.9 TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.9 TCPREMOTEHOST=one.two.three tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.9 tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.10 TCPREMOTEHOST=one.two.three TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.10 TCPREMOTEHOST=one.two.three tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.10 TCPREMOTEHOST=four.two.three tcprulescheck test.cdb
env TCPREMOTEIP=86.75.30.10 tcprulescheck test.cdb
env TCPREMOTEIP=86.75.20.10 TCPREMOTEHOST=four.two.three TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.75.20.10 TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.75.20.10 TCPREMOTEHOST=four.two.three tcprulescheck test.cdb
env TCPREMOTEIP=86.75.20.10 tcprulescheck test.cdb
env TCPREMOTEIP=86.85.20.10 TCPREMOTEHOST=four.two.three TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.85.20.10 TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=86.85.20.10 TCPREMOTEHOST=four.two.three tcprulescheck test.cdb
env TCPREMOTEIP=86.85.20.10 tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEHOST=four.two.three TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEHOST=four.two.three tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEHOST=four.three TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEHOST=four.three tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEHOST=four TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEHOST=four tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 TCPREMOTEINFO=abc tcprulescheck test.cdb
env TCPREMOTEIP=96.85.20.10 tcprulescheck test.cdb


echo '--- addcr leaves an empty file alone'
echo '' | tr -d '\012' | addcr; echo $?

echo '--- addcr leaves a partial final line alone'
echo test | tr -d '\012' | addcr; echo $?

echo '--- addcr adds CR after the first line'
echo test | addcr; echo $?

echo '--- addcr adds CR after the second line'
( echo test; echo test2 ) | addcr; echo $?

echo '--- addcr handles nulls'
echo test | tr e '\0' | addcr; echo $?

echo '--- delcr leaves an empty file alone'
echo '' | tr -d '\012' | delcr; echo $?

echo '--- delcr leaves a non-CR line alone'
echo test | delcr; echo $?

echo '--- delcr removes CR if a line has it'
echo testx | tr x '\015' | delcr; echo $?

echo '--- delcr converts CR CR LF to CR LF'
echo testxx | tr x '\015' | delcr; echo $?

echo '--- delcr does not remove CR from a partial final line'
echo testx | tr -d '\012' | tr x '\015' | delcr; echo $?

echo '--- delcr handles a non-CR partial final line'
echo test | tr -d '\012' | delcr; echo $?

echo '--- delcr handles nulls'
echo test | tr e '\0' | delcr; echo $?

echo '--- fixcrio works'
( echo ''; echo hi; echo therex ) | tr x '\015' \
| fixcrio sh -c 'cat; echo bye' | cat

echo '--- recordio works'
( echo test; sleep 1 ) | recordio cat 2>&1 >/dev/null \
| sed 's/^[0-9]*/.../' | sed 's/$/$/'

echo '--- recordio handles multiple-line packets'
( echo 'test
test2'; sleep 1 ) | recordio cat 2>&1 >/dev/null \
| sed 's/^[0-9]*/.../' | sed 's/$/$/'

echo '--- recordio handles partial final lines'
( echo test | tr -d '\012'; sleep 1 ) | recordio cat 2>&1 >/dev/null \
| sed 's/^[0-9]*/.../' | sed 's/$/$/'

echo '--- argv0 works'
argv0 sh zero -c 'echo $0'; echo $?

echo '--- argv0 requires arguments'
argv0 sh; echo $?


echo '--- rblsmtpd does not find 127.0.0.1 on the RBL'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.1 rblsmtpd echo ok 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd finds 127.0.0.2 on the RBL'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 rblsmtpd echo whoops 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd -b uses a permanent error code'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 rblsmtpd -b echo whoops 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd quits after a timeout'
sleep 2 \
| ( TCPREMOTEIP=127.0.0.2 rblsmtpd -cBt1 echo whoops 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd prints an immediate error message with -t0'
sleep 2 \
| ( TCPREMOTEIP=127.0.0.2 rblsmtpd -Ct0 echo whoops 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd understands an empty $RBLSMTPD'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 RBLSMTPD= rblsmtpd echo ok 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd understands a nonempty $RBLSMTPD'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 RBLSMTPD=Error rblsmtpd echo whoops 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd understands a permanent $RBLSMTPD'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 RBLSMTPD=-Error rblsmtpd echo whoops 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd understands -r'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 rblsmtpd -r nonexistent.local echo ok 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'

echo '--- rblsmtpd understands -a'
( echo help; echo quit ) \
| ( TCPREMOTEIP=127.0.0.2 rblsmtpd -a rbl.maps.vix.com echo ok 2>&1; echo $? ) \
| sed 's/pid [0-9]*/pid x/'


svc -dx 50016
wait

echo '--- tcpserver -1v prints proper messages'
sed -e 's/::.*/::x/' -e 's/ [0-9]* / x /' < log


exit 0