X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Fvalsort.c;h=5d89eb0554c776d55c43969d259caf027671023a;hb=c6b5abbfd20567116846ebc38f0005c429284c98;hp=5950a208c40b4e09a960901f360fcddbf3ddc2ee;hpb=3a9310431e4e90005c1d7573c2b8f492cbf0cd0d;p=openldap diff --git a/servers/slapd/overlays/valsort.c b/servers/slapd/overlays/valsort.c index 5950a208c4..5d89eb0554 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-2007 The OpenLDAP Foundation. + * Copyright 2005-2012 The OpenLDAP Foundation. * Portions copyright 2005 Symas Corporation. * All rights reserved. * @@ -152,13 +152,13 @@ valsort_cf_func(ConfigArgs *c) { vitmp.vi_ad = NULL; i = slap_str2ad( c->argv[1], &vitmp.vi_ad, &text ); if ( i ) { - sprintf( c->cr_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->cr_msg, c->argv[1] ); return(1); } if ( is_at_single_value( vitmp.vi_ad->ad_type )) { - sprintf( c->cr_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->cr_msg, c->argv[1] ); @@ -170,14 +170,14 @@ 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->cr_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->cr_msg, c->argv[2] ); return(1); } i = verb_to_mask( c->argv[3], sorts ); if ( BER_BVISNULL( &sorts[i].word )) { - sprintf( c->cr_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->cr_msg, c->argv[3] ); return(1); @@ -186,7 +186,7 @@ valsort_cf_func(ConfigArgs *c) { 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->cr_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->cr_msg, c->argv[4] ); return(1); @@ -194,7 +194,7 @@ valsort_cf_func(ConfigArgs *c) { vitmp.vi_sort |= sorts[i].mask; } if (( vitmp.vi_sort & VALSORT_NUMERIC ) && !is_numeric ) { - sprintf( c->cr_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->cr_msg, c->argv[1] ); @@ -297,16 +297,11 @@ valsort_response( Operation *op, SlapReply *rs ) a = attr_find( rs->sr_entry->e_attrs, vi->vi_ad ); if ( !a ) continue; - if (( rs->sr_flags & ( REP_ENTRY_MODIFIABLE|REP_ENTRY_MUSTBEFREED )) != - ( REP_ENTRY_MODIFIABLE|REP_ENTRY_MUSTBEFREED )) { - rs->sr_entry = entry_dup( rs->sr_entry ); - rs->sr_flags |= REP_ENTRY_MODIFIABLE|REP_ENTRY_MUSTBEFREED; + if ( rs_entry2modifiable( op, rs, on )) { 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 ); @@ -495,6 +490,10 @@ valsort_destroy( slap_overinst *on = (slap_overinst *)be->bd_info; valsort_info *vi = on->on_bi.bi_private, *next; +#ifdef SLAP_CONFIG_DELETE + overlay_unregister_control( be, LDAP_CONTROL_VALSORT ); +#endif /* SLAP_CONFIG_DELETE */ + for (; vi; vi = next) { next = vi->vi_next; ch_free( vi->vi_dn.bv_val ); @@ -560,7 +559,7 @@ int valsort_initialize( void ) SLAP_CTRL_SEARCH | SLAP_CTRL_HIDE, NULL, valsort_parseCtrl, &valsort_cid ); if ( rc != LDAP_SUCCESS ) { - fprintf( stderr, "Failed to register control %d\n", rc ); + Debug( LDAP_DEBUG_ANY, "Failed to register control %d\n", rc, 0, 0 ); return rc; }