]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
Added bdb_attribute and bdb_group ACL support routines
[openldap] / servers / slapd / schema_init.c
index e88a9fe368898c6bce17e9ed29afc5c623347250..f55e6d93183d237d8a8a929aa1e5c5ff9c6a5b9b 100644 (file)
@@ -255,7 +255,7 @@ dnNormalize(
 
        if ( val->bv_len != 0 ) {
                char *dn;
-               out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
+               out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
 
                dn = dn_validate( out->bv_val );
 
@@ -331,13 +331,10 @@ nameUIDValidate(
                                break;
                        }
                }
-               if( dn->bv_val[i] != '\'' ) {
-                       return LDAP_INVALID_SYNTAX;
-               }
-               if( dn->bv_val[i-1] != 'B' ) {
-                       return LDAP_INVALID_SYNTAX;
-               }
-               if( dn->bv_val[i-2] != '#' ) {
+               if( dn->bv_val[i] != '\'' ||
+                   dn->bv_val[i-1] != 'B' ||
+                   dn->bv_val[i-2] != '#' ) {
+                       ber_bvfree( dn );
                        return LDAP_INVALID_SYNTAX;
                }
 
@@ -620,7 +617,7 @@ UTF8SubstringsassertionNormalize(
        }
 
        if( sa->sa_initial != NULL ) {
-               nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, casefold ) );
+               nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
                if( nsa->sa_initial == NULL ) {
                        goto err;
                }
@@ -632,7 +629,7 @@ UTF8SubstringsassertionNormalize(
                }
                nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
                for( i=0; sa->sa_any[i] != NULL; i++ ) {
-                       nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, casefold ) );
+                       nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
                        if( nsa->sa_any[i] == NULL ) {
                                goto err;
                        }
@@ -641,7 +638,7 @@ UTF8SubstringsassertionNormalize(
        }
 
        if( sa->sa_final != NULL ) {
-               nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, casefold ) );
+               nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
                if( nsa->sa_final == NULL ) {
                        goto err;
                }
@@ -650,9 +647,9 @@ UTF8SubstringsassertionNormalize(
        return nsa;
 
 err:
-       ch_free( nsa->sa_final );
+       ber_bvfree( nsa->sa_final );
        ber_bvecfree( nsa->sa_any );
-       ch_free( nsa->sa_initial );
+       ber_bvfree( nsa->sa_initial );
        ch_free( nsa );
        return NULL;
 }
@@ -700,23 +697,23 @@ approxMatch(
        struct berval *value,
        void *assertedValue )
 {
-       char *val, *assertv, **values, **words, *c;
+       char *val, *nval, *assertv, **values, **words, *c;
        int i, count, len, nextchunk=0, nextavail=0;
        size_t avlen;
 
        /* Yes, this is necessary */
-       val = UTF8normalize( value->bv_val, UTF8_NOCASEFOLD );
-       if( val == NULL ) {
+       nval = UTF8normalize( value, UTF8_NOCASEFOLD );
+       if( nval == NULL ) {
                *matchp = 1;
                return LDAP_SUCCESS;
        }
-       strip8bitChars( val );
+       strip8bitChars( nval );
 
        /* Yes, this is necessary */
-       assertv = UTF8normalize( ((struct berval *)assertedValue)->bv_val,
+       assertv = UTF8normalize( ((struct berval *)assertedValue),
                                 UTF8_NOCASEFOLD );
        if( assertv == NULL ) {
-               free( val );
+               ch_free( nval );
                *matchp = 1;
                return LDAP_SUCCESS;
        }
@@ -724,7 +721,7 @@ approxMatch(
        avlen = strlen( assertv );
 
        /* Isolate how many words there are */
-       for( c=val,count=1; *c; c++ ) {
+       for( c=nval,count=1; *c; c++ ) {
                c = strpbrk( c, SLAPD_APPROX_DELIMITER );
                if ( c == NULL ) break;
                *c = '\0';
@@ -734,7 +731,7 @@ approxMatch(
        /* Get a phonetic copy of each word */
        words = (char **)ch_malloc( count * sizeof(char *) );
        values = (char **)ch_malloc( count * sizeof(char *) );
-       for( c=val,i=0;  i<count;  i++,c+=strlen(c)+1 ) {
+       for( c=nval,i=0;  i<count;  i++,c+=strlen(c)+1 ) {
                words[i] = c;
                values[i] = phonetic(c);
        }
@@ -770,6 +767,7 @@ approxMatch(
                                        break;
                                }
                        }
+                       ch_free( val );
                }
 
                /* This chunk in the asserted value was NOT within the *value. */
@@ -797,7 +795,7 @@ approxMatch(
        }
        ch_free( values );
        ch_free( words );
-       free( val );
+       ch_free( nval );
 
        return LDAP_SUCCESS;
 }
@@ -818,7 +816,7 @@ approxIndexer(
 
        for( j=0; values[j] != NULL; j++ ) {
                /* Yes, this is necessary */
-               val = UTF8normalize( values[j]->bv_val, UTF8_NOCASEFOLD );
+               val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
                strip8bitChars( val );
 
                /* Isolate how many words there are. There will be a key for each */
@@ -871,7 +869,7 @@ approxFilter(
        struct berval **keys;
 
        /* Yes, this is necessary */
-       val = UTF8normalize( ((struct berval *)assertValue)->bv_val,
+       val = UTF8normalize( ((struct berval *)assertValue),
                             UTF8_NOCASEFOLD );
        if( val == NULL ) {
                keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
@@ -926,14 +924,14 @@ approxMatch(
        char *s, *t;
 
        /* Yes, this is necessary */
-       s = UTF8normalize( value->bv_val, UTF8_NOCASEFOLD );
+       s = UTF8normalize( value, UTF8_NOCASEFOLD );
        if( s == NULL ) {
                *matchp = 1;
                return LDAP_SUCCESS;
        }
 
        /* Yes, this is necessary */
-       t = UTF8normalize( ((struct berval *)assertedValue)->bv_val,
+       t = UTF8normalize( ((struct berval *)assertedValue),
                           UTF8_NOCASEFOLD );
        if( t == NULL ) {
                free( s );
@@ -981,7 +979,7 @@ approxIndexer(
        /* Copy each value and run it through phonetic() */
        for( i=0; values[i] != NULL; i++ ) {
                /* Yes, this is necessary */
-               s = UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD );
+               s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
 
                /* strip 8-bit chars and run through phonetic() */
                keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
@@ -1010,7 +1008,7 @@ approxFilter(
        keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
 
        /* Yes, this is necessary */
-       s = UTF8normalize( ((struct berval *)assertValue)->bv_val,
+       s = UTF8normalize( ((struct berval *)assertValue),
                             UTF8_NOCASEFOLD );
        if( s == NULL ) {
                keys[0] = NULL;
@@ -1061,7 +1059,7 @@ caseExactIgnoreSubstringsMatch(
        casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
                ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
 
-       nav = UTF8normalize( value->bv_val, casefold );
+       nav = UTF8normalize( value, casefold );
        if( nav == NULL ) {
                match = 1;
                goto done;
@@ -1152,6 +1150,11 @@ retry:
 
                        if( idx >= left.bv_len ) {
                                /* this shouldn't happen */
+                               free( nav );
+                               ch_free( sub->sa_final );
+                               ber_bvecfree( sub->sa_any );
+                               ch_free( sub->sa_initial );
+                               ch_free( sub );
                                return LDAP_OTHER;
                        }
 
@@ -1183,9 +1186,9 @@ retry:
 done:
        free( nav );
        if( sub != NULL ) {
-               ch_free( sub->sa_final );
+               ber_bvfree( sub->sa_final );
                ber_bvecfree( sub->sa_any );
-               ch_free( sub->sa_initial );
+               ber_bvfree( sub->sa_initial );
                ch_free( sub );
        }
        *matchp = match;
@@ -1229,7 +1232,7 @@ int caseExactIgnoreIndexer(
 
        for( i=0; values[i] != NULL; i++ ) {
                struct berval *value;
-               value = ber_bvstr( UTF8normalize( values[i]->bv_val,
+               value = ber_bvstr( UTF8normalize( values[i],
                        casefold ) );
 
                HASH_Init( &HASHcontext );
@@ -1281,7 +1284,7 @@ int caseExactIgnoreFilter(
        casefold = strcmp( mr->smr_oid, caseExactMatchOID )
                ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
 
-       value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val,
+       value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
                casefold ) );
        /* This usually happens if filter contains bad UTF8 */
        if( value == NULL ) {
@@ -1350,7 +1353,7 @@ int caseExactIgnoreSubstringsIndexer(
 
        nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
        for( i=0; values[i] != NULL; i++ ) {
-               nvalues[i] = ber_bvstr( UTF8normalize( values[i]->bv_val,
+               nvalues[i] = ber_bvstr( UTF8normalize( values[i],
                        casefold ) );
        }
        nvalues[i] = NULL;
@@ -1390,6 +1393,7 @@ int caseExactIgnoreSubstringsIndexer(
        if( nkeys == 0 ) {
                /* no keys to generate */
                *keysp = NULL;
+               ber_bvecfree( nvalues );
                return LDAP_SUCCESS;
        }
 
@@ -1550,6 +1554,10 @@ int caseExactIgnoreSubstringsFilter(
        }
 
        if( nkeys == 0 ) {
+               ber_bvfree( sa->sa_final );
+               ber_bvecfree( sa->sa_any );
+               ber_bvfree( sa->sa_initial );
+               ch_free( sa );
                *keysp = NULL;
                return LDAP_SUCCESS;
        }
@@ -1661,9 +1669,9 @@ int caseExactIgnoreSubstringsFilter(
                ch_free( keys );
                *keysp = NULL;
        }
-       ch_free( sa->sa_final );
+       ber_bvfree( sa->sa_final );
        ber_bvecfree( sa->sa_any );
-       ch_free( sa->sa_initial );
+       ber_bvfree( sa->sa_initial );
        ch_free( sa );
 
        return LDAP_SUCCESS;
@@ -3481,7 +3489,8 @@ asn1_integer2str(ASN1_INTEGER *a)
                                 * Way too large, we need to leave
                                 * room for sign if negative
                                 */
-                         return NULL;
+                               free(copy);
+                               return NULL;
                        }
                        *--p = digit[carry];
                        if (copy[base] == 0)
@@ -4717,3 +4726,12 @@ schema_init( void )
        schema_init_done = 1;
        return LDAP_SUCCESS;
 }
+
+void
+schema_destroy( void )
+{
+       oc_destroy();
+       at_destroy();
+       mr_destroy();
+       syn_destroy();
+}