]> git.sur5r.net Git - openldap/commitdiff
Added further consistency checks and a new schema parse error value
authorPierangelo Masarati <ando@openldap.org>
Sun, 10 Apr 2005 15:14:13 +0000 (15:14 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 10 Apr 2005 15:14:13 +0000 (15:14 +0000)
which should help in debugging schema development for back-config.
The check essentially verifies, when a duplicate attributeType is found,
that the new attributeType definition is an exact duplicate of the
definition already present in the schema.

servers/slapd/at.c
servers/slapd/schemaparse.c
servers/slapd/slap.h

index f5b27f6a3908d1d97b02406e7b4ed2b254f34d6b..75f2e11b8336b80ade121e31233f661c8202188b 100644 (file)
@@ -258,7 +258,57 @@ at_next( AttributeType **at )
 
        return (*at != NULL);
 }
-       
+
+/*
+ * check whether the two attributeTypes actually __are__ identical,
+ * or rather inconsistent
+ */
+static int
+at_check_dup(
+       AttributeType           *sat,
+       AttributeType           *new_sat )
+{
+       if ( new_sat->sat_oid != NULL ) {
+               if ( sat->sat_oid == NULL ) {
+                       return SLAP_SCHERR_ATTR_INCONSISTENT;
+               }
+
+               if ( strcmp( sat->sat_oid, new_sat->sat_oid ) != 0 ) {
+                       return SLAP_SCHERR_ATTR_INCONSISTENT;
+               }
+
+       } else {
+               if ( sat->sat_oid != NULL ) {
+                       return SLAP_SCHERR_ATTR_INCONSISTENT;
+               }
+       }
+
+       if ( new_sat->sat_names ) {
+               int     i;
+
+               if ( sat->sat_names == NULL ) {
+                       return SLAP_SCHERR_ATTR_INCONSISTENT;
+               }
+
+               for ( i = 0; new_sat->sat_names[ i ]; i++ ) {
+                       if ( sat->sat_names[ i ] == NULL ) {
+                               return SLAP_SCHERR_ATTR_INCONSISTENT;
+                       }
+                       
+                       if ( strcasecmp( sat->sat_names[ i ],
+                                       new_sat->sat_names[ i ] ) != 0 )
+                       {
+                               return SLAP_SCHERR_ATTR_INCONSISTENT;
+                       }
+               }
+       } else {
+               if ( sat->sat_names != NULL ) {
+                       return SLAP_SCHERR_ATTR_INCONSISTENT;
+               }
+       }
+
+       return SLAP_SCHERR_ATTR_DUP;
+}
 
 
 static int
@@ -269,6 +319,7 @@ at_insert(
        struct aindexrec        *air;
        char                    **names;
 
+
        if ( sat->sat_oid ) {
                air = (struct aindexrec *)
                        ch_calloc( 1, sizeof(struct aindexrec) );
@@ -276,16 +327,26 @@ at_insert(
                air->air_name.bv_len = strlen(sat->sat_oid);
                air->air_at = sat;
                if ( avl_insert( &attr_index, (caddr_t) air,
-                                attr_index_cmp, avl_dup_error ) ) {
+                                attr_index_cmp, avl_dup_error ) )
+               {
+                       AttributeType   *old_sat;
+                       int             rc;
+
                        *err = sat->sat_oid;
-                       ldap_memfree(air);
-                       return SLAP_SCHERR_ATTR_DUP;
+
+                       old_sat = at_bvfind( &air->air_name );
+                       rc = at_check_dup( old_sat, sat );
+
+                       ldap_memfree( air );
+
+                       return rc;
                }
                /* FIX: temporal consistency check */
-               at_bvfind(&air->air_name);
+               at_bvfind( &air->air_name );
        }
 
-       if ( (names = sat->sat_names) ) {
+       names = sat->sat_names;
+       if ( names ) {
                while ( *names ) {
                        air = (struct aindexrec *)
                                ch_calloc( 1, sizeof(struct aindexrec) );
@@ -293,10 +354,19 @@ at_insert(
                        air->air_name.bv_len = strlen(*names);
                        air->air_at = sat;
                        if ( avl_insert( &attr_index, (caddr_t) air,
-                                        attr_index_cmp, avl_dup_error ) ) {
+                                        attr_index_cmp, avl_dup_error ) )
+                       {
+                               AttributeType   *old_sat;
+                               int             rc;
+
                                *err = *names;
+
+                               old_sat = at_bvfind( &air->air_name );
+                               rc = at_check_dup( old_sat, sat );
+
                                ldap_memfree(air);
-                               return SLAP_SCHERR_ATTR_DUP;
+
+                               return rc;
                        }
                        /* FIX: temporal consistency check */
                        at_bvfind(&air->air_name);
@@ -597,7 +667,7 @@ at_add(
                sat->sat_substr = mr;
        }
 
-       code = at_insert(sat,err);
+       code = at_insert( sat, err );
        if ( code == 0 && rsat )
                *rsat = sat;
        return code;
@@ -628,7 +698,7 @@ at_unparse( BerVarray *res, AttributeType *start, AttributeType *end, int sys )
        AttributeType *at;
        int i, num;
        struct berval bv, *bva = NULL, idx;
-       char ibuf[32], *ptr;
+       char ibuf[32];
 
        if ( !start )
                start = LDAP_STAILQ_FIRST( &attr_list );
index 16addf4a16029a93b3c64d811e1bb8b46214c044..b43874d0590fd34e8429ad0425800537713523ba 100644 (file)
@@ -43,6 +43,7 @@ static char *const err2text[] = {
        "AttributeType inappropriate SUPerior",
        "AttributeType SYNTAX or SUPerior required",
        "Duplicate attributeType",
+       "Inconsistent attributeType",
        "MatchingRule not found",
        "MatchingRule incomplete",
        "Duplicate matchingRule",
@@ -55,7 +56,8 @@ static char *const err2text[] = {
        "Duplicate Content Rule",
        "Content Rule not for STRUCTURAL object class",
        "Content Rule AUX contains inappropriate object class",
-       "Content Rule attribute type list contains duplicate"
+       "Content Rule attribute type list contains duplicate",
+       NULL
 };
 
 char *
index bf9568880c910736190e17f6c7f4c7e945e1a886..91f7c1a996f6ddd42ae406ff2ed3525477f652c8 100644 (file)
@@ -279,31 +279,35 @@ typedef struct slap_ssf_set {
 /*
  * represents schema information for a database
  */
-#define SLAP_SCHERR_OUTOFMEM                   1
-#define SLAP_SCHERR_CLASS_NOT_FOUND            2
-#define SLAP_SCHERR_CLASS_BAD_USAGE            3
-#define SLAP_SCHERR_CLASS_BAD_SUP              4
-#define SLAP_SCHERR_CLASS_DUP                  5
-#define SLAP_SCHERR_ATTR_NOT_FOUND             6
-#define SLAP_SCHERR_ATTR_BAD_MR                        7
-#define SLAP_SCHERR_ATTR_BAD_USAGE             8
-#define SLAP_SCHERR_ATTR_BAD_SUP               9
-#define SLAP_SCHERR_ATTR_INCOMPLETE            10
-#define SLAP_SCHERR_ATTR_DUP                   11
-#define SLAP_SCHERR_MR_NOT_FOUND               12
-#define SLAP_SCHERR_MR_INCOMPLETE              13
-#define SLAP_SCHERR_MR_DUP                             14
-#define SLAP_SCHERR_SYN_NOT_FOUND              15
-#define SLAP_SCHERR_SYN_DUP                            16
-#define SLAP_SCHERR_NO_NAME                            17
-#define SLAP_SCHERR_NOT_SUPPORTED              18
-#define SLAP_SCHERR_BAD_DESCR                  19
-#define SLAP_SCHERR_OIDM                               20
-#define SLAP_SCHERR_CR_DUP                             21
-#define SLAP_SCHERR_CR_BAD_STRUCT              22
-#define SLAP_SCHERR_CR_BAD_AUX                 23
-#define SLAP_SCHERR_CR_BAD_AT                  24
-#define SLAP_SCHERR_LAST                               SLAP_SCHERR_CR_BAD_AT
+enum {
+       SLAP_SCHERR_OUTOFMEM = 1,
+       SLAP_SCHERR_CLASS_NOT_FOUND,
+       SLAP_SCHERR_CLASS_BAD_USAGE,
+       SLAP_SCHERR_CLASS_BAD_SUP,
+       SLAP_SCHERR_CLASS_DUP,
+       SLAP_SCHERR_ATTR_NOT_FOUND,
+       SLAP_SCHERR_ATTR_BAD_MR,
+       SLAP_SCHERR_ATTR_BAD_USAGE,
+       SLAP_SCHERR_ATTR_BAD_SUP,
+       SLAP_SCHERR_ATTR_INCOMPLETE,
+       SLAP_SCHERR_ATTR_DUP,
+       SLAP_SCHERR_ATTR_INCONSISTENT,
+       SLAP_SCHERR_MR_NOT_FOUND,
+       SLAP_SCHERR_MR_INCOMPLETE,
+       SLAP_SCHERR_MR_DUP,
+       SLAP_SCHERR_SYN_NOT_FOUND,
+       SLAP_SCHERR_SYN_DUP,
+       SLAP_SCHERR_NO_NAME,
+       SLAP_SCHERR_NOT_SUPPORTED,
+       SLAP_SCHERR_BAD_DESCR,
+       SLAP_SCHERR_OIDM,
+       SLAP_SCHERR_CR_DUP,
+       SLAP_SCHERR_CR_BAD_STRUCT,
+       SLAP_SCHERR_CR_BAD_AUX,
+       SLAP_SCHERR_CR_BAD_AT,
+
+       SLAP_SCHERR_LAST
+};
 
 typedef union slap_sockaddr {
        struct sockaddr sa_addr;