]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/index.c
Import resetting of c_dn/c_cdn after anonymous bind.
[openldap] / servers / slapd / back-ldbm / index.c
index 3d75a091d3166f497ebbc9fa9a58bbff92521014..016be0644108895c329d9001321a243dd5240821 100644 (file)
@@ -1,23 +1,17 @@
 /* index.c - routines for dealing with attribute indexes */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
-#include "back-ldbm.h"
 
-extern char            *first_word();
-extern char            *next_word();
-extern char            *phonetic();
-extern IDList          *idl_fetch();
-extern IDList          *idl_allids();
-extern struct dbcache  *ldbm_cache_open();
+#include <ac/string.h>
+#include <ac/socket.h>
 
-int    index_add_values();
+#include "slap.h"
+#include "back-ldbm.h"
 
-static int     add_value();
-static int     index2prefix();
+static int     add_value(Backend *be, struct dbcache *db, char *type, int indextype, char *val, ID id);
+static int     index2prefix(int indextype);
 
 int
 index_add_entry(
@@ -38,7 +32,7 @@ index_add_entry(
         * with index_add_values() call
         */
 
-       bv.bv_val = strdup( e->e_dn );
+       bv.bv_val = ch_strdup( e->e_dn );
        bv.bv_len = strlen( bv.bv_val );
        (void) dn_normalize_case( bv.bv_val );
        bvals[0] = &bv;
@@ -105,6 +99,8 @@ index_read(
        char            *realval, *tmpval;
        char            buf[BUFSIZ];
 
+       ldbm_datum_init( key );
+
        prefix = index2prefix( indextype );
        Debug( LDAP_DEBUG_TRACE, "=> index_read( \"%s\" \"%c\" \"%s\" )\n",
            type, prefix, val );
@@ -113,7 +109,7 @@ index_read(
        if ( ! (indextype & indexmask) ) {
                idl =  idl_allids( be );
                Debug( LDAP_DEBUG_TRACE,
-                   "<= index_read %d candidates (allids - not indexed)\n",
+                   "<= index_read %lu candidates (allids - not indexed)\n",
                    idl ? idl->b_nids : 0, 0, 0 );
                return( idl );
        }
@@ -129,30 +125,31 @@ index_read(
 
        realval = val;
        tmpval = NULL;
-       if ( prefix != '\0' ) {
-               int     len;
+       if ( prefix != UNKNOWN_PREFIX ) {
+              unsigned int     len = strlen( val );
 
-               if ( (len = strlen( val )) < sizeof(buf) ) {
-                       buf[0] = prefix;
-                       strcpy( &buf[1], val );
+              if ( (len + 2) < sizeof(buf) ) {
                        realval = buf;
                } else {
                        /* value + prefix + null */
                        tmpval = (char *) ch_malloc( len + 2 );
-                       tmpval[0] = prefix;
-                       strcat( &tmpval[1], val );
                        realval = tmpval;
                }
+              realval[0] = prefix;
+              strcpy( &realval[1], val );
        }
 
        key.dptr = realval;
        key.dsize = strlen( realval ) + 1;
 
        idl = idl_fetch( be, db, key );
+      if ( tmpval != NULL ) {
+              free( tmpval );
+      }
 
        ldbm_cache_close( be, db );
 
-       Debug( LDAP_DEBUG_TRACE, "<= index_read %d candidates\n",
+       Debug( LDAP_DEBUG_TRACE, "<= index_read %lu candidates\n",
            idl ? idl->b_nids : 0, 0, 0 );
        return( idl );
 }
@@ -174,26 +171,26 @@ add_value(
        char    *realval, *tmpval, *s;
        char    buf[BUFSIZ];
 
+       ldbm_datum_init( key );
+
        prefix = index2prefix( indextype );
        Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 );
 
        realval = val;
        tmpval = NULL;
        idl = NULL;
-       if ( prefix != '\0' ) {
-               int     len;
+       if ( prefix != UNKNOWN_PREFIX ) {
+              unsigned int     len = strlen( val );
 
-               if ( (len = strlen( val )) < sizeof(buf) ) {
-                       buf[0] = prefix;
-                       strcpy( &buf[1], val );
+              if ( (len + 2) < sizeof(buf) ) {
                        realval = buf;
                } else {
                        /* value + prefix + null */
                        tmpval = (char *) ch_malloc( len + 2 );
-                       tmpval[0] = prefix;
-                       strcat( &tmpval[1], val );
                        realval = tmpval;
                }
+              realval[0] = prefix;
+              strcpy( &realval[1], val );
        }
 
        key.dptr = realval;
@@ -221,7 +218,7 @@ index_add_values(
 )
 {
        char            *val, *p, *code, *w;
-       int             i, j, len;
+       unsigned        i, j, len;
        int             indexmask, syntax;
        char            buf[SUBLEN + 1];
        char            vbuf[BUFSIZ];
@@ -356,7 +353,7 @@ index2prefix( int indextype )
                prefix = SUB_PREFIX;
                break;
        default:
-               prefix = '\0';
+               prefix = UNKNOWN_PREFIX;
                break;
        }