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

  1. Newsgroups: comp.sources.unix
  2. From: panos@cs.colorado.edu (Panos Tsirigotis)
  3. Subject: v26i255: xinetd-2.1.1 - inetd replacement with access control and logging, Part11/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 255
  9. Archive-Name: xinetd-2.1.1/part11
  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 11 (of 31)."
  18. # Contents:  libs/src/misc/env.c libs/src/sio/README xinetd/log.c
  19. #   xinetd/main.c xinetd/sample.conf
  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/misc/env.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'libs/src/misc/env.c'\"
  24. else
  25. echo shar: Extracting \"'libs/src/misc/env.c'\" \(4772 characters\)
  26. sed "s/^X//" >'libs/src/misc/env.c' <<'END_OF_FILE'
  27. X/*
  28. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  29. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  30. X * and conditions for redistribution.
  31. X */
  32. X
  33. Xstatic char RCSid[] = "$Id: env.c,v 1.4 1992/11/03 00:07:50 panos Exp $" ;
  34. X
  35. X#include <memory.h>
  36. X#include <string.h>
  37. X
  38. X#include "misc.h"
  39. X#include "env.h"
  40. X
  41. Xtypedef struct __env env_s ;
  42. X
  43. X#define PRIVATE                    static
  44. X#define INITIAL_VARS                20
  45. X#define INCREASE                    10
  46. X
  47. X#ifndef NULL
  48. X#define NULL                        0
  49. X#endif
  50. X
  51. Xchar *malloc() ;
  52. Xchar *realloc() ;
  53. X
  54. Xint env_errno ;
  55. X
  56. X
  57. X
  58. XPRIVATE env_s *alloc_env( max_vars )
  59. X    unsigned max_vars ;
  60. X{
  61. X    env_s *ep ;
  62. X    unsigned size ;
  63. X    char **pointers ;
  64. X
  65. X    ep = (env_s *) malloc( sizeof( env_s ) ) ;
  66. X    if ( ep == ENV_NULL )
  67. X    {
  68. X        env_errno = ENV_ENOMEM ;
  69. X        return( ENV_NULL ) ;
  70. X    }
  71. X
  72. X    size = ( max_vars + 1 ) * sizeof( char * ) ;
  73. X    pointers = (char **) malloc( size ) ;
  74. X    if ( pointers == NULL )
  75. X    {
  76. X        free( (char *)ep ) ;
  77. X        env_errno = ENV_ENOMEM ;
  78. X        return( ENV_NULL ) ;
  79. X    }
  80. X    (void) memset( (char *)pointers, 0, (int) size ) ;
  81. X
  82. X    ep->vars = pointers ;
  83. X    ep->max_vars = max_vars ;
  84. X    ep->n_vars = 0 ;
  85. X    return( ep ) ;
  86. X}
  87. X
  88. X
  89. Xenv_h env_create( init_env )
  90. X    env_h init_env ;
  91. X{
  92. X    unsigned u ;
  93. X    env_s *ep ;
  94. X    unsigned max_vars ;
  95. X
  96. X    if ( init_env == ENV_NULL )
  97. X        max_vars = INITIAL_VARS ;
  98. X    else
  99. X        max_vars = init_env->n_vars + 5 ;
  100. X    
  101. X    ep = alloc_env( max_vars ) ;
  102. X    if ( ep == NULL )
  103. X    {
  104. X        env_errno = ENV_ENOMEM ;
  105. X        return( ENV_NULL ) ;
  106. X    }
  107. X
  108. X    if ( init_env == ENV_NULL )
  109. X        return( ep ) ;
  110. X
  111. X    for ( u = 0, ep->n_vars = 0 ; u < init_env->n_vars ; u++, ep->n_vars++ )
  112. X    {
  113. X        ep->vars[ ep->n_vars ] = make_string( 1, init_env->vars[ u ] ) ;
  114. X        if ( ep->vars[ ep->n_vars ] == NULL )
  115. X        {
  116. X            env_destroy( ep ) ;
  117. X            env_errno = ENV_ENOMEM ;
  118. X            return( ENV_NULL ) ;
  119. X        }
  120. X    }
  121. X    return( ep ) ;
  122. X}
  123. X
  124. X
  125. Xvoid env_destroy( env )
  126. X    env_h env ;
  127. X{
  128. X    unsigned u ;
  129. X
  130. X    for ( u = 0 ; u < env->n_vars ; u++ )
  131. X        free( env->vars[ u ] ) ;
  132. X    free( (char *)env->vars ) ;
  133. X    free( (char *)env ) ;
  134. X}
  135. X
  136. X
  137. Xenv_h env_make( env_strings )
  138. X    char **env_strings ;
  139. X{
  140. X    env_s *ep ;
  141. X    char **pp ;
  142. X
  143. X    for ( pp = env_strings ; *pp ; pp++ ) ;
  144. X
  145. X    ep = alloc_env( (unsigned) (pp-env_strings) ) ;
  146. X    if ( ep == NULL )
  147. X    {
  148. X        env_errno = ENV_ENOMEM ;
  149. X        return( ENV_NULL ) ;
  150. X    }
  151. X
  152. X    for ( pp = env_strings ; *pp ; pp++ )
  153. X    {
  154. X        char *p = make_string( 1, *pp ) ;
  155. X
  156. X        if ( p == NULL )
  157. X        {
  158. X            env_destroy( ep ) ;
  159. X            env_errno = ENV_ENOMEM ;
  160. X            return( ENV_NULL ) ;
  161. X        }
  162. X        ep->vars[ ep->n_vars++ ] = p ;
  163. X    }
  164. X    return( ep ) ;
  165. X}
  166. X
  167. X
  168. Xchar *env_lookup( env, var )
  169. X    env_h env ;
  170. X    char *var ;
  171. X{
  172. X    char **lookup() ;
  173. X    char **pp = lookup( env, var, strlen( var ) ) ;
  174. X
  175. X    return( ( pp == NULL ) ? NULL : *pp ) ;
  176. X}
  177. X
  178. X
  179. XPRIVATE char **lookup( env, var, len )
  180. X    env_h env ;
  181. X    char *var ;
  182. X    register int len ;
  183. X{
  184. X    register char **pp ;
  185. X
  186. X    for ( pp = env->vars ; *pp ; pp++ )
  187. X        if ( strncmp( *pp, var, len ) == 0 && (*pp)[ len ] == '=' )
  188. X            return( pp ) ;
  189. X    return( NULL ) ;
  190. X}
  191. X
  192. X
  193. XPRIVATE int grow( ep )
  194. X    env_s *ep ;
  195. X{
  196. X    char **new_vars ;
  197. X    unsigned new_max_vars ;
  198. X    unsigned new_size ;
  199. X
  200. X    new_max_vars = ep->max_vars + INCREASE ;
  201. X    new_size = ( new_max_vars+1 ) * sizeof( char * ) ;
  202. X    new_vars = (char **) realloc( (char *)ep->vars, new_size ) ;
  203. X    if ( new_vars == NULL )
  204. X        return( ENV_ERR ) ;
  205. X    
  206. X    ep->vars = new_vars ;
  207. X    ep->max_vars = new_max_vars ;
  208. X    return( ENV_OK ) ;
  209. X}
  210. X
  211. X
  212. X/*
  213. X * Add the variable string to the given environment.
  214. X */
  215. XPRIVATE int addstring( ep, var_string, len )
  216. X    env_s *ep ;
  217. X    char *var_string ;
  218. X    int len ;
  219. X{
  220. X    char **pp ;
  221. X    char *p ;
  222. X
  223. X    p = make_string( 1, var_string ) ;
  224. X    if ( p == NULL )
  225. X        return( ENV_ERR ) ;
  226. X        
  227. X    pp = lookup( ep, var_string, len ) ;
  228. X    if ( pp == NULL )
  229. X    {
  230. X        if ( ep->n_vars >= ep->max_vars && grow( ep ) == ENV_ERR )
  231. X        {
  232. X            free( p ) ;
  233. X            env_errno = ENV_ENOMEM ;
  234. X            return( ENV_ERR ) ;
  235. X        }
  236. X        ep->vars[ ep->n_vars++ ] = p ;
  237. X    }
  238. X    else
  239. X    {
  240. X        free( *pp ) ;
  241. X        *pp = p ;
  242. X    }
  243. X    return( ENV_OK ) ;
  244. X}
  245. X
  246. X
  247. Xint env_addvar( env, from_env, var_name )
  248. X    env_h env ;
  249. X    env_h from_env ;
  250. X    char *var_name ;
  251. X{
  252. X    char *var_string = env_lookup( from_env, var_name ) ;
  253. X
  254. X    if ( var_string == NULL )
  255. X    {
  256. X        env_errno = ENV_EBADVAR ;
  257. X        return( ENV_ERR ) ;
  258. X    }
  259. X
  260. X    return( addstring( env, var_string, strlen( var_name ) ) ) ;
  261. X}
  262. X
  263. X
  264. Xint env_addstr( env, var_string )
  265. X    env_h env ;
  266. X    char *var_string ;
  267. X{
  268. X    char *p = strchr( var_string, '=' ) ;
  269. X
  270. X    if ( p == NULL )
  271. X    {
  272. X        env_errno = ENV_EBADSTRING ;
  273. X        return( ENV_ERR ) ;
  274. X    }
  275. X    
  276. X    return( addstring( env, var_string, p-var_string ) ) ;
  277. X}
  278. X
  279. X
  280. Xint env_remvar( env, var )
  281. X    env_h env ;
  282. X    char *var ;
  283. X{
  284. X    char **pp = lookup( env, var, strlen( var ) ) ;
  285. X
  286. X    if ( pp == NULL )
  287. X    {
  288. X        env_errno = ENV_EBADVAR ;
  289. X        return( ENV_ERR ) ;
  290. X    }
  291. X    
  292. X    free( *pp ) ;
  293. X    *pp = env->vars[ --env->n_vars ] ;
  294. X    return( ENV_OK ) ;
  295. X}
  296. X
  297. X
  298. X#ifdef notdef
  299. XPRIVATE int comparator( p1, p2 )
  300. X    char **p1, **p2 ;
  301. X{
  302. X    return( strcmp( *p1, *p2 ) ) ;
  303. X}
  304. X
  305. X
  306. Xvoid env_sort( env )
  307. X    env_h env ;
  308. X{
  309. X    qsort( (char *)env->vars, env->n_vars, sizeof( char * ), comparator ) ;
  310. X}
  311. X#endif
  312. END_OF_FILE
  313. if test 4772 -ne `wc -c <'libs/src/misc/env.c'`; then
  314.     echo shar: \"'libs/src/misc/env.c'\" unpacked with wrong size!
  315. fi
  316. # end of 'libs/src/misc/env.c'
  317. fi
  318. if test -f 'libs/src/sio/README' -a "${1}" != "-c" ; then 
  319.   echo shar: Will not clobber existing file \"'libs/src/sio/README'\"
  320. else
  321. echo shar: Extracting \"'libs/src/sio/README'\" \(4739 characters\)
  322. sed "s/^X//" >'libs/src/sio/README' <<'END_OF_FILE'
  323. X======================================================================
  324. XNOTE: I use vi with a tabstop value of 3. Using the same tabstop
  325. X        value will make the text/code look properly indented.
  326. X======================================================================
  327. X
  328. X
  329. X1. What is SIO ?
  330. X
  331. XSIO is a library that provides _stream_ I/O which is what most Unix
  332. Xprograms do. As such it is a competitor to stdio.
  333. X
  334. X
  335. X2. Why would you care to use it ?
  336. X
  337. Xa. SIO is a little faster than stdio
  338. Xb. SIO provides an easier-to-use interface (IMHO)
  339. Xc. SIO is capable of using memory mapping for reading files if the operating
  340. X    system supports it.
  341. Xd. If you have a program that uses read(2)/write(2) it is trivial
  342. X   to convert it to use SIO (just replace read with Sread and 
  343. X   write with Swrite)
  344. Xe. You get source
  345. X
  346. X
  347. X
  348. X3. Setting up the Stream I/O (SIO) library
  349. X
  350. XThere are 3 steps to the process:
  351. X    1) modifying the SIO configuration file (but you can skip this
  352. X        step if you are using one of the operating systems listed below).
  353. X    2) testing SIO
  354. X    3) installing the library and manpages
  355. X
  356. X
  357. X3.1. How to compile the Stream I/O (SIO) library
  358. X
  359. XAll the system-dependent stuff of SIO is placed in the sioconf.h file.
  360. XIf your system is not listed below, you will need to read that file
  361. Xto see what flags you need to set to properly compile SIO.
  362. X
  363. XFor the following systems, here is what you need to do:
  364. X
  365. X    SunOS 4.x:
  366. X        make "DEFS=-DHAS_MMAP -DHAS_ONEXIT -DHAS_MEMOPS -DHAS_ISATTY"
  367. X
  368. X    SunOS 5.x (aka Solaris 2.y):
  369. X        make "DEFS=-DHAS_MMAP -DHAS_ATEXIT -DHAS_MEMOPS -DHAS_ISATTY"
  370. X    (I don't have access to a system running Solaris 2.y so I have not
  371. X    tested this)
  372. X
  373. X    Ultrix 4.x:
  374. X        make "DEFS=-DHAS_MEMOPS -DHAS_ATEXIT -DHAS_ISATTY"
  375. X
  376. XIf your system is one of the above, then you can skip to the next subsection.
  377. XHowever, I should mention that the library compiles by default with
  378. Xdebugging enabled (i.e. uses the -g flag of cc). You can override this
  379. Xby appending to the invocation of 'make' the argument "DEBUG=-O"
  380. X
  381. XIf your system is not among the above, then you will need to modify the
  382. Xsioconf.h file. You do this by uncommenting the inclusion of
  383. Xcustomconf.h. Then, you can override all constants/macros defined in
  384. Xsioconf.h by defining them first in customconf.h.  Please read
  385. Xsioconf.h for more information on what constants/macros can be
  386. Xdefined.
  387. X
  388. XThe Makefile has a header that explains what the Makefile can do.
  389. XThe only flag that you may want to define is -DDEBUG which enables 
  390. Xassertions in the SIO code (if an assertion fails, the program is 
  391. Xterminated with an error message that lists the SIO file and line 
  392. Xnumber where the error occured).
  393. X
  394. X
  395. X3.2. Testing SIO
  396. X
  397. XAfter you have successfully compiled SIO, you can use the programs in
  398. Xthe "suite" directory to test the SIO functions.  Testing should be
  399. Xdone before installing the library.
  400. XThe script testlib does everything; just type:
  401. X
  402. X    testlib all
  403. X
  404. XThe script sprint_test (invoked by testlib) tests Sprint by using a variety 
  405. Xof formats and comparing its output with that of an ANSI-compatible printf.
  406. XAt least on Ultrix 4.1 and 4.2 this test fails because printf is not 
  407. XANSI-compatible.
  408. XIn such a case, you can test the rest of the SIO functions by typing:
  409. X
  410. X    testlib all Sprint
  411. X
  412. X(anything after the 'all' argument is interpreted as a function that
  413. Xshould not be tested).
  414. X
  415. XThe README file in the "suite" directory describes how to do a
  416. Xfew more tests that cannot be done automatically.
  417. X
  418. X
  419. X3.3. Installing the library and manpages
  420. X
  421. XThe 'make' command will create libsio.a in the current directory.
  422. XThe Makefile includes an "install" target. Doing a 'make install' will 
  423. Xcause the following:
  424. X
  425. Xa) libsio.a will be installed in LIBDIR
  426. Xb) the necessary SIO header files will be installed in INCLUDEDIR
  427. Xc) the SIO man pages will be installed in MANDIR
  428. X
  429. XLIBDIR, INCLUDEDIR, and MANDIR are Makefile variables that you can edit in
  430. Xthe Makefile or override when you invoke 'make'.
  431. XHere is a sample command to install SIO:
  432. X
  433. X    make install LIBDIR=/usr/local/lib INCLUDEDIR=/usr/local/include MANDIR=/usr/local/man/man3
  434. X
  435. X
  436. X4. Epilogue
  437. X
  438. XFeel free to modify SIO to suit your needs. Please let me know of
  439. Xany bugs you find.
  440. X
  441. XIf you want to distribute your modifications, please read the COPYRIGHT
  442. Xfile.  It basically says that you are free to redistribute as long as
  443. Xyou retain the original copyright notice and you make sure that your
  444. Xmodifications are identifiable. In order to achieve this I have
  445. Xreserved the first 3 components of the version number (for example,
  446. X1.4.2) and you can identify your mods by appending another component to
  447. Xthat version number (for example, 1.4.2.A2). Also, if you distribute a
  448. Xmodified version of the library, you take full responsibility for any
  449. Xbugs in the code (not just your code; the whole thing).
  450. X
  451. END_OF_FILE
  452. if test 4739 -ne `wc -c <'libs/src/sio/README'`; then
  453.     echo shar: \"'libs/src/sio/README'\" unpacked with wrong size!
  454. fi
  455. # end of 'libs/src/sio/README'
  456. fi
  457. if test -f 'xinetd/log.c' -a "${1}" != "-c" ; then 
  458.   echo shar: Will not clobber existing file \"'xinetd/log.c'\"
  459. else
  460. echo shar: Extracting \"'xinetd/log.c'\" \(4978 characters\)
  461. sed "s/^X//" >'xinetd/log.c' <<'END_OF_FILE'
  462. X/*
  463. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  464. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  465. X * and conditions for redistribution.
  466. X */
  467. X
  468. Xstatic char RCSid[] = "$Id: log.c,v 6.10 1993/06/15 23:25:57 panos Exp $" ;
  469. X
  470. X#include <sys/types.h>
  471. X#include <sys/socket.h>
  472. X#include <sys/wait.h>
  473. X#include <syslog.h>
  474. X#include <time.h>
  475. X
  476. X#include "sio.h"
  477. X#include "str.h"
  478. X
  479. X#include "connection.h"
  480. X#include "defs.h"
  481. X#include "access.h"
  482. X#include "sconst.h"
  483. X#include "service.h"
  484. X#include "server.h"
  485. X
  486. X
  487. Xvoid msg() ;
  488. X
  489. X#define LOGBUF_SIZE                        1024
  490. X
  491. X
  492. Xtime_t time() ;
  493. X
  494. X
  495. XPRIVATE int log_common() ;
  496. X
  497. X/*
  498. X * This function writes log records of the form:
  499. X *
  500. X *        START: service [pid] [from_address]
  501. X */
  502. Xvoid svc_log_success( sp, cp, pid )
  503. X    register struct service    *sp ;
  504. X    connection_s                *cp ;
  505. X    pid_t                            pid ;
  506. X{
  507. X    char                                        buf[ LOGBUF_SIZE ] ;
  508. X    int                                        bufsize ;
  509. X    register struct service_config    *scp = SVC_CONF( sp ) ;
  510. X    register int                            len ;
  511. X    register int                            cc ;
  512. X
  513. X    if ( ! SVC_LOGS_ON_SUCCESS( sp ) )
  514. X        return ;
  515. X    
  516. X    bufsize = sizeof( buf ) ;
  517. X    len = 0 ;
  518. X    
  519. X    cc = strx_nprint( buf, bufsize, "%s: %s", START_ENTRY, SC_ID( scp ) ) ;
  520. X    len += cc ;
  521. X    bufsize -= cc ;
  522. X
  523. X    if ( SC_LOGS_PID( scp ) )
  524. X    {
  525. X        cc = strx_nprint( &buf[ len ], bufsize, " pid=%d", pid ) ;
  526. X        len += cc ;
  527. X        bufsize -= cc ;
  528. X    }
  529. X
  530. X    cc = log_common( &SC_LOG_ON_FAILURE( scp ), &buf[len], bufsize, cp ) ;
  531. X    len += cc ;
  532. X    bufsize -= cc ;
  533. X
  534. X    xlog_write( sp->svc_log, buf, len, XLOG_NOFLAGS ) ;
  535. X}
  536. X
  537. X
  538. X/*
  539. X * This function writes log records of the form:
  540. X *
  541. X *        FAIL: service failure-type [from_address]
  542. X *
  543. X */
  544. Xvoid svc_log_failure( sp, cp, access_failure )
  545. X    register struct service    *sp ;
  546. X    connection_s                *cp ;
  547. X    access_e                        access_failure ;
  548. X{
  549. X    char                                        buf[ LOGBUF_SIZE ] ;
  550. X    int                                        bufsize ;
  551. X    register struct service_config    *scp = SVC_CONF( sp ) ;
  552. X    register int                            len = 0 ;
  553. X    register int                            cc ;
  554. X    
  555. X    if ( ! SVC_LOGS_ON_FAILURE( sp ) )
  556. X        return ;
  557. X    
  558. X    bufsize = sizeof( buf ) ;
  559. X    cc = strx_nprint( buf, bufsize, "%s: %s", FAIL_ENTRY, SC_ID( scp ) ) ;
  560. X    len += cc ;
  561. X    bufsize -= cc ;
  562. X
  563. X    cc = strx_nprint( &buf[ len ], bufsize,
  564. X                                " %s", access_explain( access_failure ) ) ;
  565. X    len += cc ;
  566. X    bufsize -= cc ;
  567. X
  568. X    cc = log_common( &SC_LOG_ON_FAILURE( scp ), &buf[ len ], bufsize, cp ) ;
  569. X    len += cc ;
  570. X    bufsize -= cc ;
  571. X
  572. X    xlog_write( sp->svc_log, buf, len, XLOG_NOFLAGS ) ;
  573. X}
  574. X
  575. X
  576. X
  577. XPRIVATE int log_common( logmask, buf, bufsize, cp )
  578. X    mask_t            *logmask ;
  579. X    char                *buf ;
  580. X    int                bufsize ;
  581. X    connection_s    *cp ;
  582. X{
  583. X    register int len = 0 ;
  584. X    int cc ;
  585. X
  586. X   if ( M_IS_SET( *logmask, LO_HOST ) )
  587. X   {
  588. X      cc = strx_nprint( &buf[ len ], bufsize, " from=%s", conn_addrstr( cp ) ) ;
  589. X      len += cc ;
  590. X        bufsize -= cc ;
  591. X   }
  592. X    return( len ) ;
  593. X}
  594. X
  595. X
  596. X
  597. Xvoid svc_log_exit( sp, serp )
  598. X    register struct service    *sp ;
  599. X    struct server                *serp ;
  600. X{
  601. X    char                                        buf[ LOGBUF_SIZE ] ;
  602. X    int                                        bufsize ;
  603. X    register int                            cc ;
  604. X    register int                            len ;
  605. X    int                                        exit_status = SERVER_EXITSTATUS( serp ) ;
  606. X    register struct service_config    *scp = SVC_CONF( sp ) ;
  607. X    char                                        *func = "log_exit" ;
  608. X
  609. X    if ( ! SVC_LOGS_ON_EXIT( sp ) )
  610. X        return ;
  611. X
  612. X    bufsize = sizeof( buf ) ;
  613. X    len = 0 ;
  614. X
  615. X    cc = strx_nprint( buf, bufsize, "%s: %s", EXIT_ENTRY, SC_ID( scp ) ) ;
  616. X    bufsize -= cc ;
  617. X    len += cc ;
  618. X
  619. X    /*
  620. X     * If the EXIT flag was used, log the exit status or the signal that
  621. X     * killed the process. We assume that these are the only reasons
  622. X     * for process termination.
  623. X     */
  624. X    if ( SC_LOGS_EXITS( scp ) )
  625. X    {
  626. X        int num ;
  627. X        char *s ;
  628. X
  629. X        if ( PROC_EXITED( exit_status ) )
  630. X        {
  631. X            s = "status" ;
  632. X            num = PROC_EXITSTATUS( exit_status ) ;
  633. X        }
  634. X        else if ( PROC_SIGNALED( exit_status ) )
  635. X        {
  636. X            s = "signal" ;
  637. X            num = PROC_TERMSIG( exit_status ) ;
  638. X        }
  639. X        else
  640. X        {
  641. X            msg( LOG_ERR, func, "Bad exit status" ) ;
  642. X            s = NULL ;
  643. X        }
  644. X
  645. X        if ( s )
  646. X        {
  647. X            cc = strx_nprint( &buf[ len ], bufsize, " %s=%d", s, num ) ;
  648. X            len += cc ;
  649. X            bufsize -= cc ;
  650. X        }
  651. X    }
  652. X
  653. X    if ( SC_LOGS_PID( scp ) )
  654. X    {
  655. X        cc = strx_nprint( &buf[ len ], bufsize, " pid=%d", SERVER_PID( serp ) ) ;
  656. X        len += cc ;
  657. X        bufsize -= cc ;
  658. X    }
  659. X
  660. X    if ( SC_LOGS_DURATION( scp ) )
  661. X    {
  662. X        time_t current_time ;
  663. X
  664. X        (void) time( ¤t_time ) ;
  665. X        cc = strx_nprint( &buf[ len ], bufsize, " duration=%d(sec)", 
  666. X                                    current_time - SERVER_STARTTIME( serp ) ) ;
  667. X        len += cc ;
  668. X        bufsize -= cc ;
  669. X    }
  670. X    xlog_write( sp->svc_log, buf, len, XLOG_NOFLAGS ) ;
  671. X}
  672. X
  673. X
  674. X
  675. X/*
  676. X * Used by other parts of xinetd that want to log something without
  677. X * going through the proper channels (i.e. log_{success,failure} and log_exit)
  678. X */
  679. X/* VARARGS3 */
  680. Xvoid svc_logprint( sp, line_id, fmt, va_alist )
  681. X    register struct service    *sp ;
  682. X    char                            *line_id ;
  683. X    char                            *fmt ;
  684. X    va_dcl
  685. X{
  686. X    char        buf[ LOGBUF_SIZE ] ;
  687. X    int        bufsize = sizeof( buf ) ;
  688. X    int        len ;
  689. X    int        cc ;
  690. X    va_list    ap ;
  691. X
  692. X    if ( ! SVC_IS_LOGGING( sp ) )
  693. X        return ;
  694. X
  695. X    len = strx_nprint( buf, bufsize, "%s: %s ", line_id, SVC_ID( sp ) ) ;
  696. X    va_start( ap ) ;
  697. X    cc = strx_nprintv( &buf[ len ], bufsize, fmt, ap ) ;
  698. X    va_end( ap ) ;
  699. X    xlog_write( sp->svc_log, buf, len+cc, XLOG_NO_SIZECHECK ) ;
  700. X}
  701. X
  702. END_OF_FILE
  703. if test 4978 -ne `wc -c <'xinetd/log.c'`; then
  704.     echo shar: \"'xinetd/log.c'\" unpacked with wrong size!
  705. fi
  706. # end of 'xinetd/log.c'
  707. fi
  708. if test -f 'xinetd/main.c' -a "${1}" != "-c" ; then 
  709.   echo shar: Will not clobber existing file \"'xinetd/main.c'\"
  710. else
  711. echo shar: Extracting \"'xinetd/main.c'\" \(4832 characters\)
  712. sed "s/^X//" >'xinetd/main.c' <<'END_OF_FILE'
  713. X/*
  714. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  715. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  716. X * and conditions for redistribution.
  717. X */
  718. X
  719. Xstatic char RCSid[] = "$Id: main.c,v 6.4 1993/06/06 00:10:02 panos Exp $" ;
  720. Xchar program_version[] = VERSION ;
  721. X
  722. X#include <sys/types.h>
  723. X#include <sys/stat.h>
  724. X#include <sys/time.h>
  725. X#include <errno.h>
  726. X#include <syslog.h>
  727. X
  728. X#include "sio.h"
  729. X
  730. X#include "options.h"
  731. X
  732. X#include "service.h"
  733. X#include "state.h"
  734. X
  735. X
  736. X/*
  737. X * The following are the only global variables of this program
  738. X */
  739. Xstruct program_state ps ;
  740. Xstruct debug debug ;
  741. X
  742. Xextern int errno ;
  743. X
  744. Xvoid exit() ;
  745. Xvoid msg() ;
  746. X
  747. X/*
  748. X * This is where the story starts...
  749. X */
  750. Xint main( argc, argv )
  751. X    int argc ;
  752. X    char *argv[] ;
  753. X{
  754. X    char                *func = "main" ;
  755. X    PRIVATE void    main_loop() ;
  756. X    void                init_services() ;
  757. X    void                init_daemon() ;
  758. X    void                enable_periodic_check() ;
  759. X
  760. X    init_daemon( argc, argv ) ;
  761. X    init_services() ;
  762. X
  763. X    msg( LOG_NOTICE, func, "Started working: %d available service%s",
  764. X        ps.rws.available_services,
  765. X            ( ps.rws.available_services > 1 ) ? "s" : "" ) ;
  766. X
  767. X    if ( cc_option )
  768. X#ifndef NO_TIMERS
  769. X        enable_periodic_check( cc_option_arg ) ;
  770. X#else
  771. X        msg( LOG_WARNING, func, "-cc option not supported" ) ;
  772. X#endif
  773. X    
  774. X    /*
  775. X     * The reason for doing the setjmp here instead of in main_loop is
  776. X     * that setjmp is not guaranteed to restore register values which
  777. X     * can cause a problem for register variables
  778. X     */
  779. X    if ( setjmp( ps.rws.env ) == 0 )
  780. X        ps.rws.env_is_valid = TRUE ;
  781. X
  782. X    main_loop() ;
  783. X
  784. X    /* NOTREACHED */
  785. X}
  786. X
  787. X
  788. X/*
  789. X * What main_loop does:
  790. X *
  791. X *        check if any flags are set
  792. X *        select on all active services
  793. X *        for each socket where a request is pending
  794. X *            try to start a server
  795. X */
  796. XPRIVATE void main_loop()
  797. X{
  798. X    char                *func = "main_loop" ;
  799. X    PRIVATE void    find_bad_fd() ;
  800. X    void                check_flags() ;
  801. X    void                signal_wait() ;
  802. X
  803. X    for ( ;; )
  804. X    {
  805. X        fd_set read_mask ;
  806. X        register int n_active ;
  807. X        register unsigned u ;
  808. X
  809. X        check_flags() ;
  810. X
  811. X        if ( debug.on )
  812. X            msg( LOG_DEBUG, func,
  813. X                    "active_services = %d", ps.rws.active_services ) ;
  814. X
  815. X        if ( ps.rws.active_services == 0 )
  816. X        {
  817. X            signal_wait() ;
  818. X            continue ;
  819. X        }
  820. X
  821. X        read_mask = ps.rws.socket_mask ;
  822. X        n_active = select( ps.rws.mask_max+1, &read_mask,
  823. X                                FD_SET_NULL, FD_SET_NULL, TIMEVAL_NULL ) ;
  824. X        if ( n_active == -1 )
  825. X        {
  826. X            if ( errno == EINTR )
  827. X                continue ;
  828. X            else if ( errno == EBADF )
  829. X                find_bad_fd() ;
  830. X            else
  831. X                msg( LOG_NOTICE, func, "select error: %m" ) ;
  832. X            continue ;
  833. X        }
  834. X        else if ( n_active == 0 )
  835. X            continue ;
  836. X
  837. X        if ( debug.on )
  838. X            msg( LOG_DEBUG, func, "select returned %d", n_active ) ;
  839. X
  840. X        for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ )
  841. X        {
  842. X            register struct service *sp ;
  843. X
  844. X            sp = SP( pset_pointer( SERVICES( ps ), u ) ) ;
  845. X
  846. X            if ( ! SVC_IS_ACTIVE( sp ) )
  847. X                continue ;
  848. X
  849. X            if ( FD_ISSET( SVC_FD( sp ), &read_mask ) )
  850. X            {
  851. X                svc_request( sp ) ;
  852. X                if ( --n_active == 0 )
  853. X                    break ;
  854. X            }
  855. X        }
  856. X        if ( n_active > 0 )
  857. X            msg( LOG_ERR, func, "%d descriptors still set", n_active ) ;
  858. X    }
  859. X}
  860. X
  861. X
  862. X
  863. X/*
  864. X * This function identifies if any of the fd's in the socket mask
  865. X * is bad. We use it in case select(2) returns EBADF
  866. X * When we identify such a bad fd, we remove it from the mask
  867. X * and deactivate the service.
  868. X */
  869. XPRIVATE void find_bad_fd()
  870. X{
  871. X    register int fd ;
  872. X    struct stat st ;
  873. X    unsigned bad_fd_count = 0 ;
  874. X    char *func = "find_bad_fd" ;
  875. X
  876. X    for ( fd = 0 ; fd < ps.ros.max_descriptors ; fd++ )
  877. X        if ( FD_ISSET( fd, &ps.rws.socket_mask ) && fstat( fd, &st ) == -1 )
  878. X        {
  879. X            int found = FALSE ;
  880. X            register unsigned u ;
  881. X
  882. X            for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ )
  883. X            {
  884. X                register struct service *sp ;
  885. X
  886. X                sp = SP( pset_pointer( SERVICES( ps ), u ) ) ;
  887. X
  888. X                if ( ! SVC_IS_AVAILABLE( sp ) )
  889. X                    continue ;
  890. X
  891. X                if ( SVC_FD( sp ) == fd )
  892. X                {
  893. X                    msg( LOG_ERR, func,
  894. X                        "file descriptor of service %s has been closed",
  895. X                                        SVC_ID( sp ) ) ;
  896. X                    svc_deactivate( sp ) ;
  897. X                    found = TRUE ;
  898. X                    break ;
  899. X                }
  900. X            }
  901. X            if ( ! found )
  902. X            {
  903. X                FD_CLR( fd, &ps.rws.socket_mask ) ;
  904. X                msg( LOG_ERR, func,
  905. X                    "No active service for file descriptor %d\n", fd ) ;
  906. X                bad_fd_count++ ;
  907. X            }
  908. X        }
  909. X    if ( bad_fd_count == 0 )
  910. X        msg( LOG_NOTICE, func,
  911. X            "select reported EBADF but no bad file descriptors were found" ) ;
  912. X}
  913. X
  914. X
  915. X/*
  916. X * Deactivates all active processes.
  917. X * The real reason for doing this instead of just exiting is
  918. X * to deregister the RPC services
  919. X */
  920. Xvoid quit_program()
  921. X{
  922. X    register unsigned u ;
  923. X    char *func = "quit_program" ;
  924. X
  925. X    for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ )
  926. X        svc_deactivate( SP( pset_pointer( SERVICES( ps ), u ) ) ) ;
  927. X    msg( LOG_WARNING, func, "Exiting..." ) ;
  928. X    exit( 0 ) ;
  929. X}
  930. X
  931. X
  932. Xvoid terminate_program()
  933. X{
  934. X    register unsigned u ;
  935. X    void terminate_servers() ;
  936. X
  937. X    for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ )
  938. X        terminate_servers( SP( pset_pointer( SERVICES( ps ), u ) ) ) ;
  939. X    quit_program() ;
  940. X}
  941. X
  942. END_OF_FILE
  943. if test 4832 -ne `wc -c <'xinetd/main.c'`; then
  944.     echo shar: \"'xinetd/main.c'\" unpacked with wrong size!
  945. fi
  946. # end of 'xinetd/main.c'
  947. fi
  948. if test -f 'xinetd/sample.conf' -a "${1}" != "-c" ; then 
  949.   echo shar: Will not clobber existing file \"'xinetd/sample.conf'\"
  950. else
  951. echo shar: Extracting \"'xinetd/sample.conf'\" \(4809 characters\)
  952. sed "s/^X//" >'xinetd/sample.conf' <<'END_OF_FILE'
  953. X#
  954. X# Sample configuration file for xinetd
  955. X#
  956. X
  957. Xdefaults
  958. X{
  959. X    instances         = 25
  960. X    log_type         = FILE /var/log/servicelog
  961. X    log_on_success    = HOST PID
  962. X    log_on_failure = HOST RECORD
  963. X    only_from         = 128.138.193.0 128.138.204.0 128.138.209.0 128.138.243.0
  964. X    only_from         = localhost
  965. X    disabled         = tftp
  966. X}
  967. X
  968. X
  969. X#
  970. X# Group 1: BSD services
  971. X#
  972. X# Shell, login, exec, comsat, talk, ntalk 
  973. X#
  974. X
  975. Xservice login
  976. X{
  977. X    flags                = REUSE
  978. X    socket_type        = stream
  979. X    protocol            = tcp
  980. X    wait                = no
  981. X    user                = root
  982. X    server            = /usr/etc/in.rlogind
  983. X    log_type         = SYSLOG local4 info
  984. X}
  985. X
  986. X
  987. Xservice shell
  988. X{
  989. X    socket_type        = stream
  990. X    wait                = no
  991. X    user                = root
  992. X    instances        = UNLIMITED
  993. X    flags                = IDONLY
  994. X    log_on_success += USERID
  995. X    server            = /usr/etc/in.rshd
  996. X}
  997. X
  998. X
  999. Xservice exec
  1000. X{
  1001. X    socket_type        = stream
  1002. X    wait                = no
  1003. X    user                = root
  1004. X    server            = /usr/etc/in.rexecd
  1005. X}
  1006. X
  1007. Xservice comsat
  1008. X{
  1009. X    socket_type        = dgram
  1010. X    wait                = yes
  1011. X    user                = nobody
  1012. X    group                = tty
  1013. X    server            = /usr/etc/in.comsat
  1014. X}
  1015. X
  1016. Xservice talk
  1017. X{
  1018. X    socket_type        = dgram
  1019. X    wait                = yes
  1020. X    user                = root
  1021. X    server            = /usr/etc/in.talkd
  1022. X}
  1023. X
  1024. Xservice ntalk
  1025. X{
  1026. X    socket_type        = dgram
  1027. X    wait                = yes
  1028. X    user                = root
  1029. X    server            = /usr/etc/in.ntalkd
  1030. X}
  1031. X
  1032. X#
  1033. X# Group 2: standard Internet services
  1034. X#
  1035. X# Telnet, ftp 
  1036. X#
  1037. Xservice telnet
  1038. X{
  1039. X    flags                = REUSE
  1040. X    socket_type        = stream    
  1041. X    wait                = no
  1042. X    user                = root
  1043. X    server            = /usr/etc/in.telnetd
  1044. X    log_on_failure += USERID
  1045. X}
  1046. X
  1047. Xservice ftp
  1048. X{
  1049. X    socket_type        = stream
  1050. X    wait                = no
  1051. X    user                = root
  1052. X    server            = /usr/etc/in.ftpd
  1053. X    server_args        = -l
  1054. X    instances        = 4
  1055. X    log_on_success    += DURATION USERID
  1056. X    log_on_failure += USERID
  1057. X    access_times    = 2:00-8:59 12:00-23:59
  1058. X    nice                = 10
  1059. X}
  1060. X
  1061. X#
  1062. X# Group 3: other services
  1063. X#
  1064. X
  1065. X#
  1066. X# Tnamed serves the obsolete IEN-116 name server protocol.
  1067. X#
  1068. Xservice name
  1069. X{
  1070. X    socket_type        = dgram
  1071. X    wait                = yes
  1072. X    user                = root
  1073. X    server            = /usr/etc/in.tnamed
  1074. X}
  1075. X
  1076. X#service uucp
  1077. X#{
  1078. X#    socket_type        = stream
  1079. X#    wait                = no
  1080. X#    user                = root
  1081. X#    server            = /usr/etc/in.uucpd
  1082. X#}
  1083. X
  1084. Xservice tftp
  1085. X{
  1086. X    socket_type        = dgram
  1087. X    wait                = yes
  1088. X    user                = root
  1089. X    server            = /usr/etc/in.tftpd
  1090. X    server_args        = -s /tftpboot
  1091. X}
  1092. X
  1093. X
  1094. X#
  1095. X# Group 4: information services
  1096. X#
  1097. Xservice finger
  1098. X{
  1099. X    socket_type        = stream
  1100. X    wait                = no
  1101. X    user                = nobody
  1102. X    server            = /usr/etc/in.fingerd
  1103. X}
  1104. X
  1105. Xservice systat
  1106. X{
  1107. X    socket_type        = stream
  1108. X    wait                = no
  1109. X    user                = nobody
  1110. X    server            = /usr/bin/ps
  1111. X    server_args        = -auwwx
  1112. X    only_from        = 128.138.209.0
  1113. X    log_on_success    = HOST
  1114. X}
  1115. X
  1116. Xservice netstat
  1117. X{
  1118. X    socket_type        = stream
  1119. X    wait                = no
  1120. X    user                = nobody
  1121. X    server            = /usr/ucb/netstat
  1122. X    server_args        = -f inet
  1123. X    only_from        = 128.138.209.0
  1124. X    log_on_success    = HOST
  1125. X}
  1126. X
  1127. X
  1128. X#
  1129. X# Group 5: internal services
  1130. X#
  1131. X# echo, time, daytime, chargen, servers, services
  1132. X#
  1133. Xservice echo
  1134. X{
  1135. X    type                = INTERNAL
  1136. X    id                    = echo-stream
  1137. X    socket_type        = stream
  1138. X    protocol            = tcp
  1139. X    user                = root
  1140. X    wait                = no
  1141. X}
  1142. X
  1143. Xservice echo
  1144. X{
  1145. X    type                = INTERNAL
  1146. X    id                    = echo-dgram
  1147. X    socket_type        = dgram
  1148. X    protocol            = udp
  1149. X    user                = root
  1150. X    wait                = yes
  1151. X}
  1152. X
  1153. Xservice chargen
  1154. X{
  1155. X    type                = INTERNAL
  1156. X    id                    = chargen-stream
  1157. X    socket_type        = stream
  1158. X    protocol            = tcp
  1159. X    user                = root
  1160. X    wait                = no
  1161. X}
  1162. X
  1163. Xservice chargen
  1164. X{
  1165. X    type                = INTERNAL
  1166. X    id                    = chargen-dgram
  1167. X    socket_type        = dgram
  1168. X    protocol            = udp
  1169. X    user                = root
  1170. X    wait                = yes
  1171. X}
  1172. X
  1173. Xservice daytime
  1174. X{
  1175. X    type                = INTERNAL
  1176. X    id                    = daytime-stream
  1177. X    socket_type        = stream
  1178. X    protocol            = tcp
  1179. X    user                = root
  1180. X    wait                = no
  1181. X}
  1182. X
  1183. Xservice daytime
  1184. X{
  1185. X    type                = INTERNAL
  1186. X    id                    = daytime-dgram
  1187. X    socket_type        = dgram
  1188. X    protocol            = udp
  1189. X    user                = root
  1190. X    wait                = yes
  1191. X}
  1192. X
  1193. Xservice time
  1194. X{
  1195. X    type                = INTERNAL
  1196. X    id                    = time-stream
  1197. X    socket_type        = stream
  1198. X    protocol            = tcp
  1199. X    user                = root
  1200. X    wait                = no
  1201. X}
  1202. X
  1203. X
  1204. Xservice time
  1205. X{
  1206. X    type                = INTERNAL
  1207. X    id                    = time-dgram
  1208. X    socket_type        = dgram
  1209. X    protocol            = udp
  1210. X    user                = root
  1211. X    wait                = yes
  1212. X}
  1213. X
  1214. X
  1215. Xservice servers
  1216. X{
  1217. X    type                = INTERNAL UNLISTED
  1218. X    port                = 9099
  1219. X    protocol            = tcp
  1220. X    socket_type        = stream
  1221. X    wait                = no
  1222. X    instances        = 2
  1223. X}
  1224. X
  1225. X
  1226. Xservice services
  1227. X{
  1228. X    type                = INTERNAL UNLISTED
  1229. X    port                = 9098
  1230. X    protocol            = tcp
  1231. X    socket_type        = stream
  1232. X    wait                = no
  1233. X    instances        = 2
  1234. X}
  1235. X
  1236. X
  1237. X#
  1238. X# Group 6: RPC services
  1239. X#
  1240. Xservice rstatd
  1241. X{
  1242. X    type                = RPC
  1243. X    flags                = INTERCEPT
  1244. X    rpc_version        = 2-4
  1245. X    socket_type        = dgram
  1246. X    protocol            = udp
  1247. X    server            = /usr/etc/rpc.rstatd
  1248. X    wait                = yes
  1249. X    user                = root
  1250. X}
  1251. X
  1252. Xservice rquotad
  1253. X{
  1254. X    type                = RPC
  1255. X    rpc_version        = 1
  1256. X    socket_type        = dgram
  1257. X    protocol            = udp
  1258. X    wait                = yes
  1259. X    user                = root
  1260. X    server            = /usr/etc/rpc.rstatd
  1261. X}
  1262. X
  1263. Xservice rusersd
  1264. X{
  1265. X    type                = RPC
  1266. X    rpc_version        = 1-2
  1267. X    socket_type        = dgram
  1268. X    protocol            = udp
  1269. X    wait                = yes
  1270. X    user                = root
  1271. X    server            = /usr/etc/rpc.rusersd
  1272. X}
  1273. X
  1274. Xservice sprayd
  1275. X{
  1276. X    type                = RPC
  1277. X    rpc_version        = 1
  1278. X    socket_type        = dgram
  1279. X    protocol            = udp
  1280. X    wait                = yes
  1281. X    user                = root
  1282. X    server            = /usr/etc/rpc.sprayd
  1283. X}
  1284. X
  1285. Xservice walld
  1286. X{
  1287. X    type                = RPC
  1288. X    rpc_version        = 1
  1289. X    socket_type        = dgram
  1290. X    protocol            = udp
  1291. X    wait                = yes
  1292. X    user                = nobody
  1293. X    group                = tty
  1294. X    server            = /usr/etc/rpc.rwalld
  1295. X}
  1296. X
  1297. END_OF_FILE
  1298. if test 4809 -ne `wc -c <'xinetd/sample.conf'`; then
  1299.     echo shar: \"'xinetd/sample.conf'\" unpacked with wrong size!
  1300. fi
  1301. # end of 'xinetd/sample.conf'
  1302. fi
  1303. echo shar: End of archive 11 \(of 31\).
  1304. cp /dev/null ark11isdone
  1305. MISSING=""
  1306. 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
  1307.     if test ! -f ark${I}isdone ; then
  1308.     MISSING="${MISSING} ${I}"
  1309.     fi
  1310. done
  1311. if test "${MISSING}" = "" ; then
  1312.     echo You have unpacked all 31 archives.
  1313.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1314. else
  1315.     echo You still need to unpack the following archives:
  1316.     echo "        " ${MISSING}
  1317. fi
  1318. ##  End of shell archive.
  1319. exit 0
  1320.