2000-02-05 13:01:41 +08:00
|
|
|
/* mr.c - routines to manage matching rule definitions */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 09:17:14 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2008-01-08 08:19:56 +08:00
|
|
|
* Copyright 1998-2008 The OpenLDAP Foundation.
|
2003-11-27 09:17:14 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2000-02-05 13:01:41 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
|
|
|
|
struct mindexrec {
|
2001-12-28 19:45:25 +08:00
|
|
|
struct berval mir_name;
|
2000-02-05 13:01:41 +08:00
|
|
|
MatchingRule *mir_mr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Avlnode *mr_index = NULL;
|
2007-03-20 09:07:10 +08:00
|
|
|
static LDAP_SLIST_HEAD(MRList, MatchingRule) mr_list
|
2003-01-21 04:21:17 +08:00
|
|
|
= LDAP_SLIST_HEAD_INITIALIZER(&mr_list);
|
2007-03-20 09:07:10 +08:00
|
|
|
static LDAP_SLIST_HEAD(MRUList, MatchingRuleUse) mru_list
|
2003-01-21 04:21:17 +08:00
|
|
|
= LDAP_SLIST_HEAD_INITIALIZER(&mru_list);
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
mr_index_cmp(
|
2002-12-15 06:25:52 +08:00
|
|
|
const void *v_mir1,
|
|
|
|
const void *v_mir2
|
2000-02-05 13:01:41 +08:00
|
|
|
)
|
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const struct mindexrec *mir1 = v_mir1;
|
|
|
|
const struct mindexrec *mir2 = v_mir2;
|
2001-12-28 19:45:25 +08:00
|
|
|
int i = mir1->mir_name.bv_len - mir2->mir_name.bv_len;
|
|
|
|
if (i) return i;
|
2004-09-18 08:21:29 +08:00
|
|
|
return (strcasecmp( mir1->mir_name.bv_val, mir2->mir_name.bv_val ));
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mr_index_name_cmp(
|
2002-12-15 06:25:52 +08:00
|
|
|
const void *v_name,
|
|
|
|
const void *v_mir
|
2000-02-05 13:01:41 +08:00
|
|
|
)
|
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
const struct berval *name = v_name;
|
|
|
|
const struct mindexrec *mir = v_mir;
|
2001-12-28 19:45:25 +08:00
|
|
|
int i = name->bv_len - mir->mir_name.bv_len;
|
|
|
|
if (i) return i;
|
2004-09-18 08:21:29 +08:00
|
|
|
return (strncasecmp( name->bv_val, mir->mir_name.bv_val, name->bv_len ));
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MatchingRule *
|
|
|
|
mr_find( const char *mrname )
|
2001-12-28 19:45:25 +08:00
|
|
|
{
|
|
|
|
struct berval bv;
|
|
|
|
|
2001-12-29 10:56:27 +08:00
|
|
|
bv.bv_val = (char *)mrname;
|
2001-12-28 19:45:25 +08:00
|
|
|
bv.bv_len = strlen( mrname );
|
|
|
|
return mr_bvfind( &bv );
|
|
|
|
}
|
|
|
|
|
|
|
|
MatchingRule *
|
|
|
|
mr_bvfind( struct berval *mrname )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
|
|
|
struct mindexrec *mir = NULL;
|
|
|
|
|
2002-12-15 06:25:52 +08:00
|
|
|
if ( (mir = avl_find( mr_index, mrname, mr_index_name_cmp )) != NULL ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
return( mir->mir_mr );
|
|
|
|
}
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2001-11-07 09:03:49 +08:00
|
|
|
void
|
|
|
|
mr_destroy( void )
|
|
|
|
{
|
2003-01-21 04:21:17 +08:00
|
|
|
MatchingRule *m;
|
2001-11-07 09:03:49 +08:00
|
|
|
|
|
|
|
avl_free(mr_index, ldap_memfree);
|
2003-01-21 04:21:17 +08:00
|
|
|
while( !LDAP_SLIST_EMPTY(&mr_list) ) {
|
|
|
|
m = LDAP_SLIST_FIRST(&mr_list);
|
|
|
|
LDAP_SLIST_REMOVE_HEAD(&mr_list, smr_next);
|
2002-08-31 18:45:22 +08:00
|
|
|
ch_free( m->smr_str.bv_val );
|
2003-03-14 17:37:27 +08:00
|
|
|
ch_free( m->smr_compat_syntaxes );
|
2001-11-07 09:03:49 +08:00
|
|
|
ldap_matchingrule_free((LDAPMatchingRule *)m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
static int
|
|
|
|
mr_insert(
|
|
|
|
MatchingRule *smr,
|
|
|
|
const char **err
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct mindexrec *mir;
|
|
|
|
char **names;
|
|
|
|
|
2003-02-26 15:39:30 +08:00
|
|
|
LDAP_SLIST_NEXT( smr, smr_next ) = NULL;
|
2003-01-21 04:21:17 +08:00
|
|
|
LDAP_SLIST_INSERT_HEAD(&mr_list, smr, smr_next);
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
if ( smr->smr_oid ) {
|
|
|
|
mir = (struct mindexrec *)
|
|
|
|
ch_calloc( 1, sizeof(struct mindexrec) );
|
2001-12-28 19:45:25 +08:00
|
|
|
mir->mir_name.bv_val = smr->smr_oid;
|
|
|
|
mir->mir_name.bv_len = strlen( smr->smr_oid );
|
2000-02-05 13:01:41 +08:00
|
|
|
mir->mir_mr = smr;
|
|
|
|
if ( avl_insert( &mr_index, (caddr_t) mir,
|
2002-12-15 06:25:52 +08:00
|
|
|
mr_index_cmp, avl_dup_error ) ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
*err = smr->smr_oid;
|
|
|
|
ldap_memfree(mir);
|
2002-06-01 04:24:26 +08:00
|
|
|
return SLAP_SCHERR_MR_DUP;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
/* FIX: temporal consistency check */
|
2001-12-28 19:45:25 +08:00
|
|
|
mr_bvfind(&mir->mir_name);
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
if ( (names = smr->smr_names) ) {
|
|
|
|
while ( *names ) {
|
|
|
|
mir = (struct mindexrec *)
|
|
|
|
ch_calloc( 1, sizeof(struct mindexrec) );
|
2001-12-28 19:45:25 +08:00
|
|
|
mir->mir_name.bv_val = *names;
|
|
|
|
mir->mir_name.bv_len = strlen( *names );
|
2000-02-05 13:01:41 +08:00
|
|
|
mir->mir_mr = smr;
|
|
|
|
if ( avl_insert( &mr_index, (caddr_t) mir,
|
2002-12-15 06:25:52 +08:00
|
|
|
mr_index_cmp, avl_dup_error ) ) {
|
2000-02-05 13:01:41 +08:00
|
|
|
*err = *names;
|
|
|
|
ldap_memfree(mir);
|
2002-06-01 04:24:26 +08:00
|
|
|
return SLAP_SCHERR_MR_DUP;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
/* FIX: temporal consistency check */
|
2001-12-28 19:45:25 +08:00
|
|
|
mr_bvfind(&mir->mir_name);
|
2000-02-05 13:01:41 +08:00
|
|
|
names++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-25 04:05:30 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
int
|
|
|
|
mr_add(
|
2000-07-23 01:30:44 +08:00
|
|
|
LDAPMatchingRule *mr,
|
2002-08-17 09:29:18 +08:00
|
|
|
slap_mrule_defs_rec *def,
|
2000-07-25 05:29:30 +08:00
|
|
|
MatchingRule *amr,
|
2000-02-05 13:01:41 +08:00
|
|
|
const char **err
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MatchingRule *smr;
|
|
|
|
Syntax *syn;
|
2002-09-01 04:42:25 +08:00
|
|
|
Syntax **compat_syn = NULL;
|
2000-02-05 13:01:41 +08:00
|
|
|
int code;
|
|
|
|
|
2002-09-01 04:42:25 +08:00
|
|
|
if( def->mrd_compat_syntaxes ) {
|
|
|
|
int i;
|
|
|
|
for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
|
|
|
|
/* just count em */
|
|
|
|
}
|
|
|
|
|
|
|
|
compat_syn = ch_malloc( sizeof(Syntax *) * (i+1) );
|
|
|
|
|
|
|
|
for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
|
|
|
|
compat_syn[i] = syn_find( def->mrd_compat_syntaxes[i] );
|
|
|
|
if( compat_syn[i] == NULL ) {
|
2006-03-31 20:20:04 +08:00
|
|
|
ch_free( compat_syn );
|
2002-09-01 04:42:25 +08:00
|
|
|
return SLAP_SCHERR_SYN_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compat_syn[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( &smr->smr_mrule, mr, sizeof(LDAPMatchingRule));
|
2000-02-05 13:01:41 +08:00
|
|
|
|
2002-08-31 18:45:22 +08:00
|
|
|
/*
|
|
|
|
* note: smr_bvoid uses the same memory of smr_mrule.mr_oid;
|
|
|
|
* smr_oidlen is #defined as smr_bvoid.bv_len
|
|
|
|
*/
|
|
|
|
smr->smr_bvoid.bv_val = smr->smr_mrule.mr_oid;
|
2001-12-26 22:36:02 +08:00
|
|
|
smr->smr_oidlen = strlen( mr->mr_oid );
|
2002-08-17 09:29:18 +08:00
|
|
|
smr->smr_usage = def->mrd_usage;
|
2002-09-01 04:42:25 +08:00
|
|
|
smr->smr_compat_syntaxes = compat_syn;
|
2002-08-17 09:29:18 +08:00
|
|
|
smr->smr_normalize = def->mrd_normalize;
|
|
|
|
smr->smr_match = def->mrd_match;
|
|
|
|
smr->smr_indexer = def->mrd_indexer;
|
|
|
|
smr->smr_filter = def->mrd_filter;
|
2000-07-25 05:29:30 +08:00
|
|
|
smr->smr_associated = amr;
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
if ( smr->smr_syntax_oid ) {
|
|
|
|
if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
|
|
|
|
smr->smr_syntax = syn;
|
|
|
|
} else {
|
|
|
|
*err = smr->smr_syntax_oid;
|
2006-03-31 20:20:04 +08:00
|
|
|
ch_free( smr );
|
2000-02-05 13:01:41 +08:00
|
|
|
return SLAP_SCHERR_SYN_NOT_FOUND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*err = "";
|
2006-03-31 20:20:04 +08:00
|
|
|
ch_free( smr );
|
2000-02-05 13:01:41 +08:00
|
|
|
return SLAP_SCHERR_MR_INCOMPLETE;
|
|
|
|
}
|
|
|
|
code = mr_insert(smr,err);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
register_matching_rule(
|
2002-08-17 09:29:18 +08:00
|
|
|
slap_mrule_defs_rec *def )
|
2000-02-05 13:01:41 +08:00
|
|
|
{
|
2000-07-23 01:30:44 +08:00
|
|
|
LDAPMatchingRule *mr;
|
2000-07-25 05:29:30 +08:00
|
|
|
MatchingRule *amr = NULL;
|
2000-02-05 13:01:41 +08:00
|
|
|
int code;
|
|
|
|
const char *err;
|
|
|
|
|
2005-01-27 03:46:12 +08:00
|
|
|
if( def->mrd_usage == SLAP_MR_NONE && def->mrd_compat_syntaxes == NULL ) {
|
2000-02-15 04:57:34 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "register_matching_rule: not usable %s\n",
|
2002-08-17 09:29:18 +08:00
|
|
|
def->mrd_desc, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
2000-02-15 04:57:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 09:29:18 +08:00
|
|
|
if( def->mrd_associated != NULL ) {
|
|
|
|
amr = mr_find( def->mrd_associated );
|
2000-07-25 05:40:58 +08:00
|
|
|
if( amr == NULL ) {
|
2005-01-27 03:46:12 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
|
|
|
|
"could not locate associated matching rule %s for %s\n",
|
2002-08-17 09:29:18 +08:00
|
|
|
def->mrd_associated, def->mrd_desc, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
2000-07-25 05:40:58 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2003-04-17 05:42:52 +08:00
|
|
|
|
|
|
|
if (( def->mrd_usage & SLAP_MR_EQUALITY ) &&
|
|
|
|
(( def->mrd_usage & SLAP_MR_SUBTYPE_MASK ) == SLAP_MR_NONE ))
|
|
|
|
{
|
|
|
|
if (( def->mrd_usage & SLAP_MR_EQUALITY ) &&
|
|
|
|
(( def->mrd_usage & SLAP_MR_SUBTYPE_MASK ) != SLAP_MR_NONE ))
|
|
|
|
{
|
2005-01-27 03:46:12 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
|
|
|
|
"inappropriate (approx) association %s for %s\n",
|
2003-04-17 05:42:52 +08:00
|
|
|
def->mrd_associated, def->mrd_desc, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!( amr->smr_usage & SLAP_MR_EQUALITY )) {
|
2005-01-27 03:46:12 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
|
|
|
|
"inappropriate (equalilty) association %s for %s\n",
|
2003-04-17 05:42:52 +08:00
|
|
|
def->mrd_associated, def->mrd_desc, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
2000-07-25 05:29:30 +08:00
|
|
|
}
|
|
|
|
|
2002-09-01 04:42:25 +08:00
|
|
|
mr = ldap_str2matchingrule( def->mrd_desc, &code, &err,
|
|
|
|
LDAP_SCHEMA_ALLOW_ALL );
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( !mr ) {
|
2002-09-01 04:42:25 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"Error in register_matching_rule: %s before %s in %s\n",
|
2002-08-17 09:29:18 +08:00
|
|
|
ldap_scherr2str(code), err, def->mrd_desc );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
2003-04-17 05:42:52 +08:00
|
|
|
return -1;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
2003-04-17 05:42:52 +08:00
|
|
|
|
2002-08-17 09:29:18 +08:00
|
|
|
code = mr_add( mr, def, amr, &err );
|
2000-05-29 07:51:39 +08:00
|
|
|
|
2000-07-22 01:25:41 +08:00
|
|
|
ldap_memfree( mr );
|
|
|
|
|
2000-02-05 13:01:41 +08:00
|
|
|
if ( code ) {
|
2002-09-01 04:42:25 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"Error in register_matching_rule: %s for %s in %s\n",
|
2002-08-17 09:29:18 +08:00
|
|
|
scherr2str(code), err, def->mrd_desc );
|
2001-01-16 03:17:29 +08:00
|
|
|
|
2003-04-17 05:42:52 +08:00
|
|
|
return -1;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
2000-05-29 07:51:39 +08:00
|
|
|
|
2003-04-17 05:42:52 +08:00
|
|
|
return 0;
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
|
2002-08-31 18:45:22 +08:00
|
|
|
void
|
|
|
|
mru_destroy( void )
|
|
|
|
{
|
2003-01-21 04:21:17 +08:00
|
|
|
MatchingRuleUse *m;
|
|
|
|
|
|
|
|
while( !LDAP_SLIST_EMPTY(&mru_list) ) {
|
|
|
|
m = LDAP_SLIST_FIRST(&mru_list);
|
|
|
|
LDAP_SLIST_REMOVE_HEAD(&mru_list, smru_next);
|
2002-08-31 18:45:22 +08:00
|
|
|
|
|
|
|
if ( m->smru_str.bv_val ) {
|
|
|
|
ch_free( m->smru_str.bv_val );
|
2003-10-23 09:16:06 +08:00
|
|
|
m->smru_str.bv_val = NULL;
|
2002-08-31 18:45:22 +08:00
|
|
|
}
|
|
|
|
/* memory borrowed from m->smru_mr */
|
|
|
|
m->smru_oid = NULL;
|
|
|
|
m->smru_names = NULL;
|
|
|
|
m->smru_desc = NULL;
|
|
|
|
|
2003-10-23 09:16:06 +08:00
|
|
|
/* free what's left (basically smru_mruleuse.mru_applies_oids) */
|
2002-08-31 18:45:22 +08:00
|
|
|
ldap_matchingruleuse_free((LDAPMatchingRuleUse *)m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
matching_rule_use_init( void )
|
|
|
|
{
|
|
|
|
MatchingRule *mr;
|
2003-01-21 04:21:17 +08:00
|
|
|
MatchingRuleUse **mru_ptr = &LDAP_SLIST_FIRST(&mru_list);
|
2002-08-31 18:45:22 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "matching_rule_use_init\n", 0, 0, 0 );
|
|
|
|
|
2003-01-21 04:21:17 +08:00
|
|
|
LDAP_SLIST_FOREACH( mr, &mr_list, smr_next ) {
|
2002-08-31 18:45:22 +08:00
|
|
|
AttributeType *at;
|
2008-10-13 13:44:55 +08:00
|
|
|
MatchingRuleUse mru_storage = {{ 0 }},
|
2007-08-25 04:05:30 +08:00
|
|
|
*mru = &mru_storage;
|
2002-08-31 18:45:22 +08:00
|
|
|
|
2002-08-31 19:14:15 +08:00
|
|
|
char **applies_oids = NULL;
|
|
|
|
|
2002-08-31 18:45:22 +08:00
|
|
|
mr->smr_mru = NULL;
|
|
|
|
|
|
|
|
/* hide rules marked as HIDE */
|
|
|
|
if ( mr->smr_usage & SLAP_MR_HIDE ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-09-01 03:05:36 +08:00
|
|
|
/* hide rules not marked as designed for extensibility */
|
|
|
|
/* MR_EXT means can be used any attribute type whose
|
|
|
|
* syntax is same as the assertion syntax.
|
|
|
|
* Another mechanism is needed where rule can be used
|
|
|
|
* with attribute of other syntaxes.
|
|
|
|
* Framework doesn't support this (yet).
|
|
|
|
*/
|
|
|
|
|
2002-09-01 04:42:25 +08:00
|
|
|
if (!( ( mr->smr_usage & SLAP_MR_EXT )
|
|
|
|
|| mr->smr_compat_syntaxes ) )
|
|
|
|
{
|
2002-08-31 18:45:22 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: we're using the same values of the corresponding
|
|
|
|
* MatchingRule structure; maybe we'd copy them ...
|
|
|
|
*/
|
|
|
|
mru->smru_mr = mr;
|
|
|
|
mru->smru_obsolete = mr->smr_obsolete;
|
|
|
|
mru->smru_applies_oids = NULL;
|
2003-01-21 04:21:17 +08:00
|
|
|
LDAP_SLIST_NEXT(mru, smru_next) = NULL;
|
2002-08-31 18:45:22 +08:00
|
|
|
mru->smru_oid = mr->smr_oid;
|
|
|
|
mru->smru_names = mr->smr_names;
|
|
|
|
mru->smru_desc = mr->smr_desc;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " %s (%s): ",
|
|
|
|
mru->smru_oid,
|
|
|
|
mru->smru_names ? mru->smru_names[ 0 ] : "", 0 );
|
|
|
|
|
2002-09-01 03:05:36 +08:00
|
|
|
at = NULL;
|
|
|
|
for ( at_start( &at ); at; at_next( &at ) ) {
|
2002-09-01 04:49:50 +08:00
|
|
|
if( at->sat_flags & SLAP_AT_HIDE ) continue;
|
2002-09-01 04:42:25 +08:00
|
|
|
|
2002-09-01 05:23:45 +08:00
|
|
|
if( mr_usable_with_at( mr, at )) {
|
|
|
|
ldap_charray_add( &applies_oids, at->sat_cname.bv_val );
|
2002-08-31 18:45:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: the matchingRules that are not used
|
|
|
|
* by any attributeType are not listed as
|
|
|
|
* matchingRuleUse
|
|
|
|
*/
|
2002-08-31 19:14:15 +08:00
|
|
|
if ( applies_oids != NULL ) {
|
|
|
|
mru->smru_applies_oids = applies_oids;
|
2002-08-31 18:45:22 +08:00
|
|
|
{
|
2002-09-01 04:42:25 +08:00
|
|
|
char *str = ldap_matchingruleuse2str( &mru->smru_mruleuse );
|
2002-08-31 18:45:22 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "matchingRuleUse: %s\n", str, 0, 0 );
|
|
|
|
ldap_memfree( str );
|
|
|
|
}
|
|
|
|
|
2002-08-31 19:14:15 +08:00
|
|
|
mru = (MatchingRuleUse *)ber_memalloc( sizeof( MatchingRuleUse ) );
|
|
|
|
/* call-forward from MatchingRule to MatchingRuleUse */
|
2002-08-31 18:45:22 +08:00
|
|
|
mr->smr_mru = mru;
|
2002-08-31 19:14:15 +08:00
|
|
|
/* copy static data to newly allocated struct */
|
2003-01-21 04:21:17 +08:00
|
|
|
*mru = mru_storage;
|
2002-08-31 19:14:15 +08:00
|
|
|
/* append the struct pointer to the end of the list */
|
2002-08-31 18:45:22 +08:00
|
|
|
*mru_ptr = mru;
|
2002-08-31 19:14:15 +08:00
|
|
|
/* update the list head pointer */
|
2003-01-21 04:21:17 +08:00
|
|
|
mru_ptr = &LDAP_SLIST_NEXT(mru,smru_next);
|
2002-08-31 18:45:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2007-05-17 21:57:20 +08:00
|
|
|
int
|
|
|
|
mr_usable_with_at(
|
|
|
|
MatchingRule *mr,
|
|
|
|
AttributeType *at )
|
2002-09-01 05:23:45 +08:00
|
|
|
{
|
2007-05-17 21:57:20 +08:00
|
|
|
if ( ( mr->smr_usage & SLAP_MR_EXT ) && (
|
2002-09-01 05:23:45 +08:00
|
|
|
mr->smr_syntax == at->sat_syntax ||
|
2007-05-17 21:57:20 +08:00
|
|
|
mr == at->sat_equality ||
|
|
|
|
mr == at->sat_approx ||
|
|
|
|
syn_is_sup( at->sat_syntax, mr->smr_syntax ) ) )
|
2002-09-01 05:23:45 +08:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mr->smr_compat_syntaxes ) {
|
|
|
|
int i;
|
|
|
|
for( i=0; mr->smr_compat_syntaxes[i]; i++ ) {
|
|
|
|
if( at->sat_syntax == mr->smr_compat_syntaxes[i] ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
|
|
|
|
int mr_schema_info( Entry *e )
|
|
|
|
{
|
2000-05-16 07:36:37 +08:00
|
|
|
AttributeDescription *ad_matchingRules = slap_schema.si_ad_matchingRules;
|
2003-02-28 15:06:06 +08:00
|
|
|
MatchingRule *mr;
|
|
|
|
struct berval nval;
|
2000-05-16 07:36:37 +08:00
|
|
|
|
2003-01-21 04:21:17 +08:00
|
|
|
LDAP_SLIST_FOREACH(mr, &mr_list, smr_next ) {
|
2002-01-06 13:29:04 +08:00
|
|
|
if ( mr->smr_usage & SLAP_MR_HIDE ) {
|
|
|
|
/* skip hidden rules */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-10-17 07:47:46 +08:00
|
|
|
if ( ! mr->smr_match ) {
|
|
|
|
/* skip rules without matching functions */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-31 18:45:22 +08:00
|
|
|
if ( mr->smr_str.bv_val == NULL ) {
|
|
|
|
if ( ldap_matchingrule2bv( &mr->smr_mrule, &mr->smr_str ) == NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
2000-05-24 08:59:58 +08:00
|
|
|
#if 0
|
2002-08-31 18:45:22 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "Merging mr [%lu] %s\n",
|
|
|
|
mr->smr_str.bv_len, mr->smr_str.bv_val, 0 );
|
2000-05-24 08:59:58 +08:00
|
|
|
#endif
|
2003-10-23 09:16:06 +08:00
|
|
|
|
2003-02-28 15:06:06 +08:00
|
|
|
nval.bv_val = mr->smr_oid;
|
|
|
|
nval.bv_len = strlen(mr->smr_oid);
|
2003-10-23 09:16:06 +08:00
|
|
|
if( attr_merge_one( e, ad_matchingRules, &mr->smr_str, &nval ) ) {
|
2002-11-02 02:59:52 +08:00
|
|
|
return -1;
|
2003-02-26 05:08:48 +08:00
|
|
|
}
|
2000-02-05 13:01:41 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-11 11:06:34 +08:00
|
|
|
int mru_schema_info( Entry *e )
|
|
|
|
{
|
2002-08-31 18:45:22 +08:00
|
|
|
AttributeDescription *ad_matchingRuleUse
|
|
|
|
= slap_schema.si_ad_matchingRuleUse;
|
2003-02-28 15:06:06 +08:00
|
|
|
MatchingRuleUse *mru;
|
|
|
|
struct berval nval;
|
2002-08-31 18:45:22 +08:00
|
|
|
|
2003-01-21 04:21:17 +08:00
|
|
|
LDAP_SLIST_FOREACH( mru, &mru_list, smru_next ) {
|
2002-08-31 18:45:22 +08:00
|
|
|
assert( !( mru->smru_usage & SLAP_MR_HIDE ) );
|
|
|
|
|
|
|
|
if ( mru->smru_str.bv_val == NULL ) {
|
|
|
|
if ( ldap_matchingruleuse2bv( &mru->smru_mruleuse, &mru->smru_str )
|
|
|
|
== NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "Merging mru [%lu] %s\n",
|
|
|
|
mru->smru_str.bv_len, mru->smru_str.bv_val, 0 );
|
|
|
|
#endif
|
2003-10-23 09:16:06 +08:00
|
|
|
|
2003-02-28 15:06:06 +08:00
|
|
|
nval.bv_val = mru->smru_oid;
|
|
|
|
nval.bv_len = strlen(mru->smru_oid);
|
2003-10-23 09:16:06 +08:00
|
|
|
if( attr_merge_one( e, ad_matchingRuleUse, &mru->smru_str, &nval ) ) {
|
2002-11-02 02:59:52 +08:00
|
|
|
return -1;
|
2003-02-26 05:08:48 +08:00
|
|
|
}
|
2002-08-31 18:45:22 +08:00
|
|
|
}
|
2002-03-11 11:06:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|