]> git.sur5r.net Git - openldap/blobdiff - servers/ldapd/main.c
Fix memory leak if duplicate attr name in at_insert
[openldap] / servers / ldapd / main.c
index 3f0e3d3580a15f4a2294fb559e39a58fb0cc7858..764f4e9c094e8267595f4baebe4541d97d77dc92 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright (c) 1990-1996 Regents of the University of Michigan.
  * All rights reserved.
@@ -106,12 +107,13 @@ main( int argc, char **argv )
        int                     udps;
 #endif
        int                     myport = LDAP_PORT;
+       int                     no_detach = 0;
        int                     i, pid, socktype;
        char                    *myname;
        fd_set                  readfds;
        struct hostent          *hp;
        struct sockaddr_in      from;
-       int                     len;
+       socklen_t               len;
        int                     dsapargc;
        char                    **dsapargv;
 #ifdef LDAP_PROCTITLE
@@ -150,13 +152,15 @@ main( int argc, char **argv )
                        dsapargc = 3;
                        break;
 
-               case 'd':       /* turn on debugging */
+               case 'd':       /* set debug level and 'do not detach' flag */
+                       no_detach = 1;
 #ifdef LDAP_DEBUG
                        ldap_debug = atoi( optarg );
                        if ( ldap_debug & LDAP_DEBUG_PACKETS )
-                               lber_int_debug = ldap_debug;
+                               ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
 #else
-                       fprintf( stderr, "Not compiled with -DLDAP_DEBUG!\n" );
+                       if ( atoi( optarg ) != 0 )
+                               fputs( "Not compiled with -DLDAP_DEBUG!\n", stderr );
 #endif
                        break;
 
@@ -261,11 +265,7 @@ main( int argc, char **argv )
                setproctitle( "initializing" );
 #endif
 #ifndef VMS
-#  ifdef LDAP_DEBUG
-               lutil_detach( ldap_debug, 1 );
-#  else
-               lutil_detach( 0, 1 );
-#  endif
+               lutil_detach( no_detach, 1 );
 #endif
                (void) SIGNAL( SIGCHLD, wait4child );
                (void) SIGNAL( SIGINT, log_and_exit );
@@ -406,7 +406,7 @@ main( int argc, char **argv )
 
 #ifdef HAVE_TCPD
                if ( !hosts_ctl("ldapd", (hp == NULL) ? "unknown" : hp->h_name,
-                       inet_ntoa( from.sin_addr ), STRING_UNKNOWN ) {
+                       inet_ntoa( from.sin_addr ), STRING_UNKNOWN) ) {
 
                        Debug( LDAP_DEBUG_ARGS, "connection from %s (%s) denied.\n",
                                (hp == NULL) ? "unknown" : hp->h_name,
@@ -515,10 +515,10 @@ do_queries(
                conn_init();
        }
 
-       lber_pvt_sb_init( &sb );
-       lber_pvt_sb_set_desc( &sb, clientsock );
-       lber_pvt_sb_set_io( &sb, (udp) ? &lber_pvt_sb_io_udp :
-                                       &lber_pvt_sb_io_tcp, NULL );
+       ber_pvt_sb_init( &sb );
+       ber_pvt_sb_set_desc( &sb, clientsock );
+       ber_pvt_sb_set_io( &sb, (udp) ? &ber_pvt_sb_io_udp :
+                                       &ber_pvt_sb_io_tcp, NULL );
        timeout.tv_sec = idletime;
        timeout.tv_usec = 0;
        for ( ;; ) {
@@ -547,7 +547,7 @@ do_queries(
                 * already waiting for us on the client sock.
                 */
 
-               if ( ! lber_pvt_sb_data_ready( &sb ) ) {
+               if ( ! ber_pvt_sb_data_ready( &sb ) ) {
                        if ( (rc = select( dtblsize, &readfds, 0, 0,
                            udp ? 0 : &timeout )) < 1 ) {
 #ifdef LDAP_DEBUG
@@ -573,7 +573,7 @@ do_queries(
                        }
                }
 
-               if ( lber_pvt_sb_data_ready( &sb ) ||
+               if ( ber_pvt_sb_data_ready( &sb ) ||
                    FD_ISSET( clientsock, &readfds ) ) {
                        client_request( &sb, conns, udp );
                } else {
@@ -603,18 +603,31 @@ set_socket(
                 exit( 1 );
         }
 
+#ifdef SO_REUSEADDR
         /* set option so clients can't keep us from coming back up */
-       i = 1;
+               i = 1;
         if ( setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (void *) &i, sizeof(i) )
-           < 0 ) {
+                   < 0 )
+               {
                 perror( "setsockopt" );
                 exit( 1 );
         }
+#endif
+#ifdef SO_KEEPALIVE
+        /* enable keep alives */
+               i = 1;
+        if ( setsockopt( s, SOL_SOCKET, SO_KEEPALIVE, (void *) &i, sizeof(i) )
+                   < 0 )
+               {
+                perror( "setsockopt" );
+                exit( 1 );
+        }
+#endif
 
         /* bind to a name */
        (void)memset( (void *)&addr, '\0', sizeof( addr ));
         addr.sin_family = AF_INET;
-        addr.sin_addr.s_addr = INADDR_ANY;
+        addr.sin_addr.s_addr = htonl(INADDR_ANY);
         addr.sin_port = htons( port );
         if ( bind( s, (struct sockaddr *) &addr, sizeof(addr) ) ) {
                 perror( "bind" );