]> git.sur5r.net Git - openldap/commitdiff
Add better error reporting.
authorKurt Zeilenga <kurt@openldap.org>
Thu, 20 Dec 2001 00:34:36 +0000 (00:34 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 20 Dec 2001 00:34:36 +0000 (00:34 +0000)
Handle multiple SUP objectClasses.

servers/slapd/add.c
servers/slapd/modify.c
servers/slapd/proto-slap.h
servers/slapd/schema_check.c
servers/slapd/tools/slapadd.c

index 679411fbcd04e89cfdf4366eb5976c6563f6fa52..7ab3b8300e3083fd4f71d7eb0baa11a8fb63221b 100644 (file)
@@ -266,7 +266,8 @@ do_add( Connection *conn, Operation *op )
                                        assert( (*modstail)->sml_op == LDAP_MOD_ADD );
                                        assert( (*modstail)->sml_desc != NULL );
                                }
-                               rc = slap_mods_opattrs( op, mods, modstail, &text );
+                               rc = slap_mods_opattrs( op, mods, modstail, &text,
+                                       &textbuf, textlen );
                                if( rc != LDAP_SUCCESS ) {
                                        send_ldap_result( conn, op, rc,
                                                NULL, text, NULL, NULL );
index e23dfa8ce67c77a5e55a02d724d66e5d2c940c2f..a04ba300121faa0d9ed8515e762c3a6da29415d1 100644 (file)
@@ -348,8 +348,9 @@ do_modify(
                                {
                                        /* empty */
                                }
-                               rc = slap_mods_opattrs( op, mods, modstail, &text );
 
+                               rc = slap_mods_opattrs( op, mods, modstail, &text,
+                                       textbuf, textlen );
                                if( rc != LDAP_SUCCESS ) {
                                        send_ldap_result( conn, op, rc,
                                                NULL, text,
@@ -565,7 +566,8 @@ int slap_mods_opattrs(
        Operation *op,
        Modifications *mods,
        Modifications **modtail,
-       const char **text )
+       const char **text,
+       char *textbuf, size_t textlen )
 {
        struct berval name, timestamp, csn;
        time_t now = slap_get_time();
@@ -604,7 +606,7 @@ int slap_mods_opattrs(
                char uuidbuf[40];
                int rc;
 
-               rc = mods_structural_class( mods, &tmpval, text );
+               rc = mods_structural_class( mods, &tmpval, text, textbuf, textlen );
                if( rc != LDAP_SUCCESS ) {
                        return rc;
                }
index 708928d760b25a18b8c73988ee9daa98de10caac..f2fe409f44a4d457b7e519d93cb208080aaeb6b3 100644 (file)
@@ -437,9 +437,9 @@ LDAP_SLAPD_F (int) lock_fclose LDAP_P(( FILE *fp, FILE *lfp ));
  * modify.c
  *     should be relocated to separate file
  */
-LDAP_SLAPD_F( void ) slap_mod_free LDAP_P(( Modification *mod, int freeit ));
-LDAP_SLAPD_F( void ) slap_mods_free LDAP_P(( Modifications *mods ));
-LDAP_SLAPD_F( void ) slap_modlist_free LDAP_P(( LDAPModList *ml ));
+LDAP_SLAPD_F( void ) slap_mod_free( Modification *mod, int freeit );
+LDAP_SLAPD_F( void ) slap_mods_free( Modifications *mods );
+LDAP_SLAPD_F( void ) slap_modlist_free( LDAPModList *ml );
 
 LDAP_SLAPD_F( int ) slap_modlist2mods(
        LDAPModList *ml,
@@ -452,7 +452,8 @@ LDAP_SLAPD_F( int ) slap_mods_opattrs(
        Operation *op,
        Modifications *mods,
        Modifications **modlist,
-       const char **text );
+       const char **text,
+       char *textbuf, size_t textlen );
 
 /*
  * module.c
@@ -721,18 +722,26 @@ LDAP_SLAPD_F (int) is_entry_objectclass LDAP_P((
 /*
  * schema_check.c
  */
-int oc_check_allowed(
+LDAP_SLAPD_F( int ) oc_check_allowed(
        AttributeType *type,
        struct berval **oclist );
-LDAP_SLAPD_F (int) entry_schema_check LDAP_P((
+
+LDAP_SLAPD_F( int ) structural_class(
+       struct berval **ocs,
+       struct berval *scbv,
+       const char **text,
+       char *textbuf, size_t textlen );
+
+LDAP_SLAPD_F( int ) entry_schema_check(
        Entry *e, Attribute *attrs,
        const char** text,
-       char *textbuf, size_t textlen ));
-LDAP_SLAPD_F (int) mods_structural_class LDAP_P((
+       char *textbuf, size_t textlen );
+
+LDAP_SLAPD_F( int ) mods_structural_class(
        Modifications *mods,
        struct berval *oc,
-       const char** text ));
-
+       const char** text,
+       char *textbuf, size_t textlen );
 
 /*
  * schema_init.c
index 1f1ed839fe7bcb4fb32e1f14a2ed21ccb5d8dbf0..aa3341d079ea5dd3a803d513a9b6d82af73770e2 100644 (file)
@@ -27,12 +27,13 @@ static char * oc_check_required(
 int structural_class(
        struct berval **ocs,
        struct berval *scbv,
-       const char **text )
+       const char **text,
+       char *textbuf, size_t textlen )
 {
        int i;
        ObjectClass *oc;
        ObjectClass *sc = NULL;
-       int scn = 0;
+       int scn = -1;
 
        *text = "structural_class: internal error";
        scbv->bv_len = 0;
@@ -41,7 +42,10 @@ int structural_class(
                oc = oc_find( ocs[i]->bv_val );
 
                if( oc == NULL ) {
-                       *text = "unrecongized objectClass attribute";
+                       snprintf( textbuf, textlen,
+                               "unrecongized objectClass '%s'",
+                               ocs[i]->bv_val );
+                       *text = textbuf;
                        return LDAP_OBJECT_CLASS_VIOLATION;
                }
 
@@ -51,15 +55,50 @@ int structural_class(
                                scn = i;
 
                        } else if ( !is_object_subclass( oc, sc ) ) {
-                               /* FIXME: multiple inheritance possible! */
-                               *text = "invalid strucutural object class chain";
-                               return LDAP_OBJECT_CLASS_VIOLATION;
+                               int j;
+                               ObjectClass *xc = NULL;
+
+                               /* find common superior */
+                               for( j=i+1; ocs[j]; j++ ) {
+                                       xc = oc_find( ocs[j]->bv_val );
+
+                                       if( xc == NULL ) {
+                                               snprintf( textbuf, textlen,
+                                                       "unrecongized objectClass '%s'",
+                                                       ocs[i]->bv_val );
+                                               *text = textbuf;
+                                               return LDAP_OBJECT_CLASS_VIOLATION;
+                                       }
+
+                                       if( xc->soc_kind != LDAP_SCHEMA_STRUCTURAL ) {
+                                               xc = NULL;
+                                               continue;
+                                       }
+
+                                       if( is_object_subclass( sc, xc ) &&
+                                               is_object_subclass( oc, xc ) )
+                                       {
+                                               /* found common subclass */
+                                               break;
+                                       }
+
+                                       xc = NULL;
+                               }
+
+                               if( xc == NULL ) {
+                                       /* no common subclass */
+                                       snprintf( textbuf, textlen,
+                                               "invalid structural object class chain (%s/%s)",
+                                               ocs[scn]->bv_val, ocs[i]->bv_val );
+                                       *text = textbuf;
+                                       return LDAP_OBJECT_CLASS_VIOLATION;
+                               }
                        }
                }
        }
 
        if( sc == NULL ) {
-               *text = "no strucutural object classes";
+               *text = "no structural object classes provided";
                return LDAP_OBJECT_CLASS_VIOLATION;
        }
 
@@ -73,7 +112,8 @@ int structural_class(
 int mods_structural_class(
        Modifications *mods,
        struct berval *sc,
-       const char **text )
+       const char **text,
+       char *textbuf, size_t textlen )
 {
        Modifications *ocmod = NULL;
 
@@ -97,7 +137,8 @@ int mods_structural_class(
                return LDAP_OBJECT_CLASS_VIOLATION;
        }
 
-       return structural_class( ocmod->sml_bvalues, sc, text );
+       return structural_class( ocmod->sml_bvalues, sc,
+               text, textbuf, textlen );
 }
 
 /*
@@ -233,7 +274,7 @@ entry_schema_check(
        assert( aoc->a_vals != NULL );
        assert( aoc->a_vals[0] != NULL );
 
-       rc = structural_class( aoc->a_vals, &nsc, text );
+       rc = structural_class( aoc->a_vals, &nsc, text, textbuf, textlen );
        if( rc != LDAP_SUCCESS ) {
                return rc;
        } else if ( nsc.bv_len == 0 ) {
index 099033ac3bde01f59f5607dff46c54480825db54..41c654bb919300d968c02012130826b56c9768fc 100644 (file)
@@ -27,6 +27,10 @@ main( int argc, char **argv )
        int         lmax;
        int                     rc = EXIT_SUCCESS;
 
+       const char *text;
+       char textbuf[SLAP_TEXT_BUFLEN];
+       size_t textlen = sizeof textbuf;
+
        slap_tool_init( "slapadd", SLAPADD, argc, argv );
 
        if( !be->be_entry_open ||
@@ -112,9 +116,9 @@ main( int argc, char **argv )
                        if( sc == NULL ) {
                                struct berval *vals[2];
                                struct berval scbv;
-                               const char *text;
+
                                int ret = structural_class(
-                                       oc->a_vals, &scbv, &text );
+                                       oc->a_vals, &scbv, &text, textbuf, textlen );
 
                                if( scbv.bv_len == 0 ) {
                                        fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
@@ -134,9 +138,6 @@ main( int argc, char **argv )
 
                if( global_schemacheck ) {
                        /* check schema */
-                       const char *text;
-                       char textbuf[SLAP_TEXT_BUFLEN];
-                       size_t textlen = sizeof textbuf;
 
                        rc = entry_schema_check( e, NULL, &text, textbuf, textlen );