You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13284 lines
402 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #! /usr/bin/env bash
  2. # source: test.sh
  3. # Copyright Gerhard Rieger and contributors (see file CHANGES)
  4. # Published under the GNU General Public License V.2, see file COPYING
  5. # perform lots of tests on socat
  6. # this script uses functions; you need a shell that supports them
  7. # you can pass general options to socat: export OPTS="-d -d -d -d -lu"
  8. # you can eg strace socat with: export TRACE="strace -v -tt -ff -D -x -s 1024 -o /tmp/$USER/socat.strace"
  9. #set -vx
  10. val_t=0.1
  11. NUMCOND=true
  12. #NUMCOND="test \$N -gt 70"
  13. VERBOSE=
  14. while [ "$1" ]; do
  15. case "X$1" in
  16. X-t?*) val_t="${1#-t}" ;;
  17. X-t) shift; val_t="$1" ;;
  18. X-v) VERBOSE=1 ;; # show commands
  19. X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
  20. X-n) shift; NUMCOND="test \$N -eq $1" ;;
  21. X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
  22. X-N) shift; NUMCOND="test \$N -ge $1" ;;
  23. X-C) rm -f testcert*.conf testcert.dh testcli*.* testsrv*.* ;;
  24. *) break;
  25. esac
  26. shift
  27. done
  28. opt_t="-t $val_t"
  29. UNAME=`uname`
  30. #MICROS=100000
  31. case "X$val_t" in
  32. X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
  33. X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
  34. X*) S="${val_t}"; uS="000000" ;;
  35. esac
  36. MICROS=${S}${uS}
  37. MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
  38. #
  39. _MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
  40. [ -z "$SECONDs" ] && SECONDs=0
  41. withroot=0 # perform privileged tests even if not run by root
  42. #PATH=$PATH:/opt/freeware/bin
  43. #PATH=$PATH:/usr/local/ssl/bin
  44. PATH=$PATH:/sbin # RHEL6:ip
  45. case "$0" in
  46. */*) PATH="${0%/*}:$PATH"
  47. esac
  48. #OPENSSL_RAND="-rand /dev/egd-pool"
  49. #SOCAT_EGD="egd=/dev/egd-pool"
  50. MISCDELAY=1
  51. [ -z "$SOCAT" ] && SOCAT="./socat"
  52. if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
  53. echo "$SOCAT does not exist" >&2; exit 1;
  54. fi
  55. [ -z "$PROCAN" ] && PROCAN="./procan"
  56. [ -z "$FILAN" ] && FILAN="./filan"
  57. opts="$opt_t $OPTS"
  58. export SOCAT_OPTS="$opts"
  59. #debug="1"
  60. debug=
  61. TESTS="$@"; export TESTS
  62. # for some tests we need a network interface
  63. if type ip >/dev/null 2>&1; then
  64. INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
  65. else
  66. case "$UNAME" in
  67. Linux)
  68. if [ "$IP" ]; then
  69. INTERFACE="$($IP route get 8.8.8.8 |grep ' dev ' |sed -e 's/.* dev //' -e 's/ .*//')"
  70. else
  71. INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($8);}')"
  72. fi ;;
  73. FreeBSD) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
  74. *) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
  75. esac
  76. fi
  77. MCINTERFACE=$INTERFACE
  78. [ -z "$MCINTERFACE" ] && MCINTERFACE=lo # !!! Linux only - and not always
  79. #LOCALHOST=192.168.58.1
  80. LOCALHOST=localhost
  81. #LOCALHOST=127.0.0.1
  82. LOCALHOST6=[::1]
  83. #PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
  84. #PROTO=$(($PROTO+1))
  85. PROTO=$((144+RANDOM/2048))
  86. PORT=12002
  87. SOURCEPORT=2002
  88. REUSEADDR=reuseaddr # use this with LISTEN addresses and bind options
  89. # SSL certificate contents
  90. TESTCERT_CONF=testcert.conf
  91. TESTCERT6_CONF=testcert6.conf
  92. #
  93. TESTCERT_COMMONNAME="$LOCALHOST"
  94. TESTCERT_COMMONNAME6="$LOCALHOST6"
  95. TESTCERT_COUNTRYNAME="XY"
  96. TESTCERT_LOCALITYNAME="Lunar Base"
  97. TESTCERT_ORGANIZATIONALUNITNAME="socat"
  98. TESTCERT_ORGANIZATIONNAME="dest-unreach"
  99. TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
  100. TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
  101. RSABITS=1024
  102. cat >$TESTCERT_CONF <<EOF
  103. prompt=no
  104. [ req ]
  105. default_bits = $RSABITS
  106. distinguished_name=Test
  107. [ Test ]
  108. countryName=$TESTCERT_COUNTRYNAME
  109. commonName=$TESTCERT_COMMONNAME
  110. O=$TESTCERT_ORGANIZATIONNAME
  111. OU=$TESTCERT_ORGANIZATIONALUNITNAME
  112. L=$TESTCERT_LOCALITYNAME
  113. EOF
  114. cat >$TESTCERT6_CONF <<EOF
  115. prompt=no
  116. [ req ]
  117. default_bits = $RESBITS
  118. distinguished_name=Test
  119. [ Test ]
  120. countryName=$TESTCERT_COUNTRYNAME
  121. commonName=$TESTCERT_COMMONNAME6
  122. O=$TESTCERT_ORGANIZATIONNAME
  123. OU=$TESTCERT_ORGANIZATIONALUNITNAME
  124. L=$TESTCERT_LOCALITYNAME
  125. EOF
  126. # clean up from previous runs
  127. rm -f testcli.{crt,key,pem}
  128. rm -f testsrv.{crt,key,pem}
  129. rm -f testcli6.{crt,key,pem}
  130. rm -f testsrv6.{crt,key,pem}
  131. CAT=cat
  132. OD_C="od -c"
  133. toupper () {
  134. case ${BASH_VERSION:0:1} in
  135. [1-3]) echo "$@" |tr a-z A-Z ;;
  136. [4-9]) echo "${@^^*}" ;;
  137. esac
  138. }
  139. tolower () {
  140. case ${BASH_VERSION:0:1} in
  141. [1-3]) echo "$@" |tr A-Z a-z ;;
  142. [4-9]) echo "${@,,*}" ;;
  143. esac
  144. }
  145. # precision sleep; takes seconds with fractional part
  146. psleep () {
  147. local T="$1"
  148. [ "$T" = 0 ] && T=0.000002
  149. $SOCAT -T "$T" pipe pipe
  150. }
  151. # time in microseconds to wait in some situations
  152. if ! type usleep >/dev/null 2>&1 ||
  153. usleep 0 2>&1 |grep -q deprecated; then
  154. usleep () {
  155. local n="$1"
  156. case "$n" in
  157. *???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
  158. *) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
  159. esac
  160. $SOCAT -T $S.$uS pipe pipe
  161. }
  162. fi
  163. #USLEEP=usleep
  164. if type ping6 >/dev/null 2>&1; then
  165. PING6=ping6
  166. else
  167. PING6="ping -6"
  168. fi
  169. F_n="%3d" # format string for test numbers
  170. export LC_ALL=C # for timestamps format...
  171. export LANG=C
  172. export LANGUAGE=C # knoppix
  173. case "$UNAME" in
  174. HP-UX|OSF1)
  175. echo "$SOCAT -u stdin stdout" >cat.sh
  176. chmod a+x cat.sh
  177. CAT=./cat.sh
  178. ;;
  179. SunOS)
  180. # /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
  181. # /usr/xpg4/bin/tr instead
  182. alias tr=/usr/xpg4/bin/tr
  183. ;;
  184. *)
  185. CAT=cat
  186. ;;
  187. esac
  188. case "$UNAME" in
  189. #HP-UX)
  190. # # on HP-UX, the default options (below) hang some tests (former 14, 15)
  191. # PTYOPTS=
  192. # PTYOPTS2=
  193. # ;;
  194. *)
  195. PTYOPTS="echo=0,opost=0"
  196. #PTYOPTS2="raw,echo=0"
  197. PTYOPTS2="cfmakeraw"
  198. #PTYOPTS2="rawer"
  199. ;;
  200. esac
  201. # for some tests we need an unprivileged user id to su to
  202. if [ "$SUDO_USER" ]; then
  203. SUBSTUSER="$SUDO_USER"
  204. else
  205. SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
  206. fi
  207. if type ip >/dev/null 2>&1; then
  208. if ip -V |grep -q "^ip utility, iproute2-ss"; then
  209. IP=$(which ip)
  210. else
  211. unset IP
  212. fi
  213. fi
  214. if type ss >/dev/null 2>&1; then
  215. if ss -V |grep -q "^ss utility, iproute2-ss"; then
  216. SS=$(which ss)
  217. else
  218. unset SS
  219. fi
  220. fi
  221. if [ -z "$SS" ]; then
  222. # non-root users might miss ifconfig in their path
  223. case "$UNAME" in
  224. AIX) IFCONFIG=/usr/sbin/ifconfig ;;
  225. FreeBSD) IFCONFIG=/sbin/ifconfig ;;
  226. HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
  227. Linux) IFCONFIG=/sbin/ifconfig ;;
  228. NetBSD)IFCONFIG=/sbin/ifconfig ;;
  229. OpenBSD)IFCONFIG=/sbin/ifconfig ;;
  230. OSF1) IFCONFIG=/sbin/ifconfig ;;
  231. SunOS) IFCONFIG=/sbin/ifconfig ;;
  232. Darwin)IFCONFIG=/sbin/ifconfig ;;
  233. DragonFly) IFCONFIG=/sbin/ifconfig ;;
  234. *) IFCONFIG=/sbin/ifconfig ;;
  235. esac
  236. fi
  237. # need output like "644"
  238. case "$UNAME" in
  239. Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
  240. FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
  241. *) fileperms() {
  242. local p s=0 c
  243. p="$(ls -l -L "$1" |awk '{print($1);}')"
  244. p="${p:1:9}"
  245. while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
  246. printf "%03o\n" $s;
  247. } ;;
  248. esac
  249. # need user (owner) of filesystem entry
  250. case "$UNAME" in
  251. Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
  252. FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
  253. *) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
  254. esac
  255. if2addr4() {
  256. local IF="$1"
  257. if [ "$IP" ]; then
  258. $IP address show dev $IF |grep "inet " |sed -e "s/.*inet //" -e "s/ .*//"
  259. else
  260. $IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}' |cut -d: -f2
  261. fi
  262. }
  263. if2bc4() {
  264. local IF="$1"
  265. if [ "$IP" ]; then
  266. $IP address show dev $IF |grep ' inet .* brd ' |awk '{print($4);}'
  267. else
  268. $IFCONFIG $IF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}'
  269. fi
  270. }
  271. # for some tests we need a second local IPv4 address
  272. case "$UNAME" in
  273. Linux)
  274. if [ "$IP" ]; then
  275. BROADCASTIF=$($IP r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
  276. else
  277. BROADCASTIF=$(route -n |grep '^0.0.0.0 ' |awk '{print($8);}')
  278. fi
  279. [ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
  280. SECONDADDR=127.1.0.1
  281. SECONDMASK=255.255.0.0
  282. BCADDR=127.255.255.255
  283. BCIFADDR=$(if2addr4 $BROADCASTIF) ;;
  284. FreeBSD|NetBSD|OpenBSD)
  285. MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
  286. BROADCASTIF="$MAINIF"
  287. SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
  288. BCIFADDR="$SECONDADDR"
  289. BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
  290. HP-UX)
  291. MAINIF=lan0 # might use "netstat -ni" for this
  292. BROADCASTIF="$MAINIF"
  293. SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
  294. BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
  295. SunOS)
  296. MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
  297. BROADCASTIF="$MAINIF"
  298. #BROADCASTIF=hme0
  299. #BROADCASTIF=eri0
  300. #SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
  301. SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
  302. #BCIFADDR="$SECONDADDR"
  303. #BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
  304. ;;
  305. DragonFly)
  306. MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
  307. BROADCASTIF="$MAINIF"
  308. SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
  309. BCIFADDR="$SECONDADDR"
  310. BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
  311. #AIX|FreeBSD|Solaris)
  312. *)
  313. SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
  314. ;;
  315. esac
  316. # for generic sockets we need this address in hex form
  317. if [ "$SECONDADDR" ]; then
  318. SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' '
  319. '))"
  320. fi
  321. # for some tests we need a second local IPv6 address
  322. case "$UNAME" in
  323. Linux) if [ "$IP" ]; then
  324. SECONDIP6ADDR=$(expr "$($IP address |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet6 \([0-9a-f:][0-9a-f:]*\)/.*')
  325. else
  326. SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
  327. fi ;;
  328. *)
  329. SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
  330. ;;
  331. esac
  332. if [ -z "$SECONDIP6ADDR" ]; then
  333. # case "$TESTS" in
  334. # *%root2%*) $IFCONFIG eth0 ::2/128
  335. # esac
  336. SECONDIP6ADDR="$LOCALHOST6"
  337. else
  338. SECONDIP6ADDR="[$SECONDIP6ADDR]"
  339. fi
  340. TRUE=$(which true)
  341. #E=-e # Linux
  342. if [ $(echo "x\c") = "x" ]; then E=""
  343. elif [ $(echo -e "x\c") = "x" ]; then E="-e"
  344. else
  345. echo "cannot suppress trailing newline on echo" >&2
  346. exit 1
  347. fi
  348. ECHO="echo $E"
  349. PRINTF="printf"
  350. case "$TERM" in
  351. vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color)
  352. # there are different behaviours of printf (and echo)
  353. # on some systems, echo behaves different than printf...
  354. if [ $($PRINTF "\0101") = "A" ]; then
  355. RED="\0033[31m"
  356. GREEN="\0033[32m"
  357. YELLOW="\0033[33m"
  358. # if [ "$UNAME" = SunOS ]; then
  359. # NORMAL="\0033[30m"
  360. # else
  361. NORMAL="\0033[39m"
  362. # fi
  363. else
  364. RED="\033[31m"
  365. GREEN="\033[32m"
  366. YELLOW="\033[33m"
  367. # if [ "$UNAME" = SunOS ]; then
  368. # NORMAL="\033[30m"
  369. # else
  370. NORMAL="\033[39m"
  371. # fi
  372. fi
  373. OK="${GREEN}OK${NORMAL}"
  374. FAILED="${RED}FAILED${NORMAL}"
  375. NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
  376. ;;
  377. *) OK="OK"
  378. FAILED="FAILED"
  379. NO_RESULT="NO RESULT"
  380. ;;
  381. esac
  382. if [ -x /usr/xpg4/bin/id ]; then
  383. # SunOS has rather useless tools in its default path
  384. PATH="/usr/xpg4/bin:$PATH"
  385. fi
  386. [ -z "$TESTS" ] && TESTS="consistency functions filan"
  387. # use '%' as separation char
  388. TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
  389. [ -z "$USER" ] && USER="$LOGNAME" # HP-UX
  390. if [ -z "$TMPDIR" ]; then
  391. if [ -z "$TMP" ]; then
  392. TMP=/tmp
  393. fi
  394. TMPDIR="$TMP"
  395. fi
  396. TD="$TMPDIR/$USER/$$"; td="$TD"
  397. rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
  398. mkdir -p "$TD"
  399. #trap "rm -r $TD" 0 3
  400. echo "using temp directory $TD"
  401. case "$TESTS" in
  402. *%consistency%*)
  403. # test if addresses are sorted alphabetically:
  404. $ECHO "testing if address array is sorted...\c"
  405. TF="$TD/socat-q"
  406. IFS="$($ECHO ' \n\t')"
  407. $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
  408. $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"
  409. if [ -s "$TF-diff" ]; then
  410. $ECHO "\n*** address array is not sorted. Wrong entries:" >&2
  411. cat "$TD/socat-q-diff" >&2
  412. exit 1
  413. else
  414. echo " ok"
  415. fi
  416. #/bin/rm "$TF"
  417. #/bin/rm "$TF-diff"
  418. esac
  419. case "$TESTS" in
  420. *%consistency%*)
  421. # test if address options array ("optionnames") is sorted alphabetically:
  422. $ECHO "testing if address options are sorted...\c"
  423. TF="$TD/socat-qq"
  424. $SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
  425. LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
  426. if [ -s "$TF-diff" ]; then
  427. $ECHO "\n*** option array is not sorted. Wrong entries:" >&2
  428. cat "$TD/socat-qq-diff" >&2
  429. exit 1
  430. else
  431. echo " ok"
  432. fi
  433. /bin/rm "$TF"
  434. /bin/rm "$TF-diff"
  435. esac
  436. #==============================================================================
  437. case "$TESTS" in
  438. *%options%*)
  439. # inquire which options are available
  440. OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  441. OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  442. OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  443. OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  444. OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  445. OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  446. OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  447. OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  448. OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  449. OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  450. OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  451. OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  452. OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  453. OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  454. OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
  455. OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  456. OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  457. OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  458. OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  459. OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  460. OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  461. OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  462. OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  463. OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  464. OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  465. OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  466. OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  467. OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  468. OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  469. OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
  470. # find user ids to setown to; non-root only can setown to itself
  471. if [ $(id -u) = 0 ]; then
  472. # up to now, it is not a big problem when these do not exist
  473. _UID=nobody
  474. _GID=staff
  475. else
  476. _UID=$(id -u)
  477. _GID=$(id -g)
  478. fi
  479. # some options require values; here we try to replace these bare options with
  480. # valid forms.
  481. filloptionvalues() {
  482. local OPTS=",$1,"
  483. #
  484. case "$OPTS" in
  485. *,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
  486. esac
  487. case "$OPTS" in
  488. *,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
  489. esac
  490. case "$OPTS" in
  491. *,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
  492. esac
  493. case "$OPTS" in
  494. *,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
  495. esac
  496. case "$OPTS" in
  497. *,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
  498. esac
  499. case "$OPTS" in
  500. *,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
  501. esac
  502. case "$OPTS" in
  503. *,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
  504. esac
  505. case "$OPTS" in
  506. *,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
  507. esac
  508. case "$OPTS" in
  509. *,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
  510. esac
  511. case "$OPTS" in
  512. *,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
  513. esac
  514. case "$OPTS" in
  515. *,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
  516. esac
  517. case "$OPTS" in
  518. *,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
  519. esac
  520. case "$OPTS" in
  521. *,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
  522. esac
  523. case "$OPTS" in
  524. *,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
  525. esac
  526. case "$OPTS" in
  527. *,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
  528. esac
  529. case "$OPTS" in
  530. *,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
  531. esac
  532. case "$OPTS" in
  533. *,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
  534. esac
  535. case "$OPTS" in
  536. *,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
  537. esac
  538. case "$OPTS" in
  539. *,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
  540. esac
  541. # SOCKET
  542. case "$OPTS" in
  543. *,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
  544. esac
  545. case "$OPTS" in
  546. *,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
  547. esac
  548. case "$OPTS" in
  549. *,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
  550. esac
  551. # IP
  552. case "$OPTS" in
  553. *,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
  554. esac
  555. case "$OPTS" in
  556. *,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
  557. esac
  558. case "$OPTS" in
  559. *,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
  560. esac
  561. case "$OPTS" in
  562. *,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
  563. esac
  564. # PTY
  565. case "$OPTS" in
  566. *,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
  567. esac
  568. # RETRY
  569. case "$OPTS" in
  570. *,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
  571. esac
  572. # READLINE
  573. case "$OPTS" in
  574. *,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
  575. esac
  576. case "$OPTS" in
  577. *,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
  578. esac
  579. case "$OPTS" in
  580. *,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
  581. esac
  582. # IPAPP
  583. case "$OPTS" in
  584. *,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
  585. esac
  586. # OPENSSL
  587. case "$OPTS" in
  588. *,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
  589. esac
  590. case "$OPTS" in
  591. *,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
  592. esac
  593. case "$OPTS" in
  594. *,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
  595. esac
  596. case "$OPTS" in
  597. *,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
  598. esac
  599. case "$OPTS" in
  600. *,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
  601. esac
  602. case "$OPTS" in
  603. *,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
  604. esac
  605. case "$OPTS" in
  606. *,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
  607. esac
  608. case "$OPTS" in
  609. *,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
  610. esac
  611. case "$OPTS" in
  612. *,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
  613. esac
  614. # PROXY
  615. case "$OPTS" in
  616. *,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
  617. esac
  618. case "$OPTS" in
  619. *,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
  620. esac
  621. case "$OPTS" in
  622. *,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
  623. esac
  624. # TCP-WRAPPERS
  625. case "$OPTS" in
  626. *,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
  627. esac
  628. case "$OPTS" in
  629. *,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
  630. esac
  631. case "$OPTS" in
  632. *,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
  633. esac
  634. echo $OPTS >&2
  635. expr "$OPTS" : ',\(.*\),'
  636. }
  637. # OPTS_FIFO: nothing yet
  638. # OPTS_CHR: nothing yet
  639. # OPTS_BLK: nothing yet
  640. # OPTS_REG: nothing yet
  641. OPTS_SOCKET=",$OPTS_SOCKET,"
  642. OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
  643. N=1
  644. #------------------------------------------------------------------------------
  645. #method=open
  646. #METHOD=$(echo "$method" |tr a-z A-Z)
  647. #TEST="$METHOD on file accepts all its options"
  648. # echo "### $TEST"
  649. #TF=$TD/file$N
  650. #DA="test$N $(date) $RANDOM"
  651. #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
  652. #for g in $(echo $OPTGROUPS |tr ',' ' '); do
  653. # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
  654. # OPTS="$OPTS,$OPTG";
  655. #done
  656. ##echo $OPTS
  657. #
  658. #for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  659. # echo testing if $METHOD accepts option $o
  660. # touch $TF
  661. # $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
  662. # rm -f $TF
  663. #done
  664. #------------------------------------------------------------------------------
  665. # test openssl connect
  666. #set -vx
  667. if true; then
  668. #if false; then
  669. #opts="-s -d -d -d -d"
  670. pid=$!
  671. for addr in openssl; do
  672. ADDR=$(echo "$addr" |tr a-z A-Z)
  673. TEST="$ADDR accepts all its options"
  674. echo "### $TEST"
  675. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  676. # echo OPTGROUPS=$OPTGROUPS
  677. OPTS=
  678. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  679. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  680. OPTS="$OPTS,$OPTG";
  681. done
  682. echo $OPTS
  683. openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
  684. pid=$!
  685. sleep 1
  686. #waittcp4port $PORT
  687. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  688. echo "testing if $ADDR accepts option $o"
  689. # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  690. $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  691. done
  692. kill $pid
  693. done
  694. kill $pid 2>/dev/null
  695. opts=
  696. PORT=$((PORT+1))
  697. fi
  698. #------------------------------------------------------------------------------
  699. # test proxy connect
  700. #set -vx
  701. if true; then
  702. #if false; then
  703. #opts="-s -d -d -d -d"
  704. pid=$!
  705. for addr in proxy; do
  706. ADDR=$(echo "$addr" |tr a-z A-Z)
  707. TEST="$ADDR accepts all its options"
  708. echo "### $TEST"
  709. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  710. # echo OPTGROUPS=$OPTGROUPS
  711. OPTS=
  712. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  713. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  714. OPTS="$OPTS,$OPTG";
  715. done
  716. echo $OPTS
  717. # prepare dummy server
  718. $SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/usr/bin/env bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
  719. pid=$!
  720. sleep 1
  721. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  722. echo "testing if $ADDR accepts option $o"
  723. # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
  724. $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
  725. done
  726. kill $pid 2>/dev/null
  727. done
  728. kill $pid 2>/dev/null
  729. opts=
  730. PORT=$((PORT+2))
  731. fi
  732. #------------------------------------------------------------------------------
  733. # test tcp4
  734. #set -vx
  735. if true; then
  736. #if false; then
  737. #opts="-s -d -d -d -d"
  738. $SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
  739. pid=$!
  740. for addr in tcp4; do
  741. ADDR=$(echo "$addr" |tr a-z A-Z)
  742. TEST="$ADDR accepts all its options"
  743. echo "### $TEST"
  744. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  745. # echo OPTGROUPS=$OPTGROUPS
  746. OPTS=
  747. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  748. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  749. OPTS="$OPTS,$OPTG";
  750. done
  751. echo $OPTS
  752. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  753. echo "testing if $ADDR accepts option $o"
  754. $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  755. done
  756. done
  757. kill $pid 2>/dev/null
  758. opts=
  759. PORT=$((PORT+1))
  760. fi
  761. #------------------------------------------------------------------------------
  762. # test udp4-connect
  763. #set -vx
  764. if true; then
  765. #if false; then
  766. #opts="-s -d -d -d -d"
  767. $SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
  768. pid=$!
  769. for addr in udp4-connect; do
  770. ADDR=$(echo "$addr" |tr a-z A-Z)
  771. TEST="$ADDR accepts all its options"
  772. echo "### $TEST"
  773. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  774. # echo OPTGROUPS=$OPTGROUPS
  775. OPTS=
  776. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  777. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  778. OPTS="$OPTS,$OPTG";
  779. done
  780. echo $OPTS
  781. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  782. echo "testing if $ADDR accepts option $o"
  783. $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  784. done
  785. done
  786. kill $pid 2>/dev/null
  787. opts=
  788. PORT=$((PORT+1))
  789. fi
  790. #------------------------------------------------------------------------------
  791. # test tcp4-listen
  792. #set -vx
  793. if true; then
  794. #if false; then
  795. #opts="-s -d -d -d -d"
  796. for addr in tcp4-listen; do
  797. ADDR=$(echo "$addr" |tr a-z A-Z)
  798. TEST="$ADDR accepts all its options"
  799. echo "### $TEST"
  800. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  801. OPTS=
  802. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  803. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  804. OPTS="$OPTS,$OPTG";
  805. done
  806. echo $OPTS
  807. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  808. echo "testing if $ADDR accepts option $o"
  809. $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
  810. pid=$!
  811. $SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
  812. kill $pid 2>/dev/null
  813. done
  814. done
  815. opts=
  816. PORT=$((PORT+1))
  817. fi
  818. #------------------------------------------------------------------------------
  819. # test udp4-listen
  820. #set -vx
  821. if true; then
  822. #if false; then
  823. #opts="-s -d -d -d -d"
  824. for addr in udp4-listen; do
  825. ADDR=$(echo "$addr" |tr a-z A-Z)
  826. TEST="$ADDR accepts all its options"
  827. echo "### $TEST"
  828. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  829. OPTS=
  830. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  831. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  832. OPTS="$OPTS,$OPTG";
  833. done
  834. echo $OPTS
  835. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  836. echo "testing if $ADDR accepts option $o"
  837. $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
  838. pid=$!
  839. $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
  840. kill $pid 2>/dev/null
  841. done
  842. done
  843. opts=
  844. PORT=$((PORT+1))
  845. fi
  846. #------------------------------------------------------------------------------
  847. # test udp4-sendto
  848. #set -vx
  849. if true; then
  850. #if false; then
  851. #opts="-s -d -d -d -d"
  852. $SOCAT $opts udp4-recv:$PORT,fork,$o echo </dev/null &
  853. pid=$!
  854. for addr in udp4-sendto; do
  855. ADDR=$(echo "$addr" |tr a-z A-Z)
  856. TEST="$ADDR accepts all its options"
  857. echo "### $TEST"
  858. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  859. # echo OPTGROUPS=$OPTGROUPS
  860. OPTS=
  861. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  862. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  863. OPTS="$OPTS,$OPTG";
  864. done
  865. echo $OPTS
  866. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  867. echo "testing if $ADDR accepts option $o"
  868. $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  869. done
  870. done
  871. kill $pid 2>/dev/null
  872. opts=
  873. PORT=$((PORT+1))
  874. fi
  875. #------------------------------------------------------------------------------
  876. # test udp4-datagram
  877. #set -vx
  878. if true; then
  879. #if false; then
  880. #opts="-s -d -d -d -d"
  881. #$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
  882. #pid=$!
  883. for addr in udp4-datagram; do
  884. ADDR=$(echo "$addr" |tr a-z A-Z)
  885. TEST="$ADDR accepts all its options"
  886. echo "### $TEST"
  887. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  888. # echo OPTGROUPS=$OPTGROUPS
  889. OPTS=
  890. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  891. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  892. OPTS="$OPTS,$OPTG";
  893. done
  894. echo $OPTS
  895. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  896. echo "testing if $ADDR accepts option $o"
  897. $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  898. done
  899. done
  900. #kill $pid 2>/dev/null
  901. opts=
  902. PORT=$((PORT+1))
  903. fi
  904. #------------------------------------------------------------------------------
  905. # test udp4-recv
  906. #set -vx
  907. if true; then
  908. #if false; then
  909. #opts="-s -d -d -d -d"
  910. for addr in udp4-recv; do
  911. ADDR=$(echo "$addr" |tr a-z A-Z)
  912. TEST="$ADDR accepts all its options"
  913. echo "### $TEST"
  914. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  915. OPTS=
  916. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  917. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  918. OPTS="$OPTS,$OPTG";
  919. done
  920. echo $OPTS
  921. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  922. echo "testing if $ADDR accepts option $o"
  923. $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
  924. pid=$!
  925. $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
  926. kill $pid 2>/dev/null
  927. done
  928. done
  929. opts=
  930. PORT=$((PORT+1))
  931. fi
  932. #------------------------------------------------------------------------------
  933. # test udp4-recvfrom
  934. #set -vx
  935. if true; then
  936. #if false; then
  937. #opts="-s -d -d -d -d"
  938. for addr in udp4-recvfrom; do
  939. ADDR=$(echo "$addr" |tr a-z A-Z)
  940. TEST="$ADDR accepts all its options"
  941. echo "### $TEST"
  942. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  943. OPTS=
  944. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  945. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  946. OPTS="$OPTS,$OPTG";
  947. done
  948. echo $OPTS
  949. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  950. echo "testing if $ADDR accepts option $o"
  951. $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
  952. pid=$!
  953. $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
  954. kill $pid 2>/dev/null
  955. done
  956. done
  957. opts=
  958. PORT=$((PORT+1))
  959. fi
  960. #------------------------------------------------------------------------------
  961. # test ip4-sendto
  962. #set -vx
  963. if true; then
  964. #if false; then
  965. #opts="-s -d -d -d -d"
  966. $SOCAT $opts ip4-recv:$PORT,fork,$o echo </dev/null &
  967. pid=$!
  968. for addr in ip4-sendto; do
  969. ADDR=$(echo "$addr" |tr a-z A-Z)
  970. TEST="$ADDR accepts all its options"
  971. echo "### $TEST"
  972. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  973. # echo OPTGROUPS=$OPTGROUPS
  974. OPTS=
  975. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  976. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  977. OPTS="$OPTS,$OPTG";
  978. done
  979. echo $OPTS
  980. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  981. echo "testing if $ADDR accepts option $o"
  982. $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
  983. done
  984. done
  985. kill $pid 2>/dev/null
  986. opts=
  987. PORT=$((PORT+1))
  988. fi
  989. #------------------------------------------------------------------------------
  990. # test ip4-recv
  991. #set -vx
  992. if true; then
  993. #if false; then
  994. #opts="-s -d -d -d -d"
  995. for addr in ip4-recv; do
  996. ADDR=$(echo "$addr" |tr a-z A-Z)
  997. TEST="$ADDR accepts all its options"
  998. echo "### $TEST"
  999. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1000. OPTS=
  1001. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1002. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1003. OPTS="$OPTS,$OPTG";
  1004. done
  1005. echo $OPTS
  1006. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1007. echo "testing if $ADDR accepts option $o"
  1008. $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
  1009. pid=$!
  1010. $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
  1011. kill $pid 2>/dev/null
  1012. done
  1013. done
  1014. opts=
  1015. PORT=$((PORT+1))
  1016. fi
  1017. #------------------------------------------------------------------------------
  1018. # test ip4-recvfrom
  1019. #set -vx
  1020. if true; then
  1021. #if false; then
  1022. #opts="-s -d -d -d -d"
  1023. for addr in ip4-recvfrom; do
  1024. ADDR=$(echo "$addr" |tr a-z A-Z)
  1025. TEST="$ADDR accepts all its options"
  1026. echo "### $TEST"
  1027. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1028. OPTS=
  1029. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1030. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1031. OPTS="$OPTS,$OPTG";
  1032. done
  1033. echo $OPTS
  1034. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1035. echo "testing if $ADDR accepts option $o"
  1036. $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
  1037. pid=$!
  1038. $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
  1039. kill $pid 2>/dev/null
  1040. done
  1041. done
  1042. opts=
  1043. PORT=$((PORT+1))
  1044. fi
  1045. #------------------------------------------------------------------------------
  1046. # test READLINE
  1047. if true; then
  1048. #if false; then
  1049. #opts="-s -d -d -d -d"
  1050. for addr in readline; do
  1051. ADDR=$(echo "$addr" |tr a-z A-Z)
  1052. TEST="$ADDR accepts all its options"
  1053. echo "### $TEST"
  1054. TS=$TD/script$N
  1055. OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
  1056. OPTS=
  1057. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1058. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1059. OPTS="$OPTS,$OPTG";
  1060. done
  1061. #echo $OPTS
  1062. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1063. # for o in bs0; do
  1064. echo "testing if $ADDR accepts option $o"
  1065. echo "$SOCAT $opts readline,$o /dev/null" >$TS
  1066. chmod u+x $TS
  1067. $SOCAT /dev/null,ignoreeof exec:$TS,pty
  1068. #stty sane
  1069. done
  1070. #reset 1>&0 2>&0
  1071. done
  1072. opts=
  1073. fi
  1074. #------------------------------------------------------------------------------
  1075. # unnamed pipe
  1076. #if false; then
  1077. if true; then
  1078. for addr in pipe; do
  1079. ADDR=$(echo "$addr" |tr a-z A-Z)
  1080. TEST="unnamed $ADDR accepts all its options"
  1081. echo "### $TEST"
  1082. OPTGROUPS=$($SOCAT -? |egrep " $addr[^:]" |sed 's/.*=//')
  1083. OPTS=
  1084. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1085. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1086. OPTS="$OPTS,$OPTG";
  1087. done
  1088. #echo $OPTS
  1089. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1090. echo testing if unnamed $ADDR accepts option $o
  1091. $SOCAT $opts $addr,$o /dev/null </dev/null
  1092. done
  1093. done
  1094. fi
  1095. #------------------------------------------------------------------------------
  1096. # test addresses on files
  1097. N=1
  1098. #if false; then
  1099. if true; then
  1100. for addr in create; do
  1101. ADDR=$(echo "$addr" |tr a-z A-Z)
  1102. TEST="$ADDR on new file accepts all its options"
  1103. echo "### $TEST"
  1104. TF=$TD/file$N
  1105. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1106. OPTS=
  1107. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1108. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1109. OPTS="$OPTS,$OPTG";
  1110. done
  1111. #echo $OPTS
  1112. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1113. echo testing if $ADDR accepts option $o
  1114. rm -f $TF
  1115. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1116. rm -f $TF
  1117. done
  1118. done
  1119. fi
  1120. #------------------------------------------------------------------------------
  1121. #if false; then
  1122. if true; then
  1123. for addr in exec system; do
  1124. ADDR=$(echo "$addr" |tr a-z A-Z)
  1125. TEST="$ADDR with socketpair accepts all its options"
  1126. echo "### $TEST"
  1127. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1128. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g')
  1129. OPTS=
  1130. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1131. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1132. OPTS="$OPTS,$OPTG";
  1133. done
  1134. OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
  1135. #echo $OPTS
  1136. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1137. echo testing if $ADDR with socketpair accepts option $o
  1138. $SOCAT $opts $addr:$TRUE,$o /dev/null,ignoreof </dev/null
  1139. done
  1140. TEST="$ADDR with pipes accepts all its options"
  1141. echo "### $TEST"
  1142. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1143. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
  1144. OPTS=
  1145. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1146. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1147. OPTS="$OPTS,$OPTG";
  1148. done
  1149. # flock tends to hang, so dont test it
  1150. OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g' -e 's/,flock,/,/g')
  1151. #echo $OPTS
  1152. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1153. echo testing if $ADDR with pipes accepts option $o
  1154. $SOCAT $opts $addr:$TRUE,pipes,$o /dev/null,ignoreof </dev/null
  1155. done
  1156. TEST="$ADDR with pty accepts all its options"
  1157. echo "### $TEST"
  1158. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1159. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
  1160. OPTS=
  1161. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1162. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1163. OPTS="$OPTS,$OPTG";
  1164. done
  1165. OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
  1166. #echo $OPTS
  1167. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1168. echo testing if $ADDR with pty accepts option $o
  1169. $SOCAT $opts $addr:$TRUE,pty,$o /dev/null,ignoreof </dev/null
  1170. done
  1171. TEST="$ADDR with nofork accepts all its options"
  1172. echo "### $TEST"
  1173. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1174. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,PTY,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
  1175. OPTS=
  1176. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1177. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1178. OPTS="$OPTS,$OPTG";
  1179. done
  1180. OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
  1181. #echo $OPTS
  1182. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1183. echo testing if $ADDR with nofork accepts option $o
  1184. $SOCAT /dev/null $opts $addr:$TRUE,nofork,$o </dev/null
  1185. done
  1186. done
  1187. fi
  1188. #------------------------------------------------------------------------------
  1189. #if false; then
  1190. if true; then
  1191. for addr in fd; do
  1192. ADDR=$(echo "$addr" |tr a-z A-Z)
  1193. TEST="$ADDR accepts all its options"
  1194. echo "### $TEST"
  1195. TF=$TD/file$N
  1196. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1197. OPTS=
  1198. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1199. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1200. OPTS="$OPTS,$OPTG";
  1201. done
  1202. #echo $OPTS
  1203. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1204. echo "testing if $ADDR (to file) accepts option $o"
  1205. rm -f $TF
  1206. $SOCAT $opts -u /dev/null $addr:3,$o 3>$TF
  1207. done
  1208. done
  1209. fi
  1210. #------------------------------------------------------------------------------
  1211. # test OPEN address
  1212. #! test it on pipe, device, new file
  1213. N=1
  1214. #if false; then
  1215. if true; then
  1216. for addr in open; do
  1217. ADDR=$(echo "$addr" |tr a-z A-Z)
  1218. TEST="$ADDR on file accepts all its options"
  1219. echo "### $TEST"
  1220. TF=$TD/file$N
  1221. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1222. OPTS=
  1223. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1224. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1225. OPTS="$OPTS,$OPTG";
  1226. done
  1227. #echo $OPTS
  1228. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1229. echo testing if $ADDR on file accepts option $o
  1230. touch $TF
  1231. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1232. rm -f $TF
  1233. done
  1234. done
  1235. fi
  1236. #------------------------------------------------------------------------------
  1237. # test GOPEN address on files, sockets, pipes, devices
  1238. N=1
  1239. #if false; then
  1240. if true; then
  1241. for addr in gopen; do
  1242. ADDR=$(echo "$addr" |tr a-z A-Z)
  1243. TEST="$ADDR on new file accepts all its options"
  1244. echo "### $TEST"
  1245. TF=$TD/file$N
  1246. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1247. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
  1248. OPTS=
  1249. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1250. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1251. OPTS="$OPTS,$OPTG";
  1252. done
  1253. #echo $OPTS
  1254. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1255. echo testing if $ADDR on new file accepts option $o
  1256. rm -f $TF
  1257. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1258. rm -f $TF
  1259. done
  1260. TEST="$ADDR on existing file accepts all its options"
  1261. echo "### $TEST"
  1262. TF=$TD/file$N
  1263. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1264. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
  1265. OPTS=
  1266. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1267. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1268. OPTS="$OPTS,$OPTG";
  1269. done
  1270. #echo $OPTS
  1271. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1272. echo testing if $ADDR on existing file accepts option $o
  1273. rm -f $TF; touch $TF
  1274. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1275. rm -f $TF
  1276. done
  1277. TEST="$ADDR on existing pipe accepts all its options"
  1278. echo "### $TEST"
  1279. TF=$TD/pipe$N
  1280. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1281. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
  1282. OPTS=
  1283. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1284. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1285. OPTS="$OPTS,$OPTG";
  1286. done
  1287. #echo $OPTS
  1288. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1289. echo testing if $ADDR on named pipe accepts option $o
  1290. rm -f $TF; mkfifo $TF
  1291. $SOCAT $opts $addr:$TF,$o,nonblock /dev/null </dev/null
  1292. rm -f $TF
  1293. done
  1294. TEST="$ADDR on existing socket accepts all its options"
  1295. echo "### $TEST"
  1296. TF=$TD/sock$N
  1297. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1298. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
  1299. OPTS=
  1300. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1301. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1302. OPTS="$OPTS,$OPTG";
  1303. done
  1304. #echo $OPTS
  1305. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1306. echo testing if $ADDR on socket accepts option $o
  1307. rm -f $TF; $SOCAT - UNIX-L:$TF & pid=$!
  1308. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1309. kill $pid 2>/dev/null
  1310. rm -f $TF
  1311. done
  1312. if [ $(id -u) -eq 0 ]; then
  1313. TEST="$ADDR on existing device accepts all its options"
  1314. echo "### $TEST"
  1315. TF=$TD/null
  1316. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1317. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
  1318. OPTS=
  1319. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1320. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1321. OPTS="$OPTS,$OPTG";
  1322. done
  1323. #echo $OPTS
  1324. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1325. echo testing if $ADDR on existing device accepts option $o
  1326. rm -f $TF; mknod $TF c 1 3
  1327. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1328. done
  1329. else
  1330. TEST="$ADDR on existing device accepts all its options"
  1331. echo "### $TEST"
  1332. TF=/dev/null
  1333. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1334. OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
  1335. OPTS=
  1336. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1337. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1338. OPTS="$OPTS,$OPTG";
  1339. done
  1340. #echo $OPTS
  1341. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1342. echo testing if $ADDR on existing device accepts option $o
  1343. $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
  1344. done
  1345. fi
  1346. done
  1347. fi
  1348. #------------------------------------------------------------------------------
  1349. # test named pipe
  1350. N=1
  1351. #if false; then
  1352. if true; then
  1353. for addr in pipe; do
  1354. ADDR=$(echo "$addr" |tr a-z A-Z)
  1355. TEST="$ADDR on file accepts all its options"
  1356. echo "### $TEST"
  1357. TF=$TD/pipe$N
  1358. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1359. OPTS=
  1360. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1361. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1362. OPTS="$OPTS,$OPTG";
  1363. done
  1364. #echo $OPTS
  1365. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1366. echo testing if named $ADDR accepts option $o
  1367. rm -f $TF
  1368. # blocks with rdonly, wronly
  1369. case "$o" in rdonly|wronly) o="$o,nonblock" ;; esac
  1370. $SOCAT $opts $addr:$TF,$o /dev/null </dev/null
  1371. rm -f $TF
  1372. done
  1373. done
  1374. fi
  1375. #------------------------------------------------------------------------------
  1376. # test STDIO
  1377. #! test different stream types
  1378. #if false; then
  1379. if true; then
  1380. for addr in stdio; do
  1381. ADDR=$(echo "$addr" |tr a-z A-Z)
  1382. TEST="$ADDR accepts all its options"
  1383. echo "### $TEST"
  1384. OPTGROUPS=$($SOCAT -? |fgrep " $addr" |sed 's/.*=//')
  1385. OPTS=
  1386. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1387. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1388. OPTS="$OPTS,$OPTG";
  1389. done
  1390. #echo $OPTS
  1391. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1392. echo "testing if $ADDR (/dev/null, stdout) accepts option $o"
  1393. $SOCAT $opts $addr,$o /dev/null,ignoreof </dev/null
  1394. done
  1395. done
  1396. fi
  1397. #------------------------------------------------------------------------------
  1398. # test STDIN
  1399. #if false; then
  1400. if true; then
  1401. for addr in stdin; do
  1402. ADDR=$(echo "$addr" |tr a-z A-Z)
  1403. TEST="$ADDR accepts all its options"
  1404. echo "### $TEST"
  1405. OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
  1406. OPTS=
  1407. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1408. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1409. OPTS="$OPTS,$OPTG";
  1410. done
  1411. #echo $OPTS
  1412. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1413. echo "testing if $ADDR (/dev/null) accepts option $o"
  1414. $SOCAT $opts -u $addr,$o /dev/null </dev/null
  1415. done
  1416. done
  1417. fi
  1418. #------------------------------------------------------------------------------
  1419. # test STDOUT, STDERR
  1420. if true; then
  1421. #if false; then
  1422. for addr in stdout stderr; do
  1423. ADDR=$(echo "$addr" |tr a-z A-Z)
  1424. TEST="$ADDR accepts all its options"
  1425. echo "### $TEST"
  1426. OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
  1427. OPTS=
  1428. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1429. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1430. OPTS="$OPTS,$OPTG";
  1431. done
  1432. #echo $OPTS
  1433. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1434. echo "testing if $ADDR accepts option $o"
  1435. $SOCAT $opts -u /dev/null $addr,$o
  1436. done
  1437. done
  1438. fi
  1439. #------------------------------------------------------------------------------
  1440. # REQUIRES ROOT
  1441. if [ "$withroot" ]; then
  1442. for addr in ip4; do
  1443. ADDR=$(echo "$addr" |tr a-z A-Z)
  1444. TEST="$ADDR accepts all its options"
  1445. echo "### $TEST"
  1446. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1447. OPTS=
  1448. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1449. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1450. OPTS="$OPTS,$OPTG";
  1451. done
  1452. #echo $OPTS
  1453. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1454. echo "testing if $ADDR accepts option $o"
  1455. $SOCAT $opts $addr:127.0.0.1:200 /dev/null,ignoreof </dev/null
  1456. done
  1457. done
  1458. fi
  1459. #------------------------------------------------------------------------------
  1460. # REQUIRES ROOT
  1461. if [ "$withroot" ]; then
  1462. for addr in ip6; do
  1463. ADDR=$(echo "$addr" |tr a-z A-Z)
  1464. TEST="$ADDR accepts all its options"
  1465. echo "### $TEST"
  1466. OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
  1467. OPTS=
  1468. for g in $(echo $OPTGROUPS |tr ',' ' '); do
  1469. eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
  1470. OPTS="$OPTS,$OPTG";
  1471. done
  1472. #echo $OPTS
  1473. for o in $(filloptionvalues $OPTS|tr ',' ' '); do
  1474. echo "testing if $ADDR accepts option $o"
  1475. $SOCAT $opts $addr:[::1]:200 /dev/null,ignoreof </dev/null
  1476. done
  1477. done
  1478. fi
  1479. #==============================================================================
  1480. #TEST="stdio accepts all options of GROUP_ANY"
  1481. #echo "### $TEST"
  1482. #CMD="$SOCAT $opts -,$OPTS_ANY /dev/null"
  1483. #$CMD
  1484. #if [ $? = 0 ]; then
  1485. # echo "... test $N ($TEST) succeeded"
  1486. ## echo "CMD=$CMD"
  1487. #else
  1488. # echo "*** test $N ($TEST) FAILED"
  1489. # echo "CMD=$CMD"
  1490. #fi
  1491. #
  1492. #N=$((N+1))
  1493. ##------------------------------------------------------------------------------
  1494. #
  1495. #TEST="exec accepts all options of GROUP_ANY and GROUP_SOCKET"
  1496. #echo "### $TEST"
  1497. #CMD="$SOCAT $opts exec:$TRUE,$OPTS_ANY,$OPTS_SOCKET /dev/null"
  1498. #$CMD
  1499. #if [ $? = 0 ]; then
  1500. # echo "... test $N ($TEST) succeeded"
  1501. ## echo "CMD=$CMD"
  1502. #else
  1503. # echo "*** test $N ($TEST) FAILED"
  1504. # echo "CMD=$CMD"
  1505. #fi
  1506. #------------------------------------------------------------------------------
  1507. esac
  1508. #==============================================================================
  1509. N=1
  1510. numOK=0
  1511. numFAIL=0
  1512. numCANT=0
  1513. listFAIL=
  1514. #==============================================================================
  1515. # test if selected socat features work ("FUNCTIONS")
  1516. testecho () {
  1517. local N="$1"
  1518. local title="$2"
  1519. local arg1="$3"; [ -z "$arg1" ] && arg1="-"
  1520. local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
  1521. local opts="$5"
  1522. local T="$6"; [ -z "$T" ] && T=0
  1523. local tf="$td/test$N.stdout"
  1524. local te="$td/test$N.stderr"
  1525. local tdiff="$td/test$N.diff"
  1526. local da="test$N $(date) $RANDOM"
  1527. if ! eval $NUMCOND; then :; else
  1528. #local cmd="$TRACE $SOCAT $opts $arg1 $arg2"
  1529. #$ECHO "testing $title (test $N)... \c"
  1530. $PRINTF "test $F_n %s... " $N "$title"
  1531. #echo "$da" |$cmd >"$tf" 2>"$te"
  1532. (psleep $T; echo "$da"; psleep $T) |($TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $? >"$td/test$N.rc") &
  1533. export rc1=$!
  1534. #sleep 5 && kill $rc1 2>/dev/null &
  1535. # rc2=$!
  1536. wait $rc1
  1537. # kill $rc2 2>/dev/null
  1538. if [ "$(cat "$td/test$N.rc")" != 0 ]; then
  1539. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  1540. echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
  1541. cat "$te" >&2
  1542. numFAIL=$((numFAIL+1))
  1543. listFAIL="$listFAIL $N"
  1544. elif echo "$da" |diff - "$tf" >"$tdiff" 2>&1; then
  1545. $PRINTF "$OK\n"
  1546. if [ "$verbose" ]; then echo "$SOCAT $opts $arg1 $arg2" >&2; fi
  1547. if [ -n "$debug" ]; then cat $te >&2; fi
  1548. numOK=$((numOK+1))
  1549. else
  1550. $PRINTF "$FAILED:\n"
  1551. echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
  1552. cat "$te" >&2
  1553. echo diff: >&2
  1554. cat "$tdiff" >&2
  1555. numFAIL=$((numFAIL+1))
  1556. listFAIL="$listFAIL $N"
  1557. fi
  1558. fi # NUMCOND
  1559. }
  1560. # test if call to od and throughput of data works - with graceful shutdown and
  1561. # flush of od buffers
  1562. testod () {
  1563. local num="$1"
  1564. local title="$2"
  1565. local arg1="$3"; [ -z "$arg1" ] && arg1="-"
  1566. local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
  1567. local opts="$5"
  1568. local T="$6"; [ -z "$T" ] && T=0
  1569. local tf="$td/test$N.stdout"
  1570. local te="$td/test$N.stderr"
  1571. local tr="$td/test$N.ref"
  1572. local tdiff="$td/test$N.diff"
  1573. local dain="$(date) $RANDOM"
  1574. if ! eval $NUMCOND; then :; else
  1575. echo "$dain" |$OD_C >"$tr"
  1576. # local daout="$(echo "$dain" |$OD_C)"
  1577. $PRINTF "test $F_n %s... " $num "$title"
  1578. (psleep $T; echo "$dain"; psleep $T) |$TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"
  1579. if [ "$?" != 0 ]; then
  1580. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  1581. echo "$TRACE $SOCAT $opts $arg1 $arg2"
  1582. cat "$te"
  1583. numFAIL=$((numFAIL+1))
  1584. listFAIL="$listFAIL $num"
  1585. # elif echo "$daout" |diff - "$tf" >"$tdiff" 2>&1; then
  1586. elif diff "$tr" "$tf" >"$tdiff" 2>&1; then
  1587. $PRINTF "$OK\n"
  1588. if [ -n "$debug" ]; then cat $te; fi
  1589. numOK=$((numOK+1))
  1590. else
  1591. $PRINTF "$FAILED: diff:\n"
  1592. echo "$TRACE $SOCAT $opts $arg1 $arg2"
  1593. cat "$te"
  1594. cat "$tdiff"
  1595. numFAIL=$((numFAIL+1))
  1596. listFAIL="$listFAIL $num"
  1597. fi
  1598. fi # NUMCOND
  1599. }
  1600. # test if the socat executable has these address types compiled in
  1601. # print the first missing address type
  1602. testaddrs () {
  1603. local a A;
  1604. for a in $@; do
  1605. A=$(echo "$a" |tr 'a-z-' 'A-Z_')
  1606. if $TRACE $SOCAT -V |grep "#define WITH_$A 1\$" >/dev/null; then
  1607. if [[ "$A" =~ OPENSSL.* ]]; then
  1608. gentestcert testsrv
  1609. gentestcert testcli
  1610. fi
  1611. shift
  1612. continue
  1613. fi
  1614. echo "$a"
  1615. return 1
  1616. done
  1617. return 0
  1618. }
  1619. # test if the socat executable has these options compiled in
  1620. # print the first missing option
  1621. testoptions () {
  1622. local a A;
  1623. for a in $@; do
  1624. A=$(echo "$a" |tr 'a-z' 'A-Z')
  1625. if $SOCAT -??? |grep "[^a-z0-9-]$a[^a-z0-9-]" >/dev/null; then
  1626. shift
  1627. continue
  1628. fi
  1629. echo "$a"
  1630. return 1
  1631. done
  1632. return 0
  1633. }
  1634. # check if the given pid exists and has child processes
  1635. # if yes: prints child process lines to stdout, returns 0
  1636. # if not: prints ev.message to stderr, returns 1
  1637. childprocess () {
  1638. local l
  1639. case "$UNAME" in
  1640. AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;;
  1641. FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;;
  1642. HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
  1643. Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
  1644. # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)")" ;;
  1645. NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
  1646. OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)")" ;;
  1647. SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
  1648. DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
  1649. CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]")" ;;
  1650. *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]**[ ][ ]*$(printf %5u $1) ")" ;; esac
  1651. if [ -z "$l" ]; then
  1652. return 1;
  1653. fi
  1654. echo "$l"
  1655. return 0
  1656. }
  1657. # return a list of child process pids
  1658. childpids () {
  1659. case "$UNAME" in
  1660. AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)" |awk '{print($2);}')" ;;
  1661. FreeBSD) l="$(ps -fl |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$(printf %5u $1)" |awk '{print($2);}')" ;;
  1662. HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
  1663. Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
  1664. # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)" |awk '{print($2);}')" ;;
  1665. NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)" |awk '{print($2);}')" ;;
  1666. OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
  1667. SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
  1668. DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)" |awk '{print($2);}')" ;;
  1669. CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]" |awk '{print($2)';})" ;;
  1670. *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$(printf %5u $1) " |awk '{print($2)';})" ;; esac
  1671. if [ -z "$l" ]; then
  1672. return 1;
  1673. fi
  1674. echo "$l"
  1675. return 0
  1676. }
  1677. # check if the given process line refers to a defunct (zombie) process
  1678. # yes: returns 0
  1679. # no: returns 1
  1680. isdefunct () {
  1681. local l
  1682. case "$UNAME" in
  1683. AIX) l="$(echo "$1" |grep ' <defunct>$')" ;;
  1684. FreeBSD) l="$(echo "$1" |grep ' <defunct>$')" ;;
  1685. HP-UX) l="$(echo "$1" |grep ' <defunct>$')" ;;
  1686. Linux) l="$(echo "$1" |grep ' <defunct>$')" ;;
  1687. SunOS) l="$(echo "$1" |grep ' <defunct>$')" ;;
  1688. DragonFly)l="$(echo "$1" |grep ' <defunct>$')" ;;
  1689. *) l="$(echo "$1" |grep ' <defunct>$')" ;;
  1690. esac
  1691. [ -n "$l" ];
  1692. }
  1693. # check if UNIX socket protocol is available on host
  1694. runsunix () {
  1695. return 0;
  1696. $TRACE $SOCAT /dev/null UNIX-LISTEN:"$td/unix.socket" 2>"$td/unix.stderr" &
  1697. pid=$!
  1698. usleep $MICROS
  1699. kill "$pid" 2>/dev/null
  1700. test ! -s "$td/unix.stderr"
  1701. }
  1702. unset HAVENOT_IP4
  1703. # check if an IP4 loopback interface exists
  1704. runsip4 () {
  1705. [ -n "$HAVENOT_IP4" ] && return $HAVENOT_IP4
  1706. local l
  1707. case "$UNAME" in
  1708. AIX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
  1709. FreeBSD) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
  1710. HP-UX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
  1711. Linux) if [ "$IP" ]; then
  1712. l=$($IP address |egrep ' inet 127.0.0.1/')
  1713. else
  1714. l=$($IFCONFIG |egrep 'inet (addr:)?127\.0\.0\.1 ')
  1715. fi ;;
  1716. NetBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
  1717. OpenBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
  1718. OSF1) l=$($IFCONFIG -a |grep ' inet ') ;;
  1719. SunOS) l=$($IFCONFIG -a |grep 'inet ') ;;
  1720. Darwin)l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
  1721. DragonFly)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
  1722. CYGWIN*) l=$(ipconfig |grep IPv4);;
  1723. *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
  1724. esac
  1725. [ -z "$l" ] && return 1
  1726. # existence of interface might not suffice, check for routeability:
  1727. case "$UNAME" in
  1728. Darwin) ping -c 1 127.0.0.1 >/dev/null 2>&1; l="$?" ;;
  1729. Linux) ping -c 1 127.0.0.1 >/dev/null 2>&1; l="$?" ;;
  1730. *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
  1731. esac
  1732. HAVENOT_IP4=$l
  1733. if [ "$HAVENOT_IP4" -ne 0 ]; then
  1734. echo IP4
  1735. fi
  1736. return $l;
  1737. }
  1738. unset HAVENOT_IP6
  1739. # check if an IP6 loopback interface exists
  1740. runsip6 () {
  1741. [ -n "$HAVENOT_IP6" ] && return $HAVENOT_IP6
  1742. local l
  1743. case "$UNAME" in
  1744. AIX) l=$($IFCONFIG lo0 |grep 'inet6 ::1/0') ;;
  1745. HP-UX) l=$($IFCONFIG lo0 |grep ' inet6 ') ;;
  1746. Linux) if [ "$IP" ]; then
  1747. l=$($IP address |egrep 'inet6 ::1/128')
  1748. else
  1749. l=$($IFCONFIG |egrep 'inet6 (addr: )?::1/?')
  1750. fi ;;
  1751. NetBSD)l=$($IFCONFIG -a |grep 'inet6 ::1 ');;
  1752. OSF1) l=$($IFCONFIG -a |grep ' inet6 ') ;;
  1753. SunOS) l=$($IFCONFIG -a |grep 'inet6 ') ;;
  1754. Darwin)l=$($IFCONFIG lo0 |grep 'inet6 ::1 ') ;;
  1755. CYGWIN*) l=$(ipconfig |grep IPv6);;
  1756. *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
  1757. esac
  1758. [ -z "$l" ] && return 1
  1759. # existence of interface might not suffice, check for routeability:
  1760. case "$UNAME" in
  1761. Darwin) $PING6 -c 1 ::1 >/dev/null 2>&1; l="$?" ;;
  1762. Linux) $PING6 -c 1 ::1 >/dev/null 2>&1; l="$?" ;;
  1763. *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
  1764. esac
  1765. HAVENOT_IP6=$l
  1766. if [ "$HAVENOT_IP6" -ne 0 ]; then
  1767. echo IP6
  1768. fi
  1769. return "$HAVENOT_IP6"
  1770. }
  1771. # check if TCP on IPv4 is available on host
  1772. runstcp4 () {
  1773. runsip4 >/dev/null || { echo TCP4; return 1; }
  1774. $SOCAT -h |grep '\<tcp4-' >/dev/null || return 1
  1775. return 0;
  1776. }
  1777. # check if TCP on IPv6 is available on host
  1778. runstcp6 () {
  1779. runsip6 >/dev/null || { echo TCP6; return 1; }
  1780. $SOCAT -h |grep '\<tcp6-' >/dev/null || return 1
  1781. return 0;
  1782. }
  1783. # check if UDP on IPv4 is available on host
  1784. runsudp4 () {
  1785. runsip4 >/dev/null || { echo UDP4; return 1; }
  1786. $SOCAT -h |grep '\<udp4-' >/dev/null || return 1
  1787. return 0;
  1788. }
  1789. # check if UDP on IPv6 is available on host
  1790. runsudp6 () {
  1791. runsip6 >/dev/null || { echo UDP6; return 1; }
  1792. $SOCAT -h |grep '\<udp6-' >/dev/null || return 1
  1793. return 0;
  1794. }
  1795. # check if SCTP on IPv4 is available on host
  1796. runssctp4 () {
  1797. runsip4 >/dev/null || { echo SCTP4; return 1; }
  1798. $SOCAT -h |grep '\<sctp4-' >/dev/null || return 1
  1799. return 0;
  1800. }
  1801. # check if SCTP on IPv6 is available on host
  1802. runssctp6 () {
  1803. runsip6 >/dev/null || { echo SCTP6; return 1; }
  1804. $SOCAT -h |grep '\<sctp6-' >/dev/null || return 1
  1805. return 0;
  1806. }
  1807. # wait until an IP4 protocol is ready
  1808. waitip4proto () {
  1809. local proto="$1"
  1810. local logic="$2" # 0..wait until free; 1..wait until listening
  1811. local timeout="$3"
  1812. local l
  1813. [ "$logic" ] || logic=1
  1814. [ "$timeout" ] || timeout=5
  1815. while [ $timeout -gt 0 ]; do
  1816. case "$UNAME" in
  1817. Linux) if [ "$SS" ]; then
  1818. l=$($SS -n -w -l |grep '^\(raw\|UNCONN\) .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
  1819. else
  1820. l=$(netstat -n -w -l |grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
  1821. fi ;;
  1822. # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
  1823. # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
  1824. # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
  1825. # Darwin) case "$(uname -r)" in
  1826. # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
  1827. # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
  1828. # esac ;;
  1829. AIX) # does not seem to show raw sockets in netstat
  1830. sleep 1; return 0 ;;
  1831. # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
  1832. # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
  1833. # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
  1834. *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
  1835. sleep 1; return 0 ;;
  1836. esac
  1837. [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  1838. \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
  1839. sleep 1
  1840. timeout=$((timeout-1))
  1841. done
  1842. $ECHO "!protocol $proto timed out! \c" >&2
  1843. return 1
  1844. }
  1845. # we need this misleading function name for canonical reasons
  1846. waitip4port () {
  1847. waitip4proto "$1" "$2" "$3"
  1848. }
  1849. # wait until an IP6 protocol is ready
  1850. waitip6proto () {
  1851. local proto="$1"
  1852. local logic="$2" # 0..wait until free; 1..wait until listening
  1853. local timeout="$3"
  1854. local l
  1855. [ "$logic" ] || logic=1
  1856. [ "$timeout" ] || timeout=5
  1857. while [ $timeout -gt 0 ]; do
  1858. case "$UNAME" in
  1859. Linux)
  1860. if [ "$SS" ]; then
  1861. l=$($SS -n -w -l |grep '^\(raw\|UNCONN\) .* \*:'$proto' [ ]*\*:\*')
  1862. else
  1863. l=$(netstat -n -w -l |grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*')
  1864. fi ;;
  1865. # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
  1866. # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
  1867. # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
  1868. # Darwin) case "$(uname -r)" in
  1869. # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
  1870. # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
  1871. # esac ;;
  1872. AIX) # does not seem to show raw sockets in netstat
  1873. sleep 1; return 0 ;;
  1874. # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
  1875. # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
  1876. # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
  1877. *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;;
  1878. sleep 1; return 0 ;;
  1879. esac
  1880. [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  1881. \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
  1882. sleep 1
  1883. timeout=$((timeout-1))
  1884. done
  1885. $ECHO "!protocol $proto timed out! \c" >&2
  1886. return 1
  1887. }
  1888. # we need this misleading function name for canonical reasons
  1889. waitip6port () {
  1890. waitip6proto "$1" "$2" "$3"
  1891. }
  1892. # check if a TCP4 port is in use
  1893. # exits with 0 when it is not used
  1894. checktcp4port () {
  1895. local port="$1"
  1896. local l
  1897. case "$UNAME" in
  1898. Linux) if [ "$SS" ]; then
  1899. l=$($SS -4 -l -n -t |grep "^LISTEN .*:$port\>")
  1900. else
  1901. l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
  1902. fi ;;
  1903. FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  1904. NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
  1905. Darwin) case "$(uname -r)" in
  1906. [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  1907. *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  1908. esac ;;
  1909. AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
  1910. SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
  1911. HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
  1912. OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
  1913. CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
  1914. DragonFly)l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
  1915. *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
  1916. esac
  1917. [ -z "$l" ] && return 0
  1918. return 1
  1919. }
  1920. # wait until a TCP4 listen port is ready
  1921. waittcp4port () {
  1922. local port="$1"
  1923. local logic="$2" # 0..wait until free; 1..wait until listening (default)
  1924. local timeout="$3"
  1925. local l
  1926. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  1927. [ "$logic" ] || logic=1
  1928. [ "$timeout" ] || timeout=5
  1929. while [ $timeout -gt 0 ]; do
  1930. case "$UNAME" in
  1931. Linux) if [ "$SS" ]; then
  1932. l=$($SS -l -n -t |grep "^LISTEN .*:$port\>")
  1933. else
  1934. l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
  1935. fi ;;
  1936. FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  1937. NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
  1938. Darwin) case "$(uname -r)" in
  1939. [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  1940. *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  1941. esac ;;
  1942. AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
  1943. SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
  1944. HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
  1945. OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
  1946. CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
  1947. DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
  1948. *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
  1949. esac
  1950. if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  1951. \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
  1952. set ${vx}vx
  1953. return 0
  1954. fi
  1955. sleep 1
  1956. timeout=$((timeout-1))
  1957. done
  1958. $ECHO "!port $port timed out! \c" >&2
  1959. set ${vx}vx
  1960. return 1
  1961. }
  1962. # wait until a UDP4 port is ready
  1963. waitudp4port () {
  1964. local port="$1"
  1965. local logic="$2" # 0..wait until free; 1..wait until listening
  1966. local timeout="$3"
  1967. local l
  1968. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  1969. [ "$logic" ] || logic=1
  1970. [ "$timeout" ] || timeout=5
  1971. while [ $timeout -gt 0 ]; do
  1972. case "$UNAME" in
  1973. Linux) if [ "$SS" ]; then
  1974. l=$($SS -4 -l -n -u |grep "^UNCONN .*:$port\>")
  1975. else
  1976. l=$(netstat -a -n -u -l |grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*')
  1977. fi ;;
  1978. FreeBSD) l=$(netstat -an |egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;;
  1979. NetBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
  1980. OpenBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
  1981. Darwin) case "$(uname -r)" in
  1982. [1-5]*) l=$(netstat -an |grep '^udp.* .*[0-9*]\.'$port' .* \*\.\*') ;;
  1983. *) l=$(netstat -an |grep '^udp4.* .*[0-9*]\.'$port' .* \*\.\* .*') ;;
  1984. esac ;;
  1985. AIX) l=$(netstat -an |grep '^udp[4 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
  1986. SunOS) l=$(netstat -an -f inet -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
  1987. HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
  1988. OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
  1989. DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
  1990. *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
  1991. esac
  1992. if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  1993. \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
  1994. set ${vx}vx
  1995. return 0
  1996. fi
  1997. sleep 1
  1998. timeout=$((timeout-1))
  1999. done
  2000. $ECHO "!port $port timed out! \c" >&2
  2001. set ${vx}vx
  2002. return 1
  2003. }
  2004. # wait until an SCTP4 listen port is ready
  2005. waitsctp4port () {
  2006. local port="$1"
  2007. local logic="$2" # 0..wait until free; 1..wait until listening
  2008. local timeout="$3"
  2009. local l
  2010. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  2011. [ "$logic" ] || logic=1
  2012. [ "$timeout" ] || timeout=5
  2013. while [ $timeout -gt 0 ]; do
  2014. case "$UNAME" in
  2015. Linux) if [ "$SS" ]; then
  2016. l=$($SS -4 -n -A sctp 2>/dev/null |grep "^LISTEN .*:$port\>")
  2017. else
  2018. l=$(netstat -n -a |grep '^sctp .* .*[0-9*]:'$port' .* LISTEN')
  2019. fi ;;
  2020. # FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  2021. # NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
  2022. # Darwin) case "$(uname -r)" in
  2023. # [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  2024. # *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
  2025. # esac ;;
  2026. # AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
  2027. SunOS) l=$(netstat -an -f inet -P sctp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
  2028. # HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
  2029. # OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
  2030. # CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
  2031. *) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
  2032. esac
  2033. if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  2034. \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
  2035. set ${vx}vx
  2036. return 0
  2037. fi
  2038. sleep 1
  2039. timeout=$((timeout-1))
  2040. done
  2041. $ECHO "!port $port timed out! \c" >&2
  2042. set ${vx}vx
  2043. return 1
  2044. }
  2045. # wait until a tcp6 listen port is ready
  2046. waittcp6port () {
  2047. local port="$1"
  2048. local logic="$2" # 0..wait until free; 1..wait until listening
  2049. local timeout="$3"
  2050. local l
  2051. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  2052. [ "$logic" ] || logic=1
  2053. [ "$timeout" ] || timeout=5
  2054. while [ $timeout -gt 0 ]; do
  2055. case "$UNAME" in
  2056. Linux) if [ "$SS" ]; then
  2057. l=$($SS -6 -n -t -l |grep "^LISTEN .*:$port\>")
  2058. else
  2059. l=$(netstat -an |grep -E '^tcp6? .* [0-9a-f:%]*:'$port' .* LISTEN')
  2060. fi ;;
  2061. FreeBSD) l=$(netstat -an |egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;;
  2062. NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
  2063. OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
  2064. Darwin) l=$(netstat -an |egrep '^tcp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+ +LISTEN') ;;
  2065. AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
  2066. SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
  2067. #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
  2068. DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
  2069. *) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;;
  2070. esac
  2071. if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  2072. \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
  2073. set ${vx}vx
  2074. return 0
  2075. fi
  2076. sleep 1
  2077. timeout=$((timeout-1))
  2078. done
  2079. $ECHO "!port $port timed out! \c" >&2
  2080. #echo set ${vx}vx >&2
  2081. set ${vx}vx
  2082. return 1
  2083. }
  2084. # wait until a UDP6 port is ready
  2085. waitudp6port () {
  2086. local port="$1"
  2087. local logic="$2" # 0..wait until free; 1..wait until listening
  2088. local timeout="$3"
  2089. local l
  2090. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  2091. [ "$logic" ] || logic=1
  2092. [ "$timeout" ] || timeout=5
  2093. while [ $timeout -gt 0 ]; do
  2094. case "$UNAME" in
  2095. Linux) if [ "$SS" ]; then
  2096. l=$($SS -6 -u -l -n |grep "^UNCONN .*:$port\>")
  2097. else
  2098. l=$(netstat -an |grep -E '^udp6? .* .*[0-9*:%]:'$port' [ ]*:::\*')
  2099. fi ;;
  2100. FreeBSD) l=$(netstat -an |egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;;
  2101. NetBSD) l=$(netstat -an |grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;;
  2102. OpenBSD) l=$(netstat -an |grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
  2103. Darwin) l=$(netstat -an |egrep '^udp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+') ;;
  2104. AIX) l=$(netstat -an |grep '^udp[6 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
  2105. SunOS) l=$(netstat -an -f inet6 -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
  2106. #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
  2107. #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
  2108. DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
  2109. *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
  2110. esac
  2111. if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  2112. \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
  2113. set ${vx}vx
  2114. return 0
  2115. fi
  2116. sleep 1
  2117. timeout=$((timeout-1))
  2118. done
  2119. $ECHO "!port $port timed out! \c" >&2
  2120. set ${vx}vx
  2121. return 1
  2122. }
  2123. # wait until a sctp6 listen port is ready
  2124. # not all (Linux) variants show this in netstat
  2125. waitsctp6port () {
  2126. local port="$1"
  2127. local logic="$2" # 0..wait until free; 1..wait until listening
  2128. local timeout="$3"
  2129. local l
  2130. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  2131. [ "$logic" ] || logic=1
  2132. [ "$timeout" ] || timeout=5
  2133. while [ $timeout -gt 0 ]; do
  2134. case "$UNAME" in
  2135. Linux) if [ "$SS" ]; then
  2136. l=$($SS -6 -n -A sctp 2>/dev/null |grep "^LISTEN .*:$port\>")
  2137. else
  2138. l=$(netstat -an |grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN')
  2139. fi ;;
  2140. # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
  2141. # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
  2142. # OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
  2143. # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
  2144. SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
  2145. # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
  2146. *) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
  2147. esac
  2148. if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
  2149. \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
  2150. set ${vx}vx
  2151. return 0
  2152. fi
  2153. sleep 1
  2154. timeout=$((timeout-1))
  2155. done
  2156. $ECHO "!port $port timed out! \c" >&2
  2157. set ${vx}vx
  2158. return 1
  2159. }
  2160. # we need this misleading function name for canonical reasons
  2161. waitunixport () {
  2162. waitfile "$1" "$2" "$3"
  2163. }
  2164. # wait until a filesystem entry exists
  2165. waitfile () {
  2166. local crit=-e
  2167. case "X$1" in X-*) crit="$1"; shift ;; esac
  2168. local file="$1"
  2169. local logic="$2" # 0..wait until gone; 1..wait until exists (default);
  2170. # 2..wait until not empty
  2171. local timeout="$3"
  2172. local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
  2173. [ "$logic" ] || logic=1
  2174. [ "$logic" -eq 2 ] && crit=-s
  2175. [ "$timeout" ] || timeout=5
  2176. while [ $timeout -gt 0 ]; do
  2177. if [ \( \( $logic -ne 0 \) -a $crit "$file" \) -o \
  2178. \( \( $logic -eq 0 \) -a ! $crit "$file" \) ]; then
  2179. set ${vx}vx
  2180. return 0
  2181. fi
  2182. sleep 1
  2183. timeout=$((timeout-1))
  2184. done
  2185. echo "file $file timed out" >&2
  2186. set ${vx}vx
  2187. return 1
  2188. }
  2189. # generate a test certificate and key
  2190. gentestcert () {
  2191. local name="$1"
  2192. if ! [ -f testcert.dh ]; then
  2193. openssl dhparam -out testcert.dh $RSABITS
  2194. fi
  2195. if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
  2196. openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
  2197. openssl req -new -config $TESTCERT_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
  2198. cat $name.key $name.crt testcert.dh >$name.pem
  2199. }
  2200. # generate a test DSA key and certificate
  2201. gentestdsacert () {
  2202. local name="$1"
  2203. if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
  2204. openssl dsaparam -out $name-dsa.pem 1024 >/dev/null 2>&1
  2205. openssl dhparam -dsaparam -out $name-dh.pem 1024 >/dev/null 2>&1
  2206. openssl req -newkey dsa:$name-dsa.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
  2207. cat $name-dsa.pem $name-dh.pem $name.key $name.crt >$name.pem
  2208. }
  2209. # generate a test EC key and certificate
  2210. gentesteccert () {
  2211. local name="$1"
  2212. if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
  2213. openssl ecparam -name secp521r1 -out $name-ec.pem >/dev/null 2>&1
  2214. chmod 0400 $name-ec.pem
  2215. openssl req -newkey ec:$name-ec.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
  2216. cat $name-ec.pem $name.key $name.crt >$name.pem
  2217. }
  2218. gentestcert6 () {
  2219. local name="$1"
  2220. if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
  2221. cat $TESTCERT_CONF |
  2222. { echo "# automatically generated by $0"; cat; } |
  2223. sed 's/\(commonName\s*=\s*\).*/\1[::1]/' >$TESTCERT6_CONF
  2224. openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
  2225. openssl req -new -config $TESTCERT6_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
  2226. cat $name.key $name.crt >$name.pem
  2227. }
  2228. NAME=UNISTDIO
  2229. case "$TESTS " in
  2230. *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
  2231. TEST="$NAME: unidirectional throughput from stdin to stdout"
  2232. testecho "$N" "$TEST" "stdin" "stdout" "$opts -u"
  2233. esac
  2234. N=$((N+1))
  2235. NAME=UNPIPESTDIO
  2236. case "$TESTS" in
  2237. *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
  2238. TEST="$NAME: stdio with simple echo via internal pipe"
  2239. testecho "$N" "$TEST" "stdio" "pipe" "$opts"
  2240. esac
  2241. N=$((N+1))
  2242. NAME=UNPIPESHORT
  2243. case "$TESTS" in
  2244. *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
  2245. TEST="$NAME: short form of stdio ('-') with simple echo via internal pipe"
  2246. testecho "$N" "$TEST" "-" "pipe" "$opts"
  2247. esac
  2248. N=$((N+1))
  2249. NAME=DUALSTDIO
  2250. case "$TESTS" in
  2251. *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
  2252. TEST="$NAME: splitted form of stdio ('stdin!!stdout') with simple echo via internal pipe"
  2253. testecho "$N" "$TEST" "stdin!!stdout" "pipe" "$opts"
  2254. esac
  2255. N=$((N+1))
  2256. NAME=DUALSHORTSTDIO
  2257. case "$TESTS" in
  2258. *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
  2259. TEST="$NAME: short splitted form of stdio ('-!!-') with simple echo via internal pipe"
  2260. testecho "$N" "$TEST" "-!!-" "pipe" "$opts"
  2261. esac
  2262. N=$((N+1))
  2263. NAME=DUALFDS
  2264. case "$TESTS" in
  2265. *%$N%*|*%functions%*|*%fd%*|*%$NAME%*)
  2266. TEST="$NAME: file descriptors with simple echo via internal pipe"
  2267. testecho "$N" "$TEST" "0!!1" "pipe" "$opts"
  2268. esac
  2269. N=$((N+1))
  2270. NAME=NAMEDPIPE
  2271. case "$TESTS" in
  2272. *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
  2273. TEST="$NAME: simple echo via named pipe"
  2274. # with MacOS, this test hangs if nonblock is not used. Is an OS bug.
  2275. tp="$td/pipe$N"
  2276. # note: the nonblock is required by MacOS 10.1(?), otherwise it hangs (OS bug?)
  2277. testecho "$N" "$TEST" "" "pipe:$tp,nonblock" "$opts"
  2278. esac
  2279. N=$((N+1))
  2280. NAME=DUALPIPE
  2281. case "$TESTS" in
  2282. *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
  2283. TEST="$NAME: simple echo via named pipe, specified twice"
  2284. tp="$td/pipe$N"
  2285. testecho "$N" "$TEST" "" "pipe:$tp,nonblock!!pipe:$tp" "$opts"
  2286. esac
  2287. N=$((N+1))
  2288. NAME=FILE
  2289. case "$TESTS" in
  2290. *%$N%*|*%functions%*|*%engine%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
  2291. TEST="$NAME: simple echo via file"
  2292. tf="$td/file$N"
  2293. testecho "$N" "$TEST" "" "$tf,ignoreeof!!$tf" "$opts"
  2294. esac
  2295. N=$((N+1))
  2296. NAME=EXECSOCKET
  2297. case "$TESTS" in
  2298. *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
  2299. TEST="$NAME: simple echo via exec of cat with socketpair"
  2300. testecho "$N" "$TEST" "" "exec:$CAT" "$opts"
  2301. esac
  2302. N=$((N+1))
  2303. NAME=SYSTEMSOCKET
  2304. case "$TESTS" in
  2305. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2306. TEST="$NAME: simple echo via system() of cat with socketpair"
  2307. testecho "$N" "$TEST" "" "system:$CAT" "$opts" "$val_t"
  2308. esac
  2309. N=$((N+1))
  2310. NAME=EXECPIPES
  2311. case "$TESTS" in
  2312. *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
  2313. TEST="$NAME: simple echo via exec of cat with pipes"
  2314. testecho "$N" "$TEST" "" "exec:$CAT,pipes" "$opts"
  2315. esac
  2316. N=$((N+1))
  2317. NAME=SYSTEMPIPES
  2318. case "$TESTS" in
  2319. *%$N%*|*%functions%*|*%pipes%*|*%$NAME%*)
  2320. TEST="$NAME: simple echo via system() of cat with pipes"
  2321. testecho "$N" "$TEST" "" "system:$CAT,pipes" "$opts"
  2322. esac
  2323. N=$((N+1))
  2324. NAME=EXECPTY
  2325. case "$TESTS" in
  2326. *%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
  2327. TEST="$NAME: simple echo via exec of cat with pseudo terminal"
  2328. if ! eval $NUMCOND; then :;
  2329. elif ! testaddrs pty >/dev/null; then
  2330. $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  2331. numCANT=$((numCANT+1))
  2332. else
  2333. testecho "$N" "$TEST" "" "exec:$CAT,pty,$PTYOPTS" "$opts"
  2334. fi
  2335. esac
  2336. N=$((N+1))
  2337. NAME=SYSTEMPTY
  2338. case "$TESTS" in
  2339. *%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
  2340. TEST="$NAME: simple echo via system() of cat with pseudo terminal"
  2341. if ! eval $NUMCOND; then :;
  2342. elif ! testaddrs pty >/dev/null; then
  2343. $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  2344. numCANT=$((numCANT+1))
  2345. else
  2346. testecho "$N" "$TEST" "" "system:$CAT,pty,$PTYOPTS" "$opts"
  2347. fi
  2348. esac
  2349. N=$((N+1))
  2350. NAME=SYSTEMPIPESFDS
  2351. case "$TESTS" in
  2352. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2353. TEST="$NAME: simple echo via system() of cat with pipes, non stdio"
  2354. testecho "$N" "$TEST" "" "system:$CAT>&9 <&8,pipes,fdin=8,fdout=9" "$opts"
  2355. esac
  2356. N=$((N+1))
  2357. NAME=DUALSYSTEMFDS
  2358. case "$TESTS" in
  2359. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2360. TEST="$NAME: echo via dual system() of cat"
  2361. testecho "$N" "$TEST" "system:$CAT>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" "$val_t"
  2362. esac
  2363. N=$((N+1))
  2364. # test: send EOF to exec'ed sub process, let it finish its operation, and
  2365. # check if the sub process returns its data before terminating.
  2366. NAME=EXECSOCKETFLUSH
  2367. # idea: have socat exec'ing od; send data and EOF, and check if the od'ed data
  2368. # arrives.
  2369. case "$TESTS" in
  2370. *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
  2371. TEST="$NAME: call to od via exec with socketpair"
  2372. testod "$N" "$TEST" "" "exec:$OD_C" "$opts"
  2373. esac
  2374. N=$((N+1))
  2375. NAME=SYSTEMSOCKETFLUSH
  2376. case "$TESTS" in
  2377. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2378. TEST="$NAME: call to od via system() with socketpair"
  2379. testod "$N" "$TEST" "" "system:$OD_C" "$opts" $val_t
  2380. esac
  2381. N=$((N+1))
  2382. NAME=EXECPIPESFLUSH
  2383. case "$TESTS" in
  2384. *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
  2385. TEST="$NAME: call to od via exec with pipes"
  2386. testod "$N" "$TEST" "" "exec:$OD_C,pipes" "$opts"
  2387. esac
  2388. N=$((N+1))
  2389. NAME=SYSTEMPIPESFLUSH
  2390. case "$TESTS" in
  2391. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2392. TEST="$NAME: call to od via system() with pipes"
  2393. testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
  2394. esac
  2395. N=$((N+1))
  2396. ## LATER:
  2397. #NAME=EXECPTYFLUSH
  2398. #case "$TESTS" in
  2399. #*%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
  2400. #TEST="$NAME: call to od via exec with pseudo terminal"
  2401. #if ! testaddrs pty >/dev/null; then
  2402. # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  2403. # numCANT=$((numCANT+1))
  2404. #else
  2405. #testod "$N" "$TEST" "" "exec:$OD_C,pty,$PTYOPTS" "$opts"
  2406. #fi
  2407. #esac
  2408. #N=$((N+1))
  2409. ## LATER:
  2410. #NAME=SYSTEMPTYFLUSH
  2411. #case "$TESTS" in
  2412. #*%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
  2413. #TEST="$NAME: call to od via system() with pseudo terminal"
  2414. #if ! testaddrs pty >/dev/null; then
  2415. # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  2416. # numCANT=$((numCANT+1))
  2417. #else
  2418. #testod "$N" "$TEST" "" "system:$OD_C,pty,$PTYOPTS" "$opts"
  2419. #fi
  2420. #esac
  2421. #N=$((N+1))
  2422. NAME=SYSTEMPIPESFDSFLUSH
  2423. case "$TESTS" in
  2424. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2425. TEST="$NAME: call to od via system() with pipes, non stdio"
  2426. testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
  2427. esac
  2428. N=$((N+1))
  2429. NAME=DUALSYSTEMFDSFLUSH
  2430. case "$TESTS" in
  2431. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  2432. TEST="$NAME: call to od via dual system()"
  2433. testod "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "pipe" "$opts" "$val_t"
  2434. esac
  2435. N=$((N+1))
  2436. case "$UNAME" in
  2437. Linux) IPPROTO=254 ;;
  2438. Darwin) IPPROTO=255 ;;
  2439. *) IPPROTO=254 ;; # just a guess
  2440. esac
  2441. NAME=RAWIP4SELF
  2442. case "$TESTS" in
  2443. *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
  2444. TEST="$NAME: simple echo via self receiving raw IPv4 protocol"
  2445. if ! eval $NUMCOND; then :;
  2446. elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
  2447. $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
  2448. numCANT=$((numCANT+1))
  2449. elif ! feat=$(testaddrs rawip) >/dev/null; then
  2450. $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
  2451. numCANT=$((numCANT+1))
  2452. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  2453. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  2454. numCANT=$((numCANT+1))
  2455. else
  2456. testecho "$N" "$TEST" "" "ip4:127.0.0.1:$IPPROTO" "$opts"
  2457. fi
  2458. esac
  2459. N=$((N+1))
  2460. NAME=RAWIPX4SELF
  2461. case "$TESTS" in
  2462. *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
  2463. TEST="$NAME: simple echo via self receiving raw IP protocol, v4 by target"
  2464. if ! eval $NUMCOND; then :;
  2465. elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
  2466. $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
  2467. numCANT=$((numCANT+1))
  2468. elif ! feat=$(testaddrs rawip) >/dev/null; then
  2469. $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
  2470. numCANT=$((numCANT+1))
  2471. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  2472. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  2473. numCANT=$((numCANT+1))
  2474. else
  2475. testecho "$N" "$TEST" "" "ip:127.0.0.1:$IPPROTO" "$opts"
  2476. fi ;; # NUMCOND, feats
  2477. esac
  2478. N=$((N+1))
  2479. NAME=RAWIP6SELF
  2480. case "$TESTS" in
  2481. *%$N%*|*%functions%*|*%ip6%*|*%rawip%*|*%root%*|*%$NAME%*)
  2482. TEST="$NAME: simple echo via self receiving raw IPv6 protocol"
  2483. if ! eval $NUMCOND; then :;
  2484. elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
  2485. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  2486. numCANT=$((numCANT+1))
  2487. elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
  2488. $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
  2489. numCANT=$((numCANT+1))
  2490. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  2491. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  2492. numCANT=$((numCANT+1))
  2493. else
  2494. testecho "$N" "$TEST" "" "ip6:[::1]:$IPPROTO" "$opts"
  2495. fi ;; # NUMCOND, feats
  2496. esac
  2497. N=$((N+1))
  2498. NAME=RAWIPX6SELF
  2499. case "$TESTS" in
  2500. *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%root%*|*%$NAME%*)
  2501. TEST="$NAME: simple echo via self receiving raw IP protocol, v6 by target"
  2502. if ! eval $NUMCOND; then :;
  2503. elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
  2504. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  2505. numCANT=$((numCANT+1))
  2506. elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
  2507. $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
  2508. numCANT=$((numCANT+1))
  2509. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  2510. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  2511. numCANT=$((numCANT+1))
  2512. else
  2513. testecho "$N" "$TEST" "" "ip:[::1]:$IPPROTO" "$opts"
  2514. fi
  2515. esac
  2516. N=$((N+1))
  2517. NAME=TCPSELF
  2518. case "$TESTS" in
  2519. *%$N%*|*%functions%*|*%$NAME%*)
  2520. TEST="$NAME: echo via self connection of TCP IPv4 socket"
  2521. if ! eval $NUMCOND; then :;
  2522. elif [ "$UNAME" != Linux ]; then
  2523. $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
  2524. numCANT=$((numCANT+1))
  2525. else
  2526. #ts="127.0.0.1:$tsl"
  2527. testecho "$N" "$TEST" "" "tcp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR,reuseaddr" "$opts"
  2528. fi
  2529. esac
  2530. PORT=$((PORT+1))
  2531. N=$((N+1))
  2532. NAME=UDPSELF
  2533. if ! eval $NUMCOND; then :; else
  2534. case "$TESTS" in
  2535. *%$N%*|*%functions%*|*%$NAME%*)
  2536. TEST="$NAME: echo via self connection of UDP IPv4 socket"
  2537. if [ "$UNAME" != Linux ]; then
  2538. $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
  2539. numCANT=$((numCANT+1))
  2540. else
  2541. testecho "$N" "$TEST" "" "udp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR" "$opts"
  2542. fi
  2543. esac
  2544. fi # NUMCOND
  2545. PORT=$((PORT+1))
  2546. N=$((N+1))
  2547. NAME=UDP6SELF
  2548. case "$TESTS" in
  2549. *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%$NAME%*)
  2550. TEST="$NAME: echo via self connection of UDP IPv6 socket"
  2551. if ! eval $NUMCOND; then :;
  2552. elif [ "$UNAME" != Linux ]; then
  2553. $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
  2554. numCANT=$((numCANT+1))
  2555. elif ! testaddrs udp ip6 >/dev/null || ! runsudp6 >/dev/null; then
  2556. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  2557. numCANT=$((numCANT+1))
  2558. else
  2559. tf="$td/file$N"
  2560. testecho "$N" "$TEST" "" "udp6:[::1]:$PORT,sp=$PORT,bind=[::1]" "$opts"
  2561. fi
  2562. esac
  2563. PORT=$((PORT+1))
  2564. N=$((N+1))
  2565. NAME=DUALUDPSELF
  2566. if ! eval $NUMCOND; then :; else
  2567. case "$TESTS" in
  2568. *%$N%*|*%functions%*|*%$NAME%*)
  2569. TEST="$NAME: echo via two unidirectional UDP IPv4 sockets"
  2570. tf="$td/file$N"
  2571. p1=$PORT
  2572. p2=$((PORT+1))
  2573. testecho "$N" "$TEST" "" "udp:127.0.0.1:$p2,sp=$p1!!udp:127.0.0.1:$p1,sp=$p2" "$opts"
  2574. esac
  2575. fi # NUMCOND
  2576. PORT=$((PORT+2))
  2577. N=$((N+1))
  2578. #function testdual {
  2579. # local
  2580. #}
  2581. NAME=UNIXSTREAM
  2582. if ! eval $NUMCOND; then :; else
  2583. case "$TESTS" in
  2584. *%$N%*|*%functions%*|*%unix%*|*%$NAME%*)
  2585. TEST="$NAME: echo via connection to UNIX domain socket"
  2586. tf="$td/test$N.stdout"
  2587. te="$td/test$N.stderr"
  2588. ts="$td/test$N.socket"
  2589. tdiff="$td/test$N.diff"
  2590. da="test$N $(date) $RANDOM"
  2591. CMD1="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
  2592. CMD2="$TRACE $SOCAT $opts -!!- UNIX-CONNECT:$ts"
  2593. printf "test $F_n $TEST... " $N
  2594. $CMD1 </dev/null >$tf 2>"${te}1" &
  2595. bg=$! # background process id
  2596. waitfile "$ts"
  2597. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2598. rc2=$?
  2599. if [ "$rc2" -ne 0 ]; then
  2600. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2601. echo "$CMD1 &"
  2602. echo "$CMD2"
  2603. echo "rc=$rc2"
  2604. cat "${te}1"
  2605. cat "${te}2"
  2606. numFAIL=$((numFAIL+1))
  2607. listFAIL="$listFAIL $N"
  2608. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2609. $PRINTF "$FAILED: diff:\n"
  2610. cat "$tdiff"
  2611. numFAIL=$((numFAIL+1))
  2612. listFAIL="$listFAIL $N"
  2613. else
  2614. $PRINTF "$OK\n"
  2615. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2616. numOK=$((numOK+1))
  2617. fi
  2618. kill $bg 2>/dev/null
  2619. esac
  2620. fi # NUMCOND
  2621. N=$((N+1))
  2622. NAME=TCP4
  2623. if ! eval $NUMCOND; then :; else
  2624. case "$TESTS" in
  2625. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2626. TEST="$NAME: echo via connection to TCP V4 socket"
  2627. tf="$td/test$N.stdout"
  2628. te="$td/test$N.stderr"
  2629. tdiff="$td/test$N.diff"
  2630. tsl=$PORT
  2631. ts="127.0.0.1:$tsl"
  2632. da="test$N $(date) $RANDOM"
  2633. CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
  2634. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  2635. printf "test $F_n $TEST... " $N
  2636. $CMD1 >"$tf" 2>"${te}1" &
  2637. pid1=$!
  2638. waittcp4port $tsl 1
  2639. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2640. if [ $? -ne 0 ]; then
  2641. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2642. echo "$CMD1 &"
  2643. cat "${te}1"
  2644. echo "$CMD2"
  2645. cat "${te}2"
  2646. numFAIL=$((numFAIL+1))
  2647. listFAIL="$listFAIL $N"
  2648. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2649. $PRINTF "$FAILED\n"
  2650. cat "$tdiff"
  2651. numFAIL=$((numFAIL+1))
  2652. listFAIL="$listFAIL $N"
  2653. else
  2654. $PRINTF "$OK\n"
  2655. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2656. numOK=$((numOK+1))
  2657. fi
  2658. kill $pid1 2>/dev/null
  2659. wait ;;
  2660. esac
  2661. PORT=$((PORT+1))
  2662. fi # NUMCOND
  2663. N=$((N+1))
  2664. #et -xv
  2665. NAME=TCP6
  2666. case "$TESTS" in
  2667. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2668. TEST="$NAME: echo via connection to TCP V6 socket"
  2669. if ! eval $NUMCOND; then :;
  2670. elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  2671. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  2672. numCANT=$((numCANT+1))
  2673. else
  2674. tf="$td/test$N.stdout"
  2675. te="$td/test$N.stderr"
  2676. tdiff="$td/test$N.diff"
  2677. tsl=$PORT
  2678. ts="[::1]:$tsl"
  2679. da="test$N $(date) $RANDOM"
  2680. CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
  2681. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
  2682. printf "test $F_n $TEST... " $N
  2683. $CMD1 >"$tf" 2>"${te}1" &
  2684. pid=$! # background process id
  2685. waittcp6port $tsl 1
  2686. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2687. if [ $? -ne 0 ]; then
  2688. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2689. echo "$CMD1 &"
  2690. echo "$CMD2"
  2691. cat "$te"
  2692. numFAIL=$((numFAIL+1))
  2693. listFAIL="$listFAIL $N"
  2694. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2695. $PRINTF "$FAILED: diff:\n"
  2696. cat "$tdiff"
  2697. numFAIL=$((numFAIL+1))
  2698. listFAIL="$listFAIL $N"
  2699. else
  2700. $PRINTF "$OK\n"
  2701. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2702. numOK=$((numOK+1))
  2703. fi
  2704. kill $pid 2>/dev/null
  2705. fi
  2706. esac
  2707. PORT=$((PORT+1))
  2708. N=$((N+1))
  2709. #set +vx
  2710. NAME=TCPX4
  2711. case "$TESTS" in
  2712. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2713. TEST="$NAME: echo via connection to TCP socket, v4 by target"
  2714. if ! eval $NUMCOND; then :;
  2715. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  2716. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  2717. numCANT=$((numCANT+1))
  2718. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  2719. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  2720. numCANT=$((numCANT+1))
  2721. else
  2722. tf="$td/test$N.stdout"
  2723. te="$td/test$N.stderr"
  2724. tdiff="$td/test$N.diff"
  2725. tsl=$PORT
  2726. ts="127.0.0.1:$tsl"
  2727. da="test$N $(date) $RANDOM"
  2728. CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip4,$REUSEADDR PIPE"
  2729. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
  2730. printf "test $F_n $TEST... " $N
  2731. $CMD1 >"$tf" 2>"${te}1" &
  2732. pid=$! # background process id
  2733. waittcp4port $tsl 1
  2734. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2735. if [ $? -ne 0 ]; then
  2736. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2737. echo "$CMD1 &"
  2738. echo "$CMD2"
  2739. cat "$te"
  2740. numFAIL=$((numFAIL+1))
  2741. listFAIL="$listFAIL $N"
  2742. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2743. $PRINTF "$FAILED: diff:\n"
  2744. cat "$tdiff"
  2745. numFAIL=$((numFAIL+1))
  2746. listFAIL="$listFAIL $N"
  2747. else
  2748. $PRINTF "$OK\n"
  2749. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2750. numOK=$((numOK+1))
  2751. fi
  2752. kill $pid 2>/dev/null
  2753. fi
  2754. esac
  2755. PORT=$((PORT+1))
  2756. N=$((N+1))
  2757. NAME=TCPX6
  2758. case "$TESTS" in
  2759. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2760. TEST="$NAME: echo via connection to TCP socket, v6 by target"
  2761. if ! eval $NUMCOND; then :;
  2762. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  2763. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  2764. numCANT=$((numCANT+1))
  2765. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  2766. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  2767. numCANT=$((numCANT+1))
  2768. else
  2769. tf="$td/test$N.stdout"
  2770. te="$td/test$N.stderr"
  2771. tdiff="$td/test$N.diff"
  2772. tsl=$PORT
  2773. ts="[::1]:$tsl"
  2774. da="test$N $(date) $RANDOM"
  2775. CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip6,$REUSEADDR PIPE"
  2776. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
  2777. printf "test $F_n $TEST... " $N
  2778. $CMD1 >"$tf" 2>"${te}1" &
  2779. pid=$! # background process id
  2780. waittcp6port $tsl 1
  2781. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2782. if [ $? -ne 0 ]; then
  2783. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2784. echo "$CMD1 &"
  2785. echo "$CMD2"
  2786. cat "$te"
  2787. numFAIL=$((numFAIL+1))
  2788. listFAIL="$listFAIL $N"
  2789. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2790. $PRINTF "$FAILED: diff:\n"
  2791. cat "$tdiff"
  2792. numFAIL=$((numFAIL+1))
  2793. listFAIL="$listFAIL $N"
  2794. else
  2795. $PRINTF "$OK\n"
  2796. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2797. numOK=$((numOK+1))
  2798. fi
  2799. kill $pid 2>/dev/null
  2800. fi
  2801. esac
  2802. PORT=$((PORT+1))
  2803. N=$((N+1))
  2804. # TCP6-LISTEN may also listen for IPv4 connections. Test if option
  2805. # ipv6-v6only=0 shows this behaviour.
  2806. NAME=IPV6ONLY0
  2807. case "$TESTS" in
  2808. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2809. TEST="$NAME: option ipv6-v6only=0 listens on IPv4"
  2810. # create a listening TCP6 socket and try to connect to the port using TCP4
  2811. if ! eval $NUMCOND; then :;
  2812. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  2813. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  2814. numCANT=$((numCANT+1))
  2815. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  2816. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  2817. numCANT=$((numCANT+1))
  2818. elif ! feat=$(testoptions ipv6-v6only); then
  2819. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  2820. numCANT=$((numCANT+1))
  2821. else
  2822. tf="$td/test$N.stdout"
  2823. te="$td/test$N.stderr"
  2824. tdiff="$td/test$N.diff"
  2825. tsl=$PORT
  2826. ts="127.0.0.1:$tsl"
  2827. da="test$N $(date) $RANDOM"
  2828. CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$tsl,ipv6-v6only=0,$REUSEADDR PIPE"
  2829. CMD2="$TRACE $SOCAT $opts STDIN!!STDOUT TCP4:$ts"
  2830. printf "test $F_n $TEST... " $N
  2831. $CMD1 >"$tf" 2>"${te}1" &
  2832. pid=$! # background process id
  2833. waittcp6port $tsl 1
  2834. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2835. if [ $? -ne 0 ]; then
  2836. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2837. echo "$CMD1 &"
  2838. echo "$CMD2"
  2839. cat "${te}1" "${te}2"
  2840. numFAIL=$((numFAIL+1))
  2841. listFAIL="$listFAIL $N"
  2842. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2843. $PRINTF "$FAILED: diff:\n"
  2844. cat "$tdiff"
  2845. numFAIL=$((numFAIL+1))
  2846. listFAIL="$listFAIL $N"
  2847. else
  2848. $PRINTF "$OK\n"
  2849. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2850. numOK=$((numOK+1))
  2851. fi
  2852. kill $pid 2>/dev/null
  2853. fi
  2854. esac
  2855. PORT=$((PORT+1))
  2856. N=$((N+1))
  2857. #set -vx
  2858. # TCP6-LISTEN may also listen for IPv4 connections. Test if option
  2859. # ipv6-v6only=1 turns off this behaviour.
  2860. NAME=IPV6ONLY1
  2861. case "$TESTS" in
  2862. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2863. TEST="$NAME: option ipv6-v6only=1 does not listen on IPv4"
  2864. if ! eval $NUMCOND; then :;
  2865. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  2866. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  2867. numCANT=$((numCANT+1))
  2868. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  2869. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  2870. numCANT=$((numCANT+1))
  2871. elif ! feat=$(testoptions ipv6-v6only); then
  2872. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  2873. numCANT=$((numCANT+1))
  2874. else
  2875. tf="$td/test$N.stdout"
  2876. te="$td/test$N.stderr"
  2877. tdiff="$td/test$N.diff"
  2878. tsl=$PORT
  2879. ts="127.0.0.1:$tsl"
  2880. da="test$N $(date) $RANDOM"
  2881. CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,$REUSEADDR PIPE"
  2882. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  2883. printf "test $F_n $TEST... " $N
  2884. $CMD1 >"$tf" 2>"${te}1" &
  2885. pid=$! # background process id
  2886. waittcp6port $tsl 1
  2887. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2888. if [ $? -eq 0 ]; then
  2889. $PRINTF "$FAILED:\n"
  2890. cat "${te}1" "${te}2"
  2891. numFAIL=$((numFAIL+1))
  2892. listFAIL="$listFAIL $N"
  2893. elif echo "$da" |diff - "$tf" >"$tdiff"; then
  2894. $PRINTF "$FAILED:\n"
  2895. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2896. numFAIL=$((numFAIL+1))
  2897. listFAIL="$listFAIL $N"
  2898. else
  2899. $PRINTF "$OK\n"
  2900. numOK=$((numOK+1))
  2901. fi
  2902. kill $pid; wait
  2903. wait
  2904. fi
  2905. esac
  2906. PORT=$((PORT+1))
  2907. N=$((N+1))
  2908. #set +vx
  2909. NAME=ENV_LISTEN_4
  2910. case "$TESTS" in
  2911. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2912. TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv4 preference on listen"
  2913. if ! eval $NUMCOND; then :;
  2914. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  2915. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  2916. numCANT=$((numCANT+1))
  2917. elif ! testaddrs ip6 >/dev/null || ! runstcp6 >/dev/null; then
  2918. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  2919. numCANT=$((numCANT+1))
  2920. elif ! feat=$(testoptions ipv6-v6only); then
  2921. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  2922. numCANT=$((numCANT+1))
  2923. else
  2924. tf="$td/test$N.stdout"
  2925. te="$td/test$N.stderr"
  2926. tdiff="$td/test$N.diff"
  2927. tsl=$PORT
  2928. ts="127.0.0.1:$tsl"
  2929. da="test$N $(date) $RANDOM"
  2930. CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
  2931. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  2932. printf "test $F_n $TEST... " $N
  2933. SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
  2934. pid=$! # background process id
  2935. waittcp4port $tsl 1
  2936. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2937. if [ $? -ne 0 ]; then
  2938. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2939. echo "$CMD1 &"
  2940. echo "$CMD2"
  2941. cat "${te}1" "${te}2"
  2942. numFAIL=$((numFAIL+1))
  2943. listFAIL="$listFAIL $N"
  2944. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2945. $PRINTF "$FAILED: diff:\n"
  2946. cat "$tdiff"
  2947. numFAIL=$((numFAIL+1))
  2948. listFAIL="$listFAIL $N"
  2949. else
  2950. $PRINTF "$OK\n"
  2951. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2952. numOK=$((numOK+1))
  2953. fi
  2954. kill $pid 2>/dev/null; wait
  2955. fi
  2956. esac
  2957. PORT=$((PORT+1))
  2958. N=$((N+1))
  2959. NAME=ENV_LISTEN_6
  2960. case "$TESTS" in
  2961. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  2962. TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv6 preference on listen"
  2963. if ! eval $NUMCOND; then :;
  2964. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  2965. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  2966. numCANT=$((numCANT+1))
  2967. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  2968. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  2969. numCANT=$((numCANT+1))
  2970. else
  2971. tf="$td/test$N.stdout"
  2972. te="$td/test$N.stderr"
  2973. tdiff="$td/test$N.diff"
  2974. tsl=$PORT
  2975. ts="[::1]:$tsl"
  2976. da="test$N $(date) $RANDOM"
  2977. CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
  2978. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
  2979. printf "test $F_n $TEST... " $N
  2980. SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
  2981. pid=$! # background process id
  2982. waittcp6port $tsl 1
  2983. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  2984. if [ $? -ne 0 ]; then
  2985. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  2986. echo "$CMD1 &"
  2987. echo "$CMD2"
  2988. cat "${te}1" "${te}2"
  2989. numFAIL=$((numFAIL+1))
  2990. listFAIL="$listFAIL $N"
  2991. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  2992. $PRINTF "$FAILED: diff:\n"
  2993. cat "$tdiff"
  2994. numFAIL=$((numFAIL+1))
  2995. listFAIL="$listFAIL $N"
  2996. else
  2997. $PRINTF "$OK\n"
  2998. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  2999. numOK=$((numOK+1))
  3000. fi
  3001. kill $pid 2>/dev/null; wait
  3002. fi
  3003. esac
  3004. PORT=$((PORT+1))
  3005. N=$((N+1))
  3006. NAME=LISTEN_OPTION_4
  3007. case "$TESTS" in
  3008. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  3009. TEST="$NAME: option -4 for IPv4 preference on listen"
  3010. if ! eval $NUMCOND; then :;
  3011. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3012. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  3013. numCANT=$((numCANT+1))
  3014. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  3015. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  3016. numCANT=$((numCANT+1))
  3017. elif ! feat=$(testoptions ipv6-v6only); then
  3018. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  3019. numCANT=$((numCANT+1))
  3020. else
  3021. tf="$td/test$N.stdout"
  3022. te="$td/test$N.stderr"
  3023. tdiff="$td/test$N.diff"
  3024. tsl=$PORT
  3025. ts="127.0.0.1:$tsl"
  3026. da="test$N $(date) $RANDOM"
  3027. CMD1="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,$REUSEADDR PIPE"
  3028. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  3029. printf "test $F_n $TEST... " $N
  3030. SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
  3031. pid=$! # background process id
  3032. waittcp4port $tsl 1
  3033. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  3034. if [ $? -ne 0 ]; then
  3035. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3036. echo "$CMD1 &"
  3037. echo "$CMD2"
  3038. cat "${te}1" "${te}2"
  3039. numFAIL=$((numFAIL+1))
  3040. listFAIL="$listFAIL $N"
  3041. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3042. $PRINTF "$FAILED: diff:\n"
  3043. cat "$tdiff"
  3044. numFAIL=$((numFAIL+1))
  3045. listFAIL="$listFAIL $N"
  3046. else
  3047. $PRINTF "$OK\n"
  3048. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3049. numOK=$((numOK+1))
  3050. fi
  3051. kill $pid 2>/dev/null; wait
  3052. fi
  3053. esac
  3054. PORT=$((PORT+1))
  3055. N=$((N+1))
  3056. NAME=LISTEN_OPTION_6
  3057. case "$TESTS" in
  3058. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  3059. TEST="$NAME: option -6 for IPv6 preference on listen"
  3060. if ! eval $NUMCOND; then :;
  3061. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3062. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  3063. numCANT=$((numCANT+1))
  3064. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  3065. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  3066. numCANT=$((numCANT+1))
  3067. else
  3068. tf="$td/test$N.stdout"
  3069. te="$td/test$N.stderr"
  3070. tdiff="$td/test$N.diff"
  3071. tsl=$PORT
  3072. ts="[::1]:$tsl"
  3073. da="test$N $(date) $RANDOM"
  3074. CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,$REUSEADDR PIPE"
  3075. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
  3076. printf "test $F_n $TEST... " $N
  3077. SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
  3078. pid=$! # background process id
  3079. waittcp6port $tsl 1
  3080. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  3081. if [ $? -ne 0 ]; then
  3082. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3083. echo "$CMD1 &"
  3084. echo "$CMD2"
  3085. cat "${te}1" "${te}2"
  3086. numFAIL=$((numFAIL+1))
  3087. listFAIL="$listFAIL $N"
  3088. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3089. $PRINTF "$FAILED: diff:\n"
  3090. cat "$tdiff"
  3091. numFAIL=$((numFAIL+1))
  3092. listFAIL="$listFAIL $N"
  3093. else
  3094. $PRINTF "$OK\n"
  3095. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3096. numOK=$((numOK+1))
  3097. fi
  3098. kill $pid 2>/dev/null; wait
  3099. wait
  3100. fi # feats
  3101. esac
  3102. PORT=$((PORT+1))
  3103. N=$((N+1))
  3104. NAME=LISTEN_PF_IP4
  3105. case "$TESTS" in
  3106. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  3107. TEST="$NAME: pf=4 overrides option -6 on listen"
  3108. if ! eval $NUMCOND; then :;
  3109. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3110. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  3111. numCANT=$((numCANT+1))
  3112. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  3113. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  3114. numCANT=$((numCANT+1))
  3115. elif ! feat=$(testoptions ipv6-v6only); then
  3116. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  3117. numCANT=$((numCANT+1))
  3118. else
  3119. tf="$td/test$N.stdout"
  3120. te="$td/test$N.stderr"
  3121. tdiff="$td/test$N.diff"
  3122. tsl=$PORT
  3123. ts="127.0.0.1:$tsl"
  3124. da="test$N $(date) $RANDOM"
  3125. CMD1="$TRACE $SOCAT $opts -6 TCP-LISTEN:$tsl,pf=ip4,$REUSEADDR PIPE"
  3126. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  3127. printf "test $F_n $TEST... " $N
  3128. SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
  3129. pid=$! # background process id
  3130. waittcp4port $tsl 1
  3131. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  3132. if [ $? -ne 0 ]; then
  3133. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3134. echo "$CMD1 &"
  3135. echo "$CMD2"
  3136. cat "${te}1" "${te}2"
  3137. numFAIL=$((numFAIL+1))
  3138. listFAIL="$listFAIL $N"
  3139. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3140. $PRINTF "$FAILED: diff:\n"
  3141. cat "$tdiff"
  3142. numFAIL=$((numFAIL+1))
  3143. listFAIL="$listFAIL $N"
  3144. else
  3145. $PRINTF "$OK\n"
  3146. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3147. numOK=$((numOK+1))
  3148. fi
  3149. kill $pid 2>/dev/null; wait
  3150. fi
  3151. esac
  3152. PORT=$((PORT+1))
  3153. N=$((N+1))
  3154. NAME=LISTEN_PF_IP6
  3155. case "$TESTS" in
  3156. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  3157. TEST="$NAME: pf=6 overrides option -4 on listen"
  3158. if ! eval $NUMCOND; then :;
  3159. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3160. $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
  3161. numCANT=$((numCANT+1))
  3162. elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
  3163. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  3164. numCANT=$((numCANT+1))
  3165. else
  3166. tf="$td/test$N.stdout"
  3167. te="$td/test$N.stderr"
  3168. tdiff="$td/test$N.diff"
  3169. tsl=$PORT
  3170. ts="[::1]:$tsl"
  3171. da="test$N $(date) $RANDOM"
  3172. CMD1="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,pf=ip6,$REUSEADDR PIPE"
  3173. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
  3174. printf "test $F_n $TEST... " $N
  3175. SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
  3176. pid=$! # background process id
  3177. waittcp6port $tsl 1
  3178. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  3179. if [ $? -ne 0 ]; then
  3180. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3181. echo "$CMD1 &"
  3182. echo "$CMD2"
  3183. cat "${te}1" "${te}2"
  3184. numFAIL=$((numFAIL+1))
  3185. listFAIL="$listFAIL $N"
  3186. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3187. $PRINTF "$FAILED: diff:\n"
  3188. cat "$tdiff"
  3189. numFAIL=$((numFAIL+1))
  3190. listFAIL="$listFAIL $N"
  3191. else
  3192. $PRINTF "$OK\n"
  3193. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3194. numOK=$((numOK+1))
  3195. fi
  3196. kill $pid 2>/dev/null; wait
  3197. fi ;; # NUMCOND, feats
  3198. esac
  3199. PORT=$((PORT+1))
  3200. N=$((N+1))
  3201. NAME=UDP4STREAM
  3202. case "$TESTS" in
  3203. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%$NAME%*)
  3204. TEST="$NAME: echo via connection to UDP V4 socket"
  3205. if ! eval $NUMCOND; then :; else
  3206. tf="$td/test$N.stdout"
  3207. te="$td/test$N.stderr"
  3208. tdiff="$td/test$N.diff"
  3209. tsl=$PORT
  3210. ts="$LOCALHOST:$tsl"
  3211. da="test$N $(date) $RANDOM"
  3212. CMD1="$TRACE $SOCAT $opts UDP4-LISTEN:$tsl,$REUSEADDR PIPE"
  3213. CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
  3214. printf "test $F_n $TEST... " $N
  3215. $CMD1 >"$tf" 2>"${te}1" &
  3216. pid1=$!
  3217. waitudp4port $tsl 1
  3218. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  3219. rc2=$?
  3220. kill $pid1 2>/dev/null; wait
  3221. if [ $rc2 -ne 0 ]; then
  3222. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3223. echo "$CMD1 &"
  3224. echo "$CMD2"
  3225. cat "${te}1" "${te}2"
  3226. numFAIL=$((numFAIL+1))
  3227. listFAIL="$listFAIL $N"
  3228. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3229. $PRINTF "$FAILED\n"
  3230. echo "$CMD1 &"
  3231. cat "${te}1"
  3232. echo "$CMD2"
  3233. cat "${te}2"
  3234. cat "$tdiff"
  3235. numFAIL=$((numFAIL+1))
  3236. listFAIL="$listFAIL $N"
  3237. else
  3238. $PRINTF "$OK\n"
  3239. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3240. numOK=$((numOK+1))
  3241. fi
  3242. fi ;; # NUMCOND
  3243. esac
  3244. PORT=$((PORT+1))
  3245. N=$((N+1))
  3246. NAME=UDP6STREAM
  3247. case "$TESTS" in
  3248. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
  3249. TEST="$NAME: echo via connection to UDP V6 socket"
  3250. if ! eval $NUMCOND; then :;
  3251. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  3252. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  3253. numCANT=$((numCANT+1))
  3254. else
  3255. tf="$td/test$N.stdout"
  3256. te="$td/test$N.stderr"
  3257. tdiff="$td/test$N.diff"
  3258. tsl=$PORT
  3259. ts="$LOCALHOST6:$tsl"
  3260. da="test$N $(date) $RANDOM"
  3261. CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR PIPE"
  3262. CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
  3263. printf "test $F_n $TEST... " $N
  3264. $CMD1 >"$tf" 2>"${te}1" &
  3265. pid1=$!
  3266. waitudp6port $tsl 1
  3267. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  3268. rc2=$?
  3269. kill $pid1 2>/dev/null; wait
  3270. if [ $rc2 -ne 0 ]; then
  3271. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3272. echo "$CMD1 &"
  3273. echo "$CMD2"
  3274. cat "${te}1" "${te}2"
  3275. numFAIL=$((numFAIL+1))
  3276. listFAIL="$listFAIL $N"
  3277. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3278. $PRINTF "$FAILED\n"
  3279. cat "$tdiff"
  3280. numFAIL=$((numFAIL+1))
  3281. listFAIL="$listFAIL $N"
  3282. else
  3283. $PRINTF "$OK\n"
  3284. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3285. numOK=$((numOK+1))
  3286. fi
  3287. fi ;; # ! testaddrs
  3288. esac
  3289. PORT=$((PORT+1))
  3290. N=$((N+1))
  3291. NAME=GOPENFILE
  3292. case "$TESTS" in
  3293. *%$N%*|*%functions%*|*%engine%*|*%gopen%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
  3294. TEST="$NAME: file opening with gopen"
  3295. if ! eval $NUMCOND; then :; else
  3296. tf1="$td/test$N.1.stdout"
  3297. tf2="$td/test$N.2.stdout"
  3298. te="$td/test$N.stderr"
  3299. tdiff="$td/test$N.diff"
  3300. da="test$N $(date) $RANDOM"
  3301. echo "$da" >$tf1
  3302. CMD="$TRACE $SOCAT $opts $tf1!!/dev/null /dev/null,ignoreeof!!-"
  3303. printf "test $F_n $TEST... " $N
  3304. $CMD >"$tf2" 2>"$te"
  3305. if [ $? -ne 0 ]; then
  3306. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3307. echo "$CMD"
  3308. cat "$te"
  3309. numFAIL=$((numFAIL+1))
  3310. listFAIL="$listFAIL $N"
  3311. elif ! diff "$tf1" "$tf2" >"$tdiff"; then
  3312. $PRINTF "$FAILED: diff:\n"
  3313. cat "$tdiff"
  3314. numFAIL=$((numFAIL+1))
  3315. listFAIL="$listFAIL $N"
  3316. else
  3317. $PRINTF "$OK\n"
  3318. if [ -n "$debug" ]; then cat $te; fi
  3319. numOK=$((numOK+1))
  3320. fi
  3321. fi # NUMCOND
  3322. esac
  3323. N=$((N+1))
  3324. NAME=GOPENPIPE
  3325. case "$TESTS" in
  3326. *%$N%*|*%functions%*|*%gopen%*|*%pipe%*|*%ignoreeof%*|*%$NAME%*)
  3327. TEST="$NAME: pipe opening with gopen for reading"
  3328. if ! eval $NUMCOND; then :; else
  3329. tp="$td/pipe$N"
  3330. tf="$td/test$N.stdout"
  3331. te="$td/test$N.stderr"
  3332. tdiff="$td/test$N.diff"
  3333. da="test$N $(date) $RANDOM"
  3334. CMD="$TRACE $SOCAT $opts $tp!!/dev/null /dev/null,ignoreeof!!$tf"
  3335. printf "test $F_n $TEST... " $N
  3336. #mknod $tp p # no mknod p on FreeBSD
  3337. mkfifo $tp
  3338. $CMD >$tf 2>"$te" &
  3339. #($CMD >$tf 2>"$te" || rm -f "$tp") 2>/dev/null &
  3340. bg=$! # background process id
  3341. usleep $MICROS
  3342. if [ ! -p "$tp" ]; then
  3343. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3344. echo "$CMD"
  3345. cat "$te"
  3346. numFAIL=$((numFAIL+1))
  3347. listFAIL="$listFAIL $N"
  3348. else
  3349. #echo "$da" >"$tp" # might hang forever
  3350. echo "$da" >"$tp" & export pid=$!; (sleep 1; kill $pid 2>/dev/null) &
  3351. # Solaris needs more time:
  3352. sleep 1
  3353. kill "$bg" 2>/dev/null; wait
  3354. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3355. if [ -s "$te" ]; then
  3356. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3357. echo "$CMD"
  3358. cat "$te"
  3359. else
  3360. $PRINTF "$FAILED: diff:\n"
  3361. cat "$tdiff"
  3362. fi
  3363. numFAIL=$((numFAIL+1))
  3364. listFAIL="$listFAIL $N"
  3365. else
  3366. $PRINTF "$OK\n"
  3367. if [ -n "$debug" ]; then cat $te; fi
  3368. numOK=$((numOK+1))
  3369. fi
  3370. fi
  3371. wait
  3372. fi # NUMCOND
  3373. esac
  3374. N=$((N+1))
  3375. NAME=GOPENUNIXSTREAM
  3376. case "$TESTS" in
  3377. *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%listen%*|*%$NAME%*)
  3378. TEST="$NAME: GOPEN on UNIX stream socket"
  3379. if ! eval $NUMCOND; then :; else
  3380. ts="$td/test$N.socket"
  3381. tf="$td/test$N.stdout"
  3382. te="$td/test$N.stderr"
  3383. tdiff="$td/test$N.diff"
  3384. da1="test$N $(date) $RANDOM"
  3385. #establish a listening unix socket in background
  3386. SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
  3387. #make a connection
  3388. CMD="$TRACE $SOCAT $opts - $ts"
  3389. $PRINTF "test $F_n $TEST... " $N
  3390. eval "$SRV 2>${te}s &"
  3391. pids=$!
  3392. waitfile "$ts"
  3393. echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
  3394. if [ $? -ne 0 ]; then
  3395. kill "$pids" 2>/dev/null
  3396. $PRINTF "$FAILED:\n"
  3397. echo "$SRV &"
  3398. cat "${te}s"
  3399. echo "$CMD"
  3400. cat "${te}1"
  3401. numFAIL=$((numFAIL+1))
  3402. listFAIL="$listFAIL $N"
  3403. elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
  3404. kill "$pids" 2>/dev/null
  3405. $PRINTF "$FAILED:\n"
  3406. echo "$SRV &"
  3407. cat "${te}s"
  3408. echo "$CMD"
  3409. cat "${te}1"
  3410. cat "$tdiff"
  3411. numFAIL=$((numFAIL+1))
  3412. listFAIL="$listFAIL $N"
  3413. else
  3414. $PRINTF "$OK\n"
  3415. if [ -n "$debug" ]; then cat $te; fi
  3416. numOK=$((numOK+1))
  3417. fi # !(rc -ne 0)
  3418. wait
  3419. fi # NUMCOND
  3420. esac
  3421. N=$((N+1))
  3422. NAME=GOPENUNIXDGRAM
  3423. case "$TESTS" in
  3424. *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%dgram%*|*%$NAME%*)
  3425. TEST="$NAME: GOPEN on UNIX datagram socket"
  3426. if ! eval $NUMCOND; then :; else
  3427. ts="$td/test$N.socket"
  3428. tf="$td/test$N.stdout"
  3429. te="$td/test$N.stderr"
  3430. tdiff="$td/test$N.diff"
  3431. da1="test$N $(date) $RANDOM"
  3432. #establish a receiving unix socket in background
  3433. SRV="$TRACE $SOCAT $opts -u -lpserver UNIX-RECV:\"$ts\" file:\"$tf\",create"
  3434. #make a connection
  3435. CMD="$TRACE $SOCAT $opts -u - $ts"
  3436. $PRINTF "test $F_n $TEST... " $N
  3437. eval "$SRV 2>${te}s &"
  3438. pids=$!
  3439. waitfile "$ts"
  3440. echo "$da1" |eval "$CMD" 2>"${te}1"
  3441. waitfile -s "$tf"
  3442. if [ $? -ne 0 ]; then
  3443. $PRINTF "$FAILED:\n"
  3444. echo "$SRV &"
  3445. cat "${te}s"
  3446. echo "$CMD"
  3447. cat "${te}1"
  3448. numFAIL=$((numFAIL+1))
  3449. listFAIL="$listFAIL $N"
  3450. elif ! echo "$da1" |diff - "${tf}" >"$tdiff"; then
  3451. $PRINTF "$FAILED:\n"
  3452. echo "$SRV &"
  3453. cat "${te}s"
  3454. echo "$CMD"
  3455. cat "${te}1"
  3456. cat "$tdiff"
  3457. numFAIL=$((numFAIL+1))
  3458. listFAIL="$listFAIL $N"
  3459. else
  3460. $PRINTF "$OK\n"
  3461. if [ -n "$debug" ]; then cat $te; fi
  3462. numOK=$((numOK+1))
  3463. fi # !(rc -ne 0)
  3464. kill "$pids" 2>/dev/null; wait
  3465. fi ;; # NUMCOND
  3466. esac
  3467. N=$((N+1))
  3468. NAME=IGNOREEOF
  3469. case "$TESTS" in
  3470. *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
  3471. TEST="$NAME: ignoreeof on file"
  3472. if ! eval $NUMCOND; then :; else
  3473. ti="$td/test$N.file"
  3474. tf="$td/test$N.stdout"
  3475. te="$td/test$N.stderr"
  3476. tdiff="$td/test$N.diff"
  3477. da="test$N $(date) $RANDOM"
  3478. CMD="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
  3479. printf "test $F_n $TEST... " $N
  3480. touch "$ti"
  3481. $CMD >"$tf" 2>"$te" &
  3482. bg=$!
  3483. usleep 500000
  3484. echo "$da" >>"$ti"
  3485. sleep 1
  3486. kill $bg 2>/dev/null; wait
  3487. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3488. $PRINTF "$FAILED: diff:\n"
  3489. cat "$tdiff"
  3490. listFAIL="$listFAIL $N"
  3491. numFAIL=$((numFAIL+1))
  3492. else
  3493. $PRINTF "$OK\n"
  3494. if [ -n "$debug" ]; then cat $te; fi
  3495. numOK=$((numOK+1))
  3496. fi
  3497. fi ;; # NUMCOND
  3498. esac
  3499. N=$((N+1))
  3500. NAME=IGNOREEOF_REV
  3501. case "$TESTS" in
  3502. *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
  3503. TEST="$NAME: ignoreeof on file right-to-left"
  3504. if ! eval $NUMCOND; then :; else
  3505. ti="$td/test$N.file"
  3506. tf="$td/test$N.stdout"
  3507. te="$td/test$N.stderr"
  3508. tdiff="$td/test$N.diff"
  3509. da="test$N $(date) $RANDOM"
  3510. CMD="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
  3511. printf "test $F_n $TEST... " $N
  3512. touch "$ti"
  3513. $CMD >"$tf" 2>"$te" &
  3514. bg=$!
  3515. usleep 500000
  3516. echo "$da" >>"$ti"
  3517. sleep 1
  3518. kill $bg 2>/dev/null
  3519. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3520. $PRINTF "$FAILED: diff:\n"
  3521. cat "$tdiff"
  3522. listFAIL="$listFAIL $N"
  3523. numFAIL=$((numFAIL+1))
  3524. else
  3525. $PRINTF "$OK\n"
  3526. if [ -n "$debug" ]; then cat $te; fi
  3527. numOK=$((numOK+1))
  3528. fi
  3529. wait
  3530. fi ;; # NUMCOND
  3531. esac
  3532. N=$((N+1))
  3533. NAME=EXECIGNOREEOF
  3534. case "$TESTS" in
  3535. *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
  3536. TEST="$NAME: exec against address with ignoreeof"
  3537. if ! eval $NUMCOND; then :; else
  3538. tf="$td/test$N.stdout"
  3539. te="$td/test$N.stderr"
  3540. CMD="$TRACE $SOCAT $opts -lf /dev/null EXEC:$TRUE /dev/null,ignoreeof"
  3541. printf "test $F_n $TEST... " $N
  3542. $CMD >"$tf" 2>"$te"
  3543. if [ -s "$te" ]; then
  3544. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3545. echo "$CMD"
  3546. cat "$te"
  3547. numFAIL=$((numFAIL+1))
  3548. listFAIL="$listFAIL $N"
  3549. else
  3550. $PRINTF "$OK\n"
  3551. if [ -n "$debug" ]; then cat $te; fi
  3552. numOK=$((numOK+1))
  3553. fi
  3554. fi ;; # NUMCOND
  3555. esac
  3556. N=$((N+1))
  3557. NAME=FAKEPTY
  3558. case "$TESTS" in
  3559. *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
  3560. TEST="$NAME: generation of pty for other processes"
  3561. if ! eval $NUMCOND; then :;
  3562. elif ! testaddrs pty >/dev/null; then
  3563. $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  3564. numCANT=$((numCANT+1))
  3565. else
  3566. tt="$td/pty$N"
  3567. tf="$td/test$N.stdout"
  3568. te="$td/test$N.stderr"
  3569. tdiff="$td/test$N.diff"
  3570. da="test$N $(date) $RANDOM"
  3571. CMD1="$TRACE $SOCAT $opts pty,link=$tt pipe"
  3572. CMD2="$TRACE $SOCAT $opts - $tt,$PTYOPTS2"
  3573. printf "test $F_n $TEST... " $N
  3574. $CMD1 2>"${te}1" &
  3575. pid=$! # background process id
  3576. waitfile "$tt"
  3577. # this hangs on HP-UX, so we use a timeout
  3578. (echo "$da"; sleep 1) |$CMD2 >$tf 2>"${te}2" &
  3579. rc2=$!
  3580. #sleep 5 && kill $rc2 2>/dev/null &
  3581. wait $rc2
  3582. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3583. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3584. echo "$CMD1 &"
  3585. sleep 1
  3586. echo "$CMD2"
  3587. cat "${te}1"
  3588. cat "${te}2"
  3589. cat "$tdiff"
  3590. numFAIL=$((numFAIL+1))
  3591. listFAIL="$listFAIL $N"
  3592. else
  3593. $PRINTF "$OK\n"
  3594. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3595. numOK=$((numOK+1))
  3596. fi
  3597. kill $pid 2>/dev/null; wait
  3598. fi ;; # NUMCOND, feats
  3599. esac
  3600. N=$((N+1))
  3601. NAME=O_TRUNC
  3602. case "$TESTS" in
  3603. *%$N%*|*%functions%*|*%$NAME%*)
  3604. TEST="$NAME: option o-trunc"
  3605. if ! eval $NUMCOND; then :; else
  3606. ff="$td/test$N.file"
  3607. tf="$td/test$N.stdout"
  3608. te="$td/test$N.stderr"
  3609. tdiff="$td/test$N.diff"
  3610. da="test$N $(date) $RANDOM"
  3611. CMD="$TRACE $SOCAT -u $opts - open:$ff,append,o-trunc"
  3612. printf "test $F_n $TEST... " $N
  3613. rm -f $ff; $ECHO "prefix-\c" >$ff
  3614. echo "$da" |$CMD >$tf 2>"$te"
  3615. rc0=$?
  3616. if ! [ $rc0 = 0 ] ||
  3617. ! echo "$da" |diff - $ff >"$tdiff"; then
  3618. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3619. echo "$CMD"
  3620. cat "$te"
  3621. cat "$tdiff"
  3622. numFAIL=$((numFAIL+1))
  3623. listFAIL="$listFAIL $N"
  3624. else
  3625. $PRINTF "$OK\n"
  3626. if [ -n "$debug" ]; then cat $te; fi
  3627. numOK=$((numOK+1))
  3628. fi
  3629. fi ;; # NUMCOND
  3630. esac
  3631. N=$((N+1))
  3632. NAME=FTRUNCATE
  3633. case "$TESTS" in
  3634. *%$N%*|*%functions%*|*%$NAME%*)
  3635. TEST="$NAME: option ftruncate"
  3636. if ! eval $NUMCOND; then :; else
  3637. ff="$td/test$N.file"
  3638. tf="$td/test$N.stdout"
  3639. te="$td/test$N.stderr"
  3640. tdiff="$td/test$N.diff"
  3641. da="test$N $(date) $RANDOM"
  3642. CMD="$TRACE $SOCAT -u $opts - open:$ff,append,ftruncate=0"
  3643. printf "test $F_n $TEST... " $N
  3644. rm -f $ff; $ECHO "prefix-\c" >$ff
  3645. if ! echo "$da" |$CMD >$tf 2>"$te" ||
  3646. ! echo "$da" |diff - $ff >"$tdiff"; then
  3647. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3648. echo "$CMD"
  3649. cat "$te"
  3650. cat "$tdiff"
  3651. numFAIL=$((numFAIL+1))
  3652. listFAIL="$listFAIL $N"
  3653. else
  3654. $PRINTF "$OK\n"
  3655. if [ -n "$debug" ]; then cat $te; fi
  3656. numOK=$((numOK+1))
  3657. fi
  3658. fi ;; # NUMCOND
  3659. esac
  3660. N=$((N+1))
  3661. NAME=RIGHTTOLEFT
  3662. case "$TESTS" in
  3663. *%$N%*|*%functions%*|*%$NAME%*)
  3664. TEST="$NAME: unidirectional throughput from stdin to stdout, right to left"
  3665. testecho "$N" "$TEST" "stdout" "stdin" "$opts -U"
  3666. esac
  3667. N=$((N+1))
  3668. NAME=CHILDDEFAULT
  3669. case "$TESTS" in
  3670. *%$N%*|*%functions%*|*%$NAME%*)
  3671. if ! eval $NUMCOND; then :; else
  3672. TEST="$NAME: child process default properties"
  3673. tf="$td/test$N.stdout"
  3674. te="$td/test$N.stderr"
  3675. CMD="$TRACE $SOCAT $opts -u exec:$PROCAN -"
  3676. printf "test $F_n $TEST... " $N
  3677. $CMD >$tf 2>$te
  3678. MYPID=`expr "\`grep "process id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
  3679. MYPPID=`expr "\`grep "process parent id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
  3680. MYPGID=`expr "\`grep "process group id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
  3681. MYSID=`expr "\`grep "process session id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
  3682. #echo "PID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
  3683. if [ "$MYPID" = "$MYPPID" -o "$MYPID" = "$MYPGID" -o "$MYPID" = "$MYSID" -o \
  3684. "$MYPPID" = "$MYPGID" -o "$MYPPID" = "$MYSID" -o "$MYPGID" = "$MYSID" ];
  3685. then
  3686. $PRINTF "$FAILED:\n"
  3687. echo "$CMD"
  3688. cat "$te"
  3689. numFAIL=$((numFAIL+1))
  3690. listFAIL="$listFAIL $N"
  3691. else
  3692. $PRINTF "$OK\n"
  3693. numOK=$((numOK+1))
  3694. fi
  3695. fi ;; # NUMCOND
  3696. esac
  3697. N=$((N+1))
  3698. NAME=CHILDSETSID
  3699. case "$TESTS" in
  3700. *%$N%*|*%functions%*|*%$NAME%*)
  3701. TEST="$NAME: child process with setsid"
  3702. if ! eval $NUMCOND; then :; else
  3703. tf="$td/test$N.stdout"
  3704. te="$td/test$N.stderr"
  3705. CMD="$TRACE $SOCAT $opts -u exec:$PROCAN,setsid -"
  3706. printf "test $F_n $TEST... " $N
  3707. $CMD >$tf 2>$te
  3708. MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3709. MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3710. MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3711. MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3712. #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
  3713. # PID, PGID, and SID must be the same
  3714. if [ "$MYPID" = "$MYPPID" -o \
  3715. "$MYPID" != "$MYPGID" -o "$MYPID" != "$MYSID" ];
  3716. then
  3717. $PRINTF "$FAILED\n"
  3718. echo "$CMD"
  3719. cat "$te"
  3720. numFAIL=$((numFAIL+1))
  3721. listFAIL="$listFAIL $N"
  3722. else
  3723. $PRINTF "$OK\n"
  3724. numOK=$((numOK+1))
  3725. fi
  3726. fi ;; # NUMCOND
  3727. esac
  3728. N=$((N+1))
  3729. NAME=MAINSETSID
  3730. case "$TESTS" in
  3731. *%$N%*|*%functions%*|*%$NAME%*)
  3732. TEST="$NAME: main process with setsid"
  3733. if ! eval $NUMCOND; then :; else
  3734. tf="$td/test$N.stdout"
  3735. te="$td/test$N.stderr"
  3736. CMD="$TRACE $SOCAT $opts -U -,setsid exec:$PROCAN"
  3737. printf "test $F_n $TEST... " $N
  3738. $CMD >$tf 2>$te
  3739. MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3740. MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3741. MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3742. MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
  3743. #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
  3744. # PPID, PGID, and SID must be the same
  3745. if [ "$MYPID" = "$MYPPID" -o \
  3746. "$MYPPID" != "$MYPGID" -o "$MYPPID" != "$MYSID" ];
  3747. then
  3748. $PRINTF "$FAILED\n"
  3749. echo "$CMD"
  3750. cat "$te"
  3751. numFAIL=$((numFAIL+1))
  3752. listFAIL="$listFAIL $N"
  3753. else
  3754. $PRINTF "$OK\n"
  3755. numOK=$((numOK+1))
  3756. fi
  3757. fi ;; # NUMCOND
  3758. esac
  3759. N=$((N+1))
  3760. NAME=OPENSSL_TCP4
  3761. case "$TESTS" in
  3762. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  3763. TEST="$NAME: openssl connect"
  3764. if ! eval $NUMCOND; then :;
  3765. elif ! testaddrs openssl >/dev/null; then
  3766. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  3767. numCANT=$((numCANT+1))
  3768. elif ! type openssl >/dev/null 2>&1; then
  3769. $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
  3770. numCANT=$((numCANT+1))
  3771. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3772. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  3773. numCANT=$((numCANT+1))
  3774. else
  3775. gentestcert testsrv
  3776. tf="$td/test$N.stdout"
  3777. te="$td/test$N.stderr"
  3778. tdiff="$td/test$N.diff"
  3779. da="test$N $(date) $RANDOM"
  3780. CMD2="$TRACE $SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe"
  3781. #! CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT"
  3782. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
  3783. printf "test $F_n $TEST... " $N
  3784. eval "$CMD2 2>\"${te}1\" &"
  3785. pid=$! # background process id
  3786. # this might timeout when openssl opens tcp46 port like " :::$PORT"
  3787. waittcp4port $PORT
  3788. echo "$da" |$CMD >$tf 2>"${te}2"
  3789. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3790. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3791. echo "$CMD2 &"
  3792. echo "$CMD"
  3793. cat "${te}1"
  3794. cat "${te}2"
  3795. cat "$tdiff"
  3796. numFAIL=$((numFAIL+1))
  3797. listFAIL="$listFAIL $N"
  3798. else
  3799. $PRINTF "$OK\n"
  3800. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3801. numOK=$((numOK+1))
  3802. fi
  3803. kill $pid 2>/dev/null; wait
  3804. fi ;; # NUMCOND, feats
  3805. esac
  3806. PORT=$((PORT+1))
  3807. N=$((N+1))
  3808. NAME=OPENSSLLISTEN_TCP4
  3809. case "$TESTS" in
  3810. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  3811. TEST="$NAME: openssl listen"
  3812. if ! eval $NUMCOND; then :;
  3813. elif ! testaddrs openssl >/dev/null; then
  3814. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  3815. numCANT=$((numCANT+1))
  3816. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3817. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  3818. numCANT=$((numCANT+1))
  3819. else
  3820. gentestcert testsrv
  3821. tf="$td/test$N.stdout"
  3822. te="$td/test$N.stderr"
  3823. tdiff="$td/test$N.diff"
  3824. da="test$N $(date) $RANDOM"
  3825. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
  3826. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
  3827. printf "test $F_n $TEST... " $N
  3828. eval "$CMD2 2>\"${te}1\" &"
  3829. pid=$! # background process id
  3830. waittcp4port $PORT
  3831. echo "$da" |$CMD >$tf 2>"${te}2"
  3832. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3833. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3834. echo "$CMD2 &"
  3835. echo "$CMD"
  3836. cat "${te}1"
  3837. cat "${te}2"
  3838. cat "$tdiff"
  3839. numFAIL=$((numFAIL+1))
  3840. listFAIL="$listFAIL $N"
  3841. else
  3842. $PRINTF "$OK\n"
  3843. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3844. numOK=$((numOK+1))
  3845. fi
  3846. kill $pid 2>/dev/null
  3847. wait
  3848. fi ;; # NUMCOND, feats
  3849. esac
  3850. PORT=$((PORT+1))
  3851. N=$((N+1))
  3852. NAME=OPENSSLLISTEN_TCP6
  3853. case "$TESTS" in
  3854. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
  3855. TEST="$NAME: openssl listen"
  3856. if ! eval $NUMCOND; then :;
  3857. elif ! testaddrs openssl >/dev/null; then
  3858. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  3859. numCANT=$((numCANT+1))
  3860. elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  3861. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
  3862. numCANT=$((numCANT+1))
  3863. else
  3864. gentestcert testsrv
  3865. tf="$td/test$N.stdout"
  3866. te="$td/test$N.stderr"
  3867. tdiff="$td/test$N.diff"
  3868. da="test$N $(date) $RANDOM"
  3869. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
  3870. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD"
  3871. printf "test $F_n $TEST... " $N
  3872. eval "$CMD2 2>\"${te}1\" &"
  3873. pid=$! # background process id
  3874. waittcp6port $PORT
  3875. echo "$da" |$CMD >$tf 2>"${te}2"
  3876. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3877. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3878. echo "$CMD2 &"
  3879. echo "$CMD"
  3880. cat "${te}1"
  3881. cat "${te}2"
  3882. cat "$tdiff"
  3883. numFAIL=$((numFAIL+1))
  3884. listFAIL="$listFAIL $N"
  3885. else
  3886. $PRINTF "$OK\n"
  3887. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3888. numOK=$((numOK+1))
  3889. fi
  3890. kill $pid 2>/dev/null
  3891. wait
  3892. fi ;; # NUMCOND, feats
  3893. esac
  3894. PORT=$((PORT+1))
  3895. N=$((N+1))
  3896. while read NAMEKEYW FEAT RUNS TESTTMPL PEERTMPL WAITTMPL; do
  3897. if [ -z "$NAMEKEYW" ] || [[ "$NAMEKEYW" == \#* ]]; then continue; fi
  3898. export ts="$td/test$N.socket"
  3899. WAITTMPL="$(echo "$WAITTMPL" |sed -e 's/\040/ /g')"
  3900. TESTADDR=$(eval echo $TESTTMPL)
  3901. PEERADDR=$(eval echo $PEERTMPL)
  3902. WAITCMD=$(eval echo $WAITTMPL)
  3903. TESTKEYW=${TESTADDR%%:*}
  3904. # does our address implementation support halfclose?
  3905. NAME=${NAMEKEYW}_HALFCLOSE
  3906. case "$TESTS" in
  3907. *%$N%*|*%functions%*|*%$FEAT%*|*%socket%*|*%halfclose%*|*%$NAME%*)
  3908. TEST="$NAME: $TESTKEYW half close"
  3909. # have a "peer" socat "peer" that executes "$OD_C" and see if EOF on the
  3910. # connecting socat brings the result of od
  3911. if ! eval $NUMCOND; then :;
  3912. elif [ "$FEAT" != ',' ] && ! testaddrs "$FEAT" >/dev/null; then
  3913. $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
  3914. numCANT=$((numCANT+1))
  3915. elif ! runs$RUNS >/dev/null; then
  3916. $PRINTF "test $F_n $TEST... ${YELLOW}$RUNS not available${NORMAL}\n" $N
  3917. numCANT=$((numCANT+1))
  3918. else
  3919. tf="$td/test$N.stdout"
  3920. te="$td/test$N.stderr"
  3921. tdiff="$td/test$N.diff"
  3922. da="test$N $(date) $RANDOM"
  3923. CMD2="$TRACE $SOCAT $opts \"$PEERADDR\" EXEC:'$OD_C'"
  3924. CMD="$TRACE $SOCAT -T1 $opts -t 1 - $TESTADDR"
  3925. printf "test $F_n $TEST... " $N
  3926. eval "$CMD2 2>\"${te}1\" &"
  3927. pid=$! # background process id
  3928. $WAITCMD
  3929. echo "$da" |$CMD >$tf 2>"${te}2"
  3930. if ! echo "$da" |$OD_C |diff - "$tf" >"$tdiff"; then
  3931. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3932. echo "$CMD2 &"
  3933. echo "$CMD"
  3934. cat "${te}1"
  3935. cat "${te}2"
  3936. cat "$tdiff"
  3937. numFAIL=$((numFAIL+1))
  3938. listFAIL="$listFAIL $N"
  3939. else
  3940. $PRINTF "$OK\n"
  3941. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  3942. numOK=$((numOK+1))
  3943. fi
  3944. kill $pid 2>/dev/null
  3945. wait
  3946. fi ;; # NUMCOND, feats
  3947. esac
  3948. PORT=$((PORT+1))
  3949. N=$((N+1))
  3950. done <<<"
  3951. UNIXCONNECT , unix UNIX-CONNECT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
  3952. UNIXCLIENT , unix UNIX-CLIENT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
  3953. GOPEN_UNIXSTREAM , unix GOPEN:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
  3954. UNIXLISTEN , unix UNIX-LISTEN:\$ts UNIX-CONNECT:\$ts,retry=3 sleep\040\1
  3955. TCP4CONNECT , tcp4 TCP4-CONNECT:\$LOCALHOST:\$PORT TCP4-LISTEN:\$PORT,$REUSEADDR waittcp4port\040\$PORT
  3956. TCP4LISTEN , tcp4 TCP4-LISTEN:\$PORT,$REUSEADDR TCP4-CONNECT:\$LOCALHOST:\$PORT,retry=3
  3957. TCP6CONNECT , tcp6 TCP6-CONNECT:\$LOCALHOST6:\$PORT TCP6-LISTEN:\$PORT,$REUSEADDR waittcp6port\040\$PORT
  3958. TCP6LISTEN , tcp6 TCP6-LISTEN:\$PORT,$REUSEADDR TCP6-CONNECT:\$LOCALHOST6:\$PORT,retry=3
  3959. OPENSSL4CLIENT OPENSSL tcp4 OPENSSL:\$LOCALHOST:\$PORT,verify=0 OPENSSL-LISTEN:\$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp4port\040\$PORT
  3960. OPENSSL4SERVER OPENSSL tcp4 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST:\$PORT,$REUSEADDR,verify=0,retry=3
  3961. OPENSSL6CLIENT OPENSSL tcp6 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0 OPENSSL-LISTEN:\$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp6port\040\$PORT
  3962. OPENSSL6SERVER OPENSSL tcp6 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,$REUSEADDR,verify=0,retry=3
  3963. "
  3964. NAME=OPENSSL_SERVERAUTH
  3965. case "$TESTS" in
  3966. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  3967. TEST="$NAME: openssl server authentication"
  3968. if ! eval $NUMCOND; then :;
  3969. elif ! testaddrs openssl >/dev/null; then
  3970. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  3971. numCANT=$((numCANT+1))
  3972. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  3973. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  3974. numCANT=$((numCANT+1))
  3975. else
  3976. gentestcert testsrv
  3977. gentestcert testcli
  3978. tf="$td/test$N.stdout"
  3979. te="$td/test$N.stderr"
  3980. tdiff="$td/test$N.diff"
  3981. da="test$N $(date) $RANDOM"
  3982. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
  3983. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD"
  3984. printf "test $F_n $TEST... " $N
  3985. eval "$CMD2 2>\"${te}1\" &"
  3986. pid=$! # background process id
  3987. waittcp4port $PORT
  3988. echo "$da" |$CMD >$tf 2>"${te}2"
  3989. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  3990. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  3991. echo "$CMD2 &"
  3992. echo "$CMD"
  3993. cat "${te}1"
  3994. cat "${te}2"
  3995. cat "$tdiff"
  3996. numFAIL=$((numFAIL+1))
  3997. listFAIL="$listFAIL $N"
  3998. else
  3999. $PRINTF "$OK\n"
  4000. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4001. numOK=$((numOK+1))
  4002. fi
  4003. kill $pid 2>/dev/null
  4004. wait
  4005. fi ;; # NUMCOND, feats
  4006. esac
  4007. PORT=$((PORT+1))
  4008. N=$((N+1))
  4009. NAME=OPENSSL_CLIENTAUTH
  4010. case "$TESTS" in
  4011. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  4012. TEST="$NAME: openssl client authentication"
  4013. if ! eval $NUMCOND; then :;
  4014. elif ! testaddrs openssl >/dev/null; then
  4015. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  4016. numCANT=$((numCANT+1))
  4017. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  4018. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  4019. numCANT=$((numCANT+1))
  4020. else
  4021. gentestcert testsrv
  4022. gentestcert testcli
  4023. tf="$td/test$N.stdout"
  4024. te="$td/test$N.stderr"
  4025. tdiff="$td/test$N.diff"
  4026. da="test$N $(date) $RANDOM"
  4027. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe"
  4028. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD"
  4029. printf "test $F_n $TEST... " $N
  4030. eval "$CMD2 2>\"${te}1\" &"
  4031. pid=$! # background process id
  4032. waittcp4port $PORT
  4033. echo "$da" |$CMD >$tf 2>"${te}2"
  4034. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4035. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4036. echo "$CMD2 &"
  4037. echo "$CMD"
  4038. cat "${te}1"
  4039. cat "${te}2"
  4040. cat "$tdiff"
  4041. numFAIL=$((numFAIL+1))
  4042. listFAIL="$listFAIL $N"
  4043. else
  4044. $PRINTF "$OK\n"
  4045. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4046. numOK=$((numOK+1))
  4047. fi
  4048. kill $pid 2>/dev/null
  4049. wait
  4050. fi ;; # NUMCOND, feats
  4051. esac
  4052. PORT=$((PORT+1))
  4053. N=$((N+1))
  4054. NAME=OPENSSL_FIPS_BOTHAUTH
  4055. case "$TESTS" in
  4056. *%$N%*|*%functions%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  4057. TEST="$NAME: OpenSSL+FIPS client and server authentication"
  4058. if ! eval $NUMCOND; then :;
  4059. elif ! testaddrs openssl >/dev/null; then
  4060. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  4061. numCANT=$((numCANT+1))
  4062. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  4063. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  4064. numCANT=$((numCANT+1))
  4065. elif ! testoptions fips >/dev/null; then
  4066. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
  4067. numCANT=$((numCANT+1))
  4068. else
  4069. OPENSSL_FIPS=1 gentestcert testsrvfips
  4070. OPENSSL_FIPS=1 gentestcert testclifips
  4071. tf="$td/test$N.stdout"
  4072. te="$td/test$N.stderr"
  4073. tdiff="$td/test$N.diff"
  4074. da="test$N $(date) $RANDOM"
  4075. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe"
  4076. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD"
  4077. printf "test $F_n $TEST... " $N
  4078. eval "$CMD2 2>\"${te}1\" &"
  4079. pid=$! # background process id
  4080. waittcp4port $PORT
  4081. echo "$da" |$CMD >$tf 2>"${te}2"
  4082. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4083. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4084. echo "$CMD2 &"
  4085. echo "$CMD"
  4086. cat "${te}1"
  4087. cat "${te}2"
  4088. cat "$tdiff"
  4089. numFAIL=$((numFAIL+1))
  4090. listFAIL="$listFAIL $N"
  4091. else
  4092. $PRINTF "$OK\n"
  4093. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4094. numOK=$((numOK+1))
  4095. fi
  4096. kill $pid 2>/dev/null
  4097. wait
  4098. fi ;; # NUMCOND, feats
  4099. esac
  4100. PORT=$((PORT+1))
  4101. N=$((N+1))
  4102. NAME=OPENSSL_COMPRESS
  4103. case "$TESTS" in
  4104. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  4105. TEST="$NAME: OpenSSL compression"
  4106. if ! eval $NUMCOND; then :;
  4107. elif ! testaddrs openssl >/dev/null; then
  4108. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  4109. numCANT=$((numCANT+1))
  4110. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  4111. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  4112. numCANT=$((numCANT+1))
  4113. elif ! testoptions openssl-compress >/dev/null; then
  4114. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL compression option not available${NORMAL}\n" $N
  4115. numCANT=$((numCANT+1))
  4116. else
  4117. gentestcert testsrv
  4118. printf "test $F_n $TEST... " $N
  4119. tf="$td/test$N.stdout"
  4120. te="$td/test$N.stderr"
  4121. tdiff="$td/test$N.diff"
  4122. da="test$N $(date) $RANDOM"
  4123. success=yes
  4124. for srccompr in '' compress=auto compress=none; do
  4125. for dstcompr in '' compress=auto compress=none; do
  4126. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0,$dstcompr pipe"
  4127. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD,$srccompr"
  4128. eval "$CMD2 2>\"${te}1\" &"
  4129. pid=$! # background process id
  4130. waittcp4port $PORT
  4131. echo "$da" | $CMD >$tf 2>"${te}2"
  4132. kill $pid 2>/dev/null
  4133. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4134. success=
  4135. break
  4136. fi
  4137. done
  4138. done
  4139. if test -z "$success"; then
  4140. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4141. echo "$CMD2 &"
  4142. echo "$CMD"
  4143. cat "${te}1"
  4144. cat "${te}2"
  4145. cat "$tdiff"
  4146. numFAIL=$((numFAIL+1))
  4147. listFAIL="$listFAIL $N"
  4148. else
  4149. $PRINTF "$OK\n"
  4150. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4151. numOK=$((numOK+1))
  4152. fi
  4153. fi ;; # NUMCOND, feats
  4154. esac
  4155. PORT=$((PORT+1))
  4156. N=$((N+1))
  4157. NAME=SOCKS4CONNECT_TCP4
  4158. case "$TESTS" in
  4159. *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  4160. TEST="$NAME: socks4 connect over TCP/IPv4"
  4161. if ! eval $NUMCOND; then :;
  4162. elif ! testaddrs socks4 >/dev/null; then
  4163. $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
  4164. numCANT=$((numCANT+1))
  4165. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  4166. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  4167. numCANT=$((numCANT+1))
  4168. else
  4169. tf="$td/test$N.stdout"
  4170. te="$td/test$N.stderr"
  4171. tdiff="$td/test$N.diff"
  4172. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4173. # we have a normal tcp echo listening - so the socks header must appear in answer
  4174. CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
  4175. CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
  4176. printf "test $F_n $TEST... " $N
  4177. eval "$CMD2 2>\"${te}1\" &"
  4178. pid=$! # background process id
  4179. waittcp4port $PORT 1
  4180. echo "$da" |$CMD >$tf 2>"${te}2"
  4181. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4182. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4183. echo "$CMD2 &"
  4184. echo "$CMD"
  4185. cat "${te}1"
  4186. cat "${te}2"
  4187. cat "$tdiff"
  4188. numFAIL=$((numFAIL+1))
  4189. listFAIL="$listFAIL $N"
  4190. else
  4191. $PRINTF "$OK\n"
  4192. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4193. numOK=$((numOK+1))
  4194. fi
  4195. kill $pid 2>/dev/null
  4196. wait
  4197. fi ;; # NUMCOND, feats
  4198. esac
  4199. PORT=$((PORT+1))
  4200. N=$((N+1))
  4201. NAME=SOCKS4CONNECT_TCP6
  4202. case "$TESTS" in
  4203. *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
  4204. TEST="$NAME: socks4 connect over TCP/IPv6"
  4205. if ! eval $NUMCOND; then :;
  4206. elif ! testaddrs socks4 >/dev/null; then
  4207. $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
  4208. numCANT=$((numCANT+1))
  4209. elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  4210. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
  4211. numCANT=$((numCANT+1))
  4212. else
  4213. tf="$td/test$N.stdout"
  4214. te="$td/test$N.stderr"
  4215. tdiff="$td/test$N.diff"
  4216. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4217. # we have a normal tcp echo listening - so the socks header must appear in answer
  4218. CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
  4219. CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser="nobody"
  4220. printf "test $F_n $TEST... " $N
  4221. eval "$CMD2 2>\"${te}1\" &"
  4222. pid=$! # background process id
  4223. waittcp6port $PORT 1
  4224. echo "$da" |$CMD >$tf 2>"${te}2"
  4225. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4226. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4227. echo "$CMD2 &"
  4228. echo "$CMD"
  4229. cat "${te}1"
  4230. cat "${te}2"
  4231. cat "$tdiff"
  4232. numFAIL=$((numFAIL+1))
  4233. listFAIL="$listFAIL $N"
  4234. else
  4235. $PRINTF "$OK\n"
  4236. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4237. numOK=$((numOK+1))
  4238. fi
  4239. kill $pid 2>/dev/null
  4240. wait
  4241. fi ;; # NUMCOND, feats
  4242. esac
  4243. PORT=$((PORT+1))
  4244. N=$((N+1))
  4245. NAME=SOCKS4ACONNECT_TCP4
  4246. case "$TESTS" in
  4247. *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  4248. TEST="$NAME: socks4a connect over TCP/IPv4"
  4249. if ! eval $NUMCOND; then :;
  4250. elif ! testaddrs socks4a >/dev/null; then
  4251. $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
  4252. numCANT=$((numCANT+1))
  4253. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  4254. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  4255. numCANT=$((numCANT+1))
  4256. else
  4257. tf="$td/test$N.stdout"
  4258. te="$td/test$N.stderr"
  4259. tdiff="$td/test$N.diff"
  4260. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4261. # we have a normal tcp echo listening - so the socks header must appear in answer
  4262. CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
  4263. CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
  4264. printf "test $F_n $TEST... " $N
  4265. eval "$CMD2 2>\"${te}1\" &"
  4266. pid=$! # background process id
  4267. waittcp4port $PORT 1
  4268. echo "$da" |$CMD >$tf 2>"${te}2"
  4269. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4270. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4271. echo "$CMD2 &"
  4272. echo "$CMD"
  4273. cat "${te}1"
  4274. cat "${te}2"
  4275. cat "$tdiff"
  4276. numFAIL=$((numFAIL+1))
  4277. listFAIL="$listFAIL $N"
  4278. else
  4279. $PRINTF "$OK\n"
  4280. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4281. numOK=$((numOK+1))
  4282. fi
  4283. kill $pid 2>/dev/null
  4284. wait
  4285. fi ;; # NUMCOND, feats
  4286. esac
  4287. PORT=$((PORT+1))
  4288. N=$((N+1))
  4289. NAME=SOCKS4ACONNECT_TCP6
  4290. case "$TESTS" in
  4291. *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
  4292. TEST="$NAME: socks4a connect over TCP/IPv6"
  4293. if ! eval $NUMCOND; then :;
  4294. elif ! testaddrs socks4a >/dev/null; then
  4295. $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
  4296. numCANT=$((numCANT+1))
  4297. elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  4298. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
  4299. numCANT=$((numCANT+1))
  4300. else
  4301. tf="$td/test$N.stdout"
  4302. te="$td/test$N.stderr"
  4303. tdiff="$td/test$N.diff"
  4304. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4305. # we have a normal tcp echo listening - so the socks header must appear in answer
  4306. CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
  4307. CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser="nobody"
  4308. printf "test $F_n $TEST... " $N
  4309. eval "$CMD2 2>\"${te}1\" &"
  4310. pid=$! # background process id
  4311. waittcp6port $PORT 1
  4312. echo "$da" |$CMD >$tf 2>"${te}2"
  4313. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4314. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4315. echo "$CMD2 &"
  4316. echo "$CMD"
  4317. cat "${te}1"
  4318. cat "${te}2"
  4319. cat "$tdiff"
  4320. numFAIL=$((numFAIL+1))
  4321. listFAIL="$listFAIL $N"
  4322. else
  4323. $PRINTF "$OK\n"
  4324. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4325. numOK=$((numOK+1))
  4326. fi
  4327. kill $pid 2>/dev/null
  4328. wait
  4329. fi ;; # NUMCOND, feats
  4330. esac
  4331. PORT=$((PORT+1))
  4332. N=$((N+1))
  4333. NAME=PROXYCONNECT_TCP4
  4334. case "$TESTS" in
  4335. *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  4336. TEST="$NAME: proxy connect over TCP/IPv4"
  4337. if ! eval $NUMCOND; then :;
  4338. elif ! testaddrs proxy >/dev/null; then
  4339. $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
  4340. numCANT=$((numCANT+1))
  4341. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  4342. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  4343. numCANT=$((numCANT+1))
  4344. else
  4345. ts="$td/test$N.sh"
  4346. tf="$td/test$N.stdout"
  4347. te="$td/test$N.stderr"
  4348. tdiff="$td/test$N.diff"
  4349. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4350. #CMD2="$TRACE $SOCAT tcp4-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
  4351. CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
  4352. CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
  4353. printf "test $F_n $TEST... " $N
  4354. eval "$CMD2 2>\"${te}2\" &"
  4355. pid=$! # background process id
  4356. waittcp4port $PORT 1
  4357. echo "$da" |$CMD >"$tf" 2>"${te}1"
  4358. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4359. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4360. echo "$CMD2 &"
  4361. echo "$CMD"
  4362. cat "${te}1"
  4363. cat "${te}2"
  4364. cat "$tdiff"
  4365. numFAIL=$((numFAIL+1))
  4366. listFAIL="$listFAIL $N"
  4367. else
  4368. $PRINTF "$OK\n"
  4369. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4370. numOK=$((numOK+1))
  4371. fi
  4372. kill $pid 2>/dev/null
  4373. wait
  4374. fi ;; # NUMCOND, feats
  4375. esac
  4376. PORT=$((PORT+1))
  4377. N=$((N+1))
  4378. NAME=PROXYCONNECT_TCP6
  4379. case "$TESTS" in
  4380. *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
  4381. TEST="$NAME: proxy connect over TCP/IPv6"
  4382. if ! eval $NUMCOND; then :;
  4383. elif ! testaddrs proxy >/dev/null; then
  4384. $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
  4385. numCANT=$((numCANT+1))
  4386. elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  4387. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
  4388. numCANT=$((numCANT+1))
  4389. else
  4390. ts="$td/test$N.sh"
  4391. tf="$td/test$N.stdout"
  4392. te="$td/test$N.stderr"
  4393. tdiff="$td/test$N.diff"
  4394. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4395. #CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
  4396. CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
  4397. CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT"
  4398. printf "test $F_n $TEST... " $N
  4399. eval "$CMD2 2>\"${te}2\" &"
  4400. pid=$! # background process id
  4401. waittcp6port $PORT 1
  4402. echo "$da" |$CMD >"$tf" 2>"${te}1"
  4403. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4404. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4405. echo "$CMD2 &"
  4406. echo "$CMD"
  4407. cat "${te}1"
  4408. cat "${te}2"
  4409. cat "$tdiff"
  4410. numFAIL=$((numFAIL+1))
  4411. listFAIL="$listFAIL $N"
  4412. else
  4413. $PRINTF "$OK\n"
  4414. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4415. numOK=$((numOK+1))
  4416. fi
  4417. kill $pid 2>/dev/null
  4418. wait
  4419. fi ;; # NUMCOND, feats
  4420. esac
  4421. PORT=$((PORT+1))
  4422. N=$((N+1))
  4423. NAME=TCP4NOFORK
  4424. case "$TESTS" in
  4425. *%$N%*|*%functions%*|*%$NAME%*)
  4426. TEST="$NAME: echo via connection to TCP V4 socket with nofork'ed exec"
  4427. if ! eval $NUMCOND; then :; else
  4428. tf="$td/test$N.stdout"
  4429. te="$td/test$N.stderr"
  4430. tdiff="$td/test$N.diff"
  4431. tsl=$PORT
  4432. ts="127.0.0.1:$tsl"
  4433. da="test$N $(date) $RANDOM"
  4434. CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR exec:$CAT,nofork"
  4435. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  4436. printf "test $F_n $TEST... " $N
  4437. #$CMD1 >"$tf" 2>"${te}1" &
  4438. $CMD1 >/dev/null 2>"${te}1" &
  4439. waittcp4port $tsl
  4440. #usleep $MICROS
  4441. echo "$da" |$CMD2 >"$tf" 2>>"${te}2"
  4442. if [ $? -ne 0 ]; then
  4443. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4444. echo "$CMD1 &"
  4445. echo "$CMD2"
  4446. cat "${te}1"
  4447. cat "${te}2"
  4448. numFAIL=$((numFAIL+1))
  4449. listFAIL="$listFAIL $N"
  4450. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4451. $PRINTF "$FAILED\n"
  4452. cat "$tdiff"
  4453. numFAIL=$((numFAIL+1))
  4454. listFAIL="$listFAIL $N"
  4455. else
  4456. $PRINTF "$OK\n"
  4457. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4458. numOK=$((numOK+1))
  4459. fi
  4460. fi ;; # NUMCOND
  4461. esac
  4462. PORT=$((PORT+1))
  4463. N=$((N+1))
  4464. NAME=EXECCATNOFORK
  4465. case "$TESTS" in
  4466. *%$N%*|*%functions%*|*%$NAME%*)
  4467. TEST="$NAME: simple echo via exec of cat with nofork"
  4468. testecho "$N" "$TEST" "" "exec:$CAT,nofork" "$opts"
  4469. esac
  4470. N=$((N+1))
  4471. NAME=SYSTEMCATNOFORK
  4472. case "$TESTS" in
  4473. *%$N%*|*%functions%*|*%$NAME%*)
  4474. TEST="$NAME: simple echo via system() of cat with nofork"
  4475. testecho "$N" "$TEST" "" "system:$CAT,nofork" "$opts"
  4476. esac
  4477. N=$((N+1))
  4478. NAME=NOFORKSETSID
  4479. case "$TESTS" in
  4480. *%$N%*|*%functions%*|*%$NAME%*)
  4481. TEST="$NAME: simple echo via exec() of cat with nofork and setsid"
  4482. testecho "$N" "$TEST" "" "system:$CAT,nofork,setsid" "$opts"
  4483. esac
  4484. N=$((N+1))
  4485. #==============================================================================
  4486. #TEST="$NAME: echo via 'connection' to UDP V4 socket"
  4487. #if ! eval $NUMCOND; then :; else
  4488. #tf="$td/file$N"
  4489. #tsl=65534
  4490. #ts="127.0.0.1:$tsl"
  4491. #da="test$N $(date) $RANDOM"
  4492. #$TRACE $SOCAT UDP-listen:$tsl,$REUSEADDR PIPE &
  4493. #sleep 2
  4494. #echo "$da" |$TRACE $SOCAT stdin!!stdout UDP:$ts >"$tf"
  4495. #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
  4496. # $ECHO "... test $N succeeded"
  4497. # numOK=$((numOK+1))
  4498. #else
  4499. # $ECHO "*** test $N $FAILED"
  4500. # numFAIL=$((numFAIL+1))
  4501. # listFAIL="$listFAIL $N"
  4502. #fi
  4503. #fi ;; # NUMCOND
  4504. #N=$((N+1))
  4505. #==============================================================================
  4506. # TEST 4 - simple echo via new file
  4507. #if ! eval $NUMCOND; then :; else
  4508. #N=4
  4509. #tf="$td/file$N"
  4510. #tp="$td/pipe$N"
  4511. #da="test$N $(date) $RANDOM"
  4512. #rm -f "$tf.tmp"
  4513. #echo "$da" |$TRACE $SOCAT - FILE:$tf.tmp,ignoreeof >"$tf"
  4514. #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
  4515. # $ECHO "... test $N succeeded"
  4516. # numOK=$((numOK+1))
  4517. #else
  4518. # $ECHO "*** test $N $FAILED"
  4519. # numFAIL=$((numFAIL+1))
  4520. # listFAIL="$listFAIL $N"
  4521. #fi
  4522. #fi ;; # NUMCOND
  4523. #==============================================================================
  4524. NAME=TOTALTIMEOUT
  4525. case "$TESTS" in
  4526. *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%$NAME%*)
  4527. TEST="$NAME: socat inactivity timeout"
  4528. if ! eval $NUMCOND; then :; else
  4529. #set -vx
  4530. tf="$td/test$N.stdout"
  4531. te="$td/test$N.stderr"
  4532. tdiff="$td/test$N.diff"
  4533. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4534. CMD2="$TRACE $SOCAT $opts -T 1 TCP4-LISTEN:$PORT,$REUSEADDR pipe"
  4535. CMD="$TRACE $SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT"
  4536. printf "test $F_n $TEST... " $N
  4537. eval "$CMD2 2>${te}1 &"
  4538. pid=$! # background process id
  4539. waittcp4port $PORT 1
  4540. (echo "$da"; sleep 2; echo X) |$CMD >"$tf" 2>"${te}2"
  4541. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4542. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4543. echo "$CMD2 &"
  4544. echo "$CMD"
  4545. cat "${te}1"
  4546. cat "${te}2"
  4547. cat "$tdiff"
  4548. numFAIL=$((numFAIL+1))
  4549. listFAIL="$listFAIL $N"
  4550. else
  4551. $PRINTF "$OK\n"
  4552. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4553. numOK=$((numOK+1))
  4554. fi
  4555. kill $pid 2>/dev/null
  4556. wait
  4557. #set +vx
  4558. fi ;; # NUMCOND
  4559. esac
  4560. PORT=$((PORT+1))
  4561. N=$((N+1))
  4562. NAME=IGNOREEOF+TOTALTIMEOUT
  4563. case "$TESTS" in
  4564. *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
  4565. TEST="$NAME: ignoreeof and inactivity timeout"
  4566. if ! eval $NUMCOND; then :; else
  4567. #set -vx
  4568. ti="$td/test$N.file"
  4569. tf="$td/test$N.stdout"
  4570. te="$td/test$N.stderr"
  4571. tdiff="$td/test$N.diff"
  4572. da="test$N $(date) $RANDOM"
  4573. CMD="$TRACE $SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -"
  4574. printf "test $F_n $TEST... " $N
  4575. touch "$ti"
  4576. $CMD >"$tf" 2>"$te" &
  4577. bg=$! # background process id
  4578. psleep 0.5
  4579. echo "$da" >>"$ti"
  4580. sleep 4
  4581. echo X >>"$ti"
  4582. sleep 1
  4583. kill $bg 2>/dev/null
  4584. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4585. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4586. echo "$CMD &"
  4587. cat "$te"
  4588. cat "$tdiff"
  4589. numFAIL=$((numFAIL+1))
  4590. listFAIL="$listFAIL $N"
  4591. else
  4592. $PRINTF "$OK\n"
  4593. if [ -n "$debug" ]; then cat "$te"; fi
  4594. numOK=$((numOK+1))
  4595. fi
  4596. wait
  4597. fi ;; # NUMCOND, feats
  4598. esac
  4599. N=$((N+1))
  4600. NAME=PROXY2SPACES
  4601. case "$TESTS" in
  4602. *%$N%*|*%functions%*|*%proxy%*|*%$NAME%*)
  4603. TEST="$NAME: proxy connect accepts status with multiple spaces"
  4604. if ! eval $NUMCOND; then :;
  4605. elif ! testaddrs proxy >/dev/null; then
  4606. $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
  4607. numCANT=$((numCANT+1))
  4608. else
  4609. ts="$td/test$N.sh"
  4610. tf="$td/test$N.stdout"
  4611. te="$td/test$N.stderr"
  4612. tdiff="$td/test$N.diff"
  4613. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4614. #CMD2="$TRACE $SOCAT $opts tcp-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
  4615. CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/usr/bin/env bash proxyecho.sh -w 2\""
  4616. CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
  4617. printf "test $F_n $TEST... " $N
  4618. eval "$CMD2 2>\"${te}1\" &"
  4619. pid=$! # background process id
  4620. waittcp4port $PORT 1
  4621. echo "$da" |$CMD >"$tf" 2>"${te}2"
  4622. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4623. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4624. echo "$CMD2 &"
  4625. echo "$CMD"
  4626. cat "${te}1"
  4627. cat "${te}2"
  4628. cat "$tdiff"
  4629. numFAIL=$((numFAIL+1))
  4630. listFAIL="$listFAIL $N"
  4631. else
  4632. $PRINTF "$OK\n"
  4633. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  4634. numOK=$((numOK+1))
  4635. fi
  4636. kill $pid 2>/dev/null
  4637. wait
  4638. fi ;; # NUMCOND, feats
  4639. esac
  4640. PORT=$((PORT+1))
  4641. N=$((N+1))
  4642. NAME=BUG-UNISTDIO
  4643. case "$TESTS" in
  4644. *%$N%*|*%functions%*|*%$NAME%*)
  4645. TEST="$NAME: for bug with address options on both stdin/out in unidirectional mode"
  4646. if ! eval $NUMCOND; then :; else
  4647. tf="$td/test$N.stdout"
  4648. te="$td/test$N.stderr"
  4649. ff="$td/file$N"
  4650. printf "test $F_n $TEST... " $N
  4651. >"$ff"
  4652. #$TRACE $SOCAT $opts -u /dev/null -,setlk <"$ff" 2>"$te"
  4653. CMD="$TRACE $SOCAT $opts -u /dev/null -,setlk"
  4654. $CMD <"$ff" 2>"$te"
  4655. if [ "$?" -eq 0 ]; then
  4656. $PRINTF "$OK\n"
  4657. numOK=$((numOK+1))
  4658. else
  4659. if [ "$UNAME" = "Linux" ]; then
  4660. $PRINTF "$FAILED\n"
  4661. echo "$CMD"
  4662. cat "$te"
  4663. numFAIL=$((numFAIL+1))
  4664. listFAIL="$listFAIL $N"
  4665. else
  4666. $PRINTF "${YELLOW}failed (don't care)${NORMAL}\n"
  4667. numCANT=$((numCANT+1))
  4668. fi
  4669. fi
  4670. fi ;; # NUMCOND
  4671. esac
  4672. N=$((N+1))
  4673. NAME=SINGLEEXECOUTSOCKETPAIR
  4674. case "$TESTS" in
  4675. *%$N%*|*%functions%*|*%$NAME%*)
  4676. TEST="$NAME: inheritance of stdout to single exec with socketpair"
  4677. testecho "$N" "$TEST" "-!!exec:cat" "" "$opts" 1
  4678. esac
  4679. N=$((N+1))
  4680. NAME=SINGLEEXECOUTPIPE
  4681. case "$TESTS" in
  4682. *%$N%*|*%functions%*|*%$NAME%*)
  4683. TEST="$NAME: inheritance of stdout to single exec with pipe"
  4684. testecho "$N" "$TEST" "-!!exec:cat,pipes" "" "$opts" 1
  4685. esac
  4686. N=$((N+1))
  4687. NAME=SINGLEEXECOUTPTY
  4688. case "$TESTS" in
  4689. *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
  4690. TEST="$NAME: inheritance of stdout to single exec with pty"
  4691. if ! eval $NUMCOND; then :;
  4692. elif ! testaddrs pty >/dev/null; then
  4693. $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  4694. numCANT=$((numCANT+1))
  4695. else
  4696. testecho "$N" "$TEST" "-!!exec:cat,pty,raw" "" "$opts" 1
  4697. fi ;; # NUMCOND, feats
  4698. esac
  4699. N=$((N+1))
  4700. NAME=SINGLEEXECINSOCKETPAIR
  4701. case "$TESTS" in
  4702. *%$N%*|*%functions%*|*%$NAME%*)
  4703. TEST="$NAME: inheritance of stdin to single exec with socketpair"
  4704. testecho "$N" "$TEST" "exec:cat!!-" "" "$opts"
  4705. esac
  4706. N=$((N+1))
  4707. NAME=SINGLEEXECINPIPE
  4708. case "$TESTS" in
  4709. *%$N%*|*%functions%*|*%$NAME%*)
  4710. TEST="$NAME: inheritance of stdin to single exec with pipe"
  4711. testecho "$N" "$TEST" "exec:cat,pipes!!-" "" "$opts"
  4712. esac
  4713. N=$((N+1))
  4714. NAME=SINGLEEXECINPTYDELAY
  4715. case "$TESTS" in
  4716. *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
  4717. TEST="$NAME: inheritance of stdin to single exec with pty, with delay"
  4718. if ! eval $NUMCOND; then :;
  4719. elif ! testaddrs pty >/dev/null; then
  4720. $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  4721. numCANT=$((numCANT+1))
  4722. else
  4723. testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts" $MISCDELAY
  4724. fi ;; # NUMCOND, feats
  4725. esac
  4726. N=$((N+1))
  4727. NAME=SINGLEEXECINPTY
  4728. case "$TESTS" in
  4729. *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
  4730. TEST="$NAME: inheritance of stdin to single exec with pty"
  4731. if ! eval $NUMCOND; then :;
  4732. elif ! testaddrs pty >/dev/null; then
  4733. $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
  4734. numCANT=$((numCANT+1))
  4735. else
  4736. testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts"
  4737. fi ;; # NUMCOND, feats
  4738. esac
  4739. N=$((N+1))
  4740. NAME=READLINE
  4741. #set -vx
  4742. case "$TESTS" in
  4743. *%$N%*|*%functions%*|*%pty%*|*%readline%*|*%$NAME%*)
  4744. TEST="$NAME: readline with password and sigint"
  4745. if ! eval $NUMCOND; then :;
  4746. elif ! feat=$(testaddrs readline pty); then
  4747. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  4748. numCANT=$((numCANT+1))
  4749. else
  4750. SAVETERM="$TERM"; TERM= # 'cause konsole might print controls even in raw
  4751. SAVEMICS=$MICROS
  4752. #MICROS=2000000
  4753. ts="$td/test$N.sh"
  4754. to="$td/test$N.stdout"
  4755. tpi="$td/test$N.inpipe"
  4756. tpo="$td/test$N.outpipe"
  4757. te="$td/test$N.stderr"
  4758. tr="$td/test$N.ref"
  4759. tdiff="$td/test$N.diff"
  4760. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  4761. # the feature that we really want to test is in the readline.sh script:
  4762. CMD="$TRACE $SOCAT $opts -t1 open:$tpi,nonblock!!open:$tpo exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig"
  4763. #echo "$CMD" >"$ts"
  4764. #chmod a+x "$ts"
  4765. printf "test $F_n $TEST... " $N
  4766. rm -f "$tpi" "$tpo"
  4767. mkfifo "$tpi"
  4768. touch "$tpo"
  4769. #
  4770. # during development of this test, the following command line succeeded:
  4771. # (sleep 1; $ECHO "user\n\c"; sleep 1; $ECHO "password\c"; sleep 1; $ECHO "\n\c"; sleep 1; $ECHO "test 1\n\c"; sleep 1; $ECHO "\003\c"; sleep 1; $ECHO "test 2\n\c"; sleep 1; $ECHO "exit\n\c"; sleep 1) |$TRACE $SOCAT -d -d -d -d -lf/tmp/gerhard/debug1 -v -x - exec:'./readline.sh ./readline-test.sh',pty,ctty,setsid,raw,echo=0,isig
  4772. #
  4773. PATH=${SOCAT%socat}:$PATH eval "$CMD 2>$te &"
  4774. pid=$! # background process id
  4775. usleep $MICROS
  4776. (
  4777. usleep $((3*MICROS))
  4778. $ECHO "user\n\c"
  4779. usleep $MICROS
  4780. $ECHO "password\c"
  4781. usleep $MICROS
  4782. $ECHO "\n\c"
  4783. usleep $MICROS
  4784. $ECHO "test 1\n\c"
  4785. usleep $MICROS
  4786. $ECHO "\003\c"
  4787. usleep $MICROS
  4788. $ECHO "test 2\n\c"
  4789. usleep $MICROS
  4790. $ECHO "exit\n\c"
  4791. usleep $MICROS
  4792. ) >"$tpi"
  4793. cat >$tr <<EOF
  4794. readline feature test program
  4795. Authentication required
  4796. Username: user
  4797. Password:
  4798. prog> test 1
  4799. executing test 1
  4800. prog> ./readline-test.sh got SIGINT
  4801. test 2
  4802. executing test 2
  4803. prog> exit
  4804. EOF
  4805. #0 if ! sed 's/.*\r//g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
  4806. #0 if ! sed 's/.*'"$($ECHO '\r\c')"'/</g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
  4807. wait
  4808. if ! tr "$($ECHO '\r \c')" "% " <$tpo |sed 's/%$//g' |sed 's/.*%//g' |diff "$tr" - >"$tdiff" 2>&1; then
  4809. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4810. echo "$CMD"
  4811. cat "$te"
  4812. cat "$tdiff"
  4813. numFAIL=$((numFAIL+1))
  4814. listFAIL="$listFAIL $N"
  4815. else
  4816. $PRINTF "$OK\n"
  4817. if [ -n "$debug" ]; then cat $te; fi
  4818. numOK=$((numOK+1))
  4819. fi
  4820. kill $pid 2>/dev/null # necc on OpenBSD
  4821. wait
  4822. MICROS=$SAVEMICS
  4823. TERM="$SAVETERM"
  4824. fi ;; # NUMCOND, feats
  4825. esac
  4826. PORT=$((PORT+1))
  4827. N=$((N+1))
  4828. NAME=GENDERCHANGER
  4829. case "$TESTS" in
  4830. *%$N%*|*%functions%*|*%$NAME%*)
  4831. TEST="$NAME: TCP4 \"gender changer\""
  4832. if ! eval $NUMCOND; then :; else
  4833. tf="$td/test$N.stdout"
  4834. te="$td/test$N.stderr"
  4835. tdiff="$td/test$N.diff"
  4836. da="test$N $(date) $RANDOM"
  4837. # this is the server in the protected network that we want to reach
  4838. CMD1="$TRACE $SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
  4839. # this is the double client in the protected network
  4840. CMD2="$TRACE $SOCAT -lp2client $opts tcp4:$LOCALHOST:$((PORT+1)),retry=10,interval=1 tcp4:$LOCALHOST:$PORT"
  4841. # this is the double server in the outside network
  4842. CMD3="$TRACE $SOCAT -lp2server $opts tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST"
  4843. # this is the outside client that wants to use the protected server
  4844. CMD4="$TRACE $SOCAT -lpclient $opts -t1 - tcp4:$LOCALHOST:$((PORT+2))"
  4845. printf "test $F_n $TEST... " $N
  4846. eval "$CMD1 2>${te}1 &"
  4847. pid1=$!
  4848. eval "$CMD2 2>${te}2 &"
  4849. pid2=$!
  4850. eval "$CMD3 2>${te}3 &"
  4851. pid3=$!
  4852. waittcp4port $PORT 1 &&
  4853. waittcp4port $((PORT+2)) 1
  4854. sleep 1
  4855. echo "$da" |$CMD4 >$tf 2>"${te}4"
  4856. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  4857. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4858. echo "$CMD1 &"
  4859. echo "$CMD2 &"
  4860. echo "$CMD3 &"
  4861. echo "$CMD4"
  4862. cat "${te}1" "${te}2" "${te}3" "${te}4"
  4863. cat "$tdiff"
  4864. numFAIL=$((numFAIL+1))
  4865. listFAIL="$listFAIL $N"
  4866. else
  4867. $PRINTF "$OK\n"
  4868. if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4"; fi
  4869. numOK=$((numOK+1))
  4870. fi
  4871. kill $pid1 $pid2 $pid3 $pid4 2>/dev/null
  4872. wait
  4873. fi ;; # NUMCOND
  4874. esac
  4875. PORT=$((PORT+3))
  4876. N=$((N+1))
  4877. #!
  4878. #PORT=10000
  4879. #!
  4880. NAME=OUTBOUNDIN
  4881. case "$TESTS" in
  4882. *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
  4883. TEST="$NAME: gender changer via SSL through HTTP proxy, oneshot"
  4884. if ! eval $NUMCOND; then :;
  4885. elif ! feat=$(testaddrs openssl proxy); then
  4886. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  4887. numCANT=$((numCANT+1))
  4888. else
  4889. gentestcert testsrv
  4890. gentestcert testcli
  4891. tf="$td/test$N.stdout"
  4892. te="$td/test$N.stderr"
  4893. tdiff="$td/test$N.diff"
  4894. da="test$N $(date) $RANDOM"
  4895. # this is the server in the protected network that we want to reach
  4896. CMD1="$TRACE $SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
  4897. # this is the proxy in the protected network that provides a way out
  4898. CMD2="$TRACE $SOCAT $opts -lpproxy tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
  4899. # this is our proxy connect wrapper in the protected network
  4900. CMD3="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
  4901. # this is our double client in the protected network using SSL
  4902. #CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
  4903. CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
  4904. # this is the double server in the outside network
  4905. CMD5="$TRACE $SOCAT $opts -lp2server -t1 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt"
  4906. # this is the outside client that wants to use the protected server
  4907. CMD6="$TRACE $SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4))"
  4908. printf "test $F_n $TEST... " $N
  4909. eval "$CMD1 2>${te}1 &"
  4910. pid1=$!
  4911. eval "$CMD2 2>${te}2 &"
  4912. pid2=$!
  4913. eval "$CMD3 2>${te}3 &"
  4914. pid3=$!
  4915. waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
  4916. waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
  4917. waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
  4918. eval "$CMD5 2>${te}5 &"
  4919. pid5=$!
  4920. waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
  4921. echo "$da" |$CMD6 >$tf 2>"${te}6" &
  4922. pid6=$!
  4923. waittcp4port $((PORT+3)) 1 || $PRINTF "$FAILED: port $((PORT+3))\n" >&2 </dev/null
  4924. eval "$CMD4 2>${te}4 &"
  4925. pid4=$!
  4926. wait $pid6
  4927. if ! (echo "$da"; sleep 2) |diff - "$tf" >"$tdiff"; then
  4928. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  4929. echo "$CMD1 &"
  4930. cat "${te}1"
  4931. echo "$CMD2 &"
  4932. cat "${te}2"
  4933. echo "$CMD3 &"
  4934. cat "${te}3"
  4935. echo "$CMD5 &"
  4936. cat "${te}5"
  4937. echo "$CMD6"
  4938. cat "${te}6"
  4939. echo "$CMD4 &"
  4940. cat "${te}4"
  4941. cat "$tdiff"
  4942. numFAIL=$((numFAIL+1))
  4943. listFAIL="$listFAIL $N"
  4944. else
  4945. $PRINTF "$OK\n"
  4946. if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" "${te}6"; fi
  4947. numOK=$((numOK+1))
  4948. fi
  4949. kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
  4950. wait
  4951. fi ;; # NUMCOND, feats
  4952. esac
  4953. PORT=$((PORT+5))
  4954. N=$((N+1))
  4955. # test the TCP gender changer with almost production requirements: a double
  4956. # client repeatedly tries to connect to a double server via SSL through an HTTP
  4957. # proxy. the double servers SSL port becomes active for one connection only
  4958. # after a (real) client has connected to its TCP port. when the double client
  4959. # succeeded to establish an SSL connection, it connects with its second client
  4960. # side to the specified (protected) server. all three consecutive connections
  4961. # must function for full success of this test.
  4962. PORT=$((RANDOM+16184))
  4963. #!
  4964. NAME=INTRANETRIPPER
  4965. case "$TESTS" in
  4966. *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
  4967. TEST="$NAME: gender changer via SSL through HTTP proxy, daemons"
  4968. if ! eval $NUMCOND; then :;
  4969. elif ! feat=$(testaddrs openssl proxy); then
  4970. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  4971. numCANT=$((numCANT+1))
  4972. else
  4973. gentestcert testsrv
  4974. gentestcert testcli
  4975. tf="$td/test$N.stdout"
  4976. te="$td/test$N.stderr"
  4977. tdiff="$td/test$N.diff"
  4978. da1="test$N.1 $(date) $RANDOM"
  4979. da2="test$N.2 $(date) $RANDOM"
  4980. da3="test$N.3 $(date) $RANDOM"
  4981. # this is the server in the protected network that we want to reach
  4982. CMD1="$TRACE $SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo"
  4983. # this is the proxy in the protected network that provides a way out
  4984. # note: the proxy.sh script starts one or two more socat processes without
  4985. # setting the program name
  4986. CMD2="$TRACE $SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
  4987. # this is our proxy connect wrapper in the protected network
  4988. CMD3="$TRACE $SOCAT $opts -lpwrapper -t3 tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
  4989. # this is our double client in the protected network using SSL
  4990. CMD4="$TRACE $SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT,forever,interval=0.1"
  4991. # this is the double server in the outside network
  4992. CMD5="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,backlog=3,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=20,interval=0.5"
  4993. # this is the outside client that wants to use the protected server
  4994. CMD6="$TRACE $SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3"
  4995. printf "test $F_n $TEST... " $N
  4996. # start the intranet infrastructure
  4997. eval "$CMD1 2>\"${te}1\" &"
  4998. pid1=$!
  4999. eval "$CMD2 2>\"${te}2\" &"
  5000. pid2=$!
  5001. waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
  5002. waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
  5003. # initiate our internal measures
  5004. eval "$CMD3 2>\"${te}3\" &"
  5005. pid3=$!
  5006. eval "$CMD4 2>\"${te}4\" &"
  5007. pid4=$!
  5008. waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
  5009. # now we start the external daemon
  5010. eval "$CMD5 2>\"${te}5\" &"
  5011. pid5=$!
  5012. waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
  5013. # and this is the outside client:
  5014. echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" &
  5015. pid6_1=$!
  5016. echo "$da2" |$CMD6 >${tf}_2 2>"${te}6_2" &
  5017. pid6_2=$!
  5018. echo "$da3" |$CMD6 >${tf}_3 2>"${te}6_3" &
  5019. pid6_3=$!
  5020. wait $pid6_1 $pid6_2 $pid6_3
  5021. #
  5022. (echo "$da1"; sleep 2) |diff - "${tf}_1" >"${tdiff}1"
  5023. (echo "$da2"; sleep 2) |diff - "${tf}_2" >"${tdiff}2"
  5024. (echo "$da3"; sleep 2) |diff - "${tf}_3" >"${tdiff}3"
  5025. if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then
  5026. # FAILED only when none of the three transfers succeeded
  5027. if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then
  5028. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  5029. echo "$CMD1 &"
  5030. cat "${te}1"
  5031. echo "$CMD2 &"
  5032. cat "${te}2"
  5033. echo "$CMD3 &"
  5034. cat "${te}3"
  5035. echo "$CMD4 &"
  5036. cat "${te}4"
  5037. echo "$CMD5 &"
  5038. cat "${te}5"
  5039. echo "$CMD6 &"
  5040. cat "${te}6_1"
  5041. cat "${tdiff}1"
  5042. echo "$CMD6 &"
  5043. cat "${te}6_2"
  5044. cat "${tdiff}2"
  5045. echo "$CMD6 &"
  5046. cat "${te}6_3"
  5047. cat "${tdiff}3"
  5048. numFAIL=$((numFAIL+1))
  5049. listFAIL="$listFAIL $N"
  5050. else
  5051. $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n"
  5052. if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
  5053. numOK=$((numOK+1))
  5054. fi
  5055. else
  5056. $PRINTF "$OK\n"
  5057. if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
  5058. numOK=$((numOK+1))
  5059. fi
  5060. kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
  5061. wait
  5062. fi ;; # NUMCOND, feats
  5063. esac
  5064. PORT=$((PORT+5))
  5065. N=$((N+1))
  5066. # let us test the security features with -s, retry, and fork
  5067. # method: first test without security feature if it works
  5068. # then try with security feature, must fail
  5069. # test the security features of a server address
  5070. testserversec () {
  5071. local N="$1"
  5072. local title="$2"
  5073. local opts="$3"
  5074. local arg1="$4" # the server address
  5075. local secopt0="$5" # option without security for server, mostly empty
  5076. local secopt1="$6" # the security option for server, to be tested
  5077. local arg2="$7" # the client address
  5078. local ipvers="$8" # IP version, for check of listen port
  5079. local proto="$9" # protocol, for check of listen port
  5080. local port="${10}" # start client when this port is listening
  5081. local expect="${11}" # expected behaviour of client: 0..empty output; -1..error
  5082. local T="${12}"; [ -z "$T" ] && T=0
  5083. local tf="$td/test$N.stdout"
  5084. local te="$td/test$N.stderr"
  5085. local tdiff1="$td/test$N.diff1"
  5086. local tdiff2="$td/test$N.diff2"
  5087. local da="test$N.1 $(date) $RANDOM"
  5088. local stat result
  5089. $PRINTF "test $F_n %s... " $N "$title"
  5090. # first: without security
  5091. # start server
  5092. $TRACE $SOCAT $opts "$arg1,$secopt0" echo 2>"${te}1" &
  5093. spid=$!
  5094. if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
  5095. kill $spid 2>/dev/null
  5096. $PRINTF "$NO_RESULT (ph.1 server not working):\n"
  5097. echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
  5098. cat "${te}1"
  5099. numCANT=$((numCANT+1))
  5100. wait; return
  5101. fi
  5102. # now use client
  5103. (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}2"
  5104. stat="$?"
  5105. kill $spid 2>/dev/null
  5106. #killall $TRACE $SOCAT 2>/dev/null
  5107. if [ "$stat" != 0 ]; then
  5108. $PRINTF "$NO_RESULT (ph.1 function fails): $TRACE $SOCAT:\n"
  5109. echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
  5110. cat "${te}1"
  5111. echo "$TRACE $SOCAT $opts - \"$arg2\""
  5112. cat "${te}2"
  5113. numCANT=$((numCANT+1))
  5114. wait; return
  5115. elif echo "$da" |diff - "$tf" >"$tdiff1" 2>&1; then
  5116. : # function without security is ok, go on
  5117. else
  5118. $PRINTF "$NO_RESULT (ph.1 function fails): diff:\n"
  5119. echo "$TRACE $SOCAT $opts $arg1,$secopt0 echo &"
  5120. cat "${te}1"
  5121. echo "$TRACE $SOCAT $opts - $arg2"
  5122. cat "${te}2"
  5123. cat "$tdiff1"
  5124. numCANT=$((numCANT+1))
  5125. wait; return
  5126. fi
  5127. # then: with security
  5128. if [ "$port" ] && ! wait${proto}${ipvers}port $port 0; then
  5129. $PRINTF "$NO_RESULT (ph.1 port remains in use)\n"
  5130. numCANT=$((numCANT+1))
  5131. wait; return
  5132. fi
  5133. wait
  5134. #set -vx
  5135. # assemble address w/ security option; on dual, take read part:
  5136. case "$arg1" in
  5137. *!!*) arg="${arg1%!!*},$secopt1!!${arg1#*!!}" ;;
  5138. *) arg="$arg1,$secopt1" ;;
  5139. esac
  5140. # start server
  5141. # use -s to make sure that it fails due to a sec violation, not some other failure
  5142. CMD3="$TRACE $SOCAT $opts -s $arg echo"
  5143. $CMD3 2>"${te}3" &
  5144. spid=$!
  5145. if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
  5146. kill $spid 2>/dev/null
  5147. $PRINTF "$NO_RESULT (ph.2 server not working)\n"
  5148. wait
  5149. echo "$CMD3"
  5150. cat "${te}3"
  5151. numCANT=$((numCANT+1))
  5152. return
  5153. fi
  5154. # now use client
  5155. da="test$N.2 $(date) $RANDOM"
  5156. (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}4"
  5157. stat=$?
  5158. kill $spid 2>/dev/null
  5159. #set +vx
  5160. #killall $TRACE $SOCAT 2>/dev/null
  5161. if [ "$stat" != 0 ]; then
  5162. result=-1; # socat had error
  5163. elif [ ! -s "$tf" ]; then
  5164. result=0; # empty output
  5165. elif echo "$da" |diff - "$tf" >"$tdiff2" 2>&1; then
  5166. result=1; # output is copy of input
  5167. else
  5168. result=2; # output differs from input
  5169. fi
  5170. if [ X$result != X$expect ]; then
  5171. case X$result in
  5172. X-1) $PRINTF "$NO_RESULT (ph.2 client error): $TRACE $SOCAT:\n"
  5173. echo "$TRACE $SOCAT $opts $arg echo"
  5174. cat "${te}3"
  5175. echo "$TRACE $SOCAT $opts - $arg2"
  5176. cat "${te}4"
  5177. numCANT=$((numCANT+1)) ;;
  5178. X0) $PRINTF "$NO_RESULT (ph.2 diff failed): diff:\n"
  5179. echo "$TRACE $SOCAT $opts $arg echo"
  5180. cat "${te}3"
  5181. echo "$TRACE $SOCAT $opts - $arg2"
  5182. cat "${te}4"
  5183. cat "$tdiff2"
  5184. numCANT=$((numCANT+1)) ;;
  5185. X1) $PRINTF "$FAILED: SECURITY BROKEN\n"
  5186. echo "$TRACE $SOCAT $opts $arg echo"
  5187. cat "${te}3"
  5188. echo "$TRACE $SOCAT $opts - $arg2"
  5189. cat "${te}4"
  5190. cat "$tdiff2"
  5191. numFAIL=$((numFAIL+1))
  5192. listFAIL="$listFAIL $N" ;;
  5193. X2) $PRINTF "$FAILED: diff:\n"
  5194. echo "$TRACE $SOCAT $opts $arg echo"
  5195. cat "${te}3"
  5196. echo "$TRACE $SOCAT $opts - $arg2"
  5197. cat "${te}4"
  5198. cat "$tdiff2"
  5199. numFAIL=$((numFAIL+1))
  5200. listFAIL="$listFAIL $N" ;;
  5201. esac
  5202. else
  5203. $PRINTF "$OK\n"
  5204. [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts $arg echo"
  5205. [ "$debug" ] && cat ${te}3
  5206. [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts - $arg2"
  5207. [ "$debug" ] && cat ${te}4
  5208. numOK=$((numOK+1))
  5209. fi
  5210. wait
  5211. #set +vx
  5212. }
  5213. NAME=TCP4RANGEBITS
  5214. case "$TESTS" in
  5215. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  5216. TEST="$NAME: security of TCP4-L with RANGE option"
  5217. if ! eval $NUMCOND; then :;
  5218. elif [ -z "$SECONDADDR" ]; then
  5219. # we need access to a second addresses
  5220. $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
  5221. numCANT=$((numCANT+1))
  5222. else
  5223. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
  5224. fi ;; # $SECONDADDR, NUMCOND
  5225. esac
  5226. PORT=$((PORT+1))
  5227. N=$((N+1))
  5228. NAME=TCP4RANGEMASK
  5229. case "$TESTS" in
  5230. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  5231. TEST="$NAME: security of TCP4-L with RANGE option"
  5232. if ! eval $NUMCOND; then :;
  5233. elif [ -z "$SECONDADDR" ]; then
  5234. # we need access to a second addresses
  5235. $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
  5236. numCANT=$((numCANT+1))
  5237. else
  5238. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR:255.255.255.255" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
  5239. fi ;; # $SECONDADDR, NUMCOND
  5240. esac
  5241. PORT=$((PORT+1))
  5242. N=$((N+1))
  5243. # like TCP4RANGEMASK, but the "bad" address is within the same class A network
  5244. NAME=TCP4RANGEMASKHAIRY
  5245. case "$TESTS" in
  5246. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  5247. TEST="$NAME: security of TCP4-L with RANGE option"
  5248. if ! eval $NUMCOND; then :; else
  5249. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=127.0.0.0:255.255.0.0" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
  5250. fi ;; # Linux, NUMCOND
  5251. esac
  5252. PORT=$((PORT+1))
  5253. N=$((N+1))
  5254. NAME=TCP4SOURCEPORT
  5255. case "$TESTS" in
  5256. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
  5257. TEST="$NAME: security of TCP4-L with SOURCEPORT option"
  5258. if ! eval $NUMCOND; then :; else
  5259. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
  5260. fi ;; # NUMCOND
  5261. esac
  5262. PORT=$((PORT+1))
  5263. N=$((N+1))
  5264. NAME=TCP4LOWPORT
  5265. case "$TESTS" in
  5266. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
  5267. TEST="$NAME: security of TCP4-L with LOWPORT option"
  5268. if ! eval $NUMCOND; then :; else
  5269. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
  5270. fi ;; # NUMCOND
  5271. esac
  5272. PORT=$((PORT+1))
  5273. N=$((N+1))
  5274. NAME=TCP4WRAPPERS_ADDR
  5275. case "$TESTS" in
  5276. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
  5277. TEST="$NAME: security of TCP4-L with TCPWRAP option"
  5278. if ! eval $NUMCOND; then :;
  5279. elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
  5280. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5281. numCANT=$((numCANT+1))
  5282. else
  5283. ha="$td/hosts.allow"
  5284. hd="$td/hosts.deny"
  5285. $ECHO "socat: $SECONDADDR" >"$ha"
  5286. $ECHO "ALL: ALL" >"$hd"
  5287. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
  5288. fi ;; # NUMCOND, feats
  5289. esac
  5290. PORT=$((PORT+1))
  5291. N=$((N+1))
  5292. NAME=TCP4WRAPPERS_NAME
  5293. case "$TESTS" in
  5294. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
  5295. TEST="$NAME: security of TCP4-L with TCPWRAP option"
  5296. if ! eval $NUMCOND; then :;
  5297. elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
  5298. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5299. numCANT=$((numCANT+1))
  5300. else
  5301. ha="$td/hosts.allow"
  5302. hd="$td/hosts.deny"
  5303. $ECHO "socat: $LOCALHOST" >"$ha"
  5304. $ECHO "ALL: ALL" >"$hd"
  5305. testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
  5306. fi ;; # NUMCOND, feats
  5307. esac
  5308. PORT=$((PORT+1))
  5309. N=$((N+1))
  5310. NAME=TCP6RANGE
  5311. case "$TESTS" in
  5312. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%range%*|*%$NAME%*)
  5313. TEST="$NAME: security of TCP6-L with RANGE option"
  5314. if ! eval $NUMCOND; then :;
  5315. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5316. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5317. numCANT=$((numCANT+1))
  5318. else
  5319. testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "range=[::2]/128" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
  5320. fi ;; # NUMCOND, feats
  5321. esac
  5322. PORT=$((PORT+1))
  5323. N=$((N+1))
  5324. NAME=TCP6SOURCEPORT
  5325. case "$TESTS" in
  5326. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
  5327. TEST="$NAME: security of TCP6-L with SOURCEPORT option"
  5328. if ! eval $NUMCOND; then :;
  5329. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5330. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5331. numCANT=$((numCANT+1))
  5332. else
  5333. testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
  5334. fi ;; # NUMCOND, feats
  5335. esac
  5336. PORT=$((PORT+1))
  5337. N=$((N+1))
  5338. NAME=TCP6LOWPORT
  5339. case "$TESTS" in
  5340. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
  5341. TEST="$NAME: security of TCP6-L with LOWPORT option"
  5342. if ! eval $NUMCOND; then :;
  5343. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5344. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5345. numCANT=$((numCANT+1))
  5346. else
  5347. testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
  5348. fi ;; # NUMCOND, feats
  5349. esac
  5350. PORT=$((PORT+1))
  5351. N=$((N+1))
  5352. NAME=TCP6TCPWRAP
  5353. case "$TESTS" in
  5354. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
  5355. TEST="$NAME: security of TCP6-L with TCPWRAP option"
  5356. if ! eval $NUMCOND; then :;
  5357. elif ! feat=$(testaddrs tcp ip6 libwrap && runstcp6); then
  5358. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5359. numCANT=$((numCANT+1))
  5360. else
  5361. ha="$td/hosts.allow"
  5362. hd="$td/hosts.deny"
  5363. $ECHO "socat: [::2]" >"$ha"
  5364. $ECHO "ALL: ALL" >"$hd"
  5365. testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
  5366. fi ;; # NUMCOND, feats
  5367. esac
  5368. PORT=$((PORT+1))
  5369. N=$((N+1))
  5370. NAME=UDP4RANGE
  5371. case "$TESTS" in
  5372. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  5373. TEST="$NAME: security of UDP4-L with RANGE option"
  5374. if ! eval $NUMCOND; then :; else
  5375. #testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
  5376. testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
  5377. fi ;; # NUMCOND
  5378. esac
  5379. PORT=$((PORT+1))
  5380. N=$((N+1))
  5381. NAME=UDP4SOURCEPORT
  5382. case "$TESTS" in
  5383. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
  5384. TEST="$NAME: security of UDP4-L with SOURCEPORT option"
  5385. if ! eval $NUMCOND; then :; else
  5386. testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "sp=$PORT" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
  5387. fi ;; # NUMCOND
  5388. esac
  5389. PORT=$((PORT+1))
  5390. N=$((N+1))
  5391. NAME=UDP4LOWPORT
  5392. case "$TESTS" in
  5393. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
  5394. TEST="$NAME: security of UDP4-L with LOWPORT option"
  5395. if ! eval $NUMCOND; then :; else
  5396. testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "lowport" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
  5397. fi ;; # NUMCOND
  5398. esac
  5399. PORT=$((PORT+1))
  5400. N=$((N+1))
  5401. NAME=UDP4TCPWRAP
  5402. case "$TESTS" in
  5403. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
  5404. TEST="$NAME: security of UDP4-L with TCPWRAP option"
  5405. if ! eval $NUMCOND; then :;
  5406. elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
  5407. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5408. numCANT=$((numCANT+1))
  5409. else
  5410. ha="$td/hosts.allow"
  5411. hd="$td/hosts.deny"
  5412. $ECHO "socat: $SECONDADDR" >"$ha"
  5413. $ECHO "ALL: ALL" >"$hd"
  5414. testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
  5415. fi ;; # NUMCOND, feats
  5416. esac
  5417. PORT=$((PORT+1))
  5418. N=$((N+1))
  5419. NAME=UDP6RANGE
  5420. case "$TESTS" in
  5421. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
  5422. TEST="$NAME: security of UDP6-L with RANGE option"
  5423. if ! eval $NUMCOND; then :;
  5424. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5425. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5426. numCANT=$((numCANT+1))
  5427. else
  5428. #testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
  5429. testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
  5430. fi ;; # NUMCOND, feats
  5431. esac
  5432. PORT=$((PORT+1))
  5433. N=$((N+1))
  5434. NAME=UDP6SOURCEPORT
  5435. case "$TESTS" in
  5436. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
  5437. TEST="$NAME: security of UDP6-L with SOURCEPORT option"
  5438. if ! eval $NUMCOND; then :;
  5439. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  5440. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  5441. numCANT=$((numCANT+1))
  5442. else
  5443. testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "sp=$PORT" "udp6:[::1]:$PORT" 6 udp $PORT 0
  5444. fi ;; # NUMCOND, feats
  5445. esac
  5446. PORT=$((PORT+1))
  5447. N=$((N+1))
  5448. NAME=UDP6LOWPORT
  5449. case "$TESTS" in
  5450. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
  5451. TEST="$NAME: security of UDP6-L with LOWPORT option"
  5452. if ! eval $NUMCOND; then :;
  5453. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  5454. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  5455. numCANT=$((numCANT+1))
  5456. else
  5457. testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
  5458. fi ;; # NUMCOND, feats
  5459. esac
  5460. PORT=$((PORT+1))
  5461. N=$((N+1))
  5462. NAME=UDP6TCPWRAP
  5463. case "$TESTS" in
  5464. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
  5465. TEST="$NAME: security of UDP6-L with TCPWRAP option"
  5466. if ! eval $NUMCOND; then :;
  5467. elif ! feat=$(testaddrs tcp ip6 libwrap && runsip6); then
  5468. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5469. numCANT=$((numCANT+1))
  5470. else
  5471. ha="$td/hosts.allow"
  5472. hd="$td/hosts.deny"
  5473. $ECHO "socat: [::2]" >"$ha"
  5474. $ECHO "ALL: ALL" >"$hd"
  5475. testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
  5476. fi ;; # NUMCOND, feats
  5477. esac
  5478. PORT=$((PORT+1))
  5479. N=$((N+1))
  5480. NAME=OPENSSLTCP4_RANGE
  5481. case "$TESTS" in
  5482. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%range%*|*%$NAME%*)
  5483. TEST="$NAME: security of SSL-L over TCP/IPv4 with RANGE option"
  5484. if ! eval $NUMCOND; then :;
  5485. elif ! testaddrs openssl >/dev/null; then
  5486. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5487. numCANT=$((numCANT+1))
  5488. else
  5489. gentestcert testsrv
  5490. testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "range=$SECONDADDR/32" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
  5491. fi ;; # NUMCOND, feats
  5492. esac
  5493. PORT=$((PORT+1))
  5494. N=$((N+1))
  5495. NAME=OPENSSLTCP4_SOURCEPORT
  5496. case "$TESTS" in
  5497. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
  5498. TEST="$NAME: security of SSL-L with SOURCEPORT option"
  5499. if ! eval $NUMCOND; then :;
  5500. elif ! testaddrs openssl >/dev/null; then
  5501. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5502. numCANT=$((numCANT+1))
  5503. else
  5504. gentestcert testsrv
  5505. testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "sp=$PORT" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
  5506. fi ;; # NUMCOND, feats
  5507. esac
  5508. PORT=$((PORT+1))
  5509. N=$((N+1))
  5510. NAME=OPENSSLTCP4_LOWPORT
  5511. case "$TESTS" in
  5512. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%lowport%*|*%$NAME%*)
  5513. TEST="$NAME: security of SSL-L with LOWPORT option"
  5514. if ! eval $NUMCOND; then :;
  5515. elif ! testaddrs openssl >/dev/null; then
  5516. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5517. numCANT=$((numCANT+1))
  5518. else
  5519. gentestcert testsrv
  5520. testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "lowport" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
  5521. fi ;; # NUMCOND, feats
  5522. esac
  5523. PORT=$((PORT+1))
  5524. N=$((N+1))
  5525. NAME=OPENSSLTCP4_TCPWRAP
  5526. case "$TESTS" in
  5527. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
  5528. TEST="$NAME: security of SSL-L with TCPWRAP option"
  5529. if ! eval $NUMCOND; then :;
  5530. elif ! feat=$(testaddrs ip4 tcp libwrap openssl); then
  5531. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5532. numCANT=$((numCANT+1))
  5533. else
  5534. gentestcert testsrv
  5535. ha="$td/hosts.allow"
  5536. hd="$td/hosts.deny"
  5537. $ECHO "socat: $SECONDADDR" >"$ha"
  5538. $ECHO "ALL: ALL" >"$hd"
  5539. testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "tcpwrap-etc=$td" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
  5540. fi ;; # NUMCOND, feats
  5541. esac
  5542. PORT=$((PORT+1))
  5543. N=$((N+1))
  5544. NAME=OPENSSLCERTSERVER
  5545. case "$TESTS" in
  5546. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
  5547. TEST="$NAME: security of SSL-L with client certificate"
  5548. if ! eval $NUMCOND; then :;
  5549. elif ! testaddrs openssl >/dev/null; then
  5550. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5551. numCANT=$((numCANT+1))
  5552. else
  5553. gentestcert testsrv
  5554. gentestcert testcli
  5555. testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify,cert=testsrv.crt,key=testsrv.key" "cafile=testcli.crt" "cafile=testsrv.crt" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,cert=testcli.pem,$SOCAT_EGD" 4 tcp $PORT -1
  5556. fi ;; # NUMCOND, feats
  5557. esac
  5558. PORT=$((PORT+1))
  5559. N=$((N+1))
  5560. NAME=OPENSSLCERTCLIENT
  5561. case "$TESTS" in
  5562. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
  5563. TEST="$NAME: security of SSL with server certificate"
  5564. if ! eval $NUMCOND; then :;
  5565. elif ! testaddrs openssl >/dev/null; then
  5566. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5567. numCANT=$((numCANT+1))
  5568. else
  5569. gentestcert testsrv
  5570. gentestcert testcli
  5571. testserversec "$N" "$TEST" "$opts -t 0.5 -lu -d" "ssl:$LOCALHOST:$PORT,pf=ip4,fork,retry=2,verify,cert=testcli.pem,$SOCAT_EGD" "cafile=testsrv.crt" "cafile=testcli.crt" "ssl-l:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cafile=testcli.crt,cert=testsrv.crt,key=testsrv.key" 4 tcp "" -1
  5572. fi ;; # NUMCOND, feats
  5573. esac
  5574. PORT=$((PORT+1))
  5575. N=$((N+1))
  5576. NAME=OPENSSLTCP6_RANGE
  5577. case "$TESTS" in
  5578. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%range%*|*%$NAME%*)
  5579. TEST="$NAME: security of SSL-L over TCP/IPv6 with RANGE option"
  5580. if ! eval $NUMCOND; then :;
  5581. elif ! testaddrs openssl >/dev/null; then
  5582. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5583. numCANT=$((numCANT+1))
  5584. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5585. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5586. numCANT=$((numCANT+1))
  5587. else
  5588. gentestcert6 testsrv6
  5589. testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "range=[::2]/128" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
  5590. fi ;; # NUMCOND, feats
  5591. esac
  5592. PORT=$((PORT+1))
  5593. N=$((N+1))
  5594. NAME=OPENSSLTCP6_SOURCEPORT
  5595. case "$TESTS" in
  5596. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
  5597. TEST="$NAME: security of SSL-L over TCP/IPv6 with SOURCEPORT option"
  5598. if ! eval $NUMCOND; then :;
  5599. elif ! testaddrs openssl >/dev/null; then
  5600. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5601. numCANT=$((numCANT+1))
  5602. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5603. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5604. numCANT=$((numCANT+1))
  5605. else
  5606. gentestcert6 testsrv6
  5607. testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "sp=$PORT" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
  5608. fi ;; # NUMCOND, feats
  5609. esac
  5610. PORT=$((PORT+1))
  5611. N=$((N+1))
  5612. NAME=OPENSSLTCP6_LOWPORT
  5613. case "$TESTS" in
  5614. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%lowport%*|*%$NAME%*)
  5615. TEST="$NAME: security of SSL-L over TCP/IPv6 with LOWPORT option"
  5616. if ! eval $NUMCOND; then :;
  5617. elif ! testaddrs openssl >/dev/null; then
  5618. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5619. numCANT=$((numCANT+1))
  5620. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  5621. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  5622. numCANT=$((numCANT+1))
  5623. else
  5624. gentestcert6 testsrv6
  5625. testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "lowport" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
  5626. fi ;; # NUMCOND, feats
  5627. esac
  5628. PORT=$((PORT+1))
  5629. N=$((N+1))
  5630. NAME=OPENSSLTCP6_TCPWRAP
  5631. case "$TESTS" in
  5632. *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
  5633. TEST="$NAME: security of SSL-L over TCP/IPv6 with TCPWRAP option"
  5634. if ! eval $NUMCOND; then :;
  5635. elif ! feat=$(testaddrs ip6 tcp libwrap openssl && runsip6); then
  5636. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  5637. numCANT=$((numCANT+1))
  5638. else
  5639. gentestcert6 testsrv6
  5640. ha="$td/hosts.allow"
  5641. hd="$td/hosts.deny"
  5642. $ECHO "socat: [::2]" >"$ha"
  5643. $ECHO "ALL: ALL" >"$hd"
  5644. testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "tcpwrap-etc=$td" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
  5645. fi ;; # NUMCOND, feats
  5646. esac
  5647. PORT=$((PORT+1))
  5648. N=$((N+1))
  5649. # test security with the openssl-commonname option on client side
  5650. NAME=OPENSSL_CN_CLIENT_SECURITY
  5651. case "$TESTS" in
  5652. *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  5653. TEST="$NAME: security of client openssl-commonname option"
  5654. # connect using non matching server name/address with commonname
  5655. # options, this should succeed. Then without this option, should fail
  5656. if ! eval $NUMCOND; then :;
  5657. elif ! testaddrs openssl >/dev/null; then
  5658. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5659. numCANT=$((numCANT+1))
  5660. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  5661. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  5662. numCANT=$((numCANT+1))
  5663. else
  5664. gentestcert testsrv
  5665. gentestcert testcli
  5666. testserversec "$N" "$TEST" "$opts -t 0.5 -4" "SSL:127.0.0.1:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "commonname=$LOCALHOST" "" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0" 4 tcp "" 0
  5667. fi ;; # testaddrs, NUMCOND
  5668. esac
  5669. PORT=$((PORT+1))
  5670. N=$((N+1))
  5671. # test security with the openssl-commonname option on server side
  5672. NAME=OPENSSL_CN_SERVER_SECURITY
  5673. case "$TESTS" in
  5674. *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  5675. TEST="$NAME: security of server openssl-commonname option"
  5676. # connect using with client certificate to server, this should succeed.
  5677. # Then use the server with a non matching openssl-commonname option,
  5678. # this must fail
  5679. if ! eval $NUMCOND; then :;
  5680. elif ! testaddrs openssl >/dev/null; then
  5681. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5682. numCANT=$((numCANT+1))
  5683. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  5684. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  5685. numCANT=$((numCANT+1))
  5686. else
  5687. gentestcert testsrv
  5688. gentestcert testcli
  5689. testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt" "" "commonname=onlyyou" "SSL:$LOCALHOST:$PORT,$REUSEADDR,verify=0,cafile=testsrv.crt,cert=testcli.crt,key=testcli.key" 4 tcp "$PORT" 0
  5690. fi ;; # testaddrs, NUMCOND
  5691. esac
  5692. PORT=$((PORT+1))
  5693. N=$((N+1))
  5694. NAME=OPENSSL_FIPS_SECURITY
  5695. case "$TESTS" in
  5696. *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  5697. TEST="$NAME: OpenSSL restrictions by FIPS"
  5698. if ! eval $NUMCOND; then :;
  5699. elif ! testaddrs openssl >/dev/null; then
  5700. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5701. numCANT=$((numCANT+1))
  5702. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  5703. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  5704. numCANT=$((numCANT+1))
  5705. elif ! testoptions fips >/dev/null; then
  5706. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
  5707. numCANT=$((numCANT+1))
  5708. else
  5709. gentestcert testsrv
  5710. gentestcert testcli
  5711. # openssl client accepts a "normal" certificate only when not in fips mode
  5712. testserversec "$N" "$TEST" "$opts" "ssl:$LOCALHOST:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "" "fips" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key" 4 tcp "" -1
  5713. fi ;; # testaddrs, NUMCOND
  5714. esac
  5715. PORT=$((PORT+1))
  5716. N=$((N+1))
  5717. NAME=UNIEXECEOF
  5718. case "$TESTS" in
  5719. *%$N%*|*%functions%*|*%$NAME%*)
  5720. TEST="$NAME: give exec'd write-only process a chance to flush (-u)"
  5721. testod "$N" "$TEST" "" exec:"$OD_C" "$opts -u"
  5722. esac
  5723. N=$((N+1))
  5724. NAME=REVEXECEOF
  5725. case "$TESTS" in
  5726. *%$N%*|*%functions%*|*%$NAME%*)
  5727. TEST="$NAME: give exec'd write-only process a chance to flush (-U)"
  5728. testod "$N" "$TEST" exec:"$OD_C" "-" "$opts -U"
  5729. esac
  5730. N=$((N+1))
  5731. NAME=FILANDIR
  5732. case "$TESTS" in
  5733. *%$N%*|*%filan%*|*%$NAME%*)
  5734. TEST="$NAME: check type printed for directories"
  5735. if ! eval $NUMCOND; then :; else
  5736. te="$td/test$N.stderr"
  5737. printf "test $F_n $TEST... " $N
  5738. type=$($FILAN -f . 2>$te |tail -n 1 |awk '{print($2);}')
  5739. if [ "$type" = "dir" ]; then
  5740. $PRINTF "$OK\n"
  5741. numOK=$((numOK+1))
  5742. else
  5743. $PRINTF "$FAILED\n"
  5744. cat "$te"
  5745. numFAIL=$((numFAIL+1))
  5746. listFAIL="$listFAIL $N"
  5747. fi
  5748. fi ;; # NUMCOND
  5749. esac
  5750. N=$((N+1))
  5751. NAME=FILANSOCKET
  5752. case "$TESTS" in
  5753. *%$N%*|*%filan%*|*%$NAME%*)
  5754. TEST="$NAME: capability to analyze named unix socket"
  5755. if ! eval $NUMCOND; then :; else
  5756. ts="$td/test$N.socket"
  5757. te1="$td/test$N.stderr1" # socat
  5758. te2="$td/test$N.stderr2" # filan
  5759. printf "test $F_n $TEST... " $N
  5760. $TRACE $SOCAT $opts UNIX-LISTEN:"$ts" /dev/null </dev/null 2>"$te1" &
  5761. spid=$!
  5762. waitfile "$ts" 1
  5763. type=$($FILAN -f "$ts" 2>$te2 |tail -n 1 |awk '{print($2);}')
  5764. if [ "$type" = "socket" ]; then
  5765. $PRINTF "$OK\n"
  5766. numOK=$((numOK+1))
  5767. else
  5768. $PRINTF "$FAILED\n"
  5769. cat "$te1"
  5770. cat "$te2"
  5771. numFAIL=$((numFAIL+1))
  5772. listFAIL="$listFAIL $N"
  5773. fi
  5774. kill $spid 2>/dev/null
  5775. wait
  5776. fi ;; # NUMCOND
  5777. esac
  5778. N=$((N+1))
  5779. testptywaitslave () {
  5780. local N="$1"
  5781. local TEST="$2"
  5782. local PTYTYPE="$3" # ptmx or openpty
  5783. local opts="$4"
  5784. local tp="$td/test$N.pty"
  5785. local ts="$td/test$N.socket"
  5786. local tf="$td/test$N.file"
  5787. local tdiff="$td/test$N.diff"
  5788. local te1="$td/test$N.stderr1"
  5789. local te2="$td/test$N.stderr2"
  5790. local te3="$td/test$N.stderr3"
  5791. local te4="$td/test$N.stderr4"
  5792. local da="test$N $(date) $RANDOM"
  5793. printf "test $F_n $TEST... " $N
  5794. # first generate a pty, then a socket
  5795. ($TRACE $SOCAT $opts -lpsocat1 pty,$PTYTYPE,pty-wait-slave,link="$tp" unix-listen:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev/null &
  5796. pid=$!
  5797. waitfile "$tp"
  5798. # if pty was non-blocking, the socket is active, and socat1 will term
  5799. $TRACE $SOCAT $opts -T 10 -lpsocat2 file:/dev/null unix-connect:"$ts" 2>"$te2"
  5800. # if pty is blocking, first socat is still active and we get a connection now
  5801. #((echo "$da"; sleep 2) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
  5802. ( (waitfile "$ts"; echo "$da"; sleep 1) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
  5803. waitfile "$ts"
  5804. # but we need an echoer on the socket
  5805. $TRACE $SOCAT $opts -lpsocat4 unix:"$ts" echo 2>"$te4"
  5806. # now $tf file should contain $da
  5807. #kill $pid 2>/dev/null
  5808. wait
  5809. #
  5810. if echo "$da" |diff - "$tf"> "$tdiff"; then
  5811. $PRINTF "$OK\n"
  5812. numOK=$((numOK+1))
  5813. else
  5814. $PRINTF "${YELLOW}FAILED${NORMAL}\n"
  5815. cat "$te1"
  5816. #cat "$te2" # not of interest
  5817. cat "$te3"
  5818. cat "$te4"
  5819. cat "$tdiff"
  5820. numCANT=$((numCANT+1))
  5821. fi
  5822. }
  5823. NAME=PTMXWAITSLAVE
  5824. PTYTYPE=ptmx
  5825. case "$TESTS" in
  5826. *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
  5827. TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
  5828. if ! eval $NUMCOND; then :; else
  5829. if ! feat=$(testaddrs pty); then
  5830. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  5831. numCANT=$((numCANT+1))
  5832. elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
  5833. $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  5834. numCANT=$((numCANT+1))
  5835. else
  5836. testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
  5837. fi
  5838. fi ;; # NUMCOND
  5839. esac
  5840. N=$((N+1))
  5841. NAME=OPENPTYWAITSLAVE
  5842. PTYTYPE=openpty
  5843. case "$TESTS" in
  5844. *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
  5845. TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
  5846. if ! eval $NUMCOND; then :;
  5847. elif ! feat=$(testaddrs pty); then
  5848. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  5849. numCANT=$((numCANT+1))
  5850. elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
  5851. $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  5852. numCANT=$((numCANT+1))
  5853. else
  5854. testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
  5855. fi ;; # NUMCOND, feats
  5856. esac
  5857. N=$((N+1))
  5858. NAME=CONNECTTIMEOUT
  5859. case "$TESTS" in
  5860. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
  5861. TEST="$NAME: test the connect-timeout option"
  5862. if ! eval $NUMCOND; then :;
  5863. elif ! feat=$(testaddrs tcp); then
  5864. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  5865. numCANT=$((numCANT+1))
  5866. elif ! feat=$(testoptions connect-timeout); then
  5867. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  5868. numCANT=$((numCANT+1))
  5869. else
  5870. # we need a hanging connection attempt, guess an address for this
  5871. case "$UNAME" in
  5872. Linux) HANGIP=1.0.0.1 ;;
  5873. *) HANGIP=255.255.255.254 ;;
  5874. esac
  5875. te1="$td/test$N.stderr1"
  5876. tk1="$td/test$N.kill1"
  5877. te2="$td/test$N.stderr2"
  5878. tk2="$td/test$N.kill2"
  5879. $PRINTF "test $F_n $TEST... " $N
  5880. # first, try to make socat hang and see if it can be killed
  5881. #$TRACE $SOCAT $opts - tcp:$HANGIP:1 >"$te1" 2>&1 </dev/null &
  5882. CMD="$TRACE $SOCAT $opts - tcp:$HANGIP:1"
  5883. $CMD >"$te1" 2>&1 </dev/null &
  5884. pid1=$!
  5885. sleep 2
  5886. if ! kill $pid1 2>"$tk1"; then
  5887. $PRINTF "${YELLOW}does not hang${NORMAL}\n"
  5888. numCANT=$((numCANT+1))
  5889. else
  5890. # second, set connect-timeout and see if socat exits before kill
  5891. $TRACE $SOCAT $opts - tcp:$HANGIP:1,connect-timeout=1.0 >"$te2" 2>&1 </dev/null &
  5892. pid2=$!
  5893. sleep 2
  5894. if kill $pid2 2>"$tk2"; then
  5895. $PRINTF "$FAILED\n"
  5896. echo "$CMD"
  5897. cat "$te1"
  5898. cat "$te2"
  5899. numFAIL=$((numFAIL+1))
  5900. listFAIL="$listFAIL $N"
  5901. else
  5902. $PRINTF "$OK\n"
  5903. numOK=$((numOK+1))
  5904. fi
  5905. fi
  5906. wait
  5907. fi ;; # testaddrs, NUMCOND
  5908. esac
  5909. N=$((N+1))
  5910. # version 1.7.0.0 had a bug with the connect-timeout option: while it correctly
  5911. # terminated a hanging connect attempt, it prevented a successful connection
  5912. # establishment from being recognized by socat, instead the timeout occurred
  5913. NAME=CONNECTTIMEOUT_CONN
  5914. if ! eval $NUMCOND; then :; else
  5915. case "$TESTS" in
  5916. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
  5917. TEST="$NAME: TCP4 connect-timeout option when server replies"
  5918. # just try a connection that is expected to succeed with the usual data
  5919. # transfer; with the bug it will fail
  5920. tf="$td/test$N.stdout"
  5921. te="$td/test$N.stderr"
  5922. tdiff="$td/test$N.diff"
  5923. tsl=$PORT
  5924. ts="127.0.0.1:$tsl"
  5925. da="test$N $(date) $RANDOM"
  5926. CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
  5927. CMD2="$TRACE $SOCAT $opts STDIO TCP4:$ts,connect-timeout=1"
  5928. printf "test $F_n $TEST... " $N
  5929. $CMD1 >"$tf" 2>"${te}1" &
  5930. pid1=$!
  5931. waittcp4port $tsl 1
  5932. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  5933. if [ $? -ne 0 ]; then
  5934. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  5935. echo "$CMD1 &"
  5936. cat "${te}1"
  5937. echo "$CMD2"
  5938. cat "${te}2"
  5939. numFAIL=$((numFAIL+1))
  5940. listFAIL="$listFAIL $N"
  5941. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  5942. $PRINTF "$FAILED\n"
  5943. cat "$tdiff"
  5944. numFAIL=$((numFAIL+1))
  5945. listFAIL="$listFAIL $N"
  5946. else
  5947. $PRINTF "$OK\n"
  5948. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  5949. numOK=$((numOK+1))
  5950. fi
  5951. kill $pid1 2>/dev/null
  5952. wait ;;
  5953. esac
  5954. PORT=$((PORT+1))
  5955. fi # NUMCOND
  5956. N=$((N+1))
  5957. NAME=OPENSSLLISTENDSA
  5958. case "$TESTS" in
  5959. *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
  5960. TEST="$NAME: openssl listen with DSA certificate"
  5961. if ! eval $NUMCOND; then :;
  5962. elif ! testaddrs openssl >/dev/null; then
  5963. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  5964. numCANT=$((numCANT+1))
  5965. else
  5966. SRVCERT=testsrvdsa
  5967. gentestdsacert $SRVCERT
  5968. tf="$td/test$N.stdout"
  5969. te="$td/test$N.stderr"
  5970. tdiff="$td/test$N.diff"
  5971. da="test$N $(date) $RANDOM"
  5972. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe"
  5973. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
  5974. $PRINTF "test $F_n $TEST... " $N
  5975. eval "$CMD2 2>\"${te}1\" &"
  5976. pid=$! # background process id
  5977. waittcp4port $PORT
  5978. echo "$da" |$CMD >$tf 2>"${te}2"
  5979. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  5980. $PRINTF "$FAILED\n"
  5981. echo "$CMD2 &"
  5982. echo "$CMD"
  5983. cat "${te}1"
  5984. cat "${te}2"
  5985. cat "$tdiff"
  5986. numFAIL=$((numFAIL+1))
  5987. listFAIL="$listFAIL $N"
  5988. else
  5989. $PRINTF "$OK\n"
  5990. if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
  5991. numOK=$((numOK+1))
  5992. fi
  5993. kill $pid 2>/dev/null
  5994. wait
  5995. fi ;; # testaddrs, NUMCOND
  5996. esac
  5997. PORT=$((PORT+1))
  5998. N=$((N+1))
  5999. # derive signal number from signal name
  6000. # kill -l should provide the info
  6001. signum () {
  6002. if [ ! "$BASH_VERSION" -o -o posix ]; then
  6003. # we expect:
  6004. for i in $(POSIXLY_CORRECT=1 kill -l); do echo "$i"; done |grep -n -i "^$1$" |cut -d: -f1
  6005. else
  6006. # expect:
  6007. # " 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL"
  6008. signam="$1"
  6009. kill -l </dev/null |
  6010. while read l; do printf "%s %s\n%s %s\n%s %s\n%s %s\n" $l; done |
  6011. grep -e "SIG$signam\$" |
  6012. cut -d ')' -f 1
  6013. fi
  6014. }
  6015. # problems with QUIT, INT (are blocked in system() )
  6016. for signam in TERM ILL; do
  6017. NAME=EXITCODESIG$signam
  6018. case "$TESTS" in
  6019. *%$N%*|*%functions%*|*%pty%*|*%signal%*|*%$NAME%*)
  6020. TEST="$NAME: exit status when dying on SIG$signam"
  6021. if ! eval $NUMCOND; then :;
  6022. elif ! feat=$(testaddrs pty); then
  6023. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
  6024. numCANT=$((numCANT+1))
  6025. else
  6026. SIG="$(signum $signam)"
  6027. te="$td/test$N.stderr"
  6028. tpp="$td/test$N.ppid"
  6029. tp="$td/test$N.pid"
  6030. $PRINTF "test $F_n $TEST... " $N
  6031. (sleep 1; kill -"$SIG" "$(cat "$tpp")") &
  6032. # a simple "system:echo $PPID..." does not work on NetBSD, OpenBSD
  6033. #$TRACE $SOCAT $opts echo SYSTEM:'exec /usr/bin/env bash -c "echo \$PPID '">$tpp"'; echo \$$ '">$tp; read x\"",nofork 2>"$te"; stat=$?
  6034. tsh="$td/test$N.sh"
  6035. cat <<EOF >"$tsh"
  6036. #! /usr/bin/env bash
  6037. echo \$PPID >"$tpp"
  6038. echo \$\$ >"$tp"
  6039. read x
  6040. EOF
  6041. chmod a+x "$tsh"
  6042. #$TRACE $SOCAT $opts echo SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"; stat=$?
  6043. CMD="$TRACE $SOCAT $opts ECHO SYSTEM:\"exec\\\ \\\"$tsh\\\"\",pty,setsid,nofork"
  6044. $TRACE $SOCAT $opts ECHO SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"
  6045. stat=$?
  6046. sleep 1; kill -INT $(cat $tp)
  6047. wait
  6048. if [ "$stat" -eq $((128+$SIG)) ]; then
  6049. $PRINTF "$OK\n"
  6050. numOK=$((numOK+1))
  6051. else
  6052. $PRINTF "$FAILED\n"
  6053. echo "$CMD"
  6054. cat "$te"
  6055. numFAIL=$((numFAIL+1))
  6056. listFAIL="$listFAIL $N"
  6057. fi
  6058. wait
  6059. fi ;; # NUMCOND, feats
  6060. esac
  6061. N=$((N+1))
  6062. done
  6063. NAME=READBYTES
  6064. #set -vx
  6065. case "$TESTS" in
  6066. *%$N%*|*%functions%*|*%$NAME%*)
  6067. TEST="$NAME: restrict reading from file with bytes option"
  6068. if ! eval $NUMCOND; then :;
  6069. elif false; then
  6070. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  6071. numCANT=$((numCANT+1))
  6072. else
  6073. tr="$td/test$N.ref"
  6074. ti="$td/test$N.in"
  6075. to="$td/test$N.out"
  6076. te="$td/test$N.err"
  6077. tdiff="$td/test$N.diff"
  6078. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  6079. # the feature that we really want to test is in the readline.sh script:
  6080. CMD="$TRACE $SOCAT $opts -u open:$ti,readbytes=100 -"
  6081. printf "test $F_n $TEST... " $N
  6082. rm -f "$tf" "$ti" "$to"
  6083. #
  6084. echo "AAAAAAAAAAAAAAAAAAAAAAAA
  6085. AAAAAAAAAAAAAAAAAAAAAAAA
  6086. AAAAAAAAAAAAAAAAAAAAAAAA
  6087. AAAAAAAAAAAAAAAAAAAAAAAA" >"$tr" # 100 bytes
  6088. cat "$tr" "$tr" >"$ti" # 200 bytes
  6089. $CMD >"$to" 2>"$te"
  6090. if ! diff "$tr" "$to" >"$tdiff" 2>&1; then
  6091. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6092. echo "$CMD"
  6093. cat "$te"
  6094. cat "$tdiff"
  6095. numFAIL=$((numFAIL+1))
  6096. listFAIL="$listFAIL $N"
  6097. else
  6098. $PRINTF "$OK\n"
  6099. if [ -n "$debug" ]; then cat $te; fi
  6100. numOK=$((numOK+1))
  6101. fi
  6102. fi ;; # NUMCOND, feats
  6103. esac
  6104. N=$((N+1))
  6105. NAME=UDPLISTENFORK
  6106. case "$TESTS" in
  6107. *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%listen%*|*%fork%*|*%$NAME%*)
  6108. TEST="$NAME: UDP socket rebinds after first connection"
  6109. if ! eval $NUMCOND; then :; else
  6110. tf="$td/test$N.stdout"
  6111. te="$td/test$N.stderr"
  6112. tdiff="$td/test$N.diff"
  6113. da1="test$N $(date) $RANDOM"
  6114. da2="test$N $(date) $RANDOM"
  6115. #establish a listening and forking udp socket in background
  6116. #processes hang forever without -T
  6117. SRV="$TRACE $SOCAT -T 5 $opts -lpserver UDP4-LISTEN:$PORT,bind=$LOCALHOST,$REUSEADDR,fork PIPE"
  6118. #make a first and a second connection
  6119. CLI="$TRACE $SOCAT $opts -lpclient - UDP4-CONNECT:$LOCALHOST:$PORT"
  6120. $PRINTF "test $F_n $TEST... " $N
  6121. eval "$SRV 2>${te}s &"
  6122. pids=$!
  6123. waitudp4port "$PORT"
  6124. echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
  6125. if [ $? -ne 0 ]; then
  6126. kill "$pids" 2>/dev/null
  6127. $PRINTF "$NO_RESULT (first conn failed):\n"
  6128. echo "$SRV &"
  6129. echo "$CLI"
  6130. cat "${te}s" "${te}1"
  6131. numCANT=$((numCANT+1))
  6132. elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
  6133. kill "$pids" 2>/dev/null
  6134. $PRINTF "$NO_RESULT (first conn failed); diff:\n"
  6135. cat "$tdiff"
  6136. numCANT=$((numCANT+1))
  6137. else
  6138. sleep 2 # UDP-LISTEN sleeps 1s
  6139. echo "$da2" |eval "$CLI" >"${tf}2" 2>"${te}2"
  6140. rc="$?"; kill "$pids" 2>/dev/null
  6141. if [ $rc -ne 0 ]; then
  6142. $PRINTF "$FAILED:\n"
  6143. echo "$SRV &"
  6144. cat "${te}s"
  6145. echo "$CLI"
  6146. cat "${te}2"
  6147. numFAIL=$((numFAIL+1))
  6148. listFAIL="$listFAIL $N"
  6149. elif ! echo "$da2" |diff - "${tf}2" >"$tdiff"; then
  6150. $PRINTF "$FAILED: diff\n"
  6151. cat "$tdiff"
  6152. numFAIL=$((numFAIL+1))
  6153. listFAIL="$listFAIL $N"
  6154. else
  6155. $PRINTF "$OK\n"
  6156. numOK=$((numOK+1))
  6157. fi # !( $? -ne 0)
  6158. fi # !(rc -ne 0)
  6159. wait
  6160. fi ;; # NUMCOND, feats
  6161. esac
  6162. PORT=$((PORT+1))
  6163. N=$((N+1))
  6164. # is a listen address capable of forking to child processes and have both
  6165. # active?
  6166. while read PROTOV MAJADDR MINADDR; do
  6167. if [ -z "$PROTOV" ] || [[ "$PROTOV" == \#* ]]; then continue; fi
  6168. protov="$(echo "$PROTOV" |tr A-Z a-z)"
  6169. proto="${protov%%[0-9]}"
  6170. NAME=${PROTOV}LISTENFORK
  6171. case "$TESTS" in
  6172. *%$N%*|*%functions%*|*%$protov%*|*%$proto%*|*%listen%*|*%fork%*|*%$NAME%*)
  6173. TEST="$NAME: $PROTOV listen handles 2 concurrent connections"
  6174. # have a listening address with fork option. connect with client1, send a piece
  6175. # of data, wait 1s, connect with client2, send another piece of data, wait 1s,
  6176. # and send another piece of data with client1. The server processes append all
  6177. # data to the same file. Check all data are written to the file in correct
  6178. # order.
  6179. if ! eval $NUMCOND; then :;
  6180. #elif ! feat=$(testaddrs $PROTOV); then
  6181. # $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$PROTOV" |tr a-z A-Z) not available${NORMAL}\n" $N
  6182. # numCANT=$((numCANT+1))
  6183. elif ! runs$protov >/dev/null; then
  6184. $PRINTF "test $F_n $TEST... ${YELLOW}$PROTOV not available${NORMAL}\n" $N
  6185. numCANT=$((numCANT+1))
  6186. else
  6187. ts="$td/test$N.sock"
  6188. tref="$td/test$N.ref"
  6189. tf="$td/test$N.stdout"
  6190. te="$td/test$N.stderr"
  6191. tdiff="$td/test$N.diff"
  6192. da1a="test$N $(date) 1a $RANDOM"
  6193. da1b="test$N $(date) 1b $RANDOM"
  6194. da2="test$N $(date) 2 $RANDOM"
  6195. case "$MAJADDR" in
  6196. "FILE")
  6197. tla="$ts"
  6198. tca="$ts"
  6199. waitproto="file"
  6200. waitfor="$ts" ;;
  6201. esac
  6202. case "$MINADDR" in
  6203. "PORT")
  6204. tla="$PORT,bind=$MAJADDR"
  6205. tca="$MAJADDR:$PORT"
  6206. waitproto="${protov}port"
  6207. waitfor="$PORT" ;;
  6208. esac
  6209. #set -xv
  6210. echo -e "$da1a\n$da2\n$da1b" >"$tref"
  6211. # establish a listening and forking listen socket in background
  6212. # UDP processes hang forever without -T
  6213. CMD0="$TRACE $SOCAT -T 5 $opts -lpserver $PROTOV-LISTEN:$tla,$REUSEADDR,fork PIPE"
  6214. # make a first and a second connection
  6215. CMD1="$TRACE $SOCAT $opts -lpclient - $PROTOV-CONNECT:$tca"
  6216. $PRINTF "test $F_n $TEST... " $N
  6217. eval "$CMD0 2>${te}0 &"
  6218. pid0=$!
  6219. wait$waitproto "$waitfor" 1 2
  6220. (echo "$da1a"; sleep 2; echo "$da1b") |eval "$CMD1" >>"${tf}" 2>"${te}1" &
  6221. sleep 1
  6222. # trailing sleep req for sctp because no half close
  6223. (echo "$da2"; sleep 1) |eval "$CMD1" >>"${tf}" 2>"${te}2" &
  6224. sleep 2
  6225. kill $pid0 2>/dev/null
  6226. wait
  6227. if ! diff "$tref" "$tf" >"$tdiff"; then
  6228. $PRINTF "$FAILED\n"
  6229. cat "${te}0" "${te}1" "${te}2"
  6230. cat "$tdiff"
  6231. numFAIL=$((numFAIL+1))
  6232. listFAIL="$listFAIL $N"
  6233. else
  6234. $PRINTF "$OK\n"
  6235. numOK=$((numOK+1))
  6236. fi # !(rc -ne 0)
  6237. wait
  6238. fi ;; # NUMCOND, feats
  6239. esac
  6240. PORT=$((PORT+1))
  6241. N=$((N+1))
  6242. done <<<"
  6243. TCP4 $LOCALHOST PORT
  6244. TCP6 $LOCALHOST6 PORT
  6245. UDP4 $LOCALHOST PORT
  6246. UDP6 $LOCALHOST6 PORT
  6247. SCTP4 $LOCALHOST PORT
  6248. SCTP6 $LOCALHOST6 PORT
  6249. UNIX FILE ,
  6250. "
  6251. NAME=UNIXTOSTREAM
  6252. case "$TESTS" in
  6253. *%$N%*|*%functions%*|*%unix%*|*%listen%*|*%$NAME%*)
  6254. TEST="$NAME: generic UNIX client connects to stream socket"
  6255. if ! eval $NUMCOND; then :; else
  6256. ts="$td/test$N.socket"
  6257. tf="$td/test$N.stdout"
  6258. te="$td/test$N.stderr"
  6259. tdiff="$td/test$N.diff"
  6260. da1="test$N $(date) $RANDOM"
  6261. #establish a listening unix socket in background
  6262. SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
  6263. #make a connection
  6264. CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts\""
  6265. $PRINTF "test $F_n $TEST... " $N
  6266. eval "$SRV 2>${te}s &"
  6267. pids=$!
  6268. waitfile "$ts"
  6269. echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
  6270. if [ $? -ne 0 ]; then
  6271. kill "$pids" 2>/dev/null
  6272. $PRINTF "$FAILED:\n"
  6273. echo "$SRV &"
  6274. echo "$CLI"
  6275. cat "${te}s" "${te}1"
  6276. numFAIL=$((numFAIL+1))
  6277. listFAIL="$listFAIL $N"
  6278. elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
  6279. kill "$pids" 2>/dev/null
  6280. $PRINTF "$FAILED; diff:\n"
  6281. cat "$tdiff"
  6282. numFAIL=$((numFAIL+1))
  6283. listFAIL="$listFAIL $N"
  6284. else
  6285. $PRINTF "$OK\n"
  6286. numOK=$((numOK+1))
  6287. fi # !(rc -ne 0)
  6288. wait
  6289. fi ;; # NUMCOND
  6290. esac
  6291. N=$((N+1))
  6292. NAME=UNIXTODGRAM
  6293. case "$TESTS" in
  6294. *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%recv%*|*%$NAME%*)
  6295. TEST="$NAME: generic UNIX client connects to datagram socket"
  6296. if ! eval $NUMCOND; then :; else
  6297. ts1="$td/test$N.socket1"
  6298. ts2="$td/test$N.socket2"
  6299. tf="$td/test$N.stdout"
  6300. te="$td/test$N.stderr"
  6301. tdiff="$td/test$N.diff"
  6302. da1="test$N $(date) $RANDOM"
  6303. #establish a receiving unix datagram socket in background
  6304. SRV="$TRACE $SOCAT $opts -lpserver UNIX-RECVFROM:\"$ts1\" PIPE"
  6305. #make a connection
  6306. CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\",bind=\"$ts2\""
  6307. #CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\""
  6308. $PRINTF "test $F_n $TEST... " $N
  6309. eval "$SRV 2>${te}s &"
  6310. pids=$!
  6311. waitfile "$ts1"
  6312. echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
  6313. rc=$?
  6314. wait
  6315. if [ $rc -ne 0 ]; then
  6316. kill "$pids" 2>/dev/null
  6317. $PRINTF "$FAILED:\n"
  6318. echo "$SRV &"
  6319. cat "${te}s"
  6320. echo "$CLI"
  6321. cat "${te}1" "${te}1"
  6322. numFAIL=$((numFAIL+1))
  6323. listFAIL="$listFAIL $N"
  6324. elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
  6325. kill "$pids" 2>/dev/null
  6326. $PRINTF "$FAILED:\n"
  6327. echo "$SRV &"
  6328. cat "${te}s"
  6329. echo "$CLI"
  6330. cat "${te}1"
  6331. cat "$tdiff"
  6332. numFAIL=$((numFAIL+1))
  6333. listFAIL="$listFAIL $N"
  6334. else
  6335. $PRINTF "$OK\n"
  6336. numOK=$((numOK+1))
  6337. fi # !(rc -ne 0)
  6338. fi ;; # NUMCOND
  6339. esac
  6340. N=$((N+1))
  6341. # there was an error in address EXEC with options pipes,stderr
  6342. NAME=EXECPIPESSTDERR
  6343. case "$TESTS" in
  6344. *%$N%*|*%functions%*|*%$NAME%*)
  6345. TEST="$NAME: simple echo via exec of cat with pipes,stderr"
  6346. # this test is known to fail when logging is enabled with OPTS/opts env var.
  6347. SAVE_opts="$opts"
  6348. opts="$(echo "$opts" |sed 's/-d//g')"
  6349. testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
  6350. opts="$SAVE_opts"
  6351. esac
  6352. N=$((N+1))
  6353. # EXEC and SYSTEM with stderr injected socat messages into the data stream.
  6354. NAME=EXECSTDERRLOG
  6355. case "$TESTS" in
  6356. *%$N%*|*%functions%*|*%$NAME%*)
  6357. TEST="$NAME: simple echo via exec of cat with pipes,stderr"
  6358. SAVE_opts="$opts"
  6359. # make sure at least two -d are there
  6360. case "$opts" in
  6361. *-d*-d*) ;;
  6362. *-d*) opts="$opts -d" ;;
  6363. *) opts="-d -d" ;;
  6364. esac
  6365. testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
  6366. opts="$SAVE_opts"
  6367. esac
  6368. N=$((N+1))
  6369. NAME=SIMPLEPARSE
  6370. case "$TESTS" in
  6371. *%$N%*|*%functions%*|*%PARSE%*|*%$NAME%*)
  6372. TEST="$NAME: invoke socat from socat"
  6373. testecho "$N" "$TEST" "" exec:"$SOCAT - exec\:$CAT,pipes" "$opts"
  6374. esac
  6375. N=$((N+1))
  6376. NAME=FULLPARSE
  6377. case "$TESTS" in
  6378. *%$N%*|*%functions%*|*%parse%*|*%$NAME%*)
  6379. TEST="$NAME: correctly parse special chars"
  6380. if ! eval $NUMCOND; then :; else
  6381. $PRINTF "test $F_n $TEST... " $N
  6382. tf="$td/test$N.stdout"
  6383. te="$td/test$N.stderr"
  6384. tdiff="$td/test$N.diff"
  6385. # a string where commas are hidden in nesting lexical constructs
  6386. # if they are scanned incorrectly, socat will see an "unknown option"
  6387. dain='(,)[,]{,}","([),])hugo'
  6388. daout='(,)[,]{,},([),])hugo'
  6389. $TRACE "$SOCAT" $opts -u "exec:echo $dain" - >"$tf" 2>"$te"
  6390. rc=$?
  6391. echo "$daout" |diff "$tf" - >"$tdiff"
  6392. if [ "$rc" -ne 0 ]; then
  6393. $PRINTF "$FAILED:\n"
  6394. echo "$TRACE $SOCAT" -u "exec:echo $da" -
  6395. cat "$te"
  6396. numFAIL=$((numFAIL+1))
  6397. listFAIL="$listFAIL $N"
  6398. elif [ -s "$tdiff" ]; then
  6399. $PRINTF "$FAILED:\n"
  6400. echo diff:
  6401. cat "$tdiff"
  6402. if [ -n "$debug" ]; then cat $te; fi
  6403. numFAIL=$((numFAIL+1))
  6404. listFAIL="$listFAIL $N"
  6405. else
  6406. $PRINTF "$OK\n"
  6407. if [ -n "$debug" ]; then cat $te; fi
  6408. numOK=$((numOK+1))
  6409. fi
  6410. fi ;; # NUMCOND
  6411. esac
  6412. N=$((N+1))
  6413. NAME=NESTEDSOCATEXEC
  6414. case "$TESTS" in
  6415. *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
  6416. TEST="$NAME: does lexical analysis work sensibly (exec)"
  6417. testecho "$N" "$TEST" "" "exec:'$SOCAT - exec:$CAT,pipes'" "$opts" 1
  6418. esac
  6419. N=$((N+1))
  6420. NAME=NESTEDSOCATSYSTEM
  6421. case "$TESTS" in
  6422. *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
  6423. TEST="$NAME: does lexical analysis work sensibly (system)"
  6424. testecho "$N" "$TEST" "" "system:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
  6425. esac
  6426. N=$((N+1))
  6427. NAME=TCP6BYTCP4
  6428. case "$TESTS" in
  6429. *%$N%*|*%functions%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
  6430. TEST="$NAME: TCP4 mapped into TCP6 address space"
  6431. if ! eval $NUMCOND; then :;
  6432. elif true; then
  6433. $PRINTF "test $F_n $TEST... ${YELLOW}Feature removed${NORMAL}\n" $N
  6434. elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  6435. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  6436. numCANT=$((numCANT+1))
  6437. else
  6438. tf="$td/test$N.stdout"
  6439. te="$td/test$N.stderr"
  6440. tdiff="$td/test$N.diff"
  6441. tsl=$PORT
  6442. ts="127.0.0.1:$tsl"
  6443. da="test$N $(date) $RANDOM"
  6444. CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
  6445. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
  6446. printf "test $F_n $TEST... " $N
  6447. $CMD1 >"$tf" 2>"${te}1" &
  6448. pid=$! # background process id
  6449. waittcp6port $tsl 1
  6450. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  6451. if [ $? -ne 0 ]; then
  6452. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6453. echo "$CMD1 &"
  6454. echo "$CMD2"
  6455. cat "${te}1"
  6456. cat "${te}2"
  6457. numFAIL=$((numFAIL+1))
  6458. listFAIL="$listFAIL $N"
  6459. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6460. $PRINTF "$FAILED: diff:\n"
  6461. cat "$tdiff"
  6462. numFAIL=$((numFAIL+1))
  6463. listFAIL="$listFAIL $N"
  6464. else
  6465. $PRINTF "$OK\n"
  6466. if [ -n "$debug" ]; then cat $te; fi
  6467. numOK=$((numOK+1))
  6468. fi
  6469. kill $pid 2>/dev/null; wait
  6470. fi ;; # NUMCOND, feats
  6471. esac
  6472. PORT=$((PORT+1))
  6473. N=$((N+1))
  6474. # test the UDP4-SENDTO and UDP4-RECVFROM addresses together
  6475. NAME=UDP4DGRAM
  6476. case "$TESTS" in
  6477. *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%$NAME%*)
  6478. TEST="$NAME: UDP/IPv4 sendto and recvfrom"
  6479. # start a UDP4-RECVFROM process that echoes data, and send test data using
  6480. # UDP4-SENDTO. The sent data should be returned.
  6481. if ! eval $NUMCOND; then :; else
  6482. tf="$td/test$N.stdout"
  6483. te="$td/test$N.stderr"
  6484. tdiff="$td/test$N.diff"
  6485. ts1p=$PORT; PORT=$((PORT+1))
  6486. ts1a="127.0.0.1"
  6487. ts1="$ts1a:$ts1p"
  6488. ts2p=$PORT; PORT=$((PORT+1))
  6489. ts2="127.0.0.1:$ts2p"
  6490. da="test$N $(date) $RANDOM"
  6491. CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
  6492. CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2"
  6493. printf "test $F_n $TEST... " $N
  6494. $CMD1 2>"${te}1" &
  6495. pid1="$!"
  6496. waitudp4port $ts1p 1
  6497. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  6498. rc2="$?"
  6499. kill "$pid1" 2>/dev/null; wait;
  6500. if [ "$rc2" -ne 0 ]; then
  6501. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6502. echo "$CMD1 &"
  6503. cat "${te}1"
  6504. echo "$CMD2"
  6505. cat "${te}2"
  6506. numFAIL=$((numFAIL+1))
  6507. listFAIL="$listFAIL $N"
  6508. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6509. $PRINTF "$FAILED\n"
  6510. cat "$tdiff"
  6511. echo "$CMD1 &"
  6512. cat "${te}1"
  6513. echo "$CMD2"
  6514. cat "${te}2"
  6515. numFAIL=$((numFAIL+1))
  6516. listFAIL="$listFAIL $N"
  6517. else
  6518. $PRINTF "$OK\n"
  6519. if [ -n "$debug" ]; then cat $te; fi
  6520. numOK=$((numOK+1))
  6521. fi
  6522. fi # NUMCOND
  6523. ;;
  6524. esac
  6525. PORT=$((PORT+1))
  6526. N=$((N+1))
  6527. NAME=UDP6DGRAM
  6528. case "$TESTS" in
  6529. *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%$NAME%*)
  6530. TEST="$NAME: UDP/IPv6 datagram"
  6531. if ! eval $NUMCOND; then :;
  6532. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  6533. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  6534. numCANT=$((numCANT+1))
  6535. else
  6536. tf="$td/test$N.stdout"
  6537. te="$td/test$N.stderr"
  6538. tdiff="$td/test$N.diff"
  6539. ts1p=$PORT; PORT=$((PORT+1))
  6540. tsa="[::1]"
  6541. ts1="$tsa:$ts1p"
  6542. ts2p=$PORT; PORT=$((PORT+1))
  6543. ts2="$tsa:$ts2p"
  6544. da="test$N $(date) $RANDOM"
  6545. CMD1="$TRACE $SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
  6546. CMD2="$TRACE $SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2"
  6547. printf "test $F_n $TEST... " $N
  6548. $CMD1 2>"${te}1" &
  6549. waitudp6port $ts1p 1
  6550. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  6551. if [ $? -ne 0 ]; then
  6552. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6553. echo "$CMD1 &"
  6554. echo "$CMD2"
  6555. cat "${te}1"
  6556. cat "${te}2"
  6557. numFAIL=$((numFAIL+1))
  6558. listFAIL="$listFAIL $N"
  6559. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6560. $PRINTF "$FAILED\n"
  6561. cat "$tdiff"
  6562. numFAIL=$((numFAIL+1))
  6563. listFAIL="$listFAIL $N"
  6564. else
  6565. $PRINTF "$OK\n"
  6566. if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
  6567. numOK=$((numOK+1))
  6568. fi
  6569. fi ;; # NUMCOND, feats
  6570. esac
  6571. PORT=$((PORT+1))
  6572. N=$((N+1))
  6573. NAME=RAWIP4RECVFROM
  6574. case "$TESTS" in
  6575. *%$N%*|*%functions%*|*%ip%*|*%ip4%*|*%rawip%*|*%rawip4%*|*%dgram%*|*%root%*|*%$NAME%*)
  6576. TEST="$NAME: raw IPv4 datagram"
  6577. if ! eval $NUMCOND; then :;
  6578. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  6579. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  6580. numCANT=$((numCANT+1))
  6581. else
  6582. tf="$td/test$N.stdout"
  6583. te="$td/test$N.stderr"
  6584. tdiff="$td/test$N.diff"
  6585. ts1p=$PROTO; PROTO=$((PROTO+1))
  6586. ts1a="127.0.0.1"
  6587. ts1="$ts1a:$ts1p"
  6588. ts2a="$SECONDADDR"
  6589. ts2="$ts2a:$ts2p"
  6590. da="test$N $(date) $RANDOM"
  6591. CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
  6592. CMD2="$TRACE $SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a"
  6593. printf "test $F_n $TEST... " $N
  6594. $CMD1 2>"${te}1" &
  6595. pid1=$!
  6596. waitip4proto $ts1p 1
  6597. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  6598. rc2=$?
  6599. kill $pid1 2>/dev/null; wait
  6600. if [ $rc2 -ne 0 ]; then
  6601. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6602. echo "$CMD1 &"
  6603. echo "$CMD2"
  6604. cat "${te}1"
  6605. cat "${te}2"
  6606. numFAIL=$((numFAIL+1))
  6607. listFAIL="$listFAIL $N"
  6608. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6609. $PRINTF "$FAILED\n"
  6610. cat "$tdiff"
  6611. numFAIL=$((numFAIL+1))
  6612. listFAIL="$listFAIL $N"
  6613. else
  6614. $PRINTF "$OK\n"
  6615. if [ -n "$debug" ]; then cat $te; fi
  6616. numOK=$((numOK+1))
  6617. fi
  6618. fi ;; # root, NUMCOND
  6619. esac
  6620. N=$((N+1))
  6621. if false; then
  6622. NAME=RAWIP6RECVFROM
  6623. case "$TESTS" in
  6624. *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%dgram%*|*%root%*|*%$NAME%*)
  6625. TEST="$NAME: raw IPv6 datagram by self addressing"
  6626. if ! eval $NUMCOND; then :;
  6627. elif ! feat=$(testaddrs ip6 rawip && runsip6); then
  6628. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  6629. numCANT=$((numCANT+1))
  6630. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  6631. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  6632. numCANT=$((numCANT+1))
  6633. else
  6634. tf="$td/test$N.stdout"
  6635. te="$td/test$N.stderr"
  6636. tdiff="$td/test$N.diff"
  6637. ts1p=$PROTO; PROTO=$((PROTO+1))
  6638. tsa="[::1]"
  6639. ts1="$tsa:$ts1p"
  6640. ts2="$tsa"
  6641. da="test$N $(date) $RANDOM"
  6642. #CMD1="$TRACE $SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
  6643. CMD2="$TRACE $SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2"
  6644. printf "test $F_n $TEST... " $N
  6645. #$CMD1 2>"${te}1" &
  6646. waitip6proto $ts1p 1
  6647. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  6648. if [ $? -ne 0 ]; then
  6649. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6650. # echo "$CMD1 &"
  6651. # cat "${te}1"
  6652. echo "$CMD2"
  6653. cat "${te}2"
  6654. numFAIL=$((numFAIL+1))
  6655. listFAIL="$listFAIL $N"
  6656. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6657. $PRINTF "$FAILED\n"
  6658. cat "$tdiff"
  6659. numFAIL=$((numFAIL+1))
  6660. listFAIL="$listFAIL $N"
  6661. else
  6662. $PRINTF "$OK\n"
  6663. if [ -n "$debug" ]; then cat "$te"; fi
  6664. numOK=$((numOK+1))
  6665. fi
  6666. fi ;; # root, NUMCOND
  6667. esac
  6668. N=$((N+1))
  6669. fi #false
  6670. NAME=UNIXDGRAM
  6671. case "$TESTS" in
  6672. *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%dgram%*|*%$NAME%*)
  6673. TEST="$NAME: UNIX datagram"
  6674. if ! eval $NUMCOND; then :; else
  6675. tf="$td/test$N.stdout"
  6676. te="$td/test$N.stderr"
  6677. tdiff="$td/test$N.diff"
  6678. ts1="$td/test$N.socket1"
  6679. ts2="$td/test$N.socket2"
  6680. da="test$N $(date) $RANDOM"
  6681. CMD1="$TRACE $SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE"
  6682. CMD2="$TRACE $SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2"
  6683. printf "test $F_n $TEST... " $N
  6684. $CMD1 2>"${te}1" &
  6685. pid1="$!"
  6686. waitfile $ts1 1
  6687. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  6688. rc2=$?
  6689. kill "$pid1" 2>/dev/null; wait
  6690. if [ $rc2 -ne 0 ]; then
  6691. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6692. echo "$CMD1 &"
  6693. cat "${te}1"
  6694. echo "$CMD2"
  6695. cat "${te}2"
  6696. numFAIL=$((numFAIL+1))
  6697. listFAIL="$listFAIL $N"
  6698. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6699. $PRINTF "$FAILED\n"
  6700. cat "$tdiff"
  6701. numFAIL=$((numFAIL+1))
  6702. listFAIL="$listFAIL $N"
  6703. else
  6704. $PRINTF "$OK\n"
  6705. if [ -n "$debug" ]; then cat $te; fi
  6706. numOK=$((numOK+1))
  6707. fi
  6708. fi # NUMCOND
  6709. ;;
  6710. esac
  6711. N=$((N+1))
  6712. NAME=UDP4RECV
  6713. case "$TESTS" in
  6714. *%$N%*|*%functions%*|*%engine%*|*%ip4%*|*%dgram%*|*%udp%*|*%udp4%*|*%recv%*|*%$NAME%*)
  6715. TEST="$NAME: UDP/IPv4 receive"
  6716. if ! eval $NUMCOND; then :; else
  6717. tf="$td/test$N.stdout"
  6718. te="$td/test$N.stderr"
  6719. tdiff="$td/test$N.diff"
  6720. ts1p=$PORT; PORT=$((PORT+1))
  6721. ts1a="127.0.0.1"
  6722. ts1="$ts1a:$ts1p"
  6723. da="test$N $(date) $RANDOM"
  6724. CMD1="$TRACE $SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -"
  6725. CMD2="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1"
  6726. printf "test $F_n $TEST... " $N
  6727. $CMD1 >"$tf" 2>"${te}1" &
  6728. pid1="$!"
  6729. waitudp4port $ts1p 1
  6730. echo "$da" |$CMD2 2>>"${te}2"
  6731. rc2="$?"
  6732. #ls -l $tf
  6733. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  6734. kill "$pid1" 2>/dev/null; wait
  6735. if [ "$rc2" -ne 0 ]; then
  6736. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6737. echo "$CMD1 &"
  6738. echo "$CMD2"
  6739. cat "${te}1"
  6740. cat "${te}2"
  6741. numFAIL=$((numFAIL+1))
  6742. listFAIL="$listFAIL $N"
  6743. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6744. $PRINTF "$FAILED\n"
  6745. cat "$tdiff"
  6746. echo "$CMD1 &"
  6747. echo "$CMD2"
  6748. cat "${te}1"
  6749. cat "${te}2"
  6750. numFAIL=$((numFAIL+1))
  6751. listFAIL="$listFAIL $N"
  6752. else
  6753. $PRINTF "$OK\n"
  6754. if [ -n "$debug" ]; then cat $te; fi
  6755. numOK=$((numOK+1))
  6756. fi
  6757. fi # NUMCOND
  6758. ;;
  6759. esac
  6760. N=$((N+1))
  6761. NAME=UDP6RECV
  6762. case "$TESTS" in
  6763. *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%udp%*|*%udp6%*|*%recv%*|*%$NAME%*)
  6764. TEST="$NAME: UDP/IPv6 receive"
  6765. if ! eval $NUMCOND; then :;
  6766. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  6767. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  6768. numCANT=$((numCANT+1))
  6769. else
  6770. tf="$td/test$N.stdout"
  6771. te="$td/test$N.stderr"
  6772. tdiff="$td/test$N.diff"
  6773. ts1p=$PORT; PORT=$((PORT+1))
  6774. ts1a="[::1]"
  6775. ts1="$ts1a:$ts1p"
  6776. da="test$N $(date) $RANDOM"
  6777. CMD1="$TRACE $SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -"
  6778. CMD2="$TRACE $SOCAT $opts -u - UDP6-SENDTO:$ts1"
  6779. printf "test $F_n $TEST... " $N
  6780. $CMD1 >"$tf" 2>"${te}1" &
  6781. pid1="$!"
  6782. waitudp6port $ts1p 1
  6783. echo "$da" |$CMD2 2>>"${te}2"
  6784. rc2="$?"
  6785. #ls -l $tf
  6786. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  6787. kill "$pid1" 2>/dev/null; wait
  6788. if [ "$rc2" -ne 0 ]; then
  6789. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6790. echo "$CMD1 &"
  6791. echo "$CMD2"
  6792. cat "${te}1"
  6793. cat "${te}2"
  6794. numFAIL=$((numFAIL+1))
  6795. listFAIL="$listFAIL $N"
  6796. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6797. $PRINTF "$FAILED\n"
  6798. cat "$tdiff"
  6799. numFAIL=$((numFAIL+1))
  6800. listFAIL="$listFAIL $N"
  6801. else
  6802. $PRINTF "$OK\n"
  6803. if [ -n "$debug" ]; then cat $te; fi
  6804. numOK=$((numOK+1))
  6805. fi
  6806. fi ;; # NUMCOND, feats
  6807. esac
  6808. N=$((N+1))
  6809. NAME=RAWIP4RECV
  6810. case "$TESTS" in
  6811. *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
  6812. TEST="$NAME: raw IPv4 receive"
  6813. if ! eval $NUMCOND; then :;
  6814. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  6815. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  6816. numCANT=$((numCANT+1))
  6817. else
  6818. tf="$td/test$N.stdout"
  6819. te="$td/test$N.stderr"
  6820. tdiff="$td/test$N.diff"
  6821. ts1p=$PROTO; PROTO=$((PROTO+1))
  6822. ts1a="127.0.0.1"
  6823. ts1="$ts1a:$ts1p"
  6824. da="test$N $(date) $RANDOM"
  6825. CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -"
  6826. CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
  6827. printf "test $F_n $TEST... " $N
  6828. $CMD1 >"$tf" 2>"${te}1" &
  6829. pid1="$!"
  6830. waitip4proto $ts1p 1
  6831. echo "$da" |$CMD2 2>>"${te}2"
  6832. rc2="$?"
  6833. #ls -l $tf
  6834. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  6835. kill "$pid1" 2>/dev/null; wait
  6836. if [ "$rc2" -ne 0 ]; then
  6837. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6838. echo "$CMD1 &"
  6839. echo "$CMD2"
  6840. cat "${te}1"
  6841. cat "${te}2"
  6842. numFAIL=$((numFAIL+1))
  6843. listFAIL="$listFAIL $N"
  6844. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6845. $PRINTF "$FAILED\n"
  6846. cat "$tdiff"
  6847. numFAIL=$((numFAIL+1))
  6848. listFAIL="$listFAIL $N"
  6849. else
  6850. $PRINTF "$OK\n"
  6851. if [ -n "$debug" ]; then cat $te; fi
  6852. numOK=$((numOK+1))
  6853. fi
  6854. fi ;; # NUMCOND, root
  6855. esac
  6856. N=$((N+1))
  6857. NAME=RAWIP6RECV
  6858. case "$TESTS" in
  6859. *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%rawip%*|*%rawip6%*|*%recv%*|*%root%*|*%$NAME%*)
  6860. TEST="$NAME: raw IPv6 receive"
  6861. if ! eval $NUMCOND; then :;
  6862. elif ! feat=$(testaddrs ip6 rawip && runsip6); then
  6863. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  6864. numCANT=$((numCANT+1))
  6865. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  6866. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  6867. numCANT=$((numCANT+1))
  6868. else
  6869. tf="$td/test$N.stdout"
  6870. te="$td/test$N.stderr"
  6871. tdiff="$td/test$N.diff"
  6872. ts1p=$PROTO; PROTO=$((PROTO+1))
  6873. ts1a="[::1]"
  6874. ts1="$ts1a:$ts1p"
  6875. da="test$N $(date) $RANDOM"
  6876. CMD1="$TRACE $SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -"
  6877. CMD2="$TRACE $SOCAT $opts -u - IP6-SENDTO:$ts1"
  6878. printf "test $F_n $TEST... " $N
  6879. $CMD1 >"$tf" 2>"${te}1" &
  6880. pid1="$!"
  6881. waitip6proto $ts1p 1
  6882. echo "$da" |$CMD2 2>>"${te}2"
  6883. rc2="$?"
  6884. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  6885. kill "$pid1" 2>/dev/null; wait
  6886. if [ "$rc2" -ne 0 ]; then
  6887. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6888. echo "$CMD1 &"
  6889. echo "$CMD2"
  6890. cat "${te}1"
  6891. cat "${te}2"
  6892. numFAIL=$((numFAIL+1))
  6893. listFAIL="$listFAIL $N"
  6894. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6895. $PRINTF "$FAILED\n"
  6896. cat "$tdiff"
  6897. numFAIL=$((numFAIL+1))
  6898. listFAIL="$listFAIL $N"
  6899. else
  6900. $PRINTF "$OK\n"
  6901. if [ -n "$debug" ]; then cat $te; fi
  6902. numOK=$((numOK+1))
  6903. fi
  6904. fi ;; # NUMCOND, root
  6905. esac
  6906. N=$((N+1))
  6907. NAME=UNIXRECV
  6908. case "$TESTS" in
  6909. *%$N%*|*%functions%*|*%unix%*|*%dgram%*|*%recv%*|*%$NAME%*)
  6910. TEST="$NAME: UNIX receive"
  6911. if ! eval $NUMCOND; then :; else
  6912. ts="$td/test$N.socket"
  6913. tf="$td/test$N.stdout"
  6914. te="$td/test$N.stderr"
  6915. tdiff="$td/test$N.diff"
  6916. ts1="$ts"
  6917. da="test$N $(date) $RANDOM"
  6918. CMD1="$TRACE $SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -"
  6919. CMD2="$TRACE $SOCAT $opts -u - UNIX-SENDTO:$ts1"
  6920. printf "test $F_n $TEST... " $N
  6921. $CMD1 >"$tf" 2>"${te}1" &
  6922. pid1="$!"
  6923. waitfile $ts1 1
  6924. echo "$da" |$CMD2 2>>"${te}2"
  6925. rc2="$?"
  6926. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  6927. kill "$pid1" 2>/dev/null; wait
  6928. if [ "$rc2" -ne 0 ]; then
  6929. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  6930. echo "$CMD1 &"
  6931. echo "$CMD2"
  6932. cat "${te}1"
  6933. cat "${te}2"
  6934. numFAIL=$((numFAIL+1))
  6935. listFAIL="$listFAIL $N"
  6936. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  6937. $PRINTF "$FAILED\n"
  6938. cat "$tdiff"
  6939. numFAIL=$((numFAIL+1))
  6940. listFAIL="$listFAIL $N"
  6941. else
  6942. $PRINTF "$OK\n"
  6943. if [ -n "$debug" ]; then cat $te; fi
  6944. numOK=$((numOK+1))
  6945. fi
  6946. fi # NUMCOND
  6947. ;;
  6948. esac
  6949. N=$((N+1))
  6950. NAME=UDP4RECVFROM_SOURCEPORT
  6951. case "$TESTS" in
  6952. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
  6953. TEST="$NAME: security of UDP4-RECVFROM with SOURCEPORT option"
  6954. if ! eval $NUMCOND; then :;
  6955. elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
  6956. $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
  6957. numCANT=$((numCANT+1))
  6958. else
  6959. testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
  6960. fi ;; # NUMCOND, feats
  6961. esac
  6962. PORT=$((PORT+1))
  6963. N=$((N+1))
  6964. NAME=UDP4RECVFROM_LOWPORT
  6965. case "$TESTS" in
  6966. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
  6967. TEST="$NAME: security of UDP4-RECVFROM with LOWPORT option"
  6968. if ! eval $NUMCOND; then :;
  6969. elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
  6970. $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
  6971. numCANT=$((numCANT+1))
  6972. else
  6973. testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
  6974. fi ;; # NUMCOND, feats
  6975. esac
  6976. PORT=$((PORT+1))
  6977. N=$((N+1))
  6978. NAME=UDP4RECVFROM_RANGE
  6979. case "$TESTS" in
  6980. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  6981. TEST="$NAME: security of UDP4-RECVFROM with RANGE option"
  6982. #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
  6983. if ! eval $NUMCOND; then :; else
  6984. testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
  6985. fi ;; # NUMCOND
  6986. esac
  6987. PORT=$((PORT+1))
  6988. N=$((N+1))
  6989. NAME=UDP4RECVFROM_TCPWRAP
  6990. case "$TESTS" in
  6991. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
  6992. TEST="$NAME: security of UDP4-RECVFROM with TCPWRAP option"
  6993. if ! eval $NUMCOND; then :;
  6994. elif ! feat=$(testaddrs ip4 udp libwrap) || ! runsip4 >/dev/null; then
  6995. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  6996. numCANT=$((numCANT+1))
  6997. else
  6998. ha="$td/hosts.allow"
  6999. hd="$td/hosts.deny"
  7000. $ECHO "socat: $SECONDADDR" >"$ha"
  7001. $ECHO "ALL: ALL" >"$hd"
  7002. #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "tcpwrap=$d" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
  7003. testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
  7004. fi ;; # NUMCOND, feats
  7005. esac
  7006. PORT=$((PORT+1))
  7007. N=$((N+1))
  7008. NAME=UDP4RECV_SOURCEPORT
  7009. case "$TESTS" in
  7010. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
  7011. TEST="$NAME: security of UDP4-RECV with SOURCEPORT option"
  7012. if ! eval $NUMCOND; then :;
  7013. elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
  7014. $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
  7015. numCANT=$((numCANT+1))
  7016. else
  7017. PORT1=$PORT; PORT=$((PORT+1))
  7018. PORT2=$PORT; PORT=$((PORT+1))
  7019. PORT3=$PORT
  7020. # we use the forward channel (PORT1) for testing, and have a backward channel
  7021. # (PORT2) to get the data back, so we get the classical echo behaviour
  7022. testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "sp=$PORT3" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
  7023. fi ;; # NUMCOND, feats
  7024. esac
  7025. PORT=$((PORT+1))
  7026. N=$((N+1))
  7027. NAME=UDP4RECV_LOWPORT
  7028. case "$TESTS" in
  7029. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
  7030. TEST="$NAME: security of UDP4-RECV with LOWPORT option"
  7031. if ! eval $NUMCOND; then :;
  7032. elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
  7033. $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
  7034. numCANT=$((numCANT+1))
  7035. else
  7036. PORT1=$PORT; PORT=$((PORT+1))
  7037. PORT2=$PORT
  7038. # we use the forward channel (PORT1) for testing, and have a backward channel
  7039. # (PORT2) to get the data back, so we get the classical echo behaviour
  7040. testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "lowport" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
  7041. fi ;; # NUMCOND, feats
  7042. esac
  7043. PORT=$((PORT+1))
  7044. N=$((N+1))
  7045. NAME=UDP4RECV_RANGE
  7046. case "$TESTS" in
  7047. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  7048. TEST="$NAME: security of UDP4-RECV with RANGE option"
  7049. if ! eval $NUMCOND; then :;
  7050. elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
  7051. $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
  7052. numCANT=$((numCANT+1))
  7053. else
  7054. PORT1=$PORT; PORT=$((PORT+1))
  7055. PORT2=$PORT
  7056. # we use the forward channel (PORT1) for testing, and have a backward channel
  7057. # (PORT2) to get the data back, so we get the classical echo behaviour
  7058. testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "range=$SECONDADDR/32" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
  7059. fi ;; # NUMCOND, feats
  7060. esac
  7061. PORT=$((PORT+1))
  7062. N=$((N+1))
  7063. NAME=UDP4RECV_TCPWRAP
  7064. case "$TESTS" in
  7065. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
  7066. TEST="$NAME: security of UDP4-RECV with TCPWRAP option"
  7067. if ! eval $NUMCOND; then :;
  7068. elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
  7069. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7070. numCANT=$((numCANT+1))
  7071. else
  7072. PORT1=$PORT; PORT=$((PORT+1))
  7073. PORT2=$PORT
  7074. ha="$td/hosts.allow"
  7075. hd="$td/hosts.deny"
  7076. $ECHO "socat: $SECONDADDR" >"$ha"
  7077. $ECHO "ALL: ALL" >"$hd"
  7078. # we use the forward channel (PORT1) for testing, and have a backward channel
  7079. # (PORT2) to get the data back, so we get the classical echo behaviour
  7080. testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "tcpwrap-etc=$td" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
  7081. fi ;; # NUMCOND, feats
  7082. esac
  7083. PORT=$((PORT+1))
  7084. N=$((N+1))
  7085. NAME=UDP6RECVFROM_SOURCEPORT
  7086. case "$TESTS" in
  7087. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
  7088. TEST="$NAME: security of UDP6-RECVFROM with SOURCEPORT option"
  7089. if ! eval $NUMCOND; then :;
  7090. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  7091. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  7092. numCANT=$((numCANT+1))
  7093. else
  7094. testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
  7095. fi ;; # NUMCOND, feats
  7096. esac
  7097. PORT=$((PORT+1))
  7098. N=$((N+1))
  7099. NAME=UDP6RECVFROM_LOWPORT
  7100. case "$TESTS" in
  7101. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
  7102. TEST="$NAME: security of UDP6-RECVFROM with LOWPORT option"
  7103. if ! eval $NUMCOND; then :;
  7104. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  7105. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  7106. numCANT=$((numCANT+1))
  7107. else
  7108. testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
  7109. fi ;; # NUMCOND, feats
  7110. esac
  7111. PORT=$((PORT+1))
  7112. N=$((N+1))
  7113. NAME=UDP6RECVFROM_RANGE
  7114. case "$TESTS" in
  7115. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
  7116. TEST="$NAME: security of UDP6-RECVFROM with RANGE option"
  7117. if ! eval $NUMCOND; then :;
  7118. elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
  7119. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  7120. numCANT=$((numCANT+1))
  7121. else
  7122. #testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
  7123. testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
  7124. fi ;; # NUMCOND, feats
  7125. esac
  7126. PORT=$((PORT+1))
  7127. N=$((N+1))
  7128. NAME=UDP6RECVFROM_TCPWRAP
  7129. case "$TESTS" in
  7130. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
  7131. TEST="$NAME: security of UDP6-RECVFROM with TCPWRAP option"
  7132. if ! eval $NUMCOND; then :;
  7133. elif ! feat=$(testaddrs udp ip6 libwrap && runsip6); then
  7134. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7135. numCANT=$((numCANT+1))
  7136. else
  7137. ha="$td/hosts.allow"
  7138. hd="$td/hosts.deny"
  7139. $ECHO "socat: [::2]" >"$ha"
  7140. $ECHO "ALL: ALL" >"$hd"
  7141. testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
  7142. fi ;; # NUMCOND, feats
  7143. esac
  7144. PORT=$((PORT+1))
  7145. N=$((N+1))
  7146. NAME=UDP6RECV_SOURCEPORT
  7147. case "$TESTS" in
  7148. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
  7149. TEST="$NAME: security of UDP6-RECV with SOURCEPORT option"
  7150. if ! eval $NUMCOND; then :;
  7151. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  7152. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  7153. numCANT=$((numCANT+1))
  7154. else
  7155. PORT1=$PORT; PORT=$((PORT+1))
  7156. PORT2=$PORT; PORT=$((PORT+1))
  7157. PORT3=$PORT
  7158. # we use the forward channel (PORT1) for testing, and have a backward channel
  7159. # (PORT2) to get the data back, so we get the classical echo behaviour
  7160. testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "sp=$PORT3" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
  7161. fi ;; # NUMCOND, feats
  7162. esac
  7163. PORT=$((PORT+1))
  7164. N=$((N+1))
  7165. NAME=UDP6RECV_LOWPORT
  7166. case "$TESTS" in
  7167. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
  7168. TEST="$NAME: security of UDP6-RECV with LOWPORT option"
  7169. if ! eval $NUMCOND; then :;
  7170. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  7171. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  7172. numCANT=$((numCANT+1))
  7173. else
  7174. PORT1=$PORT; PORT=$((PORT+1))
  7175. PORT2=$PORT
  7176. # we use the forward channel (PORT1) for testing, and have a backward channel
  7177. # (PORT2) to get the data back, so we get the classical echo behaviour
  7178. testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "lowport" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
  7179. fi ;; # NUMCOND, feats
  7180. esac
  7181. PORT=$((PORT+1))
  7182. N=$((N+1))
  7183. NAME=UDP6RECV_RANGE
  7184. case "$TESTS" in
  7185. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
  7186. TEST="$NAME: security of UDP6-RECV with RANGE option"
  7187. if ! eval $NUMCOND; then :;
  7188. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  7189. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  7190. numCANT=$((numCANT+1))
  7191. else
  7192. PORT1=$PORT; PORT=$((PORT+1))
  7193. PORT2=$PORT
  7194. # we use the forward channel (PORT1) for testing, and have a backward channel
  7195. # (PORT2) to get the data back, so we get the classical echo behaviour
  7196. testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "range=[::2]/128" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
  7197. fi ;; # NUMCOND, feats
  7198. esac
  7199. PORT=$((PORT+1))
  7200. N=$((N+1))
  7201. NAME=UDP6RECV_TCPWRAP
  7202. case "$TESTS" in
  7203. *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
  7204. TEST="$NAME: security of UDP6-RECV with TCPWRAP option"
  7205. if ! eval $NUMCOND; then :;
  7206. elif ! feat=$(testaddrs udp ip6 libwrap && runsip6); then
  7207. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7208. numCANT=$((numCANT+1))
  7209. else
  7210. ha="$td/hosts.allow"
  7211. hd="$td/hosts.deny"
  7212. $ECHO "socat: [::2]" >"$ha"
  7213. $ECHO "ALL: ALL" >"$hd"
  7214. PORT1=$PORT; PORT=$((PORT+1))
  7215. PORT2=$PORT
  7216. # we use the forward channel (PORT1) for testing, and have a backward channel
  7217. # (PORT2) to get the data back, so we get the classical echo behaviour
  7218. testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "tcpwrap-etc=$td" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
  7219. fi ;; # NUMCOND, feats
  7220. esac
  7221. PORT=$((PORT+1))
  7222. N=$((N+1))
  7223. NAME=IP4RECVFROM_RANGE
  7224. case "$TESTS" in
  7225. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
  7226. TEST="$NAME: security of IP4-RECVFROM with RANGE option"
  7227. if ! eval $NUMCOND; then :;
  7228. elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
  7229. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7230. numCANT=$((numCANT+1))
  7231. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7232. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7233. numCANT=$((numCANT+1))
  7234. else
  7235. #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
  7236. testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "range=$SECONDADDR/32" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
  7237. fi ;; # NUMCOND, feats, root
  7238. esac
  7239. PROTO=$((PROTO+1))
  7240. PORT=$((PORT+1))
  7241. N=$((N+1))
  7242. NAME=IP4RECVFROM_TCPWRAP
  7243. case "$TESTS" in
  7244. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
  7245. TEST="$NAME: security of IP4-RECVFROM with TCPWRAP option"
  7246. if ! eval $NUMCOND; then :;
  7247. elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
  7248. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7249. numCANT=$((numCANT+1))
  7250. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7251. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7252. numCANT=$((numCANT+1))
  7253. else
  7254. ha="$td/hosts.allow"
  7255. hd="$td/hosts.deny"
  7256. $ECHO "socat: $SECONDADDR" >"$ha"
  7257. $ECHO "ALL: ALL" >"$hd"
  7258. #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
  7259. testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "tcpwrap-etc=$td" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
  7260. fi # NUMCOND, feats, root
  7261. ;;
  7262. esac
  7263. PROTO=$((PROTO+1))
  7264. PORT=$((PORT+1))
  7265. N=$((N+1))
  7266. NAME=IP4RECV_RANGE
  7267. case "$TESTS" in
  7268. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
  7269. TEST="$NAME: security of IP4-RECV with RANGE option"
  7270. if ! eval $NUMCOND; then :;
  7271. elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
  7272. $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
  7273. numCANT=$((numCANT+1))
  7274. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7275. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7276. numCANT=$((numCANT+1))
  7277. else
  7278. PROTO1=$PROTO; PROTO=$((PROTO+1))
  7279. PROTO2=$PROTO
  7280. # we use the forward channel (PROTO1) for testing, and have a backward channel
  7281. # (PROTO2) to get the data back, so we get the classical echo behaviour
  7282. testserversec "$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "range=$SECONDADDR/32" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip $PROTO1 0
  7283. fi ;; # NUMCOND, feats, root
  7284. esac
  7285. PROTO=$((PROTO+1))
  7286. N=$((N+1))
  7287. NAME=IP4RECV_TCPWRAP
  7288. case "$TESTS" in
  7289. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
  7290. TEST="$NAME: security of IP4-RECV with TCPWRAP option"
  7291. if ! eval $NUMCOND; then :;
  7292. elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
  7293. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7294. numCANT=$((numCANT+1))
  7295. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7296. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7297. numCANT=$((numCANT+1))
  7298. else
  7299. PROTO1=$PROTO; PROTO=$((PROTO+1))
  7300. PROTO2=$PROTO
  7301. ha="$td/hosts.allow"
  7302. hd="$td/hosts.deny"
  7303. $ECHO "socat: $SECONDADDR" >"$ha"
  7304. $ECHO "ALL: ALL" >"$hd"
  7305. # we use the forward channel (PROTO1) for testing, and have a backward channel
  7306. # (PROTO2) to get the data back, so we get the classical echo behaviour
  7307. testserversec "$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "tcpwrap-etc=$td" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip $PROTO1 0
  7308. fi ;; # NUMCOND, feats, root
  7309. esac
  7310. PROTO=$((PROTO+1))
  7311. N=$((N+1))
  7312. NAME=IP6RECVFROM_RANGE
  7313. case "$TESTS" in
  7314. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
  7315. TEST="$NAME: security of IP6-RECVFROM with RANGE option"
  7316. if ! eval $NUMCOND; then :;
  7317. elif ! feat=$(testaddrs ip6 rawip && runsip6); then
  7318. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7319. numCANT=$((numCANT+1))
  7320. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7321. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7322. numCANT=$((numCANT+1))
  7323. else
  7324. #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "range=[::2]/128" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
  7325. testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "range=[::2]/128" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
  7326. fi ;; # NUMCOND, feats
  7327. esac
  7328. PROTO=$((PROTO+1))
  7329. PORT=$((PORT+1))
  7330. N=$((N+1))
  7331. NAME=IP6RECVFROM_TCPWRAP
  7332. case "$TESTS" in
  7333. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
  7334. TEST="$NAME: security of IP6-RECVFROM with TCPWRAP option"
  7335. if ! eval $NUMCOND; then :;
  7336. elif ! feat=$(testaddrs ip6 rawip libwrap && runsip6); then
  7337. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7338. numCANT=$((numCANT+1))
  7339. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7340. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7341. numCANT=$((numCANT+1))
  7342. else
  7343. ha="$td/hosts.allow"
  7344. hd="$td/hosts.deny"
  7345. $ECHO "socat: [::2]" >"$ha"
  7346. $ECHO "ALL: ALL" >"$hd"
  7347. #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
  7348. testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "tcpwrap-etc=$td" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
  7349. fi ;; # NUMCOND, feats
  7350. esac
  7351. PROTO=$((PROTO+1))
  7352. PORT=$((PORT+1))
  7353. N=$((N+1))
  7354. NAME=IP6RECV_RANGE
  7355. case "$TESTS" in
  7356. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
  7357. TEST="$NAME: security of IP6-RECV with RANGE option"
  7358. if ! eval $NUMCOND; then :;
  7359. elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
  7360. $PRINTF "test $F_n $TEST... ${YELLOW}raw IP6 not available${NORMAL}\n" $N
  7361. numCANT=$((numCANT+1))
  7362. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7363. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7364. numCANT=$((numCANT+1))
  7365. else
  7366. PROTO1=$PROTO; PROTO=$((PROTO+1))
  7367. PROTO2=$PROTO
  7368. # we use the forward channel (PROTO1) for testing, and have a backward channel
  7369. # (PROTO2) to get the data back, so we get the classical echo behaviour
  7370. testserversec "$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "range=[::2]/128" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
  7371. fi ;; # NUMCOND, feats
  7372. esac
  7373. PROTO=$((PROTO+1))
  7374. N=$((N+1))
  7375. NAME=IP6RECV_TCPWRAP
  7376. case "$TESTS" in
  7377. *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
  7378. TEST="$NAME: security of IP6-RECV with TCPWRAP option"
  7379. if ! eval $NUMCOND; then :;
  7380. elif ! feat=$(testaddrs ip6 rawip libwrap && runsip6); then
  7381. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7382. numCANT=$((numCANT+1))
  7383. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  7384. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  7385. numCANT=$((numCANT+1))
  7386. else
  7387. PROTO1=$PROTO; PROTO=$((PROTO+1))
  7388. PROTO2=$PROTO
  7389. ha="$td/hosts.allow"
  7390. hd="$td/hosts.deny"
  7391. $ECHO "socat: [::2]" >"$ha"
  7392. $ECHO "ALL: ALL" >"$hd"
  7393. # we use the forward channel (PROTO1) for testing, and have a backward channel
  7394. # (PROTO2) to get the data back, so we get the classical echo behaviour
  7395. testserversec "$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "tcpwrap-etc=$td" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
  7396. fi ;; # NUMCOND, feats
  7397. esac
  7398. PROTO=$((PROTO+1))
  7399. N=$((N+1))
  7400. NAME=O_NOATIME_FILE
  7401. case "$TESTS" in
  7402. *%$N%*|*%functions%*|*%open%*|*%noatime%*|*%$NAME%*)
  7403. TEST="$NAME: option O_NOATIME on file"
  7404. # idea: create a file with o-noatime option; one second later create a file
  7405. # without this option (using touch); one second later read from the first file.
  7406. # Then we check which file has the later ATIME stamp. For this check we use
  7407. # "ls -ltu" because it is more portable than "test ... -nt ..."
  7408. if ! eval $NUMCOND; then :;
  7409. elif ! testoptions o-noatime >/dev/null; then
  7410. $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
  7411. numCANT=$((numCANT+1))
  7412. else
  7413. tf="$td/test$N.file"
  7414. te="$td/test$N.stderr"
  7415. tdiff="$td/test$N.diff"
  7416. da="test$N $(date) $RANDOM"
  7417. $PRINTF "test $F_n $TEST... " $N
  7418. CMD="$TRACE $SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null"
  7419. # generate a file
  7420. touch "${tf}1"
  7421. sleep 1
  7422. # generate a reference file
  7423. touch "${tf}2"
  7424. sleep 1
  7425. # read from the first file
  7426. $CMD 2>"$te"
  7427. if [ $? -ne 0 ]; then # command failed
  7428. $PRINTF "${FAILED}:\n"
  7429. echo "$CMD"
  7430. cat "$te"
  7431. numFAIL=$((numFAIL+1))
  7432. listFAIL="$listFAIL $N"
  7433. else
  7434. # check which file has a later atime stamp
  7435. if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
  7436. then
  7437. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7438. echo "$CMD"
  7439. cat "$te"
  7440. numFAIL=$((numFAIL+1))
  7441. listFAIL="$listFAIL $N"
  7442. else
  7443. $PRINTF "$OK\n"
  7444. if [ -n "$debug" ]; then cat "$te"; fi
  7445. numOK=$((numOK+1))
  7446. fi # wrong time stamps
  7447. fi # command ok
  7448. fi ;; # NUMCOND, feats
  7449. esac
  7450. N=$((N+1))
  7451. NAME=O_NOATIME_FD
  7452. case "$TESTS" in
  7453. *%$N%*|*%functions%*|*%noatime%*|*%$NAME%*)
  7454. TEST="$NAME: option O_NOATIME on file descriptor"
  7455. # idea: use a fd of a file with o-noatime option; one second later create a file
  7456. # without this option (using touch); one second later read from the first file.
  7457. # Then we check which file has the later ATIME stamp. For this check we use
  7458. # "ls -ltu" because it is more portable than "test ... -nt ..."
  7459. if ! eval $NUMCOND; then :;
  7460. elif ! testoptions o-noatime >/dev/null; then
  7461. $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
  7462. numCANT=$((numCANT+1))
  7463. else
  7464. tf="$td/test$N.file"
  7465. te="$td/test$N.stderr"
  7466. tdiff="$td/test$N.diff"
  7467. da="test$N $(date) $RANDOM"
  7468. $PRINTF "test $F_n $TEST... " $N
  7469. touch ${tf}1
  7470. CMD="$TRACE $SOCAT $opts -u -,o-noatime /dev/null <${tf}1"
  7471. # generate a file, len >= 1
  7472. touch "${tf}1"
  7473. sleep 1
  7474. # generate a reference file
  7475. touch "${tf}2"
  7476. sleep 1
  7477. # read from the first file
  7478. sh -c "$CMD" 2>"$te"
  7479. if [ $? -ne 0 ]; then # command failed
  7480. $PRINTF "${FAILED}:\n"
  7481. echo "$CMD"
  7482. cat "$te"
  7483. numFAIL=$((numFAIL+1))
  7484. listFAIL="$listFAIL $N"
  7485. else
  7486. # check which file has a later atime stamp
  7487. if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
  7488. then
  7489. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7490. echo "$CMD"
  7491. cat "$te"
  7492. numFAIL=$((numFAIL+1))
  7493. listFAIL="$listFAIL $N"
  7494. else
  7495. $PRINTF "$OK\n"
  7496. if [ -n "$debug" ]; then cat "$te"; fi
  7497. numOK=$((numOK+1))
  7498. fi # wrong time stamps
  7499. fi # command ok
  7500. fi ;; # NUMCOND, feats
  7501. esac
  7502. N=$((N+1))
  7503. NAME=EXT2_NOATIME
  7504. case "$TESTS" in
  7505. *%$N%*|*%functions%*|*%ext2%*|*%noatime%*|*%$NAME%*)
  7506. TEST="$NAME: extended file system options using ext2fs noatime option"
  7507. # idea: create a file with ext2-noatime option; one second later create a file
  7508. # without this option (using touch); one second later read from the first file.
  7509. # Then we check which file has the later ATIME stamp. For this check we use
  7510. # "ls -ltu" because it is more portable than "test ... -nt ..."
  7511. if ! eval $NUMCOND; then :;
  7512. elif ! testoptions ext2-noatime >/dev/null; then
  7513. $PRINTF "test $F_n $TEST... ${YELLOW}ext2-noatime not available${NORMAL}\n" $N
  7514. numCANT=$((numCANT+1))
  7515. else
  7516. ts="$td/test$N.socket"
  7517. tf="$td/test$N.file"
  7518. te="$td/test$N.stderr"
  7519. tdiff="$td/test$N.diff"
  7520. ts1="$ts"
  7521. da="test$N $(date) $RANDOM"
  7522. $PRINTF "test $F_n $TEST... " $N
  7523. CMD0="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\""
  7524. CMD="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\",ext2-noatime"
  7525. # check if this is a capable FS; lsattr does other things on AIX, thus socat
  7526. $CMD0 2>"${te}0"
  7527. if [ $? -ne 0 ]; then
  7528. $PRINTF "${YELLOW} cannot test${NORMAL}\n"
  7529. numCANT=$((numCANT+1))
  7530. else
  7531. # generate a file with noatime, len >= 1
  7532. $CMD 2>"$te"
  7533. if [ $? -ne 0 ]; then # command failed
  7534. $PRINTF "${YELLOW}impotent file system?${NORMAL}\n"
  7535. echo "$CMD"
  7536. cat "$te"
  7537. numCANT=$((numCANT+1))
  7538. else
  7539. sleep 1
  7540. # generate a reference file
  7541. touch "${tf}2"
  7542. sleep 1
  7543. # read from the first file
  7544. cat "${tf}1" >/dev/null
  7545. # check which file has a later atime stamp
  7546. #if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |awk '{print($8);}') != "${tf}2" ];
  7547. if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |sed "s|.*\\($td.*\\)|\1|g") != "${tf}2" ];
  7548. then
  7549. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7550. echo "$CMD"
  7551. cat "$te"
  7552. numFAIL=$((numFAIL+1))
  7553. listFAIL="$listFAIL $N"
  7554. else
  7555. $PRINTF "$OK\n"
  7556. if [ -n "$debug" ]; then cat "$te"; fi
  7557. numOK=$((numOK+1))
  7558. fi
  7559. fi # not impotent
  7560. fi # can test
  7561. fi ;; # NUMCOND, feats
  7562. esac
  7563. N=$((N+1))
  7564. NAME=COOLWRITE
  7565. case "$TESTS" in
  7566. *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
  7567. TEST="$NAME: option cool-write"
  7568. if ! eval $NUMCOND; then :;
  7569. elif ! testoptions cool-write >/dev/null; then
  7570. $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
  7571. numCANT=$((numCANT+1))
  7572. else
  7573. #set -vx
  7574. ti="$td/test$N.pipe"
  7575. tf="$td/test$N.stdout"
  7576. te="$td/test$N.stderr"
  7577. tdiff="$td/test$N.diff"
  7578. da="test$N $(date) $RANDOM"
  7579. # a reader that will terminate after 1 byte
  7580. CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
  7581. CMD="$TRACE $SOCAT $opts -u - file:\"$ti\",cool-write"
  7582. printf "test $F_n $TEST... " $N
  7583. $CMD1 2>"${te}1" &
  7584. bg=$! # background process id
  7585. sleep 1
  7586. (echo .; sleep 1; echo) |$CMD 2>"$te"
  7587. rc=$?
  7588. kill $bg 2>/dev/null; wait
  7589. if [ $rc -ne 0 ]; then
  7590. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7591. echo "$CMD &"
  7592. cat "$te"
  7593. numFAIL=$((numFAIL+1))
  7594. listFAIL="$listFAIL $N"
  7595. else
  7596. $PRINTF "$OK\n"
  7597. if [ -n "$debug" ]; then cat "$te"; fi
  7598. numOK=$((numOK+1))
  7599. fi
  7600. fi ;; # NUMCOND, feats
  7601. esac
  7602. N=$((N+1))
  7603. # test if option coolwrite can be applied to bidirectional address stdio
  7604. # this failed up to socat 1.6.0.0
  7605. NAME=COOLSTDIO
  7606. case "$TESTS" in
  7607. *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
  7608. TEST="$NAME: option cool-write on bidirectional stdio"
  7609. # this test starts a socat reader that terminates after receiving one+
  7610. # bytes (option readbytes); and a test process that sends two bytes via
  7611. # named pipe to the receiving process and, a second later, sends another
  7612. # byte. The last write will fail with "broken pipe"; if option coolwrite
  7613. # has been applied successfully, socat will terminate with 0 (OK),
  7614. # otherwise with error.
  7615. if ! eval $NUMCOND; then :;
  7616. elif ! testoptions cool-write >/dev/null; then
  7617. $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
  7618. numCANT=$((numCANT+1))
  7619. else
  7620. #set -vx
  7621. ti="$td/test$N.pipe"
  7622. tf="$td/test$N.stdout"
  7623. te="$td/test$N.stderr"
  7624. tdiff="$td/test$N.diff"
  7625. da="test$N $(date) $RANDOM"
  7626. # a reader that will terminate after 1 byte
  7627. CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
  7628. CMD="$TRACE $SOCAT $opts -,cool-write pipe >\"$ti\""
  7629. printf "test $F_n $TEST... " $N
  7630. $CMD1 2>"${te}1" &
  7631. bg=$! # background process id
  7632. sleep 1
  7633. (echo .; sleep 1; echo) |eval "$CMD" 2>"$te"
  7634. rc=$?
  7635. kill $bg 2>/dev/null; wait
  7636. if [ $rc -ne 0 ]; then
  7637. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7638. echo "$CMD &"
  7639. cat "$te"
  7640. numFAIL=$((numFAIL+1))
  7641. listFAIL="$listFAIL $N"
  7642. else
  7643. $PRINTF "$OK\n"
  7644. if [ -n "$debug" ]; then cat "$te"; fi
  7645. numOK=$((numOK+1))
  7646. fi
  7647. fi ;; # NUMCOND, feats
  7648. esac
  7649. N=$((N+1))
  7650. NAME=TCP4ENDCLOSE
  7651. case "$TESTS" in
  7652. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  7653. TEST="$NAME: end-close keeps TCP V4 socket open"
  7654. if ! eval $NUMCOND; then :; else
  7655. tf="$td/test$N.stdout"
  7656. te="$td/test$N.stderr"
  7657. tdiff="$td/test$N.diff"
  7658. p1=$PORT; PORT=$((PORT+1))
  7659. p2=$PORT
  7660. da1a="$(date) $RANDOM"
  7661. da1b="$(date) $RANDOM"
  7662. CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$LOCALHOST:$p1"
  7663. CMD="$TRACE $SOCAT $opts -U TCP4:$LOCALHOST:$p2,end-close TCP4-LISTEN:$p1,bind=$LOCALHOST,$REUSEADDR,fork"
  7664. CMD3="$TRACE $SOCAT $opts -u TCP4-LISTEN:$p2,$REUSEADDR,bind=$LOCALHOST -"
  7665. printf "test $F_n $TEST... " $N
  7666. $CMD3 >"$tf" 2>"${te}3" &
  7667. pid3=$!
  7668. waittcp4port $p2 1
  7669. $CMD 2>"${te}2" &
  7670. pid2=$!
  7671. usleep $MICROS
  7672. waittcp4port $p1 1
  7673. echo "$da1a" |$CMD1 2>>"${te}1a"
  7674. echo "$da1b" |$CMD1 2>>"${te}1b"
  7675. sleep 1
  7676. kill "$pid3" "$pid2" 2>/dev/null
  7677. wait
  7678. if [ $? -ne 0 ]; then
  7679. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7680. echo "$CMD1 &"
  7681. echo "$CMD2"
  7682. cat "${te}1a" "${te}1b" "${te}2" "${te}3"
  7683. numFAIL=$((numFAIL+1))
  7684. listFAIL="$listFAIL $N"
  7685. elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
  7686. $PRINTF "$FAILED\n"
  7687. cat "$tdiff"
  7688. cat "${te}1a" "${te}1b" "${te}2" "${te}3"
  7689. numFAIL=$((numFAIL+1))
  7690. listFAIL="$listFAIL $N"
  7691. else
  7692. $PRINTF "$OK\n"
  7693. if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2" "${te}3"; fi
  7694. numOK=$((numOK+1))
  7695. fi
  7696. fi ;; # NUMCOND
  7697. esac
  7698. PORT=$((PORT+1))
  7699. N=$((N+1))
  7700. NAME=EXECENDCLOSE
  7701. case "$TESTS" in
  7702. *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
  7703. TEST="$NAME: end-close keeps EXEC child running"
  7704. if ! eval $NUMCOND; then :; else
  7705. tf="$td/test$N.stdout"
  7706. te="$td/test$N.stderr"
  7707. ts="$td/test$N.sock"
  7708. tdiff="$td/test$N.diff"
  7709. da1a="$(date) $RANDOM"
  7710. da1b="$(date) $RANDOM"
  7711. CMD1="$TRACE $SOCAT $opts - UNIX-CONNECT:$ts"
  7712. CMD="$TRACE $SOCAT $opts EXEC:"$CAT",end-close UNIX-LISTEN:$ts,fork"
  7713. printf "test $F_n $TEST... " $N
  7714. $CMD 2>"${te}2" &
  7715. pid2=$!
  7716. waitfile $ts 1
  7717. echo "$da1a" |$CMD1 2>>"${te}1a" >"$tf"
  7718. usleep $MICROS
  7719. echo "$da1b" |$CMD1 2>>"${te}1b" >>"$tf"
  7720. #usleep $MICROS
  7721. kill "$pid2" 2>/dev/null
  7722. wait
  7723. if [ $? -ne 0 ]; then
  7724. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7725. echo "$CMD1 &"
  7726. echo "$CMD2"
  7727. cat "${te}1a" "${te}1b" "${te}2"
  7728. numFAIL=$((numFAIL+1))
  7729. listFAIL="$listFAIL $N"
  7730. elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
  7731. $PRINTF "$FAILED\n"
  7732. cat "$tdiff"
  7733. cat "${te}1a" "${te}1b" "${te}2"
  7734. numFAIL=$((numFAIL+1))
  7735. listFAIL="$listFAIL $N"
  7736. else
  7737. $PRINTF "$OK\n"
  7738. if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2"; fi
  7739. numOK=$((numOK+1))
  7740. fi
  7741. fi ;; # NUMCOND
  7742. esac
  7743. N=$((N+1))
  7744. # up to 1.7.0.0 option end-close led to an error with some address types due to
  7745. # bad internal handling. here we check it for address PTY
  7746. NAME=PTYENDCLOSE
  7747. case "$TESTS" in
  7748. *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
  7749. TEST="$NAME: PTY handles option end-close"
  7750. # with the bug, socat exits with error. we invoke socat in a no-op mode and
  7751. # check its return status.
  7752. if ! eval $NUMCOND; then :;
  7753. else
  7754. tf="$td/test$N.stout"
  7755. te="$td/test$N.stderr"
  7756. CMD="$TRACE $SOCAT $opts /dev/null pty,end-close"
  7757. printf "test $F_n $TEST... " $N
  7758. $CMD 2>"${te}"
  7759. rc=$?
  7760. if [ "$rc" = 0 ]; then
  7761. $PRINTF "$OK\n"
  7762. numOK=$((numOK+1))
  7763. else
  7764. $PRINTF "$FAILED\n"
  7765. echo "$CMD"
  7766. cat "${te}"
  7767. numFAIL=$((numFAIL+1))
  7768. listFAIL="$listFAIL $N"
  7769. fi
  7770. fi # NUMCOND
  7771. ;;
  7772. esac
  7773. N=$((N+1))
  7774. # test the shut-null and null-eof options
  7775. NAME=SHUTNULLEOF
  7776. case "$TESTS" in
  7777. *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
  7778. TEST="$NAME: options shut-null and null-eof"
  7779. # run a receiving background process with option null-eof.
  7780. # start a sending process with option shut-null that sends a test record to the
  7781. # receiving process and then terminates.
  7782. # send another test record.
  7783. # whe the receiving process just got the first test record the test succeeded
  7784. if ! eval $NUMCOND; then :; else
  7785. tf="$td/test$N.stout"
  7786. te="$td/test$N.stderr"
  7787. tdiff="$td/test$N.diff"
  7788. da="test$N $(date) $RANDOM"
  7789. CMD0="$TRACE $SOCAT $opts -u UDP-RECV:$PORT,null-eof CREAT:$tf"
  7790. CMD1="$TRACE $SOCAT $opts -u - UDP-SENDTO:127.0.0.1:$PORT,shut-null"
  7791. printf "test $F_n $TEST... " $N
  7792. $CMD0 >/dev/null 2>"${te}0" &
  7793. pid0=$!
  7794. waitudp4port $PORT 1
  7795. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  7796. rc1=$?
  7797. echo "xyz" |$CMD1 >"${tf}2" 2>"${te}2"
  7798. rc2=$?
  7799. kill $pid0 2>/dev/null; wait
  7800. if [ $rc1 != 0 -o $rc2 != 0 ]; then
  7801. $PRINTF "$FAILED\n"
  7802. echo "$CMD0 &"
  7803. echo "$CMD1"
  7804. cat "${te}0"
  7805. cat "${te}1"
  7806. cat "${te}2"
  7807. numFAIL=$((numFAIL+1))
  7808. listFAIL="$listFAIL $N"
  7809. elif echo "$da" |diff - "${tf}" >"$tdiff"; then
  7810. $PRINTF "$OK\n"
  7811. numOK=$((numOK+1))
  7812. else
  7813. $PRINTF "$FAILED\n"
  7814. echo "$CMD0 &"
  7815. echo "$CMD1"
  7816. cat "${te}0"
  7817. cat "${te}1"
  7818. cat "${tdiff}"
  7819. numFAIL=$((numFAIL+1))
  7820. listFAIL="$listFAIL $N"
  7821. fi
  7822. fi # NUMCOND
  7823. ;;
  7824. esac
  7825. N=$((N+1))
  7826. NAME=UDP6LISTENBIND
  7827. # this tests for a bug in (up to) 1.5.0.0:
  7828. # with udp*-listen, the bind option supported only IPv4
  7829. case "$TESTS" in
  7830. *%$N%*|*%functions%*|*%bugs%*|*%ip6%*|*%ipapp%*|*%udp%*|*%udp6%*|*%$NAME%*)
  7831. TEST="$NAME: UDP6-LISTEN with bind"
  7832. if ! eval $NUMCOND; then :;
  7833. elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
  7834. $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
  7835. numCANT=$((numCANT+1))
  7836. else
  7837. tf="$td/test$N.stdout"
  7838. te="$td/test$N.stderr"
  7839. tdiff="$td/test$N.diff"
  7840. tsl=$PORT
  7841. ts="$LOCALHOST6:$tsl"
  7842. da="test$N $(date) $RANDOM"
  7843. CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR,bind=$LOCALHOST6 PIPE"
  7844. CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
  7845. printf "test $F_n $TEST... " $N
  7846. $CMD1 >"$tf" 2>"${te}1" &
  7847. pid1=$!
  7848. waitudp6port $tsl 1
  7849. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  7850. rc2=$?
  7851. kill $pid1 2>/dev/null; wait
  7852. if [ $rc2 -ne 0 ]; then
  7853. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7854. echo "$CMD1 &"
  7855. echo "$CMD2"
  7856. cat "${te}1" "${te}2"
  7857. numFAIL=$((numFAIL+1))
  7858. listFAIL="$listFAIL $N"
  7859. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  7860. $PRINTF "$FAILED\n"
  7861. cat "$tdiff"
  7862. numFAIL=$((numFAIL+1))
  7863. listFAIL="$listFAIL $N"
  7864. else
  7865. $PRINTF "$OK\n"
  7866. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  7867. numOK=$((numOK+1))
  7868. fi
  7869. fi ;; # NUMCOND, feats
  7870. esac
  7871. PORT=$((PORT+1))
  7872. N=$((N+1))
  7873. NAME=TCPWRAPPERS_MULTIOPTS
  7874. # this tests for a bug in 1.5.0.0 that let socat fail when more than one
  7875. # tcp-wrappers related option was specified in one address
  7876. case "$TESTS" in
  7877. *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
  7878. TEST="$NAME: use of multiple tcpwrapper enabling options"
  7879. if ! eval $NUMCOND; then :;
  7880. elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
  7881. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7882. numCANT=$((numCANT+1))
  7883. else
  7884. tf="$td/test$N.stdout"
  7885. te="$td/test$N.stderr"
  7886. tdiff="$td/test$N.diff"
  7887. da="test$N $(date) $RANDOM"
  7888. ha="$td/hosts.allow"
  7889. $ECHO "test : ALL : allow" >"$ha"
  7890. CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,hosts-allow=$ha,tcpwrap=test pipe"
  7891. CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
  7892. printf "test $F_n $TEST... " $N
  7893. $CMD1 2>"${te}1" &
  7894. waittcp4port $PORT
  7895. echo "$da" |$CMD2 >"$tf" 2>"${te}2"
  7896. if [ $? -ne 0 ]; then
  7897. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7898. echo "$CMD1 &"
  7899. echo "$CMD2"
  7900. cat "${te}1"
  7901. cat "${te}2"
  7902. numFAIL=$((numFAIL+1))
  7903. listFAIL="$listFAIL $N"
  7904. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  7905. $PRINTF "$FAILED\n"
  7906. cat "$tdiff"
  7907. numFAIL=$((numFAIL+1))
  7908. listFAIL="$listFAIL $N"
  7909. else
  7910. $PRINTF "$OK\n"
  7911. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  7912. numOK=$((numOK+1))
  7913. fi
  7914. fi ;; # NUMCOND, feats
  7915. esac
  7916. PORT=$((PORT+1))
  7917. N=$((N+1))
  7918. NAME=TCPWRAPPERS_TCP6ADDR
  7919. # this tests for a bug in 1.5.0.0 that brought false results with tcp-wrappers
  7920. # and IPv6 when
  7921. case "$TESTS" in
  7922. *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
  7923. TEST="$NAME: specification of TCP6 address in hosts.allow"
  7924. if ! eval $NUMCOND; then :;
  7925. elif ! feat=$(testaddrs tcp ip6 libwrap && runsip6); then
  7926. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  7927. numCANT=$((numCANT+1))
  7928. else
  7929. tf="$td/test$N.stdout"
  7930. te="$td/test$N.stderr"
  7931. tdiff="$td/test$N.diff"
  7932. da="test$N $(date) $RANDOM"
  7933. ha="$td/hosts.allow"
  7934. hd="$td/hosts.deny"
  7935. $ECHO "socat : [::1] : allow" >"$ha"
  7936. $ECHO "ALL : ALL : deny" >"$hd"
  7937. CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$PORT,$REUSEADDR,tcpwrap-etc=$td,tcpwrappers=socat pipe"
  7938. CMD2="$TRACE $SOCAT $opts - TCP6:[::1]:$PORT"
  7939. printf "test $F_n $TEST... " $N
  7940. $CMD1 2>"${te}1" &
  7941. pid1=$!
  7942. waittcp6port $PORT
  7943. echo "$da" |$CMD2 >"$tf" 2>"${te}2"
  7944. kill $pid1 2>/dev/null; wait
  7945. if [ $? -ne 0 ]; then
  7946. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7947. echo "$CMD1 &"
  7948. echo "$CMD2"
  7949. cat "${te}1"
  7950. cat "${te}2"
  7951. numFAIL=$((numFAIL+1))
  7952. listFAIL="$listFAIL $N"
  7953. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  7954. $PRINTF "$FAILED\n"
  7955. cat "$tdiff"
  7956. numFAIL=$((numFAIL+1))
  7957. listFAIL="$listFAIL $N"
  7958. else
  7959. $PRINTF "$OK\n"
  7960. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  7961. numOK=$((numOK+1))
  7962. fi
  7963. fi ;; # NUMCOND, feats
  7964. esac
  7965. PORT=$((PORT+1))
  7966. N=$((N+1))
  7967. NAME=UDP4BROADCAST
  7968. case "$TESTS" in
  7969. *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%$NAME%*)
  7970. TEST="$NAME: UDP/IPv4 broadcast"
  7971. if ! eval $NUMCOND; then :;
  7972. elif [ -z "$BCADDR" ]; then
  7973. $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
  7974. numCANT=$((numCANT+1))
  7975. else
  7976. tf="$td/test$N.stdout"
  7977. te="$td/test$N.stderr"
  7978. tdiff="$td/test$N.diff"
  7979. ts1p=$PORT; PORT=$((PORT+1))
  7980. #ts1="$BCADDR/8:$ts1p"
  7981. ts1="$BCADDR:$ts1p"
  7982. ts2p=$PORT; PORT=$((PORT+1))
  7983. ts2="$BCIFADDR:$ts2p"
  7984. da="test$N $(date) $RANDOM"
  7985. CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE"
  7986. #CMD2="$TRACE $SOCAT $opts - UDP4-BROADCAST:$ts1"
  7987. CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast"
  7988. printf "test $F_n $TEST... " $N
  7989. $CMD1 2>"${te}1" &
  7990. pid1="$!"
  7991. waitudp4port $ts1p 1
  7992. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  7993. rc2="$?"
  7994. kill "$pid1" 2>/dev/null; wait;
  7995. if [ "$rc2" -ne 0 ]; then
  7996. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  7997. echo "$CMD1 &"
  7998. echo "$CMD2"
  7999. cat "${te}1"
  8000. cat "${te}2"
  8001. numFAIL=$((numFAIL+1))
  8002. listFAIL="$listFAIL $N"
  8003. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8004. $PRINTF "$FAILED\n"
  8005. cat "$tdiff"
  8006. numFAIL=$((numFAIL+1))
  8007. listFAIL="$listFAIL $N"
  8008. else
  8009. $PRINTF "$OK\n"
  8010. if [ -n "$tut" ]; then
  8011. echo "$CMD1 &"
  8012. echo "$CMD2"
  8013. fi
  8014. if [ -n "$debug" ]; then cat $te; fi
  8015. numOK=$((numOK+1))
  8016. fi
  8017. fi ;; # NUMCOND, feats
  8018. esac
  8019. N=$((N+1))
  8020. NAME=IP4BROADCAST
  8021. # test a local broadcast of a raw IPv4 protocol.
  8022. # because we receive - in addition to the regular reply - our own broadcast,
  8023. # we use a token XXXX that is changed to YYYY in the regular reply packet.
  8024. case "$TESTS" in
  8025. *%$N%*|*%functions%*|*%engine%*|*%rawip%*|*%rawip4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%root%*|*%$NAME%*)
  8026. TEST="$NAME: raw IPv4 broadcast"
  8027. if ! eval $NUMCOND; then :;
  8028. elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
  8029. $PRINTF "test $F_n $TEST... ${YELLOW}raw IP4 not available${NORMAL}\n" $N
  8030. numCANT=$((numCANT+1))
  8031. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  8032. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  8033. numCANT=$((numCANT+1))
  8034. elif [ -z "$BCADDR" ]; then
  8035. $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
  8036. else
  8037. tf="$td/test$N.stdout"
  8038. te="$td/test$N.stderr"
  8039. tdiff="$td/test$N.diff"
  8040. ts1p=$PROTO
  8041. #ts1="$BCADDR/8:$ts1p"
  8042. ts1="$BCADDR:$ts1p"
  8043. ts2p=$ts1p
  8044. ts2="$BCIFADDR"
  8045. da="test$N $(date) $RANDOM XXXX"
  8046. sh="$td/test$N-sed.sh"
  8047. echo 'sed s/XXXX/YYYY/' >"$sh"
  8048. chmod a+x "$sh"
  8049. CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,broadcast exec:$sh"
  8050. #CMD2="$TRACE $SOCAT $opts - IP4-BROADCAST:$ts1"
  8051. CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:$ts1,broadcast"
  8052. printf "test $F_n $TEST... " $N
  8053. $CMD1 2>"${te}1" &
  8054. pid1="$!"
  8055. waitip4port $ts1p 1
  8056. echo "$da" |$CMD2 2>>"${te}2" |grep -v XXXX >>"$tf"
  8057. rc2="$?"
  8058. kill "$pid1" 2>/dev/null; wait;
  8059. if [ "$rc2" -ne 0 ]; then
  8060. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8061. echo "$CMD1 &"
  8062. echo "$CMD2"
  8063. cat "${te}1"
  8064. cat "${te}2"
  8065. numFAIL=$((numFAIL+1))
  8066. listFAIL="$listFAIL $N"
  8067. elif ! echo "$da" | sed 's/XXXX/YYYY/'|diff - "$tf" >"$tdiff"; then
  8068. $PRINTF "$FAILED\n"
  8069. cat "$tdiff"
  8070. numFAIL=$((numFAIL+1))
  8071. listFAIL="$listFAIL $N"
  8072. else
  8073. $PRINTF "$OK\n"
  8074. if [ -n "$debug" ]; then cat $te; fi
  8075. numOK=$((numOK+1))
  8076. fi
  8077. fi ;; # NUMCOND, feats
  8078. esac
  8079. PROTO=$((PROTO+1))
  8080. N=$((N+1))
  8081. #NAME=UDP4BROADCAST_RANGE
  8082. #case "$TESTS" in
  8083. #*%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%range%*|*%$NAME%*)
  8084. #TEST="$NAME: security of UDP4-BROADCAST with RANGE option"
  8085. #if ! eval $NUMCOND; then :;
  8086. #elif [ -z "$BCADDR" ]; then
  8087. # $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
  8088. #else
  8089. #testserversec "$N" "$TEST" "$opts" "UDP4-BROADCAST:$BCADDR/8:$PORT" "" "range=127.1.0.0:255.255.0.0" "udp4:127.1.0.0:$PORT" 4 udp $PORT 0
  8090. #fi ;; # NUMCOND, feats
  8091. #esac
  8092. #PORT=$((PORT+1))
  8093. #N=$((N+1))
  8094. NAME=UDP4MULTICAST_UNIDIR
  8095. case "$TESTS" in
  8096. *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
  8097. TEST="$NAME: UDP/IPv4 multicast, send only"
  8098. if ! eval $NUMCOND; then :;
  8099. elif ! feat=$(testaddrs ip4 udp) || ! runsip4 >/dev/null; then
  8100. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8101. numCANT=$((numCANT+1))
  8102. else
  8103. tf="$td/test$N.stdout"
  8104. te="$td/test$N.stderr"
  8105. tdiff="$td/test$N.diff"
  8106. ts1p=$PORT; PORT=$((PORT+1))
  8107. ts1a="$SECONDADDR"
  8108. ts1="$ts1a:$ts1p"
  8109. da="test$N $(date) $RANDOM"
  8110. CMD1="$TRACE $SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
  8111. CMD2="$TRACE $SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
  8112. printf "test $F_n $TEST... " $N
  8113. $CMD1 2>"${te}1" >"${tf}" &
  8114. pid1="$!"
  8115. waitudp4port $ts1p 1
  8116. echo "$da" |$CMD2 2>>"${te}2"
  8117. rc2="$?"
  8118. usleep $MICROS
  8119. kill "$pid1" 2>/dev/null; wait;
  8120. if [ "$rc2" -ne 0 ]; then
  8121. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8122. echo "$CMD1 &"
  8123. echo "$CMD2"
  8124. cat "${te}1"
  8125. cat "${te}2"
  8126. numFAIL=$((numFAIL+1))
  8127. listFAIL="$listFAIL $N"
  8128. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8129. $PRINTF "$FAILED\n"
  8130. cat "$tdiff"
  8131. numFAIL=$((numFAIL+1))
  8132. listFAIL="$listFAIL $N"
  8133. else
  8134. $PRINTF "$OK\n"
  8135. if [ -n "$debug" ]; then cat $te; fi
  8136. numOK=$((numOK+1))
  8137. fi
  8138. fi ;; # NUMCOND, feats
  8139. esac
  8140. N=$((N+1))
  8141. NAME=IP4MULTICAST_UNIDIR
  8142. case "$TESTS" in
  8143. *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
  8144. TEST="$NAME: IPv4 multicast"
  8145. if ! eval $NUMCOND; then :;
  8146. elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
  8147. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8148. numCANT=$((numCANT+1))
  8149. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  8150. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  8151. numCANT=$((numCANT+1))
  8152. else
  8153. tf="$td/test$N.stdout"
  8154. te="$td/test$N.stderr"
  8155. tdiff="$td/test$N.diff"
  8156. ts1p=$PROTO
  8157. ts1a="$SECONDADDR"
  8158. ts1="$ts1a:$ts1p"
  8159. da="test$N $(date) $RANDOM"
  8160. CMD1="$TRACE $SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
  8161. CMD2="$TRACE $SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
  8162. printf "test $F_n $TEST... " $N
  8163. $CMD1 2>"${te}1" >"${tf}" &
  8164. pid1="$!"
  8165. waitip4proto $ts1p 1
  8166. usleep $MICROS
  8167. echo "$da" |$CMD2 2>>"${te}2"
  8168. rc2="$?"
  8169. #usleep $MICROS
  8170. sleep 1
  8171. kill "$pid1" 2>/dev/null; wait;
  8172. if [ "$rc2" -ne 0 ]; then
  8173. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8174. echo "$CMD1 &"
  8175. echo "$CMD2"
  8176. cat "${te}1"
  8177. cat "${te}2"
  8178. numFAIL=$((numFAIL+1))
  8179. listFAIL="$listFAIL $N"
  8180. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8181. $PRINTF "$FAILED\n"
  8182. cat "$tdiff"
  8183. numFAIL=$((numFAIL+1))
  8184. listFAIL="$listFAIL $N"
  8185. else
  8186. $PRINTF "$OK\n"
  8187. if [ -n "$debug" ]; then cat $te; fi
  8188. numOK=$((numOK+1))
  8189. fi
  8190. fi ;; # NUMCOND, feats
  8191. esac
  8192. PROTO=$((PROTO+1))
  8193. N=$((N+1))
  8194. if true; then
  8195. NAME=UDP6MULTICAST_UNIDIR
  8196. case "$TESTS" in
  8197. *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%multicast%*|*%$NAME%*)
  8198. TEST="$NAME: UDP/IPv6 multicast"
  8199. if ! eval $NUMCOND; then :;
  8200. elif ! feat=$(testaddrs ip6 udp && runsip6); then
  8201. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8202. numCANT=$((numCANT+1))
  8203. else
  8204. tf="$td/test$N.stdout"
  8205. te="$td/test$N.stderr"
  8206. tdiff="$td/test$N.diff"
  8207. ts1p=$PORT; PORT=$((PORT+1))
  8208. if1="$MCINTERFACE"
  8209. ts1a="[::1]"
  8210. da="test$N $(date) $RANDOM"
  8211. CMD1="$TRACE $SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -"
  8212. CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a"
  8213. #CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p"
  8214. printf "test $F_n $TEST... " $N
  8215. $CMD1 2>"${te}1" >"${tf}" &
  8216. pid1="$!"
  8217. waitudp6port $ts1p 1
  8218. echo "$da" |$CMD2 2>>"${te}2"
  8219. rc2="$?"
  8220. usleep $MICROS
  8221. kill "$pid1" 2>/dev/null; wait;
  8222. if [ "$rc2" -ne 0 ]; then
  8223. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8224. echo -e "$CMD1 &\n$CMD2"
  8225. cat "${te}1"
  8226. cat "${te}2"
  8227. numFAIL=$((numFAIL+1))
  8228. listFAIL="$listFAIL $N"
  8229. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8230. $PRINTF "$FAILED\n"
  8231. echo "$CMD1 &"
  8232. echo "$CMD2"
  8233. cat "$tdiff"
  8234. numFAIL=$((numFAIL+1))
  8235. listFAIL="$listFAIL $N"
  8236. else
  8237. $PRINTF "$OK\n"
  8238. if [ "$VERBOSE" ]; then echo -e "$CMD1 &\n$CMD2"; fi
  8239. if [ -n "$debug" ]; then cat $te; fi
  8240. numOK=$((numOK+1))
  8241. fi
  8242. fi ;; # NUMCOND, feats
  8243. esac
  8244. N=$((N+1))
  8245. fi # false
  8246. NAME=UDP4MULTICAST_BIDIR
  8247. case "$TESTS" in
  8248. *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
  8249. TEST="$NAME: UDP/IPv4 multicast, with reply"
  8250. if ! eval $NUMCOND; then :; else
  8251. tf="$td/test$N.stdout"
  8252. te="$td/test$N.stderr"
  8253. tdiff="$td/test$N.diff"
  8254. ts1p=$PORT; PORT=$((PORT+1))
  8255. ts1a="$SECONDADDR"
  8256. ts1="$ts1a:$ts1p"
  8257. ts2p=$PORT; PORT=$((PORT+1))
  8258. ts2="$BCIFADDR:$ts2p"
  8259. da="test$N $(date) $RANDOM"
  8260. CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
  8261. #CMD2="$TRACE $SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
  8262. CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
  8263. printf "test $F_n $TEST... " $N
  8264. $CMD1 2>"${te}1" &
  8265. pid1="$!"
  8266. waitudp4port $ts1p 1
  8267. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  8268. rc2="$?"
  8269. kill "$pid1" 2>/dev/null; wait;
  8270. if [ "$rc2" -ne 0 ]; then
  8271. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8272. echo "$CMD1 &"
  8273. echo "$CMD2"
  8274. cat "${te}1"
  8275. cat "${te}2"
  8276. numFAIL=$((numFAIL+1))
  8277. listFAIL="$listFAIL $N"
  8278. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8279. $PRINTF "$FAILED\n"
  8280. cat "$tdiff"
  8281. numFAIL=$((numFAIL+1))
  8282. listFAIL="$listFAIL $N"
  8283. else
  8284. $PRINTF "$OK\n"
  8285. if [ -n "$VERBOSE" ]; then
  8286. echo "$CMD1 &"
  8287. echo "$CMD2"
  8288. fi
  8289. if [ -n "$debug" ]; then cat $te; fi
  8290. numOK=$((numOK+1))
  8291. fi
  8292. fi ;; # NUMCOND
  8293. esac
  8294. N=$((N+1))
  8295. NAME=IP4MULTICAST_BIDIR
  8296. case "$TESTS" in
  8297. *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
  8298. TEST="$NAME: IPv4 multicast, with reply"
  8299. if ! eval $NUMCOND; then :;
  8300. elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
  8301. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8302. numCANT=$((numCANT+1))
  8303. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  8304. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  8305. numCANT=$((numCANT+1))
  8306. else
  8307. tf="$td/test$N.stdout"
  8308. te="$td/test$N.stderr"
  8309. tdiff="$td/test$N.diff"
  8310. ts1p=$PROTO
  8311. ts1a="$SECONDADDR"
  8312. ts1="$ts1a:$ts1p"
  8313. da="test$N $(date) $RANDOM"
  8314. CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
  8315. #CMD2="$TRACE $SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
  8316. CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
  8317. printf "test $F_n $TEST... " $N
  8318. $CMD1 2>"${te}1" &
  8319. pid1="$!"
  8320. waitip4port $ts1p 1
  8321. usleep 100000 # give process a chance to add multicast membership
  8322. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  8323. rc2="$?"
  8324. kill "$pid1" 2>/dev/null; wait;
  8325. if [ "$rc2" -ne 0 ]; then
  8326. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8327. echo "$CMD1 &"
  8328. echo "$CMD2"
  8329. cat "${te}1"
  8330. cat "${te}2"
  8331. numFAIL=$((numFAIL+1))
  8332. listFAIL="$listFAIL $N"
  8333. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8334. $PRINTF "$FAILED\n"
  8335. cat "$tdiff"
  8336. numFAIL=$((numFAIL+1))
  8337. listFAIL="$listFAIL $N"
  8338. else
  8339. $PRINTF "$OK\n"
  8340. if [ -n "$tut" ]; then
  8341. echo "$CMD1 &"
  8342. echo "$CMD2"
  8343. fi
  8344. if [ -n "$debug" ]; then cat $te; fi
  8345. numOK=$((numOK+1))
  8346. fi
  8347. fi ;; # NUMCOND, feats
  8348. esac
  8349. PROTO=$((PROTO+1))
  8350. N=$((N+1))
  8351. NAME=TUNREAD
  8352. case "$TESTS" in
  8353. *%$N%*|*%functions%*|*%tun%*|*%root%*|*%$NAME%*)
  8354. TEST="$NAME: reading data sent through tun interface"
  8355. #idea: create a TUN interface and send a datagram to one of the addresses of
  8356. # its virtual network. On the tunnel side, read the packet and compare its last
  8357. # bytes with the datagram payload
  8358. if ! eval $NUMCOND; then :;
  8359. elif ! feat=$(testaddrs ip4 tun) || ! runsip4 >/dev/null; then
  8360. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8361. numCANT=$((numCANT+1))
  8362. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  8363. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  8364. numCANT=$((numCANT+1))
  8365. else
  8366. tf="$td/test$N.stdout"
  8367. te="$td/test$N.stderr"
  8368. tdiff="$td/test$N.diff"
  8369. tl="$td/test$N.lock"
  8370. da="test$N $(date) $RANDOM"
  8371. dalen=$((${#da}+1))
  8372. TUNNET=10.255.255
  8373. CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT"
  8374. #CMD="$TRACE $SOCAT $opts -u -L $tl TUN,ifaddr=$TUNNET.1,netmask=255.255.255.0,iff-up=1 -"
  8375. CMD="$TRACE $SOCAT $opts -u -L $tl TUN:$TUNNET.1/24,iff-up=1 -"
  8376. printf "test $F_n $TEST... " $N
  8377. $CMD 2>"${te}" |tail -c $dalen >"${tf}" &
  8378. sleep 1
  8379. echo "$da" |$CMD1 2>"${te}1"
  8380. sleep 1
  8381. kill "$(cat $tl 2>/dev/null)" 2>/dev/null
  8382. wait
  8383. if [ $? -ne 0 ]; then
  8384. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8385. echo "$CMD &"
  8386. echo "$CMD1"
  8387. cat "${te}" "${te}1"
  8388. numFAIL=$((numFAIL+1))
  8389. listFAIL="$listFAIL $N"
  8390. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8391. $PRINTF "$FAILED\n"
  8392. echo "$CMD &"
  8393. echo "$CMD1"
  8394. cat "$tdiff"
  8395. cat "${te}" "${te}1"
  8396. numFAIL=$((numFAIL+1))
  8397. listFAIL="$listFAIL $N"
  8398. else
  8399. $PRINTF "$OK\n"
  8400. if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
  8401. numOK=$((numOK+1))
  8402. fi
  8403. fi ;; # NUMCOND, feats
  8404. esac
  8405. PORT=$((PORT+1))
  8406. N=$((N+1))
  8407. # use the INTERFACE address on a tun/tap device and transfer data fully
  8408. # transparent
  8409. NAME=TUNINTERFACE
  8410. case "$TESTS" in
  8411. *%$N%*|*%functions%*|*%tun%*|*%interface%*|*%root%*|*%$NAME%*)
  8412. TEST="$NAME: pass data through tun interface using INTERFACE"
  8413. #idea: create a TUN interface and send a raw packet on the interface side.
  8414. # It should arrive unmodified on the tunnel side.
  8415. if ! eval $NUMCOND; then :;
  8416. elif ! feat=$(testaddrs ip4 tun interface) || ! runsip4 >/dev/null; then
  8417. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8418. numCANT=$((numCANT+1))
  8419. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  8420. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  8421. numCANT=$((numCANT+1))
  8422. else
  8423. tf="$td/test$N.stdout"
  8424. te="$td/test$N.stderr"
  8425. tdiff="$td/test$N.diff"
  8426. tl="$td/test$N.lock"
  8427. da="$(date) $RANDOM"
  8428. dalen=$((${#da}+1))
  8429. TUNNET=10.255.255
  8430. TUNNAME=tun9
  8431. CMD1="$TRACE $SOCAT $opts -L $tl TUN:$TUNNET.1/24,iff-up=1,tun-type=tun,tun-name=$TUNNAME echo"
  8432. CMD="$TRACE $SOCAT $opts - INTERFACE:$TUNNAME"
  8433. printf "test $F_n $TEST... " $N
  8434. $CMD1 2>"${te}1" &
  8435. pid1="$!"
  8436. #waitinterface "$TUNNAME"
  8437. sleep 1
  8438. echo "$da" |$CMD 2>"${te}1" >"$tf" 2>"${te}"
  8439. kill $pid1 2>/dev/null
  8440. wait
  8441. if [ $? -ne 0 ]; then
  8442. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8443. echo "$CMD &"
  8444. echo "$CMD1"
  8445. cat "${te}" "${te}1"
  8446. numFAIL=$((numFAIL+1))
  8447. listFAIL="$listFAIL $N"
  8448. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8449. $PRINTF "$FAILED\n"
  8450. echo "$CMD &"
  8451. echo "$CMD1"
  8452. cat "$tdiff"
  8453. cat "${te}" "${te}1"
  8454. numFAIL=$((numFAIL+1))
  8455. listFAIL="$listFAIL $N"
  8456. else
  8457. $PRINTF "$OK\n"
  8458. if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
  8459. numOK=$((numOK+1))
  8460. fi
  8461. fi ;; # NUMCOND, feats
  8462. esac
  8463. PORT=$((PORT+1))
  8464. N=$((N+1))
  8465. NAME=ABSTRACTSTREAM
  8466. case "$TESTS" in
  8467. *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%connect%*|*%listen%*|*%$NAME%*)
  8468. TEST="$NAME: abstract UNIX stream socket, listen and connect"
  8469. if ! eval $NUMCOND; then :;
  8470. elif ! feat=$(testaddrs abstract-unixsocket); then
  8471. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8472. numCANT=$((numCANT+1))
  8473. else
  8474. ts="$td/test$N.socket"
  8475. tf="$td/test$N.stdout"
  8476. te="$td/test$N.stderr"
  8477. tdiff="$td/test$N.diff"
  8478. da1="test$N $(date) $RANDOM"
  8479. #establish a listening abstract unix socket
  8480. SRV="$TRACE $SOCAT $opts -lpserver ABSTRACT-LISTEN:\"$ts\",$REUSEADDR PIPE"
  8481. #make a connection
  8482. CMD="$TRACE $SOCAT $opts - ABSTRACT-CONNECT:$ts"
  8483. $PRINTF "test $F_n $TEST... " $N
  8484. touch "$ts" # make a file with same name, so non-abstract fails
  8485. eval "$SRV 2>${te}s &"
  8486. pids=$!
  8487. #waitfile "$ts"
  8488. sleep 1
  8489. echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
  8490. if [ $? -ne 0 ]; then
  8491. kill "$pids" 2>/dev/null
  8492. $PRINTF "$FAILED:\n"
  8493. echo "$SRV &"
  8494. cat "${te}s"
  8495. echo "$CMD"
  8496. cat "${te}1"
  8497. numFAIL=$((numFAIL+1))
  8498. listFAIL="$listFAIL $N"
  8499. elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
  8500. kill "$pids" 2>/dev/null
  8501. $PRINTF "$FAILED:\n"
  8502. echo "$SRV &"
  8503. cat "${te}s"
  8504. echo "$CMD"
  8505. cat "${te}1"
  8506. cat "$tdiff"
  8507. numFAIL=$((numFAIL+1))
  8508. listFAIL="$listFAIL $N"
  8509. else
  8510. $PRINTF "$OK\n"
  8511. if [ -n "$debug" ]; then cat $te; fi
  8512. numOK=$((numOK+1))
  8513. fi # !(rc -ne 0)
  8514. wait
  8515. fi ;; # NUMCOND, feats
  8516. esac
  8517. N=$((N+1))
  8518. NAME=ABSTRACTDGRAM
  8519. case "$TESTS" in
  8520. *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%$NAME%*)
  8521. TEST="$NAME: abstract UNIX datagram"
  8522. if ! eval $NUMCOND; then :;
  8523. elif ! feat=$(testaddrs abstract-unixsocket); then
  8524. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8525. numCANT=$((numCANT+1))
  8526. else
  8527. tf="$td/test$N.stdout"
  8528. te="$td/test$N.stderr"
  8529. tdiff="$td/test$N.diff"
  8530. ts1="$td/test$N.socket1"
  8531. ts2="$td/test$N.socket2"
  8532. da="test$N $(date) $RANDOM"
  8533. CMD1="$TRACE $SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE"
  8534. #CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
  8535. CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
  8536. printf "test $F_n $TEST... " $N
  8537. touch "$ts1" # make a file with same name, so non-abstract fails
  8538. $CMD1 2>"${te}1" &
  8539. pid1="$!"
  8540. sleep 1
  8541. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  8542. rc2=$?
  8543. kill "$pid1" 2>/dev/null; wait
  8544. if [ $rc2 -ne 0 ]; then
  8545. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8546. echo "$CMD1 &"
  8547. cat "${te}1"
  8548. echo "$CMD2"
  8549. cat "${te}2"
  8550. numFAIL=$((numFAIL+1))
  8551. listFAIL="$listFAIL $N"
  8552. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8553. $PRINTF "$FAILED\n"
  8554. cat "$tdiff"
  8555. numFAIL=$((numFAIL+1))
  8556. listFAIL="$listFAIL $N"
  8557. else
  8558. $PRINTF "$OK\n"
  8559. if [ -n "$debug" ]; then cat $te; fi
  8560. numOK=$((numOK+1))
  8561. fi
  8562. fi ;; # NUMCOND, feats
  8563. esac
  8564. N=$((N+1))
  8565. NAME=ABSTRACTRECV
  8566. case "$TESTS" in
  8567. *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%recv%*|*%$NAME%*)
  8568. TEST="$NAME: abstract UNIX datagram receive"
  8569. if ! eval $NUMCOND; then :;
  8570. elif ! feat=$(testaddrs abstract-unixsocket); then
  8571. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  8572. numCANT=$((numCANT+1))
  8573. else
  8574. ts="$td/test$N.socket"
  8575. tf="$td/test$N.stdout"
  8576. te="$td/test$N.stderr"
  8577. tdiff="$td/test$N.diff"
  8578. ts1="$ts"
  8579. da="test$N $(date) $RANDOM"
  8580. CMD1="$TRACE $SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -"
  8581. CMD2="$TRACE $SOCAT $opts -u - ABSTRACT-SENDTO:$ts1"
  8582. printf "test $F_n $TEST... " $N
  8583. touch "$ts1" # make a file with same name, so non-abstract fails
  8584. $CMD1 >"$tf" 2>"${te}1" &
  8585. pid1="$!"
  8586. #waitfile $ts1 1
  8587. sleep 1
  8588. echo "$da" |$CMD2 2>>"${te}2"
  8589. rc2="$?"
  8590. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  8591. kill "$pid1" 2>/dev/null; wait
  8592. if [ "$rc2" -ne 0 ]; then
  8593. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8594. echo "$CMD1 &"
  8595. echo "$CMD2"
  8596. cat "${te}1"
  8597. cat "${te}2"
  8598. numFAIL=$((numFAIL+1))
  8599. listFAIL="$listFAIL $N"
  8600. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8601. $PRINTF "$FAILED\n"
  8602. cat "$tdiff"
  8603. numFAIL=$((numFAIL+1))
  8604. listFAIL="$listFAIL $N"
  8605. else
  8606. $PRINTF "$OK\n"
  8607. if [ -n "$debug" ]; then cat $te; fi
  8608. numOK=$((numOK+1))
  8609. fi
  8610. fi ;; # NUMCOND, feats
  8611. esac
  8612. N=$((N+1))
  8613. # bind with Linux abstract UNIX domain addresses bound to filesystem socket
  8614. # instead of abstract namespace
  8615. NAME=ABSTRACT_BIND
  8616. case "$TESTS" in
  8617. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
  8618. TEST="$NAME: abstract bind"
  8619. # open an abstract client address with bind option, bind to the target socket.
  8620. # send a datagram.
  8621. # when socat outputs the datagram it got the test succeeded
  8622. if ! eval $NUMCOND; then :;
  8623. elif [ "$UNAME" != Linux ]; then
  8624. $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
  8625. numCANT=$((numCANT+1))
  8626. else
  8627. tf="$td/test$N.stdout"
  8628. te="$td/test$N.stderr"
  8629. tdiff="$td/test$N.diff"
  8630. ts1="$td/test$N.sock1"
  8631. da="test$N $(date) $RANDOM"
  8632. CMD1="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts1"
  8633. printf "test $F_n $TEST... " $N
  8634. echo "$da" |$CMD1 >$tf 2>"${te}1"
  8635. rc1=$?
  8636. if [ $rc1 -ne 0 ]; then
  8637. $PRINTF "$FAILED\n"
  8638. echo "$CMD1" >&2
  8639. echo "rc=$rc1" >&2
  8640. cat "${te}1" >&2
  8641. numFAIL=$((numFAIL+1))
  8642. listFAIL="$listFAIL $N"
  8643. elif echo "$da" |diff -q - $tf; then
  8644. $PRINTF "$OK\n"
  8645. numOK=$((numOK+1))
  8646. else
  8647. $PRINTF "$FAILED\n"
  8648. echo "$CMD1" >&2
  8649. cat "${te}1" >&2
  8650. echo "$da" |diff - "$tf" >&2
  8651. numFAIL=$((numFAIL+1))
  8652. listFAIL="$listFAIL $N"
  8653. fi
  8654. fi # NUMCOND
  8655. ;;
  8656. esac
  8657. PORT=$((PORT+1))
  8658. N=$((N+1))
  8659. NAME=OPENSSLREAD
  8660. # socat determined availability of data using select(). With openssl, the
  8661. # following situation might occur:
  8662. # a SSL data block with more than 8192 bytes (socats default blocksize)
  8663. # arrives; socat calls SSL_read, and the SSL routine reads the complete block.
  8664. # socat then reads 8192 bytes from the SSL layer, the rest remains buffered.
  8665. # If the TCP connection stays idle for some time, the data in the SSL layer
  8666. # keeps there and is not transferred by socat until the socket indicates more
  8667. # data or EOF.
  8668. case "$TESTS" in
  8669. *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
  8670. TEST="$NAME: socat handles data buffered by openssl"
  8671. #idea: have a socat process (server) that gets an SSL block that is larger than
  8672. # socat transfer block size; keep the socket connection open and kill the
  8673. # server process after a short time; if not the whole data block has been
  8674. # transferred, the test has failed.
  8675. if ! eval $NUMCOND; then :;
  8676. elif ! feat=$(testaddrs openssl) >/dev/null; then
  8677. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  8678. numCANT=$((numCANT+1))
  8679. else
  8680. tf="$td/test$N.out"
  8681. te="$td/test$N.err"
  8682. tdiff="$td/test$N.diff"
  8683. da="test$N $(date) $RANDOM"
  8684. SRVCERT=testsrv
  8685. gentestcert "$SRVCERT"
  8686. CMD1="$TRACE $SOCAT $opts -u -T 1 -b $($ECHO "$da\c" |wc -c) OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$SRVCERT.pem,verify=0 -"
  8687. CMD2="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
  8688. printf "test $F_n $TEST... " $N
  8689. #
  8690. $CMD1 2>"${te}1" >"$tf" &
  8691. pid=$! # background process id
  8692. waittcp4port $PORT
  8693. (echo "$da"; sleep 2) |$CMD2 2>"${te}2"
  8694. kill "$pid" 2>/dev/null; wait
  8695. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8696. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8697. echo "$CMD1"
  8698. cat "${te}1"
  8699. echo "$CMD2"
  8700. cat "${te}2"
  8701. cat "$tdiff"
  8702. numFAIL=$((numFAIL+1))
  8703. listFAIL="$listFAIL $N"
  8704. else
  8705. $PRINTF "$OK\n"
  8706. if [ -n "$debug" ]; then cat $te; fi
  8707. numOK=$((numOK+1))
  8708. fi
  8709. wait
  8710. fi # NUMCOND, featsesac
  8711. ;;
  8712. esac
  8713. N=$((N+1))
  8714. # test: there is a bug with the readbytes option: when the socket delivered
  8715. # exacly that many bytes as specified with readbytes and the stays idle (no
  8716. # more data, no EOF), socat waits for more data instead of generating EOF on
  8717. # this in put stream.
  8718. NAME=READBYTES_EOF
  8719. #set -vx
  8720. case "$TESTS" in
  8721. *%$N%*|*%functions%*|*%$NAME%*)
  8722. TEST="$NAME: trigger EOF after that many bytes, even when socket idle"
  8723. #idea: we deliver that many bytes to socat; the process should terminate then.
  8724. # we try to transfer data in the other direction then; if transfer succeeds,
  8725. # the process did not terminate and the bug is still there.
  8726. if ! eval $NUMCOND; then :;
  8727. elif false; then
  8728. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  8729. numCANT=$((numCANT+1))
  8730. else
  8731. tr="$td/test$N.ref"
  8732. ti="$td/test$N.in"
  8733. to="$td/test$N.out"
  8734. te="$td/test$N.err"
  8735. tdiff="$td/test$N.diff"
  8736. da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
  8737. CMD="$TRACE $SOCAT $opts SYSTEM:\"echo A; sleep $((2*SECONDs))\",readbytes=2!!- -!!/dev/null"
  8738. printf "test $F_n $TEST... " $N
  8739. (usleep $((2*MICROS)); echo) |eval "$CMD" >"$to" 2>"$te"
  8740. if test -s "$to"; then
  8741. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8742. echo "$CMD"
  8743. numFAIL=$((numFAIL+1))
  8744. listFAIL="$listFAIL $N"
  8745. else
  8746. $PRINTF "$OK\n"
  8747. if [ -n "$debug" ]; then cat $te; fi
  8748. numOK=$((numOK+1))
  8749. fi
  8750. fi ;; # NUMCOND, feats
  8751. esac
  8752. N=$((N+1))
  8753. # test: there was a bug with exec:...,pty that did not kill the exec'd sub
  8754. # process under some circumstances.
  8755. NAME=EXECPTYKILL
  8756. case "$TESTS" in
  8757. *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
  8758. TEST="$NAME: exec:...,pty explicitely kills sub process"
  8759. # we want to check if the exec'd sub process is killed in time
  8760. # for this we have a shell script that generates a file after two seconds;
  8761. # it should be killed after one second, so if the file was generated the test
  8762. # has failed
  8763. if ! eval $NUMCOND; then :; else
  8764. tf="$td/test$N.stdout"
  8765. te="$td/test$N.stderr"
  8766. ts="$td/test$N.sock"
  8767. tda="$td/test$N.data"
  8768. tsh="$td/test$N.sh"
  8769. tdiff="$td/test$N.diff"
  8770. cat >"$tsh" <<EOF
  8771. sleep $SECONDs; echo; sleep $SECONDs; touch "$tda"; echo
  8772. EOF
  8773. chmod a+x "$tsh"
  8774. CMD1="$TRACE $SOCAT $opts -t $SECONDs -U UNIX-LISTEN:$ts,fork EXEC:$tsh,pty"
  8775. CMD="$TRACE $SOCAT $opts -t $SECONDs /dev/null UNIX-CONNECT:$ts"
  8776. printf "test $F_n $TEST... " $N
  8777. $CMD1 2>"${te}2" &
  8778. pid1=$!
  8779. sleep $SECONDs
  8780. waitfile $ts $SECONDs
  8781. $CMD 2>>"${te}1" >>"$tf"
  8782. sleep $((2*SECONDs))
  8783. kill "$pid1" 2>/dev/null
  8784. wait
  8785. if [ $? -ne 0 ]; then
  8786. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8787. echo "$CMD1 &"
  8788. echo "$CMD2"
  8789. cat "${te}1" "${te}2"
  8790. numFAIL=$((numFAIL+1))
  8791. listFAIL="$listFAIL $N"
  8792. elif [ -f "$tda" ]; then
  8793. $PRINTF "$FAILED\n"
  8794. cat "${te}1" "${te}2"
  8795. numFAIL=$((numFAIL+1))
  8796. listFAIL="$listFAIL $N"
  8797. else
  8798. $PRINTF "$OK\n"
  8799. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  8800. numOK=$((numOK+1))
  8801. fi
  8802. fi ;; # NUMCOND
  8803. esac
  8804. PORT=$((PORT+1))
  8805. N=$((N+1))
  8806. # test if service name resolution works; this was buggy in 1.5 and 1.6.0.0
  8807. NAME=TCP4SERVICE
  8808. case "$TESTS" in
  8809. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
  8810. TEST="$NAME: echo via connection to TCP V4 socket"
  8811. # select a tcp entry from /etc/services, have a server listen on the port
  8812. # number and connect using the service name; with the bug, connection will to a
  8813. # wrong port
  8814. if ! eval $NUMCOND; then :; else
  8815. tf="$td/test$N.stdout"
  8816. te="$td/test$N.stderr"
  8817. tdiff="$td/test$N.diff"
  8818. # find a service entry we do not need root for (>=1024; here >=1100 for ease)
  8819. SERVENT="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)"
  8820. SERVICE="$(echo $SERVENT |cut -d' ' -f1)"
  8821. _PORT="$PORT"
  8822. PORT="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')"
  8823. tsl="$PORT"
  8824. ts="127.0.0.1:$SERVICE"
  8825. da="test$N $(date) $RANDOM"
  8826. CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
  8827. CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
  8828. printf "test $F_n $TEST... " $N
  8829. $CMD1 >"$tf" 2>"${te}1" &
  8830. pid1=$!
  8831. waittcp4port $tsl 1
  8832. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  8833. if [ $? -ne 0 ]; then
  8834. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8835. echo "$CMD1 &"
  8836. cat "${te}1"
  8837. echo "$CMD2"
  8838. cat "${te}2"
  8839. numFAIL=$((numFAIL+1))
  8840. listFAIL="$listFAIL $N"
  8841. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8842. $PRINTF "$FAILED\n"
  8843. cat "$tdiff"
  8844. numFAIL=$((numFAIL+1))
  8845. listFAIL="$listFAIL $N"
  8846. else
  8847. $PRINTF "$OK\n"
  8848. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  8849. numOK=$((numOK+1))
  8850. fi
  8851. kill $pid1 2>/dev/null
  8852. wait
  8853. PORT="$_PORT"
  8854. fi ;; # NUMCOND
  8855. esac
  8856. N=$((N+1))
  8857. # test: up to socat 1.6.0.0, the highest file descriptor supported in socats
  8858. # transfer engine was FOPEN_MAX-1; this usually worked fine but would fail when
  8859. # socat was invoked with many file descriptors already opened. socat would
  8860. # just hang in the select() call. Thanks to Daniel Lucq for reporting this
  8861. # problem.
  8862. # FOPEN_MAX on different OS's:
  8863. # OS FOPEN_ ulimit ulimit FD_
  8864. # MAX -H -n -S -n SETSIZE
  8865. # Linux 2.6: 16 1024 1024 1024
  8866. # HP-UX 11.11: 60 2048 2048 2048
  8867. # FreeBSD: 20 11095 11095 1024
  8868. # Cygwin: 20 unlimit 256 64
  8869. # AIX: 32767 65534 65534
  8870. # SunOS 8: 20 1024
  8871. NAME=EXCEED_FOPEN_MAX
  8872. case "$TESTS" in
  8873. *%$N%*|*%functions%*|*%maxfds%*|*%$NAME%*)
  8874. TEST="$NAME: more than FOPEN_MAX FDs in use"
  8875. # this test opens a number of FDs before socat is invoked. socat will have to
  8876. # allocate higher FD numbers and thus hang if it cannot handle them.
  8877. if ! eval $NUMCOND; then :; else
  8878. REDIR=
  8879. #set -vx
  8880. FOPEN_MAX=$($PROCAN -c 2>/dev/null |grep '^#define[ ][ ]*FOPEN_MAX' |awk '{print($3);}')
  8881. if [ -z "$FOPEN_MAX" ]; then
  8882. $PRINTF "test $F_n $TEST... ${YELLOW}could not determine FOPEN_MAX${NORMAL}\n" "$N"
  8883. numCANT=$((numCANT+1))
  8884. else
  8885. OPEN_FILES=$FOPEN_MAX # more than the highest FOPEN_MAX
  8886. i=3; while [ "$i" -lt "$OPEN_FILES" ]; do
  8887. REDIR="$REDIR $i>&2"
  8888. i=$((i+1))
  8889. done
  8890. #echo "$REDIR"
  8891. #testecho "$N" "$TEST" "" "pipe" "$opts -T 3" "" 1
  8892. #set -vx
  8893. eval testecho "\"$N\"" "\"$TEST\"" "\"\"" "pipe" "\"$opts -T $((2*SECONDs))\"" 1 $REDIR
  8894. #set +vx
  8895. fi # could determine FOPEN_MAX
  8896. fi ;; # NUMCOND
  8897. esac
  8898. N=$((N+1))
  8899. # there was a bug with udp-listen and fork: terminating sub processes became
  8900. # zombies because the master process did not catch SIGCHLD
  8901. NAME=UDP4LISTEN_SIGCHLD
  8902. case "$TESTS" in
  8903. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%zombie%*|*%signal%*|*%$NAME%*)
  8904. TEST="$NAME: test if UDP4-LISTEN child becomes zombie"
  8905. # idea: run a udp-listen process with fork and -T. Connect once, so a sub
  8906. # process is forked off. Make some transfer and wait until the -T timeout is
  8907. # over. Now check for the child process: if it is zombie the test failed.
  8908. # Correct is that child process terminated
  8909. if ! eval $NUMCOND; then :; else
  8910. tf="$td/test$N.stdout"
  8911. te="$td/test$N.stderr"
  8912. tdiff="$td/test$N.diff"
  8913. tsl=$PORT
  8914. ts="$LOCALHOST:$tsl"
  8915. da="test$N $(date) $RANDOM"
  8916. CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,$REUSEADDR,fork PIPE"
  8917. CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
  8918. printf "test $F_n $TEST... " $N
  8919. $CMD1 >"$tf" 2>"${te}1" &
  8920. pid1=$!
  8921. waitudp4port $tsl 1
  8922. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  8923. rc2=$?
  8924. sleep 1
  8925. #read -p ">"
  8926. l="$(childprocess $pid1)"
  8927. kill $pid1 2>/dev/null; wait
  8928. if [ $rc2 -ne 0 ]; then
  8929. $PRINTF "$NO_RESULT (client failed)\n" # already handled in test UDP4STREAM
  8930. numCANT=$((numCANT+1))
  8931. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8932. $PRINTF "$NO_RESULT (diff failed)\n" # already handled in test UDP4STREAM
  8933. numCANT=$((numCANT+1))
  8934. elif $(isdefunct "$l"); then
  8935. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8936. echo "$CMD1 &"
  8937. echo "$CMD2"
  8938. cat "${te}1" "${te}2"
  8939. numFAIL=$((numFAIL+1))
  8940. listFAIL="$listFAIL $N"
  8941. else
  8942. $PRINTF "$OK\n"
  8943. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  8944. numOK=$((numOK+1))
  8945. fi
  8946. fi ;; # NUMCOND
  8947. esac
  8948. PORT=$((PORT+1))
  8949. N=$((N+1))
  8950. #set +vx
  8951. # there was a bug with udp-recvfrom and fork: terminating sub processes became
  8952. # zombies because the master process caught SIGCHLD but did not wait()
  8953. NAME=UDP4RECVFROM_SIGCHLD
  8954. case "$TESTS" in
  8955. *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%zombie%*|*%signal%*|*%$NAME%*)
  8956. TEST="$NAME: test if UDP4-RECVFROM child becomes zombie"
  8957. # idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a
  8958. # sub process is forked off. Make some transfer and wait until the -T timeout
  8959. # is over. Now check for the child process: if it is zombie the test failed.
  8960. # Correct is that child process terminated
  8961. if ! eval $NUMCOND; then :; else
  8962. tf="$td/test$N.stdout"
  8963. te="$td/test$N.stderr"
  8964. tdiff="$td/test$N.diff"
  8965. tsl=$PORT
  8966. ts="$LOCALHOST:$tsl"
  8967. da="test$N $(date) $RANDOM"
  8968. CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE"
  8969. CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts"
  8970. printf "test $F_n $TEST... " $N
  8971. $CMD1 >"$tf" 2>"${te}1" &
  8972. pid1=$!
  8973. waitudp4port $tsl 1
  8974. echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
  8975. rc2=$?
  8976. sleep 1
  8977. #read -p ">"
  8978. l="$(childprocess $pid1)"
  8979. kill $pid1 2>/dev/null; wait
  8980. if [ $rc2 -ne 0 ]; then
  8981. $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
  8982. numCANT=$((numCANT+1))
  8983. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  8984. $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
  8985. numCANT=$((numCANT+1))
  8986. elif $(isdefunct "$l"); then
  8987. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  8988. echo "$CMD1 &"
  8989. echo "$CMD2"
  8990. cat "${te}1" "${te}2"
  8991. numFAIL=$((numFAIL+1))
  8992. listFAIL="$listFAIL $N"
  8993. else
  8994. $PRINTF "$OK\n"
  8995. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  8996. numOK=$((numOK+1))
  8997. fi
  8998. fi ;; # NUMCOND
  8999. esac
  9000. PORT=$((PORT+1))
  9001. N=$((N+1))
  9002. # test: there was a bug with ip*-recv and bind option: it would not bind, and
  9003. # with the first received packet an error:
  9004. # socket_init(): unknown address family 0
  9005. # occurred
  9006. NAME=RAWIP4RECVBIND
  9007. case "$TESTS" in
  9008. *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
  9009. TEST="$NAME: raw IPv4 receive with bind"
  9010. # idea: start a socat process with ip4-recv:...,bind=... and send it a packet
  9011. # if the packet passes the test succeeded
  9012. if ! eval $NUMCOND; then :;
  9013. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  9014. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  9015. numCANT=$((numCANT+1))
  9016. else
  9017. tf="$td/test$N.stdout"
  9018. te="$td/test$N.stderr"
  9019. tdiff="$td/test$N.diff"
  9020. ts1p=$PROTO; PROTO=$((PROTO+1))
  9021. ts1a="127.0.0.1"
  9022. ts1="$ts1a:$ts1p"
  9023. da="test$N $(date) $RANDOM"
  9024. CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -"
  9025. CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
  9026. printf "test $F_n $TEST... " $N
  9027. $CMD1 >"$tf" 2>"${te}1" &
  9028. pid1="$!"
  9029. waitip4proto $ts1p 1
  9030. echo "$da" |$CMD2 2>>"${te}2"
  9031. rc2="$?"
  9032. #ls -l $tf
  9033. i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  9034. kill "$pid1" 2>/dev/null; wait
  9035. if [ "$rc2" -ne 0 ]; then
  9036. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9037. echo "$CMD1 &"
  9038. echo "$CMD2"
  9039. cat "${te}1"
  9040. cat "${te}2"
  9041. numFAIL=$((numFAIL+1))
  9042. listFAIL="$listFAIL $N"
  9043. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9044. $PRINTF "$FAILED\n"
  9045. cat "$tdiff"
  9046. numFAIL=$((numFAIL+1))
  9047. listFAIL="$listFAIL $N"
  9048. else
  9049. $PRINTF "$OK\n"
  9050. if [ -n "$debug" ]; then cat $te; fi
  9051. numOK=$((numOK+1))
  9052. fi
  9053. fi ;; # NUMCOND, root
  9054. esac
  9055. PROTO=$((PROTO+1))
  9056. N=$((N+1))
  9057. # there was a bug in *-recvfrom with fork: due to an error in the appropriate
  9058. # signal handler the master process would hang after forking off the first
  9059. # child process.
  9060. NAME=UDP4RECVFROM_FORK
  9061. case "$TESTS" in
  9062. *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
  9063. TEST="$NAME: test if UDP4-RECVFROM handles more than one packet"
  9064. # idea: run a UDP4-RECVFROM process with fork and -T. Send it one packet;
  9065. # send it a second packet and check if this is processed properly. If yes, the
  9066. # test succeeded.
  9067. if ! eval $NUMCOND; then :; else
  9068. tf="$td/test$N.stdout"
  9069. te="$td/test$N.stderr"
  9070. tdiff="$td/test$N.diff"
  9071. tsp=$PORT
  9072. ts="$LOCALHOST:$tsp"
  9073. da="test$N $(date) $RANDOM"
  9074. CMD1="$TRACE $SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE"
  9075. CMD2="$TRACE $SOCAT $opts -T 1 - UDP4-SENDTO:$ts"
  9076. printf "test $F_n $TEST... " $N
  9077. $CMD1 >/dev/null 2>"${te}1" &
  9078. pid1=$!
  9079. waitudp4port $tsp 1
  9080. echo "$da" |$CMD2 >/dev/null 2>>"${te}2" # this should always work
  9081. rc2a=$?
  9082. sleep 1
  9083. echo "$da" |$CMD2 >"$tf" 2>>"${te}3" # this would fail when bug
  9084. rc2b=$?
  9085. kill $pid1 2>/dev/null; wait
  9086. if [ $rc2b -ne 0 ]; then
  9087. $PRINTF "$NO_RESULT\n"
  9088. numCANT=$((numCANT+1))
  9089. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9090. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9091. echo "$CMD1 &"
  9092. echo "$CMD2"
  9093. cat "${te}1" "${te}2" "${te}3"
  9094. cat "$tdiff"
  9095. numFAIL=$((numFAIL+1))
  9096. listFAIL="$listFAIL $N"
  9097. else
  9098. $PRINTF "$OK\n"
  9099. if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3"; fi
  9100. numOK=$((numOK+1))
  9101. fi
  9102. fi ;; # NUMCOND
  9103. esac
  9104. PORT=$((PORT+1))
  9105. N=$((N+1))
  9106. # there was a bug in parsing the arguments of exec: consecutive spaces resulted
  9107. # in additional empty arguments
  9108. NAME=EXECSPACES
  9109. case "$TESTS" in
  9110. *%$N%*|*%functions%*|*%exec%*|*%parse%*|*%$NAME%*)
  9111. TEST="$NAME: correctly parse exec with consecutive spaces"
  9112. if ! eval $NUMCOND; then :; else
  9113. $PRINTF "test $F_n $TEST... " $N
  9114. tf="$td/test$N.stdout"
  9115. te="$td/test$N.stderr"
  9116. da="test$N $(date) $RANDOM" # with a double space
  9117. tdiff="$td/test$N.diff"
  9118. # put the test data as first argument after two spaces. expect the data in the
  9119. # first argument of the exec'd command.
  9120. $TRACE $SOCAT $opts -u "exec:\"bash -c \\\"echo \\\\\\\"\$1\\\\\\\"\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te"
  9121. rc=$?
  9122. echo "$da" |diff - "$tf" >"$tdiff"
  9123. if [ "$rc" -ne 0 ]; then
  9124. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9125. cat "$te"
  9126. numFAIL=$((numFAIL+1))
  9127. listFAIL="$listFAIL $N"
  9128. elif [ -s "$tdiff" ]; then
  9129. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9130. echo diff:
  9131. cat "$tdiff"
  9132. if [ -n "$debug" ]; then cat $te; fi
  9133. numFAIL=$((numFAIL+1))
  9134. listFAIL="$listFAIL $N"
  9135. else
  9136. $PRINTF "$OK\n"
  9137. if [ -n "$debug" ]; then cat $te; fi
  9138. numOK=$((numOK+1))
  9139. fi
  9140. fi ;; # NUMCOND
  9141. esac
  9142. N=$((N+1))
  9143. # a bug was found in the way UDP-LISTEN handles the listening socket:
  9144. # when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
  9145. # range option, the old listen socket would not be closed but a new one created.
  9146. NAME=UDP4LISTENCONT
  9147. case "$TESTS" in
  9148. *%$N%*|*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*)
  9149. TEST="$NAME: let range drop a packet and see if old socket is closed"
  9150. # idea: run a UDP4-LISTEN process with range option. Send it one packet from an
  9151. # address outside range and check if two listening sockets are open then
  9152. if ! eval $NUMCOND; then :; else
  9153. tf="$td/test$N.stdout"
  9154. te="$td/test$N.stderr"
  9155. tdiff="$td/test$N.diff"
  9156. if [ "$SS" ]; then
  9157. while [ "$($SS -anu |grep "127\.0\.0\.1:$PORT\>" |wc -l)" -ne 0 ]; do
  9158. PORT=$((PORT+1))
  9159. done
  9160. else
  9161. while [ "$(netstat -an |grep "^udp.*127\.0\.0\.1:$PORT\>" |wc -l)" -ne 0 ]; do
  9162. PORT=$((PORT+1))
  9163. done
  9164. fi
  9165. tp=$PORT
  9166. da1="test$N $(date) $RANDOM"
  9167. a1="$LOCALHOST"
  9168. a2="$SECONDADDR"
  9169. #CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
  9170. CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,$REUSEADDR,range=$a2/32 PIPE"
  9171. CMD1="$TRACE $SOCAT $opts - UDP-CONNECT:$a1:$tp"
  9172. printf "test $F_n $TEST... " $N
  9173. $CMD0 >/dev/null 2>"${te}0" &
  9174. pid1=$!
  9175. waitudp4port $tp 1
  9176. echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail
  9177. rc1=$?
  9178. waitudp4port $tp 1
  9179. if [ "$SS" ]; then
  9180. nsocks="$($SS -anu |grep ":$PORT\>" |wc -l)"
  9181. else
  9182. nsocks="$(netstat -an |grep "^udp.*[:.]$PORT\>" |wc -l)"
  9183. fi
  9184. kill $pid1 2>/dev/null; wait
  9185. if [ $rc1 -ne 0 ]; then
  9186. $PRINTF "$NO_RESULT\n"
  9187. numCANT=$((numCANT+1))
  9188. elif [ $nsocks -eq 0 ]; then
  9189. $PRINTF "$NO_RESULT\n"
  9190. numCANT=$((numCANT+1))
  9191. elif [ $nsocks -ne 1 ]; then
  9192. $PRINTF "$FAILED ($nsocks listening sockets)\n"
  9193. echo "$CMD0 &"
  9194. echo "$CMD1"
  9195. cat "${te}0" "${te}1"
  9196. numFAIL=$((numFAIL+1))
  9197. listFAIL="$listFAIL $N"
  9198. else
  9199. $PRINTF "$OK\n"
  9200. if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
  9201. numOK=$((numOK+1))
  9202. fi
  9203. fi ;; # NUMCOND
  9204. esac
  9205. PORT=$((PORT+1))
  9206. N=$((N+1))
  9207. # during wait for next poll time option ignoreeof blocked the data transfer in
  9208. # the reverse direction
  9209. NAME=IGNOREEOFNOBLOCK
  9210. case "$TESTS" in
  9211. *%$N%*|*%functions%*|*%engine%*|*%socket%*|*%ignoreeof%*|*%$NAME%*)
  9212. TEST="$NAME: ignoreeof does not block other direction"
  9213. # have socat poll in ignoreeof mode. while it waits one second for next check,
  9214. # we send data in the reverse direction and then the total timeout fires.
  9215. # it the data has passed, the test succeeded.
  9216. if ! eval $NUMCOND; then :; else
  9217. tf="$td/test$N.stout"
  9218. te="$td/test$N.stderr"
  9219. tdiff="$td/test$N.diff"
  9220. da="test$N $(date) $RANDOM"
  9221. CMD0="$TRACE $SOCAT $opts /dev/null,ignoreeof!!- -!!/dev/null"
  9222. printf "test $F_n $TEST... " $N
  9223. (usleep 333333; echo "$da") |$CMD0 >"$tf" 2>"${te}0"
  9224. rc0=$?
  9225. if [ $rc0 != 0 ]; then
  9226. $PRINTF "$FAILED\n"
  9227. echo "$CMD0 &"
  9228. echo "$CMD1"
  9229. cat "${te}0"
  9230. cat "${te}1"
  9231. numFAIL=$((numFAIL+1))
  9232. listFAIL="$listFAIL $N"
  9233. elif echo "$da" |diff - "$tf" >/dev/null; then
  9234. $PRINTF "$OK\n"
  9235. numOK=$((numOK+1))
  9236. else
  9237. $PRINTF "$FAILED\n"
  9238. echo "$CMD0 &"
  9239. echo "$CMD1"
  9240. cat "${te}0"
  9241. numFAIL=$((numFAIL+1))
  9242. listFAIL="$listFAIL $N"
  9243. fi
  9244. fi ;; # NUMCOND
  9245. esac
  9246. N=$((N+1))
  9247. # test the escape option
  9248. NAME=ESCAPE
  9249. case "$TESTS" in
  9250. *%$N%*|*%functions%*|*%engine%*|*%escape%*|*%$NAME%*)
  9251. TEST="$NAME: escape character triggers EOF"
  9252. # idea: start socat just echoing input, but apply escape option. send a string
  9253. # containing the escape character and check if the output is truncated
  9254. if ! eval $NUMCOND; then :; else
  9255. tf="$td/test$N.stdout"
  9256. te="$td/test$N.stderr"
  9257. tdiff="$td/test$N.diff"
  9258. da="test$N $(date) $RANDOM"
  9259. CMD="$TRACE $SOCAT $opts -,escape=27 pipe"
  9260. printf "test $F_n $TEST... " $N
  9261. $ECHO "$da\n\x1bXYZ" |$CMD >"$tf" 2>"$te"
  9262. if [ $? -ne 0 ]; then
  9263. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9264. echo "$CMD"
  9265. cat "$te"
  9266. numFAIL=$((numFAIL+1))
  9267. listFAIL="$listFAIL $N"
  9268. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9269. $PRINTF "$FAILED: diff:\n"
  9270. cat "$tdiff"
  9271. numFAIL=$((numFAIL+1))
  9272. listFAIL="$listFAIL $N"
  9273. else
  9274. $PRINTF "$OK\n"
  9275. if [ -n "$debug" ]; then cat $te; fi
  9276. numOK=$((numOK+1))
  9277. fi
  9278. fi ;; # NUMCOND
  9279. esac
  9280. N=$((N+1))
  9281. # test the escape option combined with ignoreeof
  9282. NAME=ESCAPE_IGNOREEOF
  9283. case "$TESTS" in
  9284. *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%escape%*|*%$NAME%*)
  9285. TEST="$NAME: escape character triggers EOF"
  9286. # idea: start socat just echoing input, but apply escape option. send a string
  9287. # containing the escape character and check if the output is truncated
  9288. if ! eval $NUMCOND; then :; else
  9289. ti="$td/test$N.file"
  9290. tf="$td/test$N.stdout"
  9291. te="$td/test$N.stderr"
  9292. tdiff="$td/test$N.diff"
  9293. da="test$N $(date) $RANDOM"
  9294. CMD="$TRACE $SOCAT -T 5 $opts file:$ti,ignoreeof,escape=27!!- pipe"
  9295. printf "test $F_n $TEST... " $N
  9296. >"$ti"
  9297. $CMD >"$tf" 2>"$te" &
  9298. $ECHO "$da\n\x1bXYZ" >>"$ti"
  9299. sleep 1
  9300. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9301. $PRINTF "$FAILED: diff:\n"
  9302. cat "$tdiff"
  9303. cat "$te"
  9304. numFAIL=$((numFAIL+1))
  9305. listFAIL="$listFAIL $N"
  9306. else
  9307. $PRINTF "$OK\n"
  9308. if [ -n "$debug" ]; then cat $te; fi
  9309. numOK=$((numOK+1))
  9310. fi
  9311. fi ;; # NUMCOND
  9312. esac
  9313. N=$((N+1))
  9314. # test: logging of ancillary message
  9315. while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_TYPE SCM_NAME ROOT SCM_VALUE
  9316. do
  9317. if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
  9318. #
  9319. pf="$(echo "$PF" |tr A-Z a-z)"
  9320. proto="$(echo "$KEYW" |tr A-Z a-z)"
  9321. NAME=${KEYW}SCM_$SCM_TYPE
  9322. case "$TESTS" in
  9323. *%$N%*|*%functions%*|*%socket%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%$ROOT%*|*%$NAME%*)
  9324. TEST="$NAME: $KEYW log ancillary message $SCM_TYPE $SCM_NAME"
  9325. # idea: start a socat process with *-RECV:..,... , ev. with ancillary message
  9326. # enabling option and send it a packet, ev. with some option. check the info log
  9327. # for the appropriate output.
  9328. if ! eval $NUMCOND; then :;
  9329. #elif [[ "$PF" == "#*" ]]; then :
  9330. elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  9331. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  9332. numCANT=$((numCANT+1))
  9333. elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null ); then
  9334. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  9335. numCANT=$((numCANT+1))
  9336. elif ! testoptions $SCM_RECV >/dev/null; then
  9337. $PRINTF "test $F_n $TEST... ${YELLOW}option $SCM_RECV not available${NORMAL}\n" $N
  9338. numCANT=$((numCANT+1))
  9339. else
  9340. tf="$td/test$N.stdout"
  9341. te="$td/test$N.stderr"
  9342. case "X$IPPORT" in
  9343. "XPORT")
  9344. tra="$PORT" # test recv address
  9345. tsa="$ADDR:$PORT" # test sendto address
  9346. PORT=$((PORT+1)) ;;
  9347. "XPROTO")
  9348. tra="$PROTO" # test recv address
  9349. tsa="$ADDR:$PROTO" # test sendto address
  9350. PROTO=$((PROTO+1)) ;;
  9351. *)
  9352. tra="$(eval echo "$ADDR")" # resolve $N
  9353. tsa="$tra"
  9354. esac
  9355. CMD0="$TRACE $SOCAT $opts -d -d -d -u $KEYW-RECV:$tra,reuseaddr,$SCM_RECV -"
  9356. CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
  9357. printf "test $F_n $TEST... " $N
  9358. # is this option supported?
  9359. if $TRACE $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
  9360. $CMD0 >"$tf" 2>"${te}0" &
  9361. pid0="$!"
  9362. wait${proto}port $tra 1
  9363. echo "XYZ" |$CMD1 2>"${te}1"
  9364. rc1="$?"
  9365. sleep 1
  9366. i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  9367. kill "$pid0" 2>/dev/null; wait
  9368. # do not show more messages than requested
  9369. case "$opts" in
  9370. *-d*-d*-d*-d*) LEVELS="[EWNID]" ;;
  9371. *-d*-d*-d*) LEVELS="[EWNI]" ;;
  9372. *-d*-d*) LEVELS="[EWN]" ;;
  9373. *-d*) LEVELS="[EW]" ;;
  9374. *) LEVELS="[E]" ;;
  9375. esac
  9376. if [ "$SCM_VALUE" = "timestamp" ]; then
  9377. SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
  9378. fi
  9379. if [ "$rc1" -ne 0 ]; then
  9380. $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
  9381. echo "$CMD0 &"
  9382. echo "$CMD1"
  9383. grep " $LEVELS " "${te}0"
  9384. grep " $LEVELS " "${te}1"
  9385. numCANT=$((numCANT+1))
  9386. elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=" ${te}0 >/dev/null; then
  9387. $PRINTF "$FAILED\n"
  9388. echo "variable $SCM_TYPE: $SCM_NAME not set"
  9389. echo "$CMD0 &"
  9390. echo "$CMD1"
  9391. grep " $LEVELS " "${te}0"
  9392. grep " $LEVELS " "${te}1"
  9393. numFAIL=$((numFAIL+1))
  9394. listFAIL="$listFAIL $N"
  9395. elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=$SCM_VALUE\$" ${te}0 >/dev/null; then
  9396. $PRINTF "$FAILED\n"
  9397. badval="$(grep "ancillary message: $SCM_TYPE: $SCM_NAME" ${te}0 |sed 's/.*=//g')"
  9398. echo "variable $SCM_TYPE: $SCM_NAME has value \"$badval\" instead of pattern \"$SCM_VALUE\"" >&2
  9399. echo "$CMD0 &"
  9400. echo "$CMD1"
  9401. grep " $LEVELS " "${te}0"
  9402. grep " $LEVELS " "${te}1"
  9403. numFAIL=$((numFAIL+1))
  9404. listFAIL="$listFAIL $N"
  9405. else
  9406. $PRINTF "$OK\n"
  9407. if [ -n "$debug" ]; then
  9408. grep " $LEVELS " "${te}0"; echo; grep " $LEVELS " "${te}1";
  9409. fi
  9410. numOK=$((numOK+1))
  9411. fi
  9412. else # option is not supported
  9413. $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
  9414. numCANT=$((numCANT+1))
  9415. fi # option is not supported
  9416. fi # NUMCOND, root, feats
  9417. ;;
  9418. esac
  9419. N=$((N+1))
  9420. #
  9421. done <<<"
  9422. IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS options user x01000000
  9423. IP4 UDP4 127.0.0.1 PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
  9424. IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL ttl user 53
  9425. IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS tos user 7
  9426. IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO locaddr user 127.0.0.1
  9427. IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO dstaddr user 127.0.0.1
  9428. IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO if user lo
  9429. IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_RECVIF if user lo0
  9430. IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_RECVDSTADDR dstaddr user 127.0.0.1
  9431. IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS options root x01000000
  9432. IP4 IP4 127.0.0.1 PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
  9433. IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL ttl root 53
  9434. IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS tos root 7
  9435. IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO locaddr root 127.0.0.1
  9436. IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO dstaddr root 127.0.0.1
  9437. IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO if root lo
  9438. IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_RECVIF if root lo0
  9439. IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_RECVDSTADDR dstaddr root 127.0.0.1
  9440. IP6 UDP6 [::1] PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
  9441. IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_PKTINFO dstaddr user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
  9442. IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit user 35
  9443. IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass user x000000aa
  9444. IP6 IP6 [::1] PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
  9445. IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_PKTINFO dstaddr root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
  9446. IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit root 35
  9447. IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass root x000000aa
  9448. #UNIX UNIX $td/test\$N.server - , so-timestamp SCM_TIMESTAMP timestamp user timestamp
  9449. "
  9450. # this one fails, appearently due to a Linux weakness:
  9451. # UNIX so-timestamp
  9452. # test: setting of environment variables that describe a stream socket
  9453. # connection: SOCAT_SOCKADDR, SOCAT_PEERADDR; and SOCAT_SOCKPORT,
  9454. # SOCAT_PEERPORT when applicable
  9455. while read KEYW FEAT TEST_SOCKADDR TEST_PEERADDR TEST_SOCKPORT TEST_PEERPORT; do
  9456. if [ -z "$KEYW" ] || [[ "$KEYW" == \#* ]]; then continue; fi
  9457. #
  9458. test_proto="$(echo "$KEYW" |tr A-Z a-z)"
  9459. NAME=${KEYW}LISTENENV
  9460. case "$TESTS" in
  9461. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$test_proto%*|*%envvar%*|*%$NAME%*)
  9462. TEST="$NAME: $KEYW-LISTEN sets environment variables with socket addresses"
  9463. # have a server accepting a connection and invoking some shell code. The shell
  9464. # code extracts and prints the SOCAT related environment vars.
  9465. # outside code then checks if the environment contains the variables correctly
  9466. # describing the peer and local sockets.
  9467. if ! eval $NUMCOND; then :;
  9468. elif ! feat=$(testaddrs $FEAT); then
  9469. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
  9470. numCANT=$((numCANT+1))
  9471. elif [ "$KEYW" = "TCP6" -o "$KEYW" = "UDP6" -o "$KEYW" = "SCTP6" ] && \
  9472. ! runsip6 >/dev/null; then
  9473. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  9474. numCANT=$((numCANT+1))
  9475. elif [ "$KEYW" = "SCTP4" ] && ! runssctp4 "$((PORT))" >/dev/null; then
  9476. $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
  9477. elif [ "$KEYW" = "SCTP6" ] && ! runssctp6 "$((PORT))" >/dev/null; then
  9478. #!!! branch not reached - caught above!
  9479. $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
  9480. else
  9481. tf="$td/test$N.stdout"
  9482. te="$td/test$N.stderr"
  9483. TEST_SOCKADDR="$(echo "$TEST_SOCKADDR" |sed "s/\$N/$N/g")" # actual vars
  9484. tsa="$TEST_SOCKADDR" # test server address
  9485. tsp="$TEST_SOCKPORT" # test server port
  9486. if [ "$tsp" != ',' ]; then
  9487. tsa1="$tsp"; tsa2="$tsa"; tsa="$tsa:$tsp" # tsa2 used for server bind=
  9488. else
  9489. tsa1="$tsa"; tsa2= # tsa1 used for addr parameter
  9490. fi
  9491. TEST_PEERADDR="$(echo "$TEST_PEERADDR" |sed "s/\$N/$N/g")" # actual vars
  9492. tca="$TEST_PEERADDR" # test client address
  9493. tcp="$TEST_PEERPORT" # test client port
  9494. if [ "$tcp" != ',' ]; then
  9495. tca="$tca:$tcp"
  9496. fi
  9497. #CMD0="$TRACE $SOCAT $opts -u $KEYW-LISTEN:$tsa1 SYSTEM:\"export -p\""
  9498. CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-LISTEN:$tsa1,$REUSEADDR SYSTEM:\"echo SOCAT_SOCKADDR=\\\$SOCAT_SOCKADDR; echo SOCAT_PEERADDR=\\\$SOCAT_PEERADDR; echo SOCAT_SOCKPORT=\\\$SOCAT_SOCKPORT; echo SOCAT_PEERPORT=\\\$SOCAT_PEERPORT; sleep 1\""
  9499. CMD1="$TRACE $SOCAT $opts -u - $KEYW-CONNECT:$tsa,bind=$tca"
  9500. printf "test $F_n $TEST... " $N
  9501. eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
  9502. pid0=$!
  9503. wait${test_proto}port $tsa1 1
  9504. echo |$CMD1 2>"${te}1"
  9505. rc1=$?
  9506. waitfile "$tf" 2
  9507. kill $pid0 2>/dev/null; wait
  9508. #set -vx
  9509. if [ $rc1 != 0 ]; then
  9510. $PRINTF "$NO_RESULT (client failed):\n"
  9511. echo "$CMD0 &"
  9512. cat "${te}0"
  9513. echo "$CMD1"
  9514. cat "${te}1"
  9515. numCANT=$((numCANT+1))
  9516. elif [ "$(grep SOCAT_SOCKADDR "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")" = "$TEST_SOCKADDR" -a \
  9517. "$(grep SOCAT_PEERADDR "${tf}" |sed -e 's/^[^=]*=//' -e "s/[\"']//g")" = "$TEST_PEERADDR" -a \
  9518. \( "$TEST_SOCKPORT" = ',' -o "$(grep SOCAT_SOCKPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tsp" \) -a \
  9519. \( "$TEST_PEERPORT" = ',' -o "$(grep SOCAT_PEERPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tcp" \) \
  9520. ]; then
  9521. $PRINTF "$OK\n"
  9522. if [ "$debug" ]; then
  9523. echo "$CMD0 &"
  9524. cat "${te}0"
  9525. echo "$CMD1"
  9526. cat "${te}1"
  9527. fi
  9528. numOK=$((numOK+1))
  9529. else
  9530. $PRINTF "$FAILED\n"
  9531. echo "$CMD0 &"
  9532. cat "${te}0"
  9533. echo "$CMD1"
  9534. cat "${te}1"
  9535. echo -e "SOCAT_SOCKADDR=$TEST_SOCKADDR\nSOCAT_PEERADDR=$TEST_PEERADDR\nSOCAT_SOCKPORT=$TEST_SOCKPORT\nSOCAT_PEERPORT=$TEST_PEERPORT" |
  9536. diff - "${tf}"
  9537. numFAIL=$((numFAIL+1))
  9538. listFAIL="$listFAIL $N"
  9539. fi
  9540. fi # NUMCOND, feats
  9541. ;;
  9542. esac
  9543. N=$((N+1))
  9544. #set +xv
  9545. #
  9546. done <<<"
  9547. TCP4 TCP 127.0.0.1 $SECONDADDR $PORT $((PORT+1))
  9548. TCP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+2)) $((PORT+3))
  9549. UDP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+6)) $((PORT+7))
  9550. SCTP4 SCTP 127.0.0.1 $SECONDADDR $((PORT+8)) $((PORT+9))
  9551. SCTP6 SCTP [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+10)) $((PORT+11))
  9552. UNIX UNIX $td/test\$N.server $td/test\$N.client , ,
  9553. "
  9554. # this one fails due to weakness in socats UDP4-LISTEN implementation:
  9555. #UDP4 $LOCALHOST $SECONDADDR $((PORT+4)) $((PORT+5))
  9556. # test: environment variables from ancillary message
  9557. while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_ENVNAME ROOT SCM_VALUE
  9558. do
  9559. if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
  9560. #
  9561. pf="$(echo "$PF" |tr A-Z a-z)"
  9562. proto="$(echo "$KEYW" |tr A-Z a-z)"
  9563. NAME=${KEYW}ENV_$SCM_ENVNAME
  9564. case "$TESTS" in
  9565. *%$N%*|*%functions%*|*%socket%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%envvar%*|*%$ROOT%*|*%$NAME%*)
  9566. #set -vx
  9567. TEST="$NAME: $KEYW ancillary message sets env SOCAT_$SCM_ENVNAME"
  9568. # idea: start a socat process with *-RECVFROM:..,... , ev. with ancillary
  9569. # message enabling option and send it a packet, ev. with some option. write
  9570. # the resulting environment to a file and check its contents for the
  9571. # appropriate variable.
  9572. if ! eval $NUMCOND; then :;
  9573. elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  9574. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  9575. numCANT=$((numCANT+1))
  9576. elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 ) >/dev/null; then
  9577. $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
  9578. numCANT=$((numCANT+1))
  9579. else
  9580. tf="$td/test$N.stdout"
  9581. te="$td/test$N.stderr"
  9582. case "X$IPPORT" in
  9583. "XPORT")
  9584. tra="$PORT" # test recv address
  9585. tsa="$ADDR:$PORT" # test sendto address
  9586. PORT=$((PORT+1)) ;;
  9587. "XPROTO")
  9588. tra="$PROTO" # test recv address
  9589. tsa="$ADDR:$PROTO" # test sendto address
  9590. PROTO=$((PROTO+1)) ;;
  9591. *)
  9592. tra="$(eval echo "$ADDR")" # resolve $N
  9593. tsa="$tra"
  9594. esac
  9595. #CMD0="$TRACE $SOCAT $opts -u $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"export -p\""
  9596. CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"echo \\\$SOCAT_$SCM_ENVNAME\""
  9597. CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
  9598. printf "test $F_n $TEST... " $N
  9599. # is this option supported?
  9600. if $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
  9601. eval "$CMD0 >\"$tf\" 2>\"${te}0\" &"
  9602. pid0="$!"
  9603. wait${proto}port $tra 1
  9604. echo "XYZ" |$CMD1 2>"${te}1"
  9605. rc1="$?"
  9606. waitfile "$tf" 2
  9607. #i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
  9608. kill "$pid0" 2>/dev/null; wait
  9609. # do not show more messages than requested
  9610. if [ "$SCM_VALUE" = "timestamp" ]; then
  9611. SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
  9612. fi
  9613. if [ "$rc1" -ne 0 ]; then
  9614. $PRINTF "$NO_RESULT: $SOCAT:\n"
  9615. echo "$CMD0 &"
  9616. echo "$CMD1"
  9617. cat "${te}0"
  9618. cat "${te}1"
  9619. numCANT=$((numCANT+1))
  9620. #elif ! egrep "^export SOCAT_$SCM_ENVNAME=[\"']?$SCM_VALUE[\"']?\$" ${tf} >/dev/null; then
  9621. #elif ! eval echo "$TRACE $SOCAT_\$SCM_VALUE" |diff - "${tf}" >/dev/null; then
  9622. elif ! expr "$(cat "$tf")" : "$(eval echo "\$SCM_VALUE")\$" >/dev/null; then
  9623. $PRINTF "$FAILED\n"
  9624. echo "logged value \"$(cat "$tf")\" instead of \"$(eval echo "\$SCM_VALUE")\""
  9625. echo "$CMD0 &"
  9626. echo "$CMD1"
  9627. cat "${te}0"
  9628. cat "${te}1"
  9629. numFAIL=$((numFAIL+1))
  9630. listFAIL="$listFAIL $N"
  9631. else
  9632. $PRINTF "$OK\n"
  9633. if [ -n "$debug" ]; then
  9634. cat "${te}0"; echo; cat "${te}1";
  9635. fi
  9636. numOK=$((numOK+1))
  9637. fi
  9638. else # option is not supported
  9639. $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
  9640. numCANT=$((numCANT+1))
  9641. fi # option is not supported
  9642. fi ;; # NUMCOND, feats
  9643. esac
  9644. N=$((N+1))
  9645. #
  9646. done <<<"
  9647. IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS user x01000000
  9648. IP4 UDP4 127.0.0.1 PORT , so-timestamp TIMESTAMP user timestamp
  9649. IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL user 53
  9650. IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS user 7
  9651. IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_LOCADDR user 127.0.0.1
  9652. IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_DSTADDR user 127.0.0.1
  9653. IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_IF user lo
  9654. IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_IF user lo0
  9655. IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_DSTADDR user 127.0.0.1
  9656. IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS root x01000000
  9657. IP4 IP4 127.0.0.1 PROTO , so-timestamp TIMESTAMP root timestamp
  9658. IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL root 53
  9659. IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS root 7
  9660. IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_LOCADDR root 127.0.0.1
  9661. IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_DSTADDR root 127.0.0.1
  9662. IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_IF root lo
  9663. IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_IF root lo0
  9664. IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_DSTADDR root 127.0.0.1
  9665. IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_DSTADDR user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
  9666. IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT user 35
  9667. IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS user x000000aa
  9668. IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_DSTADDR root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
  9669. IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT root 35
  9670. IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS root x000000aa
  9671. #UNIX UNIX $td/test\$N.server - , so-timestamp TIMESTAMP user timestamp
  9672. "
  9673. # test the SOCKET-CONNECT address (against TCP4-LISTEN)
  9674. NAME=SOCKET_CONNECT_TCP4
  9675. case "$TESTS" in
  9676. *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
  9677. TEST="$NAME: socket connect with TCP/IPv4"
  9678. # start a TCP4-LISTEN process that echoes data, and send test data using
  9679. # SOCKET-CONNECT, selecting TCP/IPv4. The sent data should be returned.
  9680. if ! eval $NUMCOND; then :; else
  9681. tf="$td/test$N.stdout"
  9682. te="$td/test$N.stderr"
  9683. tdiff="$td/test$N.diff"
  9684. ts0p=$PORT; PORT=$((PORT+1))
  9685. ts0a="127.0.0.1"
  9686. ts1p=$(printf "%04x" $ts0p);
  9687. ts1a="7f000001" # "127.0.0.1"
  9688. ts1="x${ts1p}${ts1a}x0000000000000000"
  9689. ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
  9690. da="test$N $(date) $RANDOM"
  9691. CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
  9692. CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:2:6:$ts1,bind=x${ts1b}00000000x0000000000000000"
  9693. printf "test $F_n $TEST... " $N
  9694. $CMD0 2>"${te}0" &
  9695. pid0="$!"
  9696. waittcp4port $ts0p 1
  9697. echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
  9698. rc1="$?"
  9699. kill "$pid0" 2>/dev/null; wait;
  9700. if [ "$rc1" -ne 0 ]; then
  9701. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9702. echo "$CMD0 &"
  9703. cat "${te}0"
  9704. echo "$CMD1"
  9705. cat "${te}1"
  9706. numFAIL=$((numFAIL+1))
  9707. listFAIL="$listFAIL $N"
  9708. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9709. $PRINTF "$FAILED\n"
  9710. cat "$tdiff"
  9711. echo "$CMD0 &"
  9712. cat "${te}0"
  9713. echo "$CMD1"
  9714. cat "${te}1"
  9715. numFAIL=$((numFAIL+1))
  9716. listFAIL="$listFAIL $N"
  9717. else
  9718. $PRINTF "$OK\n"
  9719. if [ -n "$debug" ]; then cat $te; fi
  9720. numOK=$((numOK+1))
  9721. fi
  9722. fi # NUMCOND
  9723. ;;
  9724. esac
  9725. PORT=$((PORT+1))
  9726. N=$((N+1))
  9727. PF_INET6="$($PROCAN -c |grep "^#define[[:space:]]*PF_INET6[[:space:]]" |cut -d' ' -f3)"
  9728. # test the SOCKET-CONNECT address (against TCP6-LISTEN)
  9729. NAME=SOCKET_CONNECT_TCP6
  9730. case "$TESTS" in
  9731. *%$N%*|*%functions%*|*%generic%*|*%tcp6%*|*%socket%*|*%$NAME%*)
  9732. TEST="$NAME: socket connect with TCP/IPv6"
  9733. if ! eval $NUMCOND; then :;
  9734. elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
  9735. $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
  9736. numCANT=$((numCANT+1))
  9737. else
  9738. # start a TCP6-LISTEN process that echoes data, and send test data using
  9739. # SOCKET-CONNECT, selecting TCP/IPv6. The sent data should be returned.
  9740. tf="$td/test$N.stdout"
  9741. te="$td/test$N.stderr"
  9742. tdiff="$td/test$N.diff"
  9743. ts0p=$PORT; PORT=$((PORT+1))
  9744. ts0a="[::1]"
  9745. ts1p=$(printf "%04x" $ts0p);
  9746. ts1a="00000000000000000000000000000001" # "[::1]"
  9747. ts1="x${ts1p}x00000000x${ts1a}x00000000"
  9748. ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
  9749. da="test$N $(date) $RANDOM"
  9750. CMD0="$TRACE $SOCAT $opts TCP6-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
  9751. CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:$PF_INET6:6:$ts1,bind=x${ts1b}x00000000x00000000000000000000000000000000x00000000"
  9752. printf "test $F_n $TEST... " $N
  9753. $CMD0 2>"${te}0" &
  9754. pid0="$!"
  9755. waittcp6port $ts0p 1
  9756. echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
  9757. rc1="$?"
  9758. kill "$pid0" 2>/dev/null; wait;
  9759. if [ "$rc1" -ne 0 ]; then
  9760. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9761. echo "$CMD0 &"
  9762. cat "${te}0"
  9763. echo "$CMD1"
  9764. cat "${te}1"
  9765. numFAIL=$((numFAIL+1))
  9766. listFAIL="$listFAIL $N"
  9767. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9768. $PRINTF "$FAILED\n"
  9769. cat "$tdiff"
  9770. echo "$CMD0 &"
  9771. cat "${te}0"
  9772. echo "$CMD1"
  9773. cat "${te}1"
  9774. numFAIL=$((numFAIL+1))
  9775. listFAIL="$listFAIL $N"
  9776. else
  9777. $PRINTF "$OK\n"
  9778. if [ -n "$debug" ]; then cat $te; fi
  9779. numOK=$((numOK+1))
  9780. fi
  9781. fi ;; # NUMCOND
  9782. esac
  9783. PORT=$((PORT+1))
  9784. N=$((N+1))
  9785. # test the SOCKET-CONNECT address (against UNIX-LISTEN)
  9786. NAME=SOCKET_CONNECT_UNIX
  9787. case "$TESTS" in
  9788. *%$N%*|*%functions%*|*%generic%*|*%unix%*|*%socket%*|*%$NAME%*)
  9789. TEST="$NAME: socket connect with UNIX domain"
  9790. # start a UNIX-LISTEN process that echoes data, and send test data using
  9791. # SOCKET-CONNECT, selecting UNIX socket. The sent data should be returned.
  9792. if ! eval $NUMCOND; then :; else
  9793. tf="$td/test$N.stdout"
  9794. te="$td/test$N.stderr"
  9795. tdiff="$td/test$N.diff"
  9796. ts0="$td/test$N.server"
  9797. ts1="$td/test$N.client"
  9798. da="test$N $(date) $RANDOM"
  9799. CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts0,$REUSEADDR PIPE"
  9800. CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:1:0:\\\"$ts0\\\0\\\",bind=\\\"$ts1\\\0\\\""
  9801. printf "test $F_n $TEST... " $N
  9802. $CMD0 2>"${te}0" &
  9803. pid0="$!"
  9804. waitfile $ts0 1
  9805. echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
  9806. rc1="$?"
  9807. kill "$pid0" 2>/dev/null; wait;
  9808. if [ "$rc1" -ne 0 ]; then
  9809. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9810. echo "$CMD0 &"
  9811. cat "${te}0"
  9812. echo "$CMD1"
  9813. cat "${te}1"
  9814. numFAIL=$((numFAIL+1))
  9815. listFAIL="$listFAIL $N"
  9816. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9817. $PRINTF "$FAILED\n"
  9818. cat "$tdiff"
  9819. echo "$CMD0 &"
  9820. cat "${te}0"
  9821. echo "$CMD1"
  9822. cat "${te}1"
  9823. numFAIL=$((numFAIL+1))
  9824. listFAIL="$listFAIL $N"
  9825. else
  9826. $PRINTF "$OK\n"
  9827. if [ -n "$debug" ]; then cat $te; fi
  9828. numOK=$((numOK+1))
  9829. fi
  9830. fi ;; # NUMCOND
  9831. esac
  9832. N=$((N+1))
  9833. # test the SOCKET-LISTEN address (with TCP4-CONNECT)
  9834. NAME=SOCKET_LISTEN
  9835. case "$TESTS" in
  9836. *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
  9837. TEST="$NAME: socket recvfrom with TCP/IPv4"
  9838. # start a SOCKET-LISTEN process that uses TCP/IPv4 and echoes data, and
  9839. # send test data using TCP4-CONNECT. The sent data should be returned.
  9840. if ! eval $NUMCOND; then :; else
  9841. tf="$td/test$N.stdout"
  9842. te="$td/test$N.stderr"
  9843. tdiff="$td/test$N.diff"
  9844. ts1p=$PORT; PORT=$((PORT+1))
  9845. ts1a="127.0.0.1"
  9846. ts0p=$(printf "%04x" $ts1p);
  9847. ts0a="7f000001" # "127.0.0.1"
  9848. ts0="x${ts0p}${ts0a}x0000000000000000"
  9849. ts1b=$PORT; PORT=$((PORT+1))
  9850. ts1="$ts1a:$ts1p"
  9851. da="test$N $(date) $RANDOM"
  9852. CMD0="$TRACE $SOCAT $opts SOCKET-LISTEN:2:6:$ts0,$REUSEADDR PIPE"
  9853. CMD1="$TRACE $SOCAT $opts - TCP4-CONNECT:$ts1,bind=:$ts1b"
  9854. printf "test $F_n $TEST... " $N
  9855. $CMD0 2>"${te}0" &
  9856. pid0="$!"
  9857. #sleep 1
  9858. waittcp4port $ts1p 1
  9859. echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
  9860. rc1="$?"
  9861. kill "$pid0" 2>/dev/null; wait;
  9862. if [ "$rc1" -ne 0 ]; then
  9863. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9864. echo "$CMD0 &"
  9865. cat "${te}0"
  9866. echo "$CMD1"
  9867. cat "${te}1"
  9868. numFAIL=$((numFAIL+1))
  9869. listFAIL="$listFAIL $N"
  9870. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9871. $PRINTF "$FAILED\n"
  9872. cat "$tdiff"
  9873. echo "$CMD0 &"
  9874. cat "${te}0"
  9875. echo "$CMD1"
  9876. cat "${te}1"
  9877. numFAIL=$((numFAIL+1))
  9878. listFAIL="$listFAIL $N"
  9879. else
  9880. $PRINTF "$OK\n"
  9881. if [ -n "$debug" ]; then cat $te; fi
  9882. numOK=$((numOK+1))
  9883. fi
  9884. fi ;; # NUMCOND
  9885. esac
  9886. PORT=$((PORT+1))
  9887. N=$((N+1))
  9888. SOCK_DGRAM="$($PROCAN -c |grep "^#define[[:space:]]*SOCK_DGRAM[[:space:]]" |cut -d' ' -f3)"
  9889. # test the SOCKET-SENDTO address (against UDP4-RECVFROM)
  9890. NAME=SOCKET_SENDTO
  9891. case "$TESTS" in
  9892. *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
  9893. TEST="$NAME: socket sendto with UDP/IPv4"
  9894. # start a UDP4-RECVFROM process that echoes data, and send test data using
  9895. # SOCKET-SENDTO, selecting UDP/IPv4. The sent data should be returned.
  9896. if ! eval $NUMCOND; then :; else
  9897. tf="$td/test$N.stdout"
  9898. te="$td/test$N.stderr"
  9899. tdiff="$td/test$N.diff"
  9900. ts0p=$PORT; PORT=$((PORT+1))
  9901. ts0a="127.0.0.1"
  9902. ts1p=$(printf "%04x" $ts0p);
  9903. ts1a="7f000001" # "127.0.0.1"
  9904. ts1="x${ts1p}${ts1a}x0000000000000000"
  9905. ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
  9906. da="test$N $(date) $RANDOM"
  9907. CMD0="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts0p,reuseaddr,bind=$ts0a PIPE"
  9908. CMD1="$TRACE $SOCAT $opts - SOCKET-SENDTO:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
  9909. printf "test $F_n $TEST... " $N
  9910. $CMD0 2>"${te}0" &
  9911. pid0="$!"
  9912. waitudp4port $ts0p 1
  9913. echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
  9914. rc1="$?"
  9915. kill "$pid0" 2>/dev/null; wait;
  9916. if [ "$rc1" -ne 0 ]; then
  9917. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9918. echo "$CMD0 &"
  9919. cat "${te}0"
  9920. echo "$CMD1"
  9921. cat "${te}1"
  9922. numFAIL=$((numFAIL+1))
  9923. listFAIL="$listFAIL $N"
  9924. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9925. $PRINTF "$FAILED\n"
  9926. cat "$tdiff"
  9927. echo "$CMD0 &"
  9928. cat "${te}0"
  9929. echo "$CMD1"
  9930. cat "${te}1"
  9931. numFAIL=$((numFAIL+1))
  9932. listFAIL="$listFAIL $N"
  9933. else
  9934. $PRINTF "$OK\n"
  9935. if [ -n "$debug" ]; then cat $te; fi
  9936. numOK=$((numOK+1))
  9937. fi
  9938. fi ;; # NUMCOND
  9939. esac
  9940. PORT=$((PORT+1))
  9941. N=$((N+1))
  9942. # test the SOCKET-RECVFROM address (with UDP4-SENDTO)
  9943. NAME=SOCKET_RECVFROM
  9944. case "$TESTS" in
  9945. *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
  9946. TEST="$NAME: socket recvfrom with UDP/IPv4"
  9947. # start a SOCKET-RECVFROM process that uses UDP/IPv4 and echoes data, and
  9948. # send test data using UDP4-SENDTO. The sent data should be returned.
  9949. if ! eval $NUMCOND; then :; else
  9950. tf="$td/test$N.stdout"
  9951. te="$td/test$N.stderr"
  9952. tdiff="$td/test$N.diff"
  9953. ts1p=$PORT; PORT=$((PORT+1))
  9954. ts1a="127.0.0.1"
  9955. ts0p=$(printf "%04x" $ts1p);
  9956. ts0a="7f000001" # "127.0.0.1"
  9957. ts0="x${ts0p}${ts0a}x0000000000000000"
  9958. ts1b=$PORT; PORT=$((PORT+1))
  9959. ts1="$ts1a:$ts1p"
  9960. da="test$N $(date) $RANDOM"
  9961. CMD0="$TRACE $SOCAT $opts SOCKET-RECVFROM:2:$SOCK_DGRAM:17:$ts0,reuseaddr PIPE"
  9962. CMD1="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=:$ts1b"
  9963. printf "test $F_n $TEST... " $N
  9964. $CMD0 2>"${te}0" &
  9965. pid0="$!"
  9966. sleep 1 # waitudp4port $ts1p 1
  9967. echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
  9968. rc1="$?"
  9969. kill "$pid0" 2>/dev/null; wait;
  9970. if [ "$rc1" -ne 0 ]; then
  9971. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  9972. echo "$CMD0 &"
  9973. cat "${te}0"
  9974. echo "$CMD1"
  9975. cat "${te}1"
  9976. numFAIL=$((numFAIL+1))
  9977. listFAIL="$listFAIL $N"
  9978. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  9979. $PRINTF "$FAILED\n"
  9980. cat "$tdiff"
  9981. echo "$CMD0 &"
  9982. cat "${te}0"
  9983. echo "$CMD1"
  9984. cat "${te}1"
  9985. numFAIL=$((numFAIL+1))
  9986. listFAIL="$listFAIL $N"
  9987. else
  9988. $PRINTF "$OK\n"
  9989. if [ -n "$debug" ]; then cat $te; fi
  9990. numOK=$((numOK+1))
  9991. fi
  9992. fi ;; # NUMCOND
  9993. esac
  9994. PORT=$((PORT+1))
  9995. N=$((N+1))
  9996. # test the SOCKET-RECV address (with UDP4-SENDTO)
  9997. NAME=SOCKET_RECV
  9998. case "$TESTS" in
  9999. *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
  10000. TEST="$NAME: socket recv with UDP/IPv4"
  10001. # start a SOCKET-RECV process that uses UPD/IPv4 and writes received data to file, and
  10002. # send test data using UDP4-SENDTO.
  10003. if ! eval $NUMCOND; then :; else
  10004. tf="$td/test$N.stdout"
  10005. te="$td/test$N.stderr"
  10006. tdiff="$td/test$N.diff"
  10007. ts1p=$PORT; PORT=$((PORT+1))
  10008. ts1a="127.0.0.1"
  10009. ts0p=$(printf "%04x" $ts1p);
  10010. ts0a="7f000001" # "127.0.0.1"
  10011. ts0="x${ts0p}${ts0a}x0000000000000000"
  10012. ts1b=$PORT; PORT=$((PORT+1))
  10013. ts1="$ts1a:$ts1p"
  10014. da="test$N $(date) $RANDOM"
  10015. CMD0="$TRACE $SOCAT $opts -u SOCKET-RECV:2:$SOCK_DGRAM:17:$ts0,reuseaddr -"
  10016. CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1,bind=:$ts1b"
  10017. printf "test $F_n $TEST... " $N
  10018. $CMD0 2>"${te}0" >"$tf" &
  10019. pid0="$!"
  10020. sleep 1 # waitudp4port $ts1p 1
  10021. echo "$da" |$CMD1 2>>"${te}1"
  10022. rc1="$?"
  10023. sleep 1
  10024. kill "$pid0" 2>/dev/null; wait;
  10025. if [ "$rc1" -ne 0 ]; then
  10026. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10027. echo "$CMD0 &"
  10028. cat "${te}0"
  10029. echo "$CMD1"
  10030. cat "${te}1"
  10031. numFAIL=$((numFAIL+1))
  10032. listFAIL="$listFAIL $N"
  10033. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  10034. $PRINTF "$FAILED\n"
  10035. cat "$tdiff"
  10036. echo "$CMD0 &"
  10037. cat "${te}0"
  10038. echo "$CMD1"
  10039. cat "${te}1"
  10040. numFAIL=$((numFAIL+1))
  10041. listFAIL="$listFAIL $N"
  10042. else
  10043. $PRINTF "$OK\n"
  10044. if [ -n "$debug" ]; then cat $te; fi
  10045. numOK=$((numOK+1))
  10046. fi
  10047. fi ;; # NUMCOND
  10048. esac
  10049. PORT=$((PORT+1))
  10050. N=$((N+1))
  10051. # test SOCKET-DATAGRAM (with UDP4-DATAGRAM)
  10052. NAME=SOCKET_DATAGRAM
  10053. case "$TESTS" in
  10054. *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
  10055. TEST="$NAME: socket datagram via UDP/IPv4"
  10056. # start a UDP4-DATAGRAM process that echoes data, and send test data using
  10057. # SOCKET-DATAGRAM, selecting UDP/IPv4. The sent data should be returned.
  10058. if ! eval $NUMCOND; then :; else
  10059. tf="$td/test$N.stdout"
  10060. te="$td/test$N.stderr"
  10061. tdiff="$td/test$N.diff"
  10062. ts0p=$PORT; PORT=$((PORT+1))
  10063. ts1p=$PORT; PORT=$((PORT+1))
  10064. ts0a="127.0.0.1"
  10065. ts1b=$(printf "%04x" $ts0p);
  10066. ts1a="7f000001" # "127.0.0.1"
  10067. ts0b=$(printf "%04x" $ts0p)
  10068. ts1b=$(printf "%04x" $ts1p)
  10069. ts1="x${ts0b}${ts1a}x0000000000000000"
  10070. da="test$N $(date) $RANDOM"
  10071. CMD0="$TRACE $SOCAT $opts UDP4-DATAGRAM:$ts0a:$ts1p,bind=:$ts0p,reuseaddr PIPE"
  10072. CMD1="$TRACE $SOCAT $opts - SOCKET-DATAGRAM:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
  10073. printf "test $F_n $TEST... " $N
  10074. $CMD0 2>"${te}0" &
  10075. pid0="$!"
  10076. waitudp4port $ts0p 1
  10077. echo "$da" |$CMD1 2>>"${te}1" >"$tf"
  10078. rc1="$?"
  10079. kill "$pid0" 2>/dev/null; wait;
  10080. if [ "$rc1" -ne 0 ]; then
  10081. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10082. echo "$CMD0 &"
  10083. cat "${te}0"
  10084. echo "$CMD1"
  10085. cat "${te}1"
  10086. numFAIL=$((numFAIL+1))
  10087. listFAIL="$listFAIL $N"
  10088. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  10089. $PRINTF "$FAILED\n"
  10090. cat "$tdiff"
  10091. echo "$CMD0 &"
  10092. cat "${te}0"
  10093. echo "$CMD1"
  10094. cat "${te}1"
  10095. numFAIL=$((numFAIL+1))
  10096. listFAIL="$listFAIL $N"
  10097. else
  10098. $PRINTF "$OK\n"
  10099. if [ -n "$debug" ]; then cat $te; fi
  10100. numOK=$((numOK+1))
  10101. fi
  10102. fi ;; # NUMCOND
  10103. esac
  10104. PORT=$((PORT+1))
  10105. N=$((N+1))
  10106. NAME=SOCKETRANGEMASK
  10107. case "$TESTS" in
  10108. *%$N%*|*%functions%*|*%security%*|*%generic%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%socket%*|*%range%*|*%$NAME%*)
  10109. TEST="$NAME: security of generic socket-listen with RANGE option"
  10110. if ! eval $NUMCOND; then :;
  10111. elif [ -z "$SECONDADDR" ]; then
  10112. # we need access to more loopback addresses
  10113. $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
  10114. numCANT=$((numCANT+1))
  10115. else
  10116. ts1p=$(printf "%04x" $PORT);
  10117. testserversec "$N" "$TEST" "$opts" "SOCKET-LISTEN:2:6:x${ts1p}x00000000x0000000000000000,$REUSEADDR,fork,retry=1" "" "range=x0000x7f000000:x0000xffffffff" "SOCKET-CONNECT:2:6:x${ts1p}x${SECONDADDRHEX}x0000000000000000" 4 tcp $PORT 0
  10118. fi ;; # NUMCOND, $SECONDADDR
  10119. esac
  10120. PORT=$((PORT+1))
  10121. N=$((N+1))
  10122. TIOCEXCL="$($PROCAN -c |grep "^#define[[:space:]]*TIOCEXCL[[:space:]]" |cut -d' ' -f3)"
  10123. # test the generic ioctl-void option
  10124. NAME=IOCTL_VOID
  10125. case "$TESTS" in
  10126. *%$N%*|*%functions%*|*%pty%*|*%generic%*|*%$NAME%*)
  10127. TEST="$NAME: test the ioctl-void option"
  10128. # there are not many ioctls that apply to non global resources and do not
  10129. # require root. TIOCEXCL seems to fit:
  10130. # process 0 provides a pty;
  10131. # process 1 opens it with the TIOCEXCL ioctl;
  10132. # process 2 opens it too and fails with "device or resource busy" only when the
  10133. # previous ioctl was successful
  10134. if ! eval $NUMCOND; then :;
  10135. elif [ -z "$TIOCEXCL" ]; then
  10136. # we use the numeric value of TIOCEXL which is system dependent
  10137. $PRINTF "test $F_n $TEST... ${YELLOW}no value of TIOCEXCL${NORMAL}\n" $N
  10138. numCANT=$((numCANT+1))
  10139. else
  10140. tp="$td/test$N.pty"
  10141. tf="$td/test$N.stdout"
  10142. te="$td/test$N.stderr"
  10143. tdiff="$td/test$N.diff"
  10144. da="test$N $(date) $RANDOM"
  10145. CMD0="$TRACE $SOCAT $opts PTY,LINK=$tp pipe"
  10146. CMD1="$TRACE $SOCAT $opts - file:$tp,ioctl-void=$TIOCEXCL,raw,echo=0"
  10147. CMD2="$TRACE $SOCAT $opts - file:$tp,raw,echo=0"
  10148. printf "test $F_n $TEST... " $N
  10149. $CMD0 >/dev/null 2>"${te}0" &
  10150. pid0=$!
  10151. waitfile $tp 1
  10152. (echo "$da"; sleep 2) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
  10153. pid1=$!
  10154. usleep 1000000
  10155. $CMD2 >/dev/null 2>"${te}2" </dev/null
  10156. rc2=$?
  10157. kill $pid0 $pid1 2>/dev/null; wait
  10158. if ! echo "$da" |diff - "$tf" >/dev/null; then
  10159. $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
  10160. echo "$CMD0 &"
  10161. echo "$CMD1"
  10162. echo "$da" |diff - "$tf"
  10163. numCANT=$((numCANT+1))
  10164. elif [ $rc2 -eq 0 ]; then
  10165. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10166. echo "$CMD0 &"
  10167. echo "$CMD1"
  10168. echo "$CMD2"
  10169. cat "${te}0" "${te}1" "${te}2"
  10170. numFAIL=$((numFAIL+1))
  10171. listFAIL="$listFAIL $N"
  10172. else
  10173. $PRINTF "$OK\n"
  10174. if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
  10175. numOK=$((numOK+1))
  10176. fi
  10177. fi # NUMCOND, TIOCEXCL
  10178. ;;
  10179. esac
  10180. N=$((N+1))
  10181. SOL_SOCKET="$($PROCAN -c |grep "^#define[[:space:]]*SOL_SOCKET[[:space:]]" |cut -d' ' -f3)"
  10182. SO_REUSEADDR="$($PROCAN -c |grep "^#define[[:space:]]*SO_REUSEADDR[[:space:]]" |cut -d' ' -f3)"
  10183. # test the generic setsockopt-int option
  10184. if false; then
  10185. # this test no longer works due to fix for options on listening sockets
  10186. NAME=SETSOCKOPT_INT
  10187. case "$TESTS" in
  10188. *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%generic%*|*%$NAME%*)
  10189. TEST="$NAME: test the setsockopt-int option"
  10190. # there are not many socket options that apply to non global resources, do not
  10191. # require root, do not require a network connection, and can easily be
  10192. # tested. SO_REUSEADDR seems to fit:
  10193. # process 0 provides a tcp listening socket with reuseaddr;
  10194. # process 1 connects to this port; thus the port is connected but no longer
  10195. # listening
  10196. # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
  10197. # (generically specified) SO_REUSEADDR socket options did not work
  10198. # process 3 connects to this port; only if it is successful the test is ok
  10199. if ! eval $NUMCOND; then :;
  10200. elif [ -z "$SO_REUSEADDR" ]; then
  10201. # we use the numeric value of SO_REUSEADDR which might be system dependent
  10202. $PRINTF "test $F_n $TEST... ${YELLOW}value of SO_REUSEADDR not known${NORMAL}\n" $N
  10203. numCANT=$((numCANT+1))
  10204. else
  10205. tp="$PORT"
  10206. tf="$td/test$N.stdout"
  10207. te="$td/test$N.stderr"
  10208. tdiff="$td/test$N.diff"
  10209. da="test$N $(date) $RANDOM"
  10210. CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,setsockopt-int=$SOL_SOCKET:$SO_REUSEADDR:1 PIPE"
  10211. CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
  10212. CMD2="$CMD0"
  10213. CMD3="$CMD1"
  10214. printf "test $F_n $TEST... " $N
  10215. $CMD0 >/dev/null 2>"${te}0" &
  10216. pid0=$!
  10217. waittcp4port $tp 1
  10218. (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
  10219. pid1=$!
  10220. usleep 1000000
  10221. $CMD2 >/dev/null 2>"${te}2" &
  10222. pid2=$!
  10223. waittcp4port $tp 1
  10224. (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
  10225. rc3=$?
  10226. kill $pid0 $pid1 $pid2 2>/dev/null; wait
  10227. if ! echo "$da" |diff - "$tf"; then
  10228. $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
  10229. echo "$CMD0 &"
  10230. echo "$CMD1"
  10231. numCANT=$((numCANT+1))
  10232. elif [ $rc3 -ne 0 ]; then
  10233. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10234. echo "$CMD0 &"
  10235. echo "$CMD1"
  10236. echo "$CMD2 &"
  10237. echo "$CMD3"
  10238. cat "${te}2" "${te}3"
  10239. numFAIL=$((numFAIL+1))
  10240. listFAIL="$listFAIL $N"
  10241. elif ! echo "$da" |diff - "${tf}3"; then
  10242. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10243. echo "$CMD0 &"
  10244. echo "$CMD1"
  10245. echo "$CMD2 &"
  10246. echo "$CMD3"
  10247. echo "$da" |diff - "${tf}3"
  10248. numCANT=$((numCANT+1))
  10249. else
  10250. $PRINTF "$OK\n"
  10251. if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
  10252. numOK=$((numOK+1))
  10253. fi
  10254. fi # NUMCOND, SO_REUSEADDR
  10255. ;;
  10256. esac
  10257. PORT=$((PORT+1))
  10258. N=$((N+1))
  10259. #
  10260. fi
  10261. NAME=SCTP4STREAM
  10262. case "$TESTS" in
  10263. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
  10264. TEST="$NAME: echo via connection to SCTP V4 socket"
  10265. PORT="$((PORT+1))"
  10266. if ! eval $NUMCOND; then :;
  10267. elif ! testaddrs sctp ip4 >/dev/null || ! runsip4 >/dev/null || ! runssctp4 "$((PORT-1))" >/dev/null; then
  10268. $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
  10269. numCANT=$((numCANT+1))
  10270. elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
  10271. # RHEL5 based systems became unusable when an sctp socket was created but
  10272. # module sctp not loaded
  10273. $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
  10274. numCANT=$((numCANT+1))
  10275. else
  10276. tf="$td/test$N.stdout"
  10277. te="$td/test$N.stderr"
  10278. tdiff="$td/test$N.diff"
  10279. tsl=$PORT
  10280. ts="127.0.0.1:$tsl"
  10281. da=$(date)
  10282. CMD1="$TRACE $SOCAT $opts SCTP4-LISTEN:$tsl,$REUSEADDR PIPE"
  10283. CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP4:$ts"
  10284. printf "test $F_n $TEST... " $N
  10285. $CMD1 >"$tf" 2>"${te}1" &
  10286. pid1=$!
  10287. waitsctp4port $tsl 1
  10288. # SCTP does not seem to support half close, so we give it 1s to finish
  10289. (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
  10290. if [ $? -ne 0 ]; then
  10291. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10292. echo "$CMD1 &"
  10293. cat "${te}1"
  10294. echo "$CMD2"
  10295. cat "${te}2"
  10296. numFAIL=$((numFAIL+1))
  10297. listFAIL="$listFAIL $N"
  10298. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  10299. $PRINTF "$FAILED\n"
  10300. cat "$tdiff"
  10301. numFAIL=$((numFAIL+1))
  10302. listFAIL="$listFAIL $N"
  10303. else
  10304. $PRINTF "$OK\n"
  10305. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  10306. numOK=$((numOK+1))
  10307. fi
  10308. kill $pid1 2>/dev/null
  10309. wait
  10310. fi # NUMCOND, feats
  10311. ;;
  10312. esac
  10313. PORT=$((PORT+1))
  10314. N=$((N+1))
  10315. NAME=SCTP6STREAM
  10316. case "$TESTS" in
  10317. *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
  10318. TEST="$NAME: echo via connection to SCTP V6 socket"
  10319. PORT="$((PORT+1))"
  10320. if ! eval $NUMCOND; then :;
  10321. elif ! testaddrs sctp ip6 >/dev/null || ! runsip6 >/dev/null || ! runssctp6 "$((PORT-1))" >/dev/null; then
  10322. $PRINTF "test $F_n $TEST... ${YELLOW}SCTP6 not available${NORMAL}\n" $N
  10323. numCANT=$((numCANT+1))
  10324. elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
  10325. $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
  10326. numCANT=$((numCANT+1))
  10327. else
  10328. tf="$td/test$N.stdout"
  10329. te="$td/test$N.stderr"
  10330. tdiff="$td/test$N.diff"
  10331. tsl=$PORT
  10332. ts="[::1]:$tsl"
  10333. da=$(date)
  10334. CMD1="$TRACE $SOCAT $opts SCTP6-listen:$tsl,$REUSEADDR PIPE"
  10335. CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP6:$ts"
  10336. printf "test $F_n $TEST... " $N
  10337. $CMD1 >"$tf" 2>"${te}1" &
  10338. pid=$! # background process id
  10339. waitsctp6port $tsl 1
  10340. # SCTP does not seem to support half close, so we let it 1s to finish
  10341. (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
  10342. if [ $? -ne 0 ]; then
  10343. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  10344. echo "$CMD1 &"
  10345. cat "${te}1"
  10346. echo "$CMD2"
  10347. cat "${te}2"
  10348. numFAIL=$((numFAIL+1))
  10349. listFAIL="$listFAIL $N"
  10350. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  10351. $PRINTF "$FAILED: diff:\n"
  10352. cat "$tdiff"
  10353. numFAIL=$((numFAIL+1))
  10354. listFAIL="$listFAIL $N"
  10355. else
  10356. $PRINTF "$OK\n"
  10357. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  10358. numOK=$((numOK+1))
  10359. fi
  10360. kill $pid 2>/dev/null
  10361. fi # NUMCOND, feats
  10362. ;;
  10363. esac
  10364. PORT=$((PORT+1))
  10365. N=$((N+1))
  10366. # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
  10367. # performed a renegotiation. Test if this is fixed.
  10368. NAME=OPENSSLRENEG1
  10369. case "$TESTS" in
  10370. *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
  10371. TEST="$NAME: OpenSSL connections survive renogotiation"
  10372. # connect with s_client to socat ssl-l; force a renog, then transfer data. When
  10373. # data is passed the test succeeded
  10374. if ! eval $NUMCOND; then :;
  10375. elif ! testaddrs openssl >/dev/null; then
  10376. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  10377. numCANT=$((numCANT+1))
  10378. elif ! type openssl >/dev/null 2>&1; then
  10379. $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
  10380. numCANT=$((numCANT+1))
  10381. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  10382. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  10383. numCANT=$((numCANT+1))
  10384. else
  10385. gentestcert testsrv
  10386. tf="$td/test$N.stdout"
  10387. te="$td/test$N.stderr"
  10388. tdiff="$td/test$N.diff"
  10389. da="test$N $(date) $RANDOM"
  10390. CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
  10391. #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
  10392. CMD1="openssl s_client -port $PORT"
  10393. printf "test $F_n $TEST... " $N
  10394. $CMD0 >/dev/null 2>"${te}0" &
  10395. pid0=$!
  10396. waittcp4port $PORT 1
  10397. (echo "R"; sleep 1; echo "$da"; sleep 1) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
  10398. rc1=$?
  10399. kill $pid0 2>/dev/null; wait
  10400. if echo "$da" |diff - ${tf}1 >"$tdiff"; then
  10401. $PRINTF "$OK\n"
  10402. numOK=$((numOK+1))
  10403. else
  10404. $PRINTF "$FAILED\n"
  10405. echo "$CMD0 &"
  10406. echo "$CMD1"
  10407. cat "${te}0"
  10408. # cat "${te}1"
  10409. cat "$tdiff"
  10410. numFAIL=$((numFAIL+1))
  10411. listFAIL="$listFAIL $N"
  10412. fi
  10413. fi # NUMCOND
  10414. ;;
  10415. esac
  10416. PORT=$((PORT+1))
  10417. N=$((N+1))
  10418. # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
  10419. # performed a renegotiation. The first temporary fix to this problem might
  10420. # leave socat in a blocking ssl-read state. Test if this has been fixed.
  10421. NAME=OPENSSLRENEG2
  10422. case "$TESTS" in
  10423. *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
  10424. TEST="$NAME: OpenSSL connections do not block after renogotiation"
  10425. # connect with s_client to socat ssl-l; force a renog, then transfer data from
  10426. # socat to the peer. When data is passed this means that the former ssl read no
  10427. # longer blocks and the test succeeds
  10428. if ! eval $NUMCOND; then :;
  10429. elif ! testaddrs openssl >/dev/null; then
  10430. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  10431. numCANT=$((numCANT+1))
  10432. elif ! type openssl >/dev/null 2>&1; then
  10433. $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
  10434. numCANT=$((numCANT+1))
  10435. elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  10436. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  10437. numCANT=$((numCANT+1))
  10438. else
  10439. gentestcert testsrv
  10440. tf="$td/test$N.stdout"
  10441. te="$td/test$N.stderr"
  10442. tdiff="$td/test$N.diff"
  10443. da="test$N $(date) $RANDOM"
  10444. CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
  10445. #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
  10446. CMD1="openssl s_client -port $PORT"
  10447. printf "test $F_n $TEST... " $N
  10448. eval "$CMD0 >/dev/null 2>\"${te}0\" &"
  10449. pid0=$!
  10450. waittcp4port $PORT 1
  10451. (echo "R"; sleep 2) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
  10452. rc1=$?
  10453. kill $pid0 2>/dev/null; wait
  10454. if echo "$da" |diff - ${tf}1 >"$tdiff"; then
  10455. $PRINTF "$OK\n"
  10456. numOK=$((numOK+1))
  10457. else
  10458. $PRINTF "$FAILED\n"
  10459. echo "$CMD0 &"
  10460. echo "$CMD1"
  10461. cat "${te}0"
  10462. # cat "${te}1"
  10463. cat "$tdiff"
  10464. numFAIL=$((numFAIL+1))
  10465. listFAIL="$listFAIL $N"
  10466. fi
  10467. fi # NUMCOND
  10468. ;;
  10469. esac
  10470. PORT=$((PORT+1))
  10471. N=$((N+1))
  10472. # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
  10473. # command line arguments (whole addresses, host names, file names) were longer
  10474. # than 512 bytes.
  10475. NAME=HOSTNAMEOVFL
  10476. case "$TESTS" in
  10477. *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
  10478. TEST="$NAME: stack overflow on overly long host name"
  10479. # provide a long host name to TCP-CONNECT and check socats exit code
  10480. if ! eval $NUMCOND; then :; else
  10481. tf="$td/test$N.stdout"
  10482. te="$td/test$N.stderr"
  10483. tdiff="$td/test$N.diff"
  10484. da="test$N $(date) $RANDOM"
  10485. # prepare long data - perl might not be installed
  10486. rm -f "$td/test$N.dat"
  10487. i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
  10488. CMD0="$TRACE $SOCAT $opts TCP-CONNECT:$(cat "$td/test$N.dat"):$PORT STDIO"
  10489. printf "test $F_n $TEST... " $N
  10490. $CMD0 </dev/null 1>&0 2>"${te}0"
  10491. rc0=$?
  10492. if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
  10493. $PRINTF "$OK\n"
  10494. numOK=$((numOK+1))
  10495. else
  10496. $PRINTF "$FAILED\n"
  10497. echo "$CMD0"
  10498. cat "${te}0"
  10499. numFAIL=$((numFAIL+1))
  10500. listFAIL="$listFAIL $N"
  10501. fi
  10502. fi # NUMCOND
  10503. ;;
  10504. esac
  10505. PORT=$((PORT+1))
  10506. N=$((N+1))
  10507. # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
  10508. # command line arguments (whole addresses, host names, file names) were longer
  10509. # than 512 bytes.
  10510. NAME=FILENAMEOVFL
  10511. case "$TESTS" in
  10512. *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%openssl%*|*%$NAME%*)
  10513. TEST="$NAME: stack overflow on overly long file name"
  10514. # provide a 600 bytes long key file option to OPENSSL-CONNECT and check socats exit code
  10515. if ! eval $NUMCOND; then :; else
  10516. tf="$td/test$N.stdout"
  10517. te="$td/test$N.stderr"
  10518. tdiff="$td/test$N.diff"
  10519. da="test$N $(date) $RANDOM"
  10520. i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
  10521. CMD0="$TRACE $SOCAT $opts OPENSSL:localhost:$PORT,key=$(cat "$td/test$N.dat") STDIO"
  10522. printf "test $F_n $TEST... " $N
  10523. $CMD0 </dev/null 1>&0 2>"${te}0"
  10524. rc0=$?
  10525. if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
  10526. $PRINTF "$OK\n"
  10527. numOK=$((numOK+1))
  10528. else
  10529. $PRINTF "$FAILED\n"
  10530. echo "$CMD0"
  10531. cat "${te}0"
  10532. numFAIL=$((numFAIL+1))
  10533. listFAIL="$listFAIL $N"
  10534. fi
  10535. fi # NUMCOND
  10536. ;;
  10537. esac
  10538. PORT=$((PORT+1))
  10539. N=$((N+1))
  10540. # socat up to 1.7.3.0 had a stack overflow vulnerability that occurred when
  10541. # command line arguments (whole addresses, host names, file names) were longer
  10542. # than 512 bytes and specially crafted.
  10543. NAME=NESTEDOVFL
  10544. case "$TESTS" in
  10545. *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%exec%*|*%$NAME%*)
  10546. TEST="$NAME: stack overflow on overly long nested arg"
  10547. # provide a long host name to TCP-CONNECT and check socats exit code
  10548. if ! eval $NUMCOND; then :; else
  10549. tf="$td/test$N.stdout"
  10550. te="$td/test$N.stderr"
  10551. tdiff="$td/test$N.diff"
  10552. da="test$N $(date) $RANDOM"
  10553. # prepare long data - perl might not be installed
  10554. rm -f "$td/test$N.dat"
  10555. i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
  10556. CMD0="$TRACE $SOCAT $opts EXEC:[$(cat "$td/test$N.dat")] STDIO"
  10557. printf "test $F_n $TEST... " $N
  10558. $CMD0 </dev/null 1>&0 2>"${te}0"
  10559. rc0=$?
  10560. if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
  10561. $PRINTF "$OK\n"
  10562. numOK=$((numOK+1))
  10563. else
  10564. $PRINTF "$FAILED\n"
  10565. echo "$CMD0"
  10566. cat "${te}0"
  10567. numFAIL=$((numFAIL+1))
  10568. listFAIL="$listFAIL $N"
  10569. fi
  10570. fi # NUMCOND
  10571. ;;
  10572. esac
  10573. PORT=$((PORT+1))
  10574. N=$((N+1))
  10575. # test for a bug in gopen that lead to crash or warning when opening a unix
  10576. # domain socket with GOPEN
  10577. NAME=GOPEN_UNIX_CRASH
  10578. case "$TESTS" in
  10579. *%$N%*|*%functions%*|*%bugs%*|*%gopen%*|*%unix%*|*%socket%*|*%$NAME%*)
  10580. TEST="$NAME: check crash when connecting to a unix domain socket using address GOPEN"
  10581. # a unix domain server is started in background. the check process connects to
  10582. # its socket. when this process crashes or issues a warning the bug is present.
  10583. # please note that a clean behaviour does not proof anything; behaviour of bug
  10584. # depends on the value of an uninitialized var
  10585. #set -vx
  10586. if ! eval $NUMCOND; then :; else
  10587. tf="$td/test$N.stdout"
  10588. te="$td/test$N.stderr"
  10589. ts="$td/test$N.sock"
  10590. tdiff="$td/test$N.diff"
  10591. da="test$N $(date) $RANDOM"
  10592. CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
  10593. CMD1="$TRACE $SOCAT $opts -d - GOPEN:$ts"
  10594. printf "test $F_n $TEST... " $N
  10595. $CMD0 >/dev/null 2>"${te}0" </dev/null &
  10596. pid0=$!
  10597. waitunixport "$ts" 1
  10598. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  10599. rc1=$?
  10600. kill $pid0 2>/dev/null; wait
  10601. if [ $rc1 -ne 0 ]; then
  10602. $PRINTF "$FAILED\n"
  10603. echo "$CMD0 &"
  10604. echo "$CMD1"
  10605. cat "${te}0"
  10606. cat "${te}1"
  10607. numFAIL=$((numFAIL+1))
  10608. listFAIL="$listFAIL $N"
  10609. elif grep -q ' W ' "${te}1"; then
  10610. $PRINTF "$FAILED\n"
  10611. echo "$CMD0 &"
  10612. echo "$CMD1"
  10613. cat "${te}0"
  10614. cat "${te}1"
  10615. numFAIL=$((numFAIL+1))
  10616. listFAIL="$listFAIL $N"
  10617. elif ! echo "$da" |diff - ${tf}1 >"$tdiff"; then
  10618. $PRINTF "$FAILED\n"
  10619. echo "$CMD0 &"
  10620. echo "$CMD1"
  10621. cat "${te}0"
  10622. cat "${te}1"
  10623. cat "$tdiff"
  10624. numFAIL=$((numFAIL+1))
  10625. listFAIL="$listFAIL $N"
  10626. else
  10627. $PRINTF "$OK\n"
  10628. numOK=$((numOK+1))
  10629. fi
  10630. fi # NUMCOND
  10631. ;;
  10632. esac
  10633. N=$((N+1))
  10634. # test if socat keeps an existing file where it wanted to create a UNIX socket
  10635. NAME=UNIXLISTEN_KEEPFILE
  10636. case "$TESTS" in
  10637. *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
  10638. TEST="$NAME: socat keeps an existing file where it wanted to create a UNIX socket"
  10639. # we create a file and start socat with UNIX-LISTEN on this file. expected
  10640. # behaviour: socat exits immediately with error, but keeps the file
  10641. # up to 1.7.1.3, it removed the file
  10642. if ! eval $NUMCOND; then :; else
  10643. tf="$td/test$N.file"
  10644. te="$td/test$N.stderr"
  10645. CMD0="$TRACE $SOCAT $opts -u UNIX-LISTEN:$tf /dev/null"
  10646. printf "test $F_n $TEST... " $N
  10647. rm -f "$tf"; touch "$tf"
  10648. $CMD0 >/dev/null 2>"${te}0"
  10649. rc0=$?
  10650. if [ $rc0 -ne 0 -a -f "$tf" ]; then
  10651. $PRINTF "$OK\n"
  10652. numOK=$((numOK+1))
  10653. else
  10654. $PRINTF "$FAILED\n"
  10655. echo "$CMD0"
  10656. cat "${te}0"
  10657. numFAIL=$((numFAIL+1))
  10658. listFAIL="$listFAIL $N"
  10659. fi
  10660. fi # NUMCOND
  10661. ;;
  10662. esac
  10663. N=$((N+1))
  10664. # PTY address allowed to sepcify address parameters but ignored them
  10665. NAME=PTY_VOIDARG
  10666. case "$TESTS" in
  10667. *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
  10668. TEST="$NAME: check if address params of PTY produce error"
  10669. # invoke socat with address PTY and some param; expect an error
  10670. if ! eval $NUMCOND; then :; else
  10671. tf="$td/test$N.stdout"
  10672. te="$td/test$N.stderr"
  10673. tdiff="$td/test$N.diff"
  10674. da="test$N $(date) $RANDOM"
  10675. CMD0="$TRACE $SOCAT $opts /dev/null PTY:/tmp/xyz"
  10676. printf "test $F_n $TEST... " $N
  10677. $CMD0 >/dev/null 2>"${te}0"
  10678. rc0=$?
  10679. if [ $rc0 -ne 0 ]; then
  10680. $PRINTF "$OK\n"
  10681. numOK=$((numOK+1))
  10682. else
  10683. $PRINTF "$FAILED\n"
  10684. echo "$CMD0"
  10685. cat "${te}0"
  10686. numFAIL=$((numFAIL+1))
  10687. listFAIL="$listFAIL $N"
  10688. fi
  10689. fi # NUMCOND
  10690. ;;
  10691. esac
  10692. N=$((N+1))
  10693. # incomplete writes were reported but led to data loss
  10694. NAME=INCOMPLETE_WRITE
  10695. case "$TESTS" in
  10696. *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
  10697. TEST="$NAME: check if incomplete writes are handled properly"
  10698. # write to a nonblocking fd a block that is too large for atomic write
  10699. # and check if all data arrives
  10700. if ! eval $NUMCOND; then :; else
  10701. tf="$td/test$N.stdout"
  10702. te="$td/test$N.stderr"
  10703. tp="$td/test$N.pipe"
  10704. tw="$td/test$N.wc-c"
  10705. # this is the size we write() in one call; data is never stored on disk, so
  10706. # make it large enough to exceed any atomic write size; but higher number might
  10707. # take much time
  10708. bytes=100000 # for Linux 2.6.? this must be >65536
  10709. CMD0="$TRACE $SOCAT $opts -u PIPE:$tp STDOUT"
  10710. CMD1="$TRACE $SOCAT $opts -u -b $bytes OPEN:/dev/zero,readbytes=$bytes FILE:$tp,o-nonblock"
  10711. printf "test $F_n $TEST... " $N
  10712. $CMD0 2>"${te}0" |wc -c >"$tw" &
  10713. pid=$!
  10714. waitfile "$tp"
  10715. $CMD1 2>"${te}1" >"${tf}1"
  10716. rc1=$?
  10717. wait
  10718. if [ $rc1 -ne 0 ]; then
  10719. $PRINTF "$NO_RESULT\n"
  10720. numCANT=$((numCANT+1))
  10721. elif [ ! -e "$tw" ]; then
  10722. $PRINTF "$NO_RESULT\n"
  10723. numCANT=$((numCANT+1))
  10724. elif [ "$bytes" -eq $(cat "$tw") ]; then
  10725. $PRINTF "$OK\n"
  10726. numOK=$((numOK+1))
  10727. else
  10728. $PRINTF "$FAILED\n"
  10729. echo "transferred only $(cat $tw) of $bytes bytes" >&2
  10730. numFAIL=$((numFAIL+1))
  10731. listFAIL="$listFAIL $N"
  10732. fi
  10733. fi # NUMCOND
  10734. ;;
  10735. esac
  10736. N=$((N+1))
  10737. NAME=OPENSSL_ANULL
  10738. case "$TESTS" in
  10739. *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
  10740. TEST="$NAME: OpenSSL server with cipher aNULL "
  10741. if ! eval $NUMCOND; then :;
  10742. elif ! testaddrs openssl >/dev/null; then
  10743. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  10744. numCANT=$((numCANT+1))
  10745. elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
  10746. $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
  10747. numCANT=$((numCANT+1))
  10748. else
  10749. tf="$td/test$N.stdout"
  10750. te="$td/test$N.stderr"
  10751. tdiff="$td/test$N.diff"
  10752. da="test$N $(date) $RANDOM"
  10753. CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,ciphers=aNULL,verify=0 pipe"
  10754. CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,ciphers=aNULL,verify=0,$SOCAT_EGD"
  10755. printf "test $F_n $TEST... " $N
  10756. eval "$CMD2 2>\"${te}1\" &"
  10757. pid=$! # background process id
  10758. waittcp4port $PORT
  10759. echo "$da" |$CMD >$tf 2>"${te}2"
  10760. if ! echo "$da" |diff - "$tf" >"$tdiff"; then
  10761. $PRINTF "${YELLOW}FAILED${NORMAL}\n"
  10762. #echo "$CMD2 &"
  10763. #echo "$CMD"
  10764. #cat "${te}1"
  10765. #cat "${te}2"
  10766. #cat "$tdiff"
  10767. numOK=$((numOK+1))
  10768. else
  10769. $PRINTF "$OK\n"
  10770. if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
  10771. numOK=$((numOK+1))
  10772. fi
  10773. kill $pid 2>/dev/null
  10774. wait
  10775. fi ;; # NUMCOND, feats
  10776. esac
  10777. PORT=$((PORT+1))
  10778. N=$((N+1))
  10779. while read KEYW FEAT ADDR IPPORT; do
  10780. if [ -z "$KEYW" ]|| [[ "$KEYW" == \#* ]]; then continue; fi
  10781. RUNS=$(tolower $KEYW)
  10782. PROTO=$KEYW
  10783. proto="$(echo "$PROTO" |tr A-Z a-z)"
  10784. # test the max-children option on really connection oriented sockets
  10785. NAME=${KEYW}MAXCHILDREN
  10786. case "$TESTS" in
  10787. *%$N%*|*%functions%*|*%maxchildren%*|*%socket%*|*%$NAME%*)
  10788. TEST="$NAME: max-children option"
  10789. # start a listen process with max-children=1; connect with a client, let it
  10790. # sleep some time before sending data; connect with second client that sends
  10791. # data immediately. If max-children is working correctly the first data should
  10792. # arrive first because the second process has to wait.
  10793. if ! eval $NUMCOND; then :;
  10794. elif ! testaddrs "$FEAT" >/dev/null; then
  10795. $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
  10796. numCANT=$((numCANT+1))
  10797. elif ! runs$RUNS >/dev/null; then
  10798. $PRINTF "test $F_n $TEST... ${YELLOW}$(toupper $RUNS) not available${NORMAL}\n" $N
  10799. numCANT=$((numCANT+1))
  10800. else
  10801. case "X$IPPORT" in
  10802. "XPORT")
  10803. tsl=$PORT # test socket listen address
  10804. tsc="$ADDR:$PORT" # test socket connect address
  10805. PORT=$((PORT+1)) ;;
  10806. *)
  10807. tsl="$(eval echo "$ADDR")" # resolve $N
  10808. tsc=$tsl
  10809. esac
  10810. #ts="$td/test$N.sock"
  10811. tf="$td/test$N.stdout"
  10812. te="$td/test$N.stderr"
  10813. tdiff="$td/test$N.diff"
  10814. da="test$N $(date) $RANDOM"
  10815. CMD0="$TRACE $SOCAT $opts -U FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
  10816. CMD1="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,shut-null"
  10817. printf "test $F_n $TEST... " $N
  10818. $CMD0 >/dev/null 2>"${te}0" &
  10819. pid0=$!
  10820. wait${proto}port $tsl 1
  10821. (echo "$da 1"; sleep 2) |$CMD1 >"${tf}1" 2>"${te}1" &
  10822. pid1=$!
  10823. sleep 1
  10824. echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2" &
  10825. pid2=$!
  10826. sleep 2
  10827. kill $pid1 $pid2 $pid0 2>/dev/null; wait
  10828. if echo -e "$da 1\n$da 2" |diff - $tf >$tdiff; then
  10829. $PRINTF "$OK\n"
  10830. numOK=$((numOK+1))
  10831. else
  10832. $PRINTF "$FAILED\n"
  10833. echo "$CMD0 &"
  10834. echo "(echo \"$da 1\"; sleep 2) |$CMD1"
  10835. echo "echo \"$da 2\" |$CMD1"
  10836. cat "${te}0"
  10837. cat "${te}1"
  10838. cat "${te}2"
  10839. cat "$tdiff"
  10840. numFAIL=$((numFAIL+1))
  10841. listFAIL="$listFAIL $N"
  10842. fi
  10843. fi # NUMCOND
  10844. ;;
  10845. esac
  10846. N=$((N+1))
  10847. done <<<"
  10848. TCP4 TCP 127.0.0.1 PORT
  10849. TCP6 TCP [::1] PORT
  10850. SCTP4 SCTP 127.0.0.1 PORT
  10851. SCTP6 SCTP [::1] PORT
  10852. UNIX unix $td/test\$N.server -
  10853. "
  10854. # debugging this hanging test was difficult - following lessons learned:
  10855. # kill <parent> had no effect when child process existed
  10856. # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
  10857. # using the TRACE feature lets above kill command kill strace, not socat
  10858. # care for timing, understand what you want :-)
  10859. while read KEYW FEAT ADDR IPPORT SHUT; do
  10860. if [ -z "$KEYW" ]|| [[ "$KEYW" == \#* ]]; then continue; fi
  10861. RUNS=$(tolower $KEYW)
  10862. PROTO=$KEYW
  10863. proto="$(echo "$PROTO" |tr A-Z a-z)"
  10864. # test the max-children option on pseudo connected sockets
  10865. NAME=${KEYW}MAXCHILDREN
  10866. case "$TESTS" in
  10867. *%$N%*|*%functions%*|*%maxchildren%*|*%socket%*|*%$NAME%*)
  10868. TEST="$NAME: max-children option"
  10869. # start a listen process with max-children=1; connect with a client, let it
  10870. # send data and then sleep; connect with second client that wants to send
  10871. # data immediately, but keep first client active until server terminates.
  10872. #If max-children is working correctly only the first data should
  10873. # arrive.
  10874. if ! eval $NUMCOND; then :;
  10875. elif ! testaddrs "$FEAT" >/dev/null; then
  10876. $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
  10877. numCANT=$((numCANT+1))
  10878. elif ! runs$RUNS >/dev/null; then
  10879. $PRINTF "test $F_n $TEST... ${YELLOW}$(toupper $RUNS) not available${NORMAL}\n" $N
  10880. numCANT=$((numCANT+1))
  10881. else
  10882. case "X$IPPORT" in
  10883. "XPORT")
  10884. tsl=$PORT # test socket listen address
  10885. tsc="$ADDR:$PORT" # test socket connect address
  10886. PORT=$((PORT+1)) ;;
  10887. *)
  10888. tsl="$(eval echo "$ADDR")" # resolve $N
  10889. tsc=$tsl
  10890. esac
  10891. #ts="$td/test$N.sock"
  10892. tf="$td/test$N.stdout"
  10893. te="$td/test$N.stderr"
  10894. tdiff="$td/test$N.diff"
  10895. da="test$N $(date) $RANDOM"
  10896. # on some Linux distributions it hangs, thus -T option here
  10897. CMD0="$TRACE $SOCAT $opts -U -T 4 FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
  10898. CMD1="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,$SHUT"
  10899. printf "test $F_n $TEST... " $N
  10900. $CMD0 >/dev/null 2>"${te}0" &
  10901. pid0=$!
  10902. wait${proto}port $tsl 1
  10903. (echo "$da 1"; sleep 3) |$CMD1 >"${tf}1" 2>"${te}1" &
  10904. pid1=$!
  10905. sleep 1
  10906. echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2" &
  10907. pid2=$!
  10908. sleep 1
  10909. cpids="$(childpids $pid0)"
  10910. kill $pid1 $pid2 $pid0 $cpids 2>/dev/null; wait
  10911. if echo -e "$da 1" |diff - $tf >$tdiff; then
  10912. $PRINTF "$OK\n"
  10913. numOK=$((numOK+1))
  10914. else
  10915. $PRINTF "$FAILED\n"
  10916. echo "$CMD0 &"
  10917. echo "(echo \"$da 1\"; sleep 2) |$CMD1"
  10918. echo "echo \"$da 2\" |$CMD1"
  10919. cat "${te}0"
  10920. cat "${te}1"
  10921. cat "${te}2"
  10922. cat "$tdiff"
  10923. numFAIL=$((numFAIL+1))
  10924. listFAIL="$listFAIL $N"
  10925. fi
  10926. fi # NUMCOND
  10927. ;;
  10928. esac
  10929. N=$((N+1))
  10930. done <<<"
  10931. UDP4 UDP 127.0.0.1 PORT shut-null
  10932. UDP6 UDP [::1] PORT shut-null
  10933. "
  10934. # debugging this hanging test was difficult - following lessons learned:
  10935. # kill <parent> had no effect when child process existed
  10936. # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
  10937. # using the TRACE feature lets above kill command kill strace, not socat
  10938. # care for timing, understand what you want :-)
  10939. # socat up to 1.7.2.0 had a bug in xioscan_readline() that could be exploited
  10940. # to overflow a heap based buffer (socat security advisory 3)
  10941. # problem reported by Johan Thillemann
  10942. NAME=READLINE_OVFL
  10943. case "$TESTS" in
  10944. *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%readline%*|*%$NAME%*)
  10945. TEST="$NAME: test for buffer overflow in readline prompt handling"
  10946. # address 1 is the readline where write data was handled erroneous
  10947. # address 2 provides data to trigger the buffer overflow
  10948. # when no SIGSEGV or so occurs the test succeeded (bug fixed)
  10949. if ! eval $NUMCOND; then :;
  10950. elif ! feat=$(testaddrs readline pty); then
  10951. $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
  10952. numCANT=$((numCANT+1))
  10953. else
  10954. tf="$td/test$N.stdout"
  10955. te="$td/test$N.stderr"
  10956. ti="$td/test$N.data"
  10957. CMD0="$SOCAT $opts READLINE $ti"
  10958. printf "test $F_n $TEST... " $N
  10959. # prepare long data - perl might not be installed
  10960. #perl -e 'print "\r","Z"x513' >"$ti"
  10961. echo $E -n "\rA" >"$ti"
  10962. i=0; while [ $i -lt 32 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$ti"; let i=i+1; done
  10963. $TRACE $SOCAT - SYSTEM:"$CMD0; echo rc=\$? >&2",pty >/dev/null 2>"${te}0"
  10964. rc=$?
  10965. rc0="$(grep ^rc= "${te}0" |sed 's/.*=//')"
  10966. if [ $rc -ne 0 ]; then
  10967. $PRINTF "${YELLOW}framework failed${NORMAL}\n"
  10968. elif [ $rc0 -eq 0 ]; then
  10969. $PRINTF "$OK\n"
  10970. numOK=$((numOK+1))
  10971. else
  10972. $PRINTF "$FAILED\n"
  10973. echo "$CMD0"
  10974. grep -v ^rc= "${te}0"
  10975. numFAIL=$((numFAIL+1))
  10976. listFAIL="$listFAIL $N"
  10977. fi
  10978. fi # NUMCOND
  10979. ;;
  10980. esac
  10981. PORT=$((PORT+1))
  10982. N=$((N+1))
  10983. # socat up to 1.7.2.1 did only shutdown() but not close() an accept() socket
  10984. # that was rejected due to range, tcpwrap, lowport, or sourceport option.
  10985. # This file descriptor leak could be used for a denial of service attack.
  10986. NAME=FDLEAK
  10987. case "$TESTS" in
  10988. *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
  10989. TEST="$NAME: file descriptor leak with range option"
  10990. # have a TCP-LISTEN with range option; connect with wrong source address until
  10991. # "open files" limit would exceed. When server continues operation the bug is
  10992. # not present.
  10993. if ! eval $NUMCOND; then :; else
  10994. tf="$td/test$N.stdout"
  10995. te="$td/test$N.stderr"
  10996. tdiff="$td/test$N.diff"
  10997. da="test$N $(date) $RANDOM"
  10998. RLIMIT_NOFILE="$(ulimit -n)"
  10999. if ! [[ "$RLIMIT_NOFILE" =~ ^[0-9][0-9]*$ ]]; then
  11000. $PRINTF "${YELLOW}cannot determine ulimit -n"
  11001. else
  11002. CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR,range=$LOCALHOST:255.255.255.255 PIPE"
  11003. CMD1="$TRACE $SOCAT $opts -t 0 /dev/null TCP:$SECONDADDR:$PORT,bind=$SECONDADDR"
  11004. CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,bind=$LOCALHOST"
  11005. printf "test $F_n $TEST... " $N
  11006. $CMD0 >/dev/null 2>"${te}0" &
  11007. pid0=$!
  11008. waittcp4port $PORT 1
  11009. while [ $RLIMIT_NOFILE -gt 0 ]; do
  11010. $CMD1 >/dev/null 2>>"${te}1"
  11011. let RLIMIT_NOFILE=RLIMIT_NOFILE-1
  11012. done
  11013. echo "$da" |$CMD2 >"${tf}2" 2>"${te}2"
  11014. rc2=$?
  11015. kill $pid0 2>/dev/null; wait
  11016. echo -e "$da" |diff "${tf}2" - >$tdiff
  11017. if [ $rc2 -ne 0 ]; then
  11018. $PRINTF "$FAILED\n"
  11019. echo "$CMD2 &"
  11020. cat "${te}2"
  11021. numFAIL=$((numFAIL+1))
  11022. listFAIL="$listFAIL $N"
  11023. elif [ -f "$tdiff" -a ! -s "$tdiff" ]; then
  11024. $PRINTF "$OK\n"
  11025. numOK=$((numOK+1))
  11026. else
  11027. $PRINTF "$FAILED\n"
  11028. echo "$CMD0 &"
  11029. echo "$CMD1"
  11030. echo "$CMD2"
  11031. cat "${te}0"
  11032. cat "${te}1"
  11033. cat "${te}2"
  11034. numFAIL=$((numFAIL+1))
  11035. listFAIL="$listFAIL $N"
  11036. fi
  11037. fi # ulimit -n
  11038. fi # NUMCOND
  11039. ;;
  11040. esac
  11041. PORT=$((PORT+1))
  11042. N=$((N+1))
  11043. if false; then # this overflow is not reliably reproducable
  11044. # socat up to 2.0.0-b6 did not check the length of the PROXY-CONNECT command line paramters when copying them into the HTTP request buffer. This could lead to a buffer overflow.
  11045. NAME=PROXY_ADDR_OVFL
  11046. case "$TESTS" in
  11047. *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
  11048. TEST="$NAME: proxy address parameters overflow"
  11049. # invoke socat PROXY-CONNECT with long proxy server and target server names. If it terminates with exit code >= 128 it is vulnerable
  11050. # However, even if vulnerable it often does not crash. Therefore we try to use a boundary check program like ElectricFence; only with its help we can tell that clean run proofs absence of vulnerability
  11051. if ! eval $NUMCOND; then :; else
  11052. tf="$td/test$N.stdout"
  11053. te="$td/test$N.stderr"
  11054. tdiff="$td/test$N.diff"
  11055. da="test$N $(date) $RANDOM"
  11056. EF=; for p in ef; do
  11057. if type ef >/dev/null 2>&1; then
  11058. EF="ef "; break
  11059. fi
  11060. done
  11061. CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR FILE:/dev/null"
  11062. #CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$(perl -e "print 'A' x 256"):$(perl -e "print 'A' x 256"):80"
  11063. CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:localhost:$(perl -e "print 'A' x 384"):80,proxyport=$PORT"
  11064. printf "test $F_n $TEST... " $N
  11065. $CMD0 >/dev/null 2>"${te}0" &
  11066. pid0=$!
  11067. waittcp4port $PORT 1
  11068. $CMD1 >/dev/null 2>"${te}1"
  11069. rc1=$?
  11070. if [ $rc1 -lt 128 ]; then
  11071. if [ "$EF" ]; then
  11072. $PRINTF "$OK\n"
  11073. numOK=$((numOK+1))
  11074. else
  11075. $PRINTF "$UNKNOWN $RED(install ElectricFEnce!)$NORMAL\n"
  11076. numCANT=$((num+1))
  11077. fi
  11078. else
  11079. $PRINTF "$FAILED\n"
  11080. echo "$CMD1"
  11081. cat "${te}"
  11082. numFAIL=$((numFAIL+1))
  11083. listFAIL="$listFAIL $N"
  11084. fi
  11085. fi # NUMCOND
  11086. ;;
  11087. esac
  11088. PORT=$((PORT+1))
  11089. N=$((N+1))
  11090. fi # false
  11091. # LISTEN addresses in socat up to 1.7.2.1 applied many file descriptor, socket,
  11092. # and TCP options only to the listening socket instead of the connection socket.
  11093. NAME=LISTEN_KEEPALIVE
  11094. case "$TESTS" in
  11095. *%$N%*|*%functions%*|*%bugs%*|*%listen%*|*%keepalive%*|*%socket%*|*%$NAME%*)
  11096. TEST="$NAME: keepalive option is applied to connection socket"
  11097. # instance 0 has TCP-LISTEN with option so-keepalive and invokes filan after
  11098. # accept(). filan writes its output to the socket. instance 1 connects to
  11099. # instance 0. The value of the sockets so-keepalive option is checked, it must
  11100. # be 1
  11101. if ! eval $NUMCOND; then :; else
  11102. tf="$td/test$N.stdout"
  11103. te="$td/test$N.stderr"
  11104. #tdiff="$td/test$N.diff"
  11105. #da="test$N $(date) $RANDOM"
  11106. CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,so-keepalive EXEC:\"$FILAN -i 1\",nofork"
  11107. CMD1="$TRACE $SOCAT $opts - TCP4:$LOCALHOST:$PORT"
  11108. printf "test $F_n $TEST... " $N
  11109. eval $CMD0 >/dev/null 2>"${te}0" &
  11110. pid0=$!
  11111. waittcp4port $PORT 1
  11112. $CMD1 >"${tf}1" 2>"${te}1"
  11113. KEEPALIVE="$(cat "${tf}1" |tail -n +2 |sed -e "s/.*KEEPALIVE=//" -e "s/[[:space:]].*//")"
  11114. rc1=$?
  11115. kill $pid0 2>/dev/null; wait
  11116. if [ -z "$KEEPALIVE" ]; then
  11117. $PRINTF "$NO_RESULT\n"
  11118. echo "$CMD0 &"
  11119. echo "$CMD1"
  11120. cat "${te}0"
  11121. cat "${te}1"
  11122. numCANT=$((numCANT+1))
  11123. elif [ "$KEEPALIVE" = "1" ]; then
  11124. $PRINTF "$OK\n";
  11125. numOK=$((numOK+1))
  11126. else
  11127. $PRINTF "$FAILED\n"
  11128. echo "$CMD0 &"
  11129. echo "$CMD1"
  11130. cat "${te}0"
  11131. cat "${te}1"
  11132. numFAIL=$((numFAIL+1))
  11133. listFAIL="$listFAIL $N"
  11134. fi
  11135. fi # NUMCOND
  11136. ;;
  11137. esac
  11138. PORT=$((PORT+1))
  11139. N=$((N+1))
  11140. # OPENSSL-CONNECT with bind option failed on some systems (eg.FreeBSD, but not
  11141. # Linux) with "Invalid argument".
  11142. NAME=OPENSSL_CONNECT_BIND
  11143. case "$TESTS" in
  11144. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
  11145. TEST="$NAME: test OPENSSL-CONNECT with bind option"
  11146. # have a simple SSL server that just echoes data.
  11147. # connect with socat using OPENSSL-CONNECT with bind, send data and check if the
  11148. # reply is identical.
  11149. if ! eval $NUMCOND; then :;
  11150. elif ! testaddrs openssl >/dev/null; then
  11151. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  11152. numCANT=$((numCANT+1))
  11153. else
  11154. gentestcert testsrv
  11155. tf0="$td/test$N.0.stdout"
  11156. te0="$td/test$N.0.stderr"
  11157. tf1="$td/test$N.1.stdout"
  11158. te1="$td/test$N.1.stderr"
  11159. tdiff="$td/test$N.diff"
  11160. da="test$N $(date) $RANDOM"
  11161. CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 PIPE"
  11162. CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,bind=$LOCALHOST,verify=0"
  11163. printf "test $F_n $TEST... " $N
  11164. $CMD0 >/dev/null 2>"$te0" &
  11165. pid0=$!
  11166. waittcp4port $PORT 1
  11167. echo "$da" |$CMD1 >"$tf1" 2>"$te1"
  11168. rc1=$?
  11169. kill $pid0 2>/dev/null; wait
  11170. if [ "$rc1" -ne 0 ]; then
  11171. $PRINTF "$FAILED\n"
  11172. echo "$CMD0 &"
  11173. echo "$CMD1"
  11174. cat "$te0"
  11175. cat "$te1"
  11176. numFAIL=$((numFAIL+1))
  11177. listFAIL="$listFAIL $N"
  11178. elif ! echo "$da" |diff - $tf1 >"$tdiff"; then
  11179. $PRINTF "$FAILED\n"
  11180. echo "$CMD0 &"
  11181. echo "$CMD1"
  11182. cat "${te}0"
  11183. cat "${te}1"
  11184. cat "$tdiff"
  11185. numFAIL=$((numFAIL+1))
  11186. listFAIL="$listFAIL $N"
  11187. else
  11188. $PRINTF "$OK\n"
  11189. numOK=$((numOK+1))
  11190. fi
  11191. fi # NUMCOND
  11192. ;;
  11193. esac
  11194. PORT=$((PORT+1))
  11195. N=$((N+1))
  11196. # socat up to version 1.7.2.3
  11197. # had a bug that converted a bit mask of 0 internally to 0xffffffff
  11198. NAME=TCP4RANGE_0BITS
  11199. case "$TESTS" in
  11200. *%$N%*|*%functions%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
  11201. TEST="$NAME: correct evaluation of range mask 0"
  11202. if ! eval $NUMCOND; then :;
  11203. elif [ -z "$SECONDADDR" ]; then
  11204. # we need access to a second addresses
  11205. $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
  11206. numCANT=$((numCANT+1))
  11207. else
  11208. tf="$td/test$N.stdout"
  11209. te="$td/test$N.stderr"
  11210. tdiff="$td/test$N.diff"
  11211. da="test$N $(date) $RANDOM"
  11212. #testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
  11213. CMD0="$TRACE $SOCAT $opts -u TCP4-LISTEN:$PORT,$REUSEADDR,range=127.0.0.1/0 CREATE:$tf"
  11214. CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$SECONDADDR:$PORT,bind=$SECONDADDR"
  11215. printf "test $F_n $TEST... " $N
  11216. $CMD0 2>"${te}0" &
  11217. pid0=$!
  11218. waittcp4port $PORT 1
  11219. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  11220. rc1=$?
  11221. kill $pid0 2>/dev/null; wait
  11222. if [ $rc1 != 0 ]; then
  11223. $PRINTF "${YELLOW}invocation failed${NORMAL}\n"
  11224. numCANT=$((numCANT+1))
  11225. elif ! [ -f "$tf" ]; then
  11226. $PRINTF "$FAILED\n"
  11227. echo "$CMD0 &"
  11228. echo "$CMD1"
  11229. cat "${te}0"
  11230. cat "${te}1"
  11231. numFAIL=$((numFAIL+1))
  11232. listFAIL="$listFAIL $N"
  11233. elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
  11234. $PRINTF "${YELLOW}diff failed${NORMAL}\n"
  11235. numCANT=$((numCANT+1))
  11236. else
  11237. $PRINTF "$OK\n"
  11238. numOK=$((numOK+1))
  11239. fi
  11240. fi ;; # $SECONDADDR, NUMCOND
  11241. esac
  11242. PORT=$((PORT+1))
  11243. N=$((N+1))
  11244. # test: OPENSSL sets of environment variables with important values of peer certificate
  11245. while read ssldist MODE MODULE FIELD TESTADDRESS PEERADDRESS VALUE; do
  11246. if [ -z "$ssldist" ] || [[ "$ssldist" == \#* ]]; then continue; fi
  11247. #
  11248. SSLDIST=$(toupper $ssldist)
  11249. NAME="ENV_${SSLDIST}_${MODE}_${MODULE}_${FIELD}"
  11250. case "$TESTS" in
  11251. *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$ssldist%*|*%envvar%*|*%$NAME%*)
  11252. TEST="$NAME: $SSLDIST sets env SOCAT_${SSLDIST}_${MODULE}_${FIELD}"
  11253. # have a server accepting a connection and invoking some shell code. The shell
  11254. # code extracts and prints the SOCAT related environment vars.
  11255. # outside code then checks if the environment contains the variables correctly
  11256. # describing the desired field.
  11257. FEAT=$(echo "$ssldist" |tr a-z A-Z)
  11258. if ! eval $NUMCOND; then :;
  11259. elif ! testaddrs $FEAT >/dev/null; then
  11260. $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
  11261. numCANT=$((numCANT+1))
  11262. else
  11263. tf="$td/test$N.stdout"
  11264. te="$td/test$N.stderr"
  11265. gentestcert testsrv
  11266. gentestcert testcli
  11267. test_proto=tcp4
  11268. case "$MODE" in
  11269. SERVER)
  11270. CMD0="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
  11271. CMD1="$SOCAT $opts -u /dev/null $PEERADDRESS"
  11272. printf "test $F_n $TEST... " $N
  11273. eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
  11274. pid0=$!
  11275. wait${test_proto}port $PORT 1
  11276. $CMD1 2>"${te}1"
  11277. rc1=$?
  11278. waitfile "$tf" 2
  11279. kill $pid0 2>/dev/null; wait
  11280. ;;
  11281. CLIENT)
  11282. CMD0="$SOCAT $opts -u /dev/null $PEERADDRESS"
  11283. CMD1="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
  11284. printf "test $F_n $TEST... " $N
  11285. $CMD0 2>"${te}0" &
  11286. pid0=$!
  11287. wait${test_proto}port $PORT 1
  11288. eval "$CMD1 2>\"${te}1\" >\"$tf\""
  11289. rc1=$?
  11290. waitfile "$tf" 2
  11291. kill $pid0 2>/dev/null; wait
  11292. ;;
  11293. esac
  11294. if [ $rc1 != 0 ]; then
  11295. $PRINTF "$NO_RESULT (client failed):\n"
  11296. echo "$CMD0 &"
  11297. cat "${te}0"
  11298. echo "$CMD1"
  11299. cat "${te}1"
  11300. numCANT=$((numCANT+1))
  11301. elif effval="$(grep SOCAT_${SSLDIST}_${MODULE}_${FIELD} "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")";
  11302. [ "$effval" = "$VALUE" ]; then
  11303. $PRINTF "$OK\n"
  11304. if [ "$debug" ]; then
  11305. echo "$CMD0 &"
  11306. cat "${te}0"
  11307. echo "$CMD1"
  11308. cat "${te}1"
  11309. fi
  11310. numOK=$((numOK+1))
  11311. else
  11312. $PRINTF "$FAILED\n"
  11313. echo "expected \"$VALUE\", got \"$effval\"" >&2
  11314. echo "$CMD0 &"
  11315. cat "${te}0"
  11316. echo "$CMD1"
  11317. cat "${te}1"
  11318. numFAIL=$((numFAIL+1))
  11319. listFAIL="$listFAIL $N"
  11320. fi
  11321. fi # NUMCOND, feats
  11322. ;;
  11323. esac
  11324. N=$((N+1))
  11325. #
  11326. done <<<"
  11327. openssl SERVER X509 ISSUER OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ISSUER
  11328. openssl SERVER X509 SUBJECT OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_SUBJECT
  11329. openssl SERVER X509 COMMONNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_COMMONNAME
  11330. openssl SERVER X509 COUNTRYNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_COUNTRYNAME
  11331. openssl SERVER X509 LOCALITYNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_LOCALITYNAME
  11332. openssl SERVER X509 ORGANIZATIONALUNITNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ORGANIZATIONALUNITNAME
  11333. openssl SERVER X509 ORGANIZATIONNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ORGANIZATIONNAME
  11334. openssl CLIENT X509 SUBJECT OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_SUBJECT
  11335. openssl CLIENT X509 ISSUER OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_ISSUER
  11336. "
  11337. ###############################################################################
  11338. # tests: option umask with "passive" NAMED group addresses
  11339. while read addr fileopt addropts proto diropt ADDR2; do
  11340. if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
  11341. # some passive (listening...) filesystem based addresses did not implement the
  11342. # umask option
  11343. ADDR=$(toupper $addr)
  11344. ADDR_=${ADDR/-/_}
  11345. PROTO=$(toupper $proto)
  11346. if [ "$diropt" = "." ]; then diropt=; fi
  11347. if [ "$fileopt" = "." ]; then fileopt=; fi
  11348. if [ "$addropts" = "." ]; then addropts=; fi
  11349. NAME=${ADDR_}_UMASK
  11350. case "$TESTS" in
  11351. *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%$NAME%*)
  11352. TEST="$NAME: $ADDR applies option umask"
  11353. # start a socat process with passive/listening file system entry. Check the
  11354. # permissions of the FS entry, then terminate the process.
  11355. # Test succeeds when FS entry exists and has expected permissions.
  11356. if ! eval $NUMCOND; then :; else
  11357. if [ $ADDR = PTY ]; then set -xv; fi
  11358. tlog="$td/test$N.log"
  11359. te0="$td/test$N.0.stderr"
  11360. tsock="$td/test$N.sock"
  11361. if [ -z "$fileopt" ]; then
  11362. CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
  11363. else
  11364. CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
  11365. fi
  11366. printf "test $F_n $TEST... " $N
  11367. $CMD0 >/dev/null 2>"$te0" &
  11368. pid0=$!
  11369. wait${proto} $tsock 1 2>"$tlog"
  11370. ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
  11371. perms=$(fileperms "$tsock")
  11372. kill $pid0 2>>"$tlog"
  11373. wait
  11374. if [ "$ERRNOENT" ]; then
  11375. $PRINTF "${RED}no entry${NORMAL}\n"
  11376. echo "$CMD0 &"
  11377. cat "$te0"
  11378. cat "$tlog"
  11379. let numFAIL=numFAIL+1
  11380. listFAIL="$listFAIL $N"
  11381. elif [ "$perms" != "600" ]; then
  11382. $PRINTF "${RED}perms \"$perms\", expected \"600\" ${NORMAL}\n"
  11383. echo "$CMD0 &"
  11384. cat "$te0"
  11385. let numFAIL=numFAIL+1
  11386. listFAIL="$listFAIL $N"
  11387. else
  11388. $PRINTF "$OK\n"
  11389. let numOK=numOK+1
  11390. fi
  11391. set +xv
  11392. fi # NUMCOND
  11393. ;;
  11394. esac
  11395. PORT=$((PORT+1))
  11396. N=$((N+1))
  11397. #
  11398. done <<<"
  11399. # address fileopt addropts waitfor direction ADDR2
  11400. create . . file -U FILE:/dev/null
  11401. open . creat file . FILE:/dev/null
  11402. gopen . creat file . FILE:/dev/null
  11403. unix-listen . . unixport . FILE:/dev/null
  11404. unix-recvfrom . . unixport . FILE:/dev/null
  11405. unix-recv . . unixport -u FILE:/dev/null
  11406. pipe . . file -u FILE:/dev/null
  11407. # pty does not seem to honor umask:
  11408. #pty link . file . PIPE
  11409. "
  11410. # tests: option perm with "passive" NAMED group addresses
  11411. while read addr fileopt addropts proto diropt; do
  11412. if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
  11413. # test if passive (listening...) filesystem based addresses implement option perm
  11414. ADDR=$(toupper $addr)
  11415. ADDR_=${ADDR/-/_}
  11416. PROTO=$(toupper $proto)
  11417. if [ "$diropt" = "." ]; then diropt=; fi
  11418. if [ "$fileopt" = "." ]; then fileopt=; fi
  11419. if [ "$addropts" = "." ]; then addropts=; fi
  11420. NAME=${ADDR_}_PERM
  11421. case "$TESTS" in
  11422. *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%ignoreeof%*|*%$NAME%*)
  11423. TEST="$NAME: $ADDR applies option perm"
  11424. # start a socat process with passive/listening file system entry. Check the
  11425. # permissions of the FS entry, then terminate the process.
  11426. # Test succeeds when FS entry exists and has expected permissions.
  11427. if ! eval $NUMCOND; then :; else
  11428. tlog="$td/test$N.log"
  11429. te0="$td/test$N.0.stderr"
  11430. tsock="$td/test$N.sock"
  11431. # set -vx
  11432. if [ -z "$fileopt" ]; then
  11433. CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
  11434. else
  11435. CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
  11436. fi
  11437. printf "test $F_n $TEST... " $N
  11438. $CMD0 >/dev/null 2>"$te0" &
  11439. pid0=$!
  11440. wait${proto} $tsock 1 2>"$tlog"
  11441. ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
  11442. perms=$(fileperms "$tsock")
  11443. kill $pid0 2>>"$tlog"
  11444. wait
  11445. if [ "$ERRNOENT" ]; then
  11446. $PRINTF "${RED}no entry${NORMAL}\n"
  11447. echo "$CMD0 &"
  11448. cat "$te0"
  11449. cat "$tlog"
  11450. let numFAIL=numFAIL+1
  11451. listFAIL="$listFAIL $N"
  11452. elif [ "$perms" != "511" ]; then
  11453. $PRINTF "${RED}perms \"$perms\", expected \"511\" ${NORMAL}\n"
  11454. echo "$CMD0 &"
  11455. cat "$te0"
  11456. let numFAIL=numFAIL+1
  11457. listFAIL="$listFAIL $N"
  11458. else
  11459. $PRINTF "$OK\n"
  11460. let numOK=numOK+1
  11461. fi
  11462. set +vx
  11463. fi # NUMCOND
  11464. ;;
  11465. esac
  11466. PORT=$((PORT+1))
  11467. N=$((N+1))
  11468. #
  11469. done <<<"
  11470. # address fileopt addropts waitfor direction
  11471. create . . file -U
  11472. open . creat file .
  11473. gopen . creat file .
  11474. unix-listen . . unixport .
  11475. unix-recvfrom . . unixport .
  11476. unix-recv . . unixport -u
  11477. pipe . . file -u
  11478. pty link . file .
  11479. "
  11480. # tests: option user with "passive" NAMED group addresses
  11481. while read addr fileopt addropts proto diropt; do
  11482. if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
  11483. # test if passive (listening...) filesystem based addresses implement option user
  11484. ADDR=$(toupper $addr)
  11485. ADDR_=${ADDR/-/_}
  11486. PROTO=$(toupper $proto)
  11487. if [ "$diropt" = "." ]; then diropt=; fi
  11488. if [ "$fileopt" = "." ]; then fileopt=; fi
  11489. if [ "$addropts" = "." ]; then addropts=; fi
  11490. NAME=${ADDR_}_USER
  11491. case "$TESTS" in
  11492. *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%root%*|*%ignoreeof%*|*%$NAME%*)
  11493. TEST="$NAME: $ADDR applies option user"
  11494. # start a socat process with passive/listening file system entry with user option.
  11495. # Check the owner of the FS entry, then terminate the process.
  11496. # Test succeeds when FS entry exists and has expected owner.
  11497. if ! eval $NUMCOND; then :;
  11498. elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
  11499. $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
  11500. numCANT=$((numCANT+1))
  11501. else
  11502. tlog="$td/test$N.log"
  11503. te0="$td/test$N.0.stderr"
  11504. tsock="$td/test$N.sock"
  11505. # set -vx
  11506. if [ -z "$fileopt" ]; then
  11507. CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
  11508. else
  11509. CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
  11510. fi
  11511. printf "test $F_n $TEST... " $N
  11512. $CMD0 >/dev/null 2>"$te0" &
  11513. pid0=$!
  11514. wait${proto} $tsock 1 2>"$tlog"
  11515. ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
  11516. user=$(fileuser "$tsock")
  11517. kill $pid0 2>>"$tlog"
  11518. wait
  11519. if [ "$ERRNOENT" ]; then
  11520. $PRINTF "${RED}no entry${NORMAL}\n"
  11521. echo "$CMD0 &"
  11522. cat "$te0"
  11523. cat "$tlog"
  11524. let numFAIL=numFAIL+1
  11525. listFAIL="$listFAIL $N"
  11526. elif [ "$user" != "$SUBSTUSER" ]; then
  11527. $PRINTF "${RED}user \"$user\", expected \"$SUBSTUSER\" ${NORMAL}\n"
  11528. echo "$CMD0 &"
  11529. cat "$te0"
  11530. let numFAIL=numFAIL+1
  11531. listFAIL="$listFAIL $N"
  11532. else
  11533. $PRINTF "$OK\n"
  11534. let numOK=numOK+1
  11535. fi
  11536. set +vx
  11537. fi # NUMCOND
  11538. ;;
  11539. esac
  11540. PORT=$((PORT+1))
  11541. N=$((N+1))
  11542. #
  11543. done <<<"
  11544. # address fileopt addropts waitfor direction
  11545. create . . file -U
  11546. open . creat file .
  11547. gopen . creat file .
  11548. unix-listen . . unixport .
  11549. unix-recvfrom . . unixport .
  11550. unix-recv . . unixport -u
  11551. pipe . . file -u
  11552. pty link . file .
  11553. "
  11554. # tests: is "passive" filesystem entry removed at the end? (without fork)
  11555. while read addr fileopt addropts proto diropt crit ADDR2; do
  11556. if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
  11557. # some passive (listening...) filesystem based addresses did not remove the file
  11558. # system entry at the end
  11559. ADDR=$(toupper $addr)
  11560. ADDR_=${ADDR/-/_}
  11561. PROTO=$(toupper $proto)
  11562. if [ "$diropt" = "." ]; then diropt=; fi
  11563. if [ "$fileopt" = "." ]; then fileopt=; fi
  11564. if [ "$addropts" = "." ]; then addropts=; fi
  11565. # $ADDR removes the file system entry when the process is terminated
  11566. NAME=${ADDR_}_REMOVE
  11567. case "$TESTS" in
  11568. *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
  11569. TEST="$NAME: $ADDR removes socket entry when terminated during accept"
  11570. # start a socat process with listening unix domain socket etc. Terminate the
  11571. # process and check if the file system socket entry still exists.
  11572. # Test succeeds when entry does not exist.
  11573. if ! eval $NUMCOND; then :; else
  11574. tlog="$td/test$N.log"
  11575. te0="$td/test$N.0.stderr"
  11576. tsock="$td/test$N.sock"
  11577. if [ -z "$fileopt" ]; then
  11578. CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts $ADDR2"
  11579. else
  11580. CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts $ADDR2"
  11581. fi
  11582. printf "test $F_n $TEST... " $N
  11583. $CMD0 >/dev/null 2>"$te0" &
  11584. pid0=$!
  11585. wait${proto} "$crit" $tsock 1 2>"$tlog"
  11586. kill $pid0 2>>"$tlog"
  11587. rc1=$?
  11588. wait >>"$tlog"
  11589. if [ $rc1 != 0 ]; then
  11590. $PRINTF "${YELLOW}setup failed${NORMAL}\n"
  11591. echo "$CMD0 &"
  11592. cat "$te0"
  11593. cat "$tlog"
  11594. let numCANT=numCANT+1
  11595. elif ! [ $crit $tsock ]; then
  11596. $PRINTF "$OK\n"
  11597. let numOK=numOK+1
  11598. else
  11599. $PRINTF "$FAILED\n"
  11600. echo "$CMD0 &"
  11601. cat "$te0"
  11602. cat "$tlog"
  11603. let numFAIL=numFAIL+1
  11604. listFAIL="$listFAIL $N"
  11605. fi
  11606. fi # NUMCOND
  11607. ;;
  11608. esac
  11609. PORT=$((PORT+1))
  11610. N=$((N+1))
  11611. #
  11612. done <<<"
  11613. # address fileopt addropts waitfor direction crit ADDR2
  11614. unix-listen . . unixport . -e FILE:/dev/null
  11615. unix-recvfrom . . unixport . -e FILE:/dev/null
  11616. unix-recv . . unixport -u -e FILE:/dev/null
  11617. pipe . . file -u -e FILE:/dev/null
  11618. pty link . file . -L PIPE
  11619. "
  11620. # tests: is "passive" filesystem entry removed at the end? (with fork)
  11621. while read addr fileopt addropts proto diropt crit ADDR2; do
  11622. if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
  11623. # some passive (listening...) filesystem based addresses with fork did not remove
  11624. # the file system entry at the end
  11625. ADDR=$(toupper $addr)
  11626. ADDR_=${ADDR/-/_}
  11627. PROTO=$(toupper $proto)
  11628. if [ "$diropt" = "." ]; then diropt=; fi
  11629. if [ "$fileopt" = "." ]; then fileopt=; fi
  11630. if [ "$addropts" = "." ]; then addropts=; fi
  11631. # $ADDR with fork removes the file system entry when the process is terminated
  11632. NAME=${ADDR_}_REMOVE_FORK
  11633. case "$TESTS" in
  11634. *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
  11635. TEST="$NAME: $ADDR with fork removes socket entry when terminated during accept"
  11636. # start a socat process with listening unix domain socket etc and option fork.
  11637. # Terminate the process and check if the file system socket entry still exists.
  11638. # Test succeeds when entry does not exist.
  11639. if ! eval $NUMCOND; then :; else
  11640. tlog="$td/test$N.log"
  11641. te0="$td/test$N.0.stderr"
  11642. tsock="$td/test$N.sock"
  11643. if [ -z "$fileopt" ]; then
  11644. CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,fork,$addropts $ADDR2"
  11645. else
  11646. CMD0="$TRACE $SOCAT $opts $diropt $ADDR,fork,$fileopt=$tsock,$addropts $ADDR2"
  11647. fi
  11648. printf "test $F_n $TEST... " $N
  11649. $CMD0 >/dev/null 2>"$te0" &
  11650. pid0=$!
  11651. wait${proto} "$crit" $tsock 1 2>"$tlog"
  11652. kill $pid0 2>>"$tlog"
  11653. rc1=$?
  11654. wait
  11655. if [ $rc1 != 0 ]; then
  11656. $PRINTF "${YELLOW}setup failed${NORMAL}\n"
  11657. echo "$CMD0 &"
  11658. cat "$te0"
  11659. cat "$tlog"
  11660. let numCANT=numCANT+1
  11661. elif ! [ $crit $tsock ]; then
  11662. $PRINTF "$OK\n"
  11663. let numOK=numOK+1
  11664. else
  11665. $PRINTF "$FAILED\n"
  11666. echo "$CMD0 &"
  11667. cat "$te0"
  11668. cat "$tlog"
  11669. let numFAIL=numFAIL+1
  11670. listFAIL="$listFAIL $N"
  11671. fi
  11672. fi # NUMCOND
  11673. ;;
  11674. esac
  11675. PORT=$((PORT+1))
  11676. N=$((N+1))
  11677. #
  11678. done <<<"
  11679. # address fileopt addropts waitfor direction crit ADDR2
  11680. unix-listen . . unixport . -e FILE:/dev/null
  11681. unix-recvfrom . . unixport . -e FILE:/dev/null
  11682. "
  11683. # bug fix: SYSTEM address child process shut down parents sockets including
  11684. # SSL connection under some circumstances.
  11685. NAME=SYSTEM_SHUTDOWN
  11686. case "$TESTS" in
  11687. *%$N%*|*%functions%*|*%bugs%*|*%system%*|*%openssl%*|*%socket%*|*%$NAME%*)
  11688. TEST="$NAME: SYSTEM address does not shutdown its parents addresses"
  11689. # start an OpenSSL echo server using SYSTEM:cat
  11690. # start an OpenSSL client that sends data
  11691. # when the client recieves its data and terminates without error the test succeeded
  11692. # in case of the bug the client issues an error like:
  11693. # SSL_connect(): error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
  11694. if ! eval $NUMCOND; then :;
  11695. elif ! testaddrs openssl >/dev/null; then
  11696. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  11697. numCANT=$((numCANT+1))
  11698. else
  11699. gentestcert testsrv
  11700. tf="$td/test$N.stdout"
  11701. te="$td/test$N.stderr"
  11702. tdiff="$td/test$N.diff"
  11703. da="test$N $(date) $RANDOM"
  11704. CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 SYSTEM:cat"
  11705. CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
  11706. printf "test $F_n $TEST... " $N
  11707. $CMD0 >/dev/null 2>"${te}0" &
  11708. pid0=$!
  11709. waittcp4port $PORT 1
  11710. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  11711. rc1=$?
  11712. kill $pid0 2>/dev/null; wait
  11713. if [ $rc1 -ne 0 ]; then
  11714. $PRINTF "$FAILED\n"
  11715. echo "rc1=$rc1"
  11716. echo "$CMD0 &"
  11717. echo "$CMD1"
  11718. cat "${te}0"
  11719. cat "${te}1"
  11720. numFAIL=$((numFAIL+1))
  11721. listFAIL="$listFAIL $N"
  11722. elif ! echo "$da" |diff - "${tf}1" >"$tdiff" 2>&1; then
  11723. $PRINTF "$FAILED\n"
  11724. echo "diff:"
  11725. cat "$tdiff"
  11726. echo "$CMD0 &"
  11727. echo "$CMD1"
  11728. cat "${te}0"
  11729. cat "${te}1"
  11730. numFAIL=$((numFAIL+1))
  11731. listFAIL="$listFAIL $N"
  11732. else
  11733. $PRINTF "$OK\n"
  11734. numOK=$((numOK+1))
  11735. fi
  11736. fi # NUMCOND
  11737. ;;
  11738. esac
  11739. PORT=$((PORT+1))
  11740. N=$((N+1))
  11741. # test if TCP4-LISTEN with empty port arg terminates with error
  11742. NAME=TCP4_NOPORT
  11743. case "$TESTS" in
  11744. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*)
  11745. TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out"
  11746. # run socat with TCP4-LISTEN with empty port arg. Check if it terminates
  11747. # immediately with return code 1
  11748. if ! eval $NUMCOND; then :; else
  11749. tf="$td/test$N.stdout"
  11750. te="$td/test$N.stderr"
  11751. t0rc="$td/test$N.rc"
  11752. tdiff="$td/test$N.diff"
  11753. da="test$N $(date) $RANDOM"
  11754. CMD0="$SOCAT $opts TCP4-LISTEN: /dev/null"
  11755. printf "test $F_n $TEST... " $N
  11756. { $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null
  11757. pid0=$!
  11758. sleep 1
  11759. kill $pid0 2>/dev/null; wait
  11760. if [ ! -f "$t0rc" ]; then
  11761. $PRINTF "$FAILED\n"
  11762. echo "no return code of CMD0 stored" >&2
  11763. echo "$CMD0 &"
  11764. cat "${te}0"
  11765. numFAIL=$((numFAIL+1))
  11766. listFAIL="$listFAIL $N"
  11767. elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then
  11768. $PRINTF "$FAILED\n"
  11769. echo "CMD0 exited with $(cat $t0rc), expected 1"
  11770. echo "$CMD0 &"
  11771. cat "${te}0"
  11772. numFAIL=$((numFAIL+1))
  11773. listFAIL="$listFAIL $N"
  11774. else
  11775. $PRINTF "$OK\n"
  11776. numOK=$((numOK+1))
  11777. fi
  11778. fi # NUMCOND
  11779. ;;
  11780. esac
  11781. PORT=$((PORT+1))
  11782. N=$((N+1))
  11783. # tests of various SSL methods:
  11784. OPENSSL_METHODS_OBSOLETE="SSL3 SSL23"
  11785. OPENSSL_METHODS_EXPECTED="TLS1 TLS1.1 TLS1.2 DTLS1"
  11786. # the OPENSSL_METHOD_DTLS1 test hangs sometimes, probably depending on the openssl version.
  11787. OPENSSL_VERSION="$(openssl version)"
  11788. OPENSSL_VERSION="${OPENSSL_VERSION#* }"
  11789. OPENSSL_VERSION="${OPENSSL_VERSION%%-*}"
  11790. OPENSSL_VERSION_GOOD=1.0.2 # this is just a guess.
  11791. # known bad: 1.0.1e
  11792. # known good: 1.0.2j
  11793. # test if the obsolete SSL methods can be used with OpenSSL
  11794. for method in $OPENSSL_METHODS_OBSOLETE; do
  11795. NAME=OPENSSL_METHOD_$method
  11796. case "$TESTS" in
  11797. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
  11798. TEST="$NAME: test OpenSSL method $method"
  11799. # Start a socat process with obsoelete OpenSSL method, it should fail
  11800. if ! eval $NUMCOND; then :;
  11801. elif ! testaddrs openssl >/dev/null; then
  11802. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  11803. numCANT=$((numCANT+1))
  11804. elif ! socat -hhh |grep -q "^[[:space:]]*openssl-method[[:space:]]"; then
  11805. $PRINTF "test $F_n $TEST... ${YELLOW}Option openssl-method not available${NORMAL}\n" $N
  11806. numCANT=$((numCANT+1))
  11807. else
  11808. gentestcert testsrv
  11809. tf="$td/test$N.stdout"
  11810. te="$td/test$N.stderr"
  11811. tdiff="$td/test$N.diff"
  11812. da="test$N $(date) $RANDOM"
  11813. CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,openssl-method=$method,cert=testsrv.pem,verify=0 PIPE"
  11814. CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,opensslmethod=$method,verify=0"
  11815. printf "test $F_n $TEST... " $N
  11816. if [ "$method" = DTLS1 -a "$(echo -e "$OPENSSL_VERSION\n1.0.2" |sort -V |tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
  11817. $PRINTF "${YELLOW}might hang, skipping${NORMAL}\n"
  11818. numCANT=$((numCANT+1))
  11819. else
  11820. $CMD0 >/dev/null 2>"${te}0" &
  11821. pid0=$!
  11822. waittcp4port $PORT 1 1 2>/dev/null; w0=$? # result of waiting for process 0
  11823. if [ $w0 -eq 0 ]; then
  11824. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  11825. rc1=$?
  11826. kill $pid0 2>/dev/null; wait
  11827. fi
  11828. if [ $w0 -eq 0 ] && echo "$da" |diff - "${tf}1"; then
  11829. $PRINTF "${YELLOW}WARN${NORMAL} (obsolete method succeeds)\n"
  11830. numOK=$((numOK+1))
  11831. else
  11832. $PRINTF "$OK (obsolete method fails)\n"
  11833. numOK=$((numOK+1))
  11834. fi
  11835. if [ "$VERBOSE" ]; then
  11836. echo " $CMD0"
  11837. echo " echo \"$da\" |$CMD1"
  11838. fi
  11839. fi # !DTLS1 hang
  11840. fi # NUMCOND
  11841. ;;
  11842. esac
  11843. PORT=$((PORT+1))
  11844. N=$((N+1))
  11845. done
  11846. # test if the various SSL methods can be used with OpenSSL
  11847. for method in $OPENSSL_METHODS_EXPECTED; do
  11848. NAME=OPENSSL_METHOD_$method
  11849. case "$TESTS" in
  11850. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
  11851. TEST="$NAME: test OpenSSL method $method"
  11852. # Start a socat process listening with OpenSSL and echoing data,
  11853. # using the selected method
  11854. # Start a second socat process connecting to the listener using
  11855. # the same method, send some data and catch the reply.
  11856. # If the reply is identical to the sent data the test succeeded.
  11857. if ! eval $NUMCOND; then :;
  11858. elif ! testaddrs openssl >/dev/null; then
  11859. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  11860. numCANT=$((numCANT+1))
  11861. elif ! socat -hhh |grep -q "^[[:space:]]*openssl-method[[:space:]]"; then
  11862. $PRINTF "test $F_n $TEST... ${YELLOW}Option openssl-method not available${NORMAL}\n" $N
  11863. numCANT=$((numCANT+1))
  11864. else
  11865. gentestcert testsrv
  11866. tf="$td/test$N.stdout"
  11867. te="$td/test$N.stderr"
  11868. tdiff="$td/test$N.diff"
  11869. da="test$N $(date) $RANDOM"
  11870. CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,openssl-method=$method,cert=testsrv.pem,verify=0 PIPE"
  11871. CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,openssl-method=$method,verify=0"
  11872. printf "test $F_n $TEST... " $N
  11873. if [ "$method" = DTLS1 -a "$(echo -e "$OPENSSL_VERSION\n1.0.2" |sort -V |tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
  11874. $PRINTF "${YELLOW}might hang, skipping${NORMAL}\n"
  11875. numCANT=$((numCANT+1))
  11876. else
  11877. $CMD0 >/dev/null 2>"${te}0" &
  11878. pid0=$!
  11879. waittcp4port $PORT 1
  11880. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  11881. rc1=$?
  11882. kill $pid0 2>/dev/null; wait
  11883. if echo "$da" |diff - "${tf}1"; then
  11884. $PRINTF "$OK\n"
  11885. numOK=$((numOK+1))
  11886. if [ "$VERBOSE" ]; then
  11887. echo " $CMD0"
  11888. echo " echo \"$da\" |$CMD1"
  11889. fi
  11890. else
  11891. $PRINTF "$FAILED\n"
  11892. echo "$CMD0 &"
  11893. echo "$CMD1"
  11894. cat "${te}0"
  11895. cat "${te}1"
  11896. numFAIL=$((numFAIL+1))
  11897. listFAIL="$listFAIL $N"
  11898. #esac
  11899. fi
  11900. fi # !DTLS1 hang
  11901. fi # NUMCOND
  11902. ;;
  11903. esac
  11904. PORT=$((PORT+1))
  11905. N=$((N+1))
  11906. done
  11907. # Address options fdin and fdout were silently ignored when not applicable
  11908. # due to -u or -U option. Now these combinations are caught as errors.
  11909. NAME=FDOUT_ERROR
  11910. case "$TESTS" in
  11911. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
  11912. TEST="$NAME: fdout bails out in write-only context"
  11913. # use EXEC in write-only context with option fdout. Expected behaviour: error
  11914. if ! eval $NUMCOND; then :; else
  11915. tf="$td/test$N.stdout"
  11916. te="$td/test$N.stderr"
  11917. tdiff="$td/test$N.diff"
  11918. da="test$N $(date) $RANDOM"
  11919. CMD="$SOCAT $opts -u /dev/null EXEC:cat,fdout=1"
  11920. printf "test $F_n $TEST... " $N
  11921. $CMD >/dev/null 2>"${te}"
  11922. rc=$?
  11923. if [ $rc -eq 1 ]; then
  11924. $PRINTF "$OK\n"
  11925. numOK=$((numOK+1))
  11926. else
  11927. $PRINTF "$FAILED\n"
  11928. echo "$CMD"
  11929. cat "${te}"
  11930. echo "command did not terminate with error!"
  11931. numFAIL=$((numFAIL+1))
  11932. listFAIL="$listFAIL $N"
  11933. fi
  11934. fi # NUMCOND
  11935. ;;
  11936. esac
  11937. PORT=$((PORT+1))
  11938. N=$((N+1))
  11939. # test if failure exit code of SYSTEM invocation causes socat to also exit
  11940. # with !=0
  11941. NAME=SYSTEM_RC
  11942. case "$TESTS" in
  11943. *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
  11944. TEST="$NAME: promote failure of SYSTEM"
  11945. # run socat with SYSTEM:false and check if socat exits with !=0
  11946. if ! eval $NUMCOND; then :; else
  11947. tf="$td/test$N.stdout"
  11948. te="$td/test$N.stderr"
  11949. tdiff="$td/test$N.diff"
  11950. da="test$N $(date) $RANDOM"
  11951. # shut-none makes sure that the child is not killed by parent
  11952. CMD0="$TRACE $SOCAT $opts - SYSTEM:false,shut-none"
  11953. printf "test $F_n $TEST... " $N
  11954. sleep 1 |$CMD0 >/dev/null 2>"${te}0"
  11955. rc0=$?
  11956. if [ $rc0 -eq 0 ]; then
  11957. $PRINTF "$FAILED\n"
  11958. echo "$CMD0"
  11959. cat "${te}0"
  11960. numFAIL=$((numFAIL+1))
  11961. listFAIL="$listFAIL $N"
  11962. else
  11963. $PRINTF "$OK\n"
  11964. numOK=$((numOK+1))
  11965. fi
  11966. fi # NUMCOND
  11967. ;;
  11968. esac
  11969. PORT=$((PORT+1))
  11970. N=$((N+1))
  11971. # test if failure exit code of EXEC invocation causes socat to also exit
  11972. # with !=0
  11973. NAME=EXEC_RC
  11974. case "$TESTS" in
  11975. *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
  11976. TEST="$NAME: promote failure of EXEC"
  11977. # run socat with EXEC:false and check if socat exits with !=0
  11978. if ! eval $NUMCOND; then :; else
  11979. tf="$td/test$N.stdout"
  11980. te="$td/test$N.stderr"
  11981. tdiff="$td/test$N.diff"
  11982. da="test$N $(date) $RANDOM"
  11983. # shut-none makes sure that the child is not killed by parent
  11984. CMD0="$TRACE $SOCAT $opts - EXEC:false,shut-none"
  11985. printf "test $F_n $TEST... " $N
  11986. sleep 1 |$CMD0 >/dev/null 2>"${te}0"
  11987. rc0=$?
  11988. if [ $rc0 -eq 0 ]; then
  11989. $PRINTF "$FAILED\n"
  11990. echo "$CMD0"
  11991. cat "${te}0"
  11992. numFAIL=$((numFAIL+1))
  11993. listFAIL="$listFAIL $N"
  11994. else
  11995. $PRINTF "$OK\n"
  11996. numOK=$((numOK+1))
  11997. fi
  11998. fi # NUMCOND
  11999. ;;
  12000. esac
  12001. PORT=$((PORT+1))
  12002. N=$((N+1))
  12003. # test the so-reuseaddr option
  12004. NAME=SO_REUSEADDR
  12005. case "$TESTS" in
  12006. *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
  12007. TEST="$NAME: test the so-reuseaddr option"
  12008. # process 0 provides a tcp listening socket with so-reuseaddr;
  12009. # process 1 connects to this port; thus the port is connected but no longer
  12010. # listening
  12011. # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
  12012. # SO_REUSEADDR socket options did not work
  12013. # process 3 connects to this port; only if it is successful the test is ok
  12014. if ! eval $NUMCOND; then :;
  12015. elif ! feat=$(testoptions so-reuseaddr); then
  12016. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  12017. numCANT=$((numCANT+1))
  12018. else
  12019. tp="$PORT"
  12020. tf="$td/test$N.stdout"
  12021. te="$td/test$N.stderr"
  12022. tdiff="$td/test$N.diff"
  12023. da="test$N $(date) $RANDOM"
  12024. CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,$REUSEADDR PIPE"
  12025. CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
  12026. CMD2="$CMD0"
  12027. CMD3="$CMD1"
  12028. printf "test $F_n $TEST... " $N
  12029. $CMD0 >/dev/null 2>"${te}0" &
  12030. pid0=$!
  12031. waittcp4port $tp 1
  12032. (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
  12033. pid1=$!
  12034. usleep 1000000
  12035. $CMD2 >/dev/null 2>"${te}2" &
  12036. pid2=$!
  12037. waittcp4port $tp 1
  12038. (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
  12039. rc3=$?
  12040. kill $pid0 $pid1 $pid2 2>/dev/null; wait
  12041. if ! echo "$da" |diff - "$tf"; then
  12042. $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
  12043. echo "$CMD0 &"
  12044. echo "$CMD1"
  12045. numCANT=$((numCANT+1))
  12046. elif [ $rc3 -ne 0 ]; then
  12047. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  12048. echo "$CMD0 &"
  12049. echo "$CMD1"
  12050. echo "$CMD2 &"
  12051. echo "$CMD3"
  12052. cat "${te}2" "${te}3"
  12053. numFAIL=$((numFAIL+1))
  12054. listFAIL="$listFAIL $N"
  12055. elif ! echo "$da" |diff - "${tf}3"; then
  12056. $PRINTF "$FAILED: $TRACE $SOCAT:\n"
  12057. echo "$CMD0 &"
  12058. echo "$CMD1"
  12059. echo "$CMD2 &"
  12060. echo "$CMD3"
  12061. echo "$da" |diff - "${tf}3"
  12062. numCANT=$((numCANT+1))
  12063. else
  12064. $PRINTF "$OK\n"
  12065. if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
  12066. numOK=$((numOK+1))
  12067. fi
  12068. fi # NUMCOND, SO_REUSEADDR
  12069. ;;
  12070. esac
  12071. PORT=$((PORT+1))
  12072. N=$((N+1))
  12073. # test the so-reuseport option
  12074. NAME=SO_REUSEPORT
  12075. case "$TESTS" in
  12076. *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
  12077. TEST="$NAME: test the so-reuseport option"
  12078. # process 0 provides a tcp listening socket with so-reuseport;
  12079. # process 1 provides an equivalent tcp listening socket with so-reuseport;
  12080. # process 2 connects to this port and transfers data
  12081. # process 3 connects to this port and transfers data
  12082. # test succeeds when both data transfers work
  12083. if ! eval $NUMCOND; then :;
  12084. elif ! feat=$(testoptions so-reuseport); then
  12085. $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
  12086. numCANT=$((numCANT+1))
  12087. else
  12088. tp="$PORT"
  12089. tf="$td/test$N.stdout"
  12090. te="$td/test$N.stderr"
  12091. tdiff="$td/test$N.diff"
  12092. da2="test$N $(date) $RANDOM"
  12093. da3="test$N $(date) $RANDOM"
  12094. CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,$REUSEADDR,so-reuseport PIPE"
  12095. CMD1="$CMD0"
  12096. CMD2="$TRACE $SOCAT $opts - TCP:localhost:$tp"
  12097. CMD3="$CMD2"
  12098. printf "test $F_n $TEST... " $N
  12099. $CMD0 >/dev/null 2>"${te}0" &
  12100. pid0=$!
  12101. $CMD1 >/dev/null 2>"${te}1" &
  12102. pid1=$!
  12103. waittcp4port $tp 1
  12104. (echo "$da2") |$CMD2 >"${tf}2" 2>"${te}2" # this should always work
  12105. rc2=$?
  12106. (echo "$da3") |$CMD3 >"${tf}3" 2>"${te}3"
  12107. rc3=$?
  12108. kill $pid0 $pid1 $pid2 2>/dev/null; wait
  12109. if ! echo "$da2" |diff - "${tf}2"; then
  12110. $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
  12111. echo "$CMD0 &"
  12112. cat "${te}0"
  12113. echo "$CMD1 &"
  12114. cat "${te}1"
  12115. echo "$CMD2"
  12116. cat "${te}2"
  12117. numCANT=$((numCANT+1))
  12118. elif [ $rc3 -ne 0 ]; then
  12119. $PRINTF "$FAILED:\n"
  12120. echo "$CMD0 &"
  12121. cat "${te}0"
  12122. echo "$CMD1 &"
  12123. cat "${te}1"
  12124. echo "$CMD2"
  12125. cat "${te}2"
  12126. echo "$CMD3"
  12127. cat "${te}3"
  12128. numFAIL=$((numFAIL+1))
  12129. listFAIL="$listFAIL $N"
  12130. elif ! echo "$da2" |diff - "${tf}2"; then
  12131. $PRINTF "$FAILED:\n"
  12132. echo "$CMD0 &"
  12133. cat "${te}0"
  12134. echo "$CMD1 &"
  12135. cat "${te}1"
  12136. echo "$CMD2"
  12137. cat "${te}2"
  12138. echo "$CMD3"
  12139. cat "${te}3"
  12140. echo "$da2" |diff - "${tf}2"
  12141. numFAIL=$((numFAIL+1))
  12142. listFAIL="$listFAIL $N"
  12143. elif ! echo "$da3" |diff - "${tf}3"; then
  12144. $PRINTF "$FAILED:\n"
  12145. echo "$CMD0 &"
  12146. cat "${te}0"
  12147. echo "$CMD1 &"
  12148. cat "${te}1"
  12149. echo "$CMD2"
  12150. cat "${te}2"
  12151. echo "$CMD3"
  12152. cat "${te}3"
  12153. echo "$da3" |diff - "${tf}3"
  12154. numFAIL=$((numFAIL+1))
  12155. listFAIL="$listFAIL $N"
  12156. else
  12157. $PRINTF "$OK\n"
  12158. if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
  12159. numOK=$((numOK+1))
  12160. fi
  12161. fi # NUMCOND, SO_REUSEPORT
  12162. ;;
  12163. esac
  12164. PORT=$((PORT+1))
  12165. N=$((N+1))
  12166. # Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped.
  12167. NAME=EXEC_NOFORK_UNIDIR
  12168. case "$TESTS" in
  12169. *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
  12170. TEST="$NAME: Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped"
  12171. # invoke a simple echo command with EXEC, nofork, and -u
  12172. # expected behaviour: output appears on stdout
  12173. if ! eval $NUMCOND; then :; else
  12174. tf="$td/test$N.stdout"
  12175. te="$td/test$N.stderr"
  12176. tdiff="$td/test$N.diff"
  12177. da="test$N $(date) $RANDOM"
  12178. CMD0="$TRACE $SOCAT $opts -u /dev/null EXEC:\"echo \\\\\\\"\\\"$da\\\"\\\\\\\"\",nofork"
  12179. printf "test $F_n $TEST... " $N
  12180. eval "$CMD0" >"${tf}0" 2>"${te}0"
  12181. rc1=$?
  12182. if echo "$da" |diff - "${tf}0" >"$tdiff"; then
  12183. $PRINTF "$OK\n"
  12184. numOK=$((numOK+1))
  12185. else
  12186. $PRINTF "$FAILED\n"
  12187. echo "$CMD0"
  12188. cat "${te}0"
  12189. cat "$tdiff"
  12190. numFAIL=$((numFAIL+1))
  12191. listFAIL="$listFAIL $N"
  12192. fi
  12193. fi # NUMCOND
  12194. ;;
  12195. esac
  12196. #PORT=$((PORT+1))
  12197. N=$((N+1))
  12198. # OpenSSL ECDHE ciphers were introduced in socat 1.7.3.0 but in the same release
  12199. # they were broken by a porting effort. This test checks if OpenSSL ECDHE works
  12200. # 2019-02: this does no longer work (Ubuntu-18.04)
  12201. NAME=OPENSSL_ECDHE
  12202. case "$TESTS" in
  12203. *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
  12204. TEST="$NAME: test OpenSSL ECDHE"
  12205. # generate a ECDHE key, start an OpenSSL server, connect with a client and try to
  12206. # pass data
  12207. if ! eval $NUMCOND; then :;
  12208. elif ! testaddrs openssl >/dev/null; then
  12209. $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
  12210. numCANT=$((numCANT+1))
  12211. else
  12212. tf="$td/test$N.stdout"
  12213. te="$td/test$N.stderr"
  12214. tdiff="$td/test$N.diff"
  12215. da="test$N $(date) $RANDOM"
  12216. #TESTSRV=./testsrvec; gentesteccert $TESTSRV
  12217. TESTSRV=./testsrv; gentestcert $TESTSRV
  12218. CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$TESTSRV.crt,key=$TESTSRV.pem,verify=0 PIPE"
  12219. CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,cipher=ECDHE-ECDSA-AES256-GCM-SHA384,cafile=$TESTSRV.crt,verify=0"
  12220. printf "test $F_n $TEST... " $N
  12221. $CMD0 >/dev/null 2>"${te}0" &
  12222. pid0=$!
  12223. waittcp4port $PORT 1
  12224. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  12225. rc1=$?
  12226. kill $pid0 2>/dev/null; wait
  12227. if [ $rc1 -ne 0 ]; then
  12228. $PRINTF "$FAILED\n"
  12229. echo "failure symptom: client error" >&2
  12230. echo "server and stderr:" >&2
  12231. echo "$CMD0 &"
  12232. cat "${te}0"
  12233. echo "client and stderr:" >&2
  12234. echo "$CMD1"
  12235. cat "${te}1"
  12236. numFAIL=$((numFAIL+1))
  12237. listFAIL="$listFAIL $N"
  12238. elif echo "$da" |diff - "${tf}1" >"$tdiff"; then
  12239. $PRINTF "$OK\n"
  12240. numOK=$((numOK+1))
  12241. else
  12242. $PRINTF "$FAILED\n"
  12243. echo "server and stderr:" >&2
  12244. echo "$CMD1"
  12245. cat "${te}1"
  12246. echo "client and stderr:" >&2
  12247. echo "$CMD0 &"
  12248. cat "${te}0"
  12249. numFAIL=$((numFAIL+1))
  12250. listFAIL="$listFAIL $N"
  12251. fi
  12252. fi # NUMCOND
  12253. ;;
  12254. esac
  12255. PORT=$((PORT+1))
  12256. N=$((N+1))
  12257. # option ipv6-join-group "could not be used"
  12258. # fixed in 1.7.3.2
  12259. NAME=USE_IPV6_JOIN_GROUP
  12260. case "$TESTS" in
  12261. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%ip6%*|*%udp%*|*%udp6%*|*%dgram%*|*%$NAME%*)
  12262. TEST="$NAME: is option ipv6-join-group used"
  12263. # Invoke socat with option ipv6-join-group on UDP6 address.
  12264. # Terminate immediately, do not transfer data.
  12265. # If socat exits with 0 the test succeeds.
  12266. # Up to 1.7.3.1 it failed with "1 option(s) could not be used"
  12267. if ! eval $NUMCOND; then :; else
  12268. tf="$td/test$N.stdout"
  12269. te="$td/test$N.stderr"
  12270. tdiff="$td/test$N.diff"
  12271. da="test$N $(date) $RANDOM"
  12272. CMD0="$TRACE $SOCAT $opts UDP6-RECV:$PORT,ipv6-join-group=[ff02::2]:$MCINTERFACE /dev/null"
  12273. printf "test $F_n $TEST... " $N
  12274. $CMD0 >/dev/null 2>"${te}0"
  12275. rc0=$?
  12276. if [ $rc0 -eq 0 ]; then
  12277. $PRINTF "$OK\n"
  12278. numOK=$((numOK+1))
  12279. else
  12280. $PRINTF "$FAILED\n"
  12281. echo "$CMD0"
  12282. cat "${te}0"
  12283. numFAIL=$((numFAIL+1))
  12284. listFAIL="$listFAIL $N"
  12285. fi
  12286. fi # NUMCOND
  12287. ;;
  12288. esac
  12289. PORT=$((PORT+1))
  12290. N=$((N+1))
  12291. # The fix to "Make code async-signal-safe" used internally FD 3 and FD 4.
  12292. # Using option fdin=3 did not pass data to executed program.
  12293. NAME=DIAG_FDIN
  12294. case "$TESTS" in
  12295. *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
  12296. TEST="$NAME: test use of fdin=3"
  12297. # Use FD 3 explicitely with fdin and test if Socat passes data to executed
  12298. # program
  12299. if ! eval $NUMCOND; then :; else
  12300. tf="$td/test$N.stdout"
  12301. te="$td/test$N.stderr"
  12302. tdiff="$td/test$N.diff"
  12303. da="test$N $(date) $RANDOM"
  12304. CMD0="$TRACE $SOCAT $opts - SYSTEM:\"cat >&3 <&4\",fdin=4,fdout=3"
  12305. printf "test $F_n $TEST... " $N
  12306. echo "$da" |$TRACE $SOCAT $opts - SYSTEM:"cat <&3 >&4",fdin=3,fdout=4 >${tf}0 2>"${te}0"
  12307. rc0=$?
  12308. if [ $rc0 -ne 0 ]; then
  12309. $PRINTF "$FAILED\n"
  12310. echo "$CMD0"
  12311. cat "${te}0"
  12312. numFAIL=$((numFAIL+1))
  12313. listFAIL="$listFAIL $N"
  12314. elif echo "$da" |diff - ${tf}0 >$tdiff; then
  12315. $PRINTF "$OK\n"
  12316. numOK=$((numOK+1))
  12317. else
  12318. $PRINTF "$FAILED\n"
  12319. echo "$CMD0"
  12320. cat "${te}0"
  12321. cat "$tdiff"
  12322. numFAIL=$((numFAIL+1))
  12323. listFAIL="$listFAIL $N"
  12324. fi
  12325. fi # NUMCOND
  12326. ;;
  12327. esac
  12328. PORT=$((PORT+1))
  12329. N=$((N+1))
  12330. NAME=SOCAT_OPT_HINT
  12331. case "$TESTS" in
  12332. *%$N%*|*%functions%*|*%$NAME%*)
  12333. TEST="$NAME: check if merging single character options is rejected"
  12334. if ! eval $NUMCOND; then :; else
  12335. te="$td/test$N.stderr"
  12336. CMD0="$TRACE $SOCAT $opts -vx FILE:/dev/null ECHO"
  12337. printf "test $F_n $TEST... " $N
  12338. $CMD0 >/dev/null 2>"${te}0"
  12339. rc0=$?
  12340. if [ "$rc0" = "1" ]; then
  12341. $PRINTF "$OK\n"
  12342. numOK=$((numOK+1))
  12343. else
  12344. $PRINTF "$FAILED\n"
  12345. echo "$CMD0" >&2
  12346. numFAIL=$((numFAIL+1))
  12347. listFAIL="$listFAIL $N"
  12348. fi
  12349. fi ;; # NUMCOND
  12350. esac
  12351. N=$((N+1))
  12352. # test for a bug in Socat version 1.7.3.3 where
  12353. # termios options of the first address were applied to the second address.
  12354. NAME=TERMIOS_PH_ALL
  12355. case "$TESTS" in
  12356. *%$N%*|*%functions%*|*%bugs%*|*%termios%*|*%$NAME%*)
  12357. TEST="$NAME: are termios options applied to the correct address"
  12358. # add a termios option to the first address, a tty, and have a second address
  12359. # with pipe. If no error occurs the termios option was not applied to the pipe,
  12360. # thus the test succeeded.
  12361. if ! eval $NUMCOND; then :; else
  12362. tf="$td/test$N.stdout"
  12363. te="$td/test$N.stderr"
  12364. tdiff="$td/test$N.diff"
  12365. da="test$N $(date) $RANDOM"
  12366. CMD0="$TRACE $SOCAT $opts -T 1 STDIO,echo=0 EXEC:cat"
  12367. echo "$CMD0" >$td/test$N.sh
  12368. chmod a+x $td/test$N.sh
  12369. printf "test $F_n $TEST... " $N
  12370. $SOCAT /dev/null EXEC:$td/test$N.sh,pty 2>"${te}0"
  12371. rc0=$?
  12372. if [ $rc0 -eq 0 ]; then
  12373. $PRINTF "$OK\n"
  12374. numOK=$((numOK+1))
  12375. else
  12376. $PRINTF "$FAILED\n"
  12377. echo "$CMD0"
  12378. cat "${te}0"
  12379. numFAIL=$((numFAIL+1))
  12380. listFAIL="$listFAIL $N"
  12381. fi
  12382. fi # NUMCOND
  12383. ;;
  12384. esac
  12385. PORT=$((PORT+1))
  12386. N=$((N+1))
  12387. # Due to a fallback logic before calling getaddrinfo(), intended to allow use
  12388. # of service (port) names with SCTP, raw socket addresses where resolved with
  12389. # socket type stream, which fails for protocol 6 (TCP)
  12390. # Fixed after 1.7.3.3
  12391. NAME=IP_SENDTO_6
  12392. case "$TESTS" in
  12393. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%rawip%*|*%rawip4%*|*%$NAME%*)
  12394. TEST="$NAME: IP-SENDTO::6 passes getaddrinfo()"
  12395. # invoke socat with address IP-SENDTO:*:6; when this does not fail with
  12396. # "ai_socktype not supported", the test succeeded
  12397. if ! eval $NUMCOND; then :; else
  12398. tf="$td/test$N.stdout"
  12399. te="$td/test$N.stderr"
  12400. tdiff="$td/test$N.diff"
  12401. CMD0="$TRACE $SOCAT $opts -u /dev/null IP-SENDTO:127.0.0.1:6"
  12402. printf "test $F_n $TEST... " $N
  12403. $CMD0 >/dev/null 2>"${te}0"
  12404. if ! grep -q "ai_socktype not supported" ${te}0; then
  12405. $PRINTF "$OK\n"
  12406. numOK=$((numOK+1))
  12407. else
  12408. $PRINTF "$FAILED\n"
  12409. echo "$CMD0"
  12410. cat "${te}0"
  12411. numFAIL=$((numFAIL+1))
  12412. listFAIL="$listFAIL $N"
  12413. fi
  12414. fi # NUMCOND
  12415. ;;
  12416. esac
  12417. N=$((N+1))
  12418. # test if the multiple EOF messages are fixed
  12419. NAME=MULTIPLE_EOF
  12420. case "$TESTS" in
  12421. *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
  12422. TEST="$NAME: multiple EOF messages"
  12423. # start two processes, connected via UNIX socket. The listener gets EOF from local address immediately; the second process then sends data. If the listener reports "socket 1 (fd .*) is at EOF" only once, the test succeeded
  12424. if ! eval $NUMCOND; then :; else
  12425. ts="$td/test$N.sock"
  12426. tf="$td/test$N.stdout"
  12427. te="$td/test$N.stderr"
  12428. tdiff="$td/test$N.diff"
  12429. da="test$N $(date) $RANDOM"
  12430. CMD0="$TRACE $SOCAT $opts -d -d UNIX-LISTEN:$ts /dev/null"
  12431. CMD1="$TRACE $SOCAT $opts -d -d - UNIX-CONNECT:$ts"
  12432. printf "test $F_n $TEST... " $N
  12433. $CMD0 >/dev/null 2>"${te}0" &
  12434. pid0=$!
  12435. waitunixport $ts 1
  12436. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  12437. rc1=$?
  12438. kill $pid0 2>/dev/null; wait
  12439. if [ $(grep "socket 2 (fd .*) is at EOF" ${te}0 |wc -l) -eq 1 ]; then
  12440. $PRINTF "$OK\n"
  12441. numOK=$((numOK+1))
  12442. else
  12443. $PRINTF "$FAILED\n"
  12444. echo "$CMD0 &"
  12445. echo "$CMD1"
  12446. cat "${te}0"
  12447. cat "${te}1"
  12448. numFAIL=$((numFAIL+1))
  12449. listFAIL="$listFAIL $N"
  12450. fi
  12451. fi # NUMCOND
  12452. ;;
  12453. esac
  12454. N=$((N+1))
  12455. ##################################################################################
  12456. #=================================================================================
  12457. # here come tests that might affect your systems integrity. Put normal tests
  12458. # before this paragraph.
  12459. # tests must be explicitely selected by roottough or name (not number)
  12460. NAME=PTYGROUPLATE
  12461. case "$TESTS" in
  12462. *%roottough%*|*%$NAME%*)
  12463. TEST="$NAME: pty with group-late works on pty"
  12464. # up to socat 1.7.1.1 address pty changed the ownership of /dev/ptmx instead of
  12465. # the pty with options user-late, group-late, or perm-late.
  12466. # here we check for correct behaviour.
  12467. # ATTENTION: in case of failure of this test the
  12468. # group of /dev/ptmx might be changed!
  12469. if ! eval $NUMCOND; then :; else
  12470. # save current /dev/ptmx properties
  12471. F=
  12472. for f in /dev/ptmx /dev/ptc; do
  12473. if [ -e $f ]; then
  12474. F=$(echo "$f" |tr / ..)
  12475. ls -l $f >"$td/test$N.$F.ls-l"
  12476. break
  12477. fi
  12478. done
  12479. printf "test $F_n $TEST... " $N
  12480. if [ -z "$F" ]; then
  12481. echo -e "${YELLOW}no /dev/ptmx or /dev/ptc${NORMAL}"
  12482. else
  12483. GROUP=daemon
  12484. tf="$td/test$N.stdout"
  12485. te="$td/test$N.stderr"
  12486. tl="$td/test$N.pty"
  12487. tdiff="$td/test$N.diff"
  12488. da="test$N $(date) $RANDOM"
  12489. CMD0="$TRACE $SOCAT $opts pty,link=$tl,group-late=$GROUP,escape=0x1a PIPE"
  12490. CMD1="$TRACE $SOCAT $opts - $tl,raw,echo=0"
  12491. $CMD0 >/dev/null 2>"${te}0" &
  12492. pid0=$!
  12493. (echo "$da"; usleep $MICROS; echo -e "\x1a") |$CMD1 >"${tf}1" 2>"${te}1" >"$tf"
  12494. rc1=$?
  12495. kill $pid0 2>/dev/null; wait
  12496. if [ $rc1 -ne 0 ]; then
  12497. $PRINTF "$FAILED\n"
  12498. echo "$CMD0 &"
  12499. echo "$CMD1"
  12500. cat "${te}0"
  12501. cat "${te}1"
  12502. numFAIL=$((numFAIL+1))
  12503. listFAIL="$listFAIL $N"
  12504. elif echo "$da" |diff - "$tf" >$tdiff; then
  12505. $PRINTF "$OK\n"
  12506. numOK=$((numOK+1))
  12507. else
  12508. $PRINTF "$FAILED\n"
  12509. cat "$tdiff"
  12510. numFAIL=$((numFAIL+1))
  12511. listFAIL="$listFAIL $N"
  12512. fi
  12513. if ! ls -l $f |diff "$td/test$N.$F.ls-l" -; then
  12514. $PRINTF "${RED}this test changed properties of $f!${NORMAL}\n"
  12515. fi
  12516. fi # no /dev/ptmx
  12517. fi # NUMCOND
  12518. ;;
  12519. esac
  12520. N=$((N+1))
  12521. echo "summary: $((N-1)) tests, $((numOK+numFAIL+numCANT)) selected; $numOK ok, $numFAIL failed, $numCANT could not be performed"
  12522. if [ "$numFAIL" -gt 0 ]; then
  12523. echo "FAILED: $listFAIL"
  12524. exit 1
  12525. fi
  12526. exit 0
  12527. #==============================================================================
  12528. rm -f testsrv.* testcli.* testsrvdsa* testsrvfips* testclifips*
  12529. # end
  12530. # too dangerous - run as root and having a shell problem, it might purge your
  12531. # file systems
  12532. #rm -r "$td"
  12533. # sometimes subprocesses hang; we want to see this
  12534. wait
  12535. exit
  12536. # test template
  12537. # give a description of what is tested (a bugfix, a new feature...)
  12538. NAME=SHORT_UNIQUE_TESTNAME
  12539. case "$TESTS" in
  12540. *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
  12541. TEST="$NAME: give a one line description of test"
  12542. # describe how the test is performed, and what's the success criteria
  12543. if ! eval $NUMCOND; then :; else
  12544. tf="$td/test$N.stdout"
  12545. te="$td/test$N.stderr"
  12546. tdiff="$td/test$N.diff"
  12547. da="test$N $(date) $RANDOM"
  12548. CMD0="$TRACE $SOCAT $opts server-address PIPE"
  12549. CMD1="$TRACE $SOCAT $opts - client-address"
  12550. printf "test $F_n $TEST... " $N
  12551. $CMD0 >/dev/null 2>"${te}0" &
  12552. pid0=$!
  12553. wait<something>port $PORT 1
  12554. echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
  12555. rc1=$?
  12556. kill $pid0 2>/dev/null; wait
  12557. if [ !!! ]; then
  12558. $PRINTF "$OK\n"
  12559. numOK=$((numOK+1))
  12560. else
  12561. $PRINTF "$FAILED\n"
  12562. echo "$CMD0 &"
  12563. echo "$CMD1"
  12564. cat "${te}0"
  12565. cat "${te}1"
  12566. numFAIL=$((numFAIL+1))
  12567. listFAIL="$listFAIL $N"
  12568. fi
  12569. fi # NUMCOND
  12570. ;;
  12571. esac
  12572. PORT=$((PORT+1))
  12573. N=$((N+1))