X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=servers%2Fslapd%2Fmr.c;h=d782148dba63cb19243316bc914472933c517037;hb=6273df07da2d23bea3f79ce630f8778e1881b3a7;hp=77e070b5952034fca924e4a34181d82b71681b96;hpb=d611a4b49a00238ed32ae84c68f27c6a0ef2273a;p=openldap
diff --git a/servers/slapd/mr.c b/servers/slapd/mr.c
index 77e070b595..d782148dba 100644
--- a/servers/slapd/mr.c
+++ b/servers/slapd/mr.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,6 @@
#include
#include "slap.h"
-#include "ldap_pvt.h"
struct mindexrec {
struct berval mir_name;
@@ -31,9 +30,9 @@ struct mindexrec {
};
static Avlnode *mr_index = NULL;
-static LDAP_SLIST_HEAD(MRList, slap_matching_rule) mr_list
+static LDAP_SLIST_HEAD(MRList, MatchingRule) mr_list
= LDAP_SLIST_HEAD_INITIALIZER(&mr_list);
-static LDAP_SLIST_HEAD(MRUList, slap_matching_rule_use) mru_list
+static LDAP_SLIST_HEAD(MRUList, MatchingRuleUse) mru_list
= LDAP_SLIST_HEAD_INITIALIZER(&mru_list);
static int
@@ -46,7 +45,7 @@ mr_index_cmp(
const struct mindexrec *mir2 = v_mir2;
int i = mir1->mir_name.bv_len - mir2->mir_name.bv_len;
if (i) return i;
- return (strcmp( mir1->mir_name.bv_val, mir2->mir_name.bv_val ));
+ return (strcasecmp( mir1->mir_name.bv_val, mir2->mir_name.bv_val ));
}
static int
@@ -59,7 +58,7 @@ mr_index_name_cmp(
const struct mindexrec *mir = v_mir;
int i = name->bv_len - mir->mir_name.bv_len;
if (i) return i;
- return (strncmp( name->bv_val, mir->mir_name.bv_val, name->bv_len ));
+ return (strncasecmp( name->bv_val, mir->mir_name.bv_val, name->bv_len ));
}
MatchingRule *
@@ -146,6 +145,67 @@ mr_insert(
return 0;
}
+int
+mr_make_syntax_compat_with_mr(
+ Syntax *syn,
+ MatchingRule *mr )
+{
+ int n = 0;
+
+ assert( syn != NULL );
+ assert( mr != NULL );
+
+ if ( mr->smr_compat_syntaxes ) {
+ /* count esisting */
+ for ( n = 0;
+ mr->smr_compat_syntaxes[ n ];
+ n++ )
+ {
+ if ( mr->smr_compat_syntaxes[ n ] == syn ) {
+ /* already compatible; mmmmh... */
+ return 1;
+ }
+ }
+ }
+
+ mr->smr_compat_syntaxes = ch_realloc(
+ mr->smr_compat_syntaxes,
+ sizeof( Syntax * )*(n + 2) );
+ mr->smr_compat_syntaxes[ n ] = syn;
+ mr->smr_compat_syntaxes[ n + 1 ] = NULL;
+
+ return 0;
+}
+
+int
+mr_make_syntax_compat_with_mrs(
+ const char *syntax,
+ char *const *mrs )
+{
+ int r, rc = 0;
+ Syntax *syn;
+
+ assert( syntax != NULL );
+ assert( mrs != NULL );
+
+ syn = syn_find( syntax );
+ if ( syn == NULL ) {
+ return -1;
+ }
+
+ for ( r = 0; mrs[ r ] != NULL; r++ ) {
+ MatchingRule *mr = mr_find( mrs[ r ] );
+ if ( mr == NULL ) {
+ /* matchingRule not found -- ignore by now */
+ continue;
+ }
+
+ rc += mr_make_syntax_compat_with_mr( syn, mr );
+ }
+
+ return rc;
+}
+
int
mr_add(
LDAPMatchingRule *mr,
@@ -170,6 +230,7 @@ mr_add(
for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
compat_syn[i] = syn_find( def->mrd_compat_syntaxes[i] );
if( compat_syn[i] == NULL ) {
+ ch_free( compat_syn );
return SLAP_SCHERR_SYN_NOT_FOUND;
}
}
@@ -199,10 +260,12 @@ mr_add(
smr->smr_syntax = syn;
} else {
*err = smr->smr_syntax_oid;
+ ch_free( smr );
return SLAP_SCHERR_SYN_NOT_FOUND;
}
} else {
*err = "";
+ ch_free( smr );
return SLAP_SCHERR_MR_INCOMPLETE;
}
code = mr_insert(smr,err);
@@ -218,9 +281,7 @@ register_matching_rule(
int code;
const char *err;
- if( def->mrd_usage == SLAP_MR_NONE &&
- def->mrd_compat_syntaxes == NULL )
- {
+ if( def->mrd_usage == SLAP_MR_NONE && def->mrd_compat_syntaxes == NULL ) {
Debug( LDAP_DEBUG_ANY, "register_matching_rule: not usable %s\n",
def->mrd_desc, 0, 0 );
@@ -229,10 +290,9 @@ register_matching_rule(
if( def->mrd_associated != NULL ) {
amr = mr_find( def->mrd_associated );
-
if( amr == NULL ) {
- Debug( LDAP_DEBUG_ANY, "register_matching_rule: could not locate "
- "associated matching rule %s for %s\n",
+ Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
+ "could not locate associated matching rule %s for %s\n",
def->mrd_associated, def->mrd_desc, 0 );
return -1;
@@ -244,17 +304,15 @@ register_matching_rule(
if (( def->mrd_usage & SLAP_MR_EQUALITY ) &&
(( def->mrd_usage & SLAP_MR_SUBTYPE_MASK ) != SLAP_MR_NONE ))
{
- Debug( LDAP_DEBUG_ANY,
- "register_matching_rule: inappropriate (approx) association "
- "%s for %s\n",
+ Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
+ "inappropriate (approx) association %s for %s\n",
def->mrd_associated, def->mrd_desc, 0 );
return -1;
}
} else if (!( amr->smr_usage & SLAP_MR_EQUALITY )) {
- Debug( LDAP_DEBUG_ANY,
- "register_matching_rule: inappropriate (equalilty) association "
- "%s for %s\n",
+ Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
+ "inappropriate (equalilty) association %s for %s\n",
def->mrd_associated, def->mrd_desc, 0 );
return -1;
}
@@ -319,7 +377,8 @@ matching_rule_use_init( void )
LDAP_SLIST_FOREACH( mr, &mr_list, smr_next ) {
AttributeType *at;
- MatchingRuleUse mru_storage, *mru = &mru_storage;
+ MatchingRuleUse mru_storage = {{ 0 }},
+ *mru = &mru_storage;
char **applies_oids = NULL;
@@ -344,8 +403,6 @@ matching_rule_use_init( void )
continue;
}
- memset( mru, 0, sizeof( MatchingRuleUse ) );
-
/*
* Note: we're using the same values of the corresponding
* MatchingRule structure; maybe we'd copy them ...
@@ -399,13 +456,16 @@ matching_rule_use_init( void )
return( 0 );
}
-int mr_usable_with_at(
- MatchingRule *mr,
- AttributeType *at )
+int
+mr_usable_with_at(
+ MatchingRule *mr,
+ AttributeType *at )
{
- if( mr->smr_usage & SLAP_MR_EXT && (
+ if ( ( mr->smr_usage & SLAP_MR_EXT ) && (
mr->smr_syntax == at->sat_syntax ||
- mr == at->sat_equality || mr == at->sat_approx ) )
+ mr == at->sat_equality ||
+ mr == at->sat_approx ||
+ syn_is_sup( at->sat_syntax, mr->smr_syntax ) ) )
{
return 1;
}