From 7f0289a390b451819fedac9908d0b0caea7e648a Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 16 Jan 2002 18:16:15 +0000 Subject: [PATCH] Move most of the new ber_*cmp routines to lber_pvt.h to keep them private, rework them slightly to avoid computations which might result in underflow. Rename them for consistency with other berval routines. Remove some utf8 lint. --- include/lber.h | 21 ++++----------------- include/lber_pvt.h | 19 +++++++++++++++++++ libraries/libldap/utf-8.c | 13 ++++++++----- servers/slapd/acl.c | 10 +++++----- servers/slapd/proto-slap.h | 2 +- servers/slapd/slap.h | 2 +- 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/include/lber.h b/include/lber.h index 80da3f19d3..c031ec1d96 100644 --- a/include/lber.h +++ b/include/lber.h @@ -580,23 +580,10 @@ ber_bvarray_free LDAP_P(( BerVarray p )); LBER_F( int ) ber_bvarray_add LDAP_P(( BerVarray *p, BerValue *bv )); -#define ber_memcmp(v1,v2) \ - ((v1)->bv_len == (v2)->bv_len ? \ - memcmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) : \ - (v1)->bv_len - (v2)->bv_len ) - -#define ber_cmp(v1,v2) \ - ((v1)->bv_len == (v2)->bv_len ? \ - strcmp((v1)->bv_val, (v2)->bv_val) : \ - (v1)->bv_len - (v2)->bv_len ) - -#define ber_casecmp(v1,v2) \ - ((v1)->bv_len == (v2)->bv_len ? \ - strcasecmp((v1)->bv_val, (v2)->bv_val) : \ - (v1)->bv_len - (v2)->bv_len ) - -#define ber_charcmp(v1,c) \ - ((v1)->bv_len == 1 ? (v1)->bv_val[0] == c : 0) +#define ber_bvcmp(v1,v2) \ + ((v1)->bv_len < (v2)->bv_len \ + ? -1 : ((v1)->bv_len > (v2)->bv_len \ + ? 1 : memcmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) )) /* * error.c diff --git a/include/lber_pvt.h b/include/lber_pvt.h index b2303eb331..836b1be4f1 100644 --- a/include/lber_pvt.h +++ b/include/lber_pvt.h @@ -61,6 +61,25 @@ ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len )); LBER_F( int ) ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb )); + +#if 0 +#define ber_bvstrcmp(v1,v2) \ + ((v1)->bv_len < (v2)->bv_len \ + ? -1 : ((v1)->bv_len > (v2)->bv_len \ + ? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) )) +#else + /* avoid strncmp() */ +#define ber_bvstrcmp(v1,v2) ber_bvcmp((v1),(v2)) +#endif + +#define ber_bvstrcasecmp(v1,v2) \ + ((v1)->bv_len < (v2)->bv_len \ + ? -1 : ((v1)->bv_len > (v2)->bv_len \ + ? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) )) + +#define ber_bvccmp(v1,c) \ + ((v1)->bv_len == 1 ? (v1)->bv_val[0] == c : 0) + LDAP_END_DECL #endif diff --git a/libraries/libldap/utf-8.c b/libraries/libldap/utf-8.c index 6f281f3039..9000e0a19b 100644 --- a/libraries/libldap/utf-8.c +++ b/libraries/libldap/utf-8.c @@ -112,11 +112,14 @@ int ldap_utf8_charlen( const char * p ) */ /* mask of required bits in second octet */ -const char ldap_utf8_mintab[] = { - 0x20, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x30, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x38, 0x80, 0x80, 0x80, 0x3c, 0x80, 0x00, 0x00 }; +#undef c +#define c const char +c ldap_utf8_mintab[] = { + (c)0x20, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, + (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, + (c)0x30, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, (c)0x80, + (c)0x38, (c)0x80, (c)0x80, (c)0x80, (c)0x3c, (c)0x80, (c)0x00, (c)0x00 }; +#undef c int ldap_utf8_charlen2( const char * p ) { diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index 3ea0297873..48aacbb501 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -15,6 +15,7 @@ #include "slap.h" #include "sets.h" +#include "lber_pvt.h" /* @@ -531,17 +532,17 @@ acl_mask( * user is bound as somebody in the same namespace as * the entry, OR the given dn matches the dn pattern */ - if ( ber_cmp( &b->a_dn_pat, &aci_bv_anonymous ) == 0 ) { + if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_anonymous ) == 0 ) { if ( op->o_ndn.bv_len != 0 ) { continue; } - } else if ( ber_cmp( &b->a_dn_pat, &aci_bv_users ) == 0 ) { + } else if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_users ) == 0 ) { if ( op->o_ndn.bv_len == 0 ) { continue; } - } else if ( ber_cmp( &b->a_dn_pat, &aci_bv_self ) == 0 ) { + } else if ( ber_bvcmp( &b->a_dn_pat, &aci_bv_self ) == 0 ) { if ( op->o_ndn.bv_len == 0 ) { continue; } @@ -552,7 +553,7 @@ acl_mask( } else if ( b->a_dn_style == ACL_STYLE_REGEX ) { if ( b->a_dn_pat.bv_len != 1 || - ber_charcmp( &b->a_dn_pat, '*' ) != 0 ) { + ber_bvccmp( &b->a_dn_pat, '*' ) != 0 ) { int ret = regex_matches( b->a_dn_pat.bv_val, op->o_ndn.bv_val, e->e_ndn, matches ); @@ -601,7 +602,6 @@ acl_mask( if ( strcmp( b->a_dn_pat.bv_val, op->o_ndn.bv_val + odnlen - patlen ) != 0 ) continue; - } } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index b9c7c645bf..346f3c3a86 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -346,7 +346,7 @@ LDAP_SLAPD_F (void) slapd_clr_read LDAP_P((ber_socket_t s, int wake)); * dn.c */ -#define dn_match(dn1, dn2) ( ber_cmp((dn1), (dn2)) == 0 ) +#define dn_match(dn1, dn2) ( ber_bvcmp((dn1), (dn2)) == 0 ) LDAP_SLAPD_F (int) dnValidate LDAP_P(( Syntax *syntax, diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 06decced85..f493fcd665 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -175,7 +175,7 @@ typedef struct slap_ssf_set { #define SLAP_INDEX_DEFAULT SLAP_INDEX_EQUALITY -#define IS_SLAP_INDEX(mask, type) (((mask) & (type)) == (type) ) +#define IS_SLAP_INDEX(mask, type) (((mask) & (type)) == (type)) #define SLAP_INDEX_SUBSTR_TYPE 0x0F00UL -- 2.39.5