]> git.sur5r.net Git - openldap/commitdiff
Add better modlist2mod error reporting (to client)
authorKurt Zeilenga <kurt@openldap.org>
Thu, 10 May 2001 03:41:17 +0000 (03:41 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 10 May 2001 03:41:17 +0000 (03:41 +0000)
servers/slapd/add.c
servers/slapd/modify.c
servers/slapd/proto-slap.h
servers/slapd/slap.h

index 28cc47990cb3ca3dfc0ae6d1e93c5978e6e159e8..f8f220aed695b1a81aee13479498d47304531092 100644 (file)
@@ -234,8 +234,12 @@ do_add( Connection *conn, Operation *op )
 #endif
                {
                        int update = be->be_update_ndn != NULL;
+                       char textbuf[SLAP_TEXT_BUFLEN];
+                       size_t textlen = sizeof textbuf;
+
+                       rc = slap_modlist2mods( modlist, update, &mods, &text,
+                               textbuf, textlen );
 
-                       rc = slap_modlist2mods( modlist, update, &mods, &text );
                        if( rc != LDAP_SUCCESS ) {
                                send_ldap_result( conn, op, rc,
                                        NULL, text, NULL, NULL );
index ca4ac9c20c4da195dd4be64ec5c0927fca07bf31..21b4bbcd6b0ff485132c4d212a58a14fecb8bab1 100644 (file)
@@ -279,7 +279,11 @@ do_modify(
                {
                        int update = be->be_update_ndn != NULL;
                        const char *text;
-                       rc = slap_modlist2mods( modlist, update, &mods, &text );
+                       char textbuf[SLAP_TEXT_BUFLEN];
+                       size_t textlen = sizeof textbuf;
+
+                       rc = slap_modlist2mods( modlist, update, &mods, &text,
+                               textbuf, textlen );
 
                        if( rc != LDAP_SUCCESS ) {
                                send_ldap_result( conn, op, rc,
@@ -347,7 +351,8 @@ int slap_modlist2mods(
        LDAPModList *ml,
        int update,
        Modifications **mods,
-       const char **text )
+       const char **text,
+       char *textbuf, size_t textlen )
 {
        int rc;
        Modifications **modtail = mods;
@@ -366,11 +371,9 @@ int slap_modlist2mods(
                rc = slap_str2ad( ml->ml_type, &mod->sml_desc, text );
 
                if( rc != LDAP_SUCCESS ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                                  "modlist2mods: Attribute %s is undefined (%s)\n", ml->ml_type, text ));
-#endif
                        slap_mods_free( mod );
+                       snprintf( textbuf, textlen, "%s: %s", ml->ml_type, text );
+                       *text = textbuf;
                        return rc;
                }
 
@@ -381,11 +384,11 @@ int slap_modlist2mods(
                {
                        /* attribute requires binary transfer */
                        slap_mods_free( mod );
-                       *text = "attribute requires ;binary transfer";
-#ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                                  "modlist2mods: Attribute %s %s\n", ml->ml_type, text ));
-#endif
+
+                       snprintf( textbuf, textlen,
+                               "%s: requires ;binary transfer",
+                               ml->ml_type );
+                       *text = textbuf;
                        return LDAP_UNDEFINED_TYPE;
                }
 
@@ -394,22 +397,20 @@ int slap_modlist2mods(
                {
                        /* attribute requires binary transfer */
                        slap_mods_free( mod );
-                       *text = "attribute disallows ;binary transfer";
-#ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                                  "modlist2mods: Attribute %s %s\n", ml->ml_type, text ));
-#endif
+                       snprintf( textbuf, textlen,
+                               "%s: disallows ;binary transfer",
+                               ml->ml_type );
+                       *text = textbuf;
                        return LDAP_UNDEFINED_TYPE;
                }
 
                if (!update && is_at_no_user_mod( ad->ad_type )) {
                        /* user modification disallowed */
                        slap_mods_free( mod );
-                       *text = "no user modification allowed";
-#ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                                  "modlist2mods: Attribute %s %s\n", ml->ml_type, text ));
-#endif
+                       snprintf( textbuf, textlen,
+                               "%s: no user modification allowed",
+                               ml->ml_type );
+                       *text = textbuf;
                        return LDAP_CONSTRAINT_VIOLATION;
                }
 
@@ -434,6 +435,11 @@ int slap_modlist2mods(
 
                                slap_mods_free( mod );
                                *text = "no validator for syntax";
+                               snprintf( textbuf, textlen,
+                                       "%s: no validator for syntax %s",
+                                       ml->ml_type,
+                                       ad->ad_type->sat_syntax->ssyn_oid );
+                               *text = textbuf;
                                return LDAP_INVALID_SYNTAX;
                        }
 
@@ -445,12 +451,10 @@ int slap_modlist2mods(
 
                                if( rc != 0 ) {
                                        slap_mods_free( mod );
-                                       *text = "value contains invalid data";
-#ifdef NEW_LOGGING
-                                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                                                  "modlist2mods: value for attribute %s contains invalid data\n",
-                                                  ml->ml_type ));
-#endif
+                                       snprintf( textbuf, textlen,
+                                               "%s: value #%ld contains invalid data",
+                                               ml->ml_type, (long) nvals );
+                                       *text = textbuf;
                                        return LDAP_INVALID_SYNTAX;
                                }
                        }
@@ -463,7 +467,10 @@ int slap_modlist2mods(
                                && nvals > 1 && is_at_single_value( ad->ad_type ))
                        {
                                slap_mods_free( mod );
-                               *text = "multiple values provided";
+                               snprintf( textbuf, textlen,
+                                       "%s: multiple value provided",
+                                       ml->ml_type );
+                               *text = textbuf;
                                return LDAP_INVALID_SYNTAX;
                        }
                }
index 0fefcde2573f9b07134e46288f0e56f2340a8cf9..883942cbd9052e108ffb6a4f04b4722e6550fa3a 100644 (file)
@@ -408,7 +408,8 @@ LDAP_SLAPD_F( int ) slap_modlist2mods(
        LDAPModList *ml,
        int update,
        Modifications **mods,
-       const char **text );
+       const char **text,
+       char *textbuf, size_t textlen );
 
 LDAP_SLAPD_F( int ) slap_mods_opattrs(
        Operation *op,
index 96bf1c42ba35a83f1b9a83437f1caffd80cafd73..57911509f6085e9c167c58b16b379ea92de8ed36 100644 (file)
@@ -61,7 +61,7 @@ LDAP_BEGIN_DECL
 #define SLAP_MAX_INCOMING (1<<18 - 1)
 #define SLAP_MAX_WORKER_THREADS                (32)
 
-#define SLAP_TEXT_LEN (256)
+#define SLAP_TEXT_BUFLEN (256)
 
 /* psuedo error code indicating abandoned operation */
 #define SLAPD_ABANDON (-1)