]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/result.c
fix config message (ITS#4853)
[openldap] / servers / slapd / result.c
index fbf6a04a5bfe218b9b3a10692e57fc051bf50f73..757076e1e9efcd0c3cd44ce1ba6f4824be2bb5a1 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -36,7 +36,6 @@
 #include <ac/unistd.h>
 
 #include "slap.h"
-#include "lutil.h"
 
 const struct berval slap_dummy_bv = BER_BVNULL;
 
@@ -1342,11 +1341,15 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
        bytes = send_ldap_ber( op->o_conn, ber );
        ber_free_buf( ber );
 
-       ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
-       ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
-       ldap_pvt_mp_add_ulong( slap_counters.sc_refs, 1 );
-       ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
-       ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+       if ( bytes < 0 ) {
+               rc = LDAP_UNAVAILABLE;
+       } else {
+               ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
+               ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
+               ldap_pvt_mp_add_ulong( slap_counters.sc_refs, 1 );
+               ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
+               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+       }
 #ifdef LDAP_CONNECTIONLESS
        }
 #endif
@@ -1421,9 +1424,43 @@ str2result(
                }
 
                if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
-                       if ( c != NULL && lutil_atoi( code, c ) != 0 ) {
-                               goto bailout;
+                       char    *next = NULL;
+                       long    retcode;
+
+                       if ( c == NULL ) {
+                               Debug( LDAP_DEBUG_ANY, "str2result (%s) missing value\n",
+                                   s, 0, 0 );
+                               rc = -1;
+                               continue;
+                       }
+
+                       while ( isspace( (unsigned char) c[ 0 ] ) ) c++;
+                       if ( c[ 0 ] == '\0' ) {
+                               Debug( LDAP_DEBUG_ANY, "str2result (%s) missing or empty value\n",
+                                   s, 0, 0 );
+                               rc = -1;
+                               continue;
+                       }
+
+                       retcode = strtol( c, &next, 10 );
+                       if ( next == NULL || next == c ) {
+                               Debug( LDAP_DEBUG_ANY, "str2result (%s) unable to parse value\n",
+                                   s, 0, 0 );
+                               rc = -1;
+                               continue;
+                       }
+
+                       while ( isspace( (unsigned char) next[ 0 ] ) ) next++;
+                       if ( next[ 0 ] != '\0' ) {
+                               Debug( LDAP_DEBUG_ANY, "str2result (%s) extra cruft after value\n",
+                                   s, 0, 0 );
+                               rc = -1;
+                               continue;
                        }
+
+                       /* FIXME: what if it's larger that max int? */
+                       *code = (int)retcode;
+
                } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
                        if ( c != NULL ) {
                                *matched = c;
@@ -1433,7 +1470,6 @@ str2result(
                                *info = c;
                        }
                } else {
-bailout:;
                        Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
                            s, 0, 0 );
 
@@ -1476,6 +1512,7 @@ int slap_read_controls(
        myop.o_bd = NULL;
        myop.o_res_ber = ber;
        myop.o_callback = NULL;
+       myop.ors_slimit = 1;
 
        rc = slap_send_search_entry( &myop, rs );
        if( rc ) return rc;