X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fschema_prep.c;h=e6d66910cae7891aa3acea3198a863ca2136a557;hb=021443bd5d355b8171dcbe4650c67507b9e1b83b;hp=9380fd0583fcdfd3a218fe19ff0e28849836c083;hpb=29bd3d4056e3e1902ec35f120ae2d2f243340162;p=openldap
diff --git a/servers/slapd/schema_prep.c b/servers/slapd/schema_prep.c
index 9380fd0583..e6d66910ca 100644
--- a/servers/slapd/schema_prep.c
+++ b/servers/slapd/schema_prep.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 1998-2003 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,8 +23,6 @@
#include
#include "slap.h"
-#include "ldap_pvt.h"
-#include "ldap_pvt_uc.h"
#define OCDEBUG 0
@@ -32,20 +30,173 @@ int schema_init_done = 0;
struct slap_internal_schema slap_schema;
+static int
+oidValidate(
+ Syntax *syntax,
+ struct berval *in )
+{
+ struct berval val = *in;
+
+ if( val.bv_len == 0 ) {
+ /* disallow empty strings */
+ return LDAP_INVALID_SYNTAX;
+ }
+
+ 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 {
+ int sep = 0;
+ while( OID_LEADCHAR( val.bv_val[0] ) ) {
+ val.bv_val++;
+ val.bv_len--;
+
+ if ( val.bv_val[-1] != '0' ) {
+ while ( OID_LEADCHAR( val.bv_val[0] )) {
+ val.bv_val++;
+ val.bv_len--;
+ }
+ }
+
+ if( val.bv_len == 0 ) {
+ if( sep == 0 ) break;
+ return LDAP_SUCCESS;
+ }
+
+ if( !OID_SEPARATOR( val.bv_val[0] )) break;
+
+ sep++;
+ val.bv_val++;
+ val.bv_len--;
+ }
+ }
+
+ return LDAP_INVALID_SYNTAX;
+}
+
+
static int objectClassPretty(
struct slap_syntax *syntax,
struct berval * in,
struct berval * out,
void *ctx )
{
- ObjectClass *oc = oc_bvfind( in );
+ ObjectClass *oc;
- if( oc != NULL ) {
- ber_dupbv_x( out, &oc->soc_cname, ctx );
- } else {
- ber_dupbv_x( out, in, ctx );
+ if( oidValidate( NULL, in )) return LDAP_INVALID_SYNTAX;
+
+ oc = oc_bvfind( in );
+ if( oc == NULL ) return LDAP_INVALID_SYNTAX;
+
+ ber_dupbv_x( out, &oc->soc_cname, ctx );
+ 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;
}
@@ -70,12 +221,12 @@ objectSubClassMatch(
}
/* desc form, return undefined */
- return SLAPD_COMPARE_UNDEFINED;
+ return LDAP_INVALID_SYNTAX;
}
if ( oc == NULL ) {
/* unrecognized stored value */
- return SLAPD_COMPARE_UNDEFINED;
+ return LDAP_INVALID_SYNTAX;
}
if( SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX( flags ) ) {
@@ -105,7 +256,7 @@ static int objectSubClassIndexer(
}
/* over allocate */
- ocvalues = sl_malloc( sizeof( struct berval ) * (noc+16), ctx );
+ ocvalues = slap_sl_malloc( sizeof( struct berval ) * (noc+16), ctx );
/* copy listed values (and termination) */
for( i=0; iad_type->sat_equality != NULL &&
- syntax == (*adp)->ad_type->sat_equality->smr_syntax ) ||
+ if( syntax != NULL ||
ad_map[i].ssam_mr_convert ||
ad_map[i].ssam_mr_normalize ||
ad_map[i].ssam_mr_match ||
@@ -980,7 +1212,7 @@ slap_schema_load( void )
MatchingRule *mr = ch_malloc( sizeof( MatchingRule ) );
*mr = *(*adp)->ad_type->sat_equality;
- if ( syntax == mr->smr_syntax ) {
+ if ( syntax != NULL ) {
mr->smr_syntax = (*adp)->ad_type->sat_syntax;
}
if ( ad_map[i].ssam_mr_convert ) {
@@ -1027,7 +1259,7 @@ slap_schema_load( void )
return LDAP_OTHER;
}
- code = oc_add(oc,0,&err);
+ code = oc_add(oc,0,NULL,&err);
if ( code ) {
fprintf( stderr, "slap_schema_load: ObjectClass "
"\"%s\": %s: \"%s\"\n",
@@ -1060,7 +1292,7 @@ slap_schema_load( void )
}
}
- slap_at_undefined.sat_syntax = slap_schema.si_syn_distinguishedName;
+ slap_at_undefined.sat_syntax = slap_schema.si_syn_octetString;
slap_schema.si_at_undefined = &slap_at_undefined;
return LDAP_SUCCESS;