From: Kurt Zeilenga Date: Thu, 10 May 2001 03:41:17 +0000 (+0000) Subject: Add better modlist2mod error reporting (to client) X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1422 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4baa7c47da4cf49f718e12b7f3e4cf98cda67341;p=openldap Add better modlist2mod error reporting (to client) --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 28cc47990c..f8f220aed6 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -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 ); diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index ca4ac9c20c..21b4bbcd6b 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -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; } } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 0fefcde257..883942cbd9 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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, diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 96bf1c42ba..57911509f6 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -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)