From comp.sources.unix Mon Jun 28 17:43:55 1993
Path: news.cso.uiuc.edu!ux1.cso.uiuc.edu!sdd.hp.com!decwrl!decwrl!vixie!vixie!not-for-mail
From: panos@cs.colorado.edu (Panos Tsirigotis)
Newsgroups: comp.sources.unix
Subject: v26i244: xinetd-2.1.1 - inetd replacement with access control and logging, Part00/31
Date: 27 Jun 1993 12:55:29 -0700
Organization: Vixie Enterprises
Lines: 539
Sender: vixie@vix.com
Approved: vixie@gw.home.vix.com
Message-ID: <20ktvh$21g@gw.home.vix.com>
NNTP-Posting-Host: gw.home.vix.com

Submitted-By: panos@cs.colorado.edu (Panos Tsirigotis)
Posting-Number: Volume 26, Issue 244
Archive-Name: xinetd-2.1.1/part00

[ This Q&A was provided by the author in his README file.  However, to me as
  the moderator of comp.sources.unix, the most important part of this package
  is its beautiful selection of general C Library functions.  Due to my bias
  (I prefer to see small applications with rich libraries), I have excerpted
  all of the SYNOPSIS sections of the library "man" pages included with this
  distribution.  They follow the author's Q&A, and due to their size I have
  taken the unusual step of putting this introductory information into a
  "Part 00" rather than prepending it to "Part 01".

  Even if you don't want the "xinetd" application (and I think you probably
  do, though you may not know it yet :-)), you should take a hard look at the
  included libraries.  I have been planning a "libcsu.a" project for a while,
  being a recurring publication of generalized C Library functions, and if I
  do one it will begin with the routines included in this package.

  --vix ]

Q. What is xinetd ?
A. xinetd is a replacement for inetd, the internet services daemon.

Q: I am not a system administrator; what do I care about an inetd replacement ?
A: xinetd is not just an inetd replacement. Anybody can use it to start servers
   that don't require privileged ports because xinetd does not require that the 
   services in its configuration file be listed in /etc/services.

Q. Is it compatible with inetd ?
A. No, its configuration file has a different format than inetd's one
   and it understands different signals. However the signal-to-action 
   assignment can be changed and a program has been included to convert 
   inetd.conf to xinetd.conf.

Q. Why should I use it ?
A. Because it is a lot better (IMHO) than inetd. Here are the reasons:

      1) It can do access control on all services based on:
            a. address of remote host
            b. time of access

      2) Access control works on all services, whether multi-threaded or
         single-threaded and for both the TCP and UDP protocols.
         All UDP packets can be checked as well as all TCP connections.

      3) It provides hard reconfiguration:
            a. kills servers for services that are no longer in the
               configuration file
            b. kills servers that no longer meet the access control criteria

      4) It can prevent denial-of-access attacks by
            a. placing limits on the number of servers for each service
               (avoids process table overflows)
            b. placing an upper bound on the number of processes it will fork
            c. placing limits on the size of log files it creates

      5) Extensive logging abilities:
            a. for every server started it can log:
                    i) the time when the server was started
                   ii) the remote host address
                  iii) who was the remote user (if the other end runs a
                       RFC-931/RFC-1413 server)
                   iv) how long the server was running
               (i, ii and iii can be logged for failed attempts too).
            b. for some services, if the access control fails, it can
               log information about the attempted access (for example,
               it can log the user name and command for the rsh service)

      6) No limit on number of server arguments

[ Here come the "SYNOPSIS" sections of all of the included library functions.
  --vix ]

SYNOPSIS
       #include "env.h"

       env_h env_create( env )
       env_h env ;

       void env_destroy( env )
       env_h env ;

       env_h env_make( env_strings )
       char **env_strings ;

       int env_addvar( env, from_env, var )
       env_h env ;
       env_h from_env ;
       char *var ;

       int env_addstr( env, str )
       env_h env ;
       char *str ;

       int env_remvar( env, var )
       env_h env ;
       char *var ;

       char **env_getvars( env )
       env_h env ;

SYNOPSIS
       #include "ftwx.h"

       int ftwx( path, func, depth, flags )
       char *path ;
       int (*func)() ;
       int depth ;
       int flags ;

SYNOPSIS
       #include "misc.h"

       char *make_string( count, ... )
       unsigned count ;

       char *make_pathname( count, ... )
       unsigned count ;

       char **argv_copy_and_clear( argv, start, count )
       char **argv ;
       int start, count ;

       char *dirname( path )
       char *path ;

       char *basename( path )
       char *path ;

SYNOPSIS
       #include "pq.h"

       pq_h pq_create( func, flags, errnop )
       int (*func)() ;
       int flags ;
       int *errnop ;

       void pq_destroy( pq )
       pq_h pq ;

       pq_obj pq_head( pq )
       pq_h pq ;

       pq_obj pq_extract_head( pq )
       pq_h pq ;

       int pq_insert( pq, object )
       pq_h pq ;
       pq_obj object ;

       int pq_delete( pq, object )
       pq_h pq ;
       pq_obj object ;

SYNOPSIS
       #include "pset.h"

       pset_h pset_create( alloc_start, alloc_step )
       unsigned alloc_start, alloc_step ;

       void pset_destroy( pset )
       pset_h pset ;

       ANY_TYPE *pset_add( pset, ptr )
       pset_h pset ;
       ANY_TYPE *ptr ;

       void *pset_insert( pset, ptr )
       pset_h pset ;
       void *ptr ;

       void pset_remove( pset, ptr )
       pset_h pset ;
       ANY_TYPE *ptr ;

       void pset_delete( pset, ptr )
       pset_h pset ;
       void *ptr ;

       void pset_remove_index( pset, index )
       pset_h pset ;
       unsigned index ;

       void pset_clear( pset )
       pset_h pset ;

       unsigned pset_count( pset )
       pset_h pset ;

       void *pset_pointer( pset, index )
       pset_h pset ;
       unsigned index ;

       void pset_compact( pset )
       pset_h pset ;

       void pset_sort( pset, compfunc )
       pset_h pset ;
       int (*compfunc)() ;

       void pset_apply( pset, func, arg )
       pset_h pset ;

       void (*func)() ;
       void *arg ;

SYNOPSIS
       #include "pset.h"

       psi_h psi_create( pset )
       pset_h pset ;

       void psi_destroy( iter )
       psi_h iter ;

       void psi_reset( iter, pset )
       psi_h iter ;
       pset_h pset ;

       void *psi_start( iter )
       psi_h iter ;

       void *psi_next( iter )
       psi_h iter ;

       void psi_remove( iter )
       psi_h iter ;

SYNOPSIS
       int Sprint( fd, format [ , ... ] )
       int fd ;
       char *format ;

SYNOPSIS
       #include "sio.h"
       #include <varargs.h>

       int Sread( fd, buf, nbytes )
       int fd ;
       char *buf ;
       int nbytes ;

       int Sgetc( fd )
       int fd ;

       char *Srdline( fd )
       int fd ;

       char *Sfetch( fd, length )
       int fd ;
       long *length ;

       int Swrite( fd, buf, nbytes )
       int fd ;
       char *buf ;
       int nbytes ;

       int Sputc( fd, c )
       int fd ;
       char c ;

       int Sprint( fd, format [ , ... ] )
       int fd ;
       char *format ;

       int Sprintv( fd, format, ap )
       int fd ;
       char *format ;
       va_list ap ;

       int Sdone( fd )
       int fd ;

       int Sundo( fd, type )
       int fd ;
       int type ;

       int Stie( ifd, ofd )
       int ifd, ofd ;

       int Suntie( fd )
       int fd ;

       int Sbuftype( fd, type )
       int fd, type ;

       int Smorefds()

       int Sflush( fd )
       int fd ;

       int Sclose( fd )
       int fd ;

       int Sgetchar( fd )
       int fd ;

       int Sputchar( fd, c )
       int fd;
       char c ;

       int SIOLINELEN( fd )
       int fd ;

       int SIOMAXLINELEN( fd )
       int fd ;

SYNOPSIS
       #include "str.h"

       str_h str_parse( str, separ, flags, errnop )
       char *str ;
       char *separ ;
       int flags ;
       int *errnop ;

       void str_endparse( handle )
       str_h handle ;

       char *str_component( handle )
       str_h handle ;

       int str_setstr( handle, newstr )
       str_h handle ;
       char *newstr ;

       int str_separator( handle, separ )
       str_h handle ;
       char *separ ;

       char *str_nextpos( handle )
       str_h handle ;

       extern int str_errno ;

SYNOPSIS
       #include "str.h"

       char *str_sprint( buf, format, ... )
       char *buf ;
       char *format ;

       char *str_sprintv( buf, format, ap )
       char *buf ;
       char *format ;
       va_list ap ;

       int str_nprint( buf, format, ... )
       char *buf ;
       char *format ;

       int str_nprintv( buf, format, ap )
       char *buf ;
       char *format ;
       va_list ap ;

       void str_print( countp, buf, format, ... )
       int *countp ;
       char *buf ;
       char *format ;

       void str_printv( countp, buf, format, ap )
       int *countp ;
       char *buf ;
       char *format ;
       va_list ap ;

       char *strx_sprint( buf, len, format, ... )
       char *buf ;
       int len ;
       char *format ;

       char *strx_sprintv( buf, len, format, ap )
       char *buf ;
       int len ;
       char *format ;
       va_list ap ;

       int strx_nprint( buf, len, format, ... )
       char *buf ;
       int len ;
       char *format ;

       int strx_nprintv( buf, len, format, ap )
       char *buf ;
       int len ;
       char *format ;
       va_list ap ;

       void strx_print( countp, buf, len, format, ... )
       int *countp ;
       char *buf ;
       int len ;
       char *format ;

       void strx_printv( countp, buf, len, format, ap )
       int *countp ;
       char *buf ;
       int len ;
       char *format ;
       va_list ap ;

SYNOPSIS
       #include "str.h"

       strs_h strs_setup( flags, pattern [, patlen] )
       int flags ;
       char *pattern ;

       char *strs_match( handle, str, len )
       strs_h handle ;
       char *str ;
       int len ;

       void strs_done( handle )
       strs_h handle ;

       char *strs_search( flags, str, len, pattern [, patlen] )
       int flags ;
       char *str ;
       int len ;
       char *pattern ;

SYNOPSIS
       #include "str.h"

       char *str_find( s1, s2 )
       char *s1, *s2 ;

       char *str_casefind( s1, s2 )
       char *s1, *s2 ;

       void str_fill( s, c )
       char *s ;
       char c ;

       char *str_lower( s )
       char *s ;

       char *str_upper( s )
       char *s ;

SYNOPSIS
       #include "timemacros.h"

       void TV_ADD( tv_res, tv1, tv2 )
       struct timeval tv_res, tv1, tv2 ;

       void TV_SUB( tv_res, tv1, tv2 )
       struct timeval tv_res, tv1, tv2 ;

       void TV_ZERO( tv )
       struct timeval tv ;

       int TV_LT( tv1, tv2 )
       struct timeval tv1, tv2 ;

       int TV_LE( tv1, tv2 )
       struct timeval tv1, tv2 ;

       int TV_GT( tv1, tv2 )
       struct timeval tv1, tv2 ;

       int TV_GE( tv1, tv2 )
       struct timeval tv1, tv2 ;

       int TV_EQ( tv1, tv2 )
       struct timeval tv1, tv2 ;

       int TV_NE( tv1, tv2 )
       struct timeval tv1, tv2 ;

       int TV_ISZERO( tv )
       struct timeval tv ;

SYNOPSIS
       #include "timer.h"

       enum timer_types { TIMER_REAL, TIMER_VIRTUAL, TIMER_PROF } ;
       enum timer_timetypes { TIMER_ABSOLUTE, TIMER_RELATIVE } ;

       extern int timer_errno ;

       timer_h timer_create( type, flags, errnop )
       enum timer_types type ;
       int flags ;
       int *errnop ;

       void timer_destroy( handle )
       timer_h handle ;

       int timer_start( handle, itvp, time_type, action )
       timer_h handle ;
       struct itimerval *itvp ;
       enum timer_timetypes time_type ;
       struct timer_action *action ;

       void timer_stop( handle )
       timer_h handle ;

       void timer_block( handle )
       timer_h handle ;

       void timer_unblock( handle )
       timer_h handle ;

       unsigned timer_expirations( handle )
       timer_h handle ;

       void timer_block_type( type )
       enum timer_types type ;

       void timer_unblock_type( type )
       enum timer_types type ;

SYNOPSIS
       #include "xlog.h"

       xlog_h xlog_create( type, id, flags, ... )
       xlog_e type ;
       char *id ;
       int flags ;

       int xlog_parms( type, ... )
       xlog_e type ;

       void xlog_destroy( xlog )
       xlog_h xlog ;

       void xlog_write( xlog, buf, len, flags, ... )
       xlog_h xlog ;
       char buf[] ;
       int len ;
       int flags ;

       int xlog_control( xlog, cmd, ... )
       xlog_h xlog ;
       xlog_cmd_e cmd ;

