X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fschema_init.c;h=d1e4068a23fcfdec981b9872af0ec0ace50c88ac;hb=fbc6a7e8ac780fd421e057c34caa9d4ecb166807;hp=d28d25a61c6605b9cc26d507e3516f03c9bd5092;hpb=e0a70010d9cce210abe95f8fafa4ba6fe3ea3718;p=openldap diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index d28d25a61c..d1e4068a23 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -28,6 +28,8 @@ #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len) #define HASH_Final(d,c) lutil_HASHFinal(d,c) +#define SLAP_NVALUES 1 + #ifdef SLAP_NVALUES /* TO BE DELETED */ #define SLAP_MR_DN_FOLD (0) @@ -42,6 +44,7 @@ #define xintegerNormalize NULL #define xnumericStringNormalize NULL #define xnameUIDNormalize NULL +#define xdnNormalize NULL /* (new) normalization routines */ #define caseExactIA5Normalize IA5StringNormalize @@ -49,22 +52,24 @@ #define caseExactNormalize UTF8StringNormalize #define caseIgnoreNormalize UTF8StringNormalize -#define distinguishedNameNormalize NULL -#define integerNormalize NULL #define integerFirstComponentNormalize NULL -#define numericStringNormalize NULL #define objectIdentifierNormalize NULL #define objectIdentifierFirstComponentNormalize NULL -#define generalizedTimeNormalize NULL -#define uniqueMemberNormalize NULL -#define bitStringNormalize NULL -#define telephoneNumberNormalize NULL +#define distinguishedNameNormalize dnNormalize #define distinguishedNameMatch dnMatch #define distinguishedNameIndexer octetStringIndexer #define distinguishedNameFilter octetStringFilter -#define uniqueMemberMatch dnMatch +#define integerOrderingMatch integerMatch +#define integerFirstComponentMatch NULL +#define integerIndexer octetStringIndexer +#define integerFilter octetStringFilter + +#define generalizedTimeMatch caseIgnoreIA5Match +#define generalizedTimeOrderingMatch caseIgnoreIA5Match + +#define uniqueMemberMatch dnMatch /* FIXME! */ #define objectIdentifierMatch octetStringMatch #define objectIdentifierIndexer octetStringIndexer @@ -76,39 +81,31 @@ #define bitStringIndexer octetStringIndexer #define bitStringFilter octetStringFilter -#define integerMatch NULL -#define integerOrderingMatch NULL -#define integerIndexer NULL -#define integerFilter NULL - -#define generalizedTimeMatch NULL -#define generalizedTimeOrderingMatch NULL - #define caseIgnoreMatch octetStringMatch #define caseIgnoreOrderingMatch octetStringOrderingMatch #define caseIgnoreIndexer octetStringIndexer #define caseIgnoreFilter octetStringFilter -#define caseIgnoreSubstringsMatch NULL -#define caseIgnoreSubstringsIndexer NULL -#define caseIgnoreSubstringsFilter NULL +#define caseIgnoreSubstringsMatch octetStringSubstringsMatch +#define caseIgnoreSubstringsIndexer octetStringSubstringsIndexer +#define caseIgnoreSubstringsFilter octetStringSubstringsFilter #define caseExactMatch octetStringMatch #define caseExactOrderingMatch octetStringOrderingMatch #define caseExactIndexer octetStringIndexer #define caseExactFilter octetStringFilter -#define caseExactSubstringsMatch NULL -#define caseExactSubstringsIndexer NULL -#define caseExactSubstringsFilter NULL +#define caseExactSubstringsMatch octetStringSubstringsMatch +#define caseExactSubstringsIndexer octetStringSubstringsIndexer +#define caseExactSubstringsFilter octetStringSubstringsFilter #define caseExactIA5Match octetStringMatch #define caseExactIA5Indexer octetStringIndexer #define caseExactIA5Filter octetStringFilter -#define caseExactIA5SubstringsMatch NULL -#define caseExactIA5SubstringsIndexer NULL -#define caseExactIA5SubstringsFilter NULL +#define caseExactIA5SubstringsMatch octetStringSubstringsMatch +#define caseExactIA5SubstringsIndexer octetStringSubstringsIndexer +#define caseExactIA5SubstringsFilter octetStringSubstringsFilter #define caseIgnoreIA5Match octetStringMatch #define caseIgnoreIA5Indexer octetStringIndexer @@ -134,6 +131,8 @@ #define telephoneNumberSubstringsIndexer caseExactIA5SubstringsIndexer #define telephoneNumberSubstringsFilter caseExactIA5SubstringsFilter +#define booleanIndexer octetStringIndexer +#define booleanFilter octetStringFilter #endif /* validatation routines */ @@ -156,6 +155,8 @@ #ifndef SLAP_NVALUES +#define xdnNormalize dnNormalize + /* (new) normalization routines */ #define caseExactNormalize NULL #define caseExactIA5Normalize NULL @@ -169,7 +170,6 @@ #define objectIdentifierFirstComponentNormalize NULL #define generalizedTimeNormalize NULL #define uniqueMemberNormalize NULL -#define bitStringNormalize NULL #define telephoneNumberNormalize NULL @@ -188,7 +188,8 @@ #define objectIdentifierIndexer caseIgnoreIA5Indexer #define objectIdentifierFilter caseIgnoreIA5Filter -#define OpenLDAPaciMatch NULL +#define octetStringSubstringsMatch NULL +#define OpenLDAPaciMatch NULL #define generalizedTimeMatch caseIgnoreIA5Match #define generalizedTimeOrderingMatch caseIgnoreIA5Match @@ -222,6 +223,9 @@ #define telephoneNumberFilter caseIgnoreIA5Filter #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter + +#define booleanIndexer octetStringIndexer +#define booleanFilter octetStringFilter #endif @@ -483,13 +487,21 @@ nameUIDValidate( return rc; } -#ifndef SLAP_NVALUES - +#ifdef SLAP_NVALUES +static int +uniqueMemberNormalize( + slap_mask_t usage, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized ) +#else static int xnameUIDNormalize( Syntax *syntax, struct berval *val, struct berval *normalized ) +#endif { struct berval out; int rc; @@ -545,7 +557,6 @@ xnameUIDNormalize( return LDAP_SUCCESS; } -#endif /* * Handling boolean syntax and matching is quite rigid. * A more flexible approach would be to allow a variety @@ -743,8 +754,8 @@ UTF8StringNormalize( } flags = SLAP_MR_ASSOCIATED(mr, slap_schema.si_mr_caseExactMatch ) - ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; - flags |= ( use & SLAP_MR_EQUALITY_APPROX == SLAP_MR_EQUALITY_APPROX ) + ? LDAP_UTF8_NOCASEFOLD : LDAP_UTF8_CASEFOLD; + flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX ) ? LDAP_UTF8_APPROX : 0; val = UTF8bvnormalize( val, &tmp, flags ); @@ -783,6 +794,7 @@ UTF8StringNormalize( nvalue.bv_len = 1; } + *normalized = nvalue; return LDAP_SUCCESS; } #else @@ -1585,10 +1597,16 @@ static int caseExactIgnoreFilter( *keysp = keys; return LDAP_SUCCESS; } +#endif /* Substrings Index generation function */ -static int caseExactIgnoreSubstringsIndexer( - slap_mask_t use, +static int +#ifdef SLAP_NVALUES +octetStringSubstringsIndexer +#else +caseExactIgnoreSubstringsIndexer +#endif + ( slap_mask_t use, slap_mask_t flags, Syntax *syntax, MatchingRule *mr, @@ -1596,11 +1614,13 @@ static int caseExactIgnoreSubstringsIndexer( BerVarray values, BerVarray *keysp ) { - unsigned casefold, wasspace; ber_len_t i, j, nkeys; size_t slen, mlen; BerVarray keys; +#ifndef SLAP_NVALUES BerVarray tvalues, nvalues; + unsigned casefold, wasspace; +#endif HASH_CONTEXT HASHcontext; unsigned char HASHdigest[HASH_BYTES]; @@ -1608,8 +1628,7 @@ static int caseExactIgnoreSubstringsIndexer( digest.bv_val = HASHdigest; digest.bv_len = sizeof(HASHdigest); - nkeys=0; - +#ifndef SLAP_NVALUES for( i=0; values[i].bv_val != NULL; i++ ) { /* empty - just count them */ } @@ -1655,6 +1674,9 @@ static int caseExactIgnoreSubstringsIndexer( tvalues[i].bv_val = NULL; nvalues[i].bv_val = NULL; values = nvalues; +#endif + + nkeys=0; for( i=0; values[i].bv_val != NULL; i++ ) { /* count number of indices to generate */ @@ -1690,8 +1712,10 @@ static int caseExactIgnoreSubstringsIndexer( if( nkeys == 0 ) { /* no keys to generate */ *keysp = NULL; +#ifndef SLAP_NVALUES ber_bvarray_free( tvalues ); ch_free( nvalues ); +#endif return LDAP_SUCCESS; } @@ -1792,14 +1816,21 @@ static int caseExactIgnoreSubstringsIndexer( *keysp = NULL; } +#ifndef SLAP_NVALUES ber_bvarray_free( tvalues ); ch_free( nvalues ); +#endif return LDAP_SUCCESS; } -static int caseExactIgnoreSubstringsFilter( - slap_mask_t use, +static int +#ifdef SLAP_NVALUES +octetStringSubstringsFilter +#else +caseExactIgnoreSubstringsFilter +#endif + ( slap_mask_t use, slap_mask_t flags, Syntax *syntax, MatchingRule *mr, @@ -1818,6 +1849,7 @@ static int caseExactIgnoreSubstringsFilter( struct berval *value; struct berval digest; +#ifndef SLAP_NVALUES casefold = ( mr != slap_schema.si_mr_caseExactSubstringsMatch ) ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; @@ -1826,6 +1858,9 @@ static int caseExactIgnoreSubstringsFilter( *keysp = NULL; return LDAP_SUCCESS; } +#else + sa = (SubstringsAssertion *) assertedValue; +#endif if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL && sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN ) @@ -1851,10 +1886,12 @@ static int caseExactIgnoreSubstringsFilter( } if( nkeys == 0 ) { +#ifndef SLAP_NVALUES if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val ); if ( sa->sa_any ) ber_bvarray_free( sa->sa_any ); if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val ); ch_free( sa ); +#endif *keysp = NULL; return LDAP_SUCCESS; } @@ -1966,13 +2003,17 @@ static int caseExactIgnoreSubstringsFilter( ch_free( keys ); *keysp = NULL; } + +#ifndef SLAP_NVALUES if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val ); if ( sa->sa_any ) ber_bvarray_free( sa->sa_any ); if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val ); ch_free( sa ); +#endif return LDAP_SUCCESS; } +#ifndef SLAP_NVALUES static int caseIgnoreMatch( @@ -1988,13 +2029,23 @@ caseIgnoreMatch( LDAP_UTF8_CASEFOLD ); return LDAP_SUCCESS; } +#endif /* Remove all spaces and '-' characters */ static int +#ifdef SLAP_NVALUES +telephoneNumberNormalize( + slap_mask_t usage, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized ) +#else xtelephoneNumberNormalize( Syntax *syntax, struct berval *val, struct berval *normalized ) +#endif { char *p, *q; @@ -2019,7 +2070,6 @@ xtelephoneNumberNormalize( return LDAP_SUCCESS; } -#endif static int oidValidate( @@ -2060,8 +2110,6 @@ oidValidate( return LDAP_INVALID_SYNTAX; } -#ifndef SLAP_NVALUES - static int integerMatch( int *matchp, @@ -2080,18 +2128,20 @@ integerMatch( /* Skip leading space/sign/zeroes, and get the sign of the *value number */ v = value->bv_val; vlen = value->bv_len; + +#ifndef SLAP_NVALUES if( mr == slap_schema.si_mr_integerFirstComponentMatch ) { char *tmp = memchr( v, '$', vlen ); - if( tmp ) - vlen = tmp - v; - while( vlen && ASCII_SPACE( v[vlen-1] )) - vlen--; + if( tmp ) vlen = tmp - v; + while( vlen && ASCII_SPACE( v[vlen-1] )) vlen--; } - for( ; vlen && ( *v < '1' || '9' < *v ); v++, vlen-- ) /* ANSI 2.2.1 */ - if( *v == '-' ) - vsign = -1; - if( vlen == 0 ) - vsign = 0; +#endif + + for( ; vlen && ( *v < '1' || '9' < *v ); v++, vlen-- ) { /* ANSI 2.2.1 */ + if( *v == '-' ) vsign = -1; + } + + if( vlen == 0 ) vsign = 0; /* Do the same with the *assertedValue number */ asserted = (struct berval *) assertedValue; @@ -2116,7 +2166,6 @@ integerMatch( return LDAP_SUCCESS; } -#endif static int integerValidate( Syntax *syntax, @@ -2128,6 +2177,7 @@ integerValidate( if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) { if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX; + } else if( !ASCII_DIGIT(val->bv_val[0]) ) { return LDAP_INVALID_SYNTAX; } @@ -2139,12 +2189,20 @@ integerValidate( return LDAP_SUCCESS; } -#ifndef SLAP_NVALUES static int +#ifdef SLAP_NVALUES +integerNormalize( + slap_mask_t use, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized ) +#else xintegerNormalize( Syntax *syntax, struct berval *val, struct berval *normalized ) +#endif { char *p; int negative=0; @@ -2180,13 +2238,11 @@ xintegerNormalize( if( len == 0 ) { normalized->bv_val = ch_strdup("0"); normalized->bv_len = 1; - } - else { + + } else { normalized->bv_len = len+negative; normalized->bv_val = ch_malloc( normalized->bv_len + 1 ); - if( negative ) { - normalized->bv_val[0] = '-'; - } + if( negative ) normalized->bv_val[0] = '-'; AC_MEMCPY( normalized->bv_val + negative, p, len ); normalized->bv_val[len+negative] = '\0'; } @@ -2194,6 +2250,8 @@ xintegerNormalize( return LDAP_SUCCESS; } +#ifndef SLAP_NVALUES + /* Index generation function */ static int integerIndexer( slap_mask_t use, @@ -2385,8 +2443,8 @@ IA5StringValidate( return LDAP_SUCCESS; } -#ifdef SLAP_NVALUES static int +#ifdef SLAP_NVALUES IA5StringNormalize( slap_mask_t use, Syntax *syntax, @@ -2394,7 +2452,6 @@ IA5StringNormalize( struct berval *val, struct berval *normalized ) #else -static int xIA5StringNormalize( Syntax *syntax, struct berval *val, @@ -2490,7 +2547,12 @@ caseExactIA5Match( } static int -caseExactIA5SubstringsMatch( +caseExactIA5SubstringsMatch +#else +static int +octetStringSubstringsMatch +#endif +( int *matchp, slap_mask_t flags, Syntax *syntax, @@ -2523,7 +2585,7 @@ caseExactIA5SubstringsMatch( goto done; } - match = strncmp( sub->sa_initial.bv_val, left.bv_val, + match = memcmp( sub->sa_initial.bv_val, left.bv_val, sub->sa_initial.bv_len ); if( match != 0 ) { @@ -2541,7 +2603,7 @@ caseExactIA5SubstringsMatch( goto done; } - match = strncmp( sub->sa_final.bv_val, + match = memcmp( sub->sa_final.bv_val, &left.bv_val[left.bv_len - sub->sa_final.bv_len], sub->sa_final.bv_len ); @@ -2569,7 +2631,7 @@ retry: continue; } - p = strchr( left.bv_val, *sub->sa_any[i].bv_val ); + p = memchr( left.bv_val, *sub->sa_any[i].bv_val, left.bv_len ); if( p == NULL ) { match = 1; @@ -2592,7 +2654,7 @@ retry: goto done; } - match = strncmp( left.bv_val, + match = memcmp( left.bv_val, sub->sa_any[i].bv_val, sub->sa_any[i].bv_len ); @@ -2613,6 +2675,8 @@ done: return LDAP_SUCCESS; } +#ifndef SLAP_NVALUES + /* Index generation function */ static int caseExactIA5Indexer( slap_mask_t use, @@ -3656,13 +3720,20 @@ numericStringValidate( return LDAP_SUCCESS; } -#ifndef SLAP_NVALUES - static int +#ifdef SLAP_NVALUES +numericStringNormalize( + slap_mask_t usage, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized ) +#else xnumericStringNormalize( Syntax *syntax, struct berval *val, struct berval *normalized ) +#endif { /* removal all spaces */ char *p, *q; @@ -3701,6 +3772,7 @@ xnumericStringNormalize( return LDAP_SUCCESS; } +#ifndef SLAP_NVALUES static int objectIdentifierFirstComponentMatch( int *matchp, @@ -4429,13 +4501,20 @@ generalizedTimeValidate( return check_time_syntax(in, 0, parts); } -#ifndef SLAP_NVALUES - static int +#ifdef SLAP_NVALUES +generalizedTimeNormalize( + slap_mask_t usage, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized ) +#else xgeneralizedTimeNormalize( Syntax *syntax, struct berval *val, struct berval *normalized ) +#endif { int parts[9], rc; @@ -4457,7 +4536,6 @@ xgeneralizedTimeNormalize( return LDAP_SUCCESS; } -#endif static int nisNetgroupTripleValidate( Syntax *syntax, @@ -4581,7 +4659,7 @@ static slap_syntax_defs_rec syntax_defs[] = { {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )", 0, countryStringValidate, xIA5StringNormalize, NULL}, {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )", - 0, dnValidate, dnNormalize2, dnPretty2}, + 0, dnValidate, xdnNormalize, dnPretty2}, {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )", 0, NULL, NULL, NULL}, {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )", @@ -4738,7 +4816,6 @@ char *objectIdentifierFirstComponentMatchSyntaxes[] = { * Other matching rules in X.520 that we do not use (yet): * * 2.5.13.9 numericStringOrderingMatch - * 2.5.13.19 octetStringSubstringsMatch * 2.5.13.25 uTCTimeMatch * 2.5.13.26 uTCTimeOrderingMatch * 2.5.13.31 directoryStringFirstComponentMatch @@ -4870,7 +4947,10 @@ static slap_mrule_defs_rec mrule_defs[] = { {"( 2.5.13.13 NAME 'booleanMatch' " "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )", SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL, - NULL, NULL, booleanMatch, NULL, NULL, NULL}, + NULL, + NULL, booleanMatch, + booleanIndexer, booleanFilter, + NULL}, {"( 2.5.13.14 NAME 'integerMatch' " "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", @@ -4891,7 +4971,7 @@ static slap_mrule_defs_rec mrule_defs[] = { "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL, NULL, - bitStringNormalize, bitStringMatch, + NULL, bitStringMatch, bitStringIndexer, bitStringFilter, NULL}, @@ -4909,6 +4989,13 @@ static slap_mrule_defs_rec mrule_defs[] = { octetStringOrderingMatch, NULL, NULL, NULL}, + {"( 2.5.13.19 NAME 'octetStringSubstringsMatch' " + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", + SLAP_MR_SUBSTR, NULL, + NULL, NULL, + octetStringSubstringsMatch, NULL, NULL, + NULL}, + {"( 2.5.13.20 NAME 'telephoneNumberMatch' " "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD, NULL,