home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / xinetd21 / part08 < prev    next >
Encoding:
Text File  |  1993-06-26  |  32.9 KB  |  1,423 lines

  1. Newsgroups: comp.sources.unix
  2. From: panos@cs.colorado.edu (Panos Tsirigotis)
  3. Subject: v26i252: xinetd-2.1.1 - inetd replacement with access control and logging, Part08/31
  4. Sender: unix-sources-moderator@gw.home.vix.com
  5. Approved: vixie@gw.home.vix.com
  6.  
  7. Submitted-By: panos@cs.colorado.edu (Panos Tsirigotis)
  8. Posting-Number: Volume 26, Issue 252
  9. Archive-Name: xinetd-2.1.1/part08
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 8 (of 31)."
  18. # Contents:  libs/src/sio/suite/tester libs/src/timer/Makefile
  19. #   libs/src/xlog/slog.c xinetd/defs.h xinetd/env.c xinetd/logctl.c
  20. #   xinetd/util.c
  21. # Wrapped by panos@mystique on Mon Jun 21 14:51:22 1993
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'libs/src/sio/suite/tester' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'libs/src/sio/suite/tester'\"
  25. else
  26. echo shar: Extracting \"'libs/src/sio/suite/tester'\" \(3971 characters\)
  27. sed "s/^X//" >'libs/src/sio/suite/tester' <<'END_OF_FILE'
  28. X#!/bin/sh
  29. X
  30. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  31. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  32. X# and conditions for redistribution.
  33. X
  34. X
  35. X#
  36. X# $Id: tester,v 8.2 1993/03/17 18:53:40 panos Exp $
  37. X#
  38. X
  39. X#
  40. X# Usage:
  41. X#            tester [all] [function-name function-name ...]
  42. X#
  43. X# function-name is the name of a sio function (or macro)
  44. X#
  45. X# If "all" is used, functions after it will *not* be tested.
  46. X#
  47. X
  48. Xscript_name=`basename $0`
  49. X
  50. Xcopy_file=/usr/dict/words
  51. Xtemp_file=/tmp/w
  52. Xmake_log=MAKE.LOG
  53. X
  54. Xif test ! -f $copy_file ; then
  55. X    echo "The file '$copy_file' is not available."
  56. X    echo "Please edit the '$script_name' script and change set the"
  57. X    echo "variable 'copy_file' to the name of a publicly readable file"
  58. X    echo "with at least a few tens of thousands of lines."
  59. X    exit 1
  60. Xfi
  61. X
  62. Xtrap_function()
  63. X{
  64. X    rm -f $temp_file $make_log
  65. X    echo
  66. X    exit 1
  67. X}
  68. X
  69. X
  70. Xmake_program()
  71. X{
  72. X    target=$1
  73. X    cflags="$2"
  74. X    if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
  75. X    if test "$cflags"
  76. X    then
  77. X        make -s "$cflags" $target >$make_log 2>&1
  78. X    else
  79. X        make -s $target >$make_log 2>&1
  80. X    fi
  81. X    exit_code=$?
  82. X    if test $exit_code -eq 0 -a -x $1
  83. X    then
  84. X        rm -f $make_log
  85. X    else
  86. X        echo "FAILED"
  87. X        echo "   The make failed. Check the make log file << $make_log >>"
  88. X        exit
  89. X    fi
  90. X}
  91. X
  92. X
  93. X
  94. X#
  95. X# test_function expects a single argument, the name of the function
  96. X# it will test.
  97. X# It creates a program that has the name of the function by invoking
  98. X# make with the symbol -DTEST_<function_name>
  99. X#
  100. Xtest_function()
  101. X{
  102. X    expression="echo $"$1
  103. X    var=`eval $expression`
  104. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  105. X
  106. X    echo -n "TESTING $1 "
  107. X    make_program $1 "CFLAGS=-g -DTEST_$1"
  108. X
  109. X    ./$1 < $copy_file >$temp_file
  110. X    exit_code=$?
  111. X    if test $exit_code -ne 0
  112. X    then
  113. X        echo "FAILED"
  114. X        echo "   Test program exited with exit code $exit_code"
  115. X        echo "   Temporary file << $temp_file >> not deleted"
  116. X        exit
  117. X    fi
  118. X    cmp -s $copy_file $temp_file
  119. X    if test $? -ne 0
  120. X    then
  121. X        echo "FAILED"
  122. X        echo "   The files << $copy_file >> and << $temp_file >> are not the same"
  123. X        exit
  124. X    else
  125. X        echo PASSED
  126. X    fi
  127. X    rm -f $temp_file
  128. X}
  129. X
  130. X
  131. Xtest_sprint()
  132. X{
  133. X    var=$Sprint
  134. X    program=Sprint
  135. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  136. X
  137. X    echo TESTING Sprint
  138. X    make_program $program ""
  139. X    $TESTSHELL sprint_test
  140. X}
  141. X
  142. X
  143. Xtest_smorefds()
  144. X{
  145. X    var=$Smorefds
  146. X    program=fdtest
  147. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  148. X
  149. X    echo -n "TESTING Smorefds "
  150. X    make_program $program "CFLAGS=-g"
  151. X    v=`fdtest 2>&1`
  152. X    if test $? -eq 0 ; then
  153. X        echo PASSED
  154. X    else
  155. X        echo "FAILED: $v"
  156. X    fi
  157. X}
  158. X
  159. X
  160. Xtrap trap_function 1 2 3 15
  161. X
  162. X#
  163. X# There is a variable for every function to be tested. That variable
  164. X# can have the values "yes", "no" or "".
  165. X# When a function is specified, it takes the value of $run. Initially $run 
  166. X# is "yes", so a specified function has its variable set to "yes". 
  167. X# If "all" is specified, $run becomes "no", so subsequently specified
  168. X# functions, have their variables set to "no".
  169. X#
  170. X# We test a function iff:
  171. X#        its variable is "yes" OR its variable is "" and $all is "yes"
  172. X# We don't test a function iff:
  173. X#        its variable is "no" OR its variable is "" and $all is "no"
  174. X#        
  175. X# Therefore, all functions specified after "all" will NOT be tested.
  176. X#
  177. Xrun=yes
  178. Xall=no
  179. X
  180. Xwhile test $# -gt 0
  181. Xdo
  182. X    case $1 in
  183. X        Sputchar)    Sputchar=$run ;;
  184. X        Sgetchar)    Sgetchar=$run ;;
  185. X        Srdline)        Srdline=$run ;;
  186. X        Sfetch)        Sfetch=$run ;;
  187. X        Sread)        Sread=$run ;;
  188. X        Swrite)        Swrite=$run ;;
  189. X        Sgetc)        Sgetc=$run ;;
  190. X        Sputc)        Sputc=$run ;;
  191. X        Sflush)        Sflush=$run ;;
  192. X        Sundo)        Sundo=$run ;;
  193. X        Sprint)        Sprint=$run ;;
  194. X        switch)        switch=$run ;;
  195. X        switch2)        switch2=$run ;;
  196. X        Smorefds)    Smorefds=$run ;;
  197. X        all)            all=yes ; run="no" ;;
  198. X        *) echo Bad argument: $1
  199. X    esac
  200. X    shift
  201. Xdone
  202. X
  203. Xtest_function Sgetchar
  204. Xtest_function Sputchar
  205. Xtest_function Sread
  206. Xtest_function Swrite
  207. Xtest_function Srdline
  208. Xtest_function Sfetch
  209. Xtest_function Sgetc
  210. Xtest_function Sputc
  211. Xtest_function Sflush
  212. Xtest_function Sundo
  213. Xtest_function switch
  214. Xtest_function switch2
  215. Xtest_smorefds
  216. Xtest_sprint
  217. X
  218. END_OF_FILE
  219. if test 3971 -ne `wc -c <'libs/src/sio/suite/tester'`; then
  220.     echo shar: \"'libs/src/sio/suite/tester'\" unpacked with wrong size!
  221. fi
  222. # end of 'libs/src/sio/suite/tester'
  223. fi
  224. if test -f 'libs/src/timer/Makefile' -a "${1}" != "-c" ; then 
  225.   echo shar: Will not clobber existing file \"'libs/src/timer/Makefile'\"
  226. else
  227. echo shar: Extracting \"'libs/src/timer/Makefile'\" \(3929 characters\)
  228. sed "s/^X//" >'libs/src/timer/Makefile' <<'END_OF_FILE'
  229. X# (c) Copyright 1993 by Panagiotis Tsirigotis
  230. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  231. X# and conditions for redistribution.
  232. X
  233. X#
  234. X# $Id: Makefile,v 4.6 1993/06/20 20:05:28 panos Exp $
  235. X#
  236. X# Based on Library makefile template: *Revision: 1.15 *
  237. X#
  238. X
  239. X# 
  240. X# Available entries:
  241. X#         lib             --> creates the library
  242. X#        install        --> installs the library (archive, man page(s), header(s))
  243. X#        uninstall    --> uninstall the library
  244. X#        clean            --> removes all .o and .a files
  245. X#        spotless        --> clean + uninstall
  246. X#         lint            --> lints a file (usage: make lint MODULE=foo.c)
  247. X#        tags            --> creates a tags file (from the SOURCES and HEADERS)
  248. X#        checkout     --> checkout all files
  249. X#        dist            --> distribution support
  250. X#
  251. X
  252. XNAME                = timer
  253. XVERSION            = 1.2.2
  254. X
  255. XHEADERS            = timer.h impl.h ostimer.h timemacros.h defs.h
  256. XSOURCES            = timer.c ostimer.c sysdep.c
  257. XOBJECTS            = timer.o ostimer.o sysdep.o
  258. X
  259. XMANFILES            = timer.3 timemacros.3
  260. XINCLUDEFILES    = timer.h timemacros.h
  261. X
  262. X# The following variables are used by the 'install' entry and
  263. X# should be customized:
  264. X#     LIBDIR:     where the library will be placed
  265. X#     INCUDEDIR:  where the include files will be placed
  266. X#     MANDIR:     where the man pages will be placed
  267. X#
  268. XLIBDIR            = $(HOME)/.links/libraries/$(ARCH)
  269. XMANDIR            = $(HOME)/.links/manpages/man3
  270. XINCLUDEDIR        = $(HOME)/.links/includes
  271. X
  272. X#
  273. X# Available flags:
  274. X#
  275. X#    DEBUG                :    enable some debugging code
  276. X#    NO_TERMINATION    :    do not terminate if an error is discovered
  277. X#    DEBUG_MSGS        :    print debugging messages
  278. X#    NO_POSIX_SIGS    :    sigaction is not available (but sigvec is)
  279. X#
  280. XDEFS                =    -DDEBUG -DNO_POSIX_SIGS
  281. XDEBUG                = -g            # -g or -O
  282. XVERSION_DEF        = -DVERSION=\"TIMER\ Version\ $(VERSION)\"
  283. X
  284. XCPP_DEFS            = -I$(INCLUDEDIR) $(VERSION_DEF) $(DEFS)
  285. X
  286. X#
  287. X# The following variables shouldn't need to be changed
  288. X#
  289. XLINT_FLAGS        = -hbux
  290. XCPP_FLAGS        = $(CPP_DEFS) -I$(INCLUDEDIR)
  291. XCC_FLAGS            = $(DEBUG)
  292. XCFLAGS            = $(CPP_FLAGS) $(CC_FLAGS)
  293. X
  294. XINSTALL            = install -c
  295. XFMODE                = -m 640            # used by install
  296. XRANLIB            = ranlib
  297. X
  298. XPAGER                = less
  299. X
  300. X
  301. XLIBNAME            = lib$(NAME).a
  302. X
  303. Xlib: $(LIBNAME)
  304. X
  305. Xlibopt: clean
  306. X    make DEBUG=-O lib
  307. X    $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)/optimized
  308. X
  309. X$(LIBNAME): $(OBJECTS)
  310. X    ar r $@ $?
  311. X    $(RANLIB) $@
  312. X
  313. Xlint:
  314. X    lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | $(PAGER)
  315. X
  316. Xinstall: $(LIBNAME)
  317. X    @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
  318. X    then \
  319. X        $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
  320. X        echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
  321. X        for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
  322. X        echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
  323. X        for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
  324. X        echo Installed $(MANFILES) to $(MANDIR) ;\
  325. X    else \
  326. X        echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
  327. X    fi
  328. X
  329. Xuninstall:
  330. X    a=`pwd` ; cd $(INCLUDEDIR) ;\
  331. X    if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
  332. X    a=`pwd` ; cd $(LIBDIR) ;\
  333. X    if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
  334. X    a=`pwd` ; cd $(MANDIR) ;\
  335. X    if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
  336. X
  337. Xclean:
  338. X    rm -f $(OBJECTS) $(LIBNAME) core
  339. X
  340. Xspotless: clean uninstall
  341. X
  342. Xtags: $(SOURCES) $(HEADERS)
  343. X    ctags -w $(SOURCES) $(HEADERS)
  344. X
  345. Xcheckout:
  346. X    co $(SOURCES) $(HEADERS) $(MANFILES)
  347. X
  348. X#
  349. X# Distribution section
  350. X# This section contains the 2 targets for distribution support: dist, dirs
  351. X# "dist" checks out all files to be distributed
  352. X# "dirs" prints a list of directories to be included in the distribution.
  353. X# These directories should have a Makefile with a "dist" target
  354. X#
  355. XDISTRIBUTION_FILES    = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT
  356. XDIRS                        =
  357. X
  358. Xdist:
  359. X    -co -q $(DISTRIBUTION_FILES)
  360. X
  361. Xdirs:
  362. X    @echo $(DIRS)
  363. X
  364. X#
  365. X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
  366. X#
  367. Xtimer.o: timemacros.h impl.h timer.h defs.h
  368. Xostimer.o: ostimer.h timemacros.h impl.h timer.h defs.h
  369. Xsysdep.o: ostimer.h timemacros.h impl.h timer.h defs.h
  370. X
  371. Xttest: ttest.c $(LIBNAME)
  372. X    cc $(DEBUG) -o $@ ttest.c $(LIBNAME) -L$(LIBDIR) -lpq
  373. X
  374. END_OF_FILE
  375. if test 3929 -ne `wc -c <'libs/src/timer/Makefile'`; then
  376.     echo shar: \"'libs/src/timer/Makefile'\" unpacked with wrong size!
  377. fi
  378. # end of 'libs/src/timer/Makefile'
  379. fi
  380. if test -f 'libs/src/xlog/slog.c' -a "${1}" != "-c" ; then 
  381.   echo shar: Will not clobber existing file \"'libs/src/xlog/slog.c'\"
  382. else
  383. echo shar: Extracting \"'libs/src/xlog/slog.c'\" \(3955 characters\)
  384. sed "s/^X//" >'libs/src/xlog/slog.c' <<'END_OF_FILE'
  385. X/*
  386. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  387. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  388. X * and conditions for redistribution.
  389. X */
  390. X
  391. Xstatic char RCSid[] = "$Id: slog.c,v 2.2 1993/06/15 18:08:16 panos Exp $" ;
  392. X
  393. X#ifndef NO_SYSLOG
  394. X#include <syslog.h>
  395. X#endif
  396. X#include <varargs.h>
  397. X
  398. X#include "xlog.h"
  399. X#include "impl.h"
  400. X#include "slog.h"
  401. X
  402. X#define MSGBUFSIZE            2048
  403. X
  404. X
  405. XPRIVATE int syslog_init() ;
  406. XPRIVATE void syslog_fini() ;
  407. XPRIVATE int syslog_control() ;
  408. XPRIVATE int syslog_write() ;
  409. XPRIVATE int syslog_parms() ;
  410. X
  411. Xstatic struct syslog_parms parms =
  412. X   {
  413. X      0,
  414. X#ifndef NO_SYSLOG
  415. X      LOG_PID + LOG_NOWAIT,
  416. X      LOG_USER,
  417. X#else
  418. X        0,
  419. X        0,
  420. X#endif
  421. X      "XLOG",
  422. X        FALSE
  423. X   } ;
  424. X
  425. X
  426. Xstruct xlog_ops __xlog_syslog_ops =
  427. X    {
  428. X        syslog_init,
  429. X        syslog_fini,
  430. X        syslog_write,
  431. X        syslog_control,
  432. X        syslog_parms
  433. X    } ;
  434. X
  435. X#ifdef NO_SYSLOG
  436. X
  437. X/*
  438. X * Notice that the following functions will never be invoked since
  439. X * the xlog_* functions will not call them. However, we need to define
  440. X * them so that we don't have any unresolved references; and we define 
  441. X * them without any arguments.
  442. X */
  443. XPRIVATE void syslog()
  444. X{
  445. X}
  446. X
  447. XPRIVATE void openlog()
  448. X{
  449. X}
  450. X
  451. XPRIVATE void closelog()
  452. X{
  453. X}
  454. X
  455. X#else
  456. X
  457. Xvoid closelog() ;
  458. X
  459. X#endif    /* NO_SYSLOG */
  460. X
  461. X
  462. X/*
  463. X * Expected arguments:
  464. X *        facility, level
  465. X */
  466. XPRIVATE int syslog_init( xp, ap )
  467. X    xlog_s    *xp ;
  468. X    va_list    ap ;
  469. X{
  470. X    register struct syslog_parms    *slp = &parms ;
  471. X    struct syslog                        *sp ;
  472. X
  473. X    sp = NEW( struct syslog ) ;
  474. X    if ( sp == NULL )
  475. X        return( XLOG_ENOMEM ) ;
  476. X    
  477. X    sp->sl_facility = va_arg( ap, int ) ;
  478. X    sp->sl_default_level = va_arg( ap, int ) ;
  479. X    if ( slp->slp_n_xlogs++ == 0 )
  480. X        openlog( slp->slp_ident, slp->slp_logopts, slp->slp_facility ) ;
  481. X    xp->xl_data = sp ;
  482. X    return( XLOG_ENOERROR ) ;
  483. X}
  484. X
  485. X
  486. XPRIVATE void syslog_fini( xp )
  487. X    xlog_s *xp ;
  488. X{
  489. X    if ( --parms.slp_n_xlogs == 0 )
  490. X        closelog() ;
  491. X    FREE( SYSLOG( xp ) ) ;
  492. X    xp->xl_data = NULL ;
  493. X}
  494. X
  495. X
  496. XPRIVATE int syslog_control( xp, cmd, ap )
  497. X    xlog_s        *xp ;
  498. X    xlog_cmd_e    cmd ;
  499. X    va_list        ap ;
  500. X{
  501. X    switch ( cmd )
  502. X    {
  503. X        case XLOG_LEVEL:
  504. X            SYSLOG( xp )->sl_default_level = va_arg( ap, int ) ;
  505. X            break ;
  506. X
  507. X        case XLOG_FACILITY:
  508. X            SYSLOG( xp )->sl_facility = va_arg( ap, int ) ;
  509. X            break ;
  510. X        
  511. X        case XLOG_PREEXEC:
  512. X            closelog() ;
  513. X            break ;
  514. X
  515. X        case XLOG_POSTEXEC:
  516. X            if ( parms.slp_n_xlogs )
  517. X                openlog( parms.slp_ident, parms.slp_logopts, parms.slp_facility ) ;
  518. X            break ;
  519. X    }
  520. X    return( XLOG_ENOERROR ) ;
  521. X}
  522. X
  523. X
  524. XPRIVATE int syslog_write( xp, buf, len, flags, ap )
  525. X    xlog_s    *xp ;
  526. X    char        buf[] ;
  527. X    int        len ;
  528. X    int        flags ;
  529. X    va_list    ap ;
  530. X{
  531. X    int    level ;
  532. X    int    syslog_arg ;
  533. X    char    prefix[ MSGBUFSIZE ] ;
  534. X    int    prefix_size = sizeof( prefix ) ;
  535. X    int    prefix_len = 0 ;
  536. X    int    cc ;
  537. X    char    *percent_m_pos ;
  538. X    int    action_flags = ( flags | xp->xl_flags ) ;
  539. X
  540. X    if ( flags & XLOG_SET_LEVEL )
  541. X        level = va_arg( ap, int ) ;
  542. X    else
  543. X        level = SYSLOG( xp )->sl_default_level ;
  544. X    syslog_arg = SYSLOG( xp )->sl_facility + level ;
  545. X
  546. X    if ( action_flags & XLOG_PRINT_ID )
  547. X    {
  548. X        cc = strx_nprint( &prefix[ prefix_len ], prefix_size, "%s: ",
  549. X                            xp->xl_id ) ;
  550. X        prefix_len += cc ;
  551. X        prefix_size -= cc ;
  552. X    }
  553. X
  554. X    if ( ( action_flags & XLOG_NO_ERRNO ) ||
  555. X                        ( percent_m_pos = __xlog_add_errno( buf, len ) ) == NULL )
  556. X        syslog( syslog_arg, "%.*s%.*s", prefix_len, prefix, len, buf ) ;
  557. X    else
  558. X    {
  559. X        int cc_before_errno = percent_m_pos - buf ;
  560. X        int cc_after_errno = len - cc_before_errno - 2 ;
  561. X        char *ep ;
  562. X        char errno_buf[ 100 ] ;
  563. X        unsigned size = sizeof( errno_buf ) ;
  564. X        
  565. X        ep = __xlog_explain_errno( errno_buf, &size ) ;
  566. X        syslog( syslog_arg, "%.*s%.*s%.*s%.*s",
  567. X                prefix_len, prefix,
  568. X                    cc_before_errno, buf,
  569. X                        (int)size, ep,
  570. X                            cc_after_errno, &percent_m_pos[ 2 ] ) ;
  571. X    }
  572. X    return( XLOG_ENOERROR ) ;
  573. X}
  574. X
  575. X
  576. XPRIVATE int syslog_parms( ap )
  577. X    va_list ap ;
  578. X{
  579. X    char *__xlog_new_string() ;
  580. X    char *id = __xlog_new_string( va_arg( ap, char * ) ) ;
  581. X
  582. X    if ( id == NULL )
  583. X        return( XLOG_ENOMEM ) ;
  584. X    parms.slp_ident = id ;
  585. X    parms.slp_logopts = va_arg( ap, int ) ;
  586. X    parms.slp_facility = va_arg( ap, int ) ;
  587. X    return( XLOG_ENOERROR ) ;
  588. X}
  589. X
  590. END_OF_FILE
  591. if test 3955 -ne `wc -c <'libs/src/xlog/slog.c'`; then
  592.     echo shar: \"'libs/src/xlog/slog.c'\" unpacked with wrong size!
  593. fi
  594. # end of 'libs/src/xlog/slog.c'
  595. fi
  596. if test -f 'xinetd/defs.h' -a "${1}" != "-c" ; then 
  597.   echo shar: Will not clobber existing file \"'xinetd/defs.h'\"
  598. else
  599. echo shar: Extracting \"'xinetd/defs.h'\" \(4102 characters\)
  600. sed "s/^X//" >'xinetd/defs.h' <<'END_OF_FILE'
  601. X/*
  602. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  603. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  604. X * and conditions for redistribution.
  605. X */
  606. X
  607. X#ifndef DEFS_H
  608. X#define DEFS_H
  609. X
  610. X/*
  611. X * $Id: defs.h,v 6.5 1993/06/13 01:43:06 panos Exp $
  612. X */
  613. X
  614. X#include <memory.h>
  615. X
  616. X#ifndef IPPROTO_TCP
  617. X#define IPPROTO_TCP                    6
  618. X#endif
  619. X
  620. X#ifndef NULL
  621. X#define NULL                             0
  622. X#endif
  623. X
  624. X#ifndef FALSE
  625. X#define FALSE                             0
  626. X#define TRUE                              1
  627. X#endif
  628. X
  629. X#define NUL                      '\0'
  630. X
  631. X#define ES_NOMEM                        "out of memory"
  632. X
  633. X#define INT_NULL                        ((int *)0)
  634. X#define CHAR_NULL                        ((char *)0)
  635. X#define VOID_NULL                        ((void *)0)
  636. X#define FD_SET_NULL                    ((fd_set *)0)
  637. X#define RUSAGE_NULL                    ((struct rusage *)0)
  638. X#define TIMEVAL_NULL                    ((struct timeval *)0)
  639. X#define ITIMERVAL_NULL                ((struct itimerval *)0)
  640. X#define SOCKADDRIN_NULL                ((struct sockaddr_in *)0)
  641. X
  642. X#define PRIVATE                        static
  643. X
  644. X#define EQ( s1, s2 )                    ( strcmp( s1, s2 ) == 0 )
  645. X#define CLEAR( x )                    (void) memset( (char *)&(x), 0, sizeof( x ) )
  646. X#define SA( p )                        ( (struct sockaddr *) (p) )
  647. X#define NEW( type )                    (type *) malloc( sizeof( type ) )
  648. X#define FREE( p )                        (void) free( (char *)(p) )
  649. X
  650. X/*
  651. X * Value for unlimited server instances
  652. X */
  653. X#define UNLIMITED                        (-1)
  654. X
  655. X/*
  656. X * We pass to the child the descriptors 0..MAX_PASS_FD
  657. X */
  658. X#define MAX_PASS_FD                    2
  659. X
  660. X/*
  661. X * Service port for the identification service
  662. X */
  663. X#define IDENTITY_SERVICE_PORT        113
  664. X
  665. X/*
  666. X * This is the signal sent to interceptor processes to tell them
  667. X * to stop intercepting
  668. X */
  669. X#define INTERCEPT_SIG                SIGUSR1
  670. X
  671. X/*
  672. X * This is how many descriptors we reserve for ourselves:
  673. X *
  674. X *        3     for stdin, stdout, stderr
  675. X *        1     for syslog/debug
  676. X *
  677. X * For the rest we just need to reserve the maximum of each category.
  678. X *
  679. X *        1     for doing accepts
  680. X *        1     for registering rpc services (initialization phase)
  681. X *        4     for reading the configuration file during reconfiguration
  682. X *                1 for the configuration file
  683. X *                1 for /etc/passwd
  684. X *                1 for /etc/group
  685. X *                1 for /etc/services, /etc/protocols, /etc/rpc
  686. X *                NOTE: We need only 1 descriptor for the last 3 files because
  687. X *                        the functions get{serv,proto,rpc}byname close the
  688. X *                        respective files after accessing them.
  689. X *        1     for dumping the internal state
  690. X *        1    for talking to the portmapper (reconfiguration phase)
  691. X *        1    for doing identification
  692. X *
  693. X * NOTE: we assume that the socket used for pmap_{set,unset} is closed
  694. X *            after the operation is completed. If it stays open, then we
  695. X *            need to increase DESCRIPTORS_RESERVED.
  696. X */
  697. X#define DESCRIPTORS_RESERVED            8
  698. X
  699. X/*
  700. X * Used for listen(2)
  701. X */
  702. X#define LISTEN_BACKLOG                    7
  703. X
  704. X/*
  705. X * When explicit values are given for enum's, that is because the structures 
  706. X * that the enum's are in may be initialized by a memory clear operation.
  707. X */
  708. X
  709. Xtypedef enum { FAILED = 0, OK } status_e ;
  710. Xtypedef enum { NO = 0, YES } boolean_e ;
  711. X
  712. X/*
  713. X * Possible outcomes of an identification attempt
  714. X */
  715. Xtypedef enum
  716. X    {
  717. X        IDR_OK,
  718. X        IDR_NOSERVER,
  719. X        IDR_TIMEDOUT,
  720. X        IDR_RESPERR,
  721. X        IDR_BADRESP,
  722. X        IDR_ERROR
  723. X    } idresult_e ;
  724. X
  725. Xtypedef int bool_int ;
  726. X
  727. Xtypedef void (*voidfunc)() ;
  728. Xtypedef status_e (*statfunc)() ;
  729. X
  730. X
  731. X/*
  732. X * A name-value list is exactly what its name says.
  733. X * The functions nv_get_name() and nv_get_value() return a pointer to
  734. X * the entry with the specified value or name respectively.
  735. X * The list ends when an antry with a NULL name is encountered.
  736. X * The value field of that entry is treated in a special manner: if it
  737. X * is non-zero, it is assumed that there exists one more entry whose
  738. X * name field will be returned by the nv_get_name function if it can't
  739. X * find an entry whose value field is equal to its 2nd parameter.
  740. X * If the value field of the NULL entry is 0, then nv_get_name() will
  741. X * return NULL.
  742. X */
  743. Xstruct name_value
  744. X{
  745. X   char    *name ;
  746. X   int    value ;
  747. X} ;
  748. X
  749. Xstruct name_value *nv_find_value( /* struct name_value [], char *name */ ) ;
  750. Xstruct name_value *nv_find_name( /* struct name_value [], int value */ ) ;
  751. Xchar                    *nv_get_name( /* struct name_value [], int value */ ) ;
  752. X
  753. X
  754. Xstruct debug
  755. X{
  756. X    bool_int on ;
  757. X    int fd ;
  758. X} ;
  759. X
  760. Xextern struct debug debug ;
  761. X
  762. X#endif    /* DEFS_H */
  763. END_OF_FILE
  764. if test 4102 -ne `wc -c <'xinetd/defs.h'`; then
  765.     echo shar: \"'xinetd/defs.h'\" unpacked with wrong size!
  766. fi
  767. # end of 'xinetd/defs.h'
  768. fi
  769. if test -f 'xinetd/env.c' -a "${1}" != "-c" ; then 
  770.   echo shar: Will not clobber existing file \"'xinetd/env.c'\"
  771. else
  772. echo shar: Extracting \"'xinetd/env.c'\" \(4000 characters\)
  773. sed "s/^X//" >'xinetd/env.c' <<'END_OF_FILE'
  774. X/*
  775. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  776. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  777. X * and conditions for redistribution.
  778. X */
  779. X
  780. Xstatic char RCSid[] = "$Id: env.c,v 6.3 1993/06/06 00:09:15 panos Exp $" ;
  781. X
  782. X#include <syslog.h>
  783. X#include <string.h>
  784. X
  785. X#include "misc.h"
  786. X
  787. X#include "attr.h"
  788. X#include "defs.h"
  789. X#include "sconf.h"
  790. X
  791. Xvoid msg() ;
  792. Xvoid out_of_memory() ;
  793. X
  794. Xextern char **environ ;
  795. X
  796. Xenv_h std_env ;                /* created from environ */
  797. X
  798. X
  799. Xstatus_e initenv()
  800. X{
  801. X    std_env = env_make( environ ) ;
  802. X    return( ( std_env == NULL ) ? FAILED : OK ) ;
  803. X}
  804. X
  805. XPRIVATE status_e make_env_with_strings() ;
  806. XPRIVATE status_e make_env_from_vars() ;
  807. XPRIVATE status_e update_env_with_strings() ;
  808. X
  809. X
  810. Xstatus_e setup_environ( scp, def )
  811. X    struct service_config    *scp ;
  812. X    struct service_config    *def ;
  813. X{
  814. X    struct environment    *ep = SC_ENV( scp ) ;
  815. X
  816. X    if ( ! SC_SPECIFIED( scp, A_PASSENV ) )
  817. X    {
  818. X        if ( ! SC_SPECIFIED( def, A_PASSENV ) )
  819. X        {
  820. X            if ( ! SC_SPECIFIED( scp, A_ENV ) )
  821. X            {
  822. X                ep->env_type = STD_ENV ;
  823. X                ep->env_handle = std_env ;
  824. X                return( OK ) ;
  825. X            }
  826. X            else
  827. X                return( 
  828. X                    make_env_with_strings( ep, std_env, scp->sc_env_var_defs ) ) ;
  829. X        }
  830. X        else    /* SC_SPECIFIED( def, A_PASSENV ) */
  831. X        {
  832. X            struct environment *dep = SC_ENV( def ) ;
  833. X
  834. X            if ( dep->env_type == NO_ENV &&
  835. X                        make_env_from_vars( dep, std_env,
  836. X                                            def->sc_pass_env_vars ) == FAILED )
  837. X                return( FAILED ) ;
  838. X
  839. X            if ( ! SC_SPECIFIED( scp, A_ENV ) )
  840. X            {
  841. X                ep->env_type = DEF_ENV ;
  842. X                ep->env_handle = dep->env_handle ;
  843. X                return( OK ) ;
  844. X            }
  845. X            else
  846. X                return( make_env_with_strings( ep, 
  847. X                                    dep->env_handle, scp->sc_env_var_defs ) ) ;
  848. X        }
  849. X    }
  850. X    else    /* SC_SPECIFIED( scp, A_PASSENV ) */
  851. X    {
  852. X        if ( make_env_from_vars( ep, std_env, scp->sc_pass_env_vars ) == FAILED )
  853. X            return( FAILED ) ;
  854. X
  855. X        if ( ! SC_SPECIFIED( scp, A_ENV ) )
  856. X            return( OK ) ;
  857. X        else
  858. X        {
  859. X            if ( update_env_with_strings( 
  860. X                            ep->env_handle, scp->sc_env_var_defs ) == FAILED )
  861. X            {
  862. X                env_destroy( ep->env_handle ) ;
  863. X                return( FAILED ) ;
  864. X            }
  865. X            return( OK ) ;
  866. X        }
  867. X    }
  868. X}
  869. X
  870. X
  871. X/*
  872. X * Create a new environment from environ and env_strings
  873. X * env_strings contains strings of the form "var=value"
  874. X */
  875. XPRIVATE status_e make_env_with_strings( ep, env, env_strings )
  876. X    struct environment    *ep ;
  877. X    env_h                        env ;
  878. X    pset_h                    env_strings ;
  879. X{
  880. X    env_h        new_env ;
  881. X    char        *func = "make_env_with_strings" ;
  882. X
  883. X    if ( ( new_env = env_create( env ) ) == ENV_NULL )
  884. X    {
  885. X        out_of_memory( func ) ;
  886. X        return( FAILED ) ;
  887. X    }
  888. X
  889. X    if ( update_env_with_strings( new_env, env_strings ) == FAILED )
  890. X    {
  891. X        env_destroy( new_env ) ;
  892. X        return( FAILED ) ;
  893. X    }
  894. X
  895. X    ep->env_type = CUSTOM_ENV ;
  896. X    ep->env_handle = new_env ;
  897. X    return( OK ) ;
  898. X}
  899. X
  900. X
  901. XPRIVATE status_e make_env_from_vars( ep, env, vars )
  902. X    struct environment    *ep ;
  903. X    env_h                        env ;
  904. X    pset_h                    vars ;
  905. X{
  906. X    env_h                    new_env ;
  907. X    char                    *varname ;
  908. X    register unsigned u ;
  909. X    char                    *func = "make_env_from_vars" ;
  910. X
  911. X    if ( ( new_env = env_create( ENV_NULL ) ) == ENV_NULL )
  912. X    {
  913. X        out_of_memory( func ) ;
  914. X        return( FAILED ) ;
  915. X    }
  916. X    
  917. X    for ( u = 0 ; u < pset_count( vars ) ; u++ )
  918. X    {
  919. X        varname = (char *) pset_pointer( vars, u ) ;
  920. X        if ( env_addvar( new_env, env, varname ) == ENV_ERR )
  921. X            switch ( env_errno )
  922. X            {
  923. X                case ENV_EBADVAR:
  924. X                    msg( LOG_ERR, func, "Unknown variable %s", varname ) ;
  925. X                    break ;
  926. X                
  927. X                case ENV_ENOMEM:
  928. X                    out_of_memory( func ) ;
  929. X                    env_destroy( new_env ) ;
  930. X                    return( FAILED ) ;
  931. X            }
  932. X    }
  933. X
  934. X    ep->env_type = CUSTOM_ENV ;
  935. X    ep->env_handle = new_env ;
  936. X    return( OK ) ;
  937. X}
  938. X
  939. X
  940. XPRIVATE status_e update_env_with_strings( env, strings )
  941. X    env_h env ;
  942. X    pset_h strings ;
  943. X{
  944. X    register unsigned u ;
  945. X    char *func = "update_env_with_strings" ;
  946. X
  947. X    for ( u = 0 ; u < pset_count( strings ) ; u++ )
  948. X    {
  949. X        char *p = (char *) pset_pointer( strings, u ) ;
  950. X
  951. X        if ( env_addstr( env, p ) == ENV_ERR )
  952. X            switch ( env_errno )
  953. X            {
  954. X                case ENV_ENOMEM:
  955. X                    out_of_memory( func ) ;
  956. X                    return( FAILED ) ;
  957. X                
  958. X                case ENV_EBADSTRING:
  959. X                    msg( LOG_ERR, func, "Bad environment string: %s\n", p ) ;
  960. X                    break ;
  961. X            }
  962. X    }
  963. X    return( OK ) ;
  964. X}
  965. X
  966. END_OF_FILE
  967. if test 4000 -ne `wc -c <'xinetd/env.c'`; then
  968.     echo shar: \"'xinetd/env.c'\" unpacked with wrong size!
  969. fi
  970. # end of 'xinetd/env.c'
  971. fi
  972. if test -f 'xinetd/logctl.c' -a "${1}" != "-c" ; then 
  973.   echo shar: Will not clobber existing file \"'xinetd/logctl.c'\"
  974. else
  975. echo shar: Extracting \"'xinetd/logctl.c'\" \(4125 characters\)
  976. sed "s/^X//" >'xinetd/logctl.c' <<'END_OF_FILE'
  977. X/*
  978. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  979. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  980. X * and conditions for redistribution.
  981. X */
  982. X
  983. Xstatic char RCSid[] = "$Id: logctl.c,v 6.6 1993/06/15 23:25:57 panos Exp $" ;
  984. X
  985. X#include <sys/types.h>
  986. X#include <sys/stat.h>
  987. X#include <syslog.h>
  988. X#include <fcntl.h>
  989. X
  990. X#include "sio.h"
  991. X#include "xlog.h"
  992. X
  993. X#include "config.h"
  994. X#include "state.h"
  995. X#include "defs.h"
  996. X#include "log.h"
  997. X#include "service.h"
  998. X
  999. Xvoid msg() ;
  1000. X
  1001. X
  1002. X
  1003. XPRIVATE xlog_h start_filelog( id, flp )
  1004. X    char                *id ;
  1005. X    struct filelog *flp ;
  1006. X{
  1007. X    xlog_h    xh ;
  1008. X    int        fd ;
  1009. X    int        log_file_mode = ( debug.on ) ? 0644 : LOG_FILE_MODE ;
  1010. X    char        *func = "start_filelog" ;
  1011. X
  1012. X    xh = xlog_create( XLOG_FILELOG, id, XLOG_NOFLAGS,
  1013. X                            flp->fl_filename, LOG_OPEN_FLAGS, log_file_mode ) ;
  1014. X    if ( xh == NULL )
  1015. X    {
  1016. X        msg( LOG_ERR, func, "creation of %s log failed", id ) ;
  1017. X        return( NULL ) ;
  1018. X    }
  1019. X
  1020. X    if ( xlog_control( xh, XLOG_GETFD, &fd ) != XLOG_ENOERROR ||
  1021. X                        fcntl( fd,  F_SETFD, 1 ) == -1 )
  1022. X    {
  1023. X        msg( LOG_ERR, func, "Failed to set close-on-exec flag for log file" ) ;
  1024. X        xlog_destroy( xh ) ;
  1025. X        return( NULL ) ;
  1026. X    }
  1027. X
  1028. X    ps.rws.descriptors_free-- ;
  1029. X
  1030. X    if ( FILELOG_SIZE_CONTROL( flp ) )
  1031. X        (void) xlog_control( xh,
  1032. X                            XLOG_LIMITS, flp->fl_soft_limit, flp->fl_hard_limit ) ;
  1033. X
  1034. X    return( xh ) ;
  1035. X}
  1036. X
  1037. X
  1038. X/*
  1039. X * This function is invoked when a xlog detects an error (for example,
  1040. X * exceeding the file size limit).
  1041. X * The function just enters a log message.
  1042. X * 
  1043. X * NOTE: We could destroy the xlog at this point but we choose not to.
  1044. X */
  1045. XPRIVATE void log_in_error( xh, error_code, arg )
  1046. X    xlog_h    xh ;
  1047. X    int        error_code ;
  1048. X    void        *arg ;
  1049. X{
  1050. X    struct service        *sp        = SP( arg ) ;
  1051. X    char                    *log_id    = ( sp == NULL ) ? "common" : SVC_ID( sp ) ;
  1052. X    char                    *func        = "log_in_error" ;
  1053. X
  1054. X#ifdef lint
  1055. X    xh = xh ;
  1056. X#endif
  1057. X    if ( error_code == XLOG_ESIZE )
  1058. X        msg( LOG_ERR, func, "Size of %s log exceeded hard limit", log_id ) ;
  1059. X    else
  1060. X        msg( LOG_ERR, func, "Error in %s log: %d", log_id, error_code ) ;
  1061. X}
  1062. X
  1063. X/*
  1064. X * Start logging for the specified service.
  1065. X * The current configuration is used to determine the common log file.
  1066. X */
  1067. Xstatus_e log_start( sp, xhp )
  1068. X    struct service        *sp ;
  1069. X    xlog_h                *xhp ;
  1070. X{
  1071. X    xlog_h        xh ;
  1072. X    char            *sid    = SVC_ID( sp ) ;
  1073. X    struct log    *lp    = SC_LOG( SVC_CONF( sp ) ) ;
  1074. X    char            *func = "log_start" ;
  1075. X
  1076. X    switch ( lp->l_type )
  1077. X    {
  1078. X        case L_NONE:
  1079. X            xh = NULL ;
  1080. X            break ;
  1081. X
  1082. X        case L_SYSLOG:
  1083. X            xh = xlog_create( XLOG_SYSLOG, sid, XLOG_NOFLAGS, 
  1084. X                        log_syslog( lp )->sl_facility, log_syslog( lp )->sl_level ) ;
  1085. X            if ( xh == NULL )
  1086. X            {
  1087. X                msg( LOG_ERR, func, "failed to create a log for service %s", sid ) ;
  1088. X                return( FAILED ) ;
  1089. X            }
  1090. X            xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ;
  1091. X            break ;
  1092. X        
  1093. X        case L_FILE:
  1094. X            /*
  1095. X             * NOTE: if the same file is specified for more than one service,
  1096. X             *            it will be opened as many times.
  1097. X             *            Furthermore, size control will not be accurate.
  1098. X             */
  1099. X            xh = start_filelog( sid, log_filelog( lp ) ) ;
  1100. X            if ( xh == NULL )
  1101. X                return( FAILED ) ;
  1102. X            (void) xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ;
  1103. X            break ;
  1104. X        
  1105. X        case L_COMMON_FILE:
  1106. X            if ( DEFAULT_LOG( ps ) == NULL )
  1107. X                if ( DEFAULT_LOG_ERROR( ps ) )
  1108. X                    return( FAILED ) ;
  1109. X                else
  1110. X                {
  1111. X                    xh = start_filelog( "default", 
  1112. X                                        log_filelog( SC_LOG( DEFAULTS( ps ) ) ) ) ;
  1113. X                    if ( xh == NULL )
  1114. X                    {
  1115. X                        DEFAULT_LOG_ERROR( ps ) = TRUE ;
  1116. X                        return( FAILED ) ;
  1117. X                    }
  1118. X                    DEFAULT_LOG( ps ) = xh ;
  1119. X                    (void) xlog_control( xh,
  1120. X                                    XLOG_CALLBACK, log_in_error, VOID_NULL ) ;
  1121. X                }
  1122. X            else
  1123. X                xh = DEFAULT_LOG( ps ) ;
  1124. X            break ;
  1125. X
  1126. X        default:            /* SHOULDN'T HAPPEN */
  1127. X            msg( LOG_ERR, func, "bad log type (%d) for service %s",
  1128. X                (int) log_get_type( lp ), sid ) ;
  1129. X            return( FAILED ) ;
  1130. X    }
  1131. X    *xhp = xh ;
  1132. X    return( OK ) ;
  1133. X}
  1134. X
  1135. X
  1136. Xvoid log_end( lp, xh )
  1137. X    struct log *lp ;
  1138. X    xlog_h xh ;
  1139. X{
  1140. X    char *func = "log_end" ;
  1141. X
  1142. X    if ( xh == NULL )        /* shouldn't be NULL but just in case */
  1143. X    {
  1144. X        msg( LOG_NOTICE, func, "%s called with NULL handle", func ) ;
  1145. X        return ;
  1146. X    }
  1147. X
  1148. X    switch ( log_get_type( lp ) )
  1149. X    {
  1150. X        case L_FILE:
  1151. X            ps.rws.descriptors_free++ ;
  1152. X            /* FALL THROUGH */
  1153. X        
  1154. X        case L_SYSLOG:
  1155. X            xlog_destroy( xh ) ;
  1156. X    }
  1157. X}
  1158. X
  1159. END_OF_FILE
  1160. if test 4125 -ne `wc -c <'xinetd/logctl.c'`; then
  1161.     echo shar: \"'xinetd/logctl.c'\" unpacked with wrong size!
  1162. fi
  1163. # end of 'xinetd/logctl.c'
  1164. fi
  1165. if test -f 'xinetd/util.c' -a "${1}" != "-c" ; then 
  1166.   echo shar: Will not clobber existing file \"'xinetd/util.c'\"
  1167. else
  1168. echo shar: Extracting \"'xinetd/util.c'\" \(3951 characters\)
  1169. sed "s/^X//" >'xinetd/util.c' <<'END_OF_FILE'
  1170. X/*
  1171. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  1172. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1173. X * and conditions for redistribution.
  1174. X */
  1175. X
  1176. Xstatic char RCSid[] = "$Id: util.c,v 6.5 1993/06/13 01:47:02 panos Exp $" ;
  1177. X
  1178. X#include <sys/types.h>
  1179. X/*
  1180. X * The following ifdef is for TIOCNOTTY
  1181. X */
  1182. X#ifndef NO_TERMIOS
  1183. X#include <sys/termios.h>
  1184. X#else
  1185. X#include <sys/ioctl.h>
  1186. X#endif
  1187. X#include <fcntl.h>
  1188. X
  1189. X#include <memory.h>
  1190. X#include <syslog.h>
  1191. X#include <errno.h>
  1192. X#include <varargs.h>
  1193. X
  1194. X#include "pset.h"
  1195. X#include "misc.h"
  1196. X#include "sio.h"
  1197. X
  1198. X#include "defs.h"
  1199. X#include "config.h"
  1200. X
  1201. Xchar *malloc() ;
  1202. X
  1203. Xvoid msg() ;
  1204. X
  1205. X
  1206. Xvoid out_of_memory( func )
  1207. X    char *func ;
  1208. X{
  1209. X    msg( LOG_CRIT, func, ES_NOMEM ) ;
  1210. X}
  1211. X
  1212. X
  1213. Xstruct name_value *nv_find_value( nv_array, name )
  1214. X    struct name_value nv_array[] ;
  1215. X    register char *name ;
  1216. X{
  1217. X    register struct name_value *nvp ;
  1218. X
  1219. X    for ( nvp = nv_array ; nvp->name ; nvp++ )
  1220. X        if ( EQ( name, nvp->name ) )
  1221. X            return( nvp ) ;
  1222. X    return( NULL ) ;
  1223. X}
  1224. X
  1225. X
  1226. Xstruct name_value *nv_find_name( nv_array, value )
  1227. X    struct name_value nv_array[] ;
  1228. X    register int value ;
  1229. X{
  1230. X    register struct name_value *nvp ;
  1231. X
  1232. X    for ( nvp = nv_array ; nvp->name ; nvp++ )
  1233. X        if ( value == nvp->value )
  1234. X            return( nvp ) ;
  1235. X    return( NULL ) ;
  1236. X}
  1237. X
  1238. X
  1239. Xchar *nv_get_name( nv_array, value )
  1240. X    struct name_value nv_array[] ;
  1241. X    register int value ;
  1242. X{
  1243. X    register struct name_value *nvp ;
  1244. X
  1245. X    for ( nvp = nv_array ; nvp->name ; nvp++ )
  1246. X        if ( value == nvp->value )
  1247. X            return( nvp->name ) ;
  1248. X    return( nvp->value ? nvp[1].name : NULL ) ;
  1249. X}
  1250. X
  1251. X
  1252. X
  1253. Xchar **argv_alloc( count )
  1254. X    unsigned count ;
  1255. X{
  1256. X    unsigned argv_size = (count + 1) * sizeof( char *) ;
  1257. X    char **argv ;
  1258. X    char *func = "new_argv" ;
  1259. X
  1260. X    argv = (char **) malloc( argv_size ) ;
  1261. X    if ( argv == NULL )
  1262. X    {
  1263. X        out_of_memory( func ) ;
  1264. X        return( NULL ) ;
  1265. X    }
  1266. X    (void) memset( (char *)argv, 0, (int) argv_size ) ;
  1267. X    return( argv ) ;
  1268. X}
  1269. X
  1270. X
  1271. X
  1272. X/*
  1273. X * If size is 0, the pset holds strings
  1274. X */
  1275. Xstatus_e copy_pset( from, to, size )
  1276. X    pset_h from ;
  1277. X    pset_h *to ;
  1278. X    unsigned size ;
  1279. X{
  1280. X    unsigned u ;
  1281. X    char *func = "copy_pset" ;
  1282. X
  1283. X    if ( *to == NULL )
  1284. X    {
  1285. X        *to = pset_create( pset_count( from ), 0 ) ;
  1286. X        if ( *to == NULL )
  1287. X        {
  1288. X            out_of_memory( func ) ;
  1289. X            return( FAILED ) ;
  1290. X        }
  1291. X    }
  1292. X
  1293. X    for ( u = 0 ; u < pset_count( from ) ; u++ )
  1294. X    {
  1295. X        char *p = (char *) pset_pointer( from, u ) ;
  1296. X        char *new ;
  1297. X        
  1298. X        if ( size == 0 )
  1299. X            new = make_string( 1, p ) ;
  1300. X        else
  1301. X            new = malloc( size ) ;
  1302. X
  1303. X        if ( new == NULL )
  1304. X        {
  1305. X            out_of_memory( func ) ;
  1306. X            return( FAILED ) ;
  1307. X        }
  1308. X
  1309. X        if ( size != 0 )
  1310. X            (void) memcpy( new, p, (int) size ) ;
  1311. X
  1312. X        if ( pset_add( *to, new ) == NULL )
  1313. X        {
  1314. X            free( new ) ;
  1315. X            out_of_memory( func ) ;
  1316. X            return( FAILED ) ;
  1317. X        }
  1318. X    }
  1319. X    return( OK ) ;
  1320. X}
  1321. X
  1322. X
  1323. X/*
  1324. X * Disassociate from controlling terminal
  1325. X */
  1326. Xvoid no_control_tty()
  1327. X{
  1328. X   int fd ;
  1329. X   char *func = "no_control_tty" ;
  1330. X
  1331. X   if ( ( fd = open( "/dev/tty", O_RDWR ) ) == -1 )
  1332. X      msg( LOG_WARNING, func, "open of /dev/tty failed: %m" ) ;
  1333. X   else
  1334. X   {
  1335. X      if ( ioctl( fd, TIOCNOTTY, (caddr_t)0 ) == -1 )
  1336. X         msg( LOG_WARNING, func, "ioctl on /dev/tty failed: %m" ) ;
  1337. X      (void) close( fd ) ;
  1338. X   }
  1339. X   (void) setpgrp( getpid(), 0 ) ;
  1340. X}
  1341. X
  1342. X
  1343. X/*
  1344. X * Write the whole buffer to the given file descriptor ignoring interrupts
  1345. X */
  1346. Xstatus_e write_buf( fd, buf, len )
  1347. X    int fd ;
  1348. X    char *buf ;
  1349. X    int len ;
  1350. X{
  1351. X    register char *p ;
  1352. X    register int cc ;
  1353. X
  1354. X    for ( p = buf ; len > 0 ; p += cc, len -= cc )
  1355. X    {
  1356. X        cc = write( fd, p, len ) ;
  1357. X        if ( cc == -1 )
  1358. X        {
  1359. X            if ( errno != EINTR )
  1360. X                return( FAILED ) ;
  1361. X            cc = 0 ;
  1362. X        }
  1363. X    }
  1364. X    return( OK ) ;
  1365. X}
  1366. X
  1367. X
  1368. Xvoid tabprint( fd, tab_level, fmt, va_alist )
  1369. X   int fd ;
  1370. X   int tab_level ;
  1371. X   char *fmt ;
  1372. X   va_dcl
  1373. X{
  1374. X   va_list ap ;
  1375. X   int i ;
  1376. X
  1377. X   for ( i = 0 ; i < tab_level ; i++ )
  1378. X      Sputchar( fd, '\t' ) ;
  1379. X
  1380. X   va_start( ap ) ;
  1381. X   Sprintv( fd, fmt, ap ) ;
  1382. X   va_end( ap ) ;
  1383. X}
  1384. X
  1385. X
  1386. X/*
  1387. X * Receive a single IP packet worth of data.
  1388. X */
  1389. Xvoid drain( sd )
  1390. X   int sd ;
  1391. X{
  1392. X   char buf[ 1 ] ;
  1393. X   char cc ;
  1394. X
  1395. X   cc = recv( sd, buf, sizeof( buf ), 0 ) ;
  1396. X   if ( cc == -1 )
  1397. X      msg( LOG_WARNING, "drain", "recv: %m" ) ;
  1398. X}
  1399. X
  1400. END_OF_FILE
  1401. if test 3951 -ne `wc -c <'xinetd/util.c'`; then
  1402.     echo shar: \"'xinetd/util.c'\" unpacked with wrong size!
  1403. fi
  1404. # end of 'xinetd/util.c'
  1405. fi
  1406. echo shar: End of archive 8 \(of 31\).
  1407. cp /dev/null ark8isdone
  1408. MISSING=""
  1409. 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
  1410.     if test ! -f ark${I}isdone ; then
  1411.     MISSING="${MISSING} ${I}"
  1412.     fi
  1413. done
  1414. if test "${MISSING}" = "" ; then
  1415.     echo You have unpacked all 31 archives.
  1416.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1417. else
  1418.     echo You still need to unpack the following archives:
  1419.     echo "        " ${MISSING}
  1420. fi
  1421. ##  End of shell archive.
  1422. exit 0
  1423.