ITS#3118: fix objectIdentifierFirstComponentMatch for schema elements

This commit is contained in:
Kurt Zeilenga 2004-04-28 20:10:21 +00:00
parent 81d31dc721
commit 05463503e8
6 changed files with 215 additions and 46 deletions

View File

@ -33,7 +33,7 @@ int is_object_subclass(
if( sub == NULL || sup == NULL ) return 0; if( sub == NULL || sup == NULL ) return 0;
#if 1 #if 0
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ARGS, LDAP_LOG ( OPERATION, ARGS,
"is_object_subclass(%s,%s) %d\n", "is_object_subclass(%s,%s) %d\n",
@ -143,8 +143,7 @@ oc_index_cmp(
{ {
const struct oindexrec *oir1 = v_oir1, *oir2 = v_oir2; const struct oindexrec *oir1 = v_oir1, *oir2 = v_oir2;
int i = oir1->oir_name.bv_len - oir2->oir_name.bv_len; int i = oir1->oir_name.bv_len - oir2->oir_name.bv_len;
if (i) if (i) return i;
return i;
return strcasecmp( oir1->oir_name.bv_val, oir2->oir_name.bv_val ); return strcasecmp( oir1->oir_name.bv_val, oir2->oir_name.bv_val );
} }
@ -156,8 +155,7 @@ oc_index_name_cmp(
const struct berval *name = v_name; const struct berval *name = v_name;
const struct oindexrec *oir = v_oir; const struct oindexrec *oir = v_oir;
int i = name->bv_len - oir->oir_name.bv_len; int i = name->bv_len - oir->oir_name.bv_len;
if (i) if (i) return i;
return i;
return strncasecmp( name->bv_val, oir->oir_name.bv_val, name->bv_len ); return strncasecmp( name->bv_val, oir->oir_name.bv_val, name->bv_len );
} }
@ -358,8 +356,7 @@ oc_destroy( void )
static int static int
oc_insert( oc_insert(
ObjectClass *soc, ObjectClass *soc,
const char **err const char **err )
)
{ {
struct oindexrec *oir; struct oindexrec *oir;
char **names; char **names;
@ -378,7 +375,7 @@ oc_insert(
assert( oir->oir_oc ); assert( oir->oir_oc );
if ( avl_insert( &oc_index, (caddr_t) oir, if ( avl_insert( &oc_index, (caddr_t) oir,
oc_index_cmp, avl_dup_error ) ) oc_index_cmp, avl_dup_error ) )
{ {
*err = soc->soc_oid; *err = soc->soc_oid;
ldap_memfree(oir); ldap_memfree(oir);
@ -401,7 +398,7 @@ oc_insert(
assert( oir->oir_oc ); assert( oir->oir_oc );
if ( avl_insert( &oc_index, (caddr_t) oir, if ( avl_insert( &oc_index, (caddr_t) oir,
oc_index_cmp, avl_dup_error ) ) oc_index_cmp, avl_dup_error ) )
{ {
*err = *names; *err = *names;
ldap_memfree(oir); ldap_memfree(oir);
@ -422,8 +419,7 @@ int
oc_add( oc_add(
LDAPObjectClass *oc, LDAPObjectClass *oc,
int user, int user,
const char **err const char **err )
)
{ {
ObjectClass *soc; ObjectClass *soc;
int code; int code;
@ -501,16 +497,14 @@ oc_schema_info( Entry *e )
return -1; return -1;
} }
nval.bv_val = oc->soc_oid; nval = oc->soc_cname;
nval.bv_len = strlen(oc->soc_oid);
#if 0 #if 0
Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s (%s)\n", Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s (%s)\n",
(long) val.bv_len, val.bv_val, nval.bv_val ); (long) val.bv_len, val.bv_val, nval.bv_val );
#endif #endif
if( attr_merge_one( e, ad_objectClasses, &val, &nval ) ) if( attr_merge_one( e, ad_objectClasses, &val, &nval ) ) {
{
return -1; return -1;
} }
ldap_memfree( val.bv_val ); ldap_memfree( val.bv_val );

View File

@ -1059,8 +1059,6 @@ LDAP_SLAPD_V( int ) schema_init_done;
LDAP_SLAPD_F (int) slap_schema_init LDAP_P((void)); LDAP_SLAPD_F (int) slap_schema_init LDAP_P((void));
LDAP_SLAPD_F (void) schema_destroy LDAP_P(( void )); LDAP_SLAPD_F (void) schema_destroy LDAP_P(( void ));
LDAP_SLAPD_F( slap_syntax_validate_func ) numericoidValidate;
LDAP_SLAPD_F( slap_mr_indexer_func ) octetStringIndexer; LDAP_SLAPD_F( slap_mr_indexer_func ) octetStringIndexer;
LDAP_SLAPD_F( slap_mr_filter_func ) octetStringFilter; LDAP_SLAPD_F( slap_mr_filter_func ) octetStringFilter;

View File

@ -1502,7 +1502,7 @@ telephoneNumberNormalize(
return LDAP_SUCCESS; return LDAP_SUCCESS;
} }
int static int
numericoidValidate( numericoidValidate(
Syntax *syntax, Syntax *syntax,
struct berval *in ) struct berval *in )

View File

@ -32,33 +32,181 @@ int schema_init_done = 0;
struct slap_internal_schema slap_schema; struct slap_internal_schema slap_schema;
static int objectClassValidate( static int
oidValidate(
Syntax *syntax, Syntax *syntax,
struct berval *in ) struct berval *in )
{ {
ObjectClass *oc; struct berval val = *in;
int rc = numericoidValidate( syntax, in );
if ( rc ) return rc;
oc = oc_bvfind( in ); if( val.bv_len == 0 ) {
if( oc == NULL ) return LDAP_INVALID_SYNTAX; /* disallow empty strings */
return LDAP_INVALID_SYNTAX;
}
return LDAP_SUCCESS; if( DESC_LEADCHAR( val.bv_val[0] ) ) {
val.bv_val++;
val.bv_len--;
if ( val.bv_len == 0 ) return LDAP_SUCCESS;
while( DESC_CHAR( val.bv_val[0] ) ) {
val.bv_val++;
val.bv_len--;
if ( val.bv_len == 0 ) return LDAP_SUCCESS;
}
} else {
while( OID_LEADCHAR( val.bv_val[0] ) ) {
if ( val.bv_len == 1 ) {
return LDAP_SUCCESS;
}
if ( val.bv_val[0] == '0' ) {
break;
}
val.bv_val++;
val.bv_len--;
while ( OID_LEADCHAR( val.bv_val[0] )) {
val.bv_val++;
val.bv_len--;
if ( val.bv_len == 0 ) {
return LDAP_SUCCESS;
}
}
if( !OID_SEPARATOR( val.bv_val[0] )) {
break;
}
val.bv_val++;
val.bv_len--;
}
}
return LDAP_INVALID_SYNTAX;
} }
static int objectClassPretty( static int objectClassPretty(
struct slap_syntax *syntax, struct slap_syntax *syntax,
struct berval * in, struct berval * in,
struct berval * out, struct berval * out,
void *ctx ) void *ctx )
{ {
ObjectClass *oc = oc_bvfind( in ); ObjectClass *oc;
if( oidValidate( NULL, in )) return LDAP_INVALID_SYNTAX;
oc = oc_bvfind( in );
if( oc == NULL ) return LDAP_INVALID_SYNTAX; if( oc == NULL ) return LDAP_INVALID_SYNTAX;
ber_dupbv_x( out, &oc->soc_cname, ctx ); ber_dupbv_x( out, &oc->soc_cname, ctx );
return LDAP_SUCCESS; return LDAP_SUCCESS;
} }
static int
attributeTypeMatch(
int *matchp,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
void *assertedValue )
{
struct berval *a = (struct berval *) assertedValue;
AttributeType *at = at_bvfind( value );
AttributeType *asserted = at_bvfind( a );
if( asserted == NULL ) {
if( OID_LEADCHAR( *a->bv_val ) ) {
/* OID form, return FALSE */
*matchp = 1;
return LDAP_SUCCESS;
}
/* desc form, return undefined */
return LDAP_INVALID_SYNTAX;
}
if ( at == NULL ) {
/* unrecognized stored value */
return LDAP_INVALID_SYNTAX;
}
*matchp = ( asserted != at );
return LDAP_SUCCESS;
}
static int
matchingRuleMatch(
int *matchp,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
void *assertedValue )
{
struct berval *a = (struct berval *) assertedValue;
MatchingRule *mrv = mr_bvfind( value );
MatchingRule *asserted = mr_bvfind( a );
if( asserted == NULL ) {
if( OID_LEADCHAR( *a->bv_val ) ) {
/* OID form, return FALSE */
*matchp = 1;
return LDAP_SUCCESS;
}
/* desc form, return undefined */
return LDAP_INVALID_SYNTAX;
}
if ( mrv == NULL ) {
/* unrecognized stored value */
return LDAP_INVALID_SYNTAX;
}
*matchp = ( asserted != mrv );
return LDAP_SUCCESS;
}
static int
objectClassMatch(
int *matchp,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
void *assertedValue )
{
struct berval *a = (struct berval *) assertedValue;
ObjectClass *oc = oc_bvfind( value );
ObjectClass *asserted = oc_bvfind( a );
if( asserted == NULL ) {
if( OID_LEADCHAR( *a->bv_val ) ) {
/* OID form, return FALSE */
*matchp = 1;
return LDAP_SUCCESS;
}
/* desc form, return undefined */
return LDAP_INVALID_SYNTAX;
}
if ( oc == NULL ) {
/* unrecognized stored value */
return LDAP_INVALID_SYNTAX;
}
*matchp = ( asserted != oc );
return LDAP_SUCCESS;
}
static int static int
objectSubClassMatch( objectSubClassMatch(
int *matchp, int *matchp,
@ -293,7 +441,7 @@ static struct slap_schema_ad_map {
"EQUALITY objectIdentifierMatch " "EQUALITY objectIdentifierMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
NULL, SLAP_AT_FINAL, NULL, SLAP_AT_FINAL,
objectClassValidate, objectClassPretty, oidValidate, objectClassPretty,
NULL, NULL, objectSubClassMatch, NULL, NULL, objectSubClassMatch,
objectSubClassIndexer, objectSubClassFilter, objectSubClassIndexer, objectSubClassFilter,
offsetof(struct slap_internal_schema, si_ad_objectClass) }, offsetof(struct slap_internal_schema, si_ad_objectClass) },
@ -305,7 +453,7 @@ static struct slap_schema_ad_map {
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 " "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )", "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
NULL, 0, NULL, 0,
objectClassValidate, objectClassPretty, oidValidate, objectClassPretty,
NULL, NULL, objectSubClassMatch, NULL, NULL, objectSubClassMatch,
objectSubClassIndexer, objectSubClassFilter, objectSubClassIndexer, objectSubClassFilter,
offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) }, offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) },
@ -585,32 +733,32 @@ static struct slap_schema_ad_map {
"EQUALITY objectIdentifierFirstComponentMatch " "EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.16 USAGE directoryOperation )", "SYNTAX 1.3.6.1.4.1.1466.115.121.1.16 USAGE directoryOperation )",
subentryAttribute, SLAP_AT_HIDE, subentryAttribute, SLAP_AT_HIDE,
NULL, NULL, oidValidate, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, objectClassMatch, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_ditContentRules) }, offsetof(struct slap_internal_schema, si_ad_ditContentRules) },
{ "matchingRules", "( 2.5.21.4 NAME 'matchingRules' " { "matchingRules", "( 2.5.21.4 NAME 'matchingRules' "
"DESC 'RFC2252: matching rules' " "DESC 'RFC2252: matching rules' "
"EQUALITY objectIdentifierFirstComponentMatch " "EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.30 USAGE directoryOperation )", "SYNTAX 1.3.6.1.4.1.1466.115.121.1.30 USAGE directoryOperation )",
subentryAttribute, 0, subentryAttribute, 0,
NULL, NULL, oidValidate, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, matchingRuleMatch, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_matchingRules) }, offsetof(struct slap_internal_schema, si_ad_matchingRules) },
{ "attributeTypes", "( 2.5.21.5 NAME 'attributeTypes' " { "attributeTypes", "( 2.5.21.5 NAME 'attributeTypes' "
"DESC 'RFC2252: attribute types' " "DESC 'RFC2252: attribute types' "
"EQUALITY objectIdentifierFirstComponentMatch " "EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.3 USAGE directoryOperation )", "SYNTAX 1.3.6.1.4.1.1466.115.121.1.3 USAGE directoryOperation )",
subentryAttribute, 0, subentryAttribute, 0,
NULL, NULL, oidValidate, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, attributeTypeMatch, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_attributeTypes) }, offsetof(struct slap_internal_schema, si_ad_attributeTypes) },
{ "objectClasses", "( 2.5.21.6 NAME 'objectClasses' " { "objectClasses", "( 2.5.21.6 NAME 'objectClasses' "
"DESC 'RFC2252: object classes' " "DESC 'RFC2252: object classes' "
"EQUALITY objectIdentifierFirstComponentMatch " "EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.37 USAGE directoryOperation )", "SYNTAX 1.3.6.1.4.1.1466.115.121.1.37 USAGE directoryOperation )",
subentryAttribute, 0, subentryAttribute, 0,
NULL, NULL, oidValidate, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, objectClassMatch, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_objectClasses) }, offsetof(struct slap_internal_schema, si_ad_objectClasses) },
{ "nameForms", "( 2.5.21.7 NAME 'nameForms' " { "nameForms", "( 2.5.21.7 NAME 'nameForms' "
"DESC 'RFC2252: name forms ' " "DESC 'RFC2252: name forms ' "
@ -625,8 +773,8 @@ static struct slap_schema_ad_map {
"EQUALITY objectIdentifierFirstComponentMatch " "EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )", "SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )",
subentryAttribute, 0, subentryAttribute, 0,
NULL, NULL, oidValidate, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, matchingRuleMatch, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_matchingRuleUse) }, offsetof(struct slap_internal_schema, si_ad_matchingRuleUse) },
{ "ldapSyntaxes", "( 1.3.6.1.4.1.1466.101.120.16 NAME 'ldapSyntaxes' " { "ldapSyntaxes", "( 1.3.6.1.4.1.1466.101.120.16 NAME 'ldapSyntaxes' "
@ -860,6 +1008,25 @@ static struct slap_schema_syn_map {
offsetof(struct slap_internal_schema, si_syn_integer) }, offsetof(struct slap_internal_schema, si_syn_integer) },
{ "1.3.6.1.4.1.1466.115.121.1.40", { "1.3.6.1.4.1.1466.115.121.1.40",
offsetof(struct slap_internal_schema, si_syn_octetString) }, offsetof(struct slap_internal_schema, si_syn_octetString) },
{ "1.3.6.1.4.1.1466.115.121.1.3",
offsetof(struct slap_internal_schema, si_syn_attributeTypeDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.16",
offsetof(struct slap_internal_schema, si_syn_ditContentRuleDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.54",
offsetof(struct slap_internal_schema, si_syn_ldapSyntaxDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.30",
offsetof(struct slap_internal_schema, si_syn_matchingRuleDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.31",
offsetof(struct slap_internal_schema, si_syn_matchingRuleUseDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.35",
offsetof(struct slap_internal_schema, si_syn_nameFormDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.37",
offsetof(struct slap_internal_schema, si_syn_objectClassDesc) },
{ "1.3.6.1.4.1.1466.115.121.1.17",
offsetof(struct slap_internal_schema, si_syn_ditStructureRuleDesc) },
{ NULL, 0 } { NULL, 0 }
}; };
@ -979,8 +1146,7 @@ slap_schema_load( void )
} }
/* install custom rule routines */ /* install custom rule routines */
if( ( (*adp)->ad_type->sat_equality != NULL && if( syntax != NULL ||
syntax == (*adp)->ad_type->sat_equality->smr_syntax ) ||
ad_map[i].ssam_mr_convert || ad_map[i].ssam_mr_convert ||
ad_map[i].ssam_mr_normalize || ad_map[i].ssam_mr_normalize ||
ad_map[i].ssam_mr_match || ad_map[i].ssam_mr_match ||
@ -990,7 +1156,7 @@ slap_schema_load( void )
MatchingRule *mr = ch_malloc( sizeof( MatchingRule ) ); MatchingRule *mr = ch_malloc( sizeof( MatchingRule ) );
*mr = *(*adp)->ad_type->sat_equality; *mr = *(*adp)->ad_type->sat_equality;
if ( syntax == mr->smr_syntax ) { if ( syntax != NULL ) {
mr->smr_syntax = (*adp)->ad_type->sat_syntax; mr->smr_syntax = (*adp)->ad_type->sat_syntax;
} }
if ( ad_map[i].ssam_mr_convert ) { if ( ad_map[i].ssam_mr_convert ) {

View File

@ -789,14 +789,14 @@ struct slap_internal_schema {
AttributeDescription *si_ad_subtreeSpecification; AttributeDescription *si_ad_subtreeSpecification;
/* subschema subentry attribute descriptions */ /* subschema subentry attribute descriptions */
AttributeDescription *si_ad_ditStructureRules;
AttributeDescription *si_ad_ditContentRules;
AttributeDescription *si_ad_nameForms;
AttributeDescription *si_ad_objectClasses;
AttributeDescription *si_ad_attributeTypes; AttributeDescription *si_ad_attributeTypes;
AttributeDescription *si_ad_ditContentRules;
AttributeDescription *si_ad_ditStructureRules;
AttributeDescription *si_ad_ldapSyntaxes; AttributeDescription *si_ad_ldapSyntaxes;
AttributeDescription *si_ad_matchingRules; AttributeDescription *si_ad_matchingRules;
AttributeDescription *si_ad_matchingRuleUse; AttributeDescription *si_ad_matchingRuleUse;
AttributeDescription *si_ad_nameForms;
AttributeDescription *si_ad_objectClasses;
/* Aliases & Referrals */ /* Aliases & Referrals */
AttributeDescription *si_ad_aliasedObjectName; AttributeDescription *si_ad_aliasedObjectName;
@ -845,6 +845,16 @@ struct slap_internal_schema {
Syntax *si_syn_distinguishedName; Syntax *si_syn_distinguishedName;
Syntax *si_syn_integer; Syntax *si_syn_integer;
Syntax *si_syn_octetString; Syntax *si_syn_octetString;
/* Schema Syntaxes */
Syntax *si_syn_attributeTypeDesc;
Syntax *si_syn_ditContentRuleDesc;
Syntax *si_syn_ditStructureRuleDesc;
Syntax *si_syn_ldapSyntaxDesc;
Syntax *si_syn_matchingRuleDesc;
Syntax *si_syn_matchingRuleUseDesc;
Syntax *si_syn_nameFormDesc;
Syntax *si_syn_objectClassDesc;
}; };
typedef struct slap_attr_assertion { typedef struct slap_attr_assertion {

View File

@ -43,7 +43,8 @@ done
if test $RC = 0 ; then if test $RC = 0 ; then
echo "Using ldapsearch to retrieve the cn=Subschema..." echo "Using ldapsearch to retrieve the cn=Subschema..."
$LDAPSEARCH -b "cn=Subschema" -s base -h $LOCALHOST -p $PORT1 \ $LDAPSEARCH -b "cn=Subschema" -s base -h $LOCALHOST -p $PORT1 \
'(objectClasses=2.5.6.0)' cn objectClass >> $SEARCHOUT 2>&1 '(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
>> $SEARCHOUT 2>&1
RC=$? RC=$?
fi fi