]> git.sur5r.net Git - openldap/commitdiff
-llber hardening
authorKurt Zeilenga <kurt@openldap.org>
Sun, 6 May 2001 22:00:01 +0000 (22:00 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sun, 6 May 2001 22:00:01 +0000 (22:00 +0000)
servers/slapd/config.c
servers/slapd/connection.c
servers/slapd/controls.c
servers/slapd/daemon.c
servers/slapd/entry.c
servers/slapd/proto-slap.h
servers/slapd/slap.h

index 48e995eb67ddae6791f06f6a85c9380dbed4b89a..df982460e87fe774e5edf894a811bd179a9e4a59 100644 (file)
@@ -40,6 +40,8 @@ char          *default_passwd_hash;
 char           *default_search_base = NULL;
 char           *default_search_nbase = NULL;
 
+ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
+
 char   *slapd_pid_file  = NULL;
 char   *slapd_args_file = NULL;
 
@@ -168,6 +170,43 @@ read_config( const char *fname )
 
                        ldap_pvt_thread_set_concurrency( c );
 
+               /* set sockbuf max */
+               } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
+                       long max;
+                       if ( cargc < 2 ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
+                                          "%s: line %d: missing max in \"sockbuf_max_incoming <bytes\" line\n",
+                                          fname, lineno ));
+#else
+                               Debug( LDAP_DEBUG_ANY,
+                                          "%s: line %d: missing max in \"sockbuf_max_incoming <bytes\" line\n",
+                                   fname, lineno, 0 );
+#endif
+
+                               return( 1 );
+                       }
+
+                       max = atol( cargv[1] );
+
+                       if( max < 0 ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
+                                          "%s: line %d: invalid max value (%ld) in "
+                                          "\"sockbuf_max_incoming <bytes>\" line.\n",
+                                          fname, lineno, max ));
+#else
+                               Debug( LDAP_DEBUG_ANY,
+                                       "%s: line %d: invalid max value (%ld) in "
+                                       "\"sockbuf_max_incoming <bytes>\" line.\n",
+                                   fname, lineno, max );
+#endif
+
+                               return( 1 );
+                       }
+
+                       sockbuf_max_incoming = max;
+
                /* default search base */
                } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
                        if ( cargc < 2 ) {
index de77e7051d1f0720e30cec32620c2f0a1b01982f..b282cf69703f5fec566ad1e1dc97d59777d5d03c 100644 (file)
@@ -362,33 +362,39 @@ long connection_init(
 
     assert( c != NULL );
 
-    if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
+       if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
                c->c_authmech = NULL;
-        c->c_dn = NULL;
-        c->c_cdn = NULL;
+               c->c_dn = NULL;
+               c->c_cdn = NULL;
 
                c->c_listener_url = NULL;
                c->c_peer_domain = NULL;
-        c->c_peer_name = NULL;
-        c->c_sock_name = NULL;
+               c->c_peer_name = NULL;
+               c->c_sock_name = NULL;
 
-        c->c_ops = NULL;
-        c->c_pending_ops = NULL;
+               c->c_ops = NULL;
+               c->c_pending_ops = NULL;
 
                c->c_sasl_bind_mech = NULL;
                c->c_sasl_context = NULL;
                c->c_sasl_extra = NULL;
 
-        c->c_sb = ber_sockbuf_alloc( );
+               c->c_sb = ber_sockbuf_alloc( );
+
+               {
+                       ber_len_t max = sockbuf_max_incoming;
+                       ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
+               }
+
                c->c_currentber = NULL;
 
-        /* should check status of thread calls */
-        ldap_pvt_thread_mutex_init( &c->c_mutex );
-        ldap_pvt_thread_mutex_init( &c->c_write_mutex );
-        ldap_pvt_thread_cond_init( &c->c_write_cv );
+               /* should check status of thread calls */
+               ldap_pvt_thread_mutex_init( &c->c_mutex );
+               ldap_pvt_thread_mutex_init( &c->c_write_mutex );
+               ldap_pvt_thread_cond_init( &c->c_write_cv );
 
-        c->c_struct_state = SLAP_C_UNUSED;
-    }
+               c->c_struct_state = SLAP_C_UNUSED;
+       }
 
     ldap_pvt_thread_mutex_lock( &c->c_mutex );
 
@@ -576,9 +582,15 @@ connection_destroy( Connection *c )
                        c->c_connid, sd, 0, 0, 0 );
        }
 
-       ber_sockbuf_free( c->c_sb );
+       ber_sockbuf_free( c->c_sb );
+
        c->c_sb = ber_sockbuf_alloc( );
 
+       {
+               ber_len_t max = sockbuf_max_incoming;
+               ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
+       }
+
     c->c_conn_state = SLAP_C_INVALID;
     c->c_struct_state = SLAP_C_UNUSED;
 }
index e99eeed1e5909301c8c437bcf9ceadcc7be78ef2..426692645c42c490572112a9972286e3a9c8de9b 100644 (file)
@@ -181,7 +181,7 @@ return_results:
 
        if( sendres && rc != LDAP_SUCCESS ) {
                if( rc == SLAPD_DISCONNECT ) {
-                       send_ldap_disconnect( conn, op, rc, errmsg );
+                       send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, errmsg );
                } else {
                        send_ldap_result( conn, op, rc,
                                NULL, errmsg, NULL, NULL );
index 04bb8f8aeeffa717f50b983f970e9a067bf9202e..f357a8c9e5d832dde02eceef94f978329336ab9b 100644 (file)
@@ -543,7 +543,7 @@ static Listener * slap_open_listener(
 
        case AF_INET: {
                char *s;
-#ifdef HAVE_GETADDRINFO                
+#if defined( HAVE_GETADDRINFO ) && defined( INET_NTOP )
                char addr[INET_ADDRSTRLEN];
                inet_ntop( AF_INET, &((struct sockaddr_in *)*sal)->sin_addr,
                           addr, sizeof(addr) );
index b52e518a80266dddfd0e0b868b7050386f7b57e5..ed81984c8be3b00408b3da15daf62a1f77292cfa 100644 (file)
@@ -264,8 +264,14 @@ entry2str(
 void
 entry_free( Entry *e )
 {
-       Attribute       *a, *next;
+       /* free an entry structure */
+       assert( e != NULL );
 
+       /* e_private must be freed by the caller */
+       assert( e->e_private == NULL );
+       e->e_private = NULL;
+
+       /* free DNs */
        if ( e->e_dn != NULL ) {
                free( e->e_dn );
                e->e_dn = NULL;
@@ -274,12 +280,11 @@ entry_free( Entry *e )
                free( e->e_ndn );
                e->e_ndn = NULL;
        }
-       for ( a = e->e_attrs; a != NULL; a = next ) {
-               next = a->a_next;
-               attr_free( a );
-       }
+
+       /* free attributes */
+       attrs_free( e->e_attrs );
        e->e_attrs = NULL;
-       e->e_private = NULL;
+
        free( e );
 }
 
index ecdaaf2dfef8953f9209bef61c6dec302c8c00ef..f8f6d43b9acb096aa626797d450135d37572c2d5 100644 (file)
@@ -760,6 +760,8 @@ LDAP_SLAPD_F (int)  krbv4_ldap_auth();
 /*
  * Other...
  */
+#define SLAP_SB_MAX_INCOMING_DEFAULT (1<<18 - 1)
+LDAP_SLAPD_F (ber_len_t) sockbuf_max_incoming;
 
 LDAP_SLAPD_F (slap_mask_t)     global_restrictops;
 LDAP_SLAPD_F (slap_mask_t)     global_allows;
index bed78c771e5b7b66eea17fcd385939c18389dc0a..89acc1fbdbd49ad9f9903ba76a5a899d0467374d 100644 (file)
@@ -58,6 +58,7 @@ LDAP_BEGIN_DECL
 
 #define MAXREMATCHES 10
 
+#define SLAP_MAX_INCOMING (1<<18 - 1)
 #define SLAP_MAX_WORKER_THREADS                32