From: Julio Sánchez Fernández Date: Fri, 13 Oct 2000 20:39:36 +0000 (+0000) Subject: The beginning of extensible matches. Do not use. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1750 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d4b63dd3e37d1ae5f74e93bbc9ab8a278033ddbf;p=openldap The beginning of extensible matches. Do not use. --- diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index eff3d14d33..10e3fb24d6 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -18,7 +18,7 @@ SRCS = main.c daemon.c connection.c search.c filter.c add.c charray.c \ schema.c schema_check.c schema_init.c schema_prep.c \ schemaparse.c ad.c at.c mr.c syntax.c oc.c saslauthz.c \ monitor.c configinfo.c starttls.c index.c sets.c\ - root_dse.c sasl.c module.c suffixalias.c $(@PLAT@_SRCS) + root_dse.c sasl.c module.c suffixalias.c mra.c $(@PLAT@_SRCS) OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \ attr.o entry.o config.o backend.o result.o operation.o \ @@ -29,7 +29,7 @@ OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \ schema.o schema_check.o schema_init.o schema_prep.o \ schemaparse.o ad.o at.o mr.o syntax.o oc.o saslauthz.o \ monitor.o configinfo.o starttls.o index.o sets.o\ - root_dse.o sasl.o module.o suffixalias.o $(@PLAT@_OBJS) + root_dse.o sasl.o module.o suffixalias.o mra.o $(@PLAT@_OBJS) LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries diff --git a/servers/slapd/filter.c b/servers/slapd/filter.c index a294ec919f..c993dae7c7 100644 --- a/servers/slapd/filter.c +++ b/servers/slapd/filter.c @@ -255,13 +255,31 @@ get_filter( break; case LDAP_FILTER_EXT: - /* not yet implemented */ - Debug( LDAP_DEBUG_ANY, "extensible match not yet implemented.\n", - 0, 0, 0 ); - (void) ber_skip_tag( ber, &len ); - f->f_choice = SLAPD_FILTER_COMPUTED; - f->f_result = SLAPD_COMPARE_UNDEFINED; - *fstr = ch_strdup( "(extended)" ); + Debug( LDAP_DEBUG_FILTER, "EXTENSIBLE\n", 0, 0, 0 ); + + err = get_mra( ber, &f->f_mra, text ); + if ( err != LDAP_SUCCESS ) { + break; + } + + assert( f->f_mra != NULL ); + + filter_escape_value( f->f_mr_value, &escaped ); + + *fstr = ch_malloc( sizeof("(:dn::=)") + + (f->f_mr_desc ? f->f_mr_desc->ad_cname->bv_len : 0) + + (f->f_mr_rule ? strlen(f->f_mr_rule) : 0) + + escaped.bv_len ); + + sprintf( *fstr, "(%s%s%s%s:=%s)", + (f->f_mr_desc ? f->f_mr_desc->ad_cname->bv_val : ""), + (f->f_mr_dnattrs ? ":dn" : ""), + (f->f_mr_rule ? ":" : ""), + (f->f_mr_rule ? f->f_mr_rule : ""), + f->f_mr_desc->ad_cname->bv_val, + escaped.bv_val ); + + ber_memfree( escaped.bv_val ); break; default: diff --git a/servers/slapd/mra.c b/servers/slapd/mra.c new file mode 100644 index 0000000000..d6fc66b58a --- /dev/null +++ b/servers/slapd/mra.c @@ -0,0 +1,126 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* mra.c - routines for dealing with extensible matching rule assertions */ + +#include "portable.h" + +#include + +#include +#include + +#include "slap.h" + + +void +mra_free( + MatchingRuleAssertion *mra, + int freeit +) +{ + ad_free( mra->ma_desc, 1 ); + ch_free( (char *) mra->ma_rule ); + ber_bvfree( mra->ma_value ); + if ( freeit ) { + ch_free( (char *) mra ); + } +} + +int +get_mra( + BerElement *ber, + MatchingRuleAssertion **mra, + const char **text +) +{ + int rc, tag; + struct berval type, value, *nvalue; + MatchingRuleAssertion *ma; + + ma = ch_malloc( sizeof( MatchingRuleAssertion ) ); + ma->ma_rule = NULL; + ma->ma_desc = NULL; + ma->ma_dnattrs = 0; + ma->ma_value = NULL; + + rc = ber_scanf( ber, "{t", &tag ); + + if( rc == LBER_ERROR ) { + Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 ); + *text = "Error parsing matching rule assertion"; + return SLAPD_DISCONNECT; + } + + if ( tag == LDAP_FILTER_EXT_OID ) { + rc = ber_scanf( ber, "a", &ma->ma_rule ); + if ( rc == LBER_ERROR ) { + Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 ); + *text = "Error parsing matching rule in matching rule assertion"; + return SLAPD_DISCONNECT; + } + + rc = ber_scanf( ber, "t", &tag ); + + if( rc == LBER_ERROR ) { + Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 ); + *text = "Error parsing matching rule assertion"; + return SLAPD_DISCONNECT; + } + } + + if ( tag == LDAP_FILTER_EXT_TYPE ) { + rc = ber_scanf( ber, "o", &type ); + if ( rc == LBER_ERROR ) { + Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for ad\n", 0, 0, 0 ); + *text = "Error parsing attribute description in matching rule assertion"; + return SLAPD_DISCONNECT; + } + + rc = slap_bv2ad( &type, &ma->ma_desc, text ); + ch_free( type.bv_val ); + + if( rc != LDAP_SUCCESS ) { + ch_free( value.bv_val ); + mra_free( ma, 1 ); + return rc; + } + + rc = ber_scanf( ber, "t", &tag ); + + if( rc == LBER_ERROR ) { + Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 ); + *text = "Error parsing matching rule assertion"; + return SLAPD_DISCONNECT; + } + } + + rc = ber_scanf( ber, "o", &value ); + + if( rc == LBER_ERROR ) { + Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 ); + *text = "Error decoding value in matching rule assertion"; + return SLAPD_DISCONNECT; + } + + /* + * OK, if no matching rule, normalize for equality, otherwise + * normalize for the matching rule. + */ + rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text ); + ch_free( value.bv_val ); + + if( rc != LDAP_SUCCESS ) { + ad_free( ma->ma_desc, 1 ); + ch_free( ma ); + return rc; + } + + ma->ma_value = nvalue; + *mra = ma; + + return LDAP_SUCCESS; +} +