Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/wldap32/page.c | 64 ++++++++++++++++++++++++++++++- dlls/wldap32/winldap_private.h | 11 +++++- dlls/wldap32/wldap32.h | 70 +++++++++++++++++++++++++++++++++- 3 files changed, 140 insertions(+), 5 deletions(-)
diff --git a/dlls/wldap32/page.c b/dlls/wldap32/page.c index 7cf7d93245..d2d86e34af 100644 --- a/dlls/wldap32/page.c +++ b/dlls/wldap32/page.c @@ -281,7 +281,67 @@ PLDAPSearch CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, PWCHAR dn, ULONG sco PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys ) { - FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), - scope, debugstr_w(filter), attrs, attrsonly ); +#ifdef HAVE_LDAP + LDAPSearch *search; + DWORD i, len; + + TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n", + ld, debugstr_w(dn), scope, debugstr_w(filter), attrs, attrsonly, + serverctrls, clientctrls, timelimit, sizelimit, sortkeys ); + + search = heap_alloc_zero( sizeof(*search) ); + if (!search) + { + ld->ld_errno = WLDAP32_LDAP_NO_MEMORY; + return NULL; + } + + if (dn) + { + search->dn = strdupW( dn ); + if (!search->dn) goto fail; + } + if (filter) + { + search->filter = strdupW( filter ); + if (!search->filter) goto fail; + } + if (attrs) + { + search->attrs = strarraydupW( attrs ); + if (!search->attrs) goto fail; + } + + len = serverctrls ? controlarraylenW( serverctrls ) : 0; + search->serverctrls = heap_alloc( sizeof(LDAPControl *) * (len + 2) ); + if (!search->serverctrls) goto fail; + search->serverctrls[0] = NULL; /* reserve 0 for page control */ + for (i = 0; i < len; i++) + { + search->serverctrls[i + 1] = controldupW( serverctrls[i] ); + if (!search->serverctrls[i + 1]) goto fail; + } + search->serverctrls[len + 1] = NULL; + + if (clientctrls) + { + search->clientctrls = controlarraydupW( clientctrls ); + if (!search->clientctrls) goto fail; + } + + search->scope = scope; + search->attrsonly = attrsonly; + search->timeout.tv_sec = timelimit; + search->timeout.tv_usec = 0; + search->sizelimit = sizelimit; + search->cookie = NULL; + + return search; + +fail: + ldap_search_abandon_page( ld, search ); + ld->ld_errno = WLDAP32_LDAP_NO_MEMORY; + +#endif return NULL; } diff --git a/dlls/wldap32/winldap_private.h b/dlls/wldap32/winldap_private.h index 30c12a909c..6903505096 100644 --- a/dlls/wldap32/winldap_private.h +++ b/dlls/wldap32/winldap_private.h @@ -234,7 +234,16 @@ typedef struct WLDAP32_ldapvlvinfo VOID *ldvlv_extradata; } WLDAP32_LDAPVLVInfo, *WLDAP32_PLDAPVLVInfo;
-typedef struct ldapsearch LDAPSearch, *PLDAPSearch; +typedef struct ldapsearch +{ + WCHAR *dn, *filter, **attrs; + ULONG scope, attrsonly; + LDAPControlW **serverctrls; + LDAPControlW **clientctrls; + struct l_timeval timeout; + ULONG sizelimit; + struct berval *cookie; +} LDAPSearch, *PLDAPSearch;
typedef struct ldapsortkeyA { diff --git a/dlls/wldap32/wldap32.h b/dlls/wldap32/wldap32.h index c329a5b76b..537de67a87 100644 --- a/dlls/wldap32/wldap32.h +++ b/dlls/wldap32/wldap32.h @@ -241,6 +241,26 @@ static inline LPWSTR *strarrayUtoW( char **strarray ) return strarrayW; }
+static inline LPWSTR *strarraydupW( LPWSTR *strarray ) +{ + LPWSTR *strarrayW = NULL; + DWORD size; + + if (strarray) + { + size = sizeof(WCHAR*) * (strarraylenW( strarray ) + 1); + if ((strarrayW = heap_alloc( size ))) + { + LPWSTR *p = strarray; + LPWSTR *q = strarrayW; + + while (*p) *q++ = strdupW( *p++ ); + *q = NULL; + } + } + return strarrayW; +} + static inline void strarrayfreeA( LPSTR *strarray ) { if (strarray) @@ -546,8 +566,34 @@ static inline LDAPControlW *controlUtoW( LDAPControl *control ) }
controlW->ldctl_oid = strUtoW( control->ldctl_oid ); - controlW->ldctl_value.bv_len = len; - controlW->ldctl_value.bv_val = val; + controlW->ldctl_value.bv_len = len; + controlW->ldctl_value.bv_val = val; + controlW->ldctl_iscritical = control->ldctl_iscritical; + + return controlW; +} + +static inline LDAPControlW *controldupW( LDAPControlW *control ) +{ + LDAPControlW *controlW; + DWORD len = control->ldctl_value.bv_len; + char *val = NULL; + + if (control->ldctl_value.bv_val) + { + if (!(val = heap_alloc( len ))) return NULL; + memcpy( val, control->ldctl_value.bv_val, len ); + } + + if (!(controlW = heap_alloc( sizeof(LDAPControlW) ))) + { + heap_free( val ); + return NULL; + } + + controlW->ldctl_oid = strdupW( control->ldctl_oid ); + controlW->ldctl_value.bv_len = len; + controlW->ldctl_value.bv_val = val; controlW->ldctl_iscritical = control->ldctl_iscritical;
return controlW; @@ -684,6 +730,26 @@ static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray ) return controlarrayW; }
+static inline LDAPControlW **controlarraydupW( LDAPControlW **controlarray ) +{ + LDAPControlW **controlarrayW = NULL; + DWORD size; + + if (controlarray) + { + size = sizeof(LDAPControlW*) * (controlarraylenW( controlarray ) + 1); + if ((controlarrayW = heap_alloc( size ))) + { + LDAPControlW **p = controlarray; + LDAPControlW **q = controlarrayW; + + while (*p) *q++ = controldupW( *p++ ); + *q = NULL; + } + } + return controlarrayW; +} + static inline void controlarrayfreeA( LDAPControlA **controlarray ) { if (controlarray)