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

  1. Newsgroups: comp.sources.unix
  2. From: panos@cs.colorado.edu (Panos Tsirigotis)
  3. Subject: v26i254: xinetd-2.1.1 - inetd replacement with access control and logging, Part10/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 254
  9. Archive-Name: xinetd-2.1.1/part10
  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 10 (of 31)."
  18. # Contents:  libs/src/str/Makefile libs/src/str/strparse.c
  19. #   libs/src/xlog/xlog.c xinetd/conf.c xinetd/msg.c xinetd/special.c
  20. # Wrapped by panos@mystique on Mon Jun 21 14:51:23 1993
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'libs/src/str/Makefile' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'libs/src/str/Makefile'\"
  24. else
  25. echo shar: Extracting \"'libs/src/str/Makefile'\" \(4534 characters\)
  26. sed "s/^X//" >'libs/src/str/Makefile' <<'END_OF_FILE'
  27. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  28. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  29. X# and conditions for redistribution.
  30. X
  31. X#
  32. X# $Id: Makefile,v 3.2 1993/06/16 00:06:57 panos Exp $
  33. X#
  34. X# Based on Library makefile template: *Revision: 1.15 *
  35. X#
  36. X
  37. X# 
  38. X# Available entries:
  39. X#         lib             --> creates the library
  40. X#        install        --> installs the library (archive, man page(s), header(s))
  41. X#        uninstall    --> uninstall the library
  42. X#        clean            --> removes all .o and .a files
  43. X#        spotless        --> clean + uninstall
  44. X#         lint            --> lints a file (usage: make lint MODULE=foo.c)
  45. X#        tags            --> creates a tags file (from the SOURCES and HEADERS)
  46. X#        checkout     --> checkout all files
  47. X#        dist            --> distribution support
  48. X#
  49. X
  50. XNAME                = str
  51. XVERSION            = 1.4.1
  52. X
  53. XHEADERS            = str.h strparse.h \
  54. X                        ss_impl.h ss_rk.h ss_kmp.h ss_sbm.h ss_bmh.h ss_so.h
  55. XSOURCES            = strutil.c strprint.c strparse.c strs.c \
  56. X                        ss_rk.c ss_kmp.c ss_bf.c ss_sbm.c ss_bmh.c ss_so.c
  57. XOBJECTS            = strutil.o strprint.o strparse.o strs.o \
  58. X                        ss_rk.o ss_kmp.o ss_bf.o ss_sbm.o ss_bmh.o ss_so.o
  59. X
  60. XMANFILES            = strparse.3 strprint.3 strutil.3 strs.3
  61. XINCLUDEFILES    = str.h
  62. X
  63. X# The following variables are used by the 'install' entry and
  64. X# should be customized:
  65. X#     LIBDIR:     where the library will be placed
  66. X#     INCUDEDIR:  where the include files will be placed
  67. X#     MANDIR:     where the man pages will be placed
  68. X#
  69. XLIBDIR            = $(HOME)/.links/libraries/$(ARCH)
  70. XMANDIR            = $(HOME)/.links/manpages/man3
  71. XINCLUDEDIR        = $(HOME)/.links/includes
  72. X
  73. X#
  74. X# Available flags
  75. X#    NBIC                : number of bits in a character variable (defaults to 8)
  76. X#    WIDE_INT            : widest integer supported by the CPU/compiler
  77. X#                          (defaults to 'long')
  78. X#    WIDE_INT_SIZE  : size of the WIDE_INT type in bits (defaults to 32);
  79. X#                          effective (and required) only when WIDE_INT is defined
  80. X#    NO_SIO            : if the SIO library is not available (results in turning
  81. X#                          all the string printing functions to no-ops)
  82. X#
  83. XDEFS                =         # for example, -DNO_SIO
  84. XDEBUG                = -g                # -g or -O
  85. XVERSION_DEF        = -DVERSION=\"STR\ Version\ $(VERSION)\"
  86. X
  87. XCPP_DEFS            = $(VERSION_DEF) $(DEFS)
  88. X
  89. X#
  90. X# The following variables shouldn't need to be changed
  91. X#
  92. XLINT_FLAGS        = -hbux
  93. XCPP_FLAGS        = $(CPP_DEFS) -I$(INCLUDEDIR)
  94. XCC_FLAGS            = $(DEBUG)
  95. XCFLAGS            = $(CPP_FLAGS) $(CC_FLAGS)
  96. X
  97. XINSTALL            = install -c
  98. XFMODE                = -m 640            # used by install
  99. XRANLIB            = ranlib
  100. X
  101. XPAGER                = less
  102. X
  103. X
  104. XLIBNAME            = lib$(NAME).a
  105. X
  106. Xlib: $(LIBNAME)
  107. X
  108. Xlibopt: clean
  109. X    make DEBUG=-O "DEFS=$(DEFS)" lib
  110. X    $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)-O
  111. X
  112. X$(LIBNAME): $(OBJECTS)
  113. X    ar r $@ $?
  114. X    $(RANLIB) $@
  115. X
  116. XLINT_IGNORE=possible pointer alignment|RCSid unused
  117. X
  118. Xlint:
  119. X    lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | egrep -v '$(LINT_IGNORE)' | $(PAGER)
  120. X
  121. Xinstall: $(LIBNAME)
  122. X    @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
  123. X    then \
  124. X        $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
  125. X        echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
  126. X        for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
  127. X        echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
  128. X        for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
  129. X        echo Installed $(MANFILES) to $(MANDIR) ;\
  130. X    else \
  131. X        echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
  132. X    fi
  133. X
  134. Xuninstall:
  135. X    a=`pwd` ; cd $(INCLUDEDIR) ;\
  136. X    if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
  137. X    a=`pwd` ; cd $(LIBDIR) ;\
  138. X    if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
  139. X    a=`pwd` ; cd $(MANDIR) ;\
  140. X    if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
  141. X
  142. Xclean:
  143. X    rm -f $(OBJECTS) $(LIBNAME) core
  144. X
  145. Xspotless: clean uninstall
  146. X
  147. Xtags: $(SOURCES) $(HEADERS)
  148. X    ctags -w $(SOURCES) $(HEADERS)
  149. X
  150. Xcheckout:
  151. X    co $(SOURCES) $(HEADERS) $(MANFILES)
  152. X
  153. X#
  154. X# Distribution section
  155. X# This section contains the 2 targets for distribution support: dist, dirs
  156. X# "dist" checks out all files to be distributed
  157. X# "dirs" prints a list of directories to be included in the distribution.
  158. X# These directories should have a Makefile with a "dist" target
  159. X#
  160. XDISTRIBUTION_FILES    = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT README
  161. XDIRS                        =
  162. X
  163. Xdist:
  164. X    -co -q $(DISTRIBUTION_FILES)
  165. X
  166. Xdirs:
  167. X    @echo $(DIRS)
  168. X
  169. X#
  170. X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
  171. X#
  172. Xstrparse.o:        strparse.h str.h
  173. Xstrprint.o:        str.h
  174. Xstrutil.o:        str.h
  175. Xstrs.o:            ss_impl.h str.h
  176. Xss_bf.o:            ss_impl.h
  177. Xss_rk.o:            ss_impl.h ss_rk.h
  178. Xss_kmp.o:        ss_impl.h ss_kmp.h
  179. Xss_sbm.o:        ss_impl.h ss_sbm.h
  180. Xss_bmh.o:        ss_impl.h ss_bmh.h
  181. Xss_so.o:            ss_impl.h ss_so.h
  182. X
  183. X
  184. X#
  185. X# Test program
  186. X#
  187. Xtt: tt.c $(LIBNAME)
  188. X    $(CC) -I$(INCDIR) -g -o $@ tt.c $(LIBNAME) -L$(LIBDIR) -lsio -lmisc
  189. X
  190. END_OF_FILE
  191. if test 4534 -ne `wc -c <'libs/src/str/Makefile'`; then
  192.     echo shar: \"'libs/src/str/Makefile'\" unpacked with wrong size!
  193. fi
  194. # end of 'libs/src/str/Makefile'
  195. fi
  196. if test -f 'libs/src/str/strparse.c' -a "${1}" != "-c" ; then 
  197.   echo shar: Will not clobber existing file \"'libs/src/str/strparse.c'\"
  198. else
  199. echo shar: Extracting \"'libs/src/str/strparse.c'\" \(4683 characters\)
  200. sed "s/^X//" >'libs/src/str/strparse.c' <<'END_OF_FILE'
  201. X/*
  202. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  203. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  204. X * and conditions for redistribution.
  205. X */
  206. X
  207. Xstatic char RCSid[] = "$Id: strparse.c,v 3.1 1993/06/13 02:48:19 panos Exp $" ;
  208. Xstatic char version[] = VERSION ;
  209. X
  210. X#include "str.h"
  211. X#include "strparse.h"
  212. X
  213. Xchar *strcpy() ;
  214. Xchar *strncpy() ;
  215. Xchar *strpbrk() ;
  216. X
  217. Xchar *malloc() ;
  218. X
  219. Xint str_errno ;
  220. X
  221. X
  222. XPRIVATE char *new_string( s )
  223. X    register char *s ;
  224. X{
  225. X    register char *p = malloc( (unsigned)strlen( s ) + 1 ) ;
  226. X
  227. X    return( p ? strcpy( p, s ) : p ) ;
  228. X}
  229. X
  230. X
  231. Xstr_h str_parse( str, separ, flags, errnop )
  232. X    register char    *str ;
  233. X    char                *separ ;
  234. X    int                flags ;
  235. X    int                *errnop ;
  236. X{
  237. X    register struct str_handle *hp ;
  238. X    int *errp = ( errnop == NULL ) ? &str_errno : errnop ;
  239. X
  240. X    if ( separ == NULL )
  241. X        HANDLE_ERROR( flags, NULL, errp, STR_ENULLSEPAR,
  242. X                                "STR str_parse: NULL separator\n" ) ;
  243. X
  244. X    hp = (struct str_handle *) malloc( sizeof( struct str_handle ) ) ;
  245. X    if ( hp == NULL )
  246. X        HANDLE_ERROR( flags, NULL, errp, STR_ENOMEM,
  247. X                                "STR str_parse: malloc failed\n" ) ;
  248. X
  249. X    hp->string = str ;
  250. X    hp->pos = str ;
  251. X    hp->separator = new_string( separ ) ;
  252. X    if ( hp->separator == NULL )
  253. X        if ( flags & STR_RETURN_ERROR )
  254. X        {
  255. X            free( (char *) hp ) ;
  256. X            *errp = STR_ENOMEM ;
  257. X            return( NULL ) ;
  258. X        }
  259. X        else
  260. X            TERMINATE( "STR str_parse: malloc failed\n" ) ;
  261. X    
  262. X    hp->flags = flags ;
  263. X    hp->errnop = errp ;
  264. X    hp->no_more = ( str == NULL ) ;
  265. X    return( (str_h) hp ) ;
  266. X}
  267. X
  268. X
  269. Xvoid str_endparse( handle )
  270. X    str_h handle ;
  271. X{
  272. X    register struct str_handle *hp = (struct str_handle *) handle ;
  273. X
  274. X    free( hp->separator ) ;
  275. X    free( (char *) handle ) ;
  276. X}
  277. X
  278. X
  279. X/*
  280. X * Change the string
  281. X */
  282. Xint str_setstr( handle, newstr )
  283. X    str_h handle ;
  284. X    char *newstr ;
  285. X{
  286. X    register struct str_handle *hp = (struct str_handle *) handle ;
  287. X    
  288. X    if ( newstr == NULL )
  289. X        HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSTRING,
  290. X                                "STR str_setstr: NULL string\n" ) ;
  291. X    
  292. X    hp->string = newstr ;
  293. X    hp->pos = newstr ;
  294. X    hp->no_more = FALSE ;
  295. X    return( STR_OK ) ;
  296. X}
  297. X
  298. X
  299. X
  300. X/*
  301. X * Change the separator
  302. X */
  303. Xint str_separator( handle, separator )
  304. X    str_h handle ;
  305. X    char *separator ;
  306. X{
  307. X    register struct str_handle *hp = (struct str_handle *) handle ;
  308. X    char *new_separator ;
  309. X
  310. X    if ( separator == NULL )
  311. X        HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSEPAR,
  312. X                                "STR str_separator: NULL separator\n" ) ;
  313. X    new_separator = new_string( separator ) ;
  314. X    if ( new_separator == NULL )
  315. X        HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENOMEM,
  316. X            "STR str_separator: malloc failed\n" ) ;
  317. X
  318. X    free( hp->separator ) ;
  319. X    hp->separator = new_separator ;
  320. X    return( STR_OK ) ;
  321. X}
  322. X
  323. X
  324. Xchar *str_nextpos( handle )
  325. X    str_h handle ;
  326. X{
  327. X    struct str_handle *hp = (struct str_handle *) handle ;
  328. X
  329. X    if ( hp->no_more || *hp->pos == '\0' )
  330. X        return( NULL ) ;
  331. X    else
  332. X        return( hp->pos ) ;
  333. X}
  334. X
  335. X
  336. Xchar *str_component( handle )
  337. X    str_h handle ;
  338. X{
  339. X    register char                        *start ;
  340. X    register char                        *last ;
  341. X    register int                        sep_count ;
  342. X    char                                    *retval ;
  343. X    int                                    last_char ;
  344. X    register struct str_handle        *hp            = (struct str_handle *) handle ;
  345. X    register int                        first_call    = ( hp->pos == hp->string ) ;
  346. X
  347. X    if ( hp->no_more )
  348. X        return( NULL ) ;
  349. X
  350. X    /*
  351. X     * Get number of separator characters.
  352. X     * Find beginning of component.
  353. X     */
  354. X    sep_count = strspn( hp->pos, hp->separator ) ;
  355. X
  356. X    /*
  357. X     * If this is the first call, and there are separator characters
  358. X     * at the beginning of the string and the STR_NULL_START flag is set
  359. X     * we return a 0-length string.
  360. X     */
  361. X    if ( first_call && sep_count > 0 && ( hp->flags & STR_NULL_START ) )
  362. X    {
  363. X        start = hp->pos ;
  364. X        last = hp->pos ;
  365. X    }
  366. X    else
  367. X    {
  368. X        start = hp->pos + sep_count ;
  369. X
  370. X        if ( *start == '\0' )
  371. X        {
  372. X            last = start ;
  373. X            hp->no_more = TRUE ;
  374. X            if ( ! ( hp->flags & STR_NULL_END ) )
  375. X                return( NULL ) ;
  376. X        }
  377. X        else
  378. X        {
  379. X            last = strpbrk( start, hp->separator ) ;
  380. X            if ( last == NULL )
  381. X                last = start + strlen( start ) ;
  382. X        }
  383. X    }
  384. X
  385. X    /*
  386. X     * At this point, the following variables must be set:
  387. X     *        start:    beginning of component
  388. X     *        last:       end of component + 1
  389. X     *
  390. X     * If STR_MALLOC is set, allocate space for the new string.
  391. X     *
  392. X     * NOTE: If STR_MALLOC is not set, the processed string is trashed.
  393. X     */
  394. X    last_char = *last ;
  395. X    if ( hp->flags & STR_MALLOC )
  396. X    {
  397. X        int len = last - start ;
  398. X
  399. X        retval = malloc( (unsigned)len + 1 ) ;
  400. X        if ( retval == NULL )
  401. X            HANDLE_ERROR( hp->flags, NULL, hp->errnop, STR_ENOMEM,
  402. X                                            "STR str_component: malloc failed\n" ) ;
  403. X        strncpy( retval, start, len )[ len ] = '\0' ;
  404. X    }
  405. X    else
  406. X    {
  407. X        retval = start ;
  408. X        *last = '\0' ;
  409. X    }
  410. X
  411. X    /*
  412. X     * Check if last_char is NUL to avoid setting hp->pos past the
  413. X     * end of the string
  414. X     */
  415. X    hp->pos = ( last_char == '\0' ) ? last : last+1 ;
  416. X    return( retval ) ;
  417. X}
  418. X
  419. X
  420. END_OF_FILE
  421. if test 4683 -ne `wc -c <'libs/src/str/strparse.c'`; then
  422.     echo shar: \"'libs/src/str/strparse.c'\" unpacked with wrong size!
  423. fi
  424. # end of 'libs/src/str/strparse.c'
  425. fi
  426. if test -f 'libs/src/xlog/xlog.c' -a "${1}" != "-c" ; then 
  427.   echo shar: Will not clobber existing file \"'libs/src/xlog/xlog.c'\"
  428. else
  429. echo shar: Extracting \"'libs/src/xlog/xlog.c'\" \(4717 characters\)
  430. sed "s/^X//" >'libs/src/xlog/xlog.c' <<'END_OF_FILE'
  431. X/*
  432. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  433. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  434. X * and conditions for redistribution.
  435. X */
  436. X
  437. Xstatic char RCSid[] = "$Id: xlog.c,v 2.1 1993/05/06 07:39:39 panos Exp $" ;
  438. Xstatic char version[] = VERSION ;
  439. X
  440. X#include <varargs.h>
  441. X
  442. X#include "xlog.h"
  443. X#include "impl.h"
  444. X
  445. Xchar *malloc() ;
  446. X
  447. Xextern struct xlog_ops __xlog_filelog_ops ;
  448. X#ifndef NO_SYSLOG
  449. Xextern struct xlog_ops __xlog_syslog_ops ;
  450. X#endif
  451. X
  452. Xstruct lookup_table
  453. X{
  454. X    struct xlog_ops    *ops ;
  455. X    xlog_e                type ;
  456. X} ;
  457. X
  458. Xstatic struct lookup_table ops_lookup_table[] =
  459. X    {
  460. X        { &__xlog_filelog_ops,                XLOG_FILELOG    },
  461. X#ifndef NO_SYSLOG
  462. X        { &__xlog_syslog_ops,                XLOG_SYSLOG        },
  463. X#endif
  464. X        { NULL }
  465. X    } ;
  466. X
  467. X
  468. X#define CALLBACK( xp, status )                                                                 \
  469. X        if ( (xp)->xl_callback )                                                                 \
  470. X            (*(xp)->xl_callback)( (xlog_h)(xp), status, (xp)->xl_callback_arg )
  471. X
  472. X
  473. XPRIVATE void xlog_link() ;
  474. XPRIVATE void xlog_unlink() ;
  475. X
  476. X
  477. XPRIVATE struct xlog_ops *xlog_ops_lookup( type )
  478. X    register xlog_e type ;
  479. X{
  480. X    register struct lookup_table *ltp ;
  481. X
  482. X    for ( ltp = &ops_lookup_table[ 0 ] ; ltp->ops ; ltp++ )
  483. X        if ( ltp->type == type )
  484. X            break ;
  485. X    return( ltp->ops ) ;
  486. X}
  487. X
  488. X
  489. X
  490. X/* VARARGS3 */
  491. Xxlog_h xlog_create( type, id, flags, va_alist )
  492. X    xlog_e    type ;
  493. X    char        *id ;
  494. X    int        flags ;
  495. X    va_dcl
  496. X{
  497. X    xlog_s                *xp ;
  498. X    va_list                ap ;
  499. X    struct xlog_ops    *xops ;
  500. X    int                    status ;
  501. X
  502. X    if ( ( xp = NEW( xlog_s ) ) == NULL )
  503. X        return( NULL ) ;
  504. X    
  505. X    if ( id == NULL || ( xp->xl_id = __xlog_new_string( id ) ) == NULL )
  506. X    {
  507. X        FREE( xp ) ;
  508. X        return( NULL ) ;
  509. X    }
  510. X
  511. X    xops = xlog_ops_lookup( type ) ;
  512. X    
  513. X    if ( xops != NULL )
  514. X    {
  515. X        va_start( ap ) ;
  516. X        xp->xl_ops = xops ;
  517. X        status = XL_INIT( xp, ap ) ;
  518. X        va_end( ap ) ;
  519. X
  520. X        if ( status == XLOG_ENOERROR )
  521. X        {
  522. X            xp->xl_flags = flags ;
  523. X            xp->xl_type = type ;
  524. X            xp->xl_clients = XLOG_NULL ;
  525. X            xp->xl_use = XLOG_NULL ;
  526. X            return( (xlog_h) xp ) ;
  527. X        }
  528. X    }
  529. X
  530. X    free( xp->xl_id ) ;
  531. X    FREE( xp ) ;
  532. X    return( NULL ) ;
  533. X}
  534. X
  535. X
  536. X
  537. XPRIVATE void xlog_link( client, server )
  538. X    xlog_s *client, *server ;
  539. X{
  540. X    client->xl_use = server ;
  541. X    if ( server == NULL )
  542. X        return ;
  543. X
  544. X    if ( server->xl_clients == XLOG_NULL )
  545. X    {
  546. X        INIT_LINKS( client, xl_other_users ) ;
  547. X        server->xl_clients = client ;
  548. X    }
  549. X    else
  550. X        LINK( server, client, xl_other_users ) ;
  551. X}
  552. X
  553. X
  554. XPRIVATE void xlog_unlink( xp )
  555. X    xlog_s *xp ;
  556. X{
  557. X    xlog_s *server = xp->xl_use ;
  558. X
  559. X    /*
  560. X     * Step 1: remove from server chain
  561. X     */
  562. X    if ( server != XLOG_NULL )
  563. X    {
  564. X        if ( server->xl_clients == xp )
  565. X            if ( NEXT( xp, xl_other_users ) == xp )
  566. X                server->xl_clients = XLOG_NULL ;
  567. X            else
  568. X                server->xl_clients = NEXT( xp, xl_other_users ) ;
  569. X        else
  570. X            UNLINK( xp, xl_other_users ) ;
  571. X    }
  572. X
  573. X    /*
  574. X     * Step 2: If we have users, clear their link to us.
  575. X     */
  576. X    if ( xp->xl_clients != NULL )
  577. X    {
  578. X        xlog_s *xp2 = xp->xl_clients ;
  579. X
  580. X        do
  581. X        {
  582. X            xp2->xl_use = XLOG_NULL ;
  583. X            xp2 = NEXT( xp2, xl_other_users ) ;
  584. X        }
  585. X        while ( xp2 != xp->xl_clients ) ;
  586. X    }
  587. X}
  588. X
  589. X
  590. XPRIVATE void xlog_flags( xp, cmd, ap )
  591. X    xlog_s        *xp ;
  592. X    xlog_cmd_e    cmd ;
  593. X    va_list        ap ;
  594. X{
  595. X    int    flag            = va_arg( ap, int ) ;
  596. X    int    old_value    = ( ( xp->xl_flags & flag ) != 0 ) ;
  597. X    int    *valp            = va_arg( ap, int * ) ;
  598. X
  599. X    if ( cmd == XLOG_SETFLAG )
  600. X        if ( *valp )
  601. X            xp->xl_flags |= flag ;
  602. X        else
  603. X            xp->xl_flags &= ~flag ;
  604. X    *valp = old_value ;
  605. X}
  606. X
  607. X
  608. Xvoid xlog_destroy( xlog )
  609. X    xlog_h xlog ;
  610. X{
  611. X    xlog_s *xp = XP( xlog ) ;
  612. X
  613. X    xlog_unlink( xp ) ;
  614. X    XL_FINI( xp ) ;
  615. X    free( xp->xl_id ) ;
  616. X    FREE( xp ) ;
  617. X}
  618. X
  619. X
  620. X/* VARARGS4 */
  621. Xvoid xlog_write( xlog, buf, len, flags, va_alist )
  622. X    xlog_h    xlog ;
  623. X    char        buf[] ;
  624. X    int        len ;
  625. X    int        flags ;
  626. X    va_dcl
  627. X{
  628. X    xlog_s    *xp = XP( xlog ) ;
  629. X    va_list    ap ;
  630. X    int        status ;
  631. X
  632. X    va_start( ap ) ;
  633. X    status = XL_WRITE( xp, buf, len, flags, ap ) ;
  634. X    va_end( ap ) ;
  635. X
  636. X    if ( status != XLOG_ENOERROR )
  637. X    {
  638. X        CALLBACK( xp, status ) ;
  639. X    }
  640. X}
  641. X
  642. X
  643. X/* VARARGS2 */
  644. Xint xlog_control( xlog, cmd, va_alist )
  645. X    xlog_h        xlog ;
  646. X    xlog_cmd_e    cmd ;
  647. X    va_dcl
  648. X{
  649. X    va_list    ap ;
  650. X    xlog_s    *xp        = XP( xlog ) ;
  651. X    int        status    = XLOG_ENOERROR ;
  652. X
  653. X    va_start( ap ) ;
  654. X
  655. X    switch ( cmd )
  656. X    {
  657. X        case XLOG_LINK:
  658. X            xlog_unlink( xp ) ;
  659. X            xlog_link( xp, va_arg( ap, xlog_s * ) ) ;
  660. X            xp->xl_callback_arg = va_arg( ap, void * ) ;
  661. X            break ;
  662. X        
  663. X        case XLOG_CALLBACK:
  664. X            xp->xl_callback = va_arg( ap, voidfunc ) ;
  665. X            break ;
  666. X            
  667. X        case XLOG_GETFLAG:
  668. X        case XLOG_SETFLAG:
  669. X            xlog_flags( xp, cmd, ap ) ;
  670. X            break ;
  671. X
  672. X        default:
  673. X            status = XL_CONTROL( xp, cmd, ap ) ;
  674. X    }
  675. X
  676. X    va_end( ap ) ;
  677. X
  678. X    return( status ) ;
  679. X}
  680. X
  681. X
  682. Xint xlog_parms( type, va_alist )
  683. X    xlog_e type ;
  684. X    va_dcl
  685. X{
  686. X    va_list    ap ;
  687. X    int        status ;
  688. X
  689. X    va_start( ap ) ;
  690. X    switch ( type )
  691. X    {
  692. X#ifndef NO_SYSLOG
  693. X        case XLOG_SYSLOG:
  694. X            status = (*__xlog_syslog_ops.parms)( ap ) ;
  695. X            break ;
  696. X#endif
  697. X        case XLOG_FILELOG:
  698. X            status = (*__xlog_filelog_ops.parms)( ap ) ;
  699. X            break ;
  700. X        
  701. X        default:
  702. X            status = XLOG_ENOERROR ;
  703. X    }
  704. X    va_end( ap ) ;
  705. X    return( status ) ;
  706. X}
  707. X
  708. END_OF_FILE
  709. if test 4717 -ne `wc -c <'libs/src/xlog/xlog.c'`; then
  710.     echo shar: \"'libs/src/xlog/xlog.c'\" unpacked with wrong size!
  711. fi
  712. # end of 'libs/src/xlog/xlog.c'
  713. fi
  714. if test -f 'xinetd/conf.c' -a "${1}" != "-c" ; then 
  715.   echo shar: Will not clobber existing file \"'xinetd/conf.c'\"
  716. else
  717. echo shar: Extracting \"'xinetd/conf.c'\" \(4677 characters\)
  718. sed "s/^X//" >'xinetd/conf.c' <<'END_OF_FILE'
  719. X/*
  720. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  721. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  722. X * and conditions for redistribution.
  723. X */
  724. X
  725. Xstatic char RCSid[] = "$Id: conf.c,v 6.4 1993/06/01 22:59:39 panos Exp $" ;
  726. X
  727. X#include <sys/types.h>
  728. X#include <netinet/in.h>
  729. X#include <syslog.h>
  730. X#include <fcntl.h>
  731. X#include <string.h>
  732. X#include <netdb.h>
  733. X
  734. X#include "pset.h"
  735. X#include "misc.h"
  736. X#include "xlog.h"
  737. X
  738. X#include "attr.h"
  739. X#include "config.h"
  740. X#include "conf.h"
  741. X#include "defs.h"
  742. X#include "service.h"
  743. X#include "state.h"
  744. X
  745. Xvoid msg() ;
  746. Xvoid out_of_memory() ;
  747. X
  748. X
  749. Xvoid cnf_free( confp )
  750. X    struct configuration *confp ;
  751. X{
  752. X    register unsigned u ;
  753. X    pset_h sconfs = confp->cnf_service_confs ;
  754. X
  755. X    for ( u = 0 ; u < pset_count( sconfs ) ; u++ )
  756. X        sc_free( SCP( pset_pointer( sconfs, u ) ) ) ;
  757. X    pset_destroy( sconfs ) ;
  758. X    if ( confp->cnf_defaults )
  759. X        sc_free( confp->cnf_defaults ) ;
  760. X}
  761. X
  762. X
  763. X/*
  764. X * Extract from 'confp' the service that matches 'scp'
  765. X */
  766. Xstruct service_config *cnf_extract( confp, scp )
  767. X    struct configuration *confp ;
  768. X    struct service_config *scp ;
  769. X{
  770. X    pset_h stab = confp->cnf_service_confs ;
  771. X   register unsigned u ;
  772. X
  773. X   for ( u = 0 ; u < pset_count( stab ) ; u++ )
  774. X   {
  775. X      struct service_config *iscp = SCP( pset_pointer( stab, u ) ) ;
  776. X
  777. X      if ( ! EQ( scp->sc_id, iscp->sc_id ) || sc_different_confs( scp, iscp ) )
  778. X         continue ;
  779. X
  780. X        pset_remove_index( stab, u ) ;
  781. X        return( iscp ) ;
  782. X   }
  783. X   return( NULL ) ;
  784. X}
  785. X
  786. X
  787. X
  788. Xvoid cnf_dump( confp, fd )
  789. X    struct configuration *confp ;
  790. X    int fd ;
  791. X{
  792. X    pset_h stab = confp->cnf_service_confs ;
  793. X    register unsigned u ;
  794. X    void tabprint() ;
  795. X
  796. X    sc_dump( confp->cnf_defaults, fd, 0, TRUE ) ;
  797. X    tabprint( fd, 0, "\n" ) ;
  798. X
  799. X    for ( u = 0 ; u < pset_count( stab ) ; u++ )
  800. X    {
  801. X        sc_dump( SCP( pset_pointer( stab, u ) ), fd, 0, FALSE ) ;
  802. X        Sputchar( fd, '\n' ) ;
  803. X    }
  804. X}
  805. X
  806. X
  807. Xstatus_e cnf_init( confp, fdp, iterp )
  808. X    struct configuration *confp ;
  809. X    int *fdp ;
  810. X    psi_h *iterp ;
  811. X{
  812. X    int fd ;
  813. X    pset_h pset ;
  814. X    psi_h pset_iter ;
  815. X    struct service_config *scp ;
  816. X    char *func = "cnf_init" ;
  817. X
  818. X    /*
  819. X     * Open configuration file
  820. X     */
  821. X   fd = open( ps.ros.config_file, O_RDONLY ) ;
  822. X
  823. X   if ( fd == -1 )
  824. X   {
  825. X      msg( LOG_ERR, func, "open( %s ) failed: %m", ps.ros.config_file ) ;
  826. X        return( FAILED ) ;
  827. X   }
  828. X
  829. X    if ( ( pset = pset_create( 0, 0 ) ) == NULL )
  830. X    {
  831. X        msg( LOG_CRIT, func, "can't create service table" ) ;
  832. X        (void) close( fd ) ;
  833. X        return( FAILED ) ;
  834. X    }
  835. X
  836. X    if ( ( scp = sc_alloc( CHAR_NULL ) ) == NULL )
  837. X    {
  838. X        msg( LOG_ERR, func, "can't allocate defaults service" ) ;
  839. X        pset_destroy( pset ) ;
  840. X        (void) close( fd ) ;
  841. X        return( FAILED ) ;
  842. X    }
  843. X
  844. X    if ( ( pset_iter = psi_create( pset ) ) == NULL )
  845. X    {
  846. X        msg( LOG_ERR, func, "can't create service table iterator" ) ;
  847. X        sc_free( scp ) ;
  848. X        pset_destroy( pset ) ;
  849. X        (void) close( fd ) ;
  850. X        return( FAILED ) ;
  851. X    }
  852. X
  853. X    *fdp = fd ;
  854. X    confp->cnf_service_confs = pset ;
  855. X    confp->cnf_defaults = scp ;
  856. X    *iterp = pset_iter ;
  857. X    return( OK ) ;
  858. X}
  859. X
  860. X
  861. XPRIVATE void destroy_service( sp )
  862. X    struct service *sp ;
  863. X{
  864. X    svc_deactivate( sp ) ;
  865. X    svc_free( sp ) ;
  866. X}
  867. X
  868. X
  869. X/*
  870. X * Try to start all services.
  871. X * Return the # of services started.
  872. X */
  873. Xunsigned cnf_start_services( confp )
  874. X    struct configuration *confp ;
  875. X{
  876. X    pset_h sconfs = confp->cnf_service_confs ;
  877. X    unsigned services_started = 0 ;
  878. X    register unsigned u ;
  879. X    char *func = "cnf_start_services" ;
  880. X
  881. X    for ( u = 0 ; u < pset_count( sconfs ) ; u++ )
  882. X    {
  883. X        register struct service_config *scp = SCP( pset_pointer( sconfs, u ) ) ;
  884. X        register struct service *sp ;
  885. X
  886. X        if ( ( sp = svc_new( scp ) ) == NULL )
  887. X        {
  888. X            sc_free( scp ) ;
  889. X            continue ;
  890. X        }
  891. X
  892. X        if ( svc_activate( sp ) == FAILED )
  893. X        {
  894. X            svc_free( sp ) ;
  895. X            continue ;
  896. X        }
  897. X
  898. X        /*
  899. X         * descriptors_free can be negative without a descriptor-allocating
  900. X         * system call failing because some of the descriptors we reserve
  901. X         * are transient
  902. X         */
  903. X        if ( ps.rws.descriptors_free < 0 )
  904. X        {
  905. X            msg( LOG_ERR, func,
  906. X                "Service %s disabled because of lack of file descriptors",
  907. X                    SVC_ID( sp ) ) ;
  908. X            destroy_service( sp ) ;
  909. X            continue ;
  910. X        }
  911. X
  912. X        /*
  913. X         * Activation successful; add service to service table
  914. X         */
  915. X        if ( pset_add( SERVICES( ps ), sp ) == NULL )
  916. X        {
  917. X            out_of_memory( func ) ;
  918. X            destroy_service( sp ) ;
  919. X            break ;
  920. X        }
  921. X
  922. X        SVC_HOLD( sp ) ;
  923. X
  924. X        services_started++ ;
  925. X
  926. X        if ( debug.on )
  927. X            msg( LOG_DEBUG, func, "Started service: %s", SVC_ID( sp ) ) ;
  928. X    }
  929. X
  930. X    /*
  931. X     * All the configurations have been linked to their services
  932. X     * so we don't need to hold references to them in the pset.
  933. X     * We need to clear the pset so that the cnf_free will not free the memory.
  934. X     */
  935. X    pset_clear( sconfs ) ;
  936. X
  937. X    if ( debug.on )
  938. X        msg( LOG_DEBUG, func, "mask_max = %d, services_started = %d",
  939. X                ps.rws.mask_max, services_started ) ;
  940. X            
  941. X    return( services_started ) ;
  942. X}
  943. X
  944. X
  945. X
  946. END_OF_FILE
  947. if test 4677 -ne `wc -c <'xinetd/conf.c'`; then
  948.     echo shar: \"'xinetd/conf.c'\" unpacked with wrong size!
  949. fi
  950. # end of 'xinetd/conf.c'
  951. fi
  952. if test -f 'xinetd/msg.c' -a "${1}" != "-c" ; then 
  953.   echo shar: Will not clobber existing file \"'xinetd/msg.c'\"
  954. else
  955. echo shar: Extracting \"'xinetd/msg.c'\" \(4533 characters\)
  956. sed "s/^X//" >'xinetd/msg.c' <<'END_OF_FILE'
  957. X/*
  958. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  959. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  960. X * and conditions for redistribution.
  961. X */
  962. X
  963. Xstatic char RCSid[] = "$Id: msg.c,v 6.6 1993/06/15 23:25:57 panos Exp $" ;
  964. X
  965. X#include <syslog.h>
  966. X#include <fcntl.h>
  967. X
  968. X#include "sio.h"
  969. X#include "str.h"
  970. X#include "xlog.h"
  971. X
  972. X#include "options.h"
  973. X
  974. X#include "state.h"
  975. X#include "defs.h"
  976. X#include "config.h"
  977. X
  978. X
  979. Xstatic struct name_value priorities[] =
  980. X    {
  981. X        { "WARNING",        LOG_WARNING        },
  982. X        { "ERROR",            LOG_ERR            },
  983. X        { "CRITICAL",        LOG_CRIT            },
  984. X        { "NOTICE",            LOG_NOTICE        },
  985. X        { "DEBUG",            LOG_DEBUG        },
  986. X        { "INFO",            LOG_INFO            },
  987. X        { NULL,                1                    },
  988. X        { "UNKNOWN",        0                    }
  989. X    } ;
  990. X
  991. X
  992. Xextern int line_count ;
  993. Xextern struct name_value syslog_facilities[] ;
  994. X
  995. Xvoid msg() ;
  996. X
  997. X#define BUFSIZE                            2048
  998. X
  999. X#define DEFAULT_SYSLOG_LEVEL            LOG_INFO
  1000. X
  1001. X
  1002. Xchar *msg_init()
  1003. X{
  1004. X    xlog_h        xh ;
  1005. X    int            fd ;
  1006. X    xlog_e        type_of_xlog ;
  1007. X    bool_int        facility_error = FALSE ;
  1008. X    char            *func                = "msg_init" ;
  1009. X
  1010. X    if ( debug.on )
  1011. X    {
  1012. X        type_of_xlog = XLOG_FILELOG ;
  1013. X        xh = xlog_create( type_of_xlog, program_name, XLOG_NOFLAGS,
  1014. X                                            "/dev/tty", O_APPEND + O_WRONLY, 0 ) ;
  1015. X        debug.fd = -1 ;
  1016. X    }
  1017. X    else
  1018. X    {
  1019. X        if ( filelog_option )
  1020. X        {
  1021. X            type_of_xlog = XLOG_FILELOG ;
  1022. X            xh = xlog_create( type_of_xlog, program_name,
  1023. X                        XLOG_PRINT_ID + XLOG_PRINT_PID,
  1024. X                            filelog_option_arg, LOG_OPEN_FLAGS, LOG_FILE_MODE ) ;
  1025. X        }
  1026. X        else
  1027. X        {
  1028. X            int facility = DEFAULT_SYSLOG_FACILITY ;
  1029. X            
  1030. X            if ( syslog_option )
  1031. X            {
  1032. X                struct name_value *nvp ;
  1033. X
  1034. X                nvp = nv_find_value( syslog_facilities, syslog_option_arg ) ;
  1035. X                if ( nvp != NULL )
  1036. X                    facility = nvp->value ;
  1037. X                else
  1038. X                    facility_error = TRUE ;
  1039. X            }
  1040. X
  1041. X            type_of_xlog = XLOG_SYSLOG ;
  1042. X            xh = xlog_create( type_of_xlog, program_name, XLOG_NOFLAGS,
  1043. X                                                    facility, DEFAULT_SYSLOG_LEVEL ) ;
  1044. X        }
  1045. X    }
  1046. X
  1047. X    if ( xh == NULL )
  1048. X    {
  1049. X        /*
  1050. X         * This simply returns the most likely reason for failure.
  1051. X         * We can't do any better since xlog_create does not return an
  1052. X         * error code.
  1053. X         */
  1054. X        if ( type_of_xlog == XLOG_SYSLOG )
  1055. X            return( "can't connect to syslog" ) ;
  1056. X        else if ( type_of_xlog == XLOG_FILELOG )
  1057. X            return( "can't open log file" ) ;
  1058. X        else
  1059. X            return( "unknown reason" ) ;
  1060. X    }
  1061. X    
  1062. X    if ( xlog_control( xh, XLOG_GETFD, &fd ) == XLOG_ENOERROR )
  1063. X    {
  1064. X        if ( fcntl( fd, F_SETFD, 1 ) == -1 )
  1065. X        {
  1066. X            xlog_destroy( xh ) ;
  1067. X            return( "can't set close-on-exec flag of log file" ) ;
  1068. X        }
  1069. X        if ( debug.on )
  1070. X            debug.fd = fd ;
  1071. X    }
  1072. X    
  1073. X    ps.rws.program_log = xh ;
  1074. X
  1075. X    if ( facility_error )
  1076. X        msg( LOG_ERR, func, "Bad syslog facility: %s", syslog_option_arg ) ;
  1077. X    return( CHAR_NULL ) ;
  1078. X}
  1079. X
  1080. X
  1081. Xvoid msg_suspend()
  1082. X{
  1083. X    (void) xlog_control( ps.rws.program_log, XLOG_PREEXEC ) ;
  1084. X}
  1085. X
  1086. X
  1087. Xvoid msg_resume()
  1088. X{
  1089. X    (void) xlog_control( ps.rws.program_log, XLOG_POSTEXEC ) ;
  1090. X}
  1091. X
  1092. X
  1093. X/*
  1094. X * The size argument is a value-result argument
  1095. X */
  1096. XPRIVATE int prepare_buffer( level, func, buf, size, fmt, ap )
  1097. X    int            level ;
  1098. X    char            *func ;
  1099. X    char            *buf ;
  1100. X    unsigned     size ;
  1101. X    char            *fmt ;
  1102. X    va_list        ap ;
  1103. X{
  1104. X    int            cc ;
  1105. X    char            *bufstart    = buf ;
  1106. X    unsigned     bytes_left    = size ;
  1107. X
  1108. X    /*
  1109. X     * Check if we need to print the level name
  1110. X     */
  1111. X    if ( debug.on || filelog_option )
  1112. X    {
  1113. X        cc = strx_nprint( bufstart, bytes_left,
  1114. X                                            "%s: ", nv_get_name( priorities, level ) ) ;
  1115. X        bufstart += cc ;
  1116. X        bytes_left -= cc ;
  1117. X    }
  1118. X
  1119. X    /*
  1120. X     * Check if we need to print the function name
  1121. X     */
  1122. X    if ( debug.on || level == LOG_CRIT )
  1123. X    {
  1124. X        cc = strx_nprint( bufstart, bytes_left, "{%s} ", func ) ;
  1125. X        bufstart += cc ;
  1126. X        bytes_left -= cc ;
  1127. X    }
  1128. X
  1129. X    cc = strx_nprintv( bufstart, bytes_left, fmt, ap ) ;
  1130. X
  1131. X    bytes_left -= cc ;
  1132. X
  1133. X    return( size - bytes_left ) ;
  1134. X}
  1135. X
  1136. X
  1137. X/* VARARGS3 */
  1138. Xvoid msg( level, func, fmt, va_alist )
  1139. X    int        level ;
  1140. X    char        *func ;
  1141. X    char        *fmt ;
  1142. X    va_dcl
  1143. X{
  1144. X    va_list    ap ;
  1145. X    char        buf[ BUFSIZE ] ;
  1146. X    int        len ;
  1147. X
  1148. X    va_start( ap ) ;
  1149. X    len = prepare_buffer( level, func, buf, sizeof( buf ), fmt, ap ) ;
  1150. X    va_end( ap ) ;
  1151. X
  1152. X    xlog_write( ps.rws.program_log, buf, len, XLOG_SET_LEVEL, level ) ;
  1153. X}
  1154. X
  1155. X
  1156. X/*
  1157. X * Parser message.
  1158. X * There are 2 differences from msg():
  1159. X *        1) parsemsg() prints the line #
  1160. X *        2) parsemsg() does not interpret %m
  1161. X */
  1162. X/* VARARGS3 */
  1163. Xvoid parsemsg( msg_level, func, fmt, va_alist )
  1164. X    int        msg_level ;
  1165. X    char        *func ;
  1166. X    char        *fmt ;
  1167. X    va_dcl
  1168. X{
  1169. X    va_list    ap ;
  1170. X    char        buf[ BUFSIZE ] ;
  1171. X    int        cc ;
  1172. X    int        len ;
  1173. X
  1174. X    va_start( ap ) ;
  1175. X    len = prepare_buffer( msg_level, func, buf, sizeof( buf ), fmt, ap ) ;
  1176. X    va_end( ap ) ;
  1177. X
  1178. X    cc = strx_nprint( &buf[ len ], sizeof(buf)-len, " [line=%d]", line_count ) ;
  1179. X    len += cc ;
  1180. X
  1181. X    xlog_write( ps.rws.program_log, buf, len, 
  1182. X            XLOG_NO_ERRNO + XLOG_SET_LEVEL, msg_level ) ;
  1183. X}
  1184. X
  1185. END_OF_FILE
  1186. if test 4533 -ne `wc -c <'xinetd/msg.c'`; then
  1187.     echo shar: \"'xinetd/msg.c'\" unpacked with wrong size!
  1188. fi
  1189. # end of 'xinetd/msg.c'
  1190. fi
  1191. if test -f 'xinetd/special.c' -a "${1}" != "-c" ; then 
  1192.   echo shar: Will not clobber existing file \"'xinetd/special.c'\"
  1193. else
  1194. echo shar: Extracting \"'xinetd/special.c'\" \(4537 characters\)
  1195. sed "s/^X//" >'xinetd/special.c' <<'END_OF_FILE'
  1196. X/*
  1197. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  1198. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1199. X * and conditions for redistribution.
  1200. X */
  1201. X
  1202. Xstatic char RCSid[] = "$Id: special.c,v 6.10 1993/06/15 23:25:57 panos Exp $" ;
  1203. X
  1204. X#include <sys/types.h>
  1205. X#include <sys/socket.h>
  1206. X#include <syslog.h>
  1207. X#include <signal.h>
  1208. X
  1209. X#include "misc.h"
  1210. X
  1211. X#include "options.h"
  1212. X
  1213. X#include "state.h"
  1214. X#include "conf.h"
  1215. X#include "sconst.h"
  1216. X#include "server.h"
  1217. X#include "config.h"
  1218. X#include "builtin.h"
  1219. X#include "connection.h"
  1220. X
  1221. Xvoid msg() ;
  1222. Xvoid out_of_memory() ;
  1223. X
  1224. Xextern struct name_value socket_types[] ;
  1225. X
  1226. XPRIVATE void stream_logging() ;
  1227. XPRIVATE void stream_shutdown() ;
  1228. Xvoid intercept() ;
  1229. X
  1230. Xstatic struct builtin_service special_services[] =
  1231. X    {
  1232. X        { LOG_SERVICE_NAME,             SOCK_STREAM,    { stream_logging,        FORK    } },
  1233. X        { SHUTDOWN_SERVICE_NAME,    SOCK_STREAM,   { stream_shutdown,      FORK  } },
  1234. X        { INTERCEPT_SERVICE_NAME,    SOCK_STREAM,    { intercept,            FORK    } },
  1235. X        { INTERCEPT_SERVICE_NAME,    SOCK_DGRAM,        { intercept,            FORK    } },
  1236. X        { NULL }
  1237. X    } ;
  1238. X
  1239. X
  1240. Xbuiltin_s *spec_find( service_name, type )
  1241. X   char *service_name ;
  1242. X   int type ;
  1243. X{
  1244. X    builtin_s *bp ;
  1245. X    struct name_value *nvp ;
  1246. X    char *func = "spec_find" ;
  1247. X
  1248. X    if ( bp = builtin_lookup( special_services, service_name, type ) )
  1249. X        return( bp ) ;
  1250. X
  1251. X    nvp = nv_find_name( socket_types, type ) ;
  1252. X    if ( nvp == NULL )
  1253. X    {
  1254. X        msg( LOG_ERR, func, "unknown socket type: %d", type ) ;
  1255. X        return( NULL ) ;
  1256. X    }
  1257. X
  1258. X    msg( LOG_ERR, func,
  1259. X                "special service %s,%s not supported", service_name, nvp->name ) ;
  1260. X   return( NULL ) ;
  1261. X}
  1262. X
  1263. X
  1264. XPRIVATE status_e spec_service_handler( sp, cp )
  1265. X    struct service *sp ;
  1266. X    connection_s *cp ;
  1267. X{
  1268. X    if ( svc_access_control( sp, cp ) == FAILED ||
  1269. X                                            server_run( sp, cp ) == FAILED )
  1270. X    {
  1271. X        /*
  1272. X         * If we couldn't start a server for the shutdown service, mark
  1273. X         * the connection for shutdown, so that we will do a simple shutdown
  1274. X         * (i.e. we won't try to collect information from the remote end).
  1275. X         */
  1276. X        if ( sp == SHUTDOWN_SERVICE( ps ) )
  1277. X            conn_shutdown( cp ) ;
  1278. X        return( FAILED ) ;
  1279. X    }
  1280. X    return( OK ) ;
  1281. X}
  1282. X
  1283. X
  1284. X
  1285. XPRIVATE struct service *spec_setup( name, socket_type, instances )
  1286. X    char *name ;
  1287. X    int socket_type ;
  1288. X    int instances ;
  1289. X{
  1290. X    builtin_s *bp ;
  1291. X    struct service_config *scp ;
  1292. X
  1293. X    bp = spec_find( name, socket_type ) ;
  1294. X    if ( bp == NULL )
  1295. X        return( NULL ) ;
  1296. X
  1297. X    if ( ( scp = sc_make_special( name, bp, instances ) ) == NULL )
  1298. X        return( NULL ) ;
  1299. X
  1300. X    return( svc_make_special( scp, spec_service_handler ) ) ;
  1301. X}
  1302. X
  1303. X
  1304. X/*
  1305. X * Initialize the special services and the corresponding entries in
  1306. X * the program state structure.
  1307. X */
  1308. Xvoid spec_include()
  1309. X{
  1310. X    int instances ;
  1311. X
  1312. X    instances = logprocs_option ? logprocs_option_arg : DEFAULT_LOGPROCS ;
  1313. X    LOG_SERVICE( ps ) = spec_setup( LOG_SERVICE_NAME, SOCK_STREAM, instances ) ;
  1314. X
  1315. X    instances = shutdownprocs_option ? shutdownprocs_option_arg
  1316. X                                                : DEFAULT_SHUTDOWNPROCS ;
  1317. X    SHUTDOWN_SERVICE( ps ) = spec_setup( SHUTDOWN_SERVICE_NAME,
  1318. X                                                                SOCK_STREAM, instances ) ;
  1319. X}
  1320. X
  1321. X
  1322. XPRIVATE void stream_logging( serp )
  1323. X    struct server *serp ;
  1324. X{
  1325. X    char *func = "stream_logging" ;
  1326. X    idresult_e result ;
  1327. X    idresult_e log_remote_user() ;
  1328. X    char *idresult_explain() ;
  1329. X
  1330. X#ifdef DEBUG_LOGGING
  1331. X    if ( debug.on )
  1332. X    {
  1333. X        msg( LOG_DEBUG, func, "%d is sleeping", getpid() ) ;
  1334. X        sleep( 10 ) ;
  1335. X    }
  1336. X#endif
  1337. X
  1338. X    result = log_remote_user( serp, LOGUSER_FAILURE_TIMEOUT ) ;
  1339. X    if ( result != IDR_OK && result != IDR_NOSERVER )
  1340. X        msg( LOG_ERR, func, "Failed to contact identity server at %s: %s",
  1341. X            conn_addrstr( SERVER_CONNECTION( serp ) ),
  1342. X                idresult_explain( result ) ) ;
  1343. X}
  1344. X
  1345. X
  1346. X
  1347. XPRIVATE void stream_shutdown( serp )
  1348. X    struct server *serp ;
  1349. X{
  1350. X    struct service *sp = SERVER_CONNSERVICE( serp ) ;
  1351. X   char *str ;
  1352. X    char *func = "stream_shutdown" ;
  1353. X
  1354. X    if ( debug.on )
  1355. X        msg( LOG_DEBUG, func, "shutdown for service %s, (fd=%d)",
  1356. X            SVC_ID( sp ), SERVER_FD( serp ) ) ;
  1357. X
  1358. X#ifdef DEBUG_SHUTDOWN
  1359. X   /*
  1360. X    * The reason for the sleep is that single stepping through this
  1361. X    * code is impossible (at least on the Sun IPC I am using).
  1362. X    */
  1363. X   if ( debug.on )
  1364. X   {
  1365. X      msg( LOG_DEBUG, func, "%d is sleeping", getpid() ) ;
  1366. X      sleep( 10 ) ;
  1367. X   }
  1368. X#endif
  1369. X
  1370. X   /*
  1371. X    * Everything must happen within 10 seconds.
  1372. X    * Since there is no alarm handler the process will be terminated if the
  1373. X    * timer runs out.
  1374. X    */
  1375. X   if ( ! debug.on )
  1376. X   {
  1377. X      (void) alarm( 10 ) ;
  1378. X      (void) signal( SIGALRM, SIG_DFL ) ;
  1379. X   }
  1380. X
  1381. X    str = NULL ;                /* must be initialized to NULL */
  1382. X    svc_shutdown( sp, SERVER_CONNECTION( serp ), &str ) ;
  1383. X
  1384. X   (void) alarm( 0 ) ;
  1385. X
  1386. X   if ( str != NULL )
  1387. X      svc_logprint( sp, DATA_ENTRY, "%s", str ) ;
  1388. X}
  1389. X
  1390. X
  1391. END_OF_FILE
  1392. if test 4537 -ne `wc -c <'xinetd/special.c'`; then
  1393.     echo shar: \"'xinetd/special.c'\" unpacked with wrong size!
  1394. fi
  1395. # end of 'xinetd/special.c'
  1396. fi
  1397. echo shar: End of archive 10 \(of 31\).
  1398. cp /dev/null ark10isdone
  1399. MISSING=""
  1400. 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
  1401.     if test ! -f ark${I}isdone ; then
  1402.     MISSING="${MISSING} ${I}"
  1403.     fi
  1404. done
  1405. if test "${MISSING}" = "" ; then
  1406.     echo You have unpacked all 31 archives.
  1407.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1408. else
  1409.     echo You still need to unpack the following archives:
  1410.     echo "        " ${MISSING}
  1411. fi
  1412. ##  End of shell archive.
  1413. exit 0
  1414.