]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
Add support for 64 bit index hashing
[openldap] / servers / slapd / schema_init.c
index 67508fc70db2862e451de0b00adb8dc2618037a2..08ef8437efa9e1843107fd8d6fa582dbcbf6670c 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2011 The OpenLDAP Foundation.
+ * Copyright 1998-2012 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include "lutil.h"
 #include "lutil_hash.h"
+
+#ifdef LUTIL_HASH64_BYTES
+#define HASH_BYTES                             LUTIL_HASH64_BYTES
+#define HASH_LEN       hashlen
+static void (*hashinit)(lutil_HASH_CTX *ctx) = lutil_HASHInit;
+static void (*hashupdate)(lutil_HASH_CTX *ctx,unsigned char const *buf, ber_len_t len) = lutil_HASHUpdate;
+static void (*hashfinal)(unsigned char digest[HASH_BYTES], lutil_HASH_CTX *ctx) = lutil_HASHFinal;
+static int hashlen = LUTIL_HASH_BYTES;
+#define HASH_Init(c)                   hashinit(c)
+#define HASH_Update(c,buf,len) hashupdate(c,buf,len)
+#define HASH_Final(d,c)                        hashfinal(d,c)
+
+/* Toggle between 32 and 64 bit hashing, default to 32 for compatibility
+   -1 to query, returns 1 if 64 bit, 0 if 32.
+   0/1 to set 32/64, returns 0 on success, -1 on failure */
+int slap_hash64( int onoff )
+{
+       if ( onoff < 0 ) {
+               return hashlen == LUTIL_HASH64_BYTES;
+       } else if ( onoff ) {
+               hashinit = lutil_HASH64Init;
+               hashupdate = lutil_HASH64Update;
+               hashfinal = lutil_HASH64Final;
+               hashlen = LUTIL_HASH64_BYTES;
+       } else {
+               hashinit = lutil_HASHInit;
+               hashupdate = lutil_HASHUpdate;
+               hashfinal = lutil_HASHFinal;
+               hashlen = LUTIL_HASH_BYTES;
+       }
+       return 0;
+}
+
+#else
 #define HASH_BYTES                             LUTIL_HASH_BYTES
-#define HASH_CONTEXT                   lutil_HASH_CTX
+#define HASH_LEN                               HASH_BYTES
 #define HASH_Init(c)                   lutil_HASHInit(c)
 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
 #define HASH_Final(d,c)                        lutil_HASHFinal(d,c)
 
+int slap_has64( int onoff )
+{
+       if ( onoff < 0 )
+               return 0;
+       else
+               return onoff ? -1 : 0;
+}
+
+#endif
+#define HASH_CONTEXT                   lutil_HASH_CTX
+
 /* approx matching rules */
 #define directoryStringApproxMatchOID  "1.3.6.1.4.1.4203.666.4.4"
 #define directoryStringApproxMatch             approxMatch
@@ -164,6 +209,7 @@ unsigned int index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
 unsigned int index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
        SLAP_INDEX_INTLEN_DEFAULT );
 
+ldap_pvt_thread_mutex_t        ad_index_mutex;
 ldap_pvt_thread_mutex_t        ad_undef_mutex;
 ldap_pvt_thread_mutex_t        oc_undef_mutex;
 
@@ -646,7 +692,7 @@ int octetStringIndexer(
        unsigned char HASHdigest[HASH_BYTES];
        struct berval digest;
        digest.bv_val = (char *)HASHdigest;
-       digest.bv_len = sizeof(HASHdigest);
+       digest.bv_len = HASH_LEN;
 
        for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
                /* just count them */
@@ -692,7 +738,7 @@ int octetStringFilter(
        struct berval *value = (struct berval *) assertedValue;
        struct berval digest;
        digest.bv_val = (char *)HASHdigest;
-       digest.bv_len = sizeof(HASHdigest);
+       digest.bv_len = HASH_LEN;
 
        slen = syntax->ssyn_oidlen;
        mlen = mr->smr_oidlen;
@@ -855,7 +901,7 @@ octetStringSubstringsIndexer(
        unsigned char HASHdigest[HASH_BYTES];
        struct berval digest;
        digest.bv_val = (char *)HASHdigest;
-       digest.bv_len = sizeof(HASHdigest);
+       digest.bv_len = HASH_LEN;
 
        nkeys = 0;
 
@@ -1020,7 +1066,7 @@ octetStringSubstringsFilter (
        }
 
        digest.bv_val = (char *)HASHdigest;
-       digest.bv_len = sizeof(HASHdigest);
+       digest.bv_len = HASH_LEN;
 
        slen = syntax->ssyn_oidlen;
        mlen = mr->smr_oidlen;
@@ -1852,12 +1898,12 @@ UTF8StringNormalize(
                }
                nvalue.bv_val[nvalue.bv_len] = '\0';
 
-       } else {
+       } else if ( tmp.bv_len )  {
                /* string of all spaces is treated as one space */
                nvalue.bv_val[0] = ' ';
                nvalue.bv_val[1] = '\0';
                nvalue.bv_len = 1;
-       }
+       }       /* should never be entered with 0-length val */
 
        *normalized = nvalue;
        return LDAP_SUCCESS;
@@ -2154,7 +2200,11 @@ approxIndexer(
                        len = strlen( c );
                        if( len < SLAPD_APPROX_WORDLEN ) continue;
                        ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
-                       keycount++;
+                       if( keys[keycount].bv_len ) {
+                               keycount++;
+                       } else {
+                               ch_free( keys[keycount].bv_val );
+                       }
                        i++;
                }
 
@@ -2331,13 +2381,18 @@ postalAddressNormalize(
        }
        lines[l].bv_len = &val->bv_val[c] - lines[l].bv_val;
 
-       normalized->bv_len = l;
+       normalized->bv_len = c = l;
 
-       for ( l = 0; !BER_BVISNULL( &lines[l] ); l++ ) {
+       for ( l = 0; l <= c; l++ ) {
                /* NOTE: we directly normalize each line,
                 * without unescaping the values, since the special
                 * values '\24' ('$') and '\5C' ('\') are not affected
                 * by normalization */
+               if ( !lines[l].bv_len ) {
+                       nlines[l].bv_len = 0;
+                       nlines[l].bv_val = NULL;
+                       continue;
+               }
                rc = UTF8StringNormalize( usage, NULL, xmr, &lines[l], &nlines[l], ctx );
                if ( rc != LDAP_SUCCESS ) {
                        rc = LDAP_INVALID_SYNTAX;
@@ -2350,7 +2405,7 @@ postalAddressNormalize(
        normalized->bv_val = slap_sl_malloc( normalized->bv_len + 1, ctx );
 
        p = normalized->bv_val;
-       for ( l = 0; !BER_BVISNULL( &nlines[l] ); l++ ) {
+       for ( l = 0; l <= c ; l++ ) {
                p = lutil_strbvcopy( p, &nlines[l] );
                *p++ = '$';
        }
@@ -6844,6 +6899,7 @@ schema_destroy( void )
        syn_destroy();
 
        if( schema_init_done ) {
+               ldap_pvt_thread_mutex_destroy( &ad_index_mutex );
                ldap_pvt_thread_mutex_destroy( &ad_undef_mutex );
                ldap_pvt_thread_mutex_destroy( &oc_undef_mutex );
        }