home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-26 | 32.9 KB | 1,423 lines |
- Newsgroups: comp.sources.unix
- From: panos@cs.colorado.edu (Panos Tsirigotis)
- Subject: v26i252: xinetd-2.1.1 - inetd replacement with access control and logging, Part08/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 252
- Archive-Name: xinetd-2.1.1/part08
-
- #! /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 8 (of 31)."
- # Contents: libs/src/sio/suite/tester libs/src/timer/Makefile
- # libs/src/xlog/slog.c xinetd/defs.h xinetd/env.c xinetd/logctl.c
- # xinetd/util.c
- # Wrapped by panos@mystique on Mon Jun 21 14:51:22 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'libs/src/sio/suite/tester' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/suite/tester'\"
- else
- echo shar: Extracting \"'libs/src/sio/suite/tester'\" \(3971 characters\)
- sed "s/^X//" >'libs/src/sio/suite/tester' <<'END_OF_FILE'
- X#!/bin/sh
- 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# $Id: tester,v 8.2 1993/03/17 18:53:40 panos Exp $
- X#
- X
- X#
- X# Usage:
- X# tester [all] [function-name function-name ...]
- X#
- X# function-name is the name of a sio function (or macro)
- X#
- X# If "all" is used, functions after it will *not* be tested.
- X#
- X
- Xscript_name=`basename $0`
- X
- Xcopy_file=/usr/dict/words
- Xtemp_file=/tmp/w
- Xmake_log=MAKE.LOG
- X
- Xif test ! -f $copy_file ; then
- X echo "The file '$copy_file' is not available."
- X echo "Please edit the '$script_name' script and change set the"
- X echo "variable 'copy_file' to the name of a publicly readable file"
- X echo "with at least a few tens of thousands of lines."
- X exit 1
- Xfi
- X
- Xtrap_function()
- X{
- X rm -f $temp_file $make_log
- X echo
- X exit 1
- X}
- X
- X
- Xmake_program()
- X{
- X target=$1
- X cflags="$2"
- X if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
- X if test "$cflags"
- X then
- X make -s "$cflags" $target >$make_log 2>&1
- X else
- X make -s $target >$make_log 2>&1
- X fi
- X exit_code=$?
- X if test $exit_code -eq 0 -a -x $1
- X then
- X rm -f $make_log
- X else
- X echo "FAILED"
- X echo " The make failed. Check the make log file << $make_log >>"
- X exit
- X fi
- X}
- X
- X
- X
- X#
- X# test_function expects a single argument, the name of the function
- X# it will test.
- X# It creates a program that has the name of the function by invoking
- X# make with the symbol -DTEST_<function_name>
- X#
- Xtest_function()
- X{
- X expression="echo $"$1
- X var=`eval $expression`
- X if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
- X
- X echo -n "TESTING $1 "
- X make_program $1 "CFLAGS=-g -DTEST_$1"
- X
- X ./$1 < $copy_file >$temp_file
- X exit_code=$?
- X if test $exit_code -ne 0
- X then
- X echo "FAILED"
- X echo " Test program exited with exit code $exit_code"
- X echo " Temporary file << $temp_file >> not deleted"
- X exit
- X fi
- X cmp -s $copy_file $temp_file
- X if test $? -ne 0
- X then
- X echo "FAILED"
- X echo " The files << $copy_file >> and << $temp_file >> are not the same"
- X exit
- X else
- X echo PASSED
- X fi
- X rm -f $temp_file
- X}
- X
- X
- Xtest_sprint()
- X{
- X var=$Sprint
- X program=Sprint
- X if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
- X
- X echo TESTING Sprint
- X make_program $program ""
- X $TESTSHELL sprint_test
- X}
- X
- X
- Xtest_smorefds()
- X{
- X var=$Smorefds
- X program=fdtest
- X if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
- X
- X echo -n "TESTING Smorefds "
- X make_program $program "CFLAGS=-g"
- X v=`fdtest 2>&1`
- X if test $? -eq 0 ; then
- X echo PASSED
- X else
- X echo "FAILED: $v"
- X fi
- X}
- X
- X
- Xtrap trap_function 1 2 3 15
- X
- X#
- X# There is a variable for every function to be tested. That variable
- X# can have the values "yes", "no" or "".
- X# When a function is specified, it takes the value of $run. Initially $run
- X# is "yes", so a specified function has its variable set to "yes".
- X# If "all" is specified, $run becomes "no", so subsequently specified
- X# functions, have their variables set to "no".
- X#
- X# We test a function iff:
- X# its variable is "yes" OR its variable is "" and $all is "yes"
- X# We don't test a function iff:
- X# its variable is "no" OR its variable is "" and $all is "no"
- X#
- X# Therefore, all functions specified after "all" will NOT be tested.
- X#
- Xrun=yes
- Xall=no
- X
- Xwhile test $# -gt 0
- Xdo
- X case $1 in
- X Sputchar) Sputchar=$run ;;
- X Sgetchar) Sgetchar=$run ;;
- X Srdline) Srdline=$run ;;
- X Sfetch) Sfetch=$run ;;
- X Sread) Sread=$run ;;
- X Swrite) Swrite=$run ;;
- X Sgetc) Sgetc=$run ;;
- X Sputc) Sputc=$run ;;
- X Sflush) Sflush=$run ;;
- X Sundo) Sundo=$run ;;
- X Sprint) Sprint=$run ;;
- X switch) switch=$run ;;
- X switch2) switch2=$run ;;
- X Smorefds) Smorefds=$run ;;
- X all) all=yes ; run="no" ;;
- X *) echo Bad argument: $1
- X esac
- X shift
- Xdone
- X
- Xtest_function Sgetchar
- Xtest_function Sputchar
- Xtest_function Sread
- Xtest_function Swrite
- Xtest_function Srdline
- Xtest_function Sfetch
- Xtest_function Sgetc
- Xtest_function Sputc
- Xtest_function Sflush
- Xtest_function Sundo
- Xtest_function switch
- Xtest_function switch2
- Xtest_smorefds
- Xtest_sprint
- X
- END_OF_FILE
- if test 3971 -ne `wc -c <'libs/src/sio/suite/tester'`; then
- echo shar: \"'libs/src/sio/suite/tester'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/suite/tester'
- fi
- if test -f 'libs/src/timer/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/timer/Makefile'\"
- else
- echo shar: Extracting \"'libs/src/timer/Makefile'\" \(3929 characters\)
- sed "s/^X//" >'libs/src/timer/Makefile' <<'END_OF_FILE'
- X# (c) Copyright 1993 by Panagiotis Tsirigotis
- X# All rights reserved. The file named COPYRIGHT specifies the terms
- X# and conditions for redistribution.
- X
- X#
- X# $Id: Makefile,v 4.6 1993/06/20 20:05:28 panos Exp $
- X#
- X# Based on Library makefile template: *Revision: 1.15 *
- X#
- X
- X#
- X# Available entries:
- X# lib --> creates the library
- X# install --> installs the library (archive, man page(s), header(s))
- X# uninstall --> uninstall the library
- X# clean --> removes all .o and .a files
- X# spotless --> clean + uninstall
- X# lint --> lints a file (usage: make lint MODULE=foo.c)
- X# tags --> creates a tags file (from the SOURCES and HEADERS)
- X# checkout --> checkout all files
- X# dist --> distribution support
- X#
- X
- XNAME = timer
- XVERSION = 1.2.2
- X
- XHEADERS = timer.h impl.h ostimer.h timemacros.h defs.h
- XSOURCES = timer.c ostimer.c sysdep.c
- XOBJECTS = timer.o ostimer.o sysdep.o
- X
- XMANFILES = timer.3 timemacros.3
- XINCLUDEFILES = timer.h timemacros.h
- X
- X# The following variables are used by the 'install' entry and
- X# should be customized:
- X# LIBDIR: where the library will be placed
- X# INCUDEDIR: where the include files will be placed
- X# MANDIR: where the man pages will be placed
- X#
- XLIBDIR = $(HOME)/.links/libraries/$(ARCH)
- XMANDIR = $(HOME)/.links/manpages/man3
- XINCLUDEDIR = $(HOME)/.links/includes
- X
- X#
- X# Available flags:
- X#
- X# DEBUG : enable some debugging code
- X# NO_TERMINATION : do not terminate if an error is discovered
- X# DEBUG_MSGS : print debugging messages
- X# NO_POSIX_SIGS : sigaction is not available (but sigvec is)
- X#
- XDEFS = -DDEBUG -DNO_POSIX_SIGS
- XDEBUG = -g # -g or -O
- XVERSION_DEF = -DVERSION=\"TIMER\ Version\ $(VERSION)\"
- X
- XCPP_DEFS = -I$(INCLUDEDIR) $(VERSION_DEF) $(DEFS)
- X
- X#
- X# The following variables shouldn't need to be changed
- X#
- XLINT_FLAGS = -hbux
- XCPP_FLAGS = $(CPP_DEFS) -I$(INCLUDEDIR)
- XCC_FLAGS = $(DEBUG)
- XCFLAGS = $(CPP_FLAGS) $(CC_FLAGS)
- X
- XINSTALL = install -c
- XFMODE = -m 640 # used by install
- XRANLIB = ranlib
- X
- XPAGER = less
- X
- X
- XLIBNAME = lib$(NAME).a
- X
- Xlib: $(LIBNAME)
- X
- Xlibopt: clean
- X make DEBUG=-O lib
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)/optimized
- X
- X$(LIBNAME): $(OBJECTS)
- X ar r $@ $?
- X $(RANLIB) $@
- X
- Xlint:
- X lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | $(PAGER)
- X
- Xinstall: $(LIBNAME)
- X @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
- X then \
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
- X echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
- X for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
- X echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
- X for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
- X echo Installed $(MANFILES) to $(MANDIR) ;\
- X else \
- X echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
- X fi
- X
- Xuninstall:
- X a=`pwd` ; cd $(INCLUDEDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
- X a=`pwd` ; cd $(LIBDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
- X a=`pwd` ; cd $(MANDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
- X
- Xclean:
- X rm -f $(OBJECTS) $(LIBNAME) core
- X
- Xspotless: clean uninstall
- X
- Xtags: $(SOURCES) $(HEADERS)
- X ctags -w $(SOURCES) $(HEADERS)
- X
- Xcheckout:
- X co $(SOURCES) $(HEADERS) $(MANFILES)
- X
- X#
- X# Distribution section
- X# This section contains the 2 targets for distribution support: dist, dirs
- X# "dist" checks out all files to be distributed
- X# "dirs" prints a list of directories to be included in the distribution.
- X# These directories should have a Makefile with a "dist" target
- X#
- XDISTRIBUTION_FILES = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT
- XDIRS =
- X
- Xdist:
- X -co -q $(DISTRIBUTION_FILES)
- X
- Xdirs:
- X @echo $(DIRS)
- X
- X#
- X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
- X#
- Xtimer.o: timemacros.h impl.h timer.h defs.h
- Xostimer.o: ostimer.h timemacros.h impl.h timer.h defs.h
- Xsysdep.o: ostimer.h timemacros.h impl.h timer.h defs.h
- X
- Xttest: ttest.c $(LIBNAME)
- X cc $(DEBUG) -o $@ ttest.c $(LIBNAME) -L$(LIBDIR) -lpq
- X
- END_OF_FILE
- if test 3929 -ne `wc -c <'libs/src/timer/Makefile'`; then
- echo shar: \"'libs/src/timer/Makefile'\" unpacked with wrong size!
- fi
- # end of 'libs/src/timer/Makefile'
- fi
- if test -f 'libs/src/xlog/slog.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/xlog/slog.c'\"
- else
- echo shar: Extracting \"'libs/src/xlog/slog.c'\" \(3955 characters\)
- sed "s/^X//" >'libs/src/xlog/slog.c' <<'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
- Xstatic char RCSid[] = "$Id: slog.c,v 2.2 1993/06/15 18:08:16 panos Exp $" ;
- X
- X#ifndef NO_SYSLOG
- X#include <syslog.h>
- X#endif
- X#include <varargs.h>
- X
- X#include "xlog.h"
- X#include "impl.h"
- X#include "slog.h"
- X
- X#define MSGBUFSIZE 2048
- X
- X
- XPRIVATE int syslog_init() ;
- XPRIVATE void syslog_fini() ;
- XPRIVATE int syslog_control() ;
- XPRIVATE int syslog_write() ;
- XPRIVATE int syslog_parms() ;
- X
- Xstatic struct syslog_parms parms =
- X {
- X 0,
- X#ifndef NO_SYSLOG
- X LOG_PID + LOG_NOWAIT,
- X LOG_USER,
- X#else
- X 0,
- X 0,
- X#endif
- X "XLOG",
- X FALSE
- X } ;
- X
- X
- Xstruct xlog_ops __xlog_syslog_ops =
- X {
- X syslog_init,
- X syslog_fini,
- X syslog_write,
- X syslog_control,
- X syslog_parms
- X } ;
- X
- X#ifdef NO_SYSLOG
- X
- X/*
- X * Notice that the following functions will never be invoked since
- X * the xlog_* functions will not call them. However, we need to define
- X * them so that we don't have any unresolved references; and we define
- X * them without any arguments.
- X */
- XPRIVATE void syslog()
- X{
- X}
- X
- XPRIVATE void openlog()
- X{
- X}
- X
- XPRIVATE void closelog()
- X{
- X}
- X
- X#else
- X
- Xvoid closelog() ;
- X
- X#endif /* NO_SYSLOG */
- X
- X
- X/*
- X * Expected arguments:
- X * facility, level
- X */
- XPRIVATE int syslog_init( xp, ap )
- X xlog_s *xp ;
- X va_list ap ;
- X{
- X register struct syslog_parms *slp = &parms ;
- X struct syslog *sp ;
- X
- X sp = NEW( struct syslog ) ;
- X if ( sp == NULL )
- X return( XLOG_ENOMEM ) ;
- X
- X sp->sl_facility = va_arg( ap, int ) ;
- X sp->sl_default_level = va_arg( ap, int ) ;
- X if ( slp->slp_n_xlogs++ == 0 )
- X openlog( slp->slp_ident, slp->slp_logopts, slp->slp_facility ) ;
- X xp->xl_data = sp ;
- X return( XLOG_ENOERROR ) ;
- X}
- X
- X
- XPRIVATE void syslog_fini( xp )
- X xlog_s *xp ;
- X{
- X if ( --parms.slp_n_xlogs == 0 )
- X closelog() ;
- X FREE( SYSLOG( xp ) ) ;
- X xp->xl_data = NULL ;
- X}
- X
- X
- XPRIVATE int syslog_control( xp, cmd, ap )
- X xlog_s *xp ;
- X xlog_cmd_e cmd ;
- X va_list ap ;
- X{
- X switch ( cmd )
- X {
- X case XLOG_LEVEL:
- X SYSLOG( xp )->sl_default_level = va_arg( ap, int ) ;
- X break ;
- X
- X case XLOG_FACILITY:
- X SYSLOG( xp )->sl_facility = va_arg( ap, int ) ;
- X break ;
- X
- X case XLOG_PREEXEC:
- X closelog() ;
- X break ;
- X
- X case XLOG_POSTEXEC:
- X if ( parms.slp_n_xlogs )
- X openlog( parms.slp_ident, parms.slp_logopts, parms.slp_facility ) ;
- X break ;
- X }
- X return( XLOG_ENOERROR ) ;
- X}
- X
- X
- XPRIVATE int syslog_write( xp, buf, len, flags, ap )
- X xlog_s *xp ;
- X char buf[] ;
- X int len ;
- X int flags ;
- X va_list ap ;
- X{
- X int level ;
- X int syslog_arg ;
- X char prefix[ MSGBUFSIZE ] ;
- X int prefix_size = sizeof( prefix ) ;
- X int prefix_len = 0 ;
- X int cc ;
- X char *percent_m_pos ;
- X int action_flags = ( flags | xp->xl_flags ) ;
- X
- X if ( flags & XLOG_SET_LEVEL )
- X level = va_arg( ap, int ) ;
- X else
- X level = SYSLOG( xp )->sl_default_level ;
- X syslog_arg = SYSLOG( xp )->sl_facility + level ;
- X
- X if ( action_flags & XLOG_PRINT_ID )
- X {
- X cc = strx_nprint( &prefix[ prefix_len ], prefix_size, "%s: ",
- X xp->xl_id ) ;
- X prefix_len += cc ;
- X prefix_size -= cc ;
- X }
- X
- X if ( ( action_flags & XLOG_NO_ERRNO ) ||
- X ( percent_m_pos = __xlog_add_errno( buf, len ) ) == NULL )
- X syslog( syslog_arg, "%.*s%.*s", prefix_len, prefix, len, buf ) ;
- X else
- X {
- X int cc_before_errno = percent_m_pos - buf ;
- X int cc_after_errno = len - cc_before_errno - 2 ;
- X char *ep ;
- X char errno_buf[ 100 ] ;
- X unsigned size = sizeof( errno_buf ) ;
- X
- X ep = __xlog_explain_errno( errno_buf, &size ) ;
- X syslog( syslog_arg, "%.*s%.*s%.*s%.*s",
- X prefix_len, prefix,
- X cc_before_errno, buf,
- X (int)size, ep,
- X cc_after_errno, &percent_m_pos[ 2 ] ) ;
- X }
- X return( XLOG_ENOERROR ) ;
- X}
- X
- X
- XPRIVATE int syslog_parms( ap )
- X va_list ap ;
- X{
- X char *__xlog_new_string() ;
- X char *id = __xlog_new_string( va_arg( ap, char * ) ) ;
- X
- X if ( id == NULL )
- X return( XLOG_ENOMEM ) ;
- X parms.slp_ident = id ;
- X parms.slp_logopts = va_arg( ap, int ) ;
- X parms.slp_facility = va_arg( ap, int ) ;
- X return( XLOG_ENOERROR ) ;
- X}
- X
- END_OF_FILE
- if test 3955 -ne `wc -c <'libs/src/xlog/slog.c'`; then
- echo shar: \"'libs/src/xlog/slog.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/xlog/slog.c'
- fi
- if test -f 'xinetd/defs.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/defs.h'\"
- else
- echo shar: Extracting \"'xinetd/defs.h'\" \(4102 characters\)
- sed "s/^X//" >'xinetd/defs.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 DEFS_H
- X#define DEFS_H
- X
- X/*
- X * $Id: defs.h,v 6.5 1993/06/13 01:43:06 panos Exp $
- X */
- X
- X#include <memory.h>
- X
- X#ifndef IPPROTO_TCP
- X#define IPPROTO_TCP 6
- X#endif
- X
- X#ifndef NULL
- X#define NULL 0
- X#endif
- X
- X#ifndef FALSE
- X#define FALSE 0
- X#define TRUE 1
- X#endif
- X
- X#define NUL '\0'
- X
- X#define ES_NOMEM "out of memory"
- X
- X#define INT_NULL ((int *)0)
- X#define CHAR_NULL ((char *)0)
- X#define VOID_NULL ((void *)0)
- X#define FD_SET_NULL ((fd_set *)0)
- X#define RUSAGE_NULL ((struct rusage *)0)
- X#define TIMEVAL_NULL ((struct timeval *)0)
- X#define ITIMERVAL_NULL ((struct itimerval *)0)
- X#define SOCKADDRIN_NULL ((struct sockaddr_in *)0)
- X
- X#define PRIVATE static
- X
- X#define EQ( s1, s2 ) ( strcmp( s1, s2 ) == 0 )
- X#define CLEAR( x ) (void) memset( (char *)&(x), 0, sizeof( x ) )
- X#define SA( p ) ( (struct sockaddr *) (p) )
- X#define NEW( type ) (type *) malloc( sizeof( type ) )
- X#define FREE( p ) (void) free( (char *)(p) )
- X
- X/*
- X * Value for unlimited server instances
- X */
- X#define UNLIMITED (-1)
- X
- X/*
- X * We pass to the child the descriptors 0..MAX_PASS_FD
- X */
- X#define MAX_PASS_FD 2
- X
- X/*
- X * Service port for the identification service
- X */
- X#define IDENTITY_SERVICE_PORT 113
- X
- X/*
- X * This is the signal sent to interceptor processes to tell them
- X * to stop intercepting
- X */
- X#define INTERCEPT_SIG SIGUSR1
- X
- X/*
- X * This is how many descriptors we reserve for ourselves:
- X *
- X * 3 for stdin, stdout, stderr
- X * 1 for syslog/debug
- X *
- X * For the rest we just need to reserve the maximum of each category.
- X *
- X * 1 for doing accepts
- X * 1 for registering rpc services (initialization phase)
- X * 4 for reading the configuration file during reconfiguration
- X * 1 for the configuration file
- X * 1 for /etc/passwd
- X * 1 for /etc/group
- X * 1 for /etc/services, /etc/protocols, /etc/rpc
- X * NOTE: We need only 1 descriptor for the last 3 files because
- X * the functions get{serv,proto,rpc}byname close the
- X * respective files after accessing them.
- X * 1 for dumping the internal state
- X * 1 for talking to the portmapper (reconfiguration phase)
- X * 1 for doing identification
- X *
- X * NOTE: we assume that the socket used for pmap_{set,unset} is closed
- X * after the operation is completed. If it stays open, then we
- X * need to increase DESCRIPTORS_RESERVED.
- X */
- X#define DESCRIPTORS_RESERVED 8
- X
- X/*
- X * Used for listen(2)
- X */
- X#define LISTEN_BACKLOG 7
- X
- X/*
- X * When explicit values are given for enum's, that is because the structures
- X * that the enum's are in may be initialized by a memory clear operation.
- X */
- X
- Xtypedef enum { FAILED = 0, OK } status_e ;
- Xtypedef enum { NO = 0, YES } boolean_e ;
- X
- X/*
- X * Possible outcomes of an identification attempt
- X */
- Xtypedef enum
- X {
- X IDR_OK,
- X IDR_NOSERVER,
- X IDR_TIMEDOUT,
- X IDR_RESPERR,
- X IDR_BADRESP,
- X IDR_ERROR
- X } idresult_e ;
- X
- Xtypedef int bool_int ;
- X
- Xtypedef void (*voidfunc)() ;
- Xtypedef status_e (*statfunc)() ;
- X
- X
- X/*
- X * A name-value list is exactly what its name says.
- X * The functions nv_get_name() and nv_get_value() return a pointer to
- X * the entry with the specified value or name respectively.
- X * The list ends when an antry with a NULL name is encountered.
- X * The value field of that entry is treated in a special manner: if it
- X * is non-zero, it is assumed that there exists one more entry whose
- X * name field will be returned by the nv_get_name function if it can't
- X * find an entry whose value field is equal to its 2nd parameter.
- X * If the value field of the NULL entry is 0, then nv_get_name() will
- X * return NULL.
- X */
- Xstruct name_value
- X{
- X char *name ;
- X int value ;
- X} ;
- X
- Xstruct name_value *nv_find_value( /* struct name_value [], char *name */ ) ;
- Xstruct name_value *nv_find_name( /* struct name_value [], int value */ ) ;
- Xchar *nv_get_name( /* struct name_value [], int value */ ) ;
- X
- X
- Xstruct debug
- X{
- X bool_int on ;
- X int fd ;
- X} ;
- X
- Xextern struct debug debug ;
- X
- X#endif /* DEFS_H */
- END_OF_FILE
- if test 4102 -ne `wc -c <'xinetd/defs.h'`; then
- echo shar: \"'xinetd/defs.h'\" unpacked with wrong size!
- fi
- # end of 'xinetd/defs.h'
- fi
- if test -f 'xinetd/env.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/env.c'\"
- else
- echo shar: Extracting \"'xinetd/env.c'\" \(4000 characters\)
- sed "s/^X//" >'xinetd/env.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: env.c,v 6.3 1993/06/06 00:09:15 panos Exp $" ;
- X
- X#include <syslog.h>
- X#include <string.h>
- X
- X#include "misc.h"
- X
- X#include "attr.h"
- X#include "defs.h"
- X#include "sconf.h"
- X
- Xvoid msg() ;
- Xvoid out_of_memory() ;
- X
- Xextern char **environ ;
- X
- Xenv_h std_env ; /* created from environ */
- X
- X
- Xstatus_e initenv()
- X{
- X std_env = env_make( environ ) ;
- X return( ( std_env == NULL ) ? FAILED : OK ) ;
- X}
- X
- XPRIVATE status_e make_env_with_strings() ;
- XPRIVATE status_e make_env_from_vars() ;
- XPRIVATE status_e update_env_with_strings() ;
- X
- X
- Xstatus_e setup_environ( scp, def )
- X struct service_config *scp ;
- X struct service_config *def ;
- X{
- X struct environment *ep = SC_ENV( scp ) ;
- X
- X if ( ! SC_SPECIFIED( scp, A_PASSENV ) )
- X {
- X if ( ! SC_SPECIFIED( def, A_PASSENV ) )
- X {
- X if ( ! SC_SPECIFIED( scp, A_ENV ) )
- X {
- X ep->env_type = STD_ENV ;
- X ep->env_handle = std_env ;
- X return( OK ) ;
- X }
- X else
- X return(
- X make_env_with_strings( ep, std_env, scp->sc_env_var_defs ) ) ;
- X }
- X else /* SC_SPECIFIED( def, A_PASSENV ) */
- X {
- X struct environment *dep = SC_ENV( def ) ;
- X
- X if ( dep->env_type == NO_ENV &&
- X make_env_from_vars( dep, std_env,
- X def->sc_pass_env_vars ) == FAILED )
- X return( FAILED ) ;
- X
- X if ( ! SC_SPECIFIED( scp, A_ENV ) )
- X {
- X ep->env_type = DEF_ENV ;
- X ep->env_handle = dep->env_handle ;
- X return( OK ) ;
- X }
- X else
- X return( make_env_with_strings( ep,
- X dep->env_handle, scp->sc_env_var_defs ) ) ;
- X }
- X }
- X else /* SC_SPECIFIED( scp, A_PASSENV ) */
- X {
- X if ( make_env_from_vars( ep, std_env, scp->sc_pass_env_vars ) == FAILED )
- X return( FAILED ) ;
- X
- X if ( ! SC_SPECIFIED( scp, A_ENV ) )
- X return( OK ) ;
- X else
- X {
- X if ( update_env_with_strings(
- X ep->env_handle, scp->sc_env_var_defs ) == FAILED )
- X {
- X env_destroy( ep->env_handle ) ;
- X return( FAILED ) ;
- X }
- X return( OK ) ;
- X }
- X }
- X}
- X
- X
- X/*
- X * Create a new environment from environ and env_strings
- X * env_strings contains strings of the form "var=value"
- X */
- XPRIVATE status_e make_env_with_strings( ep, env, env_strings )
- X struct environment *ep ;
- X env_h env ;
- X pset_h env_strings ;
- X{
- X env_h new_env ;
- X char *func = "make_env_with_strings" ;
- X
- X if ( ( new_env = env_create( env ) ) == ENV_NULL )
- X {
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X
- X if ( update_env_with_strings( new_env, env_strings ) == FAILED )
- X {
- X env_destroy( new_env ) ;
- X return( FAILED ) ;
- X }
- X
- X ep->env_type = CUSTOM_ENV ;
- X ep->env_handle = new_env ;
- X return( OK ) ;
- X}
- X
- X
- XPRIVATE status_e make_env_from_vars( ep, env, vars )
- X struct environment *ep ;
- X env_h env ;
- X pset_h vars ;
- X{
- X env_h new_env ;
- X char *varname ;
- X register unsigned u ;
- X char *func = "make_env_from_vars" ;
- X
- X if ( ( new_env = env_create( ENV_NULL ) ) == ENV_NULL )
- X {
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X
- X for ( u = 0 ; u < pset_count( vars ) ; u++ )
- X {
- X varname = (char *) pset_pointer( vars, u ) ;
- X if ( env_addvar( new_env, env, varname ) == ENV_ERR )
- X switch ( env_errno )
- X {
- X case ENV_EBADVAR:
- X msg( LOG_ERR, func, "Unknown variable %s", varname ) ;
- X break ;
- X
- X case ENV_ENOMEM:
- X out_of_memory( func ) ;
- X env_destroy( new_env ) ;
- X return( FAILED ) ;
- X }
- X }
- X
- X ep->env_type = CUSTOM_ENV ;
- X ep->env_handle = new_env ;
- X return( OK ) ;
- X}
- X
- X
- XPRIVATE status_e update_env_with_strings( env, strings )
- X env_h env ;
- X pset_h strings ;
- X{
- X register unsigned u ;
- X char *func = "update_env_with_strings" ;
- X
- X for ( u = 0 ; u < pset_count( strings ) ; u++ )
- X {
- X char *p = (char *) pset_pointer( strings, u ) ;
- X
- X if ( env_addstr( env, p ) == ENV_ERR )
- X switch ( env_errno )
- X {
- X case ENV_ENOMEM:
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X
- X case ENV_EBADSTRING:
- X msg( LOG_ERR, func, "Bad environment string: %s\n", p ) ;
- X break ;
- X }
- X }
- X return( OK ) ;
- X}
- X
- END_OF_FILE
- if test 4000 -ne `wc -c <'xinetd/env.c'`; then
- echo shar: \"'xinetd/env.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/env.c'
- fi
- if test -f 'xinetd/logctl.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/logctl.c'\"
- else
- echo shar: Extracting \"'xinetd/logctl.c'\" \(4125 characters\)
- sed "s/^X//" >'xinetd/logctl.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: logctl.c,v 6.6 1993/06/15 23:25:57 panos Exp $" ;
- X
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <syslog.h>
- X#include <fcntl.h>
- X
- X#include "sio.h"
- X#include "xlog.h"
- X
- X#include "config.h"
- X#include "state.h"
- X#include "defs.h"
- X#include "log.h"
- X#include "service.h"
- X
- Xvoid msg() ;
- X
- X
- X
- XPRIVATE xlog_h start_filelog( id, flp )
- X char *id ;
- X struct filelog *flp ;
- X{
- X xlog_h xh ;
- X int fd ;
- X int log_file_mode = ( debug.on ) ? 0644 : LOG_FILE_MODE ;
- X char *func = "start_filelog" ;
- X
- X xh = xlog_create( XLOG_FILELOG, id, XLOG_NOFLAGS,
- X flp->fl_filename, LOG_OPEN_FLAGS, log_file_mode ) ;
- X if ( xh == NULL )
- X {
- X msg( LOG_ERR, func, "creation of %s log failed", id ) ;
- X return( NULL ) ;
- X }
- X
- X if ( xlog_control( xh, XLOG_GETFD, &fd ) != XLOG_ENOERROR ||
- X fcntl( fd, F_SETFD, 1 ) == -1 )
- X {
- X msg( LOG_ERR, func, "Failed to set close-on-exec flag for log file" ) ;
- X xlog_destroy( xh ) ;
- X return( NULL ) ;
- X }
- X
- X ps.rws.descriptors_free-- ;
- X
- X if ( FILELOG_SIZE_CONTROL( flp ) )
- X (void) xlog_control( xh,
- X XLOG_LIMITS, flp->fl_soft_limit, flp->fl_hard_limit ) ;
- X
- X return( xh ) ;
- X}
- X
- X
- X/*
- X * This function is invoked when a xlog detects an error (for example,
- X * exceeding the file size limit).
- X * The function just enters a log message.
- X *
- X * NOTE: We could destroy the xlog at this point but we choose not to.
- X */
- XPRIVATE void log_in_error( xh, error_code, arg )
- X xlog_h xh ;
- X int error_code ;
- X void *arg ;
- X{
- X struct service *sp = SP( arg ) ;
- X char *log_id = ( sp == NULL ) ? "common" : SVC_ID( sp ) ;
- X char *func = "log_in_error" ;
- X
- X#ifdef lint
- X xh = xh ;
- X#endif
- X if ( error_code == XLOG_ESIZE )
- X msg( LOG_ERR, func, "Size of %s log exceeded hard limit", log_id ) ;
- X else
- X msg( LOG_ERR, func, "Error in %s log: %d", log_id, error_code ) ;
- X}
- X
- X/*
- X * Start logging for the specified service.
- X * The current configuration is used to determine the common log file.
- X */
- Xstatus_e log_start( sp, xhp )
- X struct service *sp ;
- X xlog_h *xhp ;
- X{
- X xlog_h xh ;
- X char *sid = SVC_ID( sp ) ;
- X struct log *lp = SC_LOG( SVC_CONF( sp ) ) ;
- X char *func = "log_start" ;
- X
- X switch ( lp->l_type )
- X {
- X case L_NONE:
- X xh = NULL ;
- X break ;
- X
- X case L_SYSLOG:
- X xh = xlog_create( XLOG_SYSLOG, sid, XLOG_NOFLAGS,
- X log_syslog( lp )->sl_facility, log_syslog( lp )->sl_level ) ;
- X if ( xh == NULL )
- X {
- X msg( LOG_ERR, func, "failed to create a log for service %s", sid ) ;
- X return( FAILED ) ;
- X }
- X xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ;
- X break ;
- X
- X case L_FILE:
- X /*
- X * NOTE: if the same file is specified for more than one service,
- X * it will be opened as many times.
- X * Furthermore, size control will not be accurate.
- X */
- X xh = start_filelog( sid, log_filelog( lp ) ) ;
- X if ( xh == NULL )
- X return( FAILED ) ;
- X (void) xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ;
- X break ;
- X
- X case L_COMMON_FILE:
- X if ( DEFAULT_LOG( ps ) == NULL )
- X if ( DEFAULT_LOG_ERROR( ps ) )
- X return( FAILED ) ;
- X else
- X {
- X xh = start_filelog( "default",
- X log_filelog( SC_LOG( DEFAULTS( ps ) ) ) ) ;
- X if ( xh == NULL )
- X {
- X DEFAULT_LOG_ERROR( ps ) = TRUE ;
- X return( FAILED ) ;
- X }
- X DEFAULT_LOG( ps ) = xh ;
- X (void) xlog_control( xh,
- X XLOG_CALLBACK, log_in_error, VOID_NULL ) ;
- X }
- X else
- X xh = DEFAULT_LOG( ps ) ;
- X break ;
- X
- X default: /* SHOULDN'T HAPPEN */
- X msg( LOG_ERR, func, "bad log type (%d) for service %s",
- X (int) log_get_type( lp ), sid ) ;
- X return( FAILED ) ;
- X }
- X *xhp = xh ;
- X return( OK ) ;
- X}
- X
- X
- Xvoid log_end( lp, xh )
- X struct log *lp ;
- X xlog_h xh ;
- X{
- X char *func = "log_end" ;
- X
- X if ( xh == NULL ) /* shouldn't be NULL but just in case */
- X {
- X msg( LOG_NOTICE, func, "%s called with NULL handle", func ) ;
- X return ;
- X }
- X
- X switch ( log_get_type( lp ) )
- X {
- X case L_FILE:
- X ps.rws.descriptors_free++ ;
- X /* FALL THROUGH */
- X
- X case L_SYSLOG:
- X xlog_destroy( xh ) ;
- X }
- X}
- X
- END_OF_FILE
- if test 4125 -ne `wc -c <'xinetd/logctl.c'`; then
- echo shar: \"'xinetd/logctl.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/logctl.c'
- fi
- if test -f 'xinetd/util.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/util.c'\"
- else
- echo shar: Extracting \"'xinetd/util.c'\" \(3951 characters\)
- sed "s/^X//" >'xinetd/util.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: util.c,v 6.5 1993/06/13 01:47:02 panos Exp $" ;
- X
- X#include <sys/types.h>
- X/*
- X * The following ifdef is for TIOCNOTTY
- X */
- X#ifndef NO_TERMIOS
- X#include <sys/termios.h>
- X#else
- X#include <sys/ioctl.h>
- X#endif
- X#include <fcntl.h>
- X
- X#include <memory.h>
- X#include <syslog.h>
- X#include <errno.h>
- X#include <varargs.h>
- X
- X#include "pset.h"
- X#include "misc.h"
- X#include "sio.h"
- X
- X#include "defs.h"
- X#include "config.h"
- X
- Xchar *malloc() ;
- X
- Xvoid msg() ;
- X
- X
- Xvoid out_of_memory( func )
- X char *func ;
- X{
- X msg( LOG_CRIT, func, ES_NOMEM ) ;
- X}
- X
- X
- Xstruct name_value *nv_find_value( nv_array, name )
- X struct name_value nv_array[] ;
- X register char *name ;
- X{
- X register struct name_value *nvp ;
- X
- X for ( nvp = nv_array ; nvp->name ; nvp++ )
- X if ( EQ( name, nvp->name ) )
- X return( nvp ) ;
- X return( NULL ) ;
- X}
- X
- X
- Xstruct name_value *nv_find_name( nv_array, value )
- X struct name_value nv_array[] ;
- X register int value ;
- X{
- X register struct name_value *nvp ;
- X
- X for ( nvp = nv_array ; nvp->name ; nvp++ )
- X if ( value == nvp->value )
- X return( nvp ) ;
- X return( NULL ) ;
- X}
- X
- X
- Xchar *nv_get_name( nv_array, value )
- X struct name_value nv_array[] ;
- X register int value ;
- X{
- X register struct name_value *nvp ;
- X
- X for ( nvp = nv_array ; nvp->name ; nvp++ )
- X if ( value == nvp->value )
- X return( nvp->name ) ;
- X return( nvp->value ? nvp[1].name : NULL ) ;
- X}
- X
- X
- X
- Xchar **argv_alloc( count )
- X unsigned count ;
- X{
- X unsigned argv_size = (count + 1) * sizeof( char *) ;
- X char **argv ;
- X char *func = "new_argv" ;
- X
- X argv = (char **) malloc( argv_size ) ;
- X if ( argv == NULL )
- X {
- X out_of_memory( func ) ;
- X return( NULL ) ;
- X }
- X (void) memset( (char *)argv, 0, (int) argv_size ) ;
- X return( argv ) ;
- X}
- X
- X
- X
- X/*
- X * If size is 0, the pset holds strings
- X */
- Xstatus_e copy_pset( from, to, size )
- X pset_h from ;
- X pset_h *to ;
- X unsigned size ;
- X{
- X unsigned u ;
- X char *func = "copy_pset" ;
- X
- X if ( *to == NULL )
- X {
- X *to = pset_create( pset_count( from ), 0 ) ;
- X if ( *to == NULL )
- X {
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X }
- X
- X for ( u = 0 ; u < pset_count( from ) ; u++ )
- X {
- X char *p = (char *) pset_pointer( from, u ) ;
- X char *new ;
- X
- X if ( size == 0 )
- X new = make_string( 1, p ) ;
- X else
- X new = malloc( size ) ;
- X
- X if ( new == NULL )
- X {
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X
- X if ( size != 0 )
- X (void) memcpy( new, p, (int) size ) ;
- X
- X if ( pset_add( *to, new ) == NULL )
- X {
- X free( new ) ;
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X }
- X return( OK ) ;
- X}
- X
- X
- X/*
- X * Disassociate from controlling terminal
- X */
- Xvoid no_control_tty()
- X{
- X int fd ;
- X char *func = "no_control_tty" ;
- X
- X if ( ( fd = open( "/dev/tty", O_RDWR ) ) == -1 )
- X msg( LOG_WARNING, func, "open of /dev/tty failed: %m" ) ;
- X else
- X {
- X if ( ioctl( fd, TIOCNOTTY, (caddr_t)0 ) == -1 )
- X msg( LOG_WARNING, func, "ioctl on /dev/tty failed: %m" ) ;
- X (void) close( fd ) ;
- X }
- X (void) setpgrp( getpid(), 0 ) ;
- X}
- X
- X
- X/*
- X * Write the whole buffer to the given file descriptor ignoring interrupts
- X */
- Xstatus_e write_buf( fd, buf, len )
- X int fd ;
- X char *buf ;
- X int len ;
- X{
- X register char *p ;
- X register int cc ;
- X
- X for ( p = buf ; len > 0 ; p += cc, len -= cc )
- X {
- X cc = write( fd, p, len ) ;
- X if ( cc == -1 )
- X {
- X if ( errno != EINTR )
- X return( FAILED ) ;
- X cc = 0 ;
- X }
- X }
- X return( OK ) ;
- X}
- X
- X
- Xvoid tabprint( fd, tab_level, fmt, va_alist )
- X int fd ;
- X int tab_level ;
- X char *fmt ;
- X va_dcl
- X{
- X va_list ap ;
- X int i ;
- X
- X for ( i = 0 ; i < tab_level ; i++ )
- X Sputchar( fd, '\t' ) ;
- X
- X va_start( ap ) ;
- X Sprintv( fd, fmt, ap ) ;
- X va_end( ap ) ;
- X}
- X
- X
- X/*
- X * Receive a single IP packet worth of data.
- X */
- Xvoid drain( sd )
- X int sd ;
- X{
- X char buf[ 1 ] ;
- X char cc ;
- X
- X cc = recv( sd, buf, sizeof( buf ), 0 ) ;
- X if ( cc == -1 )
- X msg( LOG_WARNING, "drain", "recv: %m" ) ;
- X}
- X
- END_OF_FILE
- if test 3951 -ne `wc -c <'xinetd/util.c'`; then
- echo shar: \"'xinetd/util.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/util.c'
- fi
- echo shar: End of archive 8 \(of 31\).
- cp /dev/null ark8isdone
- 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
-