home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-26 | 29.9 KB | 1,145 lines |
- Newsgroups: comp.sources.unix
- From: panos@cs.colorado.edu (Panos Tsirigotis)
- Subject: v26i256: xinetd-2.1.1 - inetd replacement with access control and logging, Part12/31
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: panos@cs.colorado.edu (Panos Tsirigotis)
- Posting-Number: Volume 26, Issue 256
- Archive-Name: xinetd-2.1.1/part12
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 12 (of 31)."
- # Contents: libs/src/sio/Sprint.3 libs/src/sio/sioconf.h
- # xinetd/config.h xinetd/int.c xinetd/retry.c
- # Wrapped by panos@mystique on Mon Jun 21 14:51:23 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'libs/src/sio/Sprint.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/Sprint.3'\"
- else
- echo shar: Extracting \"'libs/src/sio/Sprint.3'\" \(5277 characters\)
- sed "s/^X//" >'libs/src/sio/Sprint.3' <<'END_OF_FILE'
- X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X.\"All rights reserved. The file named COPYRIGHT specifies the terms
- X.\"and conditions for redistribution.
- X.\"
- X.\" $Id: Sprint.3,v 8.1 1993/03/13 01:15:34 panos Exp $
- X.TH Sprint 3X "29 May 1992"
- X.SH NAME
- XSprint -- formatted stream output
- X.SH SYNOPSIS
- X.LP
- X.nf
- X.ft B
- Xint Sprint( fd, format [ , ... ] )
- Xint fd ;
- Xchar *format ;
- X.SH DESCRIPTION
- X\fBSprint()\fR provides formatted output conversion. The formatting is
- Xcontrolled by the \fIformat\fR argument. All characters in
- X\fIformat\fR that do not specify a conversion are printed. A conversion
- Xis specified by a '%' followed by a string that ends with a
- Xconversion type character. The string may contain flags, a field width,
- Xa precision, and a modifier.
- X.LP
- XPossible flags (more that one can be specified and they can be in any order)
- Xinclude:
- X.TP 10
- X.B \'-'
- Xspecifies left adjustment of the converted argument. The default
- Xis right adjustment. This flag is meaningful only if a field width
- Xis specified.
- X.TP
- X.B \'+'
- Xspecifies that a number will always have a sign as a prefix (this
- Xforces a '+' sign to appear if the number is positive).
- X.TP
- X.B \' '
- Xprefixes a \fIspace\fR to the number if the number has not a sign
- X(therefore the '+' flag overrides this flag).
- X.TP
- X.B \'#'
- XThe meaning of '#' depends on the conversion type character: for \fBo\fR
- Xconversions the first digit will be 0; for \fBx\fR or \fBX\fR conversions
- X\fB0x\fR or \fB0X\fR respectively will be prefixed to the number (if it
- Xis not zero); for \fBe\fR, \fBE\fR, \fBf\fR, \fBg\fR, and \fBG\fR conversions
- Xthe number will always have a decimal point.
- X.TP
- X.B \'0'
- Xspecifies padding with zeros instead of spaces.
- X.LP
- XThe field width is specified by a number. This number indicates the
- X\fIminimum\fR width for the field. A '*' may be used instead of the number.
- XIn that case the width is the value of the next argument which should
- Xbe an \fBint\fR.
- XA negative width value specifies left adjustment with a width equal
- Xto the absolute width value.
- X.LP
- XA precision is specified by a '.' followed by a number. The meaning of
- Xthe precision depends on the type conversion character. For a string
- Xconversion, precision determines how many characters are printed from
- Xthe string. For integer conversions, precision determines the
- Xnumber of digits used to print the number (zero padding is done if
- Xthe precision exceeds the length of the number). For floating point
- Xconversions, precision determines the number of digits after the
- Xdecimal point (\fBe\fR, \fBE\fR, \fBf\fR) or the number of
- Xsignificant digits (\fBg\fR, \fBG\fR).
- XA '*' may be used instead of a number to specify the precision. In that
- Xcase the precision is the value of the next argument which should
- Xbe an \fBint\fR.
- XThe behavior of \fBSprint()\fR is undefined if the precision is negative.
- X.LP
- XThe length modifier is \fBl\fR and indicates that the argument is
- Xa \fBlong\fR integer.
- X.LP
- XThe type conversion characters are:
- X\fBd, i, o, x, X, u, c, s, f, e, E, g, G, p, n, %\fR.
- XFor floating point conversions the argument should be of type \fIdouble\fR.
- X.TP 10
- X.B d,i
- Xspecify signed decimal conversion.
- X.TP
- X.B u
- Xspecifies unsigned decimal conversion.
- X.TP
- X.B o
- Xspecifies octal conversion.
- X.TP
- X.B x,X
- Xspecify hexadecimal conversion. For
- X.B x
- Xthe hex digits used are 0123456789abcdef. For
- X.B X
- Xthe hex digits used are 0123456789ABCDEF.
- XThere is no leading
- X.B 0x
- Xor
- X.B 0X
- X(use the '#' flag for that).
- X.TP
- X.B c
- Xspecifies character conversion; the argument should be of type
- X\fIchar\fR.
- X.TP
- X.B s
- Xspecifies string conversion; the argument should be of type
- X\fIchar *\fR.
- X.TP
- X.B f
- Xspecifies conversion to the form [-]ddd.dddd. The number
- Xof digits after the decimal point depends on precision; the default is 6.
- XIf the precision is 0, the decimal point is not printed (this can
- Xbe overriden with the '#' flag).
- X.B e,E
- Xspecify conversion to the form [-]ddd.dddd[eE][+-]ddd.
- XThe number of digits after the decimal point depends on precision;
- Xthe default is 6. If the precision is 0, the decimal point is not printed
- X(this can be overriden with the '#' flag).
- XThe exponent is at least 2 digit wide.
- X.TP
- X.B g,G
- Xspecify a conversion using the
- X.B e,E
- Xformat respectively if the
- Xexponent is less than -4 or greater than or equal to the precision;
- Xotherwise the
- X.B f
- Xformat is used.
- X.TP
- X.B p
- Xis used to print pointers (type \fIvoid *\fR,
- Xor \fIchar *\fR if the compiler does not support the former).
- X.TP
- X.B n
- Xexpects a \fIint *\fR argument and puts in that integer
- Xthe number of characters already printed by this call.
- X.TP
- X.B %
- Xis used to print a \fI%\fR.
- X.LP
- XIf an unknown conversion character is specified, the percent sign
- Xfollowed by that character will be printed.
- X.SH RETURN VALUE
- X.LP
- XIf no error occured, \fBSprint()\fR returns the number of characters
- Xprinted. In case of error, it returns \fBSIO_ERR\fR.
- X.SH BUGS
- X.LP
- XThis is a list of differences between \fBSprint()\fR and the ANSI C Standard
- X\fBprintf()\fR:
- X.LP
- X\fBSprint()\fR does not support non-removal of trailing zeroes for
- X\fBg\fR and \fBG\fR conversions when the '#' flag is used.
- X.LP
- X\fBSprint()\fR does not support the h and L modifiers.
- X.LP
- XThe current implementation assumes that \fIsizeof(int)==sizeof(long)\fR.
- X.LP
- X\fBSprint()\fR supports "%p" only if \fIsizeof(pointer)<=sizeof(int)\fR.
- END_OF_FILE
- if test 5277 -ne `wc -c <'libs/src/sio/Sprint.3'`; then
- echo shar: \"'libs/src/sio/Sprint.3'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/Sprint.3'
- fi
- if test -f 'libs/src/sio/sioconf.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/sioconf.h'\"
- else
- echo shar: Extracting \"'libs/src/sio/sioconf.h'\" \(5101 characters\)
- sed "s/^X//" >'libs/src/sio/sioconf.h' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- X
- X/*
- X * $Id: sioconf.h,v 8.5 1993/03/17 02:54:47 panos Exp $
- X */
- X
- X/*
- X * This file has 2 sections:
- X * 1. a OS-specific section
- X * 2. a CPU/compiler-specific section
- X *
- X * You can override/redefing any of the constants/macros in this file.
- X * by uncommenting the inclusion of customconf.h and placing your own
- X * definitions in that file.
- X */
- X
- X/* #include "customconf.h" */
- X
- X
- X
- X/*
- X * OS-specific section.
- X *
- X * Features here use the flag HAS_<feature>.
- X * List of flags (check the following for macros that can be overriden):
- X *
- X * HAS_MMAP (overridable macros)
- X *
- X * HAS_ATEXIT
- X * HAS_ONEXIT
- X * HAS_OTHER_FINALIZER (must define macros)
- X *
- X * HAS_MEMOPS
- X * HAS_BCOPY (HAS_MEMOPS will be preferred if both are defined)
- X *
- X * At least one of the following flags must be defined. The 2nd and 3rd
- X * flags are incompatible.
- X * HAS_ISATTY
- X * HAS_SYSVTTY
- X * HAS_BSDTTY
- X */
- X
- X/*
- X * Memory mapping.
- X * The library requires 3 macros: SIO_MMAP, SIO_MUNMAP, SIO_MNEED.
- X * You can selectively override any of them.
- X * Notice that the SIO_MNEED macro is not required. If your system
- X * does not have madvise, you can define the macro as:
- X * #define SIO_MNEED( addr, len )
- X */
- X#ifdef HAS_MMAP
- X
- X#if !defined( SIO_MMAP ) || !defined( SIO_MUNMAP ) || !defined( SIO_MNEED )
- X#include <sys/types.h>
- X#include <sys/mman.h>
- X#endif
- X
- X#ifndef SIO_MMAP
- X#define SIO_MMAP( addr, len, fd, off ) \
- X mmap( addr, len, PROT_READ, \
- X ( addr == 0 ) ? MAP_PRIVATE : MAP_PRIVATE + MAP_FIXED, \
- X fd, off )
- X#endif
- X
- X#ifndef SIO_MUNMAP
- X#define SIO_MUNMAP( addr, len ) munmap( addr, len )
- X#endif
- X
- X#ifndef SIO_MNEED
- X#define SIO_MNEED( addr, len ) (void) madvise( addr, len, MADV_WILLNEED )
- X#endif
- X
- X#endif /* HAS_MMAP */
- X
- X/*
- X * N_SIO_DESCRIPTORS is the maximum number of file descriptors
- X * supported by the OS
- X */
- X#ifndef N_SIO_DESCRIPTORS
- X#include <sys/param.h>
- X#define N_SIO_DESCRIPTORS NOFILE
- X#endif
- X
- X
- X
- X/*
- X * Finalization function.
- X *
- X * The purpose of this function is to do work after your program has
- X * called exit(3). In the case of SIO, this means flushing the SIO
- X * output buffers.
- X *
- X * If your system does not support atexit or onexit but has some other
- X * way of installing a finalization function, you define the flag
- X * HAS_FINALIZER. Then you must define the macros
- X * SIO_FINALIZE and SIO_DEFINE_FIN
- X *
- X * SIO_FINALIZE attempts to install a finalization function and returns TRUE
- X * if successful, FALSE if unsuccessful.
- X * SIO_DEFINE_FIN defines the finalization function (the reason for this macro
- X * s that different systems pass different number/type of arguments to the
- X * finalization function; the SIO finalization function does not use any
- X * arguments).
- X */
- X#if defined(HAS_ONEXIT) || defined(HAS_ATEXIT) || defined(HAS_FINALIZER)
- X
- X#define HAS_FINALIZATION_FUNCTION
- X
- X#if defined( HAS_ONEXIT ) && defined( HAS_ATEXIT )
- X#undef HAS_ONEXIT
- X#endif
- X
- X#ifdef HAS_ONEXIT
- X#define SIO_FINALIZE( func ) ( on_exit( func, (caddr_t) 0 ) == 0 )
- X#define SIO_DEFINE_FIN( func ) static void func ( exit_status, arg ) \
- X int exit_status ; \
- X caddr_t arg ;
- X#endif /* HAS_ONEXIT */
- X
- X#ifdef HAS_ATEXIT
- X#define SIO_FINALIZE( func ) ( atexit( func ) == 0 )
- X#define SIO_DEFINE_FIN( func ) static void func ()
- X#endif /* HAS_ATEXIT */
- X
- X#endif /* HAS_ONEXIT || HAS_ATEXIT || HAS_FINALIZER */
- X
- X
- X/*
- X * HAS_MEMOPS should be defined if your OS supports the mem* functions
- X * (memcpy etc). If not, then you can define HAS_BCOPY if your OS supports
- X * bcopy.
- X */
- X#if defined( HAS_MEMOPS ) && defined( HAS_BCOPY )
- X#undef HAS_BCOPY
- X#endif
- X
- X
- X/*
- X * Support for the isatty(3) function. This function identifies if a
- X * desciptor refers to a terminal.
- X *
- X * Case 1: isatty(3) is in the C library
- X * --> define HAS_ISATTY
- X * Case 2: no isatty(3), BSD 4.3 tty handling
- X * --> define HAS_BSDTTY
- X * Case 3: no isatty(3), System V tty handling
- X * --> define HAS_SYSVTTY
- X *
- X * The following code checks:
- X * 1) that at least one of the flags is defined
- X * 2) only one of the BSD, SYS V flags is defined
- X */
- X#if !defined(HAS_ISATTY) && !defined(HAS_BSDTTY) && !defined(HAS_SYSVTTY)
- XERROR function_isatty_not_available ;
- X#endif
- X
- X#ifdef HAS_ISATTY
- X#undef HAS_BSDTTY
- X#undef HAS_SYSVTTY
- X#endif
- X
- X#if defined(HAS_BSDTTY) && defined(HAS_SYSVTTY)
- XERROR HAS_BSDTTY_and_HAS_SYSVTTY_both_defined ;
- X#endif
- X
- X
- X
- X/*
- X * CPU/compiler-specific section.
- X *
- X * The following constant affects the behavior of Sprint.
- X *
- X * Sprint performs integer->string conversions by first converting
- X * the integer to the widest int type supported by the CPU/compiler.
- X * By default, this is the "long int" type. If your machine has
- X * a wider type, you can specify it by defining the WIDE_INT constant.
- X * For example:
- X * #define WIDE_INT long long
- X */
- X
- END_OF_FILE
- if test 5101 -ne `wc -c <'libs/src/sio/sioconf.h'`; then
- echo shar: \"'libs/src/sio/sioconf.h'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/sioconf.h'
- fi
- if test -f 'xinetd/config.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/config.h'\"
- else
- echo shar: Extracting \"'xinetd/config.h'\" \(5195 characters\)
- sed "s/^X//" >'xinetd/config.h' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- X#ifndef CONFIG_H
- X#define CONFIG_H
- X
- X/*
- X * $Id: config.h,v 6.5 1993/06/13 01:42:32 panos Exp $
- X */
- X
- X/*
- X * The purpose of customconf.h is to allow the override of
- X * constants defined in this file. These include all constants that
- X * cannot be overriden from the command line via some option.
- X */
- X#ifdef CUSTOMCONF
- X#include "customconf.h"
- X#endif
- X
- X
- X#define DEFAULT_CONFIG_FILE "/etc/xinetd.conf"
- X
- X/*
- X * This is the facility used by xinetd to log syslog messages
- X */
- X#define DEFAULT_SYSLOG_FACILITY LOG_DAEMON
- X
- X/*
- X * This is the level used for log messages when a service logs to syslog
- X */
- X#define DEFAULT_SERVICE_SYSLOG_LEVEL LOG_INFO
- X
- X/*
- X * Max number of concurrently running processes forked to get
- X * the user id from the remote host
- X */
- X#define DEFAULT_LOGPROCS 15
- X
- X/*
- X * Max number of concurrently running processes forked to do service shutdown
- X */
- X#define DEFAULT_SHUTDOWNPROCS 10
- X
- X/*
- X * The loop rate is a bound on the rate of forking servers for a
- X * particular service. If that rate is exceeded, the service is deactivated.
- X */
- X#define DEFAULT_LOOP_RATE 10
- X
- X/*
- X * Signal-to-action mapping
- X */
- X#ifndef RECONFIG_SOFT_SIG
- X#define RECONFIG_SOFT_SIG SIGUSR1
- X#endif
- X#ifndef RECONFIG_HARD_SIG
- X#define RECONFIG_HARD_SIG SIGUSR2
- X#endif
- X#ifndef TERMINATION_SIG
- X#define TERMINATION_SIG SIGTERM
- X#endif
- X#ifndef STATE_DUMP_SIG
- X#define STATE_DUMP_SIG SIGHUP
- X#endif
- X#ifndef CONSISTENCY_CHECK_SIG
- X#define CONSISTENCY_CHECK_SIG SIGIOT
- X#endif
- X#ifndef RETRY_SIG
- X#define RETRY_SIG SIGALRM
- X#endif
- X#ifndef SERVER_EXIT_SIG
- X#define SERVER_EXIT_SIG SIGCHLD
- X#endif
- X#ifndef QUIT_SIG
- X#define QUIT_SIG SIGQUIT
- X#endif
- X
- X/*
- X * This is the file where the internal state of xinetd is dumped upon
- X * receipt of STATE_DUMP_SIG
- X */
- X#ifndef DUMP_FILE
- X#define DUMP_FILE "/tmp/xinetd.dump"
- X#endif
- X
- X/*
- X * CONF_TIMEOUT determines if there will be a timeout for reading the
- X * configuration file. The timeout is specified in seconds.
- X * Case 1: CONF_TIMEOUT is undefined
- X * there will be a timeout equal to a default value (60 sec).
- X * Case 2: CONF_TIMEOUT is a positive number
- X * there will be a timeout equal to the value of CONF_TIMEOUT
- X * Case 3: CONF_TIMEOUT is 0
- X * no timeout
- X */
- X#ifndef CONF_TIMEOUT
- X#define CONF_TIMEOUT 60
- X#endif
- X
- X/*
- X * There are 2 timeouts (in seconds) when trying to get the user id from
- X * the remote host. Any timeout value specified as 0 implies an infinite
- X * timeout.
- X * LOGUSER_SUCCESS_TIMEOUT is the timeout when access control has been passed
- X * and a new process has been forked to exec the server.
- X * LOGUSER_FAILURE_TIMEOUT is the timeout when the attempt to access the
- X * service has been rejected.
- X *
- X * Both timeouts should be at least 30 seconds as suggested in RFC 1413
- X * (assuming they are not 'infinite' timeouts).
- X */
- X#ifndef LOGUSER_SUCCESS_TIMEOUT
- X#define LOGUSER_SUCCESS_TIMEOUT 0
- X#endif
- X#ifndef LOGUSER_FAILURE_TIMEOUT
- X#define LOGUSER_FAILURE_TIMEOUT 30
- X#endif
- X
- X/*
- X * This is used when an instance limit is not specified for a service
- X * and the defaults entry does not specify an instance limit either.
- X * It can be a positive number or "UNLIMITED".
- X */
- X#ifndef DEFAULT_INSTANCE_LIMIT
- X#define DEFAULT_INSTANCE_LIMIT UNLIMITED
- X#endif
- X
- X/*
- X * This is the interval (in seconds) over which we check if the service
- X * loop rate has been exceeded.
- X */
- X#ifndef LOOP_INTERVAL
- X#define LOOP_INTERVAL 2
- X#endif
- X
- X/*
- X * LOG_OPEN_FLAGS are the flags used to open a log file (this is used as
- X * the 3rd argument of open(2))
- X */
- X#ifndef LOG_OPEN_FLAGS
- X#define LOG_OPEN_FLAGS O_CREAT+O_APPEND+O_WRONLY
- X#endif
- X
- X/*
- X * Number of consecutive fork failures that we are willing to put up with
- X * before giving up.
- X */
- X#ifndef MAX_FORK_FAILURES
- X#define MAX_FORK_FAILURES 5
- X#endif
- X
- X/*
- X * This is the time period during which we will not log subsequest attempts
- X * to access a datagram-based service from the same bad address after logging
- X * the first one.
- X * For example, if we receive a datagram at time t from address A which
- X * has a match in the no_access list, we will log the failed attempt and
- X * during the interval (t, t+DGRAM_IGNORE_TIME) we will not log attempts
- X * from address A (for the same service).
- X * In this context, the address is defined as (IP address, port number).
- X */
- X#ifndef DGRAM_IGNORE_TIME
- X#define DGRAM_IGNORE_TIME 60 /* seconds */
- X#endif
- X
- X#ifndef DUMP_FILE_MODE
- X#define DUMP_FILE_MODE 0644
- X#endif
- X
- X#ifndef LOG_FILE_MODE
- X#define LOG_FILE_MODE 0644
- X#endif
- X
- X/*
- X * The DATAGRAM_SIZE should be big enough for an ethernet packet
- X */
- X#ifndef DATAGRAM_SIZE
- X#define DATAGRAM_SIZE 2048
- X#endif
- X
- X/*
- X * Time interval between retry attempts
- X */
- X#ifndef RETRY_INTERVAL
- X#define RETRY_INTERVAL 5 /* seconds */
- X#endif
- X
- X/*
- X * LOG_EXTRA_MIN, LOG_EXTRA_MAX define the limits by which the hard limit
- X * on the log size can exceed the soft limit
- X */
- X#ifndef LOG_EXTRA_MIN
- X#define LOG_EXTRA_MIN ( 5 * 1024 )
- X#endif
- X#ifndef LOG_EXTRA_MAX
- X#define LOG_EXTRA_MAX ( 20 * 1024 )
- X#endif
- X
- X#endif /* CONFIG_H */
- END_OF_FILE
- if test 5195 -ne `wc -c <'xinetd/config.h'`; then
- echo shar: \"'xinetd/config.h'\" unpacked with wrong size!
- fi
- # end of 'xinetd/config.h'
- fi
- if test -f 'xinetd/int.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/int.c'\"
- else
- echo shar: Extracting \"'xinetd/int.c'\" \(5085 characters\)
- sed "s/^X//" >'xinetd/int.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- Xstatic char RCSid[] = "$Id: int.c,v 6.5 1993/06/15 23:25:57 panos Exp $" ;
- X
- X#include <sys/types.h>
- X#include <sys/socket.h>
- X#include <syslog.h>
- X#include <errno.h>
- X#include <signal.h>
- X
- X#include "config.h"
- X#include "connection.h"
- X#include "service.h"
- X#include "server.h"
- X#include "int.h"
- X
- Xvoid msg() ;
- Xchar *inet_ntoa() ;
- Xunsigned long inet_addr() ;
- X
- Xtypedef struct intercept *(*initfunc)() ;
- X
- Xstruct lookup_table
- X{
- X initfunc initializer ;
- X int socket_type ;
- X} ;
- X
- Xextern struct intercept *di_init() ;
- Xextern struct intercept *si_init() ;
- X
- Xstatic struct lookup_table intercept_lookup_table[] =
- X {
- X { di_init, SOCK_DGRAM },
- X { si_init, SOCK_STREAM },
- X { NULL }
- X } ;
- X
- X
- X/*
- X * This variable has file scope for the benefit of the signal handler
- X */
- Xstatic struct intercept *intp ;
- X
- X
- X
- XPRIVATE initfunc find_initializer( type )
- X int type ;
- X{
- X struct lookup_table *ltp ;
- X
- X for ( ltp = intercept_lookup_table ; ltp->initializer ; ltp++ )
- X if ( ltp->socket_type == type )
- X return( ltp->initializer ) ;
- X msg( LOG_ERR, "find_initializer", "No initializer for type %d", type ) ;
- X _exit( 0 ) ;
- X /* NOTREACHED */
- X}
- X
- X
- X/*
- X * This function is the interface of the intercept code with the rest of
- X * the program.
- X */
- Xvoid intercept( serp )
- X struct server *serp ;
- X{
- X struct service *sp = SERVER_SERVICE( serp ) ;
- X initfunc initializer ;
- X PRIVATE void start_server() ;
- X PRIVATE void terminate_server() ;
- X
- X#ifdef DEBUG_INTERCEPTOR
- X if ( debug.on )
- X {
- X msg( LOG_DEBUG, "intercept", "%d is sleeping", getpid() ) ;
- X sleep( 10 ) ;
- X }
- X#endif
- X
- X initializer = find_initializer( SVC_SOCKET_TYPE( sp ) ) ;
- X intp = (*initializer)( serp ) ;
- X start_server( intp ) ;
- X (*intp->int_ops->mux)() ;
- X terminate_server( intp ) ;
- X /*
- X * the terminate_server function should not return but even if it
- X * does, child_process will do the _exit.
- X */
- X}
- X
- X
- X
- X/*
- X * Create a socket and bind it to (INADDR_LOOPBACK,0)
- X */
- XPRIVATE int get_server_socket( ip )
- X struct intercept *ip ;
- X{
- X struct service *sp = SERVER_SERVICE( INT_SERVER( ip ) ) ;
- X struct sockaddr_in *sinp = INT_LOCALADDR( ip ) ;
- X int sd ;
- X int size ;
- X char *func = "get_server_socket" ;
- X
- X if ( ( sd = socket( AF_INET, SVC_SOCKET_TYPE( sp ), 0 ) ) == -1 )
- X int_fail( ip, "socket creation" ) ;
- X
- X sinp->sin_family = AF_INET ;
- X#ifdef INADDR_LOOPBACK
- X sinp->sin_addr.s_addr = htonl( INADDR_LOOPBACK ) ;
- X#else
- X sinp->sin_addr.s_addr = inet_addr( "127.0.0.1" ) ;
- X#endif
- X sinp->sin_port = 0 ;
- X
- X if ( bind( sd, SA( sinp ), sizeof( *sinp ) ) == -1 )
- X int_fail( ip, "bind" ) ;
- X
- X size = sizeof( *sinp ) ;
- X if ( getsockname( sd, SA( sinp ), &size ) == -1 )
- X int_fail( ip, "getsockname" ) ;
- X
- X if ( debug.on )
- X msg( LOG_DEBUG, func, "address = %s, port = %d",
- X inet_ntoa( sinp->sin_addr ), ntohs( sinp->sin_port ) ) ;
- X
- X if ( ip->int_socket_type == SOCK_STREAM )
- X (void) listen( sd, LISTEN_BACKLOG ) ;
- X
- X return( sd ) ;
- X}
- X
- X
- XPRIVATE void start_server( ip )
- X struct intercept *ip ;
- X{
- X struct server *serp = INT_SERVER( ip ) ;
- X struct service *sp = SERVER_SERVICE( serp ) ;
- X int server_socket ;
- X pid_t pid ;
- X void child_process() ;
- X
- X server_socket = get_server_socket( ip ) ;
- X
- X pid = fork() ;
- X
- X switch ( pid )
- X {
- X case -1:
- X int_fail( ip, "fork" ) ;
- X /* NOTREACHED */
- X
- X case 0:
- X conn_set_descriptor( SERVER_CONNECTION( serp ), server_socket ) ;
- X svc_make_external( sp ) ; /* avoid looping */
- X child_process( serp ) ;
- X /* NOTREACHED */
- X
- X default:
- X server_set_pid( serp, pid ) ;
- X (void) close( server_socket ) ;
- X }
- X}
- X
- X
- X
- X/*
- X * Return value:
- X * OK if the server died
- X * FAILED otherwise
- X */
- XPRIVATE status_e wait_child( ip )
- X struct intercept *ip ;
- X{
- X char *func = "wait_child" ;
- X
- X for ( ;; )
- X {
- X int status ;
- X pid_t pid = wait( &status ) ;
- X
- X if ( pid == -1 )
- X {
- X if ( errno != EINTR )
- X {
- X msg( LOG_ERR, func, "wait: %m" ) ;
- X return( FAILED ) ;
- X }
- X }
- X else if ( pid == SERVER_PID( INT_SERVER( ip ) ) )
- X {
- X if ( PROC_STOPPED( status ) )
- X return( FAILED ) ;
- X server_set_exit_status( INT_SERVER( ip ), status ) ;
- X return( OK ) ;
- X }
- X else
- X {
- X msg( LOG_ERR, func,
- X "wait returned pid of unknown process: %d", pid ) ;
- X return( FAILED ) ;
- X }
- X }
- X}
- X
- X
- X
- XPRIVATE void terminate_server( ip )
- X struct intercept *ip ;
- X{
- X pid_t pid = SERVER_PID( INT_SERVER( intp ) ) ;
- X
- X if ( pid > 0 )
- X (void) kill( pid, SIGKILL ) ;
- X
- X /*
- X * Normally, wait_child should never return since a SIGCHLD will
- X * invoke the signal handler which will then call the exit function.
- X */
- X if ( wait_child( ip ) == OK )
- X (*intp->int_ops->exit)() ;
- X}
- X
- X
- Xvoid int_sighandler( sig )
- X int sig ;
- X{
- X char *func = "int_sighandler" ;
- X char *sig_name() ;
- X
- X if ( debug.on )
- X msg( LOG_DEBUG, func, "Received signal %s", sig_name( sig ) ) ;
- X
- X if ( sig == SERVER_EXIT_SIG )
- X {
- X if ( wait_child( intp ) == OK )
- X (*intp->int_ops->exit)() ;
- X }
- X else if ( sig == INTERCEPT_SIG )
- X INTERCEPT( intp ) = FALSE ;
- X else if ( sig == SIGTERM )
- X terminate_server( intp ) ;
- X}
- END_OF_FILE
- if test 5085 -ne `wc -c <'xinetd/int.c'`; then
- echo shar: \"'xinetd/int.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/int.c'
- fi
- if test -f 'xinetd/retry.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/retry.c'\"
- else
- echo shar: Extracting \"'xinetd/retry.c'\" \(5411 characters\)
- sed "s/^X//" >'xinetd/retry.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- Xstatic char RCSid[] = "$Id: retry.c,v 6.8 1993/06/15 23:25:57 panos Exp $" ;
- X
- X#include <sys/time.h>
- X#include <syslog.h>
- X
- X#include "pset.h"
- X
- X#include "state.h"
- X#include "access.h"
- X#include "config.h"
- X#include "server.h"
- X#include "connection.h"
- X#include "flags.h"
- X
- Xvoid msg() ;
- Xvoid out_of_memory() ;
- X
- Xstatic bool_int retry_timer_running ;
- X
- XPRIVATE void stop_retry_timer() ;
- XPRIVATE void start_retry_timer() ;
- X
- X
- X/*
- X * Attempt to start all servers in the retry table
- X */
- Xvoid server_retry()
- X{
- X unsigned servers_started = 0 ;
- X register unsigned u ;
- X char *func = "server_retry" ;
- X PRIVATE void cancel_retry() ;
- X
- X for ( u = 0 ; u < pset_count( RETRIES( ps ) ) ; u++ )
- X {
- X register struct server *retry = SERP(
- X pset_pointer( RETRIES( ps ), u ) ) ;
- X register struct service *sp = SERVER_SERVICE( retry ) ;
- X connection_s *cp = SERVER_CONNECTION( retry ) ;
- X
- X /*
- X * Drop the retry if access control fails or we have
- X * a memory allocation problem
- X */
- X if ( svc_access_control( sp, cp ) == FAILED ||
- X pset_add( SERVERS( ps ), retry ) == NULL )
- X {
- X cancel_retry( retry ) ;
- X pset_pointer( RETRIES( ps ), u ) = NULL ;
- X continue ;
- X }
- X
- X if ( server_start( retry ) == OK )
- X {
- X servers_started++ ;
- X svc_dec_retries( sp ) ;
- X conn_close( cp ) ;
- X pset_pointer( RETRIES( ps ), u ) = NULL ;
- X continue ;
- X }
- X else
- X {
- X pset_remove( SERVERS( ps ), retry ) ;
- X if ( SERVER_FORKLIMIT( retry ) )
- X {
- X /*
- X * give up retrying
- X */
- X msg( LOG_ERR, func,
- X "service %s: too many consecutive fork failures", SVC_ID(sp) ) ;
- X svc_log_failure( sp, cp, AC_FORK ) ;
- X cancel_retry( retry ) ;
- X pset_pointer( RETRIES( ps ), u ) = NULL ;
- X continue ;
- X }
- X else
- X {
- X if ( debug.on )
- X msg( LOG_DEBUG, func,
- X "fork failed for service %s. Retrying...", SVC_ID( sp ) ) ;
- X }
- X }
- X }
- X
- X pset_compact( RETRIES( ps ) ) ;
- X
- X if ( debug.on )
- X msg( LOG_DEBUG, func,
- X "%d servers started, %d left to retry",
- X servers_started, pset_count( RETRIES( ps ) ) ) ;
- X
- X if ( pset_count( RETRIES( ps ) ) == 0 )
- X stop_retry_timer() ;
- X}
- X
- X
- X/*
- X * Schedule a retry by inserting the struct server in the retry table
- X * and starting the timer if necessary
- X */
- Xstatus_e schedule_retry( serp )
- X struct server *serp ;
- X{
- X struct service *sp = SERVER_SERVICE( serp ) ;
- X char *func = "schedule_retry" ;
- X
- X if ( pset_add( RETRIES( ps ), serp ) == NULL )
- X {
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X svc_inc_retries( sp ) ;
- X start_retry_timer() ;
- X if ( debug.on )
- X msg( LOG_DEBUG, func, "Scheduled retry attempt for %s", SVC_ID( sp ) ) ;
- X return( OK ) ;
- X}
- X
- X
- X/*
- X * This function should not be called for servers that correspond to
- X * services not in the service table because server_release will result
- X * in releasing all memory associated with the service (since the ref
- X * count will drop to 0).
- X */
- XPRIVATE void cancel_retry( serp )
- X struct server *serp ;
- X{
- X struct service *sp = SERVER_SERVICE( serp ) ;
- X
- X conn_free( SERVER_CONNECTION( serp ) ) ;
- X svc_dec_retries( sp ) ;
- X server_release( serp ) ;
- X}
- X
- X
- X
- X/*
- X * Cancel all retry attempts for the specified service
- X */
- Xvoid cancel_service_retries( sp )
- X register struct service *sp ;
- X{
- X register unsigned u ;
- X char *func = "cancel_service_retries" ;
- X
- X if ( SVC_RETRIES( sp ) == 0 )
- X return ;
- X
- X u = 0 ;
- X while ( u < pset_count( RETRIES( ps ) ) )
- X {
- X register struct server *serp ;
- X
- X serp = SERP( pset_pointer( RETRIES( ps ), u ) ) ;
- X if ( SERVER_SERVICE( serp ) == sp )
- X {
- X msg( LOG_NOTICE, func,
- X "dropping retry attempt for service %s", SVC_ID( sp ) ) ;
- X cancel_retry( serp ) ;
- X pset_remove_index( RETRIES( ps ), u ) ;
- X continue ;
- X }
- X u++ ;
- X }
- X
- X if ( pset_count( RETRIES( ps ) ) == 0 )
- X stop_retry_timer() ;
- X}
- X
- X
- X#ifndef NO_TIMERS
- X
- X#include "timer.h"
- X
- Xstatic timer_h retry_timer ;
- X
- Xstatus_e create_retry_timer()
- X{
- X retry_timer = timer_create( TIMER_REAL, TIMER_RETURN_ERROR, INT_NULL ) ;
- X return( ( retry_timer == NULL ) ? FAILED : OK ) ;
- X}
- X
- X
- XPRIVATE void retry_action( tp, arg )
- X timer_h tp ;
- X void *arg ;
- X{
- X#ifdef lint
- X tp = tp ;
- X arg = arg ;
- X#endif
- X M_SET( ps.flags, RETRY_FLAG ) ;
- X}
- X
- X#endif /* ! NO_TIMERS */
- X
- X
- XPRIVATE void start_retry_timer()
- X{
- X /*
- X * The retry itimerval is set so that the timer expires every
- X * RETRY_INTERVAL seconds when it is enabled.
- X */
- X static struct itimerval itv =
- X {
- X { RETRY_INTERVAL, 0 },
- X { RETRY_INTERVAL, 0 }
- X } ;
- X char *func = "start_retry_timer" ;
- X
- X /*
- X * Enable timer if necessary.
- X */
- X
- X#ifndef NO_TIMERS
- X if ( ! retry_timer_running )
- X {
- X struct timer_action ta ;
- X
- X ta.ta_flags = TIMER_NOFLAGS ;
- X ta.ta_func = retry_action ;
- X ta.ta_arg = VOID_NULL ;
- X if ( timer_start( retry_timer, &itv, TIMER_RELATIVE, &ta ) == TIMER_ERR )
- X {
- X msg( LOG_ERR, func, "failed to start retry timer" ) ;
- X return ;
- X }
- X retry_timer_running = TRUE ;
- X }
- X#else
- X if ( ! retry_timer_running )
- X if ( setitimer( ITIMER_REAL, &itv, ITIMERVAL_NULL ) == -1 )
- X msg( LOG_ERR, func, "setitimer: %m" ) ;
- X else
- X retry_timer_running = TRUE ;
- X#endif
- X}
- X
- X
- XPRIVATE void stop_retry_timer()
- X{
- X if ( retry_timer_running )
- X {
- X#ifndef NO_TIMERS
- X timer_stop( retry_timer ) ;
- X#else
- X (void) setitimer( ITIMER_REAL, ITIMERVAL_NULL, ITIMERVAL_NULL ) ;
- X#endif
- X retry_timer_running = FALSE ;
- X }
- X}
- X
- END_OF_FILE
- if test 5411 -ne `wc -c <'xinetd/retry.c'`; then
- echo shar: \"'xinetd/retry.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/retry.c'
- fi
- echo shar: End of archive 12 \(of 31\).
- cp /dev/null ark12isdone
- MISSING=""
- 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
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 31 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-