home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-26 | 32.2 KB | 1,414 lines |
- Newsgroups: comp.sources.unix
- From: panos@cs.colorado.edu (Panos Tsirigotis)
- Subject: v26i254: xinetd-2.1.1 - inetd replacement with access control and logging, Part10/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 254
- Archive-Name: xinetd-2.1.1/part10
-
- #! /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 10 (of 31)."
- # Contents: libs/src/str/Makefile libs/src/str/strparse.c
- # libs/src/xlog/xlog.c xinetd/conf.c xinetd/msg.c xinetd/special.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/str/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/Makefile'\"
- else
- echo shar: Extracting \"'libs/src/str/Makefile'\" \(4534 characters\)
- sed "s/^X//" >'libs/src/str/Makefile' <<'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#
- X# $Id: Makefile,v 3.2 1993/06/16 00:06:57 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 = str
- XVERSION = 1.4.1
- X
- XHEADERS = str.h strparse.h \
- X ss_impl.h ss_rk.h ss_kmp.h ss_sbm.h ss_bmh.h ss_so.h
- XSOURCES = strutil.c strprint.c strparse.c strs.c \
- X ss_rk.c ss_kmp.c ss_bf.c ss_sbm.c ss_bmh.c ss_so.c
- XOBJECTS = strutil.o strprint.o strparse.o strs.o \
- X ss_rk.o ss_kmp.o ss_bf.o ss_sbm.o ss_bmh.o ss_so.o
- X
- XMANFILES = strparse.3 strprint.3 strutil.3 strs.3
- XINCLUDEFILES = str.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# NBIC : number of bits in a character variable (defaults to 8)
- X# WIDE_INT : widest integer supported by the CPU/compiler
- X# (defaults to 'long')
- X# WIDE_INT_SIZE : size of the WIDE_INT type in bits (defaults to 32);
- X# effective (and required) only when WIDE_INT is defined
- X# NO_SIO : if the SIO library is not available (results in turning
- X# all the string printing functions to no-ops)
- X#
- XDEFS = # for example, -DNO_SIO
- XDEBUG = -g # -g or -O
- XVERSION_DEF = -DVERSION=\"STR\ Version\ $(VERSION)\"
- X
- XCPP_DEFS = $(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 "DEFS=$(DEFS)" lib
- X $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)-O
- X
- X$(LIBNAME): $(OBJECTS)
- X ar r $@ $?
- X $(RANLIB) $@
- X
- XLINT_IGNORE=possible pointer alignment|RCSid unused
- X
- Xlint:
- X lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | egrep -v '$(LINT_IGNORE)' | $(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 README
- 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#
- Xstrparse.o: strparse.h str.h
- Xstrprint.o: str.h
- Xstrutil.o: str.h
- Xstrs.o: ss_impl.h str.h
- Xss_bf.o: ss_impl.h
- Xss_rk.o: ss_impl.h ss_rk.h
- Xss_kmp.o: ss_impl.h ss_kmp.h
- Xss_sbm.o: ss_impl.h ss_sbm.h
- Xss_bmh.o: ss_impl.h ss_bmh.h
- Xss_so.o: ss_impl.h ss_so.h
- X
- X
- X#
- X# Test program
- X#
- Xtt: tt.c $(LIBNAME)
- X $(CC) -I$(INCDIR) -g -o $@ tt.c $(LIBNAME) -L$(LIBDIR) -lsio -lmisc
- X
- END_OF_FILE
- if test 4534 -ne `wc -c <'libs/src/str/Makefile'`; then
- echo shar: \"'libs/src/str/Makefile'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/Makefile'
- fi
- if test -f 'libs/src/str/strparse.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/str/strparse.c'\"
- else
- echo shar: Extracting \"'libs/src/str/strparse.c'\" \(4683 characters\)
- sed "s/^X//" >'libs/src/str/strparse.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: strparse.c,v 3.1 1993/06/13 02:48:19 panos Exp $" ;
- Xstatic char version[] = VERSION ;
- X
- X#include "str.h"
- X#include "strparse.h"
- X
- Xchar *strcpy() ;
- Xchar *strncpy() ;
- Xchar *strpbrk() ;
- X
- Xchar *malloc() ;
- X
- Xint str_errno ;
- X
- X
- XPRIVATE char *new_string( s )
- X register char *s ;
- X{
- X register char *p = malloc( (unsigned)strlen( s ) + 1 ) ;
- X
- X return( p ? strcpy( p, s ) : p ) ;
- X}
- X
- X
- Xstr_h str_parse( str, separ, flags, errnop )
- X register char *str ;
- X char *separ ;
- X int flags ;
- X int *errnop ;
- X{
- X register struct str_handle *hp ;
- X int *errp = ( errnop == NULL ) ? &str_errno : errnop ;
- X
- X if ( separ == NULL )
- X HANDLE_ERROR( flags, NULL, errp, STR_ENULLSEPAR,
- X "STR str_parse: NULL separator\n" ) ;
- X
- X hp = (struct str_handle *) malloc( sizeof( struct str_handle ) ) ;
- X if ( hp == NULL )
- X HANDLE_ERROR( flags, NULL, errp, STR_ENOMEM,
- X "STR str_parse: malloc failed\n" ) ;
- X
- X hp->string = str ;
- X hp->pos = str ;
- X hp->separator = new_string( separ ) ;
- X if ( hp->separator == NULL )
- X if ( flags & STR_RETURN_ERROR )
- X {
- X free( (char *) hp ) ;
- X *errp = STR_ENOMEM ;
- X return( NULL ) ;
- X }
- X else
- X TERMINATE( "STR str_parse: malloc failed\n" ) ;
- X
- X hp->flags = flags ;
- X hp->errnop = errp ;
- X hp->no_more = ( str == NULL ) ;
- X return( (str_h) hp ) ;
- X}
- X
- X
- Xvoid str_endparse( handle )
- X str_h handle ;
- X{
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X
- X free( hp->separator ) ;
- X free( (char *) handle ) ;
- X}
- X
- X
- X/*
- X * Change the string
- X */
- Xint str_setstr( handle, newstr )
- X str_h handle ;
- X char *newstr ;
- X{
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X
- X if ( newstr == NULL )
- X HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSTRING,
- X "STR str_setstr: NULL string\n" ) ;
- X
- X hp->string = newstr ;
- X hp->pos = newstr ;
- X hp->no_more = FALSE ;
- X return( STR_OK ) ;
- X}
- X
- X
- X
- X/*
- X * Change the separator
- X */
- Xint str_separator( handle, separator )
- X str_h handle ;
- X char *separator ;
- X{
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X char *new_separator ;
- X
- X if ( separator == NULL )
- X HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSEPAR,
- X "STR str_separator: NULL separator\n" ) ;
- X new_separator = new_string( separator ) ;
- X if ( new_separator == NULL )
- X HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENOMEM,
- X "STR str_separator: malloc failed\n" ) ;
- X
- X free( hp->separator ) ;
- X hp->separator = new_separator ;
- X return( STR_OK ) ;
- X}
- X
- X
- Xchar *str_nextpos( handle )
- X str_h handle ;
- X{
- X struct str_handle *hp = (struct str_handle *) handle ;
- X
- X if ( hp->no_more || *hp->pos == '\0' )
- X return( NULL ) ;
- X else
- X return( hp->pos ) ;
- X}
- X
- X
- Xchar *str_component( handle )
- X str_h handle ;
- X{
- X register char *start ;
- X register char *last ;
- X register int sep_count ;
- X char *retval ;
- X int last_char ;
- X register struct str_handle *hp = (struct str_handle *) handle ;
- X register int first_call = ( hp->pos == hp->string ) ;
- X
- X if ( hp->no_more )
- X return( NULL ) ;
- X
- X /*
- X * Get number of separator characters.
- X * Find beginning of component.
- X */
- X sep_count = strspn( hp->pos, hp->separator ) ;
- X
- X /*
- X * If this is the first call, and there are separator characters
- X * at the beginning of the string and the STR_NULL_START flag is set
- X * we return a 0-length string.
- X */
- X if ( first_call && sep_count > 0 && ( hp->flags & STR_NULL_START ) )
- X {
- X start = hp->pos ;
- X last = hp->pos ;
- X }
- X else
- X {
- X start = hp->pos + sep_count ;
- X
- X if ( *start == '\0' )
- X {
- X last = start ;
- X hp->no_more = TRUE ;
- X if ( ! ( hp->flags & STR_NULL_END ) )
- X return( NULL ) ;
- X }
- X else
- X {
- X last = strpbrk( start, hp->separator ) ;
- X if ( last == NULL )
- X last = start + strlen( start ) ;
- X }
- X }
- X
- X /*
- X * At this point, the following variables must be set:
- X * start: beginning of component
- X * last: end of component + 1
- X *
- X * If STR_MALLOC is set, allocate space for the new string.
- X *
- X * NOTE: If STR_MALLOC is not set, the processed string is trashed.
- X */
- X last_char = *last ;
- X if ( hp->flags & STR_MALLOC )
- X {
- X int len = last - start ;
- X
- X retval = malloc( (unsigned)len + 1 ) ;
- X if ( retval == NULL )
- X HANDLE_ERROR( hp->flags, NULL, hp->errnop, STR_ENOMEM,
- X "STR str_component: malloc failed\n" ) ;
- X strncpy( retval, start, len )[ len ] = '\0' ;
- X }
- X else
- X {
- X retval = start ;
- X *last = '\0' ;
- X }
- X
- X /*
- X * Check if last_char is NUL to avoid setting hp->pos past the
- X * end of the string
- X */
- X hp->pos = ( last_char == '\0' ) ? last : last+1 ;
- X return( retval ) ;
- X}
- X
- X
- END_OF_FILE
- if test 4683 -ne `wc -c <'libs/src/str/strparse.c'`; then
- echo shar: \"'libs/src/str/strparse.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/str/strparse.c'
- fi
- if test -f 'libs/src/xlog/xlog.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/xlog/xlog.c'\"
- else
- echo shar: Extracting \"'libs/src/xlog/xlog.c'\" \(4717 characters\)
- sed "s/^X//" >'libs/src/xlog/xlog.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: xlog.c,v 2.1 1993/05/06 07:39:39 panos Exp $" ;
- Xstatic char version[] = VERSION ;
- X
- X#include <varargs.h>
- X
- X#include "xlog.h"
- X#include "impl.h"
- X
- Xchar *malloc() ;
- X
- Xextern struct xlog_ops __xlog_filelog_ops ;
- X#ifndef NO_SYSLOG
- Xextern struct xlog_ops __xlog_syslog_ops ;
- X#endif
- X
- Xstruct lookup_table
- X{
- X struct xlog_ops *ops ;
- X xlog_e type ;
- X} ;
- X
- Xstatic struct lookup_table ops_lookup_table[] =
- X {
- X { &__xlog_filelog_ops, XLOG_FILELOG },
- X#ifndef NO_SYSLOG
- X { &__xlog_syslog_ops, XLOG_SYSLOG },
- X#endif
- X { NULL }
- X } ;
- X
- X
- X#define CALLBACK( xp, status ) \
- X if ( (xp)->xl_callback ) \
- X (*(xp)->xl_callback)( (xlog_h)(xp), status, (xp)->xl_callback_arg )
- X
- X
- XPRIVATE void xlog_link() ;
- XPRIVATE void xlog_unlink() ;
- X
- X
- XPRIVATE struct xlog_ops *xlog_ops_lookup( type )
- X register xlog_e type ;
- X{
- X register struct lookup_table *ltp ;
- X
- X for ( ltp = &ops_lookup_table[ 0 ] ; ltp->ops ; ltp++ )
- X if ( ltp->type == type )
- X break ;
- X return( ltp->ops ) ;
- X}
- X
- X
- X
- X/* VARARGS3 */
- Xxlog_h xlog_create( type, id, flags, va_alist )
- X xlog_e type ;
- X char *id ;
- X int flags ;
- X va_dcl
- X{
- X xlog_s *xp ;
- X va_list ap ;
- X struct xlog_ops *xops ;
- X int status ;
- X
- X if ( ( xp = NEW( xlog_s ) ) == NULL )
- X return( NULL ) ;
- X
- X if ( id == NULL || ( xp->xl_id = __xlog_new_string( id ) ) == NULL )
- X {
- X FREE( xp ) ;
- X return( NULL ) ;
- X }
- X
- X xops = xlog_ops_lookup( type ) ;
- X
- X if ( xops != NULL )
- X {
- X va_start( ap ) ;
- X xp->xl_ops = xops ;
- X status = XL_INIT( xp, ap ) ;
- X va_end( ap ) ;
- X
- X if ( status == XLOG_ENOERROR )
- X {
- X xp->xl_flags = flags ;
- X xp->xl_type = type ;
- X xp->xl_clients = XLOG_NULL ;
- X xp->xl_use = XLOG_NULL ;
- X return( (xlog_h) xp ) ;
- X }
- X }
- X
- X free( xp->xl_id ) ;
- X FREE( xp ) ;
- X return( NULL ) ;
- X}
- X
- X
- X
- XPRIVATE void xlog_link( client, server )
- X xlog_s *client, *server ;
- X{
- X client->xl_use = server ;
- X if ( server == NULL )
- X return ;
- X
- X if ( server->xl_clients == XLOG_NULL )
- X {
- X INIT_LINKS( client, xl_other_users ) ;
- X server->xl_clients = client ;
- X }
- X else
- X LINK( server, client, xl_other_users ) ;
- X}
- X
- X
- XPRIVATE void xlog_unlink( xp )
- X xlog_s *xp ;
- X{
- X xlog_s *server = xp->xl_use ;
- X
- X /*
- X * Step 1: remove from server chain
- X */
- X if ( server != XLOG_NULL )
- X {
- X if ( server->xl_clients == xp )
- X if ( NEXT( xp, xl_other_users ) == xp )
- X server->xl_clients = XLOG_NULL ;
- X else
- X server->xl_clients = NEXT( xp, xl_other_users ) ;
- X else
- X UNLINK( xp, xl_other_users ) ;
- X }
- X
- X /*
- X * Step 2: If we have users, clear their link to us.
- X */
- X if ( xp->xl_clients != NULL )
- X {
- X xlog_s *xp2 = xp->xl_clients ;
- X
- X do
- X {
- X xp2->xl_use = XLOG_NULL ;
- X xp2 = NEXT( xp2, xl_other_users ) ;
- X }
- X while ( xp2 != xp->xl_clients ) ;
- X }
- X}
- X
- X
- XPRIVATE void xlog_flags( xp, cmd, ap )
- X xlog_s *xp ;
- X xlog_cmd_e cmd ;
- X va_list ap ;
- X{
- X int flag = va_arg( ap, int ) ;
- X int old_value = ( ( xp->xl_flags & flag ) != 0 ) ;
- X int *valp = va_arg( ap, int * ) ;
- X
- X if ( cmd == XLOG_SETFLAG )
- X if ( *valp )
- X xp->xl_flags |= flag ;
- X else
- X xp->xl_flags &= ~flag ;
- X *valp = old_value ;
- X}
- X
- X
- Xvoid xlog_destroy( xlog )
- X xlog_h xlog ;
- X{
- X xlog_s *xp = XP( xlog ) ;
- X
- X xlog_unlink( xp ) ;
- X XL_FINI( xp ) ;
- X free( xp->xl_id ) ;
- X FREE( xp ) ;
- X}
- X
- X
- X/* VARARGS4 */
- Xvoid xlog_write( xlog, buf, len, flags, va_alist )
- X xlog_h xlog ;
- X char buf[] ;
- X int len ;
- X int flags ;
- X va_dcl
- X{
- X xlog_s *xp = XP( xlog ) ;
- X va_list ap ;
- X int status ;
- X
- X va_start( ap ) ;
- X status = XL_WRITE( xp, buf, len, flags, ap ) ;
- X va_end( ap ) ;
- X
- X if ( status != XLOG_ENOERROR )
- X {
- X CALLBACK( xp, status ) ;
- X }
- X}
- X
- X
- X/* VARARGS2 */
- Xint xlog_control( xlog, cmd, va_alist )
- X xlog_h xlog ;
- X xlog_cmd_e cmd ;
- X va_dcl
- X{
- X va_list ap ;
- X xlog_s *xp = XP( xlog ) ;
- X int status = XLOG_ENOERROR ;
- X
- X va_start( ap ) ;
- X
- X switch ( cmd )
- X {
- X case XLOG_LINK:
- X xlog_unlink( xp ) ;
- X xlog_link( xp, va_arg( ap, xlog_s * ) ) ;
- X xp->xl_callback_arg = va_arg( ap, void * ) ;
- X break ;
- X
- X case XLOG_CALLBACK:
- X xp->xl_callback = va_arg( ap, voidfunc ) ;
- X break ;
- X
- X case XLOG_GETFLAG:
- X case XLOG_SETFLAG:
- X xlog_flags( xp, cmd, ap ) ;
- X break ;
- X
- X default:
- X status = XL_CONTROL( xp, cmd, ap ) ;
- X }
- X
- X va_end( ap ) ;
- X
- X return( status ) ;
- X}
- X
- X
- Xint xlog_parms( type, va_alist )
- X xlog_e type ;
- X va_dcl
- X{
- X va_list ap ;
- X int status ;
- X
- X va_start( ap ) ;
- X switch ( type )
- X {
- X#ifndef NO_SYSLOG
- X case XLOG_SYSLOG:
- X status = (*__xlog_syslog_ops.parms)( ap ) ;
- X break ;
- X#endif
- X case XLOG_FILELOG:
- X status = (*__xlog_filelog_ops.parms)( ap ) ;
- X break ;
- X
- X default:
- X status = XLOG_ENOERROR ;
- X }
- X va_end( ap ) ;
- X return( status ) ;
- X}
- X
- END_OF_FILE
- if test 4717 -ne `wc -c <'libs/src/xlog/xlog.c'`; then
- echo shar: \"'libs/src/xlog/xlog.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/xlog/xlog.c'
- fi
- if test -f 'xinetd/conf.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/conf.c'\"
- else
- echo shar: Extracting \"'xinetd/conf.c'\" \(4677 characters\)
- sed "s/^X//" >'xinetd/conf.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: conf.c,v 6.4 1993/06/01 22:59:39 panos Exp $" ;
- X
- X#include <sys/types.h>
- X#include <netinet/in.h>
- X#include <syslog.h>
- X#include <fcntl.h>
- X#include <string.h>
- X#include <netdb.h>
- X
- X#include "pset.h"
- X#include "misc.h"
- X#include "xlog.h"
- X
- X#include "attr.h"
- X#include "config.h"
- X#include "conf.h"
- X#include "defs.h"
- X#include "service.h"
- X#include "state.h"
- X
- Xvoid msg() ;
- Xvoid out_of_memory() ;
- X
- X
- Xvoid cnf_free( confp )
- X struct configuration *confp ;
- X{
- X register unsigned u ;
- X pset_h sconfs = confp->cnf_service_confs ;
- X
- X for ( u = 0 ; u < pset_count( sconfs ) ; u++ )
- X sc_free( SCP( pset_pointer( sconfs, u ) ) ) ;
- X pset_destroy( sconfs ) ;
- X if ( confp->cnf_defaults )
- X sc_free( confp->cnf_defaults ) ;
- X}
- X
- X
- X/*
- X * Extract from 'confp' the service that matches 'scp'
- X */
- Xstruct service_config *cnf_extract( confp, scp )
- X struct configuration *confp ;
- X struct service_config *scp ;
- X{
- X pset_h stab = confp->cnf_service_confs ;
- X register unsigned u ;
- X
- X for ( u = 0 ; u < pset_count( stab ) ; u++ )
- X {
- X struct service_config *iscp = SCP( pset_pointer( stab, u ) ) ;
- X
- X if ( ! EQ( scp->sc_id, iscp->sc_id ) || sc_different_confs( scp, iscp ) )
- X continue ;
- X
- X pset_remove_index( stab, u ) ;
- X return( iscp ) ;
- X }
- X return( NULL ) ;
- X}
- X
- X
- X
- Xvoid cnf_dump( confp, fd )
- X struct configuration *confp ;
- X int fd ;
- X{
- X pset_h stab = confp->cnf_service_confs ;
- X register unsigned u ;
- X void tabprint() ;
- X
- X sc_dump( confp->cnf_defaults, fd, 0, TRUE ) ;
- X tabprint( fd, 0, "\n" ) ;
- X
- X for ( u = 0 ; u < pset_count( stab ) ; u++ )
- X {
- X sc_dump( SCP( pset_pointer( stab, u ) ), fd, 0, FALSE ) ;
- X Sputchar( fd, '\n' ) ;
- X }
- X}
- X
- X
- Xstatus_e cnf_init( confp, fdp, iterp )
- X struct configuration *confp ;
- X int *fdp ;
- X psi_h *iterp ;
- X{
- X int fd ;
- X pset_h pset ;
- X psi_h pset_iter ;
- X struct service_config *scp ;
- X char *func = "cnf_init" ;
- X
- X /*
- X * Open configuration file
- X */
- X fd = open( ps.ros.config_file, O_RDONLY ) ;
- X
- X if ( fd == -1 )
- X {
- X msg( LOG_ERR, func, "open( %s ) failed: %m", ps.ros.config_file ) ;
- X return( FAILED ) ;
- X }
- X
- X if ( ( pset = pset_create( 0, 0 ) ) == NULL )
- X {
- X msg( LOG_CRIT, func, "can't create service table" ) ;
- X (void) close( fd ) ;
- X return( FAILED ) ;
- X }
- X
- X if ( ( scp = sc_alloc( CHAR_NULL ) ) == NULL )
- X {
- X msg( LOG_ERR, func, "can't allocate defaults service" ) ;
- X pset_destroy( pset ) ;
- X (void) close( fd ) ;
- X return( FAILED ) ;
- X }
- X
- X if ( ( pset_iter = psi_create( pset ) ) == NULL )
- X {
- X msg( LOG_ERR, func, "can't create service table iterator" ) ;
- X sc_free( scp ) ;
- X pset_destroy( pset ) ;
- X (void) close( fd ) ;
- X return( FAILED ) ;
- X }
- X
- X *fdp = fd ;
- X confp->cnf_service_confs = pset ;
- X confp->cnf_defaults = scp ;
- X *iterp = pset_iter ;
- X return( OK ) ;
- X}
- X
- X
- XPRIVATE void destroy_service( sp )
- X struct service *sp ;
- X{
- X svc_deactivate( sp ) ;
- X svc_free( sp ) ;
- X}
- X
- X
- X/*
- X * Try to start all services.
- X * Return the # of services started.
- X */
- Xunsigned cnf_start_services( confp )
- X struct configuration *confp ;
- X{
- X pset_h sconfs = confp->cnf_service_confs ;
- X unsigned services_started = 0 ;
- X register unsigned u ;
- X char *func = "cnf_start_services" ;
- X
- X for ( u = 0 ; u < pset_count( sconfs ) ; u++ )
- X {
- X register struct service_config *scp = SCP( pset_pointer( sconfs, u ) ) ;
- X register struct service *sp ;
- X
- X if ( ( sp = svc_new( scp ) ) == NULL )
- X {
- X sc_free( scp ) ;
- X continue ;
- X }
- X
- X if ( svc_activate( sp ) == FAILED )
- X {
- X svc_free( sp ) ;
- X continue ;
- X }
- X
- X /*
- X * descriptors_free can be negative without a descriptor-allocating
- X * system call failing because some of the descriptors we reserve
- X * are transient
- X */
- X if ( ps.rws.descriptors_free < 0 )
- X {
- X msg( LOG_ERR, func,
- X "Service %s disabled because of lack of file descriptors",
- X SVC_ID( sp ) ) ;
- X destroy_service( sp ) ;
- X continue ;
- X }
- X
- X /*
- X * Activation successful; add service to service table
- X */
- X if ( pset_add( SERVICES( ps ), sp ) == NULL )
- X {
- X out_of_memory( func ) ;
- X destroy_service( sp ) ;
- X break ;
- X }
- X
- X SVC_HOLD( sp ) ;
- X
- X services_started++ ;
- X
- X if ( debug.on )
- X msg( LOG_DEBUG, func, "Started service: %s", SVC_ID( sp ) ) ;
- X }
- X
- X /*
- X * All the configurations have been linked to their services
- X * so we don't need to hold references to them in the pset.
- X * We need to clear the pset so that the cnf_free will not free the memory.
- X */
- X pset_clear( sconfs ) ;
- X
- X if ( debug.on )
- X msg( LOG_DEBUG, func, "mask_max = %d, services_started = %d",
- X ps.rws.mask_max, services_started ) ;
- X
- X return( services_started ) ;
- X}
- X
- X
- X
- END_OF_FILE
- if test 4677 -ne `wc -c <'xinetd/conf.c'`; then
- echo shar: \"'xinetd/conf.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/conf.c'
- fi
- if test -f 'xinetd/msg.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/msg.c'\"
- else
- echo shar: Extracting \"'xinetd/msg.c'\" \(4533 characters\)
- sed "s/^X//" >'xinetd/msg.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: msg.c,v 6.6 1993/06/15 23:25:57 panos Exp $" ;
- X
- X#include <syslog.h>
- X#include <fcntl.h>
- X
- X#include "sio.h"
- X#include "str.h"
- X#include "xlog.h"
- X
- X#include "options.h"
- X
- X#include "state.h"
- X#include "defs.h"
- X#include "config.h"
- X
- X
- Xstatic struct name_value priorities[] =
- X {
- X { "WARNING", LOG_WARNING },
- X { "ERROR", LOG_ERR },
- X { "CRITICAL", LOG_CRIT },
- X { "NOTICE", LOG_NOTICE },
- X { "DEBUG", LOG_DEBUG },
- X { "INFO", LOG_INFO },
- X { NULL, 1 },
- X { "UNKNOWN", 0 }
- X } ;
- X
- X
- Xextern int line_count ;
- Xextern struct name_value syslog_facilities[] ;
- X
- Xvoid msg() ;
- X
- X#define BUFSIZE 2048
- X
- X#define DEFAULT_SYSLOG_LEVEL LOG_INFO
- X
- X
- Xchar *msg_init()
- X{
- X xlog_h xh ;
- X int fd ;
- X xlog_e type_of_xlog ;
- X bool_int facility_error = FALSE ;
- X char *func = "msg_init" ;
- X
- X if ( debug.on )
- X {
- X type_of_xlog = XLOG_FILELOG ;
- X xh = xlog_create( type_of_xlog, program_name, XLOG_NOFLAGS,
- X "/dev/tty", O_APPEND + O_WRONLY, 0 ) ;
- X debug.fd = -1 ;
- X }
- X else
- X {
- X if ( filelog_option )
- X {
- X type_of_xlog = XLOG_FILELOG ;
- X xh = xlog_create( type_of_xlog, program_name,
- X XLOG_PRINT_ID + XLOG_PRINT_PID,
- X filelog_option_arg, LOG_OPEN_FLAGS, LOG_FILE_MODE ) ;
- X }
- X else
- X {
- X int facility = DEFAULT_SYSLOG_FACILITY ;
- X
- X if ( syslog_option )
- X {
- X struct name_value *nvp ;
- X
- X nvp = nv_find_value( syslog_facilities, syslog_option_arg ) ;
- X if ( nvp != NULL )
- X facility = nvp->value ;
- X else
- X facility_error = TRUE ;
- X }
- X
- X type_of_xlog = XLOG_SYSLOG ;
- X xh = xlog_create( type_of_xlog, program_name, XLOG_NOFLAGS,
- X facility, DEFAULT_SYSLOG_LEVEL ) ;
- X }
- X }
- X
- X if ( xh == NULL )
- X {
- X /*
- X * This simply returns the most likely reason for failure.
- X * We can't do any better since xlog_create does not return an
- X * error code.
- X */
- X if ( type_of_xlog == XLOG_SYSLOG )
- X return( "can't connect to syslog" ) ;
- X else if ( type_of_xlog == XLOG_FILELOG )
- X return( "can't open log file" ) ;
- X else
- X return( "unknown reason" ) ;
- X }
- X
- X if ( xlog_control( xh, XLOG_GETFD, &fd ) == XLOG_ENOERROR )
- X {
- X if ( fcntl( fd, F_SETFD, 1 ) == -1 )
- X {
- X xlog_destroy( xh ) ;
- X return( "can't set close-on-exec flag of log file" ) ;
- X }
- X if ( debug.on )
- X debug.fd = fd ;
- X }
- X
- X ps.rws.program_log = xh ;
- X
- X if ( facility_error )
- X msg( LOG_ERR, func, "Bad syslog facility: %s", syslog_option_arg ) ;
- X return( CHAR_NULL ) ;
- X}
- X
- X
- Xvoid msg_suspend()
- X{
- X (void) xlog_control( ps.rws.program_log, XLOG_PREEXEC ) ;
- X}
- X
- X
- Xvoid msg_resume()
- X{
- X (void) xlog_control( ps.rws.program_log, XLOG_POSTEXEC ) ;
- X}
- X
- X
- X/*
- X * The size argument is a value-result argument
- X */
- XPRIVATE int prepare_buffer( level, func, buf, size, fmt, ap )
- X int level ;
- X char *func ;
- X char *buf ;
- X unsigned size ;
- X char *fmt ;
- X va_list ap ;
- X{
- X int cc ;
- X char *bufstart = buf ;
- X unsigned bytes_left = size ;
- X
- X /*
- X * Check if we need to print the level name
- X */
- X if ( debug.on || filelog_option )
- X {
- X cc = strx_nprint( bufstart, bytes_left,
- X "%s: ", nv_get_name( priorities, level ) ) ;
- X bufstart += cc ;
- X bytes_left -= cc ;
- X }
- X
- X /*
- X * Check if we need to print the function name
- X */
- X if ( debug.on || level == LOG_CRIT )
- X {
- X cc = strx_nprint( bufstart, bytes_left, "{%s} ", func ) ;
- X bufstart += cc ;
- X bytes_left -= cc ;
- X }
- X
- X cc = strx_nprintv( bufstart, bytes_left, fmt, ap ) ;
- X
- X bytes_left -= cc ;
- X
- X return( size - bytes_left ) ;
- X}
- X
- X
- X/* VARARGS3 */
- Xvoid msg( level, func, fmt, va_alist )
- X int level ;
- X char *func ;
- X char *fmt ;
- X va_dcl
- X{
- X va_list ap ;
- X char buf[ BUFSIZE ] ;
- X int len ;
- X
- X va_start( ap ) ;
- X len = prepare_buffer( level, func, buf, sizeof( buf ), fmt, ap ) ;
- X va_end( ap ) ;
- X
- X xlog_write( ps.rws.program_log, buf, len, XLOG_SET_LEVEL, level ) ;
- X}
- X
- X
- X/*
- X * Parser message.
- X * There are 2 differences from msg():
- X * 1) parsemsg() prints the line #
- X * 2) parsemsg() does not interpret %m
- X */
- X/* VARARGS3 */
- Xvoid parsemsg( msg_level, func, fmt, va_alist )
- X int msg_level ;
- X char *func ;
- X char *fmt ;
- X va_dcl
- X{
- X va_list ap ;
- X char buf[ BUFSIZE ] ;
- X int cc ;
- X int len ;
- X
- X va_start( ap ) ;
- X len = prepare_buffer( msg_level, func, buf, sizeof( buf ), fmt, ap ) ;
- X va_end( ap ) ;
- X
- X cc = strx_nprint( &buf[ len ], sizeof(buf)-len, " [line=%d]", line_count ) ;
- X len += cc ;
- X
- X xlog_write( ps.rws.program_log, buf, len,
- X XLOG_NO_ERRNO + XLOG_SET_LEVEL, msg_level ) ;
- X}
- X
- END_OF_FILE
- if test 4533 -ne `wc -c <'xinetd/msg.c'`; then
- echo shar: \"'xinetd/msg.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/msg.c'
- fi
- if test -f 'xinetd/special.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/special.c'\"
- else
- echo shar: Extracting \"'xinetd/special.c'\" \(4537 characters\)
- sed "s/^X//" >'xinetd/special.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: special.c,v 6.10 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 <signal.h>
- X
- X#include "misc.h"
- X
- X#include "options.h"
- X
- X#include "state.h"
- X#include "conf.h"
- X#include "sconst.h"
- X#include "server.h"
- X#include "config.h"
- X#include "builtin.h"
- X#include "connection.h"
- X
- Xvoid msg() ;
- Xvoid out_of_memory() ;
- X
- Xextern struct name_value socket_types[] ;
- X
- XPRIVATE void stream_logging() ;
- XPRIVATE void stream_shutdown() ;
- Xvoid intercept() ;
- X
- Xstatic struct builtin_service special_services[] =
- X {
- X { LOG_SERVICE_NAME, SOCK_STREAM, { stream_logging, FORK } },
- X { SHUTDOWN_SERVICE_NAME, SOCK_STREAM, { stream_shutdown, FORK } },
- X { INTERCEPT_SERVICE_NAME, SOCK_STREAM, { intercept, FORK } },
- X { INTERCEPT_SERVICE_NAME, SOCK_DGRAM, { intercept, FORK } },
- X { NULL }
- X } ;
- X
- X
- Xbuiltin_s *spec_find( service_name, type )
- X char *service_name ;
- X int type ;
- X{
- X builtin_s *bp ;
- X struct name_value *nvp ;
- X char *func = "spec_find" ;
- X
- X if ( bp = builtin_lookup( special_services, service_name, type ) )
- X return( bp ) ;
- X
- X nvp = nv_find_name( socket_types, type ) ;
- X if ( nvp == NULL )
- X {
- X msg( LOG_ERR, func, "unknown socket type: %d", type ) ;
- X return( NULL ) ;
- X }
- X
- X msg( LOG_ERR, func,
- X "special service %s,%s not supported", service_name, nvp->name ) ;
- X return( NULL ) ;
- X}
- X
- X
- XPRIVATE status_e spec_service_handler( sp, cp )
- X struct service *sp ;
- X connection_s *cp ;
- X{
- X if ( svc_access_control( sp, cp ) == FAILED ||
- X server_run( sp, cp ) == FAILED )
- X {
- X /*
- X * If we couldn't start a server for the shutdown service, mark
- X * the connection for shutdown, so that we will do a simple shutdown
- X * (i.e. we won't try to collect information from the remote end).
- X */
- X if ( sp == SHUTDOWN_SERVICE( ps ) )
- X conn_shutdown( cp ) ;
- X return( FAILED ) ;
- X }
- X return( OK ) ;
- X}
- X
- X
- X
- XPRIVATE struct service *spec_setup( name, socket_type, instances )
- X char *name ;
- X int socket_type ;
- X int instances ;
- X{
- X builtin_s *bp ;
- X struct service_config *scp ;
- X
- X bp = spec_find( name, socket_type ) ;
- X if ( bp == NULL )
- X return( NULL ) ;
- X
- X if ( ( scp = sc_make_special( name, bp, instances ) ) == NULL )
- X return( NULL ) ;
- X
- X return( svc_make_special( scp, spec_service_handler ) ) ;
- X}
- X
- X
- X/*
- X * Initialize the special services and the corresponding entries in
- X * the program state structure.
- X */
- Xvoid spec_include()
- X{
- X int instances ;
- X
- X instances = logprocs_option ? logprocs_option_arg : DEFAULT_LOGPROCS ;
- X LOG_SERVICE( ps ) = spec_setup( LOG_SERVICE_NAME, SOCK_STREAM, instances ) ;
- X
- X instances = shutdownprocs_option ? shutdownprocs_option_arg
- X : DEFAULT_SHUTDOWNPROCS ;
- X SHUTDOWN_SERVICE( ps ) = spec_setup( SHUTDOWN_SERVICE_NAME,
- X SOCK_STREAM, instances ) ;
- X}
- X
- X
- XPRIVATE void stream_logging( serp )
- X struct server *serp ;
- X{
- X char *func = "stream_logging" ;
- X idresult_e result ;
- X idresult_e log_remote_user() ;
- X char *idresult_explain() ;
- X
- X#ifdef DEBUG_LOGGING
- X if ( debug.on )
- X {
- X msg( LOG_DEBUG, func, "%d is sleeping", getpid() ) ;
- X sleep( 10 ) ;
- X }
- X#endif
- X
- X result = log_remote_user( serp, LOGUSER_FAILURE_TIMEOUT ) ;
- X if ( result != IDR_OK && result != IDR_NOSERVER )
- X msg( LOG_ERR, func, "Failed to contact identity server at %s: %s",
- X conn_addrstr( SERVER_CONNECTION( serp ) ),
- X idresult_explain( result ) ) ;
- X}
- X
- X
- X
- XPRIVATE void stream_shutdown( serp )
- X struct server *serp ;
- X{
- X struct service *sp = SERVER_CONNSERVICE( serp ) ;
- X char *str ;
- X char *func = "stream_shutdown" ;
- X
- X if ( debug.on )
- X msg( LOG_DEBUG, func, "shutdown for service %s, (fd=%d)",
- X SVC_ID( sp ), SERVER_FD( serp ) ) ;
- X
- X#ifdef DEBUG_SHUTDOWN
- X /*
- X * The reason for the sleep is that single stepping through this
- X * code is impossible (at least on the Sun IPC I am using).
- X */
- X if ( debug.on )
- X {
- X msg( LOG_DEBUG, func, "%d is sleeping", getpid() ) ;
- X sleep( 10 ) ;
- X }
- X#endif
- X
- X /*
- X * Everything must happen within 10 seconds.
- X * Since there is no alarm handler the process will be terminated if the
- X * timer runs out.
- X */
- X if ( ! debug.on )
- X {
- X (void) alarm( 10 ) ;
- X (void) signal( SIGALRM, SIG_DFL ) ;
- X }
- X
- X str = NULL ; /* must be initialized to NULL */
- X svc_shutdown( sp, SERVER_CONNECTION( serp ), &str ) ;
- X
- X (void) alarm( 0 ) ;
- X
- X if ( str != NULL )
- X svc_logprint( sp, DATA_ENTRY, "%s", str ) ;
- X}
- X
- X
- END_OF_FILE
- if test 4537 -ne `wc -c <'xinetd/special.c'`; then
- echo shar: \"'xinetd/special.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/special.c'
- fi
- echo shar: End of archive 10 \(of 31\).
- cp /dev/null ark10isdone
- 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
-