]> git.sur5r.net Git - openldap/commitdiff
Import improved schema check error reporting from HEAD
authorKurt Zeilenga <kurt@openldap.org>
Fri, 22 Jun 2001 19:54:09 +0000 (19:54 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 22 Jun 2001 19:54:09 +0000 (19:54 +0000)
servers/slapd/back-ldbm/add.c
servers/slapd/back-ldbm/modify.c
servers/slapd/back-ldbm/modrdn.c
servers/slapd/back-ldbm/passwd.c
servers/slapd/proto-slap.h
servers/slapd/schema_check.c
servers/slapd/tools/slapadd.c

index 1b36200c8839720646eb0e883cc61ae1477b1b3a..a844bf90ce53598bd6bb26b4a76ba0a1228a4bc7 100644 (file)
@@ -31,7 +31,8 @@ ldbm_back_add(
        int                     rc; 
        const char      *text = NULL;
        AttributeDescription *children = slap_schema.si_ad_children;
-
+       char textbuf[SLAP_TEXT_BUFLEN];
+       size_t textlen = sizeof textbuf;
 
        Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_add: %s\n", e->e_dn, 0, 0);
 
@@ -45,7 +46,7 @@ ldbm_back_add(
                return( -1 );
        }
 
-       rc = entry_schema_check( e, NULL, &text );
+       rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
 
        if ( rc != LDAP_SUCCESS ) {
                ldap_pvt_thread_mutex_unlock(&li->li_add_mutex);
index 8e7c7441a852cceb361a7f9d61fc8e6b235db7e6..0dc69c133ee185ca916612fc97891f439e191292 100644 (file)
@@ -34,7 +34,9 @@ int ldbm_modify_internal(
     const char *dn,
     Modifications      *modlist,
     Entry      *e,
-       const char **text 
+       const char **text,
+       char *textbuf,
+       size_t textlen
 )
 {
        int rc, err;
@@ -135,7 +137,7 @@ int ldbm_modify_internal(
        ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
 
        /* check that the entry still obeys the schema */
-       rc = entry_schema_check( e, save_attrs, text );
+       rc = entry_schema_check( e, save_attrs, text, textbuf, textlen );
        if ( rc != LDAP_SUCCESS ) {
                attrs_free( e->e_attrs );
                e->e_attrs = save_attrs;
@@ -182,6 +184,8 @@ ldbm_back_modify(
        Entry           *e;
        int             manageDSAit = get_manageDSAit( op );
        const char *text = NULL;
+       char textbuf[SLAP_TEXT_BUFLEN];
+       size_t textlen = sizeof textbuf;
 
        Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
 
@@ -229,7 +233,8 @@ ldbm_back_modify(
        }
        
        /* Modify the entry */
-       rc = ldbm_modify_internal( be, conn, op, ndn, modlist, e, &text );
+       rc = ldbm_modify_internal( be, conn, op, ndn, modlist, e,
+               &text, textbuf, textlen );
 
        if( rc != LDAP_SUCCESS ) {
                if( rc != SLAPD_ABANDON ) {
index 45695414a7f21574588a4cb4e085a5494e83f409..ac78abf6b1893266e55d6f5439e697c0b9ede950 100644 (file)
@@ -53,6 +53,8 @@ ldbm_back_modrdn(
        int                     rootlock = 0;
        int                     rc = -1;
        const char *text = NULL;
+       char textbuf[SLAP_TEXT_BUFLEN];
+       size_t textlen = sizeof textbuf;
        /* Added to support LDAP v2 correctly (deleteoldrdn thing) */
        char            *new_rdn_val = NULL;    /* Val of new rdn */
        char            *new_rdn_type = NULL;   /* Type of new rdn */
@@ -464,7 +466,8 @@ ldbm_back_modrdn(
        }
 
        /* modify memory copy of entry */
-       rc = ldbm_modify_internal( be, conn, op, dn, &mod[0], e, &text );
+       rc = ldbm_modify_internal( be, conn, op, dn, &mod[0], e,
+               &text, textbuf, textlen );
 
        if( rc != LDAP_SUCCESS ) {
                if( rc != SLAPD_ABANDON ) {
index 00ef475a1c9cfe827a2326011da6cba579505551..563e2c89c2f51fb17167e8c1f1d87c329c4c6f06 100644 (file)
@@ -116,6 +116,8 @@ ldbm_back_exop_passwd(
        {
                Modifications ml;
                struct berval *vals[2];
+               char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
+               size_t textlen;
 
                vals[0] = hash;
                vals[1] = NULL;
@@ -126,16 +128,19 @@ ldbm_back_exop_passwd(
                ml.sml_next = NULL;
 
                rc = ldbm_modify_internal( be,
-                       conn, op, op->o_ndn, &ml, e, text );
+                       conn, op, op->o_ndn, &ml, e, text, textbuf, textlen );
 
+               if( rc ) {
+                       /* cannot return textbuf */
+                       *text = "entry modify failed";
+                       goto done;
+               }
        }
 
-       if( rc == LDAP_SUCCESS ) {
-               /* change the entry itself */
-               if( id2entry_add( be, e ) != 0 ) {
-                       *text = "entry update failed";
-                       rc = LDAP_OTHER;
-               }
+       /* change the entry itself */
+       if( id2entry_add( be, e ) != 0 ) {
+               *text = "entry update failed";
+               rc = LDAP_OTHER;
        }
        
 done:
index ba4ebec32a14c556a58688b82da1b18adcd6e1d0..c0e9a5f6f9a179fd667e0fc4030b4a770f8f25b5 100644 (file)
@@ -642,7 +642,8 @@ int oc_check_allowed(
        struct berval **oclist );
 LDAP_SLAPD_F (int) entry_schema_check LDAP_P((
        Entry *e, Attribute *attrs,
-       const char** text ));
+       const char** text,
+       char *textbuf, size_t textlen ));
 
 
 /*
index 7cf27a55a17b5118fb3565d700bc670b59b72cab..bc43608b812c73d631b1a436ec7be84e2fbffb36 100644 (file)
@@ -27,7 +27,8 @@ static char * oc_check_required(Entry *e, struct berval *ocname);
 
 int
 entry_schema_check( 
-       Entry *e, Attribute *oldattrs, const char** text )
+       Entry *e, Attribute *oldattrs, const char** text,
+       char *textbuf, size_t textlen )
 {
        Attribute       *a, *aoc;
        ObjectClass *oc;
@@ -38,6 +39,8 @@ entry_schema_check(
 
        if( !global_schemacheck ) return LDAP_SUCCESS;
 
+       *text = textbuf;
+
        /* find the object class attribute - could error out here */
        if ( (aoc = attr_find( e->e_attrs, ad_objectClass )) == NULL ) {
                Debug( LDAP_DEBUG_ANY, "No objectClass for entry (%s)\n",
@@ -49,20 +52,28 @@ entry_schema_check(
        /* check that the entry has required attrs for each oc */
        for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
                if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
+                       snprintf( textbuf, textlen, 
+                               "unrecognized objectClass '%s'",
+                               aoc->a_vals[i]->bv_val );
+
                        Debug( LDAP_DEBUG_ANY,
-                               "entry_check_schema(%s): objectClass \"%s\" not defined\n",
-                               e->e_dn, aoc->a_vals[i]->bv_val, 0 );
-                       *text = "unrecognized objectclass";
+                               "entry_check_schema(%s): \"%s\" not recognized\n",
+                               e->e_dn, textbuf, 0 );
+
                        return LDAP_OBJECT_CLASS_VIOLATION;
 
                } else {
                        char *s = oc_check_required( e, aoc->a_vals[i] );
 
                        if (s != NULL) {
+                               snprintf( textbuf, textlen, 
+                                       "object class '%s' requires attribute '%s'",
+                                       aoc->a_vals[i]->bv_val, s );
+
                                Debug( LDAP_DEBUG_ANY,
-                                       "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
-                                       e->e_dn, aoc->a_vals[i]->bv_val, s );
-                               *text = "missing required attribute";
+                                       "Entry (%s): %s\n",
+                                       e->e_dn, textbuf, 0 );
+
                                return LDAP_OBJECT_CLASS_VIOLATION;
                        }
 
@@ -85,10 +96,15 @@ entry_schema_check(
                ret = oc_check_allowed( a->a_desc->ad_type, aoc->a_vals );
                if ( ret != 0 ) {
                        char *type = a->a_desc->ad_cname->bv_val;
+
+                       snprintf( textbuf, textlen, 
+                               "attribute '%s' not allowed",
+                               type );
+
                        Debug( LDAP_DEBUG_ANY,
-                           "Entry (%s), attr \"%s\" not allowed\n",
-                           e->e_dn, type, 0 );
-                       *text = "attribute not allowed";
+                           "Entry (%s), %s\n",
+                           e->e_dn, textbuf, 0 );
+
                        break;
                }
        }
@@ -181,18 +197,9 @@ int oc_check_allowed(
                                }
                        }
                        /* maybe the next oc allows it */
-
-#ifdef OC_UNDEFINED_IMPLES_EXTENSIBLE
-               /* we don't know about the oc. assume it allows it */
-               } else {
-                       if ( t != type )
-                               ldap_memfree( t );
-                       return LDAP_SUCCESS;
-#endif
                }
        }
 
-
        /* not allowed by any oc */
        return LDAP_OBJECT_CLASS_VIOLATION;
 }
index 0e16f60749c742244c304f455ec238ca547b139a..5bc383297055752e72408664322f4450dad37632 100644 (file)
@@ -94,7 +94,12 @@ main( int argc, char **argv )
                if( global_schemacheck ) {
                        /* check schema */
                        const char *text;
-                       if ( entry_schema_check( e, NULL, &text ) != LDAP_SUCCESS ) {
+                       char textbuf[SLAP_TEXT_BUFLEN];
+                       size_t textlen = sizeof textbuf;
+
+                       rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
+
+                       if( rc != LDAP_SUCCESS ) {
                                fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
                                        progname, e->e_dn, lineno, text );
                                rc = EXIT_FAILURE;