home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: panos@cs.colorado.edu (Panos Tsirigotis)
- Subject: v26i263: xinetd-2.1.1 - inetd replacement with access control and logging, Part19/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 263
- Archive-Name: xinetd-2.1.1/part19
-
- #! /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 19 (of 31)."
- # Contents: xinetd/Makefile xinetd/addr.c
- # Wrapped by panos@mystique on Mon Jun 21 14:51:26 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'xinetd/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/Makefile'\"
- else
- echo shar: Extracting \"'xinetd/Makefile'\" \(9823 characters\)
- sed "s/^X//" >'xinetd/Makefile' <<'END_OF_FILE'
- 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# $Id: Makefile,v 6.12 1993/06/15 18:55:53 panos Exp $
- X#
- X# Based on Program makefile template: *Revision: 1.14 *
- X#
- X
- X#
- X# Available entries:
- X# $(NAME) --> create the program (this is the default target)
- X# install --> install the program (and man page)
- X# uninstall --> uninstall the program (and man page)
- X# clean --> cleanup
- X# spotless --> clean + uninstall
- X# lint --> lints a specific file (usage: make lint MODULE=foo.c)
- X# lintall --> lint all files
- X# tags --> creates a tags file
- X# checkout --> checkout all files
- X#
- X
- X#
- X# The following variables must be set by you
- X#
- XNAME = xinetd
- XVERSION = 2.1.1
- X
- X#
- X# Possible flags that can be defined in DEFS:
- X#
- X# -DCUSTOMCONF if you want to change any of the constants that
- X# affect xinetd's behavior (check config.h)
- X# -DNO_POSIX_TYPES if your OS does not know about POSIX types like pid_t
- X# -DNO_TERMIOS if you don't have /usr/include/sys/termios.h
- X# -DOLD_WAIT if your OS supports union wait
- X# -DNO_RPC if your OS does not support RPC
- X# -DNO_SIGLIST if your C library does not contain sys_siglist
- X# -DNO_TIMERS if you don't want to use the timer library
- X#
- X# About signal handling:
- X# Case 1: POSIX signal handling is supported
- X# You don't need to define anything
- X# Case 2: BSD signal handling is supported (i.e. sigvec(2))
- X# Use -DNO_POSIX_SIGS
- X# Case 3: None of the above
- X# Use -DNO_POSIX_SIGS and -DNO_SIGVEC
- X#
- X# Available debug flags:
- X# DEBUG code is being debugged
- X# DEBUG_SERVER forked server will do a sleep
- X# DEBUG_INTERCEPTOR forked interceptor will do a sleep
- X# DEBUG_SIGNALS code that handles SIGSEGV and SIGBUS
- X# DEBUG_LOGGING forked logging server will do a sleep
- X# DEBUG_SHUTDOWN forked shutdown server will do a sleep
- X# DEBUG_TPCINT enable debugging code in the tcp interceptor
- X# DEBUG_UDPINT enable debugging code in the udp interceptor
- X# DEBUG_DAEMON debug xinetd when not invoked with -d option
- X# DEBUG_RETRY debug the server retry code
- X#
- XDEFS=-DDEBUG
- X
- XDEBUG = -g # either -g or -O
- XLDFLAGS = -L$(LIBDIR)$(DEBUG)
- XLIBS = -lsio -lmisc -lstr -lpset -lxlog -ltimer -lpq
- X
- XHDRS = \
- X access.h \
- X addr.h \
- X attr.h \
- X builtin.h \
- X conf.h config.h connection.h \
- X defs.h \
- X flags.h \
- X int.h \
- X log.h \
- X mask.h \
- X parse.h \
- X sconst.h sconf.h server.h service.h state.h
- X
- XSRCS = \
- X access.c addr.c \
- X builtins.c \
- X child.c conf.c confparse.c connection.c \
- X env.c \
- X flags.c \
- X ident.c init.c int.c intcommon.c internals.c \
- X log.c logctl.c \
- X main.c msg.c \
- X nvlists.c \
- X parse.c parsesup.c parsers.c \
- X reconfig.c retry.c \
- X sconf.c server.c service.c shutdown.c \
- X signals.c special.c \
- X tcpint.c time.c \
- X udpint.c util.c
- X
- XOBJS = \
- X access.o addr.o \
- X builtins.o \
- X child.o conf.o confparse.o connection.o \
- X env.o \
- X flags.o \
- X ident.o init.o int.o intcommon.o internals.o \
- X log.o logctl.o \
- X main.o msg.o \
- X nvlists.o \
- X parse.o parsesup.o parsers.o \
- X reconfig.o retry.o \
- X sconf.o server.o service.o shutdown.o \
- X signals.o special.o \
- X tcpint.o time.o \
- X udpint.o util.o
- X
- XOPT=options.opt
- X
- XOPT_SOURCE=options.c
- XOPT_HEADER=options.h
- XOPT_OBJECT=options.o
- X
- XSOURCES = $(SRCS) $(OPT_SOURCE)
- XHEADERS = $(HDRS) $(OPT_HEADER)
- XOBJECTS = $(OBJS) $(OPT_OBJECT)
- X
- XINCLUDEDIR = -I$(HOME)/.links/includes
- X#MANPATHDIR = -I$(HOME)/.links/manpages # path up to man{1,2,etc}
- XMANPATHDIR = /tmp/t
- XINSTALLDIR = /usr/etc
- X
- X
- X#
- X# You may modify the following variables but you probably don't need to.
- X#
- X
- XPROGRAM = $(NAME)
- XMANPROGSECTION = 1
- XMANSUBSECTION = # like V,X,l
- XMANPROGFILE = $(PROGRAM).man
- XMANPROGPAGE = $(PROGRAM).$(MANPROGSECTION)$(MANSUBSECTION)
- XMANPROGDIR = $(MANPATHDIR)/man$(MANPROGSECTION)
- XMANDATASECTION = 5
- XMANDATANAMES = conf log
- XMANDATADIR = $(MANPATHDIR)/man$(MANDATASECTION)
- X
- XMANFILES = $(MANPROGFILE) $(PROGRAM).conf.man $(PROGRAM).log.man
- X
- XCC = cc # used for compiler-specific options
- XCC_FLAGS = $(DEBUG) # used for generic options
- X
- XXMODE = -m 700 # mode for executables
- XFMODE = -m 640 # mode for anything but executables
- XINSTALL = install -c
- X
- XLINT_FLAGS = -hbux
- XPAGER = less
- X
- XCPP_DEFS = $(VERSION_DEF) $(DEFS)
- X
- X#
- X# The following variables do not need to be changed
- X#
- X
- XVERSION_DEF = -DVERSION=\"$(PROGRAM)\ Version\ $(VERSION)\"
- XCPP_FLAGS = $(CPP_DEFS) $(INCLUDEDIR)
- XCFLAGS = $(CPP_FLAGS) $(CC_FLAGS)
- X
- Xall: $(PROGRAM) itox
- X
- Xitox: itox.c
- X $(CC) $(DEBUG) $(INCLUDEDIR) itox.c -o $@ $(LDFLAGS) -lmisc -lsio -lstr
- X
- X$(PROGRAM): $(OBJECTS)
- X $(CC) $(DEBUG) -o $@ $(OBJECTS) $(LDFLAGS) $(LIBS) || rm -f $@
- X
- Xtags: $(HEADERS) $(SOURCES)
- X ctags -w $(HEADERS) $(SOURCES)
- X
- Xcheckout:
- X
- Xlint:
- X lint $(LINT_FLAGS) $(CPP_FLAGS) $(MODULE) 2>&1 | $(PAGER)
- X
- Xlintall: $(OPT_HEADER)
- X lint $(LINT_FLAGS) $(CPP_FLAGS) $(SOURCES) 2>&1 | $(PAGER)
- X
- XLINT_IGNORE=RCSid|warning: possible pointer alignment problem|warning: argument op unused|warning: struct/union iovec never defined|warning: null effect|(sigprocmask|sigaction) multiply declared|argument code unused
- X
- Xlintq: $(OPT_HEADER)
- X lint $(LINT_FLAGS) $(CPP_FLAGS) $(SOURCES) 2>&1 | egrep -v '$(LINT_IGNORE)' | $(PAGER)
- X
- Xclean:
- X rm -f $(OBJECTS) $(PROGRAM) core
- X
- Xxclean: clean
- X rm -f $(OPT_SOURCE) $(OPT_HEADER)
- X
- Xinstall: $(PROGRAM)
- X $(INSTALL) $(XMODE) $(PROGRAM) $(INSTALLDIR)
- X
- Xinstall.man:
- X if test "$(MANPROGDIR)" ; then \
- X $(INSTALL) $(FMODE) $(MANPROGFILE) $(MANPROGDIR)/$(MANPROGPAGE) ;\
- X fi
- X if test "$(MANDATADIR)" ; then \
- X for i in $(MANDATANAMES) ; do \
- X name=$(PROGRAM).$$i ; \
- X $(INSTALL) $(FMODE) $$name.man $(MANDATADIR)/$$name.$(MANDATASECTION);\
- X done ;\
- X fi
- X
- Xuninstall:
- X a=`pwd` ; cd $(INSTALLDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(PROGRAM) ; fi
- X a=`pwd` ; cd $(MANPROGDIR) ;\
- X if test $$a != `pwd` ; then rm -f $(MANPROGPAGE) ; fi
- X a=`pwd` ; cd $(MANDATADIR) ;\
- X if test $$a != `pwd` ; then \
- X for i in $(MANDATANAMES) ; do \
- X rm -f $(PROGRAM).$$i.$(MANDATASECTION) ;\
- X done ;\
- X fi
- 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#
- XSUPPORT_FILES = sample.conf itox.c BUG-REPORTS
- XDISTRIBUTION_FILES = $(HDRS) $(SRCS) $(MANFILES) $(SUPPORT_FILES)
- XDIRS =
- X
- Xdist1:
- X
- Xdist: dist1 $(OPT_SOURCE) $(OPT_HEADER)
- X -co -q $(DISTRIBUTION_FILES)
- X
- Xdirs:
- X @echo $(DIRS)
- X
- X#
- X# This part of the file shows how to make $(OBJECTS)
- X#
- X
- X
- X
- X#
- X# Header file dependencies
- X#
- Xaddr.h: defs.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xbuiltin.h: defs.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xconf.h: service.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xint.h: server.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xparse.h: defs.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xsconf.h: defs.h log.h mask.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xserver.h: defs.h service.h connection.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xservice.h: defs.h sconf.h builtin.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xstate.h: mask.h sconf.h conf.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- Xconnection.h: mask.h service.h
- X @if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi
- X
- X#
- X# Object file dependencies
- X#
- Xaccess.o: access.h addr.h connection.h service.h state.h
- Xaddr.o: addr.h defs.h
- Xbuiltins.o: builtin.h config.h defs.h sconf.h server.h
- Xchild.o: attr.h config.h sconst.h server.h state.h $(OPT_HEADER)
- Xconf.o: attr.h conf.h config.h defs.h service.h state.h
- Xconfparse.o: attr.h config.h conf.h defs.h parse.h sconst.h sconf.h state.h
- Xconnection.o: connection.h service.h state.h
- Xsconf.o: addr.h attr.h defs.h sconf.h state.h
- Xenv.o: attr.h defs.h sconf.h
- Xflags.o: defs.h flags.h state.h
- Xident.o: defs.h sconst.h server.h
- Xinit.o: defs.h conf.h config.h state.h $(OPT_HEADER)
- Xint.o: config.h connection.h defs.h int.h server.h service.h
- Xintcommon.o: config.h defs.h int.h server.h service.h state.h
- Xinternals.o: config.h flags.h server.h service.h state.h
- Xlog.o: access.h defs.h connection.h sconst.h server.h service.h
- Xlogctl.o: config.h defs.h log.h service.h state.h
- Xmain.o: service.h state.h $(OPT_HEADER)
- Xmsg.o: config.h defs.h state.h $(OPT_HEADER)
- Xnvlists.o: defs.h sconf.h
- Xparse.o: addr.h attr.h conf.h defs.h parse.h service.h
- Xparsesup.o: defs.h parse.h
- Xparsers.o: addr.h config.h defs.h parse.h sconf.h
- Xreconfig.o: access.h conf.h config.h defs.h server.h service.h state.h
- Xretry.o: access.h config.h connection.h flags.h server.h state.h
- Xserver.o: access.h config.h connection.h server.h state.h
- Xservice.o: access.h attr.h config.h connection.h defs.h \
- X server.h service.h state.h $(OPT_HEADER)
- Xshutdown.o: defs.h
- Xsignals.o: config.h defs.h flags.h state.h
- Xspecial.o: builtin.h conf.h config.h connection.h \
- X server.h sconst.h state.h $(OPT_HEADER)
- Xtcpint.o: access.h config.h defs.h int.h
- Xtime.o: defs.h
- Xudpint.o: access.h defs.h int.h
- Xutil.o: config.h defs.h
- X
- END_OF_FILE
- if test 9823 -ne `wc -c <'xinetd/Makefile'`; then
- echo shar: \"'xinetd/Makefile'\" unpacked with wrong size!
- fi
- # end of 'xinetd/Makefile'
- fi
- if test -f 'xinetd/addr.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/addr.c'\"
- else
- echo shar: Extracting \"'xinetd/addr.c'\" \(10437 characters\)
- sed "s/^X//" >'xinetd/addr.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: addr.c,v 6.4 1993/06/06 00:06:13 panos Exp $" ;
- X
- X#include <sys/types.h>
- X#include <sys/socket.h>
- X#include <netinet/in.h>
- X#include <syslog.h>
- X#include <netdb.h>
- X#include <memory.h>
- X
- X#include "pset.h"
- X
- X#include "defs.h"
- X#include "addr.h"
- X
- Xunsigned long inet_addr() ;
- Xchar *malloc() ;
- Xint free() ;
- X
- Xvoid msg() ;
- Xvoid parsemsg() ;
- Xvoid out_of_memory() ;
- X
- X#define OPEN_CURLY_BRACKET '{'
- X#define CLOSED_CURLY_BRACKET '}'
- X#define COMMA ','
- X#define DOT '.'
- X
- X/*
- X * address types denote how the actual numeric address was obtained.
- X * Currently they are only useful for debugging.
- X * Note that NUMERIC_ADDR includes both simple (e.g. 128.138.91.1) and
- X * factorized symbolic addresses (e.g. 128.138.91.{1,2,3}).
- X */
- Xtypedef enum { NUMERIC_ADDR, NET_ADDR, HOST_ADDR } address_e ;
- X
- Xtypedef enum { CANT_PARSE, PARSED, ERROR } result_e ;
- X
- Xstruct comp_addr
- X{
- X address_e addr_type ;
- X unsigned long addr ;
- X unsigned long mask ;
- X} ;
- X
- X#define CAP( p ) ( (struct comp_addr *) (p) )
- X
- X
- X#define NEW_CAP() NEW( struct comp_addr )
- X#define FREE_CAP( cap ) FREE( cap )
- X
- X
- X/*
- X * Try to match the given address 'addr' with the specified address list.
- X * Returns TRUE if the address matched, FALSE otherwise.
- X * If the address matched, '*matchp' will hold the mask of the matching
- X * address (a greater numerical value for the mask implies a more
- X * precise match).
- X */
- Xbool_int addrlist_match( addr_list, addr, matchp )
- X pset_h addr_list ;
- X struct in_addr *addr ;
- X unsigned long *matchp ;
- X{
- X register unsigned long remote_addr = ntohl( addr->s_addr ) ;
- X register unsigned u ;
- X
- X for ( u = 0 ; u < pset_count( addr_list ) ; u++ )
- X {
- X register struct comp_addr *cap = CAP( pset_pointer( addr_list, u ) ) ;
- X
- X if ( ( remote_addr & cap->mask ) == cap->addr )
- X {
- X *matchp = cap->mask ;
- X return( TRUE ) ;
- X }
- X }
- X return( FALSE ) ;
- X}
- X
- X
- X
- Xvoid addrlist_dump( addr_list, fd )
- X pset_h addr_list ;
- X int fd ;
- X{
- X register unsigned u ;
- X struct in_addr inaddr ;
- X char *inet_ntoa() ;
- X
- X for ( u = 0 ; u < pset_count( addr_list ) ; u++ )
- X {
- X struct comp_addr *cap = CAP( pset_pointer( addr_list, u ) ) ;
- X char *type ;
- X
- X inaddr.s_addr = htonl( cap->addr ) ;
- X if ( cap->addr_type == NUMERIC_ADDR )
- X type = "NUMERIC" ;
- X else if ( cap->addr_type == NET_ADDR )
- X type = "NET" ;
- X else if ( cap->addr_type == HOST_ADDR )
- X type = "HOST" ;
- X else
- X type = "BAD" ;
- X
- X Sprint( fd, " %s(%s)", inet_ntoa( inaddr ), type ) ;
- X }
- X}
- X
- X
- Xvoid addrlist_free( addr_list )
- X pset_h addr_list ;
- X{
- X pset_apply( addr_list, free, NULL ) ;
- X}
- X
- X
- X
- X/*
- X * Add an address to the address list
- X */
- XPRIVATE status_e add( addr_list, cap )
- X pset_h addr_list ;
- X struct comp_addr *cap ;
- X{
- X struct comp_addr *new_cap ;
- X char *func = "add" ;
- X
- X new_cap = NEW_CAP() ;
- X if ( new_cap == NULL )
- X {
- X out_of_memory( func ) ;
- X return( FAILED ) ;
- X }
- X
- X *new_cap = *cap ;
- X if ( pset_add( addr_list, new_cap ) == NULL )
- X {
- X out_of_memory( func ) ;
- X FREE_CAP( new_cap ) ;
- X return( FAILED ) ;
- X }
- X return( OK ) ;
- X}
- X
- X
- X/*
- X * Find the address and remove it from the list
- X * Since there is no check when we add entries that an
- X * address is not entered twice, in this function we remove all
- X * addresses that match.
- X *
- X * XXX: we need to work on the way two cap's are considered equal
- X */
- XPRIVATE status_e remove( addr_list, cap )
- X pset_h addr_list ;
- X register struct comp_addr *cap ;
- X{
- X register unsigned u = 0 ;
- X register struct comp_addr *old_cap ;
- X
- X for ( u = 0 ; u < pset_count( addr_list ) ; u++ )
- X {
- X old_cap = CAP( pset_pointer( addr_list, u ) ) ;
- X
- X if ( old_cap->addr == cap->addr && old_cap->mask == cap->mask )
- X {
- X pset_pointer( addr_list, u ) = NULL ;
- X FREE_CAP( old_cap ) ;
- X }
- X }
- X pset_compact( addr_list ) ;
- X return( OK ) ;
- X}
- X
- X
- X/*
- X * Try to parse 'str_addr' as a symbolic net name
- X */
- XPRIVATE result_e net_addr( str_addr, op, addr_list )
- X char *str_addr ;
- X statfunc op ;
- X pset_h addr_list ;
- X{
- X /*
- X *
- X * The following table demonstrates how the mask is determined
- X * given a net number N and following the relation:
- X * net #1 <= N <= #2
- X *
- X * net #1 net #2 mask
- X * 0 0 FFFFFFFF (this should be rejected)
- X * 1 FF FF000000
- X * 100 FFFF FFFF0000
- X * 10000 FFFFFF FFFFFF00
- X * 1000000 FFFFFFFF FFFFFFFF
- X */
- X static struct { int lim, mask, shift ; } net_to_mask[] =
- X {
- X { 0, 0xFF000000, 24 },
- X { 0xFF, 0xFFFF0000, 16 },
- X { 0xFFFF, 0xFFFFFF00, 8 },
- X { 0xFFFFFF, 0xFFFFFFFF, 0 },
- X { 0xFFFFFFFF, 0, 0 }
- X } ;
- X struct comp_addr ca ;
- X struct netent *nep ;
- X register unsigned long net_num ;
- X int i ;
- X char *func = "net_addr" ;
- X
- X nep = getnetbyname( str_addr ) ;
- X if ( nep == NULL || nep->n_addrtype != AF_INET || nep->n_net == 0 )
- X return( CANT_PARSE ) ;
- X
- X for ( i = 0, net_num = (unsigned long) nep->n_net ;; i++ )
- X {
- X if ( net_to_mask[ i ].mask == 0 )
- X {
- X msg( LOG_CRIT, func,
- X "INTERNAL ERROR: Cannot process net number %ld", net_num ) ;
- X return( ERROR ) ;
- X }
- X if ( net_to_mask[i].lim < net_num && net_num <= net_to_mask[i+1].lim )
- X {
- X ca.addr_type = NET_ADDR ;
- X ca.addr = net_num << net_to_mask[ i ].shift ;
- X ca.mask = net_to_mask[ i ].mask ;
- X return( ( (*op)( addr_list, &ca ) == OK ) ? PARSED : ERROR ) ;
- X }
- X }
- X}
- X
- X
- X
- X/*
- X * Try to parse 'str_addr' as a numeric address
- X */
- XPRIVATE result_e numeric_addr( str_addr, op, addr_list )
- X char *str_addr ;
- X status_e (*op)() ;
- X pset_h addr_list ;
- X{
- X register unsigned long addr ;
- X register unsigned long mask ;
- X struct comp_addr ca ;
- X
- X addr = inet_addr( str_addr ) ;
- X if ( addr == (unsigned long) -1 )
- X return( CANT_PARSE ) ;
- X
- X if ( addr == 0 )
- X mask = 0 ; /* i.e. matches everything */
- X else
- X {
- X for ( mask = 0xFF ;; )
- X {
- X if ( addr & mask )
- X break ;
- X mask <<= 8 ;
- X mask |= 0xFF ;
- X }
- X mask = ~( mask >> 8 ) ;
- X }
- X ca.mask = mask ;
- X ca.addr = addr ;
- X ca.addr_type = NUMERIC_ADDR ;
- X return( ( (*op)( addr_list, &ca ) == OK ) ? PARSED : ERROR ) ;
- X}
- X
- X
- X
- X/*
- X * Try to parse 'str_addr' as a symbolic host name
- X * Apply 'op' to the 'addrlist' for *all* IP addresses of the host
- X */
- XPRIVATE result_e host_addr( str_addr, op, addr_list )
- X char *str_addr ;
- X status_e (*op)() ;
- X pset_h addr_list ;
- X{
- X struct hostent *hep ;
- X struct comp_addr ca ;
- X char **ap ;
- X
- X hep = gethostbyname( str_addr ) ;
- X if ( hep == NULL || hep->h_addrtype != AF_INET )
- X return( CANT_PARSE ) ;
- X
- X ca.addr_type = HOST_ADDR ;
- X for ( ap = hep->h_addr_list ; *ap ; ap++ )
- X {
- X struct in_addr inaddr ;
- X
- X /*
- X * Copy the address to avoid alignment problems
- X */
- X (void) memcpy( (char *) &inaddr, *ap, hep->h_length ) ;
- X
- X ca.addr = ntohl( inaddr.s_addr ) ;
- X ca.mask = 0xFFFFFFFF ;
- X if ( (*op)( addr_list, &ca ) == FAILED )
- X return( ERROR ) ;
- X }
- X return( PARSED ) ;
- X}
- X
- X
- X/*
- X * Try to parse 'str_addr' as a factorized address
- X * (for example, 128.138.{200,201})
- X *
- X * XXX: It is unclear whether this function should exist. It is really doing
- X * the job of a preprocessor.
- X */
- XPRIVATE result_e factorized_addr( str_addr, op, addr_list )
- X char *str_addr ;
- X status_e (*op)() ;
- X pset_h addr_list ;
- X{
- X char *p ;
- X char *fact_start ;
- X int pass ;
- X char last = DOT ;
- X unsigned num = 0 ;
- X int shift = 24 ; /* because we assume a 32-bit IP address */
- X register unsigned long addr = 0 ;
- X struct comp_addr ca ;
- X char *func = "factorized_addr" ;
- X
- X for ( p = str_addr ; *p != OPEN_CURLY_BRACKET ; last = *p++ )
- X {
- X if ( isdigit( *p ) )
- X {
- X num = num * 10 + *p - '0' ;
- X continue ;
- X }
- X switch ( *p )
- X {
- X case DOT:
- X if ( last == DOT )
- X {
- X parsemsg( LOG_ERR, func,
- X "Bad address: %s. Consecutive dots", str_addr ) ;
- X return( ERROR ) ;
- X }
- X addr = addr * 256 + num ;
- X num = 0 ;
- X shift -= 8 ;
- X break ;
- X
- X default:
- X return( CANT_PARSE ) ;
- X }
- X }
- X
- X ca.addr_type = NUMERIC_ADDR ;
- X fact_start = p+1 ;
- X if ( addr != 0 )
- X addr <<= ( shift+8 ) ;
- X
- X /*
- X * First pass is for syntax checking
- X */
- X for ( pass = 0 ; pass < 2 ; pass++ )
- X {
- X num = 0 ;
- X for ( p = fact_start, last = COMMA ;; last = *p++ )
- X {
- X if ( isdigit( *p ) )
- X {
- X num = num * 10 + *p - '0' ;
- X continue ;
- X }
- X switch ( *p )
- X {
- X case COMMA:
- X case CLOSED_CURLY_BRACKET:
- X if ( last == COMMA )
- X {
- X parsemsg( LOG_ERR, func,
- X "Bad address: %s. Consecutive commas", str_addr ) ;
- X return( ERROR ) ;
- X }
- X
- X if ( pass == 1 )
- X {
- X ca.addr = addr + ( num << shift ) ;
- X ca.mask = ~( ( 1 << shift ) - 1 ) ;
- X if ( (*op)( addr_list, &ca ) == FAILED )
- X return( ERROR ) ;
- X num = 0 ;
- X }
- X break ;
- X
- X default:
- X parsemsg( LOG_ERR, func, "Bad address: %s", str_addr ) ;
- X return( ERROR ) ;
- X }
- X if ( *p == CLOSED_CURLY_BRACKET )
- X {
- X if ( p[1] != NUL )
- X {
- X parsemsg( LOG_ERR, func, "Bad address: %s", str_addr ) ;
- X return( ERROR ) ;
- X }
- X
- X if ( pass == 0 )
- X break ;
- X else
- X return( PARSED ) ;
- X }
- X }
- X }
- X /* NOTREACHED */
- X}
- X
- X
- X/*
- X * Try to parse 'str_addr' using all known methods.
- X * Try until one of the methods succeeds.
- X * A successful method will apply 'op' with the parsed address to the
- X * 'addr_list'. The 'op' can be either 'add' or 'remove'
- X * This means that the parsed address will be either added or removed
- X * from the addr_list.
- X */
- XPRIVATE status_e addrlist_op( addr_list, op, str_addr )
- X pset_h addr_list ;
- X status_e (*op)() ;
- X char *str_addr ;
- X{
- X int i ;
- X static result_e (*addr_parser[])() =
- X {
- X numeric_addr,
- X factorized_addr,
- X net_addr,
- X host_addr,
- X NULL
- X } ;
- X char *func = "addrlist_op" ;
- X
- X for ( i = 0 ; addr_parser[ i ] != NULL ; i++ )
- X switch ( (*addr_parser[ i ])( str_addr, op, addr_list ) )
- X {
- X case PARSED:
- X return( OK ) ;
- X
- X case ERROR:
- X return( FAILED ) ;
- X }
- X
- X parsemsg( LOG_ERR, func, "failed to parse %s", str_addr ) ;
- X return( OK ) ;
- X}
- X
- X
- Xstatus_e addrlist_add( addr_list, str_addr )
- X pset_h addr_list ;
- X char *str_addr ;
- X{
- X return( addrlist_op( addr_list, add, str_addr ) ) ;
- X}
- X
- X
- Xstatus_e addrlist_remove( addr_list, str_addr )
- X pset_h addr_list ;
- X char *str_addr ;
- X{
- X return( addrlist_op( addr_list, remove, str_addr ) ) ;
- X}
- X
- X
- Xstatus_e addrlist_copy( from, to )
- X pset_h from ;
- X pset_h *to ;
- X{
- X status_e copy_pset() ;
- X
- X return( copy_pset( from, to, sizeof( struct comp_addr ) ) ) ;
- X}
- X
- END_OF_FILE
- if test 10437 -ne `wc -c <'xinetd/addr.c'`; then
- echo shar: \"'xinetd/addr.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/addr.c'
- fi
- echo shar: End of archive 19 \(of 31\).
- cp /dev/null ark19isdone
- 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
-