home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / xinetd.2.0.6 / access.c next >
Encoding:
C/C++ Source or Header  |  1993-01-22  |  2.9 KB  |  118 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: access.c,v 5.2 1993/01/14 01:50:25 panos Exp $" ;
  8.  
  9. #include <syslog.h>
  10. #include <time.h>
  11.  
  12. #include "addr.h"
  13. #include "connection.h"
  14. #include "service.h"
  15. #include "access.h"
  16. #include "state.h"
  17.  
  18. char *inet_ntoa() ;
  19. time_t time() ;
  20.  
  21. void msg() ;
  22.  
  23.  
  24. /*
  25.  * m is the mask pointer, t is the check type
  26.  */
  27. #define CHECK( mp, t )        ( ( (mp) == NULL ) || M_IS_SET( *mp, t ) )
  28.  
  29. /*
  30.  * Perform the access controls specified by check_mask.
  31.  * If check_mask is NULL, perform all access controls
  32.  */
  33. access_e access_control( sp, cp, check_mask )
  34.     register struct service *sp ;
  35.     register connection_s *cp ;
  36.     register mask_t *check_mask ;
  37. {
  38.     struct service_config *scp = CONF( sp ) ;
  39.     struct service_data *sdp = SDATA( sp ) ;
  40.     status_e remote_address_check() ;
  41.  
  42.     if ( CHECK( check_mask, CF_ADDRESS ) && 
  43.                 conn_address( cp ) != SOCKADDRIN_NULL &&
  44.                 remote_address_check( sp, conn_address( cp ) ) == FAILED )
  45.         return( AC_ADDRESS ) ;
  46.  
  47.     if ( CHECK( check_mask, CF_TIME ) &&
  48.             scp->access_times && ! time_in_range( scp->access_times ) )
  49.         return( AC_TIME ) ;
  50.     
  51.     if ( CHECK( check_mask, CF_SERVICE_LIMIT ) &&
  52.                                 sdp->running_servers >= scp->instances )
  53.         return( AC_SERVICE_LIMIT ) ;
  54.     
  55.     if ( CHECK( check_mask, CF_PROCESS_LIMIT ) && ps.ros.process_limit )
  56.     {
  57.         unsigned processes_to_create = IS_INTERCEPTED( CONF( sp ) ) ? 2 : 1 ;
  58.  
  59.         if ( pset_count( ps.rws.servers ) + processes_to_create >
  60.                                                                 ps.ros.process_limit )
  61.         return( AC_PROCESS_LIMIT ) ;
  62.     }
  63.     return( AC_OK ) ;
  64. }
  65.  
  66.  
  67. PRIVATE status_e remote_address_check( sp, sinp )
  68.     struct service *sp ;
  69.     struct sockaddr_in *sinp ;
  70. {
  71.     unsigned long na_match, of_match ;
  72.     register bool_int na_matched, of_matched ;
  73.     struct in_addr *addr ;
  74.     register struct service_data *sdp = SDATA( sp ) ;
  75.  
  76.     addr = &sinp->sin_addr ;
  77.  
  78.     if ( sdp->no_access != NULL )
  79.         na_matched = addrlist_match( sdp->no_access, addr, &na_match ) ;
  80.     else
  81.         na_matched = FALSE ;
  82.  
  83.     if ( sdp->only_from != NULL )
  84.         of_matched = addrlist_match( sdp->only_from, addr, &of_match ) ;
  85.     else
  86.         of_matched = FALSE ;
  87.  
  88.     /*
  89.      * Check if the specified address is in both lists
  90.      */
  91.     if ( na_matched && of_matched )
  92.     {
  93.         /*
  94.          * The greater match wins.
  95.          * If the matches are equal, this is an error in the service entry
  96.          * and we cannot allow a server to start.
  97.          * We do not disable the service entry (not our job).
  98.          */
  99.         if ( na_match == of_match )
  100.             msg( LOG_ERR, "remote_address_check",
  101. "Service=%s: only_from list and no_access list match equally the address %s",
  102.                 CONF( sp )->id, inet_ntoa( sinp->sin_addr ) ) ;
  103.         return( ( of_match > na_match ) ? OK : FAILED ) ;
  104.     }
  105.  
  106.     if ( sdp->no_access != NULL && na_matched )
  107.         return( FAILED ) ;
  108.     if ( sdp->only_from != NULL && ! of_matched )
  109.         return( FAILED ) ;
  110.  
  111.     /*
  112.      * If no lists were specified, the default is to allow starting a server
  113.      */
  114.     return( OK ) ;
  115. }
  116.  
  117.  
  118.