]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Updated numericString syntax routines
authorKurt Zeilenga <kurt@openldap.org>
Sat, 3 Feb 2001 04:45:59 +0000 (04:45 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sat, 3 Feb 2001 04:45:59 +0000 (04:45 +0000)
OC checks usage checks

servers/slapd/oc.c
servers/slapd/schema_init.c
servers/slapd/schemaparse.c
servers/slapd/slap.h

index 8ffd3d43c0b00e68eada4e46fafc9e967c44420b..c27f518029fe214d8e2bf42d9885d48458003035 100644 (file)
@@ -214,23 +214,23 @@ oc_add_sups(
        int             code;
        ObjectClass     *soc1;
        int             nsups;
-       char            **sups1;
+       char    **sups1;
        int             add_sups = 0;
 
        if ( sups ) {
                if ( !soc->soc_sups ) {
                        /* We are at the first recursive level */
                        add_sups = 1;
-                       nsups = 0;
+                       nsups = 1;
                        sups1 = sups;
                        while ( *sups1 ) {
                                nsups++;
                                sups1++;
                        }
-                       nsups++;
                        soc->soc_sups = (ObjectClass **)ch_calloc(nsups,
                                          sizeof(ObjectClass *));
                }
+
                nsups = 0;
                sups1 = sups;
                while ( *sups1 ) {
@@ -240,6 +240,18 @@ oc_add_sups(
                                return SLAP_SCHERR_CLASS_NOT_FOUND;
                        }
 
+                       /* check object class usage
+                        * abstract classes can only sup abstract classes 
+                        * structural classes can not sup auxiliary classes
+                        * auxiliary classes can not sup structural classes
+                        */
+                       if( soc->soc_kind != soc1->soc_kind
+                               && soc1->soc_kind != LDAP_SCHEMA_ABSTRACT )
+                       {
+                               *err = *sups1;
+                               return SLAP_SCHERR_CLASS_BAD_USAGE;
+                       }
+
                        if ( add_sups )
                                soc->soc_sups[nsups] = soc1;
 
@@ -256,6 +268,7 @@ oc_add_sups(
                        sups1++;
                }
        }
+
        return 0;
 }
 
@@ -349,6 +362,7 @@ oc_add(
        } else {
                code = oc_add_sups( soc, soc->soc_sup_oids, err );
        }
+
        if ( code != 0 ) return code;
 
        code = oc_create_required( soc, soc->soc_at_oids_must, err );
index 25e89e88e5eb4c253b10d05a11ac13849e58f960..179a84a61a553fbd9b12c46fa4298a768b18a016 100644 (file)
 /* recycled matching routines */
 #define bitStringMatch                                 octetStringMatch
 #define integerMatch                                   caseIgnoreIA5Match
-#define numericStringMatch                             caseIgnoreMatch
-#define objectIdentifierMatch                  numericStringMatch
-#define telephoneNumberMatch                   numericStringMatch
+#define numericStringMatch                             caseIgnoreIA5Match
+#define objectIdentifierMatch                  caseIgnoreIA5Match
+#define telephoneNumberMatch                   caseIgnoreIA5Match
 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
-#define generalizedTimeMatch                   numericStringMatch
-#define generalizedTimeOrderingMatch   numericStringMatch
+#define generalizedTimeMatch                   caseIgnoreIA5Match
+#define generalizedTimeOrderingMatch   caseIgnoreIA5Match
 #define uniqueMemberMatch                              dnMatch
 
 /* approx matching rules */
@@ -2594,7 +2594,7 @@ caseIgnoreIA5Match(
 {
        int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
 
-       if( match == 0 ) {
+       if( match == 0 && value->bv_len ) {
                match = strncasecmp( value->bv_val,
                        ((struct berval *) assertedValue)->bv_val,
                        value->bv_len );
@@ -3167,32 +3167,39 @@ int caseIgnoreIA5SubstringsFilter(
        return LDAP_SUCCESS;
 }
        
+static int
+numericStringValidate(
+       Syntax *syntax,
+       struct berval *in )
+{
+       ber_len_t i;
+
+       /* disallow empty numeric strings */
+
+       for(i=0; i < in->bv_len; i++) {
+               if( !SLAP_NUMERIC(in->bv_val[i]) ) {
+                       return LDAP_INVALID_SYNTAX;
+               }
+       }
+
+       return LDAP_SUCCESS;
+}
+
 static int
 numericStringNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval **normalized )
 {
-       /* similiar to IA5StringNormalize except removes all spaces */
+       /* removal all spaces */
        struct berval *newval;
        char *p, *q;
 
        newval = ch_malloc( sizeof( struct berval ) );
+       newval->bv_val = ch_malloc( val->bv_len + 1 );
 
        p = val->bv_val;
-
-       /* Ignore initial whitespace */
-       while ( ASCII_SPACE( *p ) ) {
-               p++;
-       }
-
-       if( *p == '\0' ) {
-               ch_free( newval );
-               return LDAP_INVALID_SYNTAX;
-       }
-
-       newval->bv_val = ch_strdup( p );
-       p = q = newval->bv_val;
+       q = newval->bv_val;
 
        while ( *p ) {
                if ( ASCII_SPACE( *p ) ) {
@@ -3203,16 +3210,9 @@ numericStringNormalize(
                }
        }
 
-       assert( *newval->bv_val );
        assert( newval->bv_val < p );
        assert( q <= p );
 
-       /* cannot start with a space */
-       assert( !ASCII_SPACE(*newval->bv_val) );
-
-       /* cannot end with a space */
-       assert( !ASCII_SPACE( q[-1] ) );
-
        /* null terminate */
        *q = '\0';
 
@@ -3758,7 +3758,7 @@ struct syntax_defs_rec syntax_defs[] = {
        {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
                0, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
-               0, IA5StringValidate, numericStringNormalize, NULL},
+               0, numericStringValidate, numericStringNormalize, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
                0, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
index 7009c265a91a443629ec3999170262ba9eff4940..855e503ef2064811fc486abeef43a069bcb052d6 100644 (file)
@@ -1,4 +1,3 @@
-/* schemaparse.c - routines to parse config file objectclass definitions */
 /* $OpenLDAP$ */
 /*
  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
@@ -25,7 +24,9 @@ static char *const err2text[] = {
        "Success",
        "Out of memory",
        "ObjectClass not found",
+       "ObjectClass inappropriate SUPerior",
        "AttributeType not found",
+       "AttributeType inappropriate USAGE",
        "Duplicate objectClass",
        "Duplicate attributeType",
        "Duplicate ldapSyntax",
index e87a194e496ba93c697c8677c15704211ee6401a..ee4d4d34f47aea442a6c90e2fd79de436457f4ea 100644 (file)
@@ -101,11 +101,12 @@ LDAP_BEGIN_DECL
 #define AD_LEADCHAR(c) ( ATTR_CHAR(c) )
 #define AD_CHAR(c)             ( ATTR_CHAR(c) || (c) == ';' )
 
+#define SLAP_NUMERIC(c) ( ASCII_DIGIT(c) || ASCII_SPACE(c) )
+
 #define SLAP_PRINTABLE(c)      ( ASCII_ALNUM(c) || (c) == '\'' || \
        (c) == '(' || (c) == ')' || (c) == '+' || (c) == ',' || \
        (c) == '-' || (c) == '.' || (c) == '/' || (c) == ':' || \
        (c) == '?' || (c) == ' ' )
-
 #define SLAP_PRINTABLES(c)     ( SLAP_PRINTABLE(c) || (c) == '$' )
 
 /* must match in schema_init.c */
@@ -201,16 +202,18 @@ typedef struct slap_ssf_set {
  */
 #define SLAP_SCHERR_OUTOFMEM           1
 #define SLAP_SCHERR_CLASS_NOT_FOUND    2
-#define SLAP_SCHERR_ATTR_NOT_FOUND     3
-#define SLAP_SCHERR_DUP_CLASS          4
-#define SLAP_SCHERR_DUP_ATTR           5
-#define SLAP_SCHERR_DUP_SYNTAX         6
-#define SLAP_SCHERR_DUP_RULE           7
-#define SLAP_SCHERR_NO_NAME            8
-#define SLAP_SCHERR_ATTR_INCOMPLETE    9
-#define SLAP_SCHERR_MR_NOT_FOUND       10
-#define SLAP_SCHERR_SYN_NOT_FOUND      11
-#define SLAP_SCHERR_MR_INCOMPLETE      12
+#define SLAP_SCHERR_CLASS_BAD_USAGE    3
+#define SLAP_SCHERR_ATTR_NOT_FOUND     4
+#define SLAP_SCHERR_ATTR_BAD_USAGE     5
+#define SLAP_SCHERR_DUP_CLASS          6
+#define SLAP_SCHERR_DUP_ATTR           7
+#define SLAP_SCHERR_DUP_SYNTAX         8
+#define SLAP_SCHERR_DUP_RULE           9
+#define SLAP_SCHERR_NO_NAME            10
+#define SLAP_SCHERR_ATTR_INCOMPLETE    11
+#define SLAP_SCHERR_MR_NOT_FOUND       12
+#define SLAP_SCHERR_SYN_NOT_FOUND      13
+#define SLAP_SCHERR_MR_INCOMPLETE      14
 
 typedef struct slap_oid_macro {
        struct berval som_oid;