From 6b63e25bc202b095e0ad525440819a7c92a0b72a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 24 Aug 2005 01:52:05 +0000 Subject: [PATCH] Check for numeric syntaxes --- servers/slapd/overlays/valsort.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/servers/slapd/overlays/valsort.c b/servers/slapd/overlays/valsort.c index 68ad11035f..268d35e5b6 100644 --- a/servers/slapd/overlays/valsort.c +++ b/servers/slapd/overlays/valsort.c @@ -81,12 +81,14 @@ static slap_verbmasks sorts[] = { { BER_BVNULL, 0 } }; +static Syntax *syn_numericString; + static int valsort_cf_func(ConfigArgs *c) { slap_overinst *on = (slap_overinst *)c->bi; valsort_info vitmp, *vi; const char *text = NULL; - int i; + int i, is_numeric; struct berval bv = BER_BVNULL; if ( c->op == SLAP_CONFIG_EMIT ) { @@ -159,6 +161,9 @@ valsort_cf_func(ConfigArgs *c) { c->log, c->msg, c->argv[1] ); return(0); } + is_numeric = ( vitmp.vi_ad->ad_type->sat_syntax == syn_numericString || + vitmp.vi_ad->ad_type->sat_syntax == slap_schema.si_syn_integer ) ? 1 + : 0; ber_str2bv( c->argv[2], 0, 0, &bv ); i = dnNormalize( 0, NULL, NULL, &bv, &vitmp.vi_dn, NULL ); if ( i ) { @@ -185,6 +190,13 @@ valsort_cf_func(ConfigArgs *c) { } 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", + c->argv[0] ); + Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n", + c->log, c->msg, c->argv[1] ); + return(1); + } vi = ch_malloc( sizeof(valsort_info) ); *vi = vitmp; vi->vi_next = on->on_bi.bi_private; @@ -485,6 +497,8 @@ int valsort_init() valsort.on_bi.bi_cf_ocs = valsort_cfocs; + syn_numericString = syn_find( "1.3.6.1.4.1.1466.115.121.1.36" ); + rc = config_register_schema( valsort_cfats, valsort_cfocs ); if ( rc ) return rc; -- 2.39.5