X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Fvalsort.c;h=c5716eee3e066cd9e983591bdc0e50c9711de8d8;hb=fcf97e84486e1159c0f57114e3b130cf49d7f89d;hp=02ab60417bbc1f9d9e751f9ad333f4f0f8aa933f;hpb=474dfbc8fd75aed0376695ccc2f8c092a7a1bc6f;p=openldap diff --git a/servers/slapd/overlays/valsort.c b/servers/slapd/overlays/valsort.c index 02ab60417b..c5716eee3e 100644 --- a/servers/slapd/overlays/valsort.c +++ b/servers/slapd/overlays/valsort.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2005 The OpenLDAP Foundation. + * Copyright 2005-2009 The OpenLDAP Foundation. * Portions copyright 2005 Symas Corporation. * All rights reserved. * @@ -152,16 +152,16 @@ valsort_cf_func(ConfigArgs *c) { vitmp.vi_ad = NULL; i = slap_str2ad( c->argv[1], &vitmp.vi_ad, &text ); if ( i ) { - sprintf( c->msg, "<%s> %s", c->argv[0], text ); + snprintf( c->cr_msg, sizeof( c->cr_msg), "<%s> %s", c->argv[0], text ); Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", - c->log, c->msg, c->argv[1] ); + c->log, c->cr_msg, c->argv[1] ); return(1); } if ( is_at_single_value( vitmp.vi_ad->ad_type )) { - sprintf( c->msg, "<%s> %s is single-valued, ignoring", c->argv[0], + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> %s is single-valued, ignoring", c->argv[0], vitmp.vi_ad->ad_cname.bv_val ); Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", - c->log, c->msg, c->argv[1] ); + c->log, c->cr_msg, c->argv[1] ); return(0); } is_numeric = ( vitmp.vi_ad->ad_type->sat_syntax == syn_numericString || @@ -170,34 +170,34 @@ valsort_cf_func(ConfigArgs *c) { ber_str2bv( c->argv[2], 0, 0, &bv ); i = dnNormalize( 0, NULL, NULL, &bv, &vitmp.vi_dn, NULL ); if ( i ) { - sprintf( c->msg, "<%s> unable to normalize DN", c->argv[0] ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to normalize DN", c->argv[0] ); Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", - c->log, c->msg, c->argv[2] ); + c->log, c->cr_msg, c->argv[2] ); return(1); } i = verb_to_mask( c->argv[3], sorts ); if ( BER_BVISNULL( &sorts[i].word )) { - sprintf( c->msg, "<%s> unrecognized sort type", c->argv[0] ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unrecognized sort type", c->argv[0] ); Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", - c->log, c->msg, c->argv[3] ); + c->log, c->cr_msg, c->argv[3] ); return(1); } vitmp.vi_sort = sorts[i].mask; if ( sorts[i].mask == VALSORT_WEIGHTED && c->argc == 5 ) { i = verb_to_mask( c->argv[4], sorts ); if ( BER_BVISNULL( &sorts[i].word )) { - sprintf( c->msg, "<%s> unrecognized sort type", c->argv[0] ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unrecognized sort type", c->argv[0] ); Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", - c->log, c->msg, c->argv[4] ); + c->log, c->cr_msg, c->argv[4] ); return(1); } vitmp.vi_sort |= sorts[i].mask; } if (( vitmp.vi_sort & VALSORT_NUMERIC ) && !is_numeric ) { - sprintf( c->msg, "<%s> numeric sort specified for non-numeric syntax", + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> numeric sort specified for non-numeric syntax", c->argv[0] ); Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", - c->log, c->msg, c->argv[1] ); + c->log, c->cr_msg, c->argv[1] ); return(1); } vi = ch_malloc( sizeof(valsort_info) ); @@ -304,9 +304,7 @@ valsort_response( Operation *op, SlapReply *rs ) a = attr_find( rs->sr_entry->e_attrs, vi->vi_ad ); } - /* count values */ - for ( n = 0; !BER_BVISNULL( &a->a_vals[n] ); n++ ); - + n = a->a_numvals; if ( vi->vi_sort & VALSORT_WEIGHTED ) { int j, gotnvals; long *index = op->o_tmpalloc( n * sizeof(long), op->o_tmpmemctx ); @@ -339,8 +337,9 @@ valsort_response( Operation *op, SlapReply *rs ) if ( a->a_vals != a->a_nvals ) { ptr = a->a_vals[i].bv_val; - end = ber_bvchr( &a->a_vals[i], '}' ) + 1; + end = ber_bvchr( &a->a_vals[i], '}' ); assert( end != NULL ); + end++; for (;*end;) *ptr++ = *end++; *ptr = '\0'; @@ -446,6 +445,9 @@ valsort_modify( Operation *op, SlapReply *rs ) if ( !(vi->vi_sort & VALSORT_WEIGHTED )) continue; for (ml = op->orm_modlist; ml; ml=ml->sml_next ) { + /* Must be a Delete Attr op, so no values to consider */ + if ( !ml->sml_values ) + continue; if ( ml->sml_desc == vi->vi_ad ) break; } @@ -475,7 +477,8 @@ valsort_modify( Operation *op, SlapReply *rs ) static int valsort_db_open( - BackendDB *be + BackendDB *be, + ConfigReply *cr ) { return overlay_register_control( be, LDAP_CONTROL_VALSORT ); @@ -483,7 +486,8 @@ valsort_db_open( static int valsort_destroy( - BackendDB *be + BackendDB *be, + ConfigReply *cr ) { slap_overinst *on = (slap_overinst *)be->bd_info; @@ -509,8 +513,13 @@ valsort_parseCtrl( BerElement *ber = (BerElement *)&berbuf; ber_int_t flag = 0; - if ( ctrl->ldctl_value.bv_len == 0 ) { - rs->sr_text = "valSort control value is empty (or absent)"; + if ( BER_BVISNULL( &ctrl->ldctl_value )) { + rs->sr_text = "valSort control value is absent"; + return LDAP_PROTOCOL_ERROR; + } + + if ( BER_BVISEMPTY( &ctrl->ldctl_value )) { + rs->sr_text = "valSort control value is empty"; return LDAP_PROTOCOL_ERROR; } @@ -530,7 +539,7 @@ valsort_parseCtrl( static slap_overinst valsort; -int valsort_init() +int valsort_initialize( void ) { int rc; @@ -563,7 +572,7 @@ int valsort_init() #if SLAPD_OVER_VALSORT == SLAPD_MOD_DYNAMIC int init_module( int argc, char *argv[]) { - return valsort_init(); + return valsort_initialize(); } #endif