home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / xinetd21 / part12 < prev    next >
Encoding:
Text File  |  1993-06-26  |  29.9 KB  |  1,145 lines

  1. Newsgroups: comp.sources.unix
  2. From: panos@cs.colorado.edu (Panos Tsirigotis)
  3. Subject: v26i256: xinetd-2.1.1 - inetd replacement with access control and logging, Part12/31
  4. Sender: unix-sources-moderator@gw.home.vix.com
  5. Approved: vixie@gw.home.vix.com
  6.  
  7. Submitted-By: panos@cs.colorado.edu (Panos Tsirigotis)
  8. Posting-Number: Volume 26, Issue 256
  9. Archive-Name: xinetd-2.1.1/part12
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 12 (of 31)."
  18. # Contents:  libs/src/sio/Sprint.3 libs/src/sio/sioconf.h
  19. #   xinetd/config.h xinetd/int.c xinetd/retry.c
  20. # Wrapped by panos@mystique on Mon Jun 21 14:51:23 1993
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'libs/src/sio/Sprint.3' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'libs/src/sio/Sprint.3'\"
  24. else
  25. echo shar: Extracting \"'libs/src/sio/Sprint.3'\" \(5277 characters\)
  26. sed "s/^X//" >'libs/src/sio/Sprint.3' <<'END_OF_FILE'
  27. X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  28. X.\"All rights reserved.  The file named COPYRIGHT specifies the terms 
  29. X.\"and conditions for redistribution.
  30. X.\"
  31. X.\" $Id: Sprint.3,v 8.1 1993/03/13 01:15:34 panos Exp $
  32. X.TH Sprint 3X "29 May 1992"
  33. X.SH NAME
  34. XSprint -- formatted stream output
  35. X.SH SYNOPSIS
  36. X.LP
  37. X.nf
  38. X.ft B
  39. Xint Sprint( fd, format [ , ... ] )
  40. Xint fd ;
  41. Xchar *format ;
  42. X.SH DESCRIPTION
  43. X\fBSprint()\fR provides formatted output conversion. The formatting is
  44. Xcontrolled by the \fIformat\fR argument. All characters in
  45. X\fIformat\fR that do not specify a conversion are printed. A conversion
  46. Xis specified by a '%' followed by a string that ends with a
  47. Xconversion type character. The string may contain flags, a field width,
  48. Xa precision, and a modifier.
  49. X.LP
  50. XPossible flags (more that one can be specified and they can be in any order)
  51. Xinclude:
  52. X.TP 10
  53. X.B \'-'
  54. Xspecifies left adjustment of the converted argument. The default
  55. Xis right adjustment. This flag is meaningful only if a field width
  56. Xis specified.
  57. X.TP
  58. X.B \'+'
  59. Xspecifies that a number will always have a sign as a prefix (this
  60. Xforces a '+' sign to appear if the number is positive).
  61. X.TP
  62. X.B \' '
  63. Xprefixes a \fIspace\fR to the number if the number has not a sign
  64. X(therefore the '+' flag overrides this flag).
  65. X.TP
  66. X.B \'#'
  67. XThe meaning of '#' depends on the conversion type character: for \fBo\fR 
  68. Xconversions the first digit will be 0; for \fBx\fR or \fBX\fR conversions
  69. X\fB0x\fR or \fB0X\fR respectively will be prefixed to the number (if it
  70. Xis not zero); for \fBe\fR, \fBE\fR, \fBf\fR, \fBg\fR, and \fBG\fR conversions
  71. Xthe number will always have a decimal point.
  72. X.TP
  73. X.B \'0'
  74. Xspecifies padding with zeros instead of spaces.
  75. X.LP
  76. XThe field width is specified by a number. This number indicates the
  77. X\fIminimum\fR width for the field. A '*' may be used instead of the number.
  78. XIn that case the width is the value of the next argument which should
  79. Xbe an \fBint\fR. 
  80. XA negative width value specifies left adjustment with a width equal
  81. Xto the absolute width value.
  82. X.LP
  83. XA precision is specified by a '.' followed by a number. The meaning of
  84. Xthe precision depends on the type conversion character. For a string
  85. Xconversion, precision determines how many characters are printed from
  86. Xthe string. For integer conversions, precision determines the 
  87. Xnumber of digits used to print the number (zero padding is done if
  88. Xthe precision exceeds the length of the number). For floating point
  89. Xconversions, precision determines the number of digits after the
  90. Xdecimal point (\fBe\fR, \fBE\fR, \fBf\fR) or the number of
  91. Xsignificant digits (\fBg\fR, \fBG\fR).
  92. XA '*' may be used instead of a number to specify the precision. In that
  93. Xcase the precision is the value of the next argument which should
  94. Xbe an \fBint\fR.
  95. XThe behavior of \fBSprint()\fR is undefined if the precision is negative.
  96. X.LP
  97. XThe length modifier is \fBl\fR and indicates that the argument is
  98. Xa \fBlong\fR integer.
  99. X.LP
  100. XThe type conversion characters are:
  101. X\fBd, i, o, x, X, u, c, s, f, e, E, g, G, p, n, %\fR.
  102. XFor floating point conversions the argument should be of type \fIdouble\fR.
  103. X.TP 10
  104. X.B d,i
  105. Xspecify signed decimal conversion.
  106. X.TP
  107. X.B u
  108. Xspecifies unsigned decimal conversion.
  109. X.TP
  110. X.B o
  111. Xspecifies octal conversion.
  112. X.TP
  113. X.B x,X
  114. Xspecify hexadecimal conversion. For 
  115. X.B x
  116. Xthe hex digits used are 0123456789abcdef. For
  117. X.B X
  118. Xthe hex digits used are 0123456789ABCDEF.
  119. XThere is no leading
  120. X.B 0x
  121. Xor
  122. X.B 0X
  123. X(use the '#' flag for that).
  124. X.TP
  125. X.B c
  126. Xspecifies character conversion; the argument should be of type
  127. X\fIchar\fR.
  128. X.TP
  129. X.B s
  130. Xspecifies string conversion; the argument should be of type
  131. X\fIchar *\fR.
  132. X.TP
  133. X.B f
  134. Xspecifies conversion to the form [-]ddd.dddd. The number
  135. Xof digits after the decimal point depends on precision; the default is 6.
  136. XIf the precision is 0, the decimal point is not printed (this can
  137. Xbe overriden with the '#' flag).
  138. X.B e,E
  139. Xspecify conversion to the form [-]ddd.dddd[eE][+-]ddd.
  140. XThe number of digits after the decimal point depends on precision;
  141. Xthe default is 6. If the precision is 0, the decimal point is not printed
  142. X(this can be overriden with the '#' flag).
  143. XThe exponent is at least 2 digit wide.
  144. X.TP
  145. X.B g,G
  146. Xspecify a conversion using the
  147. X.B e,E
  148. Xformat respectively if the
  149. Xexponent is less than -4 or greater than or equal to the precision;
  150. Xotherwise the 
  151. X.B f
  152. Xformat is used.
  153. X.TP
  154. X.B p
  155. Xis used to print pointers (type \fIvoid *\fR,
  156. Xor \fIchar *\fR if the compiler does not support the former).
  157. X.TP
  158. X.B n
  159. Xexpects a \fIint *\fR argument and puts in that integer 
  160. Xthe number of characters already printed by this call.
  161. X.TP
  162. X.B %
  163. Xis used to print a \fI%\fR.
  164. X.LP
  165. XIf an unknown conversion character is specified, the percent sign
  166. Xfollowed by that character will be printed.
  167. X.SH RETURN VALUE
  168. X.LP
  169. XIf no error occured, \fBSprint()\fR returns the number of characters
  170. Xprinted. In case of error, it returns \fBSIO_ERR\fR.
  171. X.SH BUGS
  172. X.LP
  173. XThis is a list of differences between \fBSprint()\fR and the ANSI C Standard
  174. X\fBprintf()\fR:
  175. X.LP
  176. X\fBSprint()\fR does not support non-removal of trailing zeroes for
  177. X\fBg\fR and \fBG\fR conversions when the '#' flag is used.
  178. X.LP
  179. X\fBSprint()\fR does not support the h and L modifiers.
  180. X.LP
  181. XThe current implementation assumes that \fIsizeof(int)==sizeof(long)\fR.
  182. X.LP
  183. X\fBSprint()\fR supports "%p" only if \fIsizeof(pointer)<=sizeof(int)\fR.
  184. END_OF_FILE
  185. if test 5277 -ne `wc -c <'libs/src/sio/Sprint.3'`; then
  186.     echo shar: \"'libs/src/sio/Sprint.3'\" unpacked with wrong size!
  187. fi
  188. # end of 'libs/src/sio/Sprint.3'
  189. fi
  190. if test -f 'libs/src/sio/sioconf.h' -a "${1}" != "-c" ; then 
  191.   echo shar: Will not clobber existing file \"'libs/src/sio/sioconf.h'\"
  192. else
  193. echo shar: Extracting \"'libs/src/sio/sioconf.h'\" \(5101 characters\)
  194. sed "s/^X//" >'libs/src/sio/sioconf.h' <<'END_OF_FILE'
  195. X/*
  196. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  197. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  198. X * and conditions for redistribution.
  199. X */
  200. X
  201. X
  202. X/*
  203. X * $Id: sioconf.h,v 8.5 1993/03/17 02:54:47 panos Exp $
  204. X */
  205. X
  206. X/*
  207. X * This file has 2 sections:
  208. X *        1. a OS-specific section
  209. X *        2. a CPU/compiler-specific section
  210. X *
  211. X * You can override/redefing any of the constants/macros in this file.
  212. X * by uncommenting the inclusion of customconf.h and placing your own
  213. X * definitions in that file.
  214. X */
  215. X
  216. X/* #include "customconf.h" */
  217. X
  218. X
  219. X
  220. X/*
  221. X * OS-specific section.
  222. X *
  223. X * Features here use the flag HAS_<feature>.
  224. X * List of flags (check the following for macros that can be overriden):
  225. X *
  226. X *            HAS_MMAP (overridable macros)
  227. X *
  228. X *            HAS_ATEXIT
  229. X *            HAS_ONEXIT
  230. X *            HAS_OTHER_FINALIZER    (must define macros)
  231. X *
  232. X *            HAS_MEMOPS
  233. X *            HAS_BCOPY             (HAS_MEMOPS will be preferred if both are defined)
  234. X *
  235. X *    At least one of the following flags must be defined. The 2nd and 3rd
  236. X * flags are incompatible.
  237. X *            HAS_ISATTY
  238. X *            HAS_SYSVTTY
  239. X *            HAS_BSDTTY
  240. X */
  241. X
  242. X/*
  243. X * Memory mapping.
  244. X *        The library requires 3 macros: SIO_MMAP, SIO_MUNMAP, SIO_MNEED.
  245. X *        You can selectively override any of them.
  246. X *        Notice that the SIO_MNEED macro is not required. If your system
  247. X *        does not have madvise, you can define the macro as:
  248. X *            #define SIO_MNEED( addr, len )
  249. X */
  250. X#ifdef HAS_MMAP
  251. X
  252. X#if !defined( SIO_MMAP ) || !defined( SIO_MUNMAP ) || !defined( SIO_MNEED )
  253. X#include <sys/types.h>
  254. X#include <sys/mman.h>
  255. X#endif
  256. X
  257. X#ifndef SIO_MMAP
  258. X#define SIO_MMAP( addr, len, fd, off )                                  \
  259. X         mmap( addr, len, PROT_READ,                                    \
  260. X            ( addr == 0 ) ? MAP_PRIVATE : MAP_PRIVATE + MAP_FIXED,      \
  261. X               fd, off )
  262. X#endif
  263. X
  264. X#ifndef SIO_MUNMAP
  265. X#define SIO_MUNMAP( addr, len )  munmap( addr, len )
  266. X#endif
  267. X
  268. X#ifndef SIO_MNEED
  269. X#define SIO_MNEED( addr, len )      (void) madvise( addr, len, MADV_WILLNEED )
  270. X#endif
  271. X
  272. X#endif    /* HAS_MMAP */
  273. X
  274. X/*
  275. X * N_SIO_DESCRIPTORS is the maximum number of file descriptors
  276. X * supported by the OS
  277. X */
  278. X#ifndef N_SIO_DESCRIPTORS
  279. X#include <sys/param.h>
  280. X#define N_SIO_DESCRIPTORS        NOFILE
  281. X#endif
  282. X
  283. X
  284. X
  285. X/*
  286. X * Finalization function. 
  287. X *
  288. X * The purpose of this function is to do work after your program has
  289. X * called exit(3). In the case of SIO, this means flushing the SIO
  290. X * output buffers.
  291. X *
  292. X * If your system does not support atexit or onexit but has some other
  293. X * way of installing a finalization function, you define the flag 
  294. X * HAS_FINALIZER. Then you must define the macros 
  295. X *            SIO_FINALIZE and SIO_DEFINE_FIN
  296. X *
  297. X * SIO_FINALIZE attempts to install a finalization function and returns TRUE 
  298. X * if successful, FALSE if unsuccessful.
  299. X * SIO_DEFINE_FIN defines the finalization function (the reason for this macro
  300. X * s that different systems pass different number/type of arguments to the
  301. X * finalization function; the SIO finalization function does not use any
  302. X * arguments).
  303. X */
  304. X#if defined(HAS_ONEXIT) || defined(HAS_ATEXIT) || defined(HAS_FINALIZER)
  305. X
  306. X#define HAS_FINALIZATION_FUNCTION
  307. X
  308. X#if defined( HAS_ONEXIT ) && defined( HAS_ATEXIT )
  309. X#undef HAS_ONEXIT
  310. X#endif
  311. X
  312. X#ifdef HAS_ONEXIT
  313. X#define SIO_FINALIZE( func )        ( on_exit( func, (caddr_t) 0 ) == 0 )
  314. X#define SIO_DEFINE_FIN( func )      static void func ( exit_status, arg )  \
  315. X                                          int exit_status ;                \
  316. X                                          caddr_t arg ;
  317. X#endif    /* HAS_ONEXIT */
  318. X
  319. X#ifdef HAS_ATEXIT
  320. X#define SIO_FINALIZE( func )        ( atexit( func ) == 0 )
  321. X#define SIO_DEFINE_FIN( func )      static void func ()
  322. X#endif    /* HAS_ATEXIT */
  323. X
  324. X#endif    /* HAS_ONEXIT || HAS_ATEXIT || HAS_FINALIZER */
  325. X
  326. X
  327. X/*
  328. X * HAS_MEMOPS should be defined if your OS supports the mem* functions
  329. X * (memcpy etc). If not, then you can define HAS_BCOPY if your OS supports 
  330. X * bcopy.
  331. X */
  332. X#if defined( HAS_MEMOPS ) && defined( HAS_BCOPY )
  333. X#undef HAS_BCOPY
  334. X#endif
  335. X
  336. X
  337. X/*
  338. X * Support for the isatty(3) function. This function identifies if a 
  339. X * desciptor refers to a terminal.
  340. X *
  341. X * Case 1: isatty(3) is in the C library
  342. X *        --> define HAS_ISATTY
  343. X *    Case 2: no isatty(3), BSD 4.3 tty handling
  344. X *        --> define HAS_BSDTTY
  345. X * Case 3: no isatty(3), System V tty handling
  346. X *        --> define HAS_SYSVTTY
  347. X *
  348. X * The following code checks:
  349. X *        1) that at least one of the flags is defined
  350. X *        2) only one of the BSD, SYS V flags is defined
  351. X */
  352. X#if !defined(HAS_ISATTY) && !defined(HAS_BSDTTY) && !defined(HAS_SYSVTTY)
  353. XERROR function_isatty_not_available ;
  354. X#endif
  355. X
  356. X#ifdef HAS_ISATTY
  357. X#undef HAS_BSDTTY
  358. X#undef HAS_SYSVTTY
  359. X#endif
  360. X
  361. X#if defined(HAS_BSDTTY) && defined(HAS_SYSVTTY)
  362. XERROR HAS_BSDTTY_and_HAS_SYSVTTY_both_defined ;
  363. X#endif
  364. X
  365. X
  366. X
  367. X/*
  368. X * CPU/compiler-specific section.
  369. X *
  370. X * The following constant affects the behavior of Sprint.
  371. X *
  372. X * Sprint performs integer->string conversions by first converting
  373. X * the integer to the widest int type supported by the CPU/compiler.
  374. X * By default, this is the "long int" type. If your machine has
  375. X * a wider type, you can specify it by defining the WIDE_INT constant.
  376. X * For example:
  377. X *        #define WIDE_INT                    long long
  378. X */
  379. X
  380. END_OF_FILE
  381. if test 5101 -ne `wc -c <'libs/src/sio/sioconf.h'`; then
  382.     echo shar: \"'libs/src/sio/sioconf.h'\" unpacked with wrong size!
  383. fi
  384. # end of 'libs/src/sio/sioconf.h'
  385. fi
  386. if test -f 'xinetd/config.h' -a "${1}" != "-c" ; then 
  387.   echo shar: Will not clobber existing file \"'xinetd/config.h'\"
  388. else
  389. echo shar: Extracting \"'xinetd/config.h'\" \(5195 characters\)
  390. sed "s/^X//" >'xinetd/config.h' <<'END_OF_FILE'
  391. X/*
  392. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  393. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  394. X * and conditions for redistribution.
  395. X */
  396. X
  397. X#ifndef CONFIG_H
  398. X#define CONFIG_H
  399. X
  400. X/*
  401. X * $Id: config.h,v 6.5 1993/06/13 01:42:32 panos Exp $
  402. X */
  403. X
  404. X/*
  405. X * The purpose of customconf.h is to allow the override of
  406. X * constants defined in this file. These include all constants that
  407. X * cannot be overriden from the command line via some option.
  408. X */
  409. X#ifdef CUSTOMCONF
  410. X#include "customconf.h"
  411. X#endif
  412. X
  413. X
  414. X#define DEFAULT_CONFIG_FILE            "/etc/xinetd.conf"
  415. X
  416. X/*
  417. X * This is the facility used by xinetd to log syslog messages
  418. X */
  419. X#define DEFAULT_SYSLOG_FACILITY      LOG_DAEMON
  420. X
  421. X/*
  422. X * This is the level used for log messages when a service logs to syslog
  423. X */
  424. X#define DEFAULT_SERVICE_SYSLOG_LEVEL    LOG_INFO
  425. X
  426. X/*
  427. X * Max number of concurrently running processes forked to get 
  428. X * the user id from the remote host
  429. X */
  430. X#define DEFAULT_LOGPROCS                15
  431. X
  432. X/*
  433. X * Max number of concurrently running processes forked to do service shutdown
  434. X */
  435. X#define DEFAULT_SHUTDOWNPROCS            10
  436. X
  437. X/*
  438. X * The loop rate is a bound on the rate of forking servers for a
  439. X * particular service. If that rate is exceeded, the service is deactivated.
  440. X */
  441. X#define DEFAULT_LOOP_RATE                10
  442. X
  443. X/*
  444. X * Signal-to-action mapping
  445. X */
  446. X#ifndef RECONFIG_SOFT_SIG
  447. X#define RECONFIG_SOFT_SIG                SIGUSR1
  448. X#endif
  449. X#ifndef RECONFIG_HARD_SIG
  450. X#define RECONFIG_HARD_SIG                SIGUSR2
  451. X#endif
  452. X#ifndef TERMINATION_SIG
  453. X#define TERMINATION_SIG                    SIGTERM
  454. X#endif
  455. X#ifndef STATE_DUMP_SIG
  456. X#define STATE_DUMP_SIG                    SIGHUP
  457. X#endif
  458. X#ifndef CONSISTENCY_CHECK_SIG
  459. X#define CONSISTENCY_CHECK_SIG            SIGIOT
  460. X#endif
  461. X#ifndef RETRY_SIG
  462. X#define RETRY_SIG                            SIGALRM
  463. X#endif
  464. X#ifndef SERVER_EXIT_SIG
  465. X#define SERVER_EXIT_SIG                    SIGCHLD
  466. X#endif
  467. X#ifndef QUIT_SIG
  468. X#define QUIT_SIG                            SIGQUIT
  469. X#endif
  470. X
  471. X/*
  472. X * This is the file where the internal state of xinetd is dumped upon 
  473. X * receipt of STATE_DUMP_SIG
  474. X */
  475. X#ifndef DUMP_FILE
  476. X#define DUMP_FILE                            "/tmp/xinetd.dump"
  477. X#endif
  478. X
  479. X/*
  480. X * CONF_TIMEOUT determines if there will be a timeout for reading the
  481. X * configuration file. The timeout is specified in seconds.
  482. X *        Case 1: CONF_TIMEOUT is undefined
  483. X *            there will be a timeout equal to a default value (60 sec).
  484. X *        Case 2: CONF_TIMEOUT is a positive number
  485. X *            there will be a timeout equal to the value of CONF_TIMEOUT
  486. X *        Case 3: CONF_TIMEOUT is 0
  487. X *            no timeout
  488. X */
  489. X#ifndef CONF_TIMEOUT
  490. X#define CONF_TIMEOUT                        60
  491. X#endif
  492. X
  493. X/*
  494. X * There are 2 timeouts (in seconds) when trying to get the user id from 
  495. X * the remote host. Any timeout value specified as 0 implies an infinite
  496. X * timeout.
  497. X * LOGUSER_SUCCESS_TIMEOUT is the timeout when access control has been passed 
  498. X * and a new process has been forked to exec the server. 
  499. X * LOGUSER_FAILURE_TIMEOUT is the timeout when the attempt to access the
  500. X * service has been rejected.
  501. X *
  502. X * Both timeouts should be at least 30 seconds as suggested in RFC 1413
  503. X * (assuming they are not 'infinite' timeouts).
  504. X */
  505. X#ifndef LOGUSER_SUCCESS_TIMEOUT
  506. X#define LOGUSER_SUCCESS_TIMEOUT        0
  507. X#endif
  508. X#ifndef LOGUSER_FAILURE_TIMEOUT
  509. X#define LOGUSER_FAILURE_TIMEOUT        30
  510. X#endif
  511. X
  512. X/*
  513. X * This is used when an instance limit is not specified for a service
  514. X * and the defaults entry does not specify an instance limit either.
  515. X * It can be a positive number or "UNLIMITED".
  516. X */
  517. X#ifndef DEFAULT_INSTANCE_LIMIT
  518. X#define DEFAULT_INSTANCE_LIMIT        UNLIMITED
  519. X#endif
  520. X
  521. X/*
  522. X * This is the interval (in seconds) over which we check if the service 
  523. X * loop rate has been exceeded.
  524. X */
  525. X#ifndef LOOP_INTERVAL
  526. X#define LOOP_INTERVAL                    2
  527. X#endif
  528. X
  529. X/*
  530. X * LOG_OPEN_FLAGS are the flags used to open a log file (this is used as 
  531. X * the 3rd argument of open(2))
  532. X */
  533. X#ifndef LOG_OPEN_FLAGS
  534. X#define LOG_OPEN_FLAGS                    O_CREAT+O_APPEND+O_WRONLY
  535. X#endif
  536. X
  537. X/*
  538. X * Number of consecutive fork failures that we are willing to put up with
  539. X * before giving up.
  540. X */
  541. X#ifndef MAX_FORK_FAILURES
  542. X#define MAX_FORK_FAILURES            5
  543. X#endif
  544. X
  545. X/*
  546. X * This is the time period during which we will not log subsequest attempts 
  547. X * to access a datagram-based service from the same bad address after logging 
  548. X * the first one.
  549. X * For example, if we receive a datagram at time t from address A which
  550. X * has a match in the no_access list, we will log the failed attempt and 
  551. X * during the interval (t, t+DGRAM_IGNORE_TIME) we will not log attempts 
  552. X * from address A (for the same service).
  553. X * In this context, the address is defined as (IP address, port number).
  554. X */
  555. X#ifndef DGRAM_IGNORE_TIME
  556. X#define DGRAM_IGNORE_TIME                60            /* seconds */
  557. X#endif
  558. X
  559. X#ifndef DUMP_FILE_MODE
  560. X#define DUMP_FILE_MODE                    0644
  561. X#endif
  562. X
  563. X#ifndef LOG_FILE_MODE
  564. X#define LOG_FILE_MODE                 0644
  565. X#endif
  566. X
  567. X/*
  568. X * The DATAGRAM_SIZE should be big enough for an ethernet packet
  569. X */
  570. X#ifndef DATAGRAM_SIZE
  571. X#define DATAGRAM_SIZE                    2048
  572. X#endif
  573. X
  574. X/*
  575. X * Time interval between retry attempts
  576. X */
  577. X#ifndef RETRY_INTERVAL
  578. X#define RETRY_INTERVAL                    5        /* seconds */
  579. X#endif
  580. X
  581. X/*
  582. X * LOG_EXTRA_MIN, LOG_EXTRA_MAX define the limits by which the hard limit
  583. X * on the log size can exceed the soft limit
  584. X */
  585. X#ifndef LOG_EXTRA_MIN
  586. X#define LOG_EXTRA_MIN                    (  5 * 1024 )
  587. X#endif
  588. X#ifndef LOG_EXTRA_MAX
  589. X#define LOG_EXTRA_MAX                    ( 20 * 1024 )
  590. X#endif
  591. X
  592. X#endif    /* CONFIG_H */
  593. END_OF_FILE
  594. if test 5195 -ne `wc -c <'xinetd/config.h'`; then
  595.     echo shar: \"'xinetd/config.h'\" unpacked with wrong size!
  596. fi
  597. # end of 'xinetd/config.h'
  598. fi
  599. if test -f 'xinetd/int.c' -a "${1}" != "-c" ; then 
  600.   echo shar: Will not clobber existing file \"'xinetd/int.c'\"
  601. else
  602. echo shar: Extracting \"'xinetd/int.c'\" \(5085 characters\)
  603. sed "s/^X//" >'xinetd/int.c' <<'END_OF_FILE'
  604. X/*
  605. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  606. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  607. X * and conditions for redistribution.
  608. X */
  609. X
  610. Xstatic char RCSid[] = "$Id: int.c,v 6.5 1993/06/15 23:25:57 panos Exp $" ;
  611. X
  612. X#include <sys/types.h>
  613. X#include <sys/socket.h>
  614. X#include <syslog.h>
  615. X#include <errno.h>
  616. X#include <signal.h>
  617. X
  618. X#include "config.h"
  619. X#include "connection.h"
  620. X#include "service.h"
  621. X#include "server.h"
  622. X#include "int.h"
  623. X
  624. Xvoid msg() ;
  625. Xchar *inet_ntoa() ;
  626. Xunsigned long inet_addr() ;
  627. X
  628. Xtypedef struct intercept *(*initfunc)() ;
  629. X
  630. Xstruct lookup_table
  631. X{
  632. X    initfunc    initializer ;
  633. X    int        socket_type ;
  634. X} ;
  635. X
  636. Xextern struct intercept *di_init() ;
  637. Xextern struct intercept *si_init() ;
  638. X
  639. Xstatic struct lookup_table intercept_lookup_table[] =
  640. X    {
  641. X        { di_init,            SOCK_DGRAM },
  642. X        { si_init,            SOCK_STREAM },
  643. X        { NULL }
  644. X    } ;
  645. X
  646. X            
  647. X/*
  648. X * This variable has file scope for the benefit of the signal handler
  649. X */
  650. Xstatic struct intercept *intp ;
  651. X
  652. X
  653. X
  654. XPRIVATE initfunc find_initializer( type )
  655. X    int type ;
  656. X{
  657. X    struct lookup_table *ltp ;
  658. X
  659. X    for ( ltp = intercept_lookup_table ; ltp->initializer ; ltp++ )
  660. X        if ( ltp->socket_type == type )
  661. X            return( ltp->initializer ) ;
  662. X    msg( LOG_ERR, "find_initializer", "No initializer for type %d", type ) ;
  663. X    _exit( 0 ) ;
  664. X    /* NOTREACHED */
  665. X}
  666. X
  667. X
  668. X/*
  669. X * This function is the interface of the intercept code with the rest of 
  670. X * the program. 
  671. X */
  672. Xvoid intercept( serp )
  673. X    struct server *serp ;
  674. X{
  675. X    struct service *sp = SERVER_SERVICE( serp ) ;
  676. X    initfunc initializer ;
  677. X    PRIVATE void start_server() ;
  678. X    PRIVATE void terminate_server() ;
  679. X
  680. X#ifdef DEBUG_INTERCEPTOR
  681. X    if ( debug.on )
  682. X    {
  683. X        msg( LOG_DEBUG, "intercept", "%d is sleeping", getpid() ) ;
  684. X        sleep( 10 ) ;
  685. X    }
  686. X#endif
  687. X
  688. X    initializer = find_initializer( SVC_SOCKET_TYPE( sp ) ) ;
  689. X    intp = (*initializer)( serp ) ;
  690. X    start_server( intp ) ;
  691. X    (*intp->int_ops->mux)() ;
  692. X    terminate_server( intp ) ;
  693. X    /*
  694. X     * the terminate_server function should not return but even if it
  695. X     * does, child_process will do the _exit.
  696. X     */ 
  697. X}
  698. X
  699. X
  700. X
  701. X/*
  702. X * Create a socket and bind it to (INADDR_LOOPBACK,0)
  703. X */
  704. XPRIVATE int get_server_socket( ip )
  705. X    struct intercept *ip ;
  706. X{
  707. X    struct service *sp = SERVER_SERVICE( INT_SERVER( ip ) ) ;
  708. X    struct sockaddr_in *sinp = INT_LOCALADDR( ip ) ;
  709. X    int sd ;
  710. X    int size ;
  711. X    char *func = "get_server_socket" ;
  712. X
  713. X    if ( ( sd = socket( AF_INET, SVC_SOCKET_TYPE( sp ), 0 ) ) == -1 )
  714. X        int_fail( ip, "socket creation" ) ;
  715. X    
  716. X    sinp->sin_family = AF_INET ;
  717. X#ifdef INADDR_LOOPBACK
  718. X    sinp->sin_addr.s_addr = htonl( INADDR_LOOPBACK ) ;
  719. X#else
  720. X    sinp->sin_addr.s_addr = inet_addr( "127.0.0.1" ) ;
  721. X#endif
  722. X    sinp->sin_port = 0 ;
  723. X
  724. X    if ( bind( sd, SA( sinp ), sizeof( *sinp ) ) == -1 )
  725. X        int_fail( ip, "bind" ) ;
  726. X    
  727. X    size = sizeof( *sinp ) ;
  728. X    if ( getsockname( sd, SA( sinp ), &size ) == -1 )
  729. X        int_fail( ip, "getsockname" ) ;
  730. X    
  731. X    if ( debug.on )
  732. X        msg( LOG_DEBUG, func, "address = %s, port = %d",
  733. X            inet_ntoa( sinp->sin_addr ), ntohs( sinp->sin_port ) ) ;
  734. X        
  735. X    if ( ip->int_socket_type == SOCK_STREAM )
  736. X        (void) listen( sd, LISTEN_BACKLOG ) ;
  737. X    
  738. X    return( sd ) ;
  739. X}
  740. X
  741. X
  742. XPRIVATE void start_server( ip )
  743. X    struct intercept *ip ;
  744. X{
  745. X    struct server        *serp = INT_SERVER( ip ) ;
  746. X    struct service        *sp = SERVER_SERVICE( serp ) ;
  747. X    int                    server_socket ;
  748. X    pid_t                    pid ;
  749. X    void                    child_process() ;
  750. X
  751. X    server_socket = get_server_socket( ip ) ;
  752. X    
  753. X    pid = fork() ;
  754. X
  755. X    switch ( pid )
  756. X    {
  757. X        case -1:
  758. X            int_fail( ip, "fork" ) ;
  759. X            /* NOTREACHED */
  760. X        
  761. X        case 0:
  762. X            conn_set_descriptor( SERVER_CONNECTION( serp ), server_socket ) ;
  763. X            svc_make_external( sp ) ;                /* avoid looping */
  764. X            child_process( serp ) ;
  765. X            /* NOTREACHED */
  766. X        
  767. X        default:
  768. X            server_set_pid( serp, pid ) ;
  769. X            (void) close( server_socket ) ;
  770. X    }
  771. X}
  772. X
  773. X
  774. X
  775. X/*
  776. X * Return value:
  777. X *            OK             if the server died
  778. X *            FAILED         otherwise
  779. X */
  780. XPRIVATE status_e wait_child( ip )
  781. X    struct intercept *ip ;
  782. X{
  783. X    char *func = "wait_child" ;
  784. X
  785. X    for ( ;; )
  786. X    {
  787. X        int status ;
  788. X        pid_t pid = wait( &status ) ;
  789. X
  790. X        if ( pid == -1 )
  791. X        {
  792. X            if ( errno != EINTR )
  793. X            {
  794. X                msg( LOG_ERR, func, "wait: %m" ) ;
  795. X                return( FAILED ) ;
  796. X            }
  797. X        }
  798. X        else if ( pid == SERVER_PID( INT_SERVER( ip ) ) )
  799. X        {
  800. X            if ( PROC_STOPPED( status ) )
  801. X                return( FAILED ) ;
  802. X            server_set_exit_status( INT_SERVER( ip ), status ) ;
  803. X            return( OK ) ;
  804. X        }
  805. X        else
  806. X        {
  807. X            msg( LOG_ERR, func,
  808. X                "wait returned pid of unknown process: %d", pid ) ;
  809. X            return( FAILED ) ;
  810. X        }
  811. X    }
  812. X}
  813. X
  814. X
  815. X
  816. XPRIVATE void terminate_server( ip )
  817. X    struct intercept *ip ;
  818. X{
  819. X    pid_t pid = SERVER_PID( INT_SERVER( intp ) ) ;
  820. X
  821. X    if ( pid > 0 )
  822. X        (void) kill( pid, SIGKILL ) ;
  823. X
  824. X    /*
  825. X     * Normally, wait_child should never return since a SIGCHLD will 
  826. X     * invoke the signal handler which will then call the exit function.
  827. X     */
  828. X    if ( wait_child( ip ) == OK )
  829. X        (*intp->int_ops->exit)() ;
  830. X}
  831. X
  832. X
  833. Xvoid int_sighandler( sig )
  834. X    int sig ;
  835. X{
  836. X    char *func = "int_sighandler" ;
  837. X    char *sig_name() ;
  838. X
  839. X    if ( debug.on )
  840. X        msg( LOG_DEBUG, func, "Received signal %s", sig_name( sig ) ) ;
  841. X
  842. X    if ( sig == SERVER_EXIT_SIG )
  843. X    {
  844. X        if ( wait_child( intp ) == OK )
  845. X            (*intp->int_ops->exit)() ;
  846. X    }
  847. X    else if ( sig == INTERCEPT_SIG )
  848. X        INTERCEPT( intp ) = FALSE ;
  849. X    else if ( sig == SIGTERM )
  850. X        terminate_server( intp ) ;
  851. X}
  852. END_OF_FILE
  853. if test 5085 -ne `wc -c <'xinetd/int.c'`; then
  854.     echo shar: \"'xinetd/int.c'\" unpacked with wrong size!
  855. fi
  856. # end of 'xinetd/int.c'
  857. fi
  858. if test -f 'xinetd/retry.c' -a "${1}" != "-c" ; then 
  859.   echo shar: Will not clobber existing file \"'xinetd/retry.c'\"
  860. else
  861. echo shar: Extracting \"'xinetd/retry.c'\" \(5411 characters\)
  862. sed "s/^X//" >'xinetd/retry.c' <<'END_OF_FILE'
  863. X/*
  864. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  865. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  866. X * and conditions for redistribution.
  867. X */
  868. X
  869. Xstatic char RCSid[] = "$Id: retry.c,v 6.8 1993/06/15 23:25:57 panos Exp $" ;
  870. X
  871. X#include <sys/time.h>
  872. X#include <syslog.h>
  873. X
  874. X#include "pset.h"
  875. X
  876. X#include "state.h"
  877. X#include "access.h"
  878. X#include "config.h"
  879. X#include "server.h"
  880. X#include "connection.h"
  881. X#include "flags.h"
  882. X
  883. Xvoid msg() ;
  884. Xvoid out_of_memory() ;
  885. X
  886. Xstatic bool_int retry_timer_running ;
  887. X
  888. XPRIVATE void stop_retry_timer() ;
  889. XPRIVATE void start_retry_timer() ;
  890. X
  891. X
  892. X/*
  893. X * Attempt to start all servers in the retry table
  894. X */
  895. Xvoid server_retry()
  896. X{
  897. X    unsigned                servers_started = 0 ;
  898. X    register unsigned u ;
  899. X    char                    *func = "server_retry" ;
  900. X    PRIVATE void        cancel_retry() ;
  901. X
  902. X    for ( u = 0 ; u < pset_count( RETRIES( ps ) ) ; u++ )
  903. X    {
  904. X        register struct server *retry = SERP( 
  905. X                                                    pset_pointer( RETRIES( ps ), u ) ) ;
  906. X        register struct service *sp = SERVER_SERVICE( retry ) ;
  907. X        connection_s *cp = SERVER_CONNECTION( retry ) ;
  908. X
  909. X        /*
  910. X         * Drop the retry if access control fails or we have
  911. X         * a memory allocation problem
  912. X         */
  913. X        if ( svc_access_control( sp, cp ) == FAILED ||
  914. X                      pset_add( SERVERS( ps ), retry ) == NULL )
  915. X        {
  916. X            cancel_retry( retry ) ;
  917. X            pset_pointer( RETRIES( ps ), u ) = NULL ;
  918. X            continue ;
  919. X        }
  920. X
  921. X        if ( server_start( retry ) == OK )
  922. X        {
  923. X            servers_started++ ;
  924. X            svc_dec_retries( sp ) ;
  925. X            conn_close( cp ) ;
  926. X            pset_pointer( RETRIES( ps ), u ) = NULL ;
  927. X            continue ;
  928. X        }
  929. X        else
  930. X        {
  931. X            pset_remove( SERVERS( ps ), retry ) ;
  932. X            if ( SERVER_FORKLIMIT( retry ) )
  933. X            {
  934. X                /*
  935. X                 * give up retrying
  936. X                 */
  937. X                msg( LOG_ERR, func,
  938. X                    "service %s: too many consecutive fork failures", SVC_ID(sp) ) ;
  939. X                svc_log_failure( sp, cp, AC_FORK ) ;
  940. X                cancel_retry( retry ) ;
  941. X                pset_pointer( RETRIES( ps ), u ) = NULL ;
  942. X                continue ;
  943. X            }
  944. X            else
  945. X            {
  946. X                if ( debug.on )
  947. X                    msg( LOG_DEBUG, func,
  948. X                        "fork failed for service %s. Retrying...", SVC_ID( sp ) ) ;
  949. X            }
  950. X        }
  951. X    }
  952. X
  953. X    pset_compact( RETRIES( ps ) ) ;
  954. X
  955. X    if ( debug.on )
  956. X        msg( LOG_DEBUG, func,
  957. X            "%d servers started, %d left to retry",
  958. X                servers_started, pset_count( RETRIES( ps ) ) ) ;
  959. X
  960. X    if ( pset_count( RETRIES( ps ) ) == 0 )
  961. X        stop_retry_timer() ;
  962. X}
  963. X
  964. X
  965. X/*
  966. X * Schedule a retry by inserting the struct server in the retry table
  967. X * and starting the timer if necessary
  968. X */
  969. Xstatus_e schedule_retry( serp )
  970. X    struct server *serp ;
  971. X{
  972. X    struct service *sp = SERVER_SERVICE( serp ) ;
  973. X    char *func = "schedule_retry" ;
  974. X
  975. X    if ( pset_add( RETRIES( ps ), serp ) == NULL )
  976. X    {
  977. X        out_of_memory( func ) ;
  978. X        return( FAILED ) ;
  979. X    }
  980. X    svc_inc_retries( sp ) ;
  981. X    start_retry_timer() ;
  982. X    if ( debug.on )
  983. X        msg( LOG_DEBUG, func, "Scheduled retry attempt for %s", SVC_ID( sp ) ) ;
  984. X    return( OK ) ;
  985. X}
  986. X
  987. X
  988. X/*
  989. X * This function should not be called for servers that correspond to
  990. X * services not in the service table because server_release will result
  991. X * in releasing all memory associated with the service (since the ref
  992. X * count will drop to 0).
  993. X */
  994. XPRIVATE void cancel_retry( serp )
  995. X    struct server *serp ;
  996. X{
  997. X    struct service *sp = SERVER_SERVICE( serp ) ;
  998. X
  999. X    conn_free( SERVER_CONNECTION( serp ) ) ;
  1000. X    svc_dec_retries( sp ) ;
  1001. X    server_release( serp ) ;
  1002. X}
  1003. X
  1004. X
  1005. X
  1006. X/*
  1007. X * Cancel all retry attempts for the specified service
  1008. X */
  1009. Xvoid cancel_service_retries( sp )
  1010. X   register struct service *sp ;
  1011. X{
  1012. X   register unsigned u ;
  1013. X   char *func = "cancel_service_retries" ;
  1014. X
  1015. X    if ( SVC_RETRIES( sp ) == 0 )
  1016. X      return ;
  1017. X
  1018. X    u = 0 ;
  1019. X    while ( u < pset_count( RETRIES( ps ) ) )
  1020. X    {
  1021. X        register struct server *serp ;
  1022. X
  1023. X        serp = SERP( pset_pointer( RETRIES( ps ), u ) ) ;
  1024. X        if ( SERVER_SERVICE( serp ) == sp )
  1025. X        {
  1026. X            msg( LOG_NOTICE, func,
  1027. X            "dropping retry attempt for service %s", SVC_ID( sp ) ) ;
  1028. X            cancel_retry( serp ) ;
  1029. X            pset_remove_index( RETRIES( ps ), u ) ;
  1030. X            continue ;
  1031. X        }
  1032. X        u++ ;
  1033. X   }
  1034. X
  1035. X    if ( pset_count( RETRIES( ps ) ) == 0 )
  1036. X        stop_retry_timer() ;
  1037. X}
  1038. X
  1039. X
  1040. X#ifndef NO_TIMERS
  1041. X
  1042. X#include "timer.h"
  1043. X
  1044. Xstatic timer_h retry_timer ;
  1045. X
  1046. Xstatus_e create_retry_timer()
  1047. X{
  1048. X    retry_timer = timer_create( TIMER_REAL, TIMER_RETURN_ERROR, INT_NULL ) ;
  1049. X    return( ( retry_timer == NULL ) ? FAILED : OK ) ;
  1050. X}
  1051. X
  1052. X
  1053. XPRIVATE void retry_action( tp, arg )
  1054. X    timer_h tp ;
  1055. X    void *arg ;
  1056. X{
  1057. X#ifdef lint
  1058. X    tp = tp ;
  1059. X    arg = arg ;
  1060. X#endif
  1061. X    M_SET( ps.flags, RETRY_FLAG ) ;
  1062. X}
  1063. X
  1064. X#endif        /* ! NO_TIMERS */
  1065. X
  1066. X
  1067. XPRIVATE void start_retry_timer()
  1068. X{
  1069. X    /*
  1070. X     * The retry itimerval is set so that the timer expires every 
  1071. X     * RETRY_INTERVAL seconds when it is enabled.
  1072. X     */
  1073. X    static struct itimerval itv =
  1074. X        {
  1075. X            { RETRY_INTERVAL, 0 },
  1076. X            { RETRY_INTERVAL, 0 }
  1077. X        } ;
  1078. X    char *func = "start_retry_timer" ;
  1079. X
  1080. X    /*
  1081. X     * Enable timer if necessary.
  1082. X     */
  1083. X
  1084. X#ifndef NO_TIMERS
  1085. X    if ( ! retry_timer_running )
  1086. X    {
  1087. X        struct timer_action ta ;
  1088. X
  1089. X        ta.ta_flags = TIMER_NOFLAGS ;
  1090. X        ta.ta_func = retry_action ;
  1091. X        ta.ta_arg = VOID_NULL ;
  1092. X        if ( timer_start( retry_timer, &itv, TIMER_RELATIVE, &ta ) == TIMER_ERR )
  1093. X        {
  1094. X            msg( LOG_ERR, func, "failed to start retry timer" ) ;
  1095. X            return ;
  1096. X        }
  1097. X        retry_timer_running = TRUE ;
  1098. X    }
  1099. X#else
  1100. X    if ( ! retry_timer_running )
  1101. X        if ( setitimer( ITIMER_REAL, &itv, ITIMERVAL_NULL ) == -1 )
  1102. X            msg( LOG_ERR, func, "setitimer: %m" ) ;
  1103. X        else
  1104. X            retry_timer_running = TRUE ;
  1105. X#endif
  1106. X}
  1107. X
  1108. X
  1109. XPRIVATE void stop_retry_timer()
  1110. X{
  1111. X    if ( retry_timer_running )
  1112. X    {
  1113. X#ifndef NO_TIMERS
  1114. X        timer_stop( retry_timer ) ;
  1115. X#else
  1116. X        (void) setitimer( ITIMER_REAL, ITIMERVAL_NULL, ITIMERVAL_NULL ) ;
  1117. X#endif
  1118. X        retry_timer_running = FALSE ;
  1119. X    }
  1120. X}
  1121. X
  1122. END_OF_FILE
  1123. if test 5411 -ne `wc -c <'xinetd/retry.c'`; then
  1124.     echo shar: \"'xinetd/retry.c'\" unpacked with wrong size!
  1125. fi
  1126. # end of 'xinetd/retry.c'
  1127. fi
  1128. echo shar: End of archive 12 \(of 31\).
  1129. cp /dev/null ark12isdone
  1130. MISSING=""
  1131. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; do
  1132.     if test ! -f ark${I}isdone ; then
  1133.     MISSING="${MISSING} ${I}"
  1134.     fi
  1135. done
  1136. if test "${MISSING}" = "" ; then
  1137.     echo You have unpacked all 31 archives.
  1138.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1139. else
  1140.     echo You still need to unpack the following archives:
  1141.     echo "        " ${MISSING}
  1142. fi
  1143. ##  End of shell archive.
  1144. exit 0
  1145.