Add better modlist2mod error reporting (to client)

This commit is contained in:
Kurt Zeilenga 2001-05-10 03:41:17 +00:00
parent f48cb50f12
commit 4baa7c47da
4 changed files with 43 additions and 31 deletions

View 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 );

View 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;
}
}

View 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,

View 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)