Download | Plain Text | No Line Numbers


  1. --- FILES 14 Jun 2002 08:47:30 -0000 1.1.1.1
  2. +++ FILES 5 Apr 2004 15:34:57 -0000 1.2
  3. @@ -216,3 +216,19 @@
  4. warn-auto.sh
  5. warn-shsgr
  6. x86cpuid.c
  7. +addcr.1
  8. +argv0.1
  9. +date@.1
  10. +delcr.1
  11. +finger@.1
  12. +fixcrio.1
  13. +http@.1
  14. +mconnect.1
  15. +recordio.1
  16. +tcpcat.1
  17. +tcpclient.1
  18. +tcprules.1
  19. +tcprulescheck.1
  20. +tcpserver.1
  21. +who@.1
  22. +tcp-environ.5
  23. --- Makefile 14 Jun 2002 08:47:30 -0000 1.1.1.1
  24. +++ Makefile 5 Apr 2004 15:34:57 -0000 1.3
  25. @@ -1,5 +1,13 @@
  26. # Don't edit Makefile! Use conf-* for configuration.
  27.  
  28. +DEFINES=-DWITH_SSL
  29. +#add -DWITH_SSL to enable ssl support
  30. +
  31. +# LIBS for additional libraries and INCS for additional includes
  32. +LIBS=-lcrypto -lssl
  33. +#INCS=-I/usr/local/include
  34. +OPENSSLBIN=openssl
  35. +
  36. SHELL=/bin/sh
  37.  
  38. default: it
  39. @@ -745,7 +753,7 @@
  40. load tcpserver.o rules.o remoteinfo.o timeoutconn.o cdb.a dns.a \
  41. time.a unix.a byte.a socket.lib
  42. ./load tcpserver rules.o remoteinfo.o timeoutconn.o cdb.a \
  43. - dns.a time.a unix.a byte.a `cat socket.lib`
  44. + dns.a time.a unix.a byte.a $(LIBS) `cat socket.lib`
  45.  
  46. tcpserver.o: \
  47. compile tcpserver.c uint16.h str.h byte.h fmt.h scan.h ip4.h fd.h \
  48. @@ -754,7 +762,7 @@
  49. socket.h uint16.h ndelay.h remoteinfo.h stralloc.h uint16.h rules.h \
  50. stralloc.h sig.h dns.h stralloc.h iopause.h taia.h tai.h uint64.h \
  51. taia.h
  52. - ./compile tcpserver.c
  53. + ./compile $(DEFINES) $(INCS) tcpserver.c
  54.  
  55. time.a: \
  56. makelib iopause.o tai_pack.o taia_add.o taia_approx.o taia_frac.o \
  57. @@ -835,3 +843,21 @@
  58. | sed s}HOME}"`head -1 conf-home`"}g \
  59. > who@
  60. chmod 755 who@
  61. +
  62. +clean:
  63. + rm -f `cat TARGETS`
  64. +
  65. +cert:
  66. + ${OPENSSLBIN} req -new -x509 -nodes \
  67. + -out cert.pem -days 366 \
  68. + -keyout cert.pem
  69. +
  70. +cert-req:
  71. + ${OPENSSLBIN} req -new -nodes \
  72. + -out req.pem \
  73. + -keyout cert.pem
  74. + @echo
  75. + @echo "Send req.pem to your CA to obtain signed_req.pem, and do:"
  76. + @echo "cat signed_req.pem >> `head -1 conf-qmail`/control/cert.pem"
  77. +
  78. +
  79. --- /dev/null 1 Jan 1970 00:00:00 -0000
  80. +++ addcr.1 5 Apr 2004 15:34:57 -0000 1.1
  81. @@ -0,0 +1,22 @@
  82. +.TH addcr 1
  83. +.SH NAME
  84. +addcr \- add a CR before each LF
  85. +.SH SYNOPSIS
  86. +.B addcr
  87. +.SH DESCRIPTION
  88. +.B addcr
  89. +inserts CR at the end of each line of input.
  90. +It does not insert CR at the end of a partial final line.
  91. +.SH COMPATIBILITY
  92. +Some vendors ship
  93. +.B unix2dos
  94. +or
  95. +.B bsd2dos
  96. +tools similar to
  97. +.BR addcr .
  98. +Those tools often blow up on long lines and nulls.
  99. +.B addcr
  100. +has no trouble with long lines and nulls.
  101. +.SH "SEE ALSO"
  102. +delcr(1),
  103. +fixcrio(1)
  104. --- /dev/null 1 Jan 1970 00:00:00 -0000
  105. +++ argv0.1 5 Apr 2004 15:34:57 -0000 1.1
  106. @@ -0,0 +1,47 @@
  107. +.TH argv0 1
  108. +.SH NAME
  109. +argv0 \- run a program with a specified 0th argument
  110. +.SH SYNOPSIS
  111. +.B argv0
  112. +.I realname
  113. +.I zero
  114. +[
  115. +.I arg ...
  116. +]
  117. +.SH DESCRIPTION
  118. +.B argv0
  119. +runs
  120. +the program stored as
  121. +.I realname
  122. +on disk,
  123. +with the given
  124. +arguments.
  125. +It sets the 0th argument of
  126. +the program to
  127. +.IR zero .
  128. +
  129. +For example,
  130. +
  131. +.EX
  132. + argv0 /bin/csh -bin/csh
  133. +.EE
  134. +
  135. +runs
  136. +.B /bin/csh
  137. +with a 0th argument of
  138. +.BR -bin/csh .
  139. +.B csh
  140. +will think it is a login shell
  141. +and behave accordingly.
  142. +
  143. +.B argv0
  144. +can be used to run some
  145. +.B inetd
  146. +wrappers under
  147. +.BR tcpserver .
  148. +.SH "SEE ALSO"
  149. +csh(1),
  150. +tcpserver(1),
  151. +execve(2),
  152. +execvp(3),
  153. +inetd(8)
  154. --- /dev/null 1 Jan 1970 00:00:00 -0000
  155. +++ date@.1 5 Apr 2004 15:34:57 -0000 1.1
  156. @@ -0,0 +1,32 @@
  157. +.TH date@ 1
  158. +.SH NAME
  159. +date@ \- print the date on a host
  160. +.SH SYNTAX
  161. +.B date@
  162. +[
  163. +.I host
  164. +]
  165. +.SH DESCRIPTION
  166. +.B date@
  167. +connects to TCP port 13 (Daytime) on
  168. +.I host
  169. +and prints any data it receives.
  170. +It removes CR and converts unprintable characters to a visible format.
  171. +
  172. +If
  173. +.I host
  174. +is not supplied,
  175. +.B date@
  176. +connects to the local host.
  177. +
  178. +Some computers respond to port 13 with a human-readable date.
  179. +For example, they may be running
  180. +
  181. +.EX
  182. + tcpserver 0 13 date &
  183. +.EE
  184. +.SH "SEE ALSO"
  185. +cat(1),
  186. +delcr(1),
  187. +tcpclient(1),
  188. +tcpserver(1)
  189. --- /dev/null 1 Jan 1970 00:00:00 -0000
  190. +++ delcr.1 5 Apr 2004 15:34:57 -0000 1.1
  191. @@ -0,0 +1,30 @@
  192. +.TH delcr 1
  193. +.SH NAME
  194. +delcr \- remove a CR before each LF
  195. +.SH SYNOPSIS
  196. +.B delcr
  197. +.SH DESCRIPTION
  198. +.B delcr
  199. +removes a CR at the end of each line of input,
  200. +if a CR is present.
  201. +It also removes a CR at the end of a partial final line.
  202. +
  203. +The pipeline
  204. +
  205. +.EX
  206. + addcr | delcr
  207. +.EE
  208. +
  209. +prints an exact copy of its input.
  210. +.SH COMPATIBILITY
  211. +Some vendors ship
  212. +.B dos2unix
  213. +or
  214. +.B dos2bsd
  215. +tools similar to
  216. +.BR delcr .
  217. +Those tools often blow up on long lines and nulls.
  218. +.B delcr
  219. +has no trouble with long lines and nulls.
  220. +.SH "SEE ALSO"
  221. +addcr(1)
  222. --- error.h 14 Jun 2002 08:47:31 -0000 1.1.1.1
  223. +++ error.h 6 Nov 2003 09:47:05 -0000 1.2
  224. @@ -1,7 +1,7 @@
  225. #ifndef ERROR_H
  226. #define ERROR_H
  227.  
  228. -extern int errno;
  229. +#include <errno.h>
  230.  
  231. extern int error_intr;
  232. extern int error_nomem;
  233. --- /dev/null 1 Jan 1970 00:00:00 -0000
  234. +++ finger@.1 5 Apr 2004 15:34:57 -0000 1.1
  235. @@ -0,0 +1,45 @@
  236. +.TH finger@ 1
  237. +.SH NAME
  238. +finger@ \- get user information from a host
  239. +.SH SYNTAX
  240. +.B finger@
  241. +[
  242. +.I host
  243. +[
  244. +.I user
  245. +]
  246. +]
  247. +.SH DESCRIPTION
  248. +.B finger@
  249. +connects to TCP port 79 (Finger) on
  250. +.IR host ,
  251. +sends
  252. +.I user
  253. +(with an extra CR)
  254. +to
  255. +.IR host ,
  256. +and prints any data it receives.
  257. +It removes CR and converts unprintable characters to a visible format.
  258. +Some computers respond to port 79 with information about
  259. +.IR user .
  260. +
  261. +If
  262. +.I user
  263. +is not supplied,
  264. +.B finger@
  265. +sends a blank line to
  266. +.IR host .
  267. +Some computers respond with information about
  268. +all the users who are logged in.
  269. +
  270. +If
  271. +.I host
  272. +is not supplied,
  273. +.B finger@
  274. +connects to the local host.
  275. +.SH "SEE ALSO"
  276. +addcr(1),
  277. +cat(1),
  278. +delcr(1),
  279. +finger(1),
  280. +tcpclient(1)
  281. --- /dev/null 1 Jan 1970 00:00:00 -0000
  282. +++ fixcrio.1 5 Apr 2004 15:34:57 -0000 1.1
  283. @@ -0,0 +1,15 @@
  284. +.TH fixcrio 1
  285. +.SH NAME
  286. +fixcrio \- make sure that there is a CR before each LF
  287. +.SH SYNOPSIS
  288. +.B fixcrio
  289. +.I program
  290. +[
  291. +.I arg ...
  292. +]
  293. +.SH DESCRIPTION
  294. +.B fixcrio
  295. +inserts CR at the end of each line of input where a CR is not already present.
  296. +It does not insert CR at the end of a partial final line.
  297. +.SH "SEE ALSO"
  298. +addcr(1)
  299. --- hier.c 14 Jun 2002 08:47:32 -0000 1.1.1.1
  300. +++ hier.c 5 Apr 2004 15:34:57 -0000 1.2
  301. @@ -2,8 +2,11 @@
  302.  
  303. void hier()
  304. {
  305. - h(auto_home,-1,-1,02755);
  306. - d(auto_home,"bin",-1,-1,02755);
  307. + h(auto_home,-1,-1,0755);
  308. + d(auto_home,"bin",-1,-1,0755);
  309. + d(auto_home,"man",-1,-1,0755);
  310. + d(auto_home,"man/man1",-1,-1,0755);
  311. + d(auto_home,"man/man5",-1,-1,0755);
  312.  
  313. c(auto_home,"bin","tcpserver",-1,-1,0755);
  314. c(auto_home,"bin","tcprules",-1,-1,0755);
  315. @@ -22,4 +27,21 @@
  316. c(auto_home,"bin","delcr",-1,-1,0755);
  317. c(auto_home,"bin","fixcrio",-1,-1,0755);
  318. c(auto_home,"bin","rblsmtpd",-1,-1,0755);
  319. +
  320. + c(auto_home,"man/man1","addcr.1",-1,-1,0644);
  321. + c(auto_home,"man/man1","argv0.1",-1,-1,0644);
  322. + c(auto_home,"man/man1","date@.1",-1,-1,0644);
  323. + c(auto_home,"man/man1","delcr.1",-1,-1,0644);
  324. + c(auto_home,"man/man1","finger@.1",-1,-1,0644);
  325. + c(auto_home,"man/man1","fixcrio.1",-1,-1,0644);
  326. + c(auto_home,"man/man1","http@.1",-1,-1,0644);
  327. + c(auto_home,"man/man1","mconnect.1",-1,-1,0644);
  328. + c(auto_home,"man/man1","recordio.1",-1,-1,0644);
  329. + c(auto_home,"man/man1","tcpcat.1",-1,-1,0644);
  330. + c(auto_home,"man/man1","tcpclient.1",-1,-1,0644);
  331. + c(auto_home,"man/man1","tcprules.1",-1,-1,0644);
  332. + c(auto_home,"man/man1","tcprulescheck.1",-1,-1,0644);
  333. + c(auto_home,"man/man1","tcpserver.1",-1,-1,0644);
  334. + c(auto_home,"man/man1","who@.1",-1,-1,0644);
  335. + c(auto_home,"man/man5","tcp-environ.5",-1,-1,0644);
  336. }
  337. --- /dev/null 1 Jan 1970 00:00:00 -0000
  338. +++ http@.1 5 Apr 2004 15:34:57 -0000 1.1
  339. @@ -0,0 +1,52 @@
  340. +.TH http@ 1
  341. +.SH NAME
  342. +http@ \- get a web page from a host through HTTP
  343. +.SH SYNTAX
  344. +.B http@
  345. +[
  346. +.I host
  347. +[
  348. +.I page
  349. +[
  350. +.I port
  351. +]
  352. +]
  353. +]
  354. +.SH DESCRIPTION
  355. +.B http@
  356. +connects to
  357. +.I port
  358. +on
  359. +.IR host ,
  360. +sends
  361. +.B GET /\fIpage
  362. +(with an extra CR)
  363. +to
  364. +.IR host ,
  365. +and prints any data it receives,
  366. +removing CR from the end of each line.
  367. +
  368. +If
  369. +.I port
  370. +is not supplied,
  371. +.B http@
  372. +uses port 80 (HTTP).
  373. +
  374. +If
  375. +.I page
  376. +is not supplied,
  377. +.B http@
  378. +sends
  379. +.B GET /
  380. +to
  381. +.IR host .
  382. +
  383. +If
  384. +.I host
  385. +is not supplied,
  386. +.B http@
  387. +connects to the local host.
  388. +.SH "SEE ALSO"
  389. +addcr(1),
  390. +delcr(1),
  391. +tcpclient(1)
  392. --- /dev/null 1 Jan 1970 00:00:00 -0000
  393. +++ mconnect.1 5 Apr 2004 15:34:57 -0000 1.1
  394. @@ -0,0 +1,36 @@
  395. +.TH mconnect 1
  396. +.SH NAME
  397. +mconnect \- connect to the SMTP server on a host
  398. +.SH SYNTAX
  399. +.B mconnect
  400. +[
  401. +.I host
  402. +[
  403. +.I port
  404. +]
  405. +]
  406. +.SH DESCRIPTION
  407. +.B mconnect
  408. +connects to
  409. +.I port
  410. +on
  411. +.IR host .
  412. +It sends its input to
  413. +.IR host ,
  414. +adding a CR to each line.
  415. +Meanwhile it prints anything it receives from
  416. +.IR host .
  417. +
  418. +If
  419. +.I port
  420. +is not supplied,
  421. +.B mconnect
  422. +uses port 25 (SMTP).
  423. +
  424. +If
  425. +.I host
  426. +is not supplied,
  427. +.B mconnect
  428. +connects to the local host.
  429. +.SH "SEE ALSO"
  430. +tcpclient(1)
  431. --- /dev/null 1 Jan 1970 00:00:00 -0000
  432. +++ recordio.1 5 Apr 2004 15:34:57 -0000 1.1
  433. @@ -0,0 +1,75 @@
  434. +.TH recordio 1
  435. +.SH NAME
  436. +recordio \- record the input and output of a program
  437. +.SH SYNTAX
  438. +.B recordio
  439. +.I program
  440. +[
  441. +.I arg ...
  442. +]
  443. +.SH DESCRIPTION
  444. +.B recordio
  445. +runs
  446. +.I program
  447. +with the given arguments.
  448. +It prints lines to stderr
  449. +showing the input and output of
  450. +.IR program .
  451. +
  452. +At the beginning of each line on stderr,
  453. +.B recordio
  454. +inserts the
  455. +.I program
  456. +process ID,
  457. +along with
  458. +.B <
  459. +for input or
  460. +.B >
  461. +for output.
  462. +At the end of each line it inserts a space, a plus sign, or [EOF];
  463. +a space indicates that there was a newline in the input or output,
  464. +and [EOF] indicates the end of input or output.
  465. +
  466. +.B recordio
  467. +prints every packet of input and output immediately.
  468. +It does not attempt to combine packets into coherent stderr lines.
  469. +For example,
  470. +
  471. +.EX
  472. + recordio sh -c 'cat /dev/fd/8 2>&1' > /dev/null
  473. +.EE
  474. +
  475. +could produce
  476. +
  477. +.EX
  478. + 5135 > cat: /dev/fd/8: Bad file descriptor
  479. +.br
  480. + 5135 > [EOF]
  481. +.EE
  482. +
  483. +or
  484. +
  485. +.EX
  486. + 5135 > cat: +
  487. +.br
  488. + 5135 > /dev/fd/8+
  489. +.br
  490. + 5135 > : +
  491. +.br
  492. + 5135 > Bad file descriptor
  493. +.br
  494. + 5135 > [EOF]
  495. +.EE
  496. +
  497. +.B recordio
  498. +uses several lines for long packets
  499. +to guarantee that each line is printed atomically to stderr.
  500. +
  501. +.B recordio
  502. +runs as a child of
  503. +.IR program .
  504. +It exits when it sees the end of
  505. +.IR program 's
  506. +output.
  507. +.SH "SEE ALSO"
  508. +tcpserver(1)
  509. --- /dev/null 1 Jan 1970 00:00:00 -0000
  510. +++ tcp-environ.5 5 Apr 2004 15:34:57 -0000 1.1
  511. @@ -0,0 +1,62 @@
  512. +.TH tcp-environ 5
  513. +.SH NAME
  514. +tcp-environ \- TCP-related environment variables
  515. +.SH DESCRIPTION
  516. +The following environment variables
  517. +describe a TCP connection.
  518. +They are set up by
  519. +.BR tcp-env ,
  520. +.BR tcpclient ,
  521. +and
  522. +.BR tcpserver .
  523. +Note that
  524. +.BR TCPLOCALHOST ,
  525. +.BR TCPREMOTEHOST ,
  526. +and
  527. +.B TCPREMOTEINFO
  528. +can contain arbitrary characters.
  529. +.TP 5
  530. +PROTO
  531. +The string
  532. +.BR TCP .
  533. +.TP 5
  534. +TCPLOCALHOST
  535. +The domain name of the local host,
  536. +with uppercase letters converted to lowercase.
  537. +If there is no currently available domain name
  538. +for the local IP address,
  539. +.B TCPLOCALHOST
  540. +is not set.
  541. +.TP 5
  542. +TCPLOCALIP
  543. +The IP address of the local host, in dotted-decimal form.
  544. +.TP 5
  545. +TCPLOCALPORT
  546. +The local TCP port number, in decimal.
  547. +.TP 5
  548. +TCPREMOTEHOST
  549. +The domain name of the remote host,
  550. +with uppercase letters converted to lowercase.
  551. +If there is no currently available domain name
  552. +for the remote IP address,
  553. +.B TCPREMOTEHOST
  554. +is not set.
  555. +.TP 5
  556. +TCPREMOTEINFO
  557. +A connection-specific string, perhaps a username,
  558. +supplied by the remote host
  559. +via 931/1413/IDENT/TAP.
  560. +If the remote host did not supply connection information,
  561. +.B TCPREMOTEINFO
  562. +is not set.
  563. +.TP 5
  564. +TCPREMOTEIP
  565. +The IP address of the remote host.
  566. +.TP 5
  567. +TCPREMOTEPORT
  568. +The remote TCP port number.
  569. +.SH "SEE ALSO"
  570. +tcpclient(1),
  571. +tcpserver(1),
  572. +tcp-env(1),
  573. +tcp(4)
  574. --- /dev/null 1 Jan 1970 00:00:00 -0000
  575. +++ tcpcat.1 5 Apr 2004 15:34:57 -0000 1.1
  576. @@ -0,0 +1,20 @@
  577. +.TH tcpcat 1
  578. +.SH NAME
  579. +tcpcat \- print data from a TCP port
  580. +.SH SYNTAX
  581. +.B tcpcat
  582. +.I host
  583. +.I port
  584. +.SH DESCRIPTION
  585. +.B tcpcat
  586. +connects to
  587. +.I port
  588. +on
  589. +.I host
  590. +and prints any data it receives.
  591. +
  592. +.B tcpcat
  593. +can be used to transfer binary data.
  594. +It does no conversions.
  595. +.SH "SEE ALSO"
  596. +tcpclient(1)
  597. --- /dev/null 1 Jan 1970 00:00:00 -0000
  598. +++ tcpclient.1 5 Apr 2004 15:34:57 -0000 1.1
  599. @@ -0,0 +1,151 @@
  600. +.TH tcpclient 1
  601. +.SH NAME
  602. +tcpclient \- create an outgoing TCP connection
  603. +.SH SYNOPSIS
  604. +.B tcpclient
  605. +[
  606. +.B \-hHrRdDqQv
  607. +]
  608. +[
  609. +.B \-i\fIlocalip
  610. +]
  611. +[
  612. +.B \-p\fIlocalport
  613. +]
  614. +[
  615. +.B \-T\fItimeoutconn
  616. +]
  617. +[
  618. +.B \-l\fIlocalname
  619. +]
  620. +[
  621. +.B \-t\fItimeoutinfo
  622. +]
  623. +.I host
  624. +.I port
  625. +.I program
  626. +[
  627. +.I arg ...
  628. +]
  629. +.SH DESCRIPTION
  630. +.B tcpclient
  631. +attempts to connect to a TCP server.
  632. +If it is successful, it runs
  633. +.I program
  634. +with the given arguments,
  635. +with descriptor 6 reading from the network
  636. +and descriptor 7 writing to the network.
  637. +
  638. +The server's address is given by
  639. +.I host
  640. +and
  641. +.IR port .
  642. +.I host
  643. +may be 0, referring to the local machine,
  644. +or a dotted-decimal IP address,
  645. +or a host name;
  646. +if a host has several IP addresses,
  647. +.B tcpclient
  648. +tries each in turn.
  649. +.I port
  650. +may be a numeric port number
  651. +or a port name.
  652. +
  653. +.B tcpclient
  654. +sets up several environment variables,
  655. +as described in
  656. +.B tcp-environ(5).
  657. +.SH OPTIONS
  658. +.TP
  659. +.B \-i\fIlocalip
  660. +Use
  661. +.I localip
  662. +as the IP address for the local side of the connection;
  663. +quit if
  664. +.I localip
  665. +is not available.
  666. +.TP
  667. +.B \-p\fIlocalport
  668. +Use
  669. +.I localport
  670. +as the port number for the local side of the connection;
  671. +quit if
  672. +.I localport
  673. +is not available.
  674. +.TP
  675. +.B \-T\fItimeoutconn
  676. +Give up on the
  677. +connection attempt
  678. +after
  679. +.I timeoutconn
  680. +seconds. Default: 60.
  681. +This timeout applies to each IP address tried.
  682. +.TP
  683. +.B \-d
  684. +(Default.)
  685. +Delay sending data for a fraction of a second whenever the
  686. +remote host is responding slowly,
  687. +to make better use of the network.
  688. +.TP
  689. +.B \-D
  690. +Never delay sending data;
  691. +enable TCP_NODELAY.
  692. +This is appropriate for interactive connections.
  693. +.TP
  694. +.B \-q
  695. +Quiet.
  696. +Do not print any messages.
  697. +.TP
  698. +.B \-Q
  699. +(Default.)
  700. +Print error messages.
  701. +.TP
  702. +.B \-v
  703. +Verbose.
  704. +Print all available messages.
  705. +.SH "DATA-GATHERING OPTIONS"
  706. +.TP
  707. +.B \-h
  708. +(Default.)
  709. +Look up the remote host name for
  710. +.BR TCPREMOTEHOST .
  711. +.TP
  712. +.B \-H
  713. +Do not look up the remote host name;
  714. +unset
  715. +.BR TCPREMOTEHOST .
  716. +.TP
  717. +.B \-l\fIlocalname
  718. +Do not look up the local host name;
  719. +use
  720. +.I localname
  721. +for
  722. +.BR TCPLOCALHOST .
  723. +.TP
  724. +.B \-r
  725. +(Default.)
  726. +Attempt to obtain
  727. +.B TCPREMOTEINFO
  728. +from the remote host.
  729. +.TP
  730. +.B \-R
  731. +Do not attempt to obtain
  732. +.B TCPREMOTEINFO
  733. +from the remote host.
  734. +.TP
  735. +.B \-t\fItimeoutinfo
  736. +Give up on the
  737. +.B TCPREMOTEINFO
  738. +connection attempt
  739. +after
  740. +.I timeoutinfo
  741. +seconds. Default: 26.
  742. +.SH "SEE ALSO"
  743. +date@(1),
  744. +finger@(1),
  745. +http@(1),
  746. +mconnect(1),
  747. +tcpcat(1),
  748. +tcpserver(1),
  749. +who@(1),
  750. +tcp-environ(5)
  751. --- /dev/null 1 Jan 1970 00:00:00 -0000
  752. +++ tcprules.1 5 Apr 2004 15:34:57 -0000 1.1
  753. @@ -0,0 +1,208 @@
  754. +.TH tcprules 1
  755. +.SH NAME
  756. +tcprules \- compile rules for tcpserver
  757. +.SH SYNOPSIS
  758. +.B tcprules
  759. +.I rules.cdb
  760. +.I rules.tmp
  761. +.SH OVERVIEW
  762. +.B tcpserver
  763. +optionally follows rules to decide whether a TCP connection is acceptable.
  764. +For example, a rule of
  765. +
  766. +.EX
  767. + 18.23.0.32:deny
  768. +.EE
  769. +
  770. +prohibits connections from IP address 18.23.0.32.
  771. +
  772. +.B tcprules
  773. +reads rules from its standard input
  774. +and writes them into
  775. +.I rules.cdb
  776. +in a binary format suited
  777. +for quick access by
  778. +.BR tcpserver .
  779. +
  780. +.B tcprules
  781. +can be used while
  782. +.B tcpserver
  783. +is running:
  784. +it ensures that
  785. +.I rules.cdb
  786. +is updated atomically.
  787. +It does this by first writing the rules to
  788. +.I rules.tmp
  789. +and then moving
  790. +.I rules.tmp
  791. +on top of
  792. +.IR rules.cdb .
  793. +If
  794. +.I rules.tmp
  795. +already exists, it is destroyed.
  796. +The directories containing
  797. +.I rules.cdb
  798. +and
  799. +.I rules.tmp
  800. +must be writable to
  801. +.BR tcprules ;
  802. +they must also be on the same filesystem.
  803. +
  804. +If there is a problem with the input,
  805. +.B tcprules
  806. +complains and leaves
  807. +.I rules.cdb
  808. +alone.
  809. +
  810. +The binary
  811. +.I rules.cdb
  812. +format is portable across machines.
  813. +.SH "RULE FORMAT"
  814. +A rule takes up one line.
  815. +A file containing rules
  816. +may also contain comments: lines beginning with # are ignored.
  817. +
  818. +Each rule contains an
  819. +.BR address ,
  820. +a colon,
  821. +and a list of
  822. +.BR instructions ,
  823. +with no extra spaces.
  824. +When
  825. +.B tcpserver
  826. +receives a connection from that address,
  827. +it follows the instructions.
  828. +.SH "ADDRESSES"
  829. +.B tcpserver
  830. +starts by looking for a rule with address
  831. +.IR TCPREMOTEINFO\fB@\fITCPREMOTEIP .
  832. +If it doesn't find one, or if
  833. +.I TCPREMOTEINFO
  834. +is not set, it tries the address
  835. +.IR TCPREMOTEIP .
  836. +If that doesn't work, it tries shorter and shorter prefixes of
  837. +.I TCPREMOTEIP
  838. +ending with a dot.
  839. +If none of them work, it tries the empty string.
  840. +
  841. +For example, here are some rules:
  842. +
  843. +.EX
  844. + joe@127.0.0.1:first
  845. +.br
  846. + 18.23.0.32:second
  847. +.br
  848. + 127.:third
  849. +.br
  850. + :fourth
  851. +.EE
  852. +
  853. +If
  854. +.I TCPREMOTEIP
  855. +is
  856. +.BR 10.119.75.38 ,
  857. +.B tcpserver
  858. +will follow the
  859. +.B fourth
  860. +instructions.
  861. +
  862. +If
  863. +.I TCPREMOTEIP
  864. +is
  865. +.BR 18.23.0.32 ,
  866. +.B tcpserver
  867. +will follow the
  868. +.B second
  869. +instructions.
  870. +
  871. +If
  872. +.I TCPREMOTEINFO
  873. +is
  874. +.B bill
  875. +and
  876. +.I TCPREMOTEIP
  877. +is
  878. +.BR 127.0.0.1 ,
  879. +.B tcpserver
  880. +will follow the
  881. +.B third
  882. +instructions.
  883. +
  884. +If
  885. +.I TCPREMOTEINFO
  886. +is
  887. +.B joe
  888. +and
  889. +.I TCPREMOTEIP
  890. +is
  891. +.BR 127.0.0.1 ,
  892. +.B tcpserver
  893. +will follow the
  894. +.B first
  895. +instructions.
  896. +.SH "ADDRESS RANGES"
  897. +.B tcprules
  898. +treats
  899. +.B 1.2.3.37-53:ins
  900. +as an abbreviation
  901. +for the rules
  902. +.BR 1.2.3.37:ins ,
  903. +.BR 1.2.3.38:ins ,
  904. +and so on up through
  905. +.BR 1.2.3.53:ins .
  906. +Similarly,
  907. +.BR 10.2-3.:ins
  908. +is an abbreviation for
  909. +.B 10.2.:ins
  910. +and
  911. +.BR 10.3.:ins .
  912. +.SH "INSTRUCTIONS"
  913. +The instructions in a rule must begin with either
  914. +.B allow
  915. +or
  916. +.BR deny .
  917. +.B deny
  918. +tells
  919. +.B tcpserver
  920. +to drop the connection without running anything.
  921. +For example, the rule
  922. +
  923. +.EX
  924. + :deny
  925. +.EE
  926. +
  927. +tells
  928. +.B tcpserver
  929. +to drop all connections that aren't handled by more specific rules.
  930. +
  931. +The instructions may continue with some environment variables,
  932. +in the format
  933. +.IR ,VAR="VALUE" .
  934. +.B tcpserver
  935. +adds
  936. +.I VAR=VALUE
  937. +to the current environment.
  938. +For example,
  939. +
  940. +.EX
  941. + 10.0.:allow,RELAYCLIENT="@fix.me"
  942. +.EE
  943. +
  944. +adds
  945. +.B RELAYCLIENT=@fix.me
  946. +to the environment.
  947. +The quotes here may be replaced by any repeated character:
  948. +
  949. +.EX
  950. + 10.0.:allow,RELAYCLIENT=/@fix.me/
  951. +.EE
  952. +
  953. +Any number of variables may be listed:
  954. +
  955. +.EX
  956. + 127.0.0.1:allow,RELAYCLIENT="",TCPLOCALHOST="movie.edu"
  957. +.EE
  958. +.SH "SEE ALSO"
  959. +tcprulescheck(1),
  960. +tcpserver(1),
  961. +tcp-environ(5)
  962. --- tcprules.c 14 Jun 2002 08:47:30 -0000 1.1.1.1
  963. +++ tcprules.c 16 Mar 2004 15:12:26 -0000 1.2
  964. @@ -94,6 +94,7 @@
  965. int len;
  966. int fd;
  967. int i;
  968. + int e;
  969. char ch;
  970.  
  971. fn = argv[1];
  972. @@ -144,8 +145,16 @@
  973. while (len)
  974. switch(*x) {
  975. case ',':
  976. + e = byte_chr(x + 1,len - 1,',');
  977. i = byte_chr(x,len,'=');
  978. - if (i == len) die_bad();
  979. + if (i > e) {
  980. + if (e < 2 || x[1] != '!') die_bad();
  981. + if (!stralloc_catb(&data,"-",1)) nomem();
  982. + if (!stralloc_catb(&data,x + 2,e - 1)) nomem();
  983. + if (!stralloc_0(&data)) nomem();
  984. + x += e + 1; len -= e + 1;
  985. + break;
  986. + }
  987. if (!stralloc_catb(&data,"+",1)) nomem();
  988. if (!stralloc_catb(&data,x + 1,i)) nomem();
  989. x += i + 1; len -= i + 1;
  990. --- /dev/null 1 Jan 1970 00:00:00 -0000
  991. +++ tcprulescheck.1 5 Apr 2004 15:34:57 -0000 1.1
  992. @@ -0,0 +1,25 @@
  993. +.TH tcprulescheck 1
  994. +.SH NAME
  995. +tcprulescheck \- try out rules for tcpserver
  996. +.SH SYNTAX
  997. +.B tcprulescheck
  998. +.I rules.cdb
  999. +.I tcpremoteip
  1000. +[
  1001. +.I tcpremoteinfo
  1002. +]
  1003. +.SH DESCRIPTION
  1004. +.B tcprulescheck
  1005. +says what
  1006. +.B tcpserver
  1007. +will do with a connection from
  1008. +IP address
  1009. +.IR tcpremoteip ,
  1010. +following the rules compiled into
  1011. +.I rules.cdb
  1012. +by
  1013. +.BR tcprules .
  1014. +.SH "SEE ALSO"
  1015. +tcprules(1),
  1016. +tcpserver(1),
  1017. +tcp-environ(5)
  1018. diff -u -p -r1.1.1.1 -r1.2
  1019. --- tcprulescheck.c 14 Jun 2002 08:47:30 -0000 1.1.1.1
  1020. +++ tcprulescheck.c 16 Mar 2004 15:12:27 -0000 1.2
  1021. @@ -22,6 +22,11 @@
  1022. buffer_puts(buffer_1,data + 1);
  1023. buffer_puts(buffer_1,"\n");
  1024. break;
  1025. + case '-':
  1026. + buffer_puts(buffer_1,"unset environment variable ");
  1027. + buffer_puts(buffer_1,data + 1);
  1028. + buffer_puts(buffer_1,"\n");
  1029. + break;
  1030. }
  1031. ++next0;
  1032. data += next0; datalen -= next0;
  1033. --- /dev/null 1 Jan 1970 00:00:00 -0000
  1034. +++ tcpserver.1 6 Apr 2004 11:49:45 -0000 1.2
  1035. @@ -0,0 +1,284 @@
  1036. +.TH tcpserver 1
  1037. +.SH NAME
  1038. +tcpserver \- accept incoming TCP connections
  1039. +.SH SYNOPSIS
  1040. +.B tcpserver
  1041. +[
  1042. +.B \-1UXpPhHrRoOdDqQsSv
  1043. +]
  1044. +[
  1045. +.B \-c\fIlimit
  1046. +]
  1047. +[
  1048. +.B \-x\fIrules.cdb
  1049. +]
  1050. +[
  1051. +.B \-B\fIbanner
  1052. +]
  1053. +[
  1054. +.B \-g\fIgid
  1055. +]
  1056. +[
  1057. +.B \-u\fIuid
  1058. +]
  1059. +[
  1060. +.B \-b\fIbacklog
  1061. +]
  1062. +[
  1063. +.B \-l\fIlocalname
  1064. +]
  1065. +[
  1066. +.B \-t\fItimeout
  1067. +]
  1068. +[
  1069. +.B \-n\fIcertfile
  1070. +]
  1071. +.I host
  1072. +.I port
  1073. +.I program
  1074. +[
  1075. +.I arg ...
  1076. +]
  1077. +.SH DESCRIPTION
  1078. +.B tcpserver
  1079. +waits for connections from TCP clients.
  1080. +For each connection, it runs
  1081. +.I program
  1082. +with the given arguments,
  1083. +with descriptor 0 reading from the network
  1084. +and descriptor 1 writing to the network.
  1085. +
  1086. +The server's address is given by
  1087. +.I host
  1088. +and
  1089. +.IR port .
  1090. +.I host
  1091. +can be 0, allowing connections from any host;
  1092. +or a particular IP address,
  1093. +allowing connections only to that address;
  1094. +or a host name, allowing connections to the first IP address
  1095. +for that host.
  1096. +.I port
  1097. +may be a numeric port number
  1098. +or a port name.
  1099. +If
  1100. +.I port
  1101. +is 0,
  1102. +.B tcpserver
  1103. +will choose a free port.
  1104. +
  1105. +.B tcpserver
  1106. +sets up several environment variables,
  1107. +as described in
  1108. +.B tcp-environ(5).
  1109. +
  1110. +.B tcpserver
  1111. +exits when it receives SIGTERM.
  1112. +.SH "OPTIONS"
  1113. +.TP
  1114. +.B \-c\fIlimit
  1115. +Do not handle more than
  1116. +.I limit
  1117. +simultaneous connections.
  1118. +If there are
  1119. +.I limit
  1120. +simultaneous copies of
  1121. +.I program
  1122. +running, defer acceptance of a new connection
  1123. +until one copy finishes.
  1124. +.I limit
  1125. +must be a positive integer.
  1126. +Default: 40.
  1127. +.TP
  1128. +.B \-x\fIrules.cdb
  1129. +Follow the rules compiled into
  1130. +.I rules.cdb
  1131. +by
  1132. +.BR tcprules .
  1133. +These rules may specify setting environment variables
  1134. +or rejecting connections from bad sources.
  1135. +
  1136. +.B tcpserver
  1137. +does not read
  1138. +.I rules.cdb
  1139. +into memory;
  1140. +you can rerun
  1141. +.B tcprules
  1142. +to change
  1143. +.BR tcpserver 's
  1144. +behavior on the fly.
  1145. +.TP
  1146. +.B \-B\fIbanner
  1147. +Write
  1148. +.I banner
  1149. +to the network immediately after each connection is made.
  1150. +.B tcpserver
  1151. +writes
  1152. +.I banner
  1153. +before looking up
  1154. +.BR TCPREMOTEHOST ,
  1155. +before looking up
  1156. +.BR TCPREMOTEINFO ,
  1157. +and before checking
  1158. +.IR rules.cdb .
  1159. +
  1160. +This feature can be used to reduce latency in protocols
  1161. +where the client waits for a greeting from the server.
  1162. +.TP
  1163. +.B \-g\fIgid
  1164. +Switch group ID to
  1165. +.I gid
  1166. +after preparing to receive connections.
  1167. +.I gid
  1168. +must be a positive integer.
  1169. +.TP
  1170. +.B \-u\fIuid
  1171. +Switch user ID to
  1172. +.I uid
  1173. +after preparing to receive connections.
  1174. +.I uid
  1175. +must be a positive integer.
  1176. +.TP
  1177. +.B \-U
  1178. +Same as
  1179. +.B \-g\fI$GID
  1180. +.BR \-u\fI$UID .
  1181. +Typically
  1182. +.I $GID
  1183. +and
  1184. +.I $UID
  1185. +are set by envuidgid.
  1186. +.TP
  1187. +.B \-1
  1188. +After preparing to receive connections,
  1189. +print the local port number to standard output.
  1190. +.TP
  1191. +.B \-b\fIbacklog
  1192. +Allow up to
  1193. +.I backlog
  1194. +simultaneous SYN_RECEIVEDs.
  1195. +Default: 20.
  1196. +On some systems,
  1197. +.I backlog
  1198. +is silently limited to 5.
  1199. +See
  1200. +.BR listen (2)
  1201. +for more details.
  1202. +.TP
  1203. +.B \-o
  1204. +Leave IP options alone.
  1205. +If the client is sending packets along an IP source route,
  1206. +send packets back along the same route.
  1207. +.TP
  1208. +.B \-O
  1209. +(Default.)
  1210. +Kill IP options.
  1211. +A client can still use source routing to connect and to send data,
  1212. +but packets will be sent back along the default route.
  1213. +.TP
  1214. +.B \-d
  1215. +(Default.)
  1216. +Delay sending data for a fraction of a second whenever the
  1217. +remote host is responding slowly,
  1218. +to make better use of the network.
  1219. +.TP
  1220. +.B \-D
  1221. +Never delay sending data;
  1222. +enable TCP_NODELAY.
  1223. +This is appropriate for interactive connections.
  1224. +.TP
  1225. +.B \-q
  1226. +Quiet.
  1227. +Do not print any messages.
  1228. +.TP
  1229. +.B \-Q
  1230. +(Default.)
  1231. +Print error messages.
  1232. +.TP
  1233. +.B \-s
  1234. +Enable SSL/TLS mode. This modus needs a SSL enabled build and a certificat.
  1235. +.TP
  1236. +.B \-S
  1237. +(Default.)
  1238. +Don't enable SSL/TLS mode.
  1239. +.TP
  1240. +.B \-n\fIcertfile
  1241. +Instead of the default ./cert.pem certificate us the specified
  1242. +.IR certfile .
  1243. +.TP
  1244. +.B \-v
  1245. +Verbose.
  1246. +Print all available messages.
  1247. +.TP
  1248. +.B \-X
  1249. +With
  1250. +.BR -x\fIcdb ,
  1251. +allow connections even if
  1252. +.I cdb
  1253. +does not exist.
  1254. +Normally the connection gets dropped.
  1255. +.SH "DATA-GATHERING OPTIONS"
  1256. +.TP
  1257. +.B \-p
  1258. +Paranoid.
  1259. +After looking up the remote host name,
  1260. +look up the IP addresses for that name,
  1261. +and make sure one of them matches
  1262. +.BR TCPREMOTEIP .
  1263. +If none of them do,
  1264. +unset
  1265. +.BR TCPREMOTEHOST .
  1266. +.TP
  1267. +.B \-P
  1268. +(Default.)
  1269. +Not paranoid.
  1270. +.TP
  1271. +.B \-h
  1272. +(Default.)
  1273. +Look up the remote host name and set
  1274. +.BR TCPREMOTEHOST .
  1275. +.TP
  1276. +.B \-H
  1277. +Do not look up the remote host name.
  1278. +.TP
  1279. +.B \-l\fIlocalname
  1280. +Do not look up the local host name;
  1281. +use
  1282. +.I localname
  1283. +for
  1284. +.BR TCPLOCALHOST .
  1285. +.TP
  1286. +.B \-r
  1287. +(Default.)
  1288. +Attempt to obtain
  1289. +.B TCPREMOTEINFO
  1290. +from the remote host.
  1291. +.TP
  1292. +.B \-R
  1293. +Do not attempt to obtain
  1294. +.B TCPREMOTEINFO
  1295. +from the remote host.
  1296. +.TP
  1297. +.B \-t\fItimeout
  1298. +Give up on the
  1299. +.B TCPREMOTEINFO
  1300. +connection attempt
  1301. +after
  1302. +.I timeout
  1303. +seconds. Default: 26.
  1304. +.SH ENVIRONMENT
  1305. +.TP
  1306. +.B SSL_CIPHER
  1307. +Specifies the ciphers that should be used in SSL/TLS mode.
  1308. +See
  1309. +.I openssl(1)
  1310. +for more information.
  1311. +.SH "SEE ALSO"
  1312. +argv0(1),
  1313. +fixcr(1),
  1314. +recordio(1),
  1315. +tcpclient(1),
  1316. +tcprules(1),
  1317. +listen(2),
  1318. +tcp-environ(5),
  1319. +openssl(1)
  1320. --- tcpserver.c 14 Jun 2002 08:47:30 -0000 1.1.1.1
  1321. +++ tcpserver.c 1 Apr 2005 15:13:15 -0000 1.8
  1322. @@ -1,6 +1,8 @@
  1323. #include <sys/types.h>
  1324. #include <sys/param.h>
  1325. #include <netdb.h>
  1326. +#include <openssl/ssl.h>
  1327. +#include <fcntl.h>
  1328. #include "uint16.h"
  1329. #include "str.h"
  1330. #include "byte.h"
  1331. @@ -36,6 +37,13 @@
  1332. int flagremotehost = 1;
  1333. int flagparanoid = 0;
  1334. unsigned long timeout = 26;
  1335. +#ifdef WITH_SSL
  1336. +int flagssl = 0;
  1337. +struct stralloc certfile = {0};
  1338. +#define CERTFILE "./cert.pem"
  1339. +
  1340. +void translate(SSL*, int, int, unsigned int);
  1341. +#endif
  1342.  
  1343. static stralloc tcpremoteinfo;
  1344.  
  1345. @@ -127,6 +135,9 @@
  1346. env(data + 1,data + 1 + split + 1);
  1347. }
  1348. break;
  1349. + case '-':
  1350. + env(data + 1, (char *)0);
  1351. + break;
  1352. }
  1353. ++next0;
  1354. data += next0; datalen -= next0;
  1355. @@ -238,6 +249,7 @@
  1356.  
  1357. void usage(void)
  1358. {
  1359. +#ifndef WITH_SSL
  1360. strerr_warn1("\
  1361. tcpserver: usage: tcpserver \
  1362. [ -1UXpPhHrRoOdDqQv ] \
  1363. @@ -250,6 +262,21 @@
  1364. [ -l localname ] \
  1365. [ -t timeout ] \
  1366. host port program",0);
  1367. +#else
  1368. + strerr_warn1("\
  1369. +tcpserver: usage: tcpserver \
  1370. +[ -1UXpPhHrRoOdDqQsSv ] \
  1371. +[ -c limit ] \
  1372. +[ -x rules.cdb ] \
  1373. +[ -B banner ] \
  1374. +[ -g gid ] \
  1375. +[ -u uid ] \
  1376. +[ -b backlog ] \
  1377. +[ -l localname ] \
  1378. +[ -t timeout ] \
  1379. +[ -n certfile ] \
  1380. +host port program",0);
  1381. +#endif
  1382. _exit(100);
  1383. }
  1384.  
  1385. @@ -300,7 +327,20 @@
  1386. int s;
  1387. int t;
  1388.  
  1389. +#ifdef WITH_SSL
  1390. + BIO *sbio;
  1391. + SSL *ssl;
  1392. + SSL_CTX *ctx;
  1393. + int pi2c[2], pi4c[2];
  1394. +
  1395. + ctx = NULL;
  1396. +
  1397. + if (!stralloc_copys(&certfile, CERTFILE) || !stralloc_0(&certfile) )
  1398. + strerr_die2x(111,FATAL,"out of memory");
  1399. + while ((opt = getopt(argc,argv,"dDvqQhHrRsS1UXx:t:u:g:l:b:B:c:n:pPoO")) != opteof)
  1400. +#else
  1401. while ((opt = getopt(argc,argv,"dDvqQhHrR1UXx:t:u:g:l:b:B:c:pPoO")) != opteof)
  1402. +#endif
  1403. switch(opt) {
  1404. case 'b': scan_ulong(optarg,&backlog); break;
  1405. case 'c': scan_ulong(optarg,&limit); break;
  1406. @@ -327,6 +367,14 @@
  1407. case 'g': scan_ulong(optarg,&gid); break;
  1408. case '1': flag1 = 1; break;
  1409. case 'l': localhost = optarg; break;
  1410. +#ifdef WITH_SSL
  1411. + case 's': flagssl = 1; break;
  1412. + case 'S': flagssl = 0; break;
  1413. + case 'n': if (!stralloc_copys(&certfile, optarg) ||
  1414. + !stralloc_0(&certfile) )
  1415. + strerr_die2x(111,FATAL,"out of memory");
  1416. + break;
  1417. +#endif
  1418. default: usage();
  1419. }
  1420. argc -= optind;
  1421. @@ -334,6 +382,11 @@
  1422.  
  1423. if (!verbosity)
  1424. buffer_2->fd = -1;
  1425. +
  1426. + if (limit == 0)
  1427. + strerr_die2x(100,FATAL,"limit may not be set to 0");
  1428. + if (limit > 65000)
  1429. + strerr_die2x(100,FATAL,"limit way to high");
  1430.  
  1431. hostname = *argv++;
  1432. if (!hostname) usage();
  1433. @@ -366,6 +419,25 @@
  1434. strerr_die3x(111,FATAL,"no IP address for ",hostname);
  1435. byte_copy(localip,4,addresses.s);
  1436.  
  1437. +#ifdef WITH_SSL
  1438. + if (flagssl == 1) {
  1439. + /* setup SSL context (load key and cert into ctx) */
  1440. + SSL_library_init();
  1441. + ctx=SSL_CTX_new(SSLv23_server_method());
  1442. + if (!ctx) strerr_die2x(111,FATAL,"unable to create SSL context");
  1443. +
  1444. + /* set prefered ciphers */
  1445. + if (env_get("SSL_CIPHER"))
  1446. + if (SSL_CTX_set_cipher_list(ctx, env_get("SSL_CIPHER")) == 0)
  1447. + strerr_die2x(111,FATAL,"unable to set cipher list");
  1448. +
  1449. + if(SSL_CTX_use_RSAPrivateKey_file(ctx, certfile.s, SSL_FILETYPE_PEM) != 1)
  1450. + strerr_die2x(111,FATAL,"unable to load RSA private key");
  1451. + if(SSL_CTX_use_certificate_chain_file(ctx, certfile.s) != 1)
  1452. + strerr_die2x(111,FATAL,"unable to load certificate");
  1453. + }
  1454. +#endif
  1455. +
  1456. s = socket_tcp();
  1457. if (s == -1)
  1458. strerr_die2sys(111,FATAL,"unable to create socket: ");
  1459. @@ -415,6 +487,39 @@
  1460. sig_unblock(sig_child);
  1461. sig_uncatch(sig_term);
  1462. sig_uncatch(sig_pipe);
  1463. +#ifdef WITH_SSL
  1464. + if (flagssl == 1) {
  1465. + if (pipe(pi2c) != 0)
  1466. + strerr_die2sys(111,DROP,"unable to create pipe: ");
  1467. + if (pipe(pi4c) != 0)
  1468. + strerr_die2sys(111,DROP,"unable to create pipe: ");
  1469. + switch(fork()) {
  1470. + case 0:
  1471. + close(0); close(1);
  1472. + close(pi2c[1]);
  1473. + close(pi4c[0]);
  1474. + if ((fd_move(0,pi2c[0]) == -1) || (fd_move(1,pi4c[1]) == -1))
  1475. + strerr_die2sys(111,DROP,"unable to set up descriptors: ");
  1476. + /* signals are allready set in the parent */
  1477. + pathexec(argv);
  1478. + strerr_die4sys(111,DROP,"unable to run ",*argv,": ");
  1479. + case -1:
  1480. + strerr_die2sys(111,DROP,"unable to fork: ");
  1481. + default:
  1482. + ssl = SSL_new(ctx);
  1483. + if (!ssl)
  1484. + strerr_die2x(111,DROP,"unable to set up SSL session");
  1485. + sbio = BIO_new_socket(0,BIO_NOCLOSE);
  1486. + if (!sbio)
  1487. + strerr_die2x(111,DROP,"unable to set up BIO socket");
  1488. + SSL_set_bio(ssl,sbio,sbio);
  1489. + close(pi2c[0]);
  1490. + close(pi4c[1]);
  1491. + translate(ssl, pi2c[1], pi4c[0], 3600);
  1492. + _exit(0);
  1493. + }
  1494. + }
  1495. +#endif
  1496. pathexec(argv);
  1497. strerr_die4sys(111,DROP,"unable to run ",*argv,": ");
  1498. case -1:
  1499. @@ -424,3 +529,186 @@
  1500. close(t);
  1501. }
  1502. }
  1503. +
  1504. +#ifdef WITH_SSL
  1505. +int ssl_timeoutio(int (*func)(), long t, int rfd, int wfd, SSL *ssl, char *buf, int len)
  1506. +{
  1507. + int n;
  1508. + const long end = t + time(NULL);
  1509. +
  1510. + do {
  1511. + fd_set fds;
  1512. + struct timeval tv;
  1513. +
  1514. + const int r = buf ? func(ssl, buf, len) : func(ssl);
  1515. + if (r > 0)
  1516. + return r;
  1517. +
  1518. + t = end - time(NULL);
  1519. + if (t < 0)
  1520. + break;
  1521. + tv.tv_sec = t;
  1522. + tv.tv_usec = 0;
  1523. +
  1524. + FD_ZERO(&fds);
  1525. + switch (SSL_get_error(ssl, r))
  1526. + {
  1527. + default:
  1528. + return r; /* some other error */
  1529. + case SSL_ERROR_WANT_READ:
  1530. + FD_SET(rfd, &fds);
  1531. + n = select(rfd + 1, &fds, NULL, NULL, &tv);
  1532. + break;
  1533. + case SSL_ERROR_WANT_WRITE:
  1534. + FD_SET(wfd, &fds);
  1535. + n = select(wfd + 1, NULL, &fds, NULL, &tv);
  1536. + break;
  1537. + }
  1538. +
  1539. + /* n is the number of descriptors that changed status */
  1540. + }
  1541. + while (n > 0);
  1542. +
  1543. + if (n != -1) errno = error_timeout;
  1544. + return -1;
  1545. +}
  1546. +
  1547. +int ssl_timeoutaccept(long t, int rfd, int wfd, SSL *ssl)
  1548. +{
  1549. + int r;
  1550. +
  1551. + /* if connection is established, keep NDELAY */
  1552. + if (ndelay_on(rfd) == -1 || ndelay_on(wfd) == -1)
  1553. + return -1;
  1554. + r = ssl_timeoutio(SSL_accept, t, rfd, wfd, ssl, NULL, 0);
  1555. +
  1556. + if (r <= 0) {
  1557. + ndelay_off(rfd);
  1558. + ndelay_off(wfd);
  1559. + }
  1560. + else
  1561. + SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
  1562. +
  1563. + return r;
  1564. +}
  1565. +
  1566. +int ssl_timeoutread(long t, int rfd, int wfd, SSL *ssl, char *buf, int len)
  1567. +{
  1568. + if (!buf)
  1569. + return 0;
  1570. + if (SSL_pending(ssl))
  1571. + return SSL_read(ssl, buf, len);
  1572. + return ssl_timeoutio(SSL_read, t, rfd, wfd, ssl, buf, len);
  1573. +}
  1574. +
  1575. +int ssl_timeoutwrite(long t, int rfd, int wfd, SSL *ssl, char *buf, int len)
  1576. +{
  1577. + if (!buf)
  1578. + return 0;
  1579. + return ssl_timeoutio(SSL_write, t, rfd, wfd, ssl, buf, len);
  1580. +}
  1581. +
  1582. +static int allwrite(int fd, char *buf, int len)
  1583. +{
  1584. + int w;
  1585. +
  1586. + while (len) {
  1587. + w = write(fd,buf,len);
  1588. + if (w == -1) {
  1589. + if (errno == error_intr) continue;
  1590. + return -1; /* note that some data may have been written */
  1591. + }
  1592. + if (w == 0) ; /* luser's fault */
  1593. + buf += w;
  1594. + len -= w;
  1595. + }
  1596. + return 0;
  1597. +}
  1598. +
  1599. +static int allwritessl(long t, int rfd, int wfd, SSL* ssl, char *buf, int len)
  1600. +{
  1601. + int w;
  1602. +
  1603. + while (len) {
  1604. + w = ssl_timeoutwrite(t, rfd, wfd, ssl, buf, len);
  1605. + if (w == -1) {
  1606. + if (errno == error_intr) continue;
  1607. + return -1; /* note that some data may have been written */
  1608. + }
  1609. + if (w == 0) ; /* luser's fault */
  1610. + buf += w;
  1611. + len -= w;
  1612. + }
  1613. + return 0;
  1614. +}
  1615. +
  1616. +char tbuf[2048];
  1617. +
  1618. +void translate(SSL* ssl, int clearout, int clearin, unsigned int iotimeout)
  1619. +{
  1620. + struct taia now;
  1621. + struct taia deadline;
  1622. + iopause_fd iop[2];
  1623. + int flagexitasap;
  1624. + int iopl;
  1625. + int sslout, sslin;
  1626. + int n, r;
  1627. +
  1628. + sslin = SSL_get_fd(ssl);
  1629. + sslout = SSL_get_fd(ssl);
  1630. + if (sslin == -1 || sslout == -1)
  1631. + strerr_die2x(111,DROP,"unable to set up SSL connection");
  1632. +
  1633. + flagexitasap = 0;
  1634. +
  1635. + if (ssl_timeoutaccept(timeout, sslin, sslout, ssl) <= 0)
  1636. + strerr_die2x(111,DROP,"unable to accept SSL connection");
  1637. +
  1638. + while (!flagexitasap) {
  1639. + taia_now(&now);
  1640. + taia_uint(&deadline,iotimeout);
  1641. + taia_add(&deadline,&now,&deadline);
  1642. +
  1643. + /* fill iopause struct */
  1644. + iopl = 2;
  1645. + iop[0].fd = sslin;
  1646. + iop[0].events = IOPAUSE_READ;
  1647. + iop[1].fd = clearin;
  1648. + iop[1].events = IOPAUSE_READ;
  1649. +
  1650. + /* do iopause read */
  1651. + iopause(iop,iopl,&deadline,&now);
  1652. + if (iop[0].revents) {
  1653. + do {
  1654. + /* data on sslin */
  1655. + n = ssl_timeoutread(iotimeout, sslin, sslout, ssl, tbuf, sizeof(tbuf));
  1656. + if ( n < 0 )
  1657. + strerr_die2sys(111,DROP,"unable to read form network: ");
  1658. + if ( n == 0 )
  1659. + flagexitasap = 1;
  1660. + r = allwrite(clearout, tbuf, n);
  1661. + if ( r < 0 )
  1662. + strerr_die2sys(111,DROP,"unable to write to client: ");
  1663. + /*
  1664. + * if the data payload was longer than sizeof(tbuf) then SSL will have
  1665. + * bytes processed and pending. We need to pick them up and write them
  1666. + * to clearout.
  1667. + */
  1668. + } while (SSL_pending(ssl));
  1669. + }
  1670. + if (iop[1].revents) {
  1671. + /* data on clearin */
  1672. + n = read(clearin, tbuf, sizeof(tbuf));
  1673. + if ( n < 0 )
  1674. + strerr_die2sys(111,DROP,"unable to read form client: ");
  1675. + if ( n == 0 )
  1676. + flagexitasap = 1;
  1677. + r = allwritessl(iotimeout, sslin, sslout, ssl, tbuf, n);
  1678. + if ( r < 0 )
  1679. + strerr_die2sys(111,DROP,"unable to write to network: ");
  1680. + }
  1681. + if (!iop[0].revents && !iop[1].revents)
  1682. + strerr_die2x(0, DROP,"timeout reached without input");
  1683. + }
  1684. +}
  1685. +#endif
  1686. --- /dev/null 1 Jan 1970 00:00:00 -0000
  1687. +++ who@.1 5 Apr 2004 15:34:57 -0000 1.1
  1688. @@ -0,0 +1,32 @@
  1689. +.TH who@ 1
  1690. +.SH NAME
  1691. +who@ \- print list of active users on a host
  1692. +.SH SYNTAX
  1693. +.B who@
  1694. +[
  1695. +.I host
  1696. +]
  1697. +.SH DESCRIPTION
  1698. +.B who@
  1699. +connects to TCP port 11 (Systat) on
  1700. +.I host
  1701. +and prints any data it receives.
  1702. +It removes CR and converts unprintable characters to a visible format.
  1703. +
  1704. +If
  1705. +.I host
  1706. +is not supplied,
  1707. +.B who@
  1708. +connects to the local host.
  1709. +
  1710. +Some computers respond to port 11 with a list of active users.
  1711. +For example, they may be running
  1712. +
  1713. +.EX
  1714. + tcpserver 0 11 who &
  1715. +.EE
  1716. +.SH "SEE ALSO"
  1717. +cat(1),
  1718. +delcr(1),
  1719. +tcpclient(1),
  1720. +tcpserver(1)
  1721.