diff --git a/dlls/wldap32/misc.c b/dlls/wldap32/misc.c index 785887f5c69..f69832a51d5 100644 --- a/dlls/wldap32/misc.c +++ b/dlls/wldap32/misc.c @@ -24,6 +24,7 @@ #include "wine/debug.h" #include +#include #include "windef.h" #include "winbase.h" @@ -125,6 +126,77 @@ ULONG WLDAP32_ldap_count_references( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res return ret; } +static ULONG get_escape_size( PCHAR src, ULONG srclen ) +{ + ULONG i, size = 0; + + if (src) + { + for (i = 0; i < srclen; i++) + { + if ((src[i] >= '0' && src[i] <= '9') || + (src[i] >= 'A' && src[i] <= 'Z') || + (src[i] >= 'a' && src[i] <= 'z')) + size++; + else + size += 3; + } + } + return size + 1; +} + +static void escape_filter_element( PCHAR src, ULONG srclen, PCHAR dst ) +{ + ULONG i; + char fmt[] = "\\%02X"; + char *d = dst; + + for (i = 0; i < srclen; i++) + { + if ((src[i] >= '0' && src[i] <= '9') || + (src[i] >= 'A' && src[i] <= 'Z') || + (src[i] >= 'a' && src[i] <= 'z')) + *d++ = src[i]; + else + { + sprintf( d, fmt, (unsigned char)src[i] ); + d += 3; + } + } + *++d = 0; +} + +ULONG ldap_escape_filter_elementA( PCHAR src, ULONG srclen, PCHAR dst, ULONG dstlen ) +{ + ULONG len; + + TRACE( "(%p, 0x%08lx, %p, 0x%08lx)\n", src, srclen, dst, dstlen ); + + len = get_escape_size( src, srclen ); + if (!dst) return len; + + if (!src || dstlen < len) + return WLDAP32_LDAP_PARAM_ERROR; + else + { + escape_filter_element( src, srclen, dst ); + return LDAP_SUCCESS; + } +} + +ULONG ldap_escape_filter_elementW( PCHAR src, ULONG srclen, PWCHAR dst, ULONG dstlen ) +{ + ULONG len; + + TRACE( "(%p, 0x%08lx, %p, 0x%08lx)\n", src, srclen, dst, dstlen ); + + len = get_escape_size( src, srclen ); + if (!dst) return len; + + /* no matter what you throw at it, this is what native returns */ + return WLDAP32_LDAP_PARAM_ERROR; +} + PCHAR ldap_first_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, WLDAP32_BerElement** ptr ) { diff --git a/dlls/wldap32/winldap_private.h b/dlls/wldap32/winldap_private.h index c6ae029570f..02c9247ec1e 100644 --- a/dlls/wldap32/winldap_private.h +++ b/dlls/wldap32/winldap_private.h @@ -283,6 +283,8 @@ PCHAR ldap_dn2ufnA(PCHAR); PWCHAR ldap_dn2ufnW(PWCHAR); PCHAR ldap_err2stringA(ULONG); PWCHAR ldap_err2stringW(ULONG); +ULONG ldap_escape_filter_elementA(PCHAR,ULONG,PCHAR,ULONG); +ULONG ldap_escape_filter_elementW(PCHAR,ULONG,PWCHAR,ULONG); PCHAR *ldap_explode_dnA(PCHAR,ULONG); PWCHAR *ldap_explode_dnW(PWCHAR,ULONG); ULONG ldap_extended_operationA(WLDAP32_LDAP*,PCHAR,struct WLDAP32_berval*,PLDAPControlA*,PLDAPControlA*,ULONG*); diff --git a/dlls/wldap32/wldap32.spec b/dlls/wldap32/wldap32.spec index 7022838dff5..0969ec94ab9 100644 --- a/dlls/wldap32/wldap32.spec +++ b/dlls/wldap32/wldap32.spec @@ -95,9 +95,9 @@ @ cdecl ldap_err2string(long) ldap_err2stringA @ cdecl ldap_err2stringA(long) @ cdecl ldap_err2stringW(long) -@ stub ldap_escape_filter_element -@ stub ldap_escape_filter_elementA -@ stub ldap_escape_filter_elementW +@ cdecl ldap_escape_filter_element(str long ptr long) ldap_escape_filter_elementA +@ cdecl ldap_escape_filter_elementA(str long ptr long) +@ cdecl ldap_escape_filter_elementW(wstr long ptr long) @ cdecl ldap_explode_dn(str long) ldap_explode_dnA @ cdecl ldap_explode_dnA(str long) @ cdecl ldap_explode_dnW(wstr long) diff --git a/include/winldap.h b/include/winldap.h index 2b981175014..6c1e15a613b 100644 --- a/include/winldap.h +++ b/include/winldap.h @@ -445,7 +445,7 @@ PCHAR ldap_err2stringA(ULONG); PWCHAR ldap_err2stringW(ULONG); #define ldap_err2string WINELIB_NAME_AW(ldap_err2string) ULONG ldap_escape_filter_elementA(PCHAR,ULONG,PCHAR,ULONG); -ULONG ldap_escape_filter_elementW(PWCHAR,ULONG,PWCHAR,ULONG); +ULONG ldap_escape_filter_elementW(PCHAR,ULONG,PWCHAR,ULONG); #define ldap_escape_filter_element WINELIB_NAME_AW(ldap_escape_filter_element) PCHAR *ldap_explode_dnA(PCHAR,ULONG); PWCHAR *ldap_explode_dnW(PWCHAR,ULONG);