]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/daemon.c
Changed search attrs to struct berval **.
[openldap] / servers / slapd / daemon.c
index 9f2b9079684570c9f7b6724aebd88c3e408a75fb..911db57cd54f68b91af3add7284a032b9244bfbe 100644 (file)
@@ -17,6 +17,7 @@
 #include <ac/unistd.h>
 
 #include "ldap_pvt.h"
+#include "ldap_pvt_thread.h"
 #include "lutil.h"
 #include "slap.h"
 
@@ -64,12 +65,6 @@ static int waking;
 do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0)
 #endif
 
-#ifdef HAVE_NT_SERVICE_MANAGER
-/* in nt_main.c */
-extern ldap_pvt_thread_cond_t                  started_event;
-extern int       is_NT_Service;
-#endif
-
 #ifndef HAVE_WINSOCK
 static
 #endif
@@ -374,7 +369,7 @@ static int slap_get_listener_addresses(
                hints.ai_family = AF_UNSPEC;
                snprintf(serv, sizeof serv, "%d", port);
 
-               if (err = getaddrinfo(host, serv, &hints, &res)) {
+               if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
                                   "slap_get_listener_addresses: getaddrinfo failed: %s\n",
@@ -390,12 +385,13 @@ static int slap_get_listener_addresses(
                for (n=2; (sai = sai->ai_next) != NULL; n++) {
                        /* EMPTY */ ;
                }
-               *sal = ch_malloc(n * sizeof(void *));
+               *sal = ch_calloc(n, sizeof(void *));
                if (*sal == NULL) {
                        return -1;
                }
 
                sap = *sal;
+               *sap = NULL;
 
                for ( sai=res; sai; sai=sai->ai_next ) {
                        if( sai->ai_addr == NULL ) {
@@ -436,13 +432,14 @@ static int slap_get_listener_addresses(
                                *sap = NULL;
                                break;
                        }
+
                        if (*sap != NULL) {
                                (*sap)->sa_family = sai->ai_family;
                                sap++;
+                               *sap = NULL;
                        }
                }
 
-               *sap = NULL;
                freeaddrinfo(res);
 #else
                struct in_addr in;
@@ -500,7 +497,7 @@ static Listener * slap_open_listener(
        Listener *li;
        LDAPURLDesc *lud;
        unsigned short port;
-       int err, addrlen;
+       int err, addrlen = 0;
        struct sockaddr **sal, **psal;
        int socktype = SOCK_STREAM;     /* default to COTS */
 
@@ -736,11 +733,10 @@ static Listener * slap_open_listener(
                inet_ntop( AF_INET, &((struct sockaddr_in *)*sal)->sin_addr,
                           addr, sizeof(addr) );
                s = addr;
-               port = ((struct sockaddr_in *)*sal) ->sin_port;
 #else
-               s = inet_ntoa( l.sl_addr.sin_addr );
-               port = l.sl_addr.sin_port;
+               s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
 #endif
+               port = ((struct sockaddr_in *)*sal) ->sin_port;
                l.sl_name = ch_malloc( sizeof("IP=255.255.255.255:65535") );
                sprintf( l.sl_name, "IP=%s:%d",
                         s != NULL ? s : "unknown" , port );
@@ -938,9 +934,12 @@ slapd_daemon_task(
 )
 {
        int l;
-       time_t  last_idle_check = slap_get_time();
+       time_t  last_idle_check = 0;
        time( &starttime );
 
+       if ( global_idletimeout > 0 ) {
+               last_idle_check = slap_get_time();
+       }
        for ( l = 0; slap_listeners[l] != NULL; l++ ) {
                if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
                        continue;
@@ -991,7 +990,7 @@ slapd_daemon_task(
                int emfile = 0;
 
 #define SLAPD_IDLE_CHECK_LIMIT 4
-               time_t  now = slap_get_time();
+               time_t  now;
 
 
                fd_set                  readfds;
@@ -1004,11 +1003,15 @@ slapd_daemon_task(
                struct timeval          zero;
                struct timeval          *tvp;
 
-               if( emfile || ( global_idletimeout > 0 && difftime(
-                       last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT,
-                       now ) < 0 ))
-               {
-                       connections_timeout_idle(now);
+               if( emfile ) {
+                       now = slap_get_time();
+                       connections_timeout_idle( now );
+               }
+               else if ( global_idletimeout > 0 ) {
+                       now = slap_get_time();
+                       if ( difftime( last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) {
+                               connections_timeout_idle( now );
+                       }
                }
 
                FD_ZERO( &writefds );
@@ -1153,7 +1156,7 @@ slapd_daemon_task(
                        slap_ssf_t ssf = 0;
                        char *authid = NULL;
 
-                       char    *dnsname;
+                       char    *dnsname = NULL;
                        char    *peeraddr;
 #ifdef LDAP_PF_LOCAL
                        char    peername[MAXPATHLEN + sizeof("PATH=")];
@@ -1671,9 +1674,15 @@ slapd_daemon_task(
                        }
 #endif /* LDAP_PF_LOCAL */
                        slapd_close( slap_listeners[l]->sl_sd );
-                       break;
                }
+               if ( slap_listeners[l]->sl_url )
+                       free ( slap_listeners[l]->sl_url );
+               if ( slap_listeners[l]->sl_name )
+                       free ( slap_listeners[l]->sl_name );
+               free ( slap_listeners[l] );
        }
+       free ( slap_listeners );
+       slap_listeners = NULL;
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,