home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1992 by Panagiotis Tsirigotis
- * All rights reserved. The file named COPYRIGHT specifies the terms
- * and conditions for redistribution.
- */
-
- static char RCSid[] = "$Id: sconf.c,v 5.1 1992/11/01 00:01:21 panos Exp $" ;
-
- #include "fsma.h"
- #include "sio.h"
-
- #include "defs.h"
- #include "attr.h"
- #include "sconf.h"
- #include "state.h"
- #include "addr.h"
-
- #define FREE( x ) if ( x ) \
- { \
- free( (char *) x ) ; \
- x = NULL ; \
- }
-
- extern struct name_value success_log_options[] ;
- extern struct name_value failure_log_options[] ;
- extern struct name_value service_types[] ;
- extern struct name_value service_flags[] ;
- extern struct name_value socket_types[] ;
- extern struct name_value syslog_facilities[] ;
- extern struct name_value syslog_levels[] ;
-
- void tabprint() ;
-
-
- /*
- * Print info about service sp to file descriptor fd
- */
- void sconf_dump( scp, fd, tab_level, is_defaults )
- register struct service_config *scp ;
- register int fd ;
- int tab_level ;
- bool_int is_defaults ;
- {
- register struct name_value *nvp ;
- register unsigned u ;
- register char **pp ;
- void dump_intervals() ;
- void dump_log_data() ;
- struct name_value *nv_find_name() ;
-
- if ( is_defaults )
- tabprint( fd, tab_level, "Service defaults\n" ) ;
- else
- tabprint( fd, tab_level, "Service configuration data\n" ) ;
-
- if ( ! is_defaults )
- {
- tabprint( fd, tab_level+1, "id = %s\n", scp->id ) ;
-
- tabprint( fd, tab_level+1, "flags =" ) ;
- for ( nvp = &service_flags[ 0 ] ; nvp->name != NULL ; nvp++ )
- if ( M_IS_SET( scp->flags, nvp->value ) )
- Sprint( fd, " %s", nvp->name ) ;
- Sputchar( fd, '\n' ) ;
-
- tabprint( fd, tab_level+1, "type =" ) ;
- for ( nvp = &service_types[ 0 ] ; nvp->name != NULL ; nvp++ )
- if ( M_IS_SET( scp->type, nvp->value ) )
- Sprint( fd, " %s", nvp->name ) ;
- Sputchar( fd, '\n' ) ;
-
- tabprint( fd, tab_level+1, "socket_type = %s\n",
- ( nvp = nv_find_name( socket_types, scp->socket_type ) )
- ? nvp->name : "BAD_SOCKET_TYPE" ) ;
-
- if ( SPECIFIED( scp, A_PORT ) )
- tabprint( fd, tab_level+1, "port = %d\n", scp->port ) ;
-
- tabprint( fd, tab_level+1, "Protocol (name,number) = (%s,%d)\n",
- scp->protocol.name, scp->protocol.value ) ;
- }
-
- if ( SPECIFIED( scp, A_INSTANCES ) )
- if ( scp->instances == UNLIMITED )
- tabprint( fd, tab_level+1, "Instances = UNLIMITED\n" ) ;
- else
- tabprint( fd, tab_level+1, "Instances = %d\n", scp->instances ) ;
-
- if ( ! is_defaults )
- {
- if ( ! IS_INTERNAL( scp ) )
- {
- tabprint( fd, tab_level+1, "Server = %s\n", scp->server ) ;
- tabprint( fd, tab_level+1, "Server argv =" ) ;
- for ( pp = scp->server_argv ; *pp ; pp++ )
- Sprint( fd, " %s", *pp ) ;
- Sputchar( fd, '\n' ) ;
- }
-
- if ( IS_RPC( scp ) )
- {
- struct rpc_data *rdp = &scp->rd ;
-
- tabprint( fd, tab_level+1, "RPC data\n" ) ;
- tabprint( fd, tab_level+2,
- "program number = %ld\n", rdp->program_number ) ;
- tabprint( fd, tab_level+2, "rpc_version = " ) ;
- if ( rdp->min_version == rdp->max_version )
- Sprint( fd, "%ld\n", rdp->min_version ) ;
- else
- Sprint( fd, "%ld-%ld\n", rdp->min_version, rdp->max_version ) ;
- }
-
- if ( SPECIFIED( scp, A_ACCESS_TIMES ) )
- {
- tabprint( fd, tab_level+1, "Access times =" ) ;
- dump_intervals( scp->access_times, fd ) ;
- Sputchar ( fd, '\n' ) ;
- }
- }
-
- if ( SPECIFIED( scp, A_ONLY_FROM ) )
- {
- tabprint( fd, tab_level+1, "Only from: " ) ;
- addrlist_dump( scp->only_from, fd ) ;
- Sputchar( fd, '\n' ) ;
- }
-
- if ( SPECIFIED( scp, A_NO_ACCESS ) )
- {
- tabprint( fd, tab_level+1, "No access: " ) ;
- addrlist_dump( scp->no_access, fd ) ;
- Sputchar( fd, '\n' ) ;
- }
-
- dump_log_data( fd, scp, tab_level+1 ) ;
-
- if ( SPECIFIED( scp, A_PASSENV ) )
- {
- tabprint( fd, tab_level+1, "Passenv =" ) ;
- for ( u = 0 ; u < pset_count( scp->passenv ) ; u++ )
- Sprint( fd, " %s", (char *) pset_pointer( scp->passenv, u ) ) ;
- Sputchar ( fd, '\n' ) ;
- }
-
- if ( ! is_defaults )
- if ( SPECIFIED( scp, A_ENV ) )
- {
- tabprint( fd, tab_level+1, "Environment additions:\n" ) ;
- for ( u = 0 ; u < pset_count( scp->env ) ; u++ )
- tabprint( fd, tab_level+2,
- "%s\n", (char *) pset_pointer( scp->env, u ) ) ;
- }
-
- if ( ENV( scp )->env_type == CUSTOM_ENV )
- {
- tabprint( fd, tab_level+1, "Environment strings:\n" ) ;
- for ( pp = env_getvars( ENV( scp )->env ) ; *pp ; pp++ )
- tabprint( fd, tab_level+2, "%s\n", *pp ) ;
- }
- }
-
-
- PRIVATE void dump_log_data( fd, scp, tab_level )
- int fd ;
- register struct service_config *scp ;
- int tab_level ;
- {
- register struct log *lp = LOG( scp ) ;
- register struct filelog *flp ;
- register struct name_value *nvp, *nvp2 ;
- int i ;
-
- switch ( lp->log_type )
- {
- case L_NONE:
- tabprint( fd, tab_level, "No logging\n" ) ;
- return ;
-
- case L_COMMON_FILE:
- tabprint( fd, tab_level, "Logging to common log file\n" ) ;
- break ;
-
- case L_FILE:
- flp = FILELOG( lp ) ;
- tabprint( fd, tab_level, "Logging to file: %s", flp->filename ) ;
-
- if ( FILELOG_SIZE_CONTROL( flp ) )
- Sprint( fd, " (soft=%d hard=%d)\n",
- flp->soft_limit, flp->hard_limit ) ;
- else
- Sprint( fd, " (no limits)\n" ) ;
- break ;
-
- case L_SYSLOG:
- tabprint( fd, tab_level,
- "Logging to syslog. Facility = %s, level = %s\n",
- ( nvp = nv_find_name( syslog_facilities, SYSLOG( lp )->facility ) )
- ? nvp->name : "BAD FACILITY",
- ( nvp2 = nv_find_name( syslog_levels, SYSLOG( lp )->level ) )
- ? nvp2->name : "BAD LEVEL" ) ;
- break ;
- }
-
- tabprint( fd, tab_level, "Log_on_success flags =" ) ;
- for ( i = 0 ; success_log_options[ i ].name != NULL ; i++ )
- if ( M_IS_SET( scp->log_on_success, success_log_options[ i ].value ) )
- Sprint( fd, " %s", success_log_options[ i ].name ) ;
- Sputchar( fd, '\n' ) ;
-
- tabprint( fd, tab_level, "Log_on_failure flags =" ) ;
- for ( i = 0 ; failure_log_options[ i ].name != NULL ; i++ )
- if ( M_IS_SET( scp->log_on_failure, failure_log_options[ i ].value ) )
- Sprint( fd, " %s", failure_log_options[ i ].name ) ;
- Sputchar( fd, '\n' ) ;
- }
-
-
-
- /*
- * Free all malloc'ed memory for the specified service
- */
- void sconf_free( scp )
- register struct service_config *scp ;
- {
- void free_intervals() ;
- void release_pset() ;
-
- FREE( scp->name ) ;
- FREE( scp->id ) ;
- FREE( scp->protocol.name ) ;
- FREE( scp->server ) ;
- if ( scp->server_argv )
- {
- register char **pp ;
-
- /*
- * argv[ 0 ] is a special case because it may not have been allocated yet
- */
- if ( scp->server_argv[ 0 ] != NULL)
- free( scp->server_argv[ 0 ] ) ;
- for ( pp = &scp->server_argv[ 1 ] ; *pp != NULL ; pp++ )
- free( *pp ) ;
- free( (char *) scp->server_argv ) ;
- }
- FREE( FILELOG( LOG( scp ) )->filename ) ;
-
- if ( scp->access_times != NULL )
- {
- free_intervals( scp->access_times ) ;
- pset_destroy( scp->access_times ) ;
- }
-
- if ( scp->only_from != NULL )
- {
- addrlist_free( scp->only_from ) ;
- pset_destroy( scp->only_from ) ;
- }
-
- if ( scp->no_access != NULL )
- {
- addrlist_free( scp->no_access ) ;
- pset_destroy( scp->no_access ) ;
- }
-
- if ( scp->env != NULL )
- release_pset( scp->env, (fsma_h) NULL ) ;
- if ( scp->passenv != NULL )
- release_pset( scp->passenv, (fsma_h) NULL ) ;
- if ( scp->environment.env_type == CUSTOM_ENV && ENV( scp )->env != ENV_NULL )
- env_destroy( ENV( scp )->env ) ;
- }
-
-
- PRIVATE void release_pset( pset, allocator )
- pset_h pset ;
- fsma_h allocator ;
- {
- void free_pset() ;
-
- free_pset( pset, allocator ) ;
- pset_destroy( pset ) ;
- }
-
-