From: Kurt Zeilenga Date: Thu, 13 Oct 2005 06:35:28 +0000 (+0000) Subject: Add ldap_bv2escaped_filter_value (ITS#2535) X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~279 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a534d5fb6b33ae53758d1681d31a3b792cb243a7;p=openldap Add ldap_bv2escaped_filter_value (ITS#2535) --- diff --git a/include/ldap.h b/include/ldap.h index 67c9a7bcea..1a01f462fd 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -1665,6 +1665,11 @@ ldap_msgdelete LDAP_P(( * in search.c: */ LDAP_F( int ) +ldap_bv2escaped_filter_value LDAP_P(( + struct berval *in, + struct berval *out )); + +LDAP_F( int ) ldap_search_ext LDAP_P(( LDAP *ld, LDAP_CONST char *base, diff --git a/libraries/libldap/search.c b/libraries/libldap/search.c index a2d97a3e01..83202ace80 100644 --- a/libraries/libldap/search.c +++ b/libraries/libldap/search.c @@ -365,3 +365,53 @@ ldap_search_s( return( ldap_result2error( ld, *res, 0 ) ); } +int +ldap_bv2escaped_filter_value( struct berval *in, struct berval *out ) +{ + char c; + ber_len_t i; + static char escape[128] = { + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1 + }; + + out->bv_len = 0; + out->bv_val = NULL; + + if( in->bv_len == 0 ) return 0; + + /* assume we'll escape everything */ + out->bv_val = LDAP_MALLOC( 3 * in->bv_len + 1 ); + if( out->bv_val == NULL ) return -1; + + for( i=0; ibv_len; i++ ) { + if (c & 0x80 || escape[in->bv_val[i]]) { + out->bv_val[out->bv_len++] = '\\'; + out->bv_val[out->bv_len++] = "0123456789ABCDEF"[0x0f & (c>>4)]; + out->bv_val[out->bv_len++] = "0123456789ABCDEF"[0x0f & c]; + } else { + out->bv_val[out->bv_len++] = c; + } + } + + out->bv_val[out->bv_len] = '\0'; + return 0; +} +