1 /* component.c -- Component Filter Match Routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2004 by IBM Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
21 #include <ac/socket.h>
27 #ifdef LDAP_COMP_MATCH
29 #include "component.h"
32 * This three function pointers are initialized
33 * when a component module is loaded
35 convert_attr_to_comp_func* attr_converter = NULL ;
36 convert_assert_to_comp_func* assert_converter = NULL ;
37 convert_asn_to_ldap_func* csi_converter = NULL ;
38 free_component_func* component_destructor = NULL ;
40 #define OID_ALL_COMP_MATCH "1.2.36.79672281.1.13.6"
41 #define OID_COMP_FILTER_MATCH "1.2.36.79672281.1.13.2"
42 #define MAX_LDAP_STR_LEN 128
45 peek_componentId_type( ComponentAssertionValue* cav );
48 strip_cav_str( ComponentAssertionValue* cav, char* str);
51 peek_cav_str( ComponentAssertionValue* cav, char* str );
54 parse_comp_filter( Operation* op, ComponentAssertionValue* cav,
55 ComponentFilter** filt, const char** text );
58 free_comp_filter( ComponentFilter* f );
61 test_comp_filter( Syntax *syn, Attribute *a, struct berval *bv,
65 componentCertificateValidate(
73 componentFilterValidate(
81 allComponentsValidate(
89 componentFilterMatch (
97 Attribute *a = (Attribute*)value;
98 MatchingRuleAssertion * ma = (MatchingRuleAssertion*)assertedValue;
102 if ( !(mr && mr->smr_usage & SLAP_MR_COMPONENT) || !ma->ma_cf )
103 return LDAP_INAPPROPRIATE_MATCHING;
105 rc = test_comp_filter( syntax, a, a->a_vals, ma->ma_cf );
106 if ( component_destructor && a->a_component_values ) {
107 component_destructor(a->a_component_values);
108 a->a_component_values = NULL;
110 if ( rc == LDAP_COMPARE_TRUE ) {
114 else if ( rc == LDAP_COMPARE_FALSE ) {
119 return LDAP_INAPPROPRIATE_MATCHING;
130 struct berval *value,
131 void *assertedValue )
133 /* Only for Registeration */
139 slapd_ber2cav( struct berval* bv, ComponentAssertionValue* cav)
143 len = ldap_pvt_filter_value_unescape( bv->bv_val );
145 return LDAP_FILTER_ERROR;
147 cav->cav_ptr = cav->cav_buf = bv->bv_val;
148 cav->cav_end = bv->bv_val + len;
154 get_comp_filter( Operation* op, struct berval* bv, ComponentFilter** filt,
157 ComponentAssertionValue cav;
160 Debug( LDAP_DEBUG_FILTER, "get_comp_filter\n", 0, 0, 0 );
161 if ( (rc = slapd_ber2cav(bv, &cav) ) != LDAP_SUCCESS ) {
164 rc = parse_comp_filter( op, &cav, filt, text );
165 bv->bv_val = cav.cav_ptr;
171 eat_whsp( ComponentAssertionValue* cav )
173 for ( ; ( *cav->cav_ptr == ' ' ) && ( cav->cav_ptr < cav->cav_end ) ; ) {
179 cav_cur_len( ComponentAssertionValue* cav )
181 return cav->cav_end - cav->cav_ptr;
185 comp_first_element( ComponentAssertionValue* cav )
188 if ( cav_cur_len( cav ) >= 8 && strncmp( cav->cav_ptr, "item", 4 ) == 0 ) {
189 return LDAP_COMP_FILTER_ITEM;
191 else if ( cav_cur_len( cav ) >= 7 && strncmp( cav->cav_ptr, "and", 3 ) == 0 ) {
192 return LDAP_COMP_FILTER_AND;
194 else if ( cav_cur_len( cav ) >= 6 && strncmp( cav->cav_ptr, "or" , 2 ) == 0 ) {
195 return LDAP_COMP_FILTER_OR;
197 else if ( cav_cur_len( cav ) >= 7 && strncmp( cav->cav_ptr, "not", 3 ) == 0 ) {
198 return LDAP_COMP_FILTER_NOT;
201 return LDAP_COMP_FILTER_UNDEFINED;
205 comp_next_element( ComponentAssertionValue* cav )
209 if ( *(cav->cav_ptr) == ',' ) {
210 /* move pointer to the next CA */
212 return comp_first_element( cav );
214 else return LDAP_COMP_FILTER_UNDEFINED;
218 get_comp_filter_list( Operation *op, ComponentAssertionValue *cav,
219 ComponentFilter** f, const char** text )
221 ComponentFilter **new;
225 Debug( LDAP_DEBUG_FILTER, "get_comp_filter_list\n", 0, 0, 0 );
227 for ( tag = comp_first_element( cav ); tag != LDAP_COMP_FILTER_UNDEFINED;
228 tag = comp_next_element( cav ) )
230 err = parse_comp_filter( op, cav, new, text );
231 if ( err != LDAP_SUCCESS )
233 new = &(*new)->cf_next;
237 return( LDAP_SUCCESS );
241 get_componentId( Operation *op, ComponentAssertionValue* cav,
242 ComponentId ** cid, const char** text )
248 type = peek_componentId_type( cav );
250 Debug( LDAP_DEBUG_FILTER, "get_compId [%d]\n", type, 0, 0 );
255 case LDAP_COMPREF_IDENTIFIER :
256 _cid.ci_val.ci_identifier.bv_val = cav->cav_ptr;
257 for( ;cav->cav_ptr[len] != ' ' && cav->cav_ptr[len] != '\0' &&
258 cav->cav_ptr[len] != '.' && cav->cav_ptr[len] != '\"' ; len++ );
259 _cid.ci_val.ci_identifier.bv_len = len;
262 case LDAP_COMPREF_FROM_BEGINNING :
263 for( ;cav->cav_ptr[len] != ' ' && cav->cav_ptr[len] != '\0' &&
264 cav->cav_ptr[len] != '.' && cav->cav_ptr[len] != '\"' ; len++ );
265 _cid.ci_val.ci_from_beginning = strtol( cav->cav_ptr, NULL, 0 );
268 case LDAP_COMPREF_FROM_END :
269 for( ;cav->cav_ptr[len] != ' ' && cav->cav_ptr[len] != '\0' &&
270 cav->cav_ptr[len] != '.' && cav->cav_ptr[len] != '\"' ; len++ );
271 _cid.ci_val.ci_from_end = strtol( cav->cav_ptr, NULL, 0 );
274 case LDAP_COMPREF_COUNT :
275 _cid.ci_val.ci_count = 0;
278 case LDAP_COMPREF_CONTENT :
279 /* FIXEME: yet to be implemented */
281 case LDAP_COMPREF_SELECT :
282 /* FIXEME: yet to be implemented */
284 case LDAP_COMPREF_ALL :
285 _cid.ci_val.ci_all = '*';
287 Debug( LDAP_DEBUG_FILTER, "get_compId : ALL\n", 0, 0, 0 );
290 return LDAP_COMPREF_UNDEFINED;
293 *cid = op->o_tmpalloc( sizeof( ComponentId ), op->o_tmpmemctx );
299 peek_componentId_type( ComponentAssertionValue* cav )
302 if ( cav->cav_ptr[0] == '-' )
303 return LDAP_COMPREF_FROM_END;
304 else if ( cav->cav_ptr[0] == '(' )
305 return LDAP_COMPREF_SELECT;
306 else if ( cav->cav_ptr[0] == '*' )
307 return LDAP_COMPREF_ALL;
308 else if ( cav->cav_ptr[0] == '0' )
309 return LDAP_COMPREF_COUNT;
310 else if ( cav->cav_ptr[0] > '0' && cav->cav_ptr[0] <= '9' )
311 return LDAP_COMPREF_FROM_BEGINNING;
312 else if ( (cav->cav_end - cav->cav_ptr) >= 7 &&
313 strncmp(cav->cav_ptr,"content",7) == 0 )
314 return LDAP_COMPREF_CONTENT;
315 else if ( (cav->cav_ptr[0] >= 'a' && cav->cav_ptr[0] <= 'z') ||
316 (cav->cav_ptr[0] >= 'A' && cav->cav_ptr[0] <= 'Z') )
318 return LDAP_COMPREF_IDENTIFIER;
320 return LDAP_COMPREF_UNDEFINED;
324 comp_next_id( ComponentAssertionValue* cav )
327 if ( *(cav->cav_ptr) == '.' ) {
329 return LDAP_COMPREF_DEFINED;
331 else return LDAP_COMPREF_UNDEFINED;
335 get_component_reference( Operation *op, ComponentAssertionValue* cav,
336 ComponentReference** cr, const char** text )
340 ComponentReference* ca_comp_ref;
341 ComponentId** cr_list;
345 op->o_tmpalloc( sizeof( ComponentReference ), op->o_tmpmemctx );
347 cr_list = &ca_comp_ref->cr_list;
348 strip_cav_str( cav, "\"");
349 for ( type = peek_componentId_type( cav ) ; type != LDAP_COMPREF_UNDEFINED
350 ; type = comp_next_id( cav ), count++ ) {
351 rc = get_componentId( op, cav, cr_list, text );
352 if ( rc == LDAP_SUCCESS ) {
353 if ( count == 0 ) ca_comp_ref->cr_curr = ca_comp_ref->cr_list;
354 cr_list = &(*cr_list)->ci_next;
356 else if ( rc == LDAP_COMPREF_UNDEFINED )
359 ca_comp_ref->cr_len = count;
360 strip_cav_str( cav, "\"");
362 if ( rc == LDAP_SUCCESS ) {
366 else op->o_tmpfree( ca_comp_ref , op->o_tmpmemctx );
372 get_ca_use_default( Operation *op, ComponentAssertionValue* cav,
373 int* ca_use_def, const char** text )
375 if ( peek_cav_str( cav, "useDefaultValues" ) == LDAP_SUCCESS ) {
376 strip_cav_str( cav, "useDefaultValues" );
377 if ( peek_cav_str( cav, "TRUE" ) == LDAP_SUCCESS ) {
378 strip_cav_str( cav, "TRUE" );
380 } else if ( peek_cav_str( cav, "FALSE" ) == LDAP_SUCCESS ) {
381 strip_cav_str( cav, "FALSE" );
384 return LDAP_INVALID_SYNTAX;
388 /* If not defined, default value is TRUE */
396 get_matching_rule( Operation *op, ComponentAssertionValue* cav,
397 MatchingRule** mr, const char** text )
400 struct berval rule_text = { 0L, NULL };
404 for ( ; ; count++ ) {
405 if ( cav->cav_ptr[count] == ' ' || cav->cav_ptr[count] == ',' ||
406 cav->cav_ptr[count] == '\0' || cav->cav_ptr[count] == '{' ||
407 cav->cav_ptr[count] == '}' || cav->cav_ptr[count] == '\n' )
412 *text = "component matching rule not recognized";
413 return LDAP_INAPPROPRIATE_MATCHING;
416 rule_text.bv_len = count;
417 rule_text.bv_val = cav->cav_ptr;
418 *mr = mr_bvfind( &rule_text );
419 cav->cav_ptr += count;
420 Debug( LDAP_DEBUG_FILTER, "get_matching_rule: %s\n", (*mr)->smr_mrule.mr_oid, 0, 0 );
422 *text = "component matching rule not recognized";
423 return LDAP_INAPPROPRIATE_MATCHING;
429 get_GSER_value( ComponentAssertionValue* cav, struct berval* bv )
431 int count, sequent_dquote, unclosed_brace, succeed;
435 * Four cases of GSER <Values>
437 * StringVal, GeneralizedTimeVal, UTCTimeVal, ObjectDescriptorVal
438 * 2) '...'B or '...'H :
439 * BitStringVal, OctetStringVal
441 * SEQUENCE, SEQUENCEOF, SETOF, SET, CHOICE
442 * 4) Between two white spaces
443 * INTEGER, BOOLEAN, NULL,ENUMERATE, etc
447 if ( cav->cav_ptr[0] == '"' ) {
448 for( count = 1, sequent_dquote = 0 ; ; count++ ) {
449 /* In order to find escaped double quote */
450 if ( cav->cav_ptr[count] == '"' ) sequent_dquote++;
451 else sequent_dquote = 0;
453 if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) {
457 if ( ( cav->cav_ptr[count] == '"' && cav->cav_ptr[count-1] != '"') ||
458 ( sequent_dquote > 2 && (sequent_dquote%2) == 1 ) ) {
464 else if ( cav->cav_ptr[0] == '\'' ) {
465 for( count = 1 ; ; count++ ) {
466 if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end ) {
469 if ((cav->cav_ptr[count-1] == '\'' && cav->cav_ptr[count] == 'B')||
470 (cav->cav_ptr[count-1] == '\'' && cav->cav_ptr[count] == 'H') ) {
477 else if ( cav->cav_ptr[0] == '{' ) {
478 for( count = 1, unclosed_brace = 1 ; ; count++ ) {
479 if ( cav->cav_ptr[count] == '{' ) unclosed_brace++;
480 if ( cav->cav_ptr[count] == '}' ) unclosed_brace--;
482 if ( cav->cav_ptr[count] == '\0' || cav->cav_ptr > cav->cav_end )
484 if ( unclosed_brace == 0 ) {
492 count = cav->cav_end - cav->cav_ptr;
495 if ( !succeed ) return LDAP_FILTER_ERROR;
497 bv->bv_val = cav->cav_ptr;
498 bv->bv_len = count + 1 ;
499 cav->cav_ptr += count;
504 get_matching_value( Operation *op, ComponentAssertion* ca,
505 ComponentAssertionValue* cav, struct berval* bv,
508 if ( !(ca->ca_ma_rule->smr_usage & (SLAP_MR_COMPONENT)) ) {
509 if ( get_GSER_value( cav, bv ) != LDAP_SUCCESS ) {
510 return LDAP_FILTER_ERROR;
514 /* embeded componentFilterMatch Description */
515 bv->bv_val = cav->cav_ptr;
516 bv->bv_len = cav_cur_len( cav );
522 /* Don't move the position pointer, just peek given string */
524 peek_cav_str( ComponentAssertionValue* cav, char* str )
527 if ( cav_cur_len( cav ) >= strlen( str ) &&
528 strncmp( cav->cav_ptr, str, strlen( str ) ) == 0 )
531 return LDAP_INVALID_SYNTAX;
535 strip_cav_str( ComponentAssertionValue* cav, char* str)
538 if ( cav_cur_len( cav ) >= strlen( str ) &&
539 strncmp( cav->cav_ptr, str, strlen( str ) ) == 0 ) {
540 cav->cav_ptr += strlen( str );
544 return LDAP_INVALID_SYNTAX;
548 * TAG : "item", "and", "or", "not"
551 strip_cav_tag( ComponentAssertionValue* cav )
555 if ( cav_cur_len( cav ) >= 8 && strncmp( cav->cav_ptr, "item", 4 ) == 0 ) {
556 strip_cav_str( cav , "item:" );
557 return LDAP_COMP_FILTER_ITEM;
559 else if ( cav_cur_len( cav ) >= 7 && strncmp( cav->cav_ptr, "and", 3 ) == 0 ) {
560 strip_cav_str( cav , "and:" );
561 return LDAP_COMP_FILTER_AND;
563 else if ( cav_cur_len( cav ) >= 6 && strncmp( cav->cav_ptr, "or" , 2 ) == 0 ) {
564 strip_cav_str( cav , "or:" );
565 return LDAP_COMP_FILTER_OR;
567 else if ( cav_cur_len( cav ) >= 7 && strncmp( cav->cav_ptr, "not", 3 ) == 0 ) {
568 strip_cav_str( cav , "not:" );
569 return LDAP_COMP_FILTER_NOT;
576 * when encoding, "item" is denotation of ComponentAssertion
577 * ComponentAssertion :: SEQUENCE {
578 * component ComponentReference (SIZE(1..MAX)) OPTIONAL,
579 * useDefaultValues BOOLEAN DEFAULT TRUE,
580 * rule MATCHING-RULE.&id,
581 * value MATCHING-RULE.&AssertionType }
584 get_item( Operation *op, ComponentAssertionValue* cav, ComponentAssertion** ca,
588 ComponentAssertion* _ca;
590 Debug( LDAP_DEBUG_FILTER, "get_item: %s\n", 0, 0, 0 );
591 _ca = op->o_tmpalloc( sizeof( ComponentAssertion ), op->o_tmpmemctx );
593 _ca->ca_component_values = NULL;
595 rc = peek_cav_str( cav, "component" );
596 if ( rc == LDAP_SUCCESS ) {
597 strip_cav_str( cav, "component" );
598 rc = get_component_reference( op, cav, &_ca->ca_comp_ref, text );
599 if ( rc != LDAP_SUCCESS ) {
600 rc = LDAP_INVALID_SYNTAX;
601 op->o_tmpfree( _ca, op->o_tmpmemctx );
606 strip_cav_str( cav,",");
607 rc = peek_cav_str( cav, "useDefaultValues");
608 if ( rc == LDAP_SUCCESS ) {
609 rc = get_ca_use_default( op, cav, &_ca->ca_use_def, text );
610 if ( rc != LDAP_SUCCESS ) {
611 rc = LDAP_INVALID_SYNTAX;
612 op->o_tmpfree( _ca, op->o_tmpmemctx );
615 strip_cav_str( cav,",");
618 if ( !( strip_cav_str( cav, "rule" ) == LDAP_SUCCESS &&
619 get_matching_rule( op, cav , &_ca->ca_ma_rule, text ) == LDAP_SUCCESS )) {
620 rc = LDAP_INAPPROPRIATE_MATCHING;
621 op->o_tmpfree( _ca, op->o_tmpmemctx );
625 strip_cav_str( cav,",");
626 if ( !(strip_cav_str( cav, "value" ) == LDAP_SUCCESS &&
627 get_matching_value( op, _ca, cav, &_ca->ca_ma_value,text ) == LDAP_SUCCESS )) {
628 rc = LDAP_INVALID_SYNTAX;
629 op->o_tmpfree( _ca, op->o_tmpmemctx );
633 /* componentFilterMatch contains componentFilterMatch in it */
634 if ( strcmp(_ca->ca_ma_rule->smr_mrule.mr_oid, OID_COMP_FILTER_MATCH ) == 0) {
636 bv.bv_val = cav->cav_ptr;
637 bv.bv_len = cav_cur_len( cav );
638 rc = get_comp_filter( op, &bv,(ComponentFilter**)&_ca->ca_cf, text );
639 if ( rc != LDAP_SUCCESS ) {
640 op->o_tmpfree( _ca, op->o_tmpmemctx );
643 cav->cav_ptr = bv.bv_val;
644 assert( cav->cav_end >= bv.bv_val );
652 parse_comp_filter( Operation* op, ComponentAssertionValue* cav,
653 ComponentFilter** filt, const char** text )
656 * A component filter looks like this coming in:
657 * Filter ::= CHOICE {
658 * item [0] ComponentAssertion,
659 * and [1] SEQUENCE OF ComponentFilter,
660 * or [2] SEQUENCE OF ComponentFilter,
661 * not [3] ComponentFilter,
668 /* TAG : item, and, or, not in RFC 2254 */
669 tag = strip_cav_tag( cav );
671 if ( tag == LBER_ERROR ) {
672 *text = "error decoding comp filter";
673 return LDAP_PROTOCOL_ERROR;
676 if ( tag != LDAP_COMP_FILTER_NOT )
677 strip_cav_str( cav, "{");
684 switch ( f.cf_choice ) {
685 case LDAP_COMP_FILTER_AND:
686 Debug( LDAP_DEBUG_FILTER, "LDAP_COMP_FILTER_AND\n", 0, 0, 0 );
687 err = get_comp_filter_list( op, cav, &f.cf_and, text );
688 if ( err != LDAP_SUCCESS ) {
691 if ( f.cf_and == NULL ) {
692 f.cf_choice = SLAPD_FILTER_COMPUTED;
693 f.cf_result = LDAP_COMPARE_TRUE;
697 case LDAP_COMP_FILTER_OR:
698 Debug( LDAP_DEBUG_FILTER, "LDAP_COMP_FILTER_OR\n", 0, 0, 0 );
699 err = get_comp_filter_list( op, cav, &f.cf_or, text );
700 if ( err != LDAP_SUCCESS ) {
703 if ( f.cf_or == NULL ) {
704 f.cf_choice = SLAPD_FILTER_COMPUTED;
705 f.cf_result = LDAP_COMPARE_FALSE;
707 /* no assert - list could be empty */
710 case LDAP_COMP_FILTER_NOT:
711 Debug( LDAP_DEBUG_FILTER, "LDAP_COMP_FILTER_NOT\n", 0, 0, 0 );
712 err = parse_comp_filter( op, cav, &f.cf_not, text );
713 if ( err != LDAP_SUCCESS ) {
717 assert( f.cf_not != NULL );
718 if ( f.cf_not->cf_choice == SLAPD_FILTER_COMPUTED ) {
719 int fresult = f.cf_not->cf_result;
720 f.cf_choice = SLAPD_FILTER_COMPUTED;
721 op->o_tmpfree( f.cf_not, op->o_tmpmemctx );
725 case LDAP_COMPARE_TRUE:
726 f.cf_result = LDAP_COMPARE_FALSE;
728 case LDAP_COMPARE_FALSE:
729 f.cf_result = LDAP_COMPARE_TRUE;
732 /* (!Undefined) is Undefined */
737 case LDAP_COMP_FILTER_ITEM:
738 Debug( LDAP_DEBUG_FILTER, "LDAP_COMP_FILTER_ITEM\n", 0, 0, 0 );
739 err = get_item( op, cav, &f.cf_ca, text );
740 if ( err != LDAP_SUCCESS ) {
744 assert( f.cf_ca != NULL );
748 f.cf_choice = SLAPD_FILTER_COMPUTED;
749 f.cf_result = SLAPD_COMPARE_UNDEFINED;
753 if ( tag != LDAP_COMP_FILTER_NOT )
754 strip_cav_str( cav, "}");
756 if ( err != LDAP_SUCCESS && err != SLAPD_DISCONNECT ) {
758 f.cf_choice = SLAPD_FILTER_COMPUTED;
759 f.cf_result = SLAPD_COMPARE_UNDEFINED;
763 if ( err == LDAP_SUCCESS ) {
764 *filt = op->o_tmpalloc( sizeof(f), op->o_tmpmemctx );
772 test_comp_filter_and(
776 ComponentFilter *flist )
779 int rtn = LDAP_COMPARE_TRUE;
781 for ( f = flist ; f != NULL; f = f->cf_next ) {
782 int rc = test_comp_filter( syn, a, bv, f );
783 if ( rc == LDAP_COMPARE_FALSE ) {
788 if ( rc != LDAP_COMPARE_TRUE ) {
801 ComponentFilter *flist )
804 int rtn = LDAP_COMPARE_TRUE;
806 for ( f = flist ; f != NULL; f = f->cf_next ) {
807 int rc = test_comp_filter( syn, a, bv, f );
808 if ( rc == LDAP_COMPARE_TRUE ) {
813 if ( rc != LDAP_COMPARE_FALSE ) {
822 csi_value_match( MatchingRule *mr, struct berval* bv_attr,
823 struct berval* bv_assert )
828 assert( mr != NULL );
829 assert( !(mr->smr_usage & SLAP_MR_COMPONENT) );
831 if( !mr->smr_match ) {
832 return LDAP_INAPPROPRIATE_MATCHING;
835 rc = (mr->smr_match)( &match, 0, NULL /*ad->ad_type->sat_syntax*/,
836 mr, bv_attr, bv_assert );
837 if ( rc == LDAP_SUCCESS )
838 return match? LDAP_COMPARE_FALSE:LDAP_COMPARE_TRUE;
844 component_value_match( MatchingRule* mr,
845 ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert )
847 if ( mr->smr_usage & SLAP_MR_COMPONENT ){
848 if ( strcmp( mr->smr_mrule.mr_oid, OID_ALL_COMP_MATCH ) == 0 )
850 /* allComponentMatch */
851 return csi_attr->csi_comp_desc->cd_all_match( NULL,
852 csi_attr, csi_assert );
854 return csi_assert->csi_comp_desc->cd_all_match(
855 mr->smr_mrule.mr_oid, csi_attr, csi_assert );
859 if ( csi_attr->csi_comp_desc->cd_type == ASN_BASIC ) {
860 struct berval bv1, bv2;
861 char attr_buf[MAX_LDAP_STR_LEN],assert_buf[MAX_LDAP_STR_LEN];
862 bv1.bv_val = attr_buf;
863 bv2.bv_val = assert_buf;
864 if ( csi_converter &&
865 ( csi_converter ( csi_attr, &bv1 ) == LDAP_SUCCESS ) &&
866 ( csi_converter ( csi_assert, &bv2 ) == LDAP_SUCCESS ) )
868 return csi_value_match( mr, &bv1, &bv2 );
871 return LDAP_INAPPROPRIATE_MATCHING;
874 } else if ( csi_attr->csi_comp_desc->cd_type == ASN_COMPOSITE )
876 return LDAP_INAPPROPRIATE_MATCHING;
880 /* FIXME: what should be returned here? Is this rachable at all? */
881 return LDAP_INAPPROPRIATE_MATCHING;
885 * return codes : LDAP_COMPARE_TRUE, LDAP_COMPARE_FALSE
889 test_comp_filter_item(
893 ComponentAssertion *ca )
896 ComponentSyntaxInfo* csi_attr, *csi_assert=NULL;
898 if ( strcmp(ca->ca_ma_rule->smr_mrule.mr_oid,
899 OID_COMP_FILTER_MATCH ) == 0 && ca->ca_cf ) {
900 /* componentFilterMatch inside of componentFilterMatch */
901 rc = test_comp_filter( syn, a, bv, ca->ca_cf );
905 /* load attribute containg components */
906 /* For a testing purpose, link following function here */
907 if ( !a->a_component_values && attr_converter )
908 a->a_component_values = attr_converter (a, syn, bv);
910 if ( a->a_component_values == NULL )
911 return LDAP_PROTOCOL_ERROR;
913 /* load component containg the referenced component */
914 ca->ca_comp_ref->cr_curr = ca->ca_comp_ref->cr_list;
915 csi_attr = (((ComponentSyntaxInfo*)a->a_component_values)->csi_comp_desc->cd_extract_i)( ca->ca_comp_ref, a->a_component_values );
918 return LDAP_PROTOCOL_ERROR;
920 /* decode the asserted value */
921 if( !ca->ca_component_values && assert_converter ) {
922 assert_converter ( csi_attr, &ca->ca_ma_value,
923 &csi_assert, &len, DEC_ALLOC_MODE_0 );
924 ca->ca_component_values = (void*)csi_assert;
926 else csi_assert = ca->ca_component_values;
929 return LDAP_PROTOCOL_ERROR;
931 return component_value_match( ca->ca_ma_rule, csi_attr, csi_assert);
943 if ( !f ) return LDAP_PROTOCOL_ERROR;
945 Debug( LDAP_DEBUG_FILTER, "test_comp_filter\n", 0, 0, 0 );
946 switch ( f->cf_choice ) {
947 case SLAPD_FILTER_COMPUTED:
950 case LDAP_COMP_FILTER_AND:
951 rc = test_comp_filter_and( syn, a, bv, f->cf_and );
953 case LDAP_COMP_FILTER_OR:
954 rc = test_comp_filter_or( syn, a, bv, f->cf_or );
956 case LDAP_COMP_FILTER_NOT:
957 rc = test_comp_filter( syn, a, bv, f->cf_not );
960 case LDAP_COMPARE_TRUE:
961 rc = LDAP_COMPARE_FALSE;
963 case LDAP_COMPARE_FALSE:
964 rc = LDAP_COMPARE_TRUE;
968 case LDAP_COMP_FILTER_ITEM:
969 rc = test_comp_filter_item( syn, a, bv, f->cf_ca );
972 rc = LDAP_PROTOCOL_ERROR;
979 free_comp_filter_list( ComponentFilter* f )
981 ComponentFilter* tmp;
982 for ( tmp = f ; tmp; tmp = tmp->cf_next );
984 free_comp_filter( tmp );
989 free_comp_filter( ComponentFilter* f )
991 switch ( f->cf_choice ) {
992 case LDAP_COMP_FILTER_AND:
993 case LDAP_COMP_FILTER_OR:
994 case LDAP_COMP_FILTER_NOT:
995 free_comp_filter( f->cf_any );
998 case LDAP_COMP_FILTER_ITEM:
999 if ( component_destructor && f->cf_ca->ca_component_values )
1000 component_destructor( f->cf_ca->ca_component_values );
1009 component_free( ComponentFilter *f ) {
1010 free_comp_filter( f );