2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
29 #include "winldap_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
33 /***********************************************************************
34 * ldap_searchA (WLDAP32.@)
36 ULONG CDECL
ldap_searchA( LDAP
*ld
, char *base
, ULONG scope
, char *filter
, char **attrs
, ULONG attrsonly
)
38 ULONG ret
= WLDAP32_LDAP_NO_MEMORY
;
39 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
41 TRACE( "(%p, %s, %#lx, %s, %p, %#lx)\n", ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
, attrsonly
);
45 if (base
&& !(baseW
= strAtoW( base
))) goto exit
;
46 if (filter
&& !(filterW
= strAtoW( filter
))) goto exit
;
47 if (attrs
&& !(attrsW
= strarrayAtoW( attrs
))) goto exit
;
49 ret
= ldap_searchW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
);
54 strarrayfreeW( attrsW
);
58 /***********************************************************************
59 * ldap_searchW (WLDAP32.@)
61 ULONG CDECL
ldap_searchW( LDAP
*ld
, WCHAR
*base
, ULONG scope
, WCHAR
*filter
, WCHAR
**attrs
, ULONG attrsonly
)
64 TRACE( "(%p, %s, %#lx, %s, %p, %#lx)\n", ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
, attrsonly
);
66 ret
= ldap_search_extW( ld
, base
, scope
, filter
, attrs
, attrsonly
, NULL
, NULL
, 0, 0, &msg
);
67 if (ret
== WLDAP32_LDAP_SUCCESS
) return msg
;
71 /***********************************************************************
72 * ldap_search_extA (WLDAP32.@)
74 ULONG CDECL
ldap_search_extA( LDAP
*ld
, char *base
, ULONG scope
, char *filter
, char **attrs
, ULONG attrsonly
,
75 LDAPControlA
**serverctrls
, LDAPControlA
**clientctrls
, ULONG timelimit
,
76 ULONG sizelimit
, ULONG
*message
)
78 ULONG ret
= WLDAP32_LDAP_NO_MEMORY
;
79 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
80 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
82 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p, %#lx, %#lx, %p)\n", ld
, debugstr_a(base
), scope
,
83 debugstr_a(filter
), attrs
, attrsonly
, serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
85 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
87 if (base
&& !(baseW
= strAtoW( base
))) goto exit
;
88 if (filter
&& !(filterW
= strAtoW( filter
))) goto exit
;
89 if (attrs
&& !(attrsW
= strarrayAtoW( attrs
))) goto exit
;
90 if (serverctrls
&& !(serverctrlsW
= controlarrayAtoW( serverctrls
))) goto exit
;
91 if (clientctrls
&& !(clientctrlsW
= controlarrayAtoW( clientctrls
))) goto exit
;
93 ret
= ldap_search_extW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, serverctrlsW
, clientctrlsW
, timelimit
,
99 strarrayfreeW( attrsW
);
100 controlarrayfreeW( serverctrlsW
);
101 controlarrayfreeW( clientctrlsW
);
105 /***********************************************************************
106 * ldap_search_extW (WLDAP32.@)
108 ULONG CDECL
ldap_search_extW( LDAP
*ld
, WCHAR
*base
, ULONG scope
, WCHAR
*filter
, WCHAR
**attrs
, ULONG attrsonly
,
109 LDAPControlW
**serverctrls
, LDAPControlW
**clientctrls
, ULONG timelimit
,
110 ULONG sizelimit
, ULONG
*message
)
113 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
114 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
115 struct l_timeval timevalW
= { timelimit
, 0 };
116 struct timeval timevalU
= { timelimit
, 0 };
118 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p, %#lx, %#lx, %p)\n", ld
, debugstr_w(base
), scope
,
119 debugstr_w(filter
), attrs
, attrsonly
, serverctrls
, clientctrls
, timelimit
, sizelimit
, message
);
121 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
122 if ((ret
= WLDAP32_ldap_connect( ld
, &timevalW
))) return ret
;
124 ret
= WLDAP32_LDAP_NO_MEMORY
;
125 if (base
&& !(baseU
= strWtoU( base
))) goto exit
;
126 if (filter
&& !(filterU
= strWtoU( filter
))) goto exit
;
127 if (attrs
&& !(attrsU
= strarrayWtoU( attrs
))) goto exit
;
128 if (serverctrls
&& !(serverctrlsU
= controlarrayWtoU( serverctrls
))) goto exit
;
129 if (clientctrls
&& !(clientctrlsU
= controlarrayWtoU( clientctrls
))) goto exit
;
131 ret
= map_error( ldap_search_ext( CTX(ld
), baseU
, scope
, filterU
, attrsU
, attrsonly
, serverctrlsU
,
132 clientctrlsU
, timelimit
? &timevalU
: NULL
, sizelimit
, (int *)message
) );
136 strarrayfreeU( attrsU
);
137 controlarrayfreeU( serverctrlsU
);
138 controlarrayfreeU( clientctrlsU
);
142 /***********************************************************************
143 * ldap_search_ext_sA (WLDAP32.@)
145 ULONG CDECL
ldap_search_ext_sA( LDAP
*ld
, char *base
, ULONG scope
, char *filter
, char **attrs
, ULONG attrsonly
,
146 LDAPControlA
**serverctrls
, LDAPControlA
**clientctrls
, struct l_timeval
*timeout
,
147 ULONG sizelimit
, WLDAP32_LDAPMessage
**res
)
149 ULONG ret
= WLDAP32_LDAP_NO_MEMORY
;
150 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
151 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
153 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p, %p, %#lx, %p)\n", ld
, debugstr_a(base
), scope
,
154 debugstr_a(filter
), attrs
, attrsonly
, serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
156 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
158 if (base
&& !(baseW
= strAtoW( base
))) goto exit
;
159 if (filter
&& !(filterW
= strAtoW( filter
))) goto exit
;
160 if (attrs
&& !(attrsW
= strarrayAtoW( attrs
))) goto exit
;
161 if (serverctrls
&& !(serverctrlsW
= controlarrayAtoW( serverctrls
))) goto exit
;
162 if (clientctrls
&& !(clientctrlsW
= controlarrayAtoW( clientctrls
))) goto exit
;
164 ret
= ldap_search_ext_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, serverctrlsW
, clientctrlsW
, timeout
,
170 strarrayfreeW( attrsW
);
171 controlarrayfreeW( serverctrlsW
);
172 controlarrayfreeW( clientctrlsW
);
176 /***********************************************************************
177 * ldap_search_ext_sW (WLDAP32.@)
179 ULONG CDECL
ldap_search_ext_sW( LDAP
*ld
, WCHAR
*base
, ULONG scope
, WCHAR
*filter
, WCHAR
**attrs
, ULONG attrsonly
,
180 LDAPControlW
**serverctrls
, LDAPControlW
**clientctrls
, struct l_timeval
*timeout
,
181 ULONG sizelimit
, LDAPMessage
**res
)
184 char *baseU
= NULL
, *filterU
= NULL
, **attrsU
= NULL
;
185 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
186 struct timeval timevalU
;
187 LDAPMessage
*msgU
= NULL
;
189 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p, %p, %#lx, %p)\n", ld
, debugstr_w(base
), scope
,
190 debugstr_w(filter
), attrs
, attrsonly
, serverctrls
, clientctrls
, timeout
, sizelimit
, res
);
192 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
193 if ((ret
= WLDAP32_ldap_connect( ld
, timeout
))) return ret
;
195 ret
= WLDAP32_LDAP_NO_MEMORY
;
196 if (base
&& !(baseU
= strWtoU( base
))) goto exit
;
197 if (filter
&& !(filterU
= strWtoU( filter
))) goto exit
;
198 if (attrs
&& !(attrsU
= strarrayWtoU( attrs
))) goto exit
;
199 if (serverctrls
&& !(serverctrlsU
= controlarrayWtoU( serverctrls
))) goto exit
;
200 if (clientctrls
&& !(clientctrlsU
= controlarrayWtoU( clientctrls
))) goto exit
;
204 timevalU
.tv_sec
= timeout
->tv_sec
;
205 timevalU
.tv_usec
= timeout
->tv_usec
;
208 ret
= map_error( ldap_search_ext_s( CTX(ld
), baseU
, scope
, filterU
, attrsU
, attrsonly
, serverctrlsU
,
209 clientctrlsU
, timeout
? &timevalU
: NULL
, sizelimit
, &msgU
) );
213 LDAPMessage
*msg
= calloc( 1, sizeof(*msg
) );
221 ldap_msgfree( msgU
);
222 ret
= WLDAP32_LDAP_NO_MEMORY
;
229 strarrayfreeU( attrsU
);
230 controlarrayfreeU( serverctrlsU
);
231 controlarrayfreeU( clientctrlsU
);
235 /***********************************************************************
236 * ldap_search_sA (WLDAP32.@)
238 ULONG CDECL
ldap_search_sA( LDAP
*ld
, char *base
, ULONG scope
, char *filter
, char **attrs
, ULONG attrsonly
,
239 WLDAP32_LDAPMessage
**res
)
241 ULONG ret
= WLDAP32_LDAP_NO_MEMORY
;
242 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
244 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p)\n", ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
,
247 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
249 if (base
&& !(baseW
= strAtoW( base
))) goto exit
;
250 if (filter
&& !(filterW
= strAtoW( filter
))) goto exit
;
251 if (attrs
&& !(attrsW
= strarrayAtoW( attrs
))) goto exit
;
253 ret
= ldap_search_sW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, res
);
258 strarrayfreeW( attrsW
);
262 /***********************************************************************
263 * ldap_search_sW (WLDAP32.@)
265 ULONG CDECL
ldap_search_sW( LDAP
*ld
, WCHAR
*base
, ULONG scope
, WCHAR
*filter
, WCHAR
**attrs
, ULONG attrsonly
,
266 WLDAP32_LDAPMessage
**res
)
268 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p)\n", ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
270 return ldap_search_ext_sW( ld
, base
, scope
, filter
, attrs
, attrsonly
, NULL
, NULL
, NULL
, 0, res
);
273 /***********************************************************************
274 * ldap_search_stA (WLDAP32.@)
276 ULONG CDECL
ldap_search_stA( LDAP
*ld
, const PCHAR base
, ULONG scope
, const PCHAR filter
, char **attrs
,
277 ULONG attrsonly
, struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
279 ULONG ret
= WLDAP32_LDAP_NO_MEMORY
;
280 WCHAR
*baseW
= NULL
, *filterW
= NULL
, **attrsW
= NULL
;
282 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p)\n", ld
, debugstr_a(base
), scope
, debugstr_a(filter
), attrs
,
283 attrsonly
, timeout
, res
);
285 if (!ld
|| !res
) return WLDAP32_LDAP_PARAM_ERROR
;
287 if (base
&& !(baseW
= strAtoW( base
))) goto exit
;
288 if (filter
&& !(filterW
= strAtoW( filter
))) goto exit
;
289 if (attrs
&& !(attrsW
= strarrayAtoW( attrs
))) goto exit
;
291 ret
= ldap_search_stW( ld
, baseW
, scope
, filterW
, attrsW
, attrsonly
, timeout
, res
);
296 strarrayfreeW( attrsW
);
300 /***********************************************************************
301 * ldap_search_stW (WLDAP32.@)
303 ULONG CDECL
ldap_search_stW( LDAP
*ld
, const PWCHAR base
, ULONG scope
, const PWCHAR filter
, WCHAR
**attrs
,
304 ULONG attrsonly
, struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
306 TRACE( "(%p, %s, %#lx, %s, %p, %#lx, %p, %p)\n", ld
, debugstr_w(base
), scope
, debugstr_w(filter
), attrs
,
307 attrsonly
, timeout
, res
);
308 return ldap_search_ext_sW( ld
, base
, scope
, filter
, attrs
, attrsonly
, NULL
, NULL
, timeout
, 0, res
);