X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fschema_init.c;h=e0a0600542be8973823c6bc0019f161ea7dde35e;hb=08fe5e7026a6ea7ab301f6ab9bd383b85f1e2149;hp=90f2fb7647b3bd8477367838d0cf4c0777eb867f;hpb=e7e8ec90b61c67b8dae11e0a5f6642187e78e57c;p=openldap diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 90f2fb7647..e0a0600542 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2006 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -17,7 +17,9 @@ #include "portable.h" #include +#ifdef HAVE_LIMITS_H #include +#endif #include #include @@ -48,8 +50,6 @@ #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len) #define HASH_Final(d,c) lutil_HASHFinal(d,c) -#define OpenLDAPaciMatch NULL - /* approx matching rules */ #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4" #define directoryStringApproxMatch approxMatch @@ -67,11 +67,19 @@ #define csnIndexer generalizedTimeIndexer #define csnFilter generalizedTimeFilter +#ifdef SLAP_AUTHZ_SYNTAX +/* FIXME: temporary */ +#define authzMatch octetStringMatch +#endif /* SLAP_AUTHZ_SYNTAX */ + unsigned int index_substr_if_minlen = SLAP_INDEX_SUBSTR_IF_MINLEN_DEFAULT; unsigned int index_substr_if_maxlen = SLAP_INDEX_SUBSTR_IF_MAXLEN_DEFAULT; unsigned int index_substr_any_len = SLAP_INDEX_SUBSTR_ANY_LEN_DEFAULT; unsigned int index_substr_any_step = SLAP_INDEX_SUBSTR_ANY_STEP_DEFAULT; +ldap_pvt_thread_mutex_t ad_undef_mutex; +ldap_pvt_thread_mutex_t oc_undef_mutex; + static int inValidate( Syntax *syntax, @@ -119,7 +127,7 @@ static int certificateValidate( Syntax *syntax, struct berval *in ) #define certificateValidate sequenceValidate #endif -static int +int octetStringMatch( int *matchp, slap_mask_t flags, @@ -161,16 +169,13 @@ octetStringOrderingMatch( return LDAP_SUCCESS; } -void -hashDigestify( +static void +hashPreset( HASH_CONTEXT *HASHcontext, - unsigned char *HASHdigest, struct berval *prefix, char pre, Syntax *syntax, - MatchingRule *mr, - unsigned char *value, - int value_len) + MatchingRule *mr) { HASH_Init(HASHcontext); if(prefix && prefix->bv_len > 0) { @@ -180,11 +185,21 @@ hashDigestify( if(pre) HASH_Update(HASHcontext, (unsigned char*)&pre, sizeof(pre)); HASH_Update(HASHcontext, (unsigned char*)syntax->ssyn_oid, syntax->ssyn_oidlen); HASH_Update(HASHcontext, (unsigned char*)mr->smr_oid, mr->smr_oidlen); - HASH_Update(HASHcontext, value, value_len); - HASH_Final(HASHdigest, HASHcontext); return; } +static void +hashIter( + HASH_CONTEXT *HASHcontext, + unsigned char *HASHdigest, + unsigned char *value, + int len) +{ + HASH_CONTEXT ctx = *HASHcontext; + HASH_Update( &ctx, value, len ); + HASH_Final( HASHdigest, &ctx ); +} + /* Index generation function */ int octetStringIndexer( slap_mask_t use, @@ -217,9 +232,10 @@ int octetStringIndexer( slen = syntax->ssyn_oidlen; mlen = mr->smr_oidlen; + hashPreset( &HASHcontext, prefix, 0, syntax, mr); for( i=0; !BER_BVISNULL( &values[i] ); i++ ) { - hashDigestify( &HASHcontext, HASHdigest, prefix, 0, - syntax, mr, (unsigned char *)values[i].bv_val, values[i].bv_len ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)values[i].bv_val, values[i].bv_len ); ber_dupbv_x( &keys[i], &digest, ctx ); } @@ -255,8 +271,9 @@ int octetStringFilter( keys = slap_sl_malloc( sizeof( struct berval ) * 2, ctx ); - hashDigestify( &HASHcontext, HASHdigest, prefix, 0, - syntax, mr, (unsigned char *)value->bv_val, value->bv_len ); + hashPreset( &HASHcontext, prefix, 0, syntax, mr ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)value->bv_val, value->bv_len ); ber_dupbv_x( keys, &digest, ctx ); BER_BVZERO( &keys[1] ); @@ -402,11 +419,11 @@ octetStringSubstringsIndexer( BerVarray *keysp, void *ctx ) { - ber_len_t i, j, len, nkeys; + ber_len_t i, nkeys; size_t slen, mlen; BerVarray keys; - HASH_CONTEXT HASHcontext; + HASH_CONTEXT HCany, HCini, HCfin; unsigned char HASHdigest[HASH_BYTES]; struct berval digest; digest.bv_val = (char *)HASHdigest; @@ -452,6 +469,13 @@ octetStringSubstringsIndexer( slen = syntax->ssyn_oidlen; mlen = mr->smr_oidlen; + if ( flags & SLAP_INDEX_SUBSTR_ANY ) + hashPreset( &HCany, prefix, SLAP_INDEX_SUBSTR_PREFIX, syntax, mr ); + if( flags & SLAP_INDEX_SUBSTR_INITIAL ) + hashPreset( &HCini, prefix, SLAP_INDEX_SUBSTR_INITIAL_PREFIX, syntax, mr ); + if( flags & SLAP_INDEX_SUBSTR_FINAL ) + hashPreset( &HCfin, prefix, SLAP_INDEX_SUBSTR_FINAL_PREFIX, syntax, mr ); + nkeys = 0; for ( i = 0; !BER_BVISNULL( &values[i] ); i++ ) { ber_len_t j,max; @@ -459,12 +483,12 @@ octetStringSubstringsIndexer( if( ( flags & SLAP_INDEX_SUBSTR_ANY ) && ( values[i].bv_len >= index_substr_any_len ) ) { - char pre = SLAP_INDEX_SUBSTR_PREFIX; max = values[i].bv_len - (index_substr_any_len - 1); for( j=0; jbv_len ? index_substr_if_maxlen : value->bv_len; - hashDigestify( &HASHcontext, HASHdigest, prefix, pre, - syntax, mr, (unsigned char *)value->bv_val, klen ); + hashPreset( &HASHcontext, prefix, pre, syntax, mr ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)value->bv_val, klen ); ber_dupbv_x( &keys[nkeys++], &digest, ctx ); /* If initial is too long and we have subany indexed, use it @@ -599,10 +621,11 @@ octetStringSubstringsFilter ( { ber_len_t j; pre = SLAP_INDEX_SUBSTR_PREFIX; + hashPreset( &HASHcontext, prefix, pre, syntax, mr); for ( j=index_substr_if_maxlen-1; j <= value->bv_len - index_substr_any_len; j+=index_substr_any_step ) { - hashDigestify( &HASHcontext, HASHdigest, prefix, pre, - syntax, mr, (unsigned char *)&value->bv_val[j], index_substr_any_len ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)&value->bv_val[j], index_substr_any_len ); ber_dupbv_x( &keys[nkeys++], &digest, ctx ); } } @@ -620,12 +643,13 @@ octetStringSubstringsFilter ( value = &sa->sa_any[i]; + hashPreset( &HASHcontext, prefix, pre, syntax, mr); for(j=0; j <= value->bv_len - index_substr_any_len; j += index_substr_any_step ) { - hashDigestify( &HASHcontext, HASHdigest, prefix, pre, - syntax, mr, (unsigned char *)&value->bv_val[j], klen ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)&value->bv_val[j], klen ); ber_dupbv_x( &keys[nkeys++], &digest, ctx ); } } @@ -641,8 +665,9 @@ octetStringSubstringsFilter ( klen = index_substr_if_maxlen < value->bv_len ? index_substr_if_maxlen : value->bv_len; - hashDigestify( &HASHcontext, HASHdigest, prefix, pre, - syntax, mr, (unsigned char *)&value->bv_val[value->bv_len-klen], klen ); + hashPreset( &HASHcontext, prefix, pre, syntax, mr ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)&value->bv_val[value->bv_len-klen], klen ); ber_dupbv_x( &keys[nkeys++], &digest, ctx ); /* If final is too long and we have subany indexed, use it @@ -652,10 +677,11 @@ octetStringSubstringsFilter ( { ber_len_t j; pre = SLAP_INDEX_SUBSTR_PREFIX; + hashPreset( &HASHcontext, prefix, pre, syntax, mr); for ( j=0; j <= value->bv_len - index_substr_if_maxlen; j+=index_substr_any_step ) { - hashDigestify( &HASHcontext, HASHdigest, prefix, pre, - syntax, mr, (unsigned char *)&value->bv_val[j], index_substr_any_len ); + hashIter( &HASHcontext, HASHdigest, + (unsigned char *)&value->bv_val[j], index_substr_any_len ); ber_dupbv_x( &keys[nkeys++], &digest, ctx ); } } @@ -890,8 +916,8 @@ nameUIDPretty( struct berval *out, void *ctx ) { - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> nameUIDPretty: <%s>\n", val->bv_val, 0, 0 ); @@ -1058,7 +1084,7 @@ uniqueMemberMatch( struct berval *asserted = (struct berval *) assertedValue; struct berval assertedDN = *asserted; struct berval assertedUID = BER_BVNULL; - struct berval valueDN = BER_BVNULL; + struct berval valueDN = *value; struct berval valueUID = BER_BVNULL; int approx = ((flags & SLAP_MR_EQUALITY_APPROX) == SLAP_MR_EQUALITY_APPROX); @@ -1079,7 +1105,6 @@ uniqueMemberMatch( } if ( !BER_BVISEMPTY( value ) ) { - valueDN = *value; valueUID.bv_val = strrchr( valueDN.bv_val, '#' ); if ( !BER_BVISNULL( &valueUID ) ) { @@ -1854,7 +1879,7 @@ telephoneNumberNormalize( return LDAP_SUCCESS; } -static int +int numericoidValidate( Syntax *syntax, struct berval *in ) @@ -2163,6 +2188,56 @@ UUIDValidate( } static int +UUIDPretty( + Syntax *syntax, + struct berval *in, + struct berval *out, + void *ctx ) +{ + int i; + int rc=LDAP_INVALID_SYNTAX; + + assert( in != NULL ); + assert( out != NULL ); + + if( in->bv_len != 36 ) return LDAP_INVALID_SYNTAX; + + out->bv_len = 36; + out->bv_val = slap_sl_malloc( out->bv_len + 1, ctx ); + + for( i=0; i<36; i++ ) { + switch(i) { + case 8: + case 13: + case 18: + case 23: + if( in->bv_val[i] != '-' ) { + goto handle_error; + } + out->bv_val[i] = '-'; + break; + + default: + if( !ASCII_HEX( in->bv_val[i]) ) { + goto handle_error; + } + out->bv_val[i] = TOLOWER( in->bv_val[i] ); + } + } + + rc = LDAP_SUCCESS; + out->bv_val[ out->bv_len ] = '\0'; + + if( 0 ) { +handle_error: + slap_sl_free( out->bv_val, ctx ); + out->bv_val = NULL; + } + + return rc; +} + +int UUIDNormalize( slap_mask_t usage, Syntax *syntax, @@ -2319,7 +2394,7 @@ integerBitAndMatch( return LDAP_CONSTRAINT_VIOLATION; } - *matchp = (lValue & lAssertedValue) ? 0 : 1; + *matchp = ((lValue & lAssertedValue) == lAssertedValue) ? 0 : 1; return LDAP_SUCCESS; } @@ -2350,7 +2425,7 @@ integerBitOrMatch( return LDAP_CONSTRAINT_VIOLATION; } - *matchp = (lValue | lAssertedValue) ? 0 : -1; + *matchp = ((lValue & lAssertedValue) != 0) ? 0 : -1; return LDAP_SUCCESS; } @@ -2360,12 +2435,11 @@ serialNumberAndIssuerValidate( struct berval *in ) { int rc; - int state; ber_len_t n; struct berval sn, i; if( in->bv_len < 3 ) return LDAP_INVALID_SYNTAX; - i.bv_val = strchr( in->bv_val, '$' ); + i.bv_val = ber_bvchr( in, '$' ); if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX; sn.bv_val = in->bv_val; @@ -2394,19 +2468,18 @@ serialNumberAndIssuerPretty( void *ctx ) { int rc; - int state; ber_len_t n; struct berval sn, i, newi; - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> serialNumberAndIssuerPretty: <%s>\n", val->bv_val, 0, 0 ); if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX; - i.bv_val = strchr( val->bv_val, '$' ); + i.bv_val = ber_bvchr( val, '$' ); if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX; sn.bv_val = val->bv_val; @@ -2434,13 +2507,14 @@ serialNumberAndIssuerPretty( out->bv_len = sn.bv_len + newi.bv_len + 1; out->bv_val = slap_sl_realloc( newi.bv_val, out->bv_len + 1, ctx ); - if( BER_BVISNULL( out ) ) { + if( out->bv_val == NULL ) { + out->bv_len = 0; slap_sl_free( newi.bv_val, ctx ); return LDAP_OTHER; } /* push issuer over */ - AC_MEMCPY( &out->bv_val[sn.bv_len+1], newi.bv_val, newi.bv_len ); + AC_MEMCPY( &out->bv_val[sn.bv_len+1], out->bv_val, newi.bv_len ); /* insert sn and "$" */ AC_MEMCPY( out->bv_val, sn.bv_val, sn.bv_len ); out->bv_val[sn.bv_len] = '$'; @@ -2469,19 +2543,18 @@ serialNumberAndIssuerNormalize( void *ctx ) { int rc; - int state; ber_len_t n; struct berval sn, i, newi; - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> serialNumberAndIssuerNormalize: <%s>\n", val->bv_val, 0, 0 ); if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX; - i.bv_val = strchr( val->bv_val, '$' ); + i.bv_val = ber_bvchr( val, '$' ); if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX; sn.bv_val = val->bv_val; @@ -2511,13 +2584,14 @@ serialNumberAndIssuerNormalize( out->bv_len = sn.bv_len + newi.bv_len + 1; out->bv_val = slap_sl_realloc( newi.bv_val, out->bv_len + 1, ctx ); - if( BER_BVISNULL( out ) ) { + if( out->bv_val == NULL ) { + out->bv_len = 0; slap_sl_free( newi.bv_val, ctx ); return LDAP_OTHER; } /* push issuer over */ - AC_MEMCPY( &out->bv_val[sn.bv_len+1], newi.bv_val, newi.bv_len ); + AC_MEMCPY( &out->bv_val[sn.bv_len+1], out->bv_val, newi.bv_len ); /* insert sn and "$" */ AC_MEMCPY( out->bv_val, sn.bv_val, sn.bv_len ); out->bv_val[sn.bv_len] = '$'; @@ -2898,7 +2972,6 @@ int generalizedTimeIndexer( void *ctx ) { int i, j; - size_t slen, mlen; BerVarray keys; char tmp[5]; BerValue bvtmp; /* 40 bit index */ @@ -3418,22 +3491,14 @@ static slap_syntax_defs_rec syntax_defs[] = { serialNumberAndIssuerValidate, serialNumberAndIssuerPretty}, -#ifdef SLAPD_ACI_ENABLED - /* OpenLDAP Experimental Syntaxes */ - {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )", - SLAP_SYNTAX_HIDE, - UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */, - NULL}, -#endif - #ifdef SLAPD_AUTHPASSWD /* needs updating */ {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )", SLAP_SYNTAX_HIDE, NULL, NULL}, #endif - {"( 1.3.6.1.4.1.4203.666.2.6 DESC 'UUID' )", - SLAP_SYNTAX_HIDE, UUIDValidate, NULL}, + {"( 1.3.6.1.1.16.1 DESC 'UUID' )", + 0, UUIDValidate, UUIDPretty}, {"( 1.3.6.1.4.1.4203.666.11.2.1 DESC 'CSN' )", SLAP_SYNTAX_HIDE, csnValidate, NULL}, @@ -3441,6 +3506,13 @@ static slap_syntax_defs_rec syntax_defs[] = { /* OpenLDAP Void Syntax */ {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" , SLAP_SYNTAX_HIDE, inValidate, NULL}, + +#ifdef SLAP_AUTHZ_SYNTAX + /* FIXME: OID is unused, but not registered yet */ + {"( 1.3.6.1.4.1.4203.666.2.7 DESC 'OpenLDAP authz' )", + SLAP_SYNTAX_HIDE, authzValidate, authzPretty}, +#endif /* SLAP_AUTHZ_SYNTAX */ + {NULL, 0, NULL, NULL} }; @@ -3835,15 +3907,6 @@ static slap_mrule_defs_rec mrule_defs[] = { NULL}, #endif -#ifdef SLAPD_ACI_ENABLED - {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' " - "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )", - SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL, - NULL, NULL, OpenLDAPaciMatch, - NULL, NULL, - NULL}, -#endif - {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' " "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", SLAP_MR_EXT, NULL, @@ -3858,16 +3921,16 @@ static slap_mrule_defs_rec mrule_defs[] = { NULL, NULL, "integerMatch" }, - {"( 1.3.6.1.4.1.4203.666.4.6 NAME 'UUIDMatch' " - "SYNTAX 1.3.6.1.4.1.4203.666.2.6 )", - SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL, + {"( 1.3.6.1.1.16.2 NAME 'UUIDMatch' " + "SYNTAX 1.3.6.1.1.16.1 )", + SLAP_MR_EQUALITY | SLAP_MR_MUTATION_NORMALIZER, NULL, NULL, UUIDNormalize, octetStringMatch, octetStringIndexer, octetStringFilter, NULL}, - {"( 1.3.6.1.4.1.4203.666.4.7 NAME 'UUIDOrderingMatch' " - "SYNTAX 1.3.6.1.4.1.4203.666.2.6 )", - SLAP_MR_HIDE | SLAP_MR_ORDERING, NULL, + {"( 1.3.6.1.1.16.3 NAME 'UUIDOrderingMatch' " + "SYNTAX 1.3.6.1.1.16.1 )", + SLAP_MR_ORDERING | SLAP_MR_MUTATION_NORMALIZER, NULL, NULL, UUIDNormalize, octetStringOrderingMatch, octetStringIndexer, octetStringFilter, "UUIDMatch"}, @@ -3886,6 +3949,16 @@ static slap_mrule_defs_rec mrule_defs[] = { NULL, NULL, "CSNMatch" }, +#ifdef SLAP_AUTHZ_SYNTAX + /* FIXME: OID is unused, but not registered yet */ + {"( 1.3.6.1.4.1.4203.666.4.12 NAME 'authzMatch' " + "SYNTAX 1.3.6.1.4.1.4203.666.2.7 )", + SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL, + NULL, authzNormalize, authzMatch, + NULL, NULL, + NULL}, +#endif /* SLAP_AUTHZ_SYNTAX */ + {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL, NULL, NULL, NULL } @@ -3944,4 +4017,7 @@ schema_destroy( void ) mr_destroy(); mru_destroy(); syn_destroy(); + + ldap_pvt_thread_mutex_destroy( &ad_undef_mutex ); + ldap_pvt_thread_mutex_destroy( &oc_undef_mutex ); }