forked from erluko/socat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·12360 lines (11691 loc) · 374 KB
/
test.sh
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/bash
# source: test.sh
# Copyright Gerhard Rieger
# Published under the GNU General Public License V.2, see file COPYING
# perform lots of tests on socat
# this script uses functions; you need a shell that supports them
# you can pass general options to socat: export OPTS="-d -d -d -d -lu"
# you can eg strace socat with: export TRACE="strace -v -tt -ff -D -x -s 1024 -o /tmp/$USER/socat.strace"
#set -vx
val_t=0.1
NUMCOND=true
#NUMCOND="test \$N -gt 70"
while [ "$1" ]; do
case "X$1" in
X-t?*) val_t="${1#-t}" ;;
X-t) shift; val_t="$1" ;;
X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
X-n) shift; NUMCOND="test \$N -eq $1" ;;
X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
X-N) shift; NUMCOND="test \$N -ge $1" ;;
*) break;
esac
shift
done
opt_t="-t $val_t"
#MICROS=100000
case "X$val_t" in
X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
X*) S="${val_t}"; uS="000000" ;;
esac
MICROS=${S}${uS}
MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
#
_MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
[ -z "$SECONDs" ] && SECONDs=0
withroot=0 # perform privileged tests even if not run by root
#PATH=$PATH:/opt/freeware/bin
#PATH=$PATH:/usr/local/ssl/bin
case "$0" in
*/*) PATH="${0%/*}:$PATH"
esac
#OPENSSL_RAND="-rand /dev/egd-pool"
#SOCAT_EGD="egd=/dev/egd-pool"
MISCDELAY=1
[ -z "$SOCAT" ] && SOCAT="./socat"
if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
echo "$SOCAT does not exist" >&2; exit 1;
fi
[ -z "$PROCAN" ] && PROCAN="./procan"
[ -z "$FILAN" ] && FILAN="./filan"
opts="$opt_t $OPTS"
export SOCAT_OPTS="$opts"
#debug="1"
debug=
TESTS="$@"; export TESTS
# for some tests we need a network interface
if type ip >/dev/null 2>&1; then
INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
else
INTERFACE=eth0
fi
MCINTERFACE=lo # !!! Linux only
#LOCALHOST=192.168.58.1
LOCALHOST=localhost
#LOCALHOST=127.0.0.1
LOCALHOST6=[::1]
#PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
#PROTO=$(($PROTO+1))
PROTO=$((144+RANDOM/2048))
PORT=12002
SOURCEPORT=2002
# SSL certificate contents
TESTCERT_CONF=testcert.conf
TESTCERT6_CONF=testcert6.conf
#
TESTCERT_COMMONNAME="$LOCALHOST"
TESTCERT_COMMONNAME6="$LOCALHOST6"
TESTCERT_COUNTRYNAME="XY"
TESTCERT_LOCALITYNAME="Lunar Base"
TESTCERT_ORGANIZATIONALUNITNAME="socat"
TESTCERT_ORGANIZATIONNAME="dest-unreach"
TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
cat >$TESTCERT_CONF <<EOF
prompt=no
[ req ]
default_bits = 768
distinguished_name=Test
[ Test ]
countryName=$TESTCERT_COUNTRYNAME
commonName=$TESTCERT_COMMONNAME
O=$TESTCERT_ORGANIZATIONNAME
OU=$TESTCERT_ORGANIZATIONALUNITNAME
L=$TESTCERT_LOCALITYNAME
EOF
cat >$TESTCERT6_CONF <<EOF
prompt=no
[ req ]
default_bits = 768
distinguished_name=Test
[ Test ]
countryName=$TESTCERT_COUNTRYNAME
commonName=$TESTCERT_COMMONNAME6
O=$TESTCERT_ORGANIZATIONNAME
OU=$TESTCERT_ORGANIZATIONALUNITNAME
L=$TESTCERT_LOCALITYNAME
EOF
# clean up from previous runs
rm -f testcli.{crt,key,pem}
rm -f testsrv.{crt,key,pem}
rm -f testcli6.{crt,key,pem}
rm -f testsrv6.{crt,key,pem}
CAT=cat
OD_C="od -c"
# precision sleep; takes seconds with fractional part
psleep () {
local T="$1"
[ "$T" = 0 ] && T=0.000002
$SOCAT -T "$T" pipe pipe
}
# time in microseconds to wait in some situations
if ! type usleep >/dev/null 2>&1; then
usleep () {
local n="$1"
case "$n" in
*???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
*) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
esac
$SOCAT -T $S.$uS pipe pipe
}
fi
#USLEEP=usleep
F_n="%3d" # format string for test numbers
LC_ALL=C # for timestamps format...
LANG=C
LANGUAGE=C # knoppix
UNAME=`uname`
case "$UNAME" in
HP-UX|OSF1)
echo "$SOCAT -u stdin stdout" >cat.sh
chmod a+x cat.sh
CAT=./cat.sh
;;
SunOS)
# /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
# /usr/xpg4/bin/tr instead
alias tr=/usr/xpg4/bin/tr
;;
*)
CAT=cat
;;
esac
case "$UNAME" in
#HP-UX)
# # on HP-UX, the default options (below) hang some tests (former 14, 15)
# PTYOPTS=
# PTYOPTS2=
# ;;
*)
PTYOPTS="echo=0,opost=0"
#PTYOPTS2="raw,echo=0"
PTYOPTS2="cfmakeraw"
#PTYOPTS2="rawer"
;;
esac
# for some tests we need an unprivileged user id to su to
if [ "$SUDO_USER" ]; then
SUBSTUSER="$SUDO_USER"
else
SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
fi
# non-root users might miss ifconfig in their path
case "$UNAME" in
AIX) IFCONFIG=/usr/sbin/ifconfig ;;
FreeBSD) IFCONFIG=/sbin/ifconfig ;;
HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
Linux) IFCONFIG=/sbin/ifconfig ;;
NetBSD)IFCONFIG=/sbin/ifconfig ;;
OpenBSD)IFCONFIG=/sbin/ifconfig ;;
OSF1) IFCONFIG=/sbin/ifconfig ;;
SunOS) IFCONFIG=/sbin/ifconfig ;;
Darwin)IFCONFIG=/sbin/ifconfig ;;
DragonFly) IFCONFIG=/sbin/ifconfig ;;
*) IFCONFIG=/sbin/ifconfig ;;
esac
# need output like "644"
case "$UNAME" in
Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
*) fileperms() {
local p s=0 c
p="$(ls -l -L "$1" |awk '{print($1);}')"
p="${p:1:9}"
while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
printf "%03o\n" $s;
} ;;
esac
# need user (owner) of filesystem entry
case "$UNAME" in
Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
*) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
esac
# for some tests we need a second local IPv4 address
case "$UNAME" in
Linux)
BROADCASTIF=$(ip r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
[ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
SECONDADDR=127.1.0.1
SECONDMASK=255.255.0.0
BCADDR=127.255.255.255
BCIFADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}' |cut -d: -f2) ;;
FreeBSD|NetBSD|OpenBSD)
MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
BROADCASTIF="$MAINIF"
SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
BCIFADDR="$SECONDADDR"
BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
HP-UX)
MAINIF=lan0 # might use "netstat -ni" for this
BROADCASTIF="$MAINIF"
SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
SunOS)
MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
BROADCASTIF="$MAINIF"
#BROADCASTIF=hme0
#BROADCASTIF=eri0
#SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
#BCIFADDR="$SECONDADDR"
#BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
;;
DragonFly)
MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
BROADCASTIF="$MAINIF"
SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
BCIFADDR="$SECONDADDR"
BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
#AIX|FreeBSD|Solaris)
*)
SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
;;
esac
# for generic sockets we need this address in hex form
if [ "$SECONDADDR" ]; then
SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' '
'))"
fi
# for some tests we need a second local IPv6 address
case "$UNAME" in
*)
SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
;;
esac
if [ -z "$SECONDIP6ADDR" ]; then
# case "$TESTS" in
# *%root2%*) $IFCONFIG eth0 ::2/128
# esac
SECONDIP6ADDR="$LOCALHOST6"
else
SECONDIP6ADDR="[$SECONDIP6ADDR]"
fi
TRUE=$(which true)
#E=-e # Linux
if [ $(echo "x\c") = "x" ]; then E=""
elif [ $(echo -e "x\c") = "x" ]; then E="-e"
else
echo "cannot suppress trailing newline on echo" >&2
exit 1
fi
ECHO="echo $E"
PRINTF="printf"
case "$TERM" in
vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color)
# there are different behaviours of printf (and echo)
# on some systems, echo behaves different than printf...
if [ $($PRINTF "\0101") = "A" ]; then
RED="\0033[31m"
GREEN="\0033[32m"
YELLOW="\0033[33m"
# if [ "$UNAME" = SunOS ]; then
# NORMAL="\0033[30m"
# else
NORMAL="\0033[39m"
# fi
else
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
# if [ "$UNAME" = SunOS ]; then
# NORMAL="\033[30m"
# else
NORMAL="\033[39m"
# fi
fi
OK="${GREEN}OK${NORMAL}"
FAILED="${RED}FAILED${NORMAL}"
NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
;;
*) OK="OK"
FAILED="FAILED"
NO_RESULT="NO RESULT"
;;
esac
if [ -x /usr/xpg4/bin/id ]; then
# SunOS has rather useless tools in its default path
PATH="/usr/xpg4/bin:$PATH"
fi
[ -z "$TESTS" ] && TESTS="consistency functions filan"
# use '%' as separation char
TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
[ -z "$USER" ] && USER="$LOGNAME" # HP-UX
if [ -z "$TMPDIR" ]; then
if [ -z "$TMP" ]; then
TMP=/tmp
fi
TMPDIR="$TMP"
fi
TD="$TMPDIR/$USER/$$"; td="$TD"
rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
mkdir -p "$TD"
#trap "rm -r $TD" 0 3
echo "using temp directory $TD"
case "$TESTS" in
*%consistency%*)
# test if addresses are sorted alphabetically:
$ECHO "testing if address array is sorted...\c"
TF="$TD/socat-q"
IFS="$($ECHO ' \n\t')"
$SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
$SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done |LC_ALL=C sort |diff "$TF" - >"$TF-diff"
if [ -s "$TF-diff" ]; then
$ECHO "\n*** address array is not sorted. Wrong entries:" >&2
cat "$TD/socat-q-diff" >&2
exit 1
else
echo " ok"
fi
#/bin/rm "$TF"
#/bin/rm "$TF-diff"
esac
case "$TESTS" in
*%consistency%*)
# test if address options array ("optionnames") is sorted alphabetically:
$ECHO "testing if address options are sorted...\c"
TF="$TD/socat-qq"
$SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
if [ -s "$TF-diff" ]; then
$ECHO "\n*** option array is not sorted. Wrong entries:" >&2
cat "$TD/socat-qq-diff" >&2
exit 1
else
echo " ok"
fi
/bin/rm "$TF"
/bin/rm "$TF-diff"
esac
#==============================================================================
case "$TESTS" in
*%options%*)
# inquire which options are available
OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
# find user ids to setown to; non-root only can setown to itself
if [ $(id -u) = 0 ]; then
# up to now, it is not a big problem when these do not exist
_UID=nobody
_GID=staff
else
_UID=$(id -u)
_GID=$(id -g)
fi
# some options require values; here we try to replace these bare options with
# valid forms.
filloptionvalues() {
local OPTS=",$1,"
#
case "$OPTS" in
*,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
esac
case "$OPTS" in
*,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
esac
case "$OPTS" in
*,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
esac
case "$OPTS" in
*,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
esac
case "$OPTS" in
*,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
esac
case "$OPTS" in
*,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
esac
case "$OPTS" in
*,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
esac
case "$OPTS" in
*,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
esac
case "$OPTS" in
*,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
esac
case "$OPTS" in
*,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
esac
case "$OPTS" in
*,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
esac
case "$OPTS" in
*,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
esac
case "$OPTS" in
*,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
esac
case "$OPTS" in
*,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
esac
case "$OPTS" in
*,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
esac
case "$OPTS" in
*,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
esac
case "$OPTS" in
*,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
esac
case "$OPTS" in
*,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
esac
case "$OPTS" in
*,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
esac
# SOCKET
case "$OPTS" in
*,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
esac
case "$OPTS" in
*,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
esac
case "$OPTS" in
*,rcvtimeo,*) OPTS=$(echo "$OPTS" |sed "s/,rcvtimeo,/,rcvtimeo=1,/g");;
esac
case "$OPTS" in
*,sndtimeo,*) OPTS=$(echo "$OPTS" |sed "s/,sndtimeo,/,sndtimeo=1,/g");;
esac
case "$OPTS" in
*,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
esac
# IP
case "$OPTS" in
*,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
esac
case "$OPTS" in
*,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
esac
case "$OPTS" in
*,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
esac
case "$OPTS" in
*,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
esac
# PTY
case "$OPTS" in
*,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
esac
# RETRY
case "$OPTS" in
*,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
esac
# READLINE
case "$OPTS" in
*,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
esac
case "$OPTS" in
*,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
esac
case "$OPTS" in
*,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
esac
# IPAPP
case "$OPTS" in
*,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
esac
# OPENSSL
case "$OPTS" in
*,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
esac
case "$OPTS" in
*,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
esac
case "$OPTS" in
*,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
esac
# PROXY
case "$OPTS" in
*,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
esac
case "$OPTS" in
*,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
esac
case "$OPTS" in
*,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
esac
# TCP-WRAPPERS
case "$OPTS" in
*,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
esac
case "$OPTS" in
*,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
esac
case "$OPTS" in
*,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
esac
echo $OPTS >&2
expr "$OPTS" : ',\(.*\),'
}
# OPTS_FIFO: nothing yet
# OPTS_CHR: nothing yet
# OPTS_BLK: nothing yet
# OPTS_REG: nothing yet
OPTS_SOCKET=",$OPTS_SOCKET,"
OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
N=1
#------------------------------------------------------------------------------
#method=open
#METHOD=$(echo "$method" |tr a-z A-Z)
#TEST="$METHOD on file accepts all its options"
# echo "### $TEST"
#TF=$TD/file$N
#DA="test$N $(date) $RANDOM"
#OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
#for g in $(echo $OPTGROUPS |tr ',' ' '); do
# eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
# OPTS="$OPTS,$OPTG";
#done
##echo $OPTS
#
#for o in $(filloptionvalues $OPTS|tr ',' ' '); do
# echo testing if $METHOD accepts option $o
# touch $TF
# $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
# rm -f $TF
#done
#------------------------------------------------------------------------------
# test openssl connect
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
pid=$!
for addr in openssl; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
pid=$!
sleep 1
#waittcp4port $PORT
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
# echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
kill $pid
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test proxy connect
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
pid=$!
for addr in proxy; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
# prepare dummy server
$SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/bin/bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
pid=$!
sleep 1
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
# echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
$SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
done
kill $pid 2>/dev/null
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+2))
fi
#------------------------------------------------------------------------------
# test tcp4
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
$SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
pid=$!
for addr in tcp4; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-connect
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
$SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
pid=$!
for addr in udp4-connect; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test tcp4-listen
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
for addr in tcp4-listen; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
pid=$!
$SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
kill $pid 2>/dev/null
done
done
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-listen
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
for addr in udp4-listen; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
pid=$!
$SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
kill $pid 2>/dev/null
done
done
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-sendto
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
$SOCAT $opts udp4-recv:$PORT,fork,$o echo </dev/null &
pid=$!
for addr in udp4-sendto; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-datagram
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
#$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
#pid=$!
for addr in udp4-datagram; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
#kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-recv
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
for addr in udp4-recv; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
pid=$!
$SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
kill $pid 2>/dev/null
done
done
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-recvfrom
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
for addr in udp4-recvfrom; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
pid=$!
$SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
kill $pid 2>/dev/null
done
done
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test ip4-sendto
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
$SOCAT $opts ip4-recv:$PORT,fork,$o echo </dev/null &
pid=$!
for addr in ip4-sendto; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------