Disable services from inetd.conf if a service with the same id exists.
authorPierre Habouzit <madcoder@debian.org>
Wed, 28 Nov 2007 09:13:08 +0000 (10:13 +0100)
committerPierre Habouzit <madcoder@debian.org>
Wed, 28 Nov 2007 09:50:48 +0000 (10:50 +0100)
  This way, if a service is enabled in /etc/xinetd* _and_ in
/etc/inetd.conf, the one (even if disabled) from /etc/xinetd* takes
precedence.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
xinetd/inet.c

index 1cb2ba2..8caab45 100644 (file)
@@ -23,6 +23,8 @@
 #include "parsesup.h"
 #include "nvlists.h"
 
+static psi_h iter ;
+
 static int get_next_inet_entry( int fd, pset_h sconfs, 
                           struct service_config *defaults);
 
@@ -32,12 +34,15 @@ void parse_inet_conf_file( int fd, struct configuration *confp )
    struct service_config *default_config = CNF_DEFAULTS( confp );
    
    line_count = 0;
+   iter = psi_create (sconfs);
 
    for( ;; )
    {   
       if (get_next_inet_entry(fd, sconfs, default_config) == -2)
          break;
    }
+
+   psi_destroy(iter);
 }
 
 static int get_next_inet_entry( int fd, pset_h sconfs, 
@@ -46,7 +51,7 @@ static int get_next_inet_entry( int fd, pset_h sconfs,
    char *p;
    str_h strp;
    char *line = next_line(fd);
-   struct service_config *scp;
+   struct service_config *scp, *tmp;
    unsigned u, i;
    const char *func = "get_next_inet_entry";
    char *name = NULL, *rpcvers = NULL, *rpcproto = NULL;
@@ -405,7 +410,16 @@ static int get_next_inet_entry( int fd, pset_h sconfs,
    SC_SPECIFY( scp, A_SOCKET_TYPE );
    SC_SPECIFY( scp, A_WAIT );
 
-   if( ! pset_add(sconfs, scp) )
+   for ( tmp = SCP( psi_start( iter ) ) ; tmp ; tmp = SCP( psi_next(iter)) ){
+      if (EQ(SC_ID(scp), SC_ID(tmp))) {
+         parsemsg(LOG_DEBUG, func, "removing duplicate service %s", SC_NAME(scp));
+         sc_free(scp);
+         scp = NULL;
+         break;
+      }
+   }
+
+   if( scp && ! pset_add(sconfs, scp) )
    {
       out_of_memory( func );
       pset_destroy(args);
@@ -414,7 +428,9 @@ static int get_next_inet_entry( int fd, pset_h sconfs,
    }
 
    pset_destroy(args);
-   parsemsg( LOG_DEBUG, func, "added service %s", SC_NAME(scp));
+   if (scp) {
+      parsemsg( LOG_DEBUG, func, "added service %s", SC_NAME(scp));
+   }
    return 0;
 }