2 * test parsing functions
4 * Copyright 2008 Hans Leidekker for CodeWeavers
5 * Copyright 2020 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
31 #ifndef LDAP_AUTH_SIMPLE
32 #define LDAP_AUTH_SIMPLE 0x80
35 #ifndef LDAP_OPT_SERVER_CONTROLS
36 #define LDAP_OPT_SERVER_CONTROLS 0x0012
39 static void test_ldap_parse_sort_control( LDAP
*ld
)
42 LDAPSortKeyA
*sortkeys
[2], key
;
43 LDAPControlA
*sort
, *ctrls
[2], **server_ctrls
;
44 LDAPMessage
*res
= NULL
;
45 struct l_timeval timeout
;
47 key
.sk_attrtype
= (char *)"ou";
48 key
.sk_matchruleoid
= NULL
;
49 key
.sk_reverseorder
= FALSE
;
53 ret
= ldap_create_sort_controlA( ld
, sortkeys
, 0, &sort
);
54 ok( !ret
, "ldap_create_sort_controlA failed %#lx\n", ret
);
60 ret
= ldap_search_ext_sA( ld
, (char *)"dc=debian,dc=org", LDAP_SCOPE_ONELEVEL
, (char *)"(uid=*)", NULL
, 0,
61 ctrls
, NULL
, &timeout
, 10, &res
);
62 if (ret
== LDAP_SERVER_DOWN
|| ret
== LDAP_TIMEOUT
)
64 skip("test server can't be reached\n");
65 ldap_control_freeA( sort
);
68 ok( !ret
, "ldap_search_ext_sA failed %#lx\n", ret
);
69 ok( res
!= NULL
, "expected res != NULL\n" );
71 ret
= ldap_parse_resultA( NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &server_ctrls
, 0 );
72 ok( ret
== LDAP_PARAM_ERROR
, "ldap_parse_resultA should fail, got %#lx\n", ret
);
73 ret
= ldap_parse_resultA( NULL
, res
, NULL
, NULL
, NULL
, NULL
, &server_ctrls
, 0 );
74 ok( ret
== LDAP_PARAM_ERROR
, "ldap_parse_resultA should fail, got %#lx\n", ret
);
75 ret
= ldap_parse_resultA( ld
, NULL
, NULL
, NULL
, NULL
, NULL
, &server_ctrls
, 0 );
76 ok( ret
== LDAP_NO_RESULTS_RETURNED
, "ldap_parse_resultA should fail, got %#lx\n", ret
);
78 ret
= ldap_parse_resultA( ld
, res
, &result
, NULL
, NULL
, NULL
, &server_ctrls
, 1 );
79 ok( !ret
, "ldap_parse_resultA failed %#lx\n", ret
);
80 ok( !result
, "got %#lx expected 0\n", result
);
82 ret
= ldap_parse_sort_controlA( NULL
, NULL
, NULL
, NULL
);
83 ok( ret
== LDAP_PARAM_ERROR
, "ldap_parse_sort_controlA failed %#lx\n", ret
);
85 ret
= ldap_parse_sort_controlA( ld
, NULL
, NULL
, NULL
);
86 ok( ret
== LDAP_CONTROL_NOT_FOUND
, "ldap_parse_sort_controlA failed %#lx\n", ret
);
88 ret
= ldap_parse_sort_controlA( ld
, NULL
, &result
, NULL
);
89 ok( ret
== LDAP_CONTROL_NOT_FOUND
, "ldap_parse_sort_controlA failed %#lx\n", ret
);
91 ret
= ldap_parse_sort_controlA( ld
, server_ctrls
, &result
, NULL
);
92 ok( ret
== LDAP_CONTROL_NOT_FOUND
, "ldap_parse_sort_controlA failed %#lx\n", ret
);
94 ldap_control_freeA( sort
);
95 ldap_controls_freeA( server_ctrls
);
98 static void test_ldap_search_extW( LDAP
*ld
)
100 ULONG ret
, message
, timelimit
;
101 WCHAR base
[] = L
"", filter
[] = L
"ou=*";
104 ret
= ldap_search_extW( ld
, base
, LDAP_SCOPE_SUBTREE
, filter
, NULL
, 0, NULL
, NULL
, timelimit
, 0, &message
);
105 if (ret
== LDAP_SERVER_DOWN
|| ret
== LDAP_UNAVAILABLE
)
107 skip("test server can't be reached\n");
110 ok( !ret
, "ldap_search_extW failed %#lx\n", ret
);
113 ret
= ldap_search_extW( ld
, base
, LDAP_SCOPE_SUBTREE
, filter
, NULL
, 0, NULL
, NULL
, timelimit
, 0, &message
);
114 ok( !ret
, "ldap_search_extW failed %#lx\n", ret
);
117 static void test_opt_referrals( LDAP
*ld
)
122 ret
= ldap_get_optionW( ld
, LDAP_OPT_REFERRALS
, &value
);
123 ok( !ret
, "ldap_get_optionW failed %#lx\n", ret
);
124 todo_wine
ok( value
== 1, "got %lu\n", value
);
127 ret
= ldap_set_optionW( ld
, LDAP_OPT_REFERRALS
, (void *)&value
);
128 ok( !ret
, "ldap_set_optionW failed %#lx\n", ret
);
131 ret
= ldap_get_optionW( ld
, LDAP_OPT_REFERRALS
, &value
);
132 ok( !ret
, "ldap_get_optionW failed %#lx\n", ret
);
133 ok( !value
, "got %lu\n", value
);
135 ret
= ldap_set_optionW( ld
, LDAP_OPT_REFERRALS
, LDAP_OPT_ON
);
136 ok( !ret
, "ldap_set_optionW failed %#lx\n", ret
);
139 ret
= ldap_get_optionW( ld
, LDAP_OPT_REFERRALS
, &value
);
140 ok( !ret
, "ldap_get_optionW failed %#lx\n", ret
);
141 todo_wine
ok( value
== 1, "got %lu\n", value
);
144 static void test_opt_protocol_version( LDAP
*ld
)
148 ret
= ldap_get_optionW( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
149 ok( !ret
, "ldap_get_optionW failed %#lx\n", ret
);
150 ok( version
== LDAP_VERSION3
, "got %lu\n", version
);
153 static void test_ldap_bind_sA( void )
159 ld
= ldap_sslinitA( (char *)"db.debian.org", 636, 1 );
160 ok( ld
!= NULL
, "ldap_sslinit failed\n" );
162 version
= LDAP_VERSION3
;
163 ret
= ldap_set_optionW( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
164 if (ret
== LDAP_SERVER_DOWN
|| ret
== LDAP_UNAVAILABLE
)
166 skip( "test server can't be reached\n" );
171 ret
= ldap_connect( ld
, NULL
);
172 ok( !ret
, "ldap_connect failed %#lx\n", ret
);
174 ret
= ldap_bind_sA( ld
, (char *)"uid=winetest,ou=users,dc=debian,dc=org", (char *)"winetest",
176 ok( ret
== LDAP_INVALID_CREDENTIALS
, "ldap_bind_s returned %#lx\n", ret
);
179 ld
= ldap_sslinitA( (char *)"db.debian.org", 389, 0 );
180 ok( ld
!= NULL
, "ldap_sslinit failed\n" );
182 ret
= ldap_connect( ld
, NULL
);
183 ok( !ret
, "ldap_connect failed %#lx\n", ret
);
187 static void test_ldap_add( LDAP
*ld
)
189 char *one_empty_string
[] = { (char *)"", NULL
};
190 LDAPModA empty_equals_empty
= { 0, (char *)"", { one_empty_string
} };
191 LDAPModA
*attrs
[] = { &empty_equals_empty
, NULL
};
194 ret
= ldap_addA( NULL
, NULL
, NULL
);
195 ok( ret
== (ULONG
)-1, "ldap_addA should fail, got %#lx\n", ret
);
196 ret
= ldap_addA( NULL
, (char *)"", attrs
);
197 ok( ret
== (ULONG
)-1, "ldap_addA should fail, got %#lx\n", ret
);
198 ret
= ldap_addA( ld
, NULL
, attrs
);
199 ok( ret
!= (ULONG
)-1, "ldap_addA should succeed, got %#lx\n", ret
);
200 ret
= ldap_addA( ld
, (char *)"", NULL
);
201 ok( ret
!= (ULONG
)-1, "ldap_addA should succeed, got %#lx\n", ret
);
202 ret
= ldap_addA( ld
, (char *)"", attrs
);
203 ok( ret
!= (ULONG
)-1, "ldap_addA should succeed, got %#lx\n", ret
);
205 ret
= ldap_add_sA( NULL
, NULL
, NULL
);
206 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_sA should fail, got %#lx\n", ret
);
207 ret
= ldap_add_sA( NULL
, (char *)"", attrs
);
208 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_sA should fail, got %#lx\n", ret
);
209 ret
= ldap_add_sA( ld
, NULL
, attrs
);
210 ok( ret
== LDAP_ALREADY_EXISTS
, "ldap_add_sA should fail, got %#lx\n", ret
);
211 ret
= ldap_add_sA( ld
, (char *)"", NULL
);
212 ok( ret
== LDAP_PROTOCOL_ERROR
, "ldap_add_sA should fail, got %#lx\n", ret
);
213 ret
= ldap_add_sA( ld
, (char *)"", attrs
);
214 ok( ret
== LDAP_ALREADY_EXISTS
, "ldap_add_sA should fail, got %#lx\n", ret
);
216 ret
= ldap_add_extA( NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
217 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_extA should fail, got %#lx\n", ret
);
218 ret
= ldap_add_extA( NULL
, (char *)"", attrs
, NULL
, NULL
, &num
);
219 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_extA should fail, got %#lx\n", ret
);
220 ret
= ldap_add_extA( ld
, NULL
, attrs
, NULL
, NULL
, &num
);
221 ok( !ret
, "ldap_add_extA should succeed, got %#lx\n", ret
);
222 ret
= ldap_add_extA( ld
, (char *)"", NULL
, NULL
, NULL
, &num
);
223 ok( !ret
, "ldap_add_extA should succeed, got %#lx\n", ret
);
224 ret
= ldap_add_extA( ld
, (char *)"", attrs
, NULL
, NULL
, NULL
);
225 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_extA should fail, got %#lx\n", ret
);
226 ret
= ldap_add_extA( ld
, (char *)"", attrs
, NULL
, NULL
, &num
);
227 ok( !ret
, "ldap_add_extA should succeed, got %#lx\n", ret
);
229 ret
= ldap_add_ext_sA( NULL
, NULL
, NULL
, NULL
, NULL
);
230 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_ext_sA should fail, got %#lx\n", ret
);
231 ret
= ldap_add_ext_sA( NULL
, (char *)"", attrs
, NULL
, NULL
);
232 ok( ret
== LDAP_PARAM_ERROR
, "ldap_add_ext_sA should fail, got %#lx\n", ret
);
233 ret
= ldap_add_ext_sA( ld
, NULL
, attrs
, NULL
, NULL
);
234 ok( ret
== LDAP_ALREADY_EXISTS
, "ldap_add_ext_sA should fail, got %#lx\n", ret
);
235 ret
= ldap_add_ext_sA( ld
, (char *)"", NULL
, NULL
, NULL
);
236 ok( ret
== LDAP_PROTOCOL_ERROR
, "ldap_add_ext_sA should fail, got %#lx\n", ret
);
237 ret
= ldap_add_ext_sA( ld
, (char *)"", attrs
, NULL
, NULL
);
238 ok( ret
== LDAP_ALREADY_EXISTS
, "ldap_add_ext_sA should fail, got %#lx\n", ret
);
241 static void test_ldap_modify( LDAP
*ld
)
243 char *one_empty_string
[] = { (char *)"", NULL
};
244 LDAPModA empty_equals_empty
= { 0, (char *)"", { one_empty_string
} };
245 LDAPModA
*attrs
[] = { &empty_equals_empty
, NULL
};
248 ret
= ldap_modifyA( NULL
, NULL
, NULL
);
249 ok( ret
== (ULONG
)-1, "ldap_modifyA should fail, got %#lx\n", ret
);
250 ret
= ldap_modifyA( NULL
, (char *)"", attrs
);
251 ok( ret
== (ULONG
)-1, "ldap_modifyA should fail, got %#lx\n", ret
);
252 ret
= ldap_modifyA( ld
, NULL
, attrs
);
253 ok( ret
!= (ULONG
)-1, "ldap_modifyA should succeed, got %#lx\n", ret
);
254 ret
= ldap_modifyA( ld
, (char *)"", NULL
);
255 ok( ret
!= (ULONG
)-1, "ldap_modifyA should succeed, got %#lx\n", ret
);
256 ret
= ldap_modifyA( ld
, (char *)"", attrs
);
257 ok( ret
!= (ULONG
)-1, "ldap_modifyA should succeed, got %#lx\n", ret
);
259 ret
= ldap_modify_sA( NULL
, NULL
, NULL
);
260 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_sA should fail, got %#lx\n", ret
);
261 ret
= ldap_modify_sA( NULL
, (char *)"", attrs
);
262 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_sA should fail, got %#lx\n", ret
);
263 ret
= ldap_modify_sA( ld
, NULL
, attrs
);
264 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_modify_sA should fail, got %#lx\n", ret
);
265 ret
= ldap_modify_sA( ld
, (char *)"", NULL
);
266 ok( ret
== LDAP_UNWILLING_TO_PERFORM
, "ldap_modify_sA should fail, got %#lx\n", ret
);
267 ret
= ldap_modify_sA( ld
, (char *)"", attrs
);
268 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_modify_sA should fail, got %#lx\n", ret
);
270 ret
= ldap_modify_extA( NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
271 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_extA should fail, got %#lx\n", ret
);
272 ret
= ldap_modify_extA( NULL
, (char *)"", attrs
, NULL
, NULL
, &num
);
273 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_extA should fail, got %#lx\n", ret
);
274 ret
= ldap_modify_extA( ld
, NULL
, attrs
, NULL
, NULL
, &num
);
275 ok( !ret
, "ldap_modify_extA should succeed, got %#lx\n", ret
);
276 ret
= ldap_modify_extA( ld
, (char *)"", NULL
, NULL
, NULL
, &num
);
277 ok( !ret
, "ldap_modify_extA should succeed, got %#lx\n", ret
);
278 ret
= ldap_modify_extA( ld
, (char *)"", attrs
, NULL
, NULL
, NULL
);
279 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_extA should fail, got %#lx\n", ret
);
280 ret
= ldap_modify_extA( ld
, (char *)"", attrs
, NULL
, NULL
, &num
);
281 ok( !ret
, "ldap_modify_extA should succeed, got %#lx\n", ret
);
283 ret
= ldap_modify_ext_sA( NULL
, NULL
, NULL
, NULL
, NULL
);
284 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_ext_sA should fail, got %#lx\n", ret
);
285 ret
= ldap_modify_ext_sA( NULL
, (char *)"", attrs
, NULL
, NULL
);
286 ok( ret
== LDAP_PARAM_ERROR
, "ldap_modify_ext_sA should fail, got %#lx\n", ret
);
287 ret
= ldap_modify_ext_sA( ld
, NULL
, attrs
, NULL
, NULL
);
288 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_modify_ext_sA should fail, got %#lx\n", ret
);
289 ret
= ldap_modify_ext_sA( ld
, (char *)"", NULL
, NULL
, NULL
);
290 ok( ret
== LDAP_UNWILLING_TO_PERFORM
, "ldap_modify_ext_sA should fail, got %#lx\n", ret
);
291 ret
= ldap_modify_ext_sA( ld
, (char *)"", attrs
, NULL
, NULL
);
292 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_modify_ext_sA should fail, got %#lx\n", ret
);
295 static void test_ldap_compare( LDAP
*ld
)
297 struct berval empty_value
= { 0 };
300 ret
= ldap_compareA( NULL
, NULL
, NULL
, NULL
);
301 ok( ret
== (ULONG
)-1, "ldap_compareA should fail, got %#lx\n", ret
);
302 ret
= ldap_compareA( NULL
, (char *)"", (char *)"", (char *)"" );
303 ok( ret
== (ULONG
)-1, "ldap_compareA should fail, got %#lx\n", ret
);
304 ret
= ldap_compareA( ld
, NULL
, (char *)"", (char *)"" );
305 ok( ret
!= (ULONG
)-1, "ldap_compareA should succeed, got %#lx\n", ret
);
306 ret
= ldap_compareA( ld
, (char *)"", NULL
, (char *)"" );
307 ok( ret
== (ULONG
)-1, "ldap_compareA should fail, got %#lx\n", ret
);
308 ret
= ldap_compareA( ld
, (char *)"", (char *)"", NULL
);
309 ok( ret
!= (ULONG
)-1, "ldap_compareA should succeed, got %#lx\n", ret
);
310 ret
= ldap_compareA( ld
, (char *)"", (char *)"", (char *)"" );
311 ok( ret
!= (ULONG
)-1, "ldap_compareA should succeed, got %#lx\n", ret
);
313 ret
= ldap_compare_sA( NULL
, NULL
, NULL
, NULL
);
314 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_sA should fail, got %#lx\n", ret
);
315 ret
= ldap_compare_sA( NULL
, (char *)"", (char *)"", (char *)"" );
316 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_sA should fail, got %#lx\n", ret
);
317 ret
= ldap_compare_sA( ld
, NULL
, (char *)"", (char *)"" );
318 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_sA should fail, got %#lx\n", ret
);
319 ret
= ldap_compare_sA( ld
, (char *)"", NULL
, (char *)"" );
320 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_sA should fail, got %#lx\n", ret
);
321 ret
= ldap_compare_sA( ld
, (char *)"", (char *)"", NULL
);
322 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_sA should fail, got %#lx\n", ret
);
323 ret
= ldap_compare_sA( ld
, (char *)"", (char *)"", (char *)"" );
324 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_sA should fail, got %#lx\n", ret
);
326 ret
= ldap_compare_extA( NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
327 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_extA should fail, got %#lx\n", ret
);
328 ret
= ldap_compare_extA( NULL
, (char *)"", (char *)"", (char *)"", &empty_value
, NULL
, NULL
, &num
);
329 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_extA should fail, got %#lx\n", ret
);
330 ret
= ldap_compare_extA( ld
, NULL
, (char *)"", (char *)"", &empty_value
, NULL
, NULL
, &num
);
331 ok( !ret
, "ldap_compare_extA should succeed, got %#lx\n", ret
);
332 ret
= ldap_compare_extA( ld
, (char *)"", NULL
, (char *)"", &empty_value
, NULL
, NULL
, &num
);
333 ok( ret
== LDAP_NO_MEMORY
, "ldap_compare_extA should fail, got %#lx\n", ret
);
334 ret
= ldap_compare_extA( ld
, (char *)"", (char *)"", NULL
, &empty_value
, NULL
, NULL
, &num
);
335 ok( !ret
, "ldap_compare_extA should succeed, got %#lx\n", ret
);
336 ret
= ldap_compare_extA( ld
, (char *)"", (char *)"", (char *)"", NULL
, NULL
, NULL
, &num
);
337 ok( !ret
, "ldap_compare_extA should succeed, got %#lx\n", ret
);
338 ret
= ldap_compare_extA( ld
, (char *)"", (char *)"", (char *)"", &empty_value
, NULL
, NULL
, &num
);
339 ok( !ret
, "ldap_compare_extA should succeed, got %#lx\n", ret
);
340 ret
= ldap_compare_extA( ld
, (char *)"", (char *)"", (char *)"", &empty_value
, NULL
, NULL
, NULL
);
341 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_extA should fail, got %#lx\n", ret
);
342 ret
= ldap_compare_extA( ld
, (char *)"", (char *)"", (char *)"", &empty_value
, NULL
, NULL
, &num
);
343 ok( !ret
, "ldap_compare_extA should succeed, got %#lx\n", ret
);
345 ret
= ldap_compare_ext_sA( NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
346 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
347 ret
= ldap_compare_ext_sA( NULL
, (char *)"", (char *)"", (char *)"", &empty_value
, NULL
, NULL
);
348 ok( ret
== LDAP_PARAM_ERROR
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
349 ret
= ldap_compare_ext_sA( ld
, NULL
, (char *)"", (char *)"", &empty_value
, NULL
, NULL
);
350 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
351 ret
= ldap_compare_ext_sA( ld
, (char *)"", NULL
, (char *)"", &empty_value
, NULL
, NULL
);
352 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
353 ret
= ldap_compare_ext_sA( ld
, (char *)"", (char *)"", NULL
, &empty_value
, NULL
, NULL
);
354 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
355 ret
= ldap_compare_ext_sA( ld
, (char *)"", (char *)"", (char *)"", NULL
, NULL
, NULL
);
356 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
357 ret
= ldap_compare_ext_sA( ld
, (char *)"", (char *)"", (char *)"", &empty_value
, NULL
, NULL
);
358 ok( ret
== LDAP_UNDEFINED_TYPE
, "ldap_compare_ext_sA should fail, got %#lx\n", ret
);
361 static void test_ldap_delete( LDAP
*ld
)
365 ret
= ldap_deleteA( NULL
, NULL
);
366 ok( ret
== (ULONG
)-1, "ldap_deleteA should fail, got %#lx\n", ret
);
367 ret
= ldap_deleteA( NULL
, (char *)"" );
368 ok( ret
== (ULONG
)-1, "ldap_deleteA should fail, got %#lx\n", ret
);
370 ret
= ldap_delete_sA( NULL
, NULL
);
371 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_sA should fail, got %#lx\n", ret
);
372 ret
= ldap_delete_sA( NULL
, (char *)"" );
373 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_sA should fail, got %#lx\n", ret
);
375 ret
= ldap_delete_extA( NULL
, NULL
, NULL
, NULL
, NULL
);
376 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_extA should fail, got %#lx\n", ret
);
377 ret
= ldap_delete_extA( NULL
, (char *)"", NULL
, NULL
, &num
);
378 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_extA should fail, got %#lx\n", ret
);
379 ret
= ldap_delete_extA( ld
, (char *)"", NULL
, NULL
, NULL
);
380 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_extA should fail, got %#lx\n", ret
);
382 ret
= ldap_delete_ext_sA( NULL
, NULL
, NULL
, NULL
);
383 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_ext_sA should fail, got %#lx\n", ret
);
384 ret
= ldap_delete_ext_sA( NULL
, (char *)"", NULL
, NULL
);
385 ok( ret
== LDAP_PARAM_ERROR
, "ldap_delete_ext_sA should fail, got %#lx\n", ret
);
388 static void test_ldap_server_control( void )
390 /* SEQUENCE { INTEGER :: 0x07 } */
391 static char mask_ber
[5] = {0x30,0x03,0x02,0x01,0x07};
395 LDAPControlW
*ctrls
[2], mask
;
398 ld
= ldap_initA( (char *)"db.debian.org", 389 );
399 ok( ld
!= NULL
, "ldap_init failed\n" );
401 version
= LDAP_VERSION3
;
402 ret
= ldap_set_optionW( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
403 if (ret
== LDAP_SERVER_DOWN
|| ret
== LDAP_UNAVAILABLE
)
405 skip( "test server can't be reached\n" );
410 ret
= ldap_connect( ld
, NULL
);
411 ok( !ret
, "ldap_connect failed %#lx\n", ret
);
413 /* test setting a not supported server control */
414 mask
.ldctl_oid
= (WCHAR
*)L
"1.2.840.113556.1.4.801";
415 mask
.ldctl_iscritical
= TRUE
;
416 mask
.ldctl_value
.bv_val
= mask_ber
;
417 mask
.ldctl_value
.bv_len
= sizeof(mask_ber
);
420 ret
= ldap_set_optionW(ld
, LDAP_OPT_SERVER_CONTROLS
, ctrls
);
421 ok( ret
== LDAP_PARAM_ERROR
, "ldap_set_optionW should fail: %#lx\n", ret
);
424 ret
= ldap_search_sA( ld
, (char *)"dc=debian,dc=org", LDAP_SCOPE_BASE
, (char *)"(objectclass=*)", NULL
, FALSE
, &res
);
425 ok( !ret
, "ldap_search_sA failed %#lx\n", ret
);
426 ok( res
!= NULL
, "expected res != NULL\n" );
432 static void test_ldap_paged_search(void)
438 LDAPMessage
*res
, *entry
;
442 ld
= ldap_initA( (char *)"db.debian.org", 389 );
443 ok( ld
!= NULL
, "ldap_init failed\n" );
445 version
= LDAP_VERSION3
;
446 ret
= ldap_set_optionW( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
447 if (ret
== LDAP_SERVER_DOWN
|| ret
== LDAP_UNAVAILABLE
)
449 skip( "test server can't be reached\n" );
454 search
= ldap_search_init_pageW( ld
, (WCHAR
*)L
"", LDAP_SCOPE_BASE
, (WCHAR
*)L
"(objectclass=*)",
455 NULL
, FALSE
, NULL
, NULL
, 0, 0, NULL
);
456 ok( search
!= NULL
, "ldap_search_init_page failed\n" );
460 ret
= ldap_get_next_page_s( ld
, search
, NULL
, 1, &count
, &res
);
461 if (ret
== LDAP_SERVER_DOWN
|| ret
== LDAP_UNAVAILABLE
)
463 skip( "test server can't be reached\n" );
467 ok( !ret
, "ldap_get_next_page_s failed %#lx\n", ret
);
468 ok( res
!= NULL
, "expected res != NULL\n" );
469 ok( count
== 0, "got %lu\n", count
);
471 count
= ldap_count_entries( NULL
, NULL
);
472 ok( count
== 0, "got %lu\n", count
);
473 count
= ldap_count_entries( ld
, NULL
);
474 ok( count
== 0, "got %lu\n", count
);
475 count
= ldap_count_entries( NULL
, res
);
476 todo_wine
ok( count
== 1, "got %lu\n", count
);
477 count
= ldap_count_entries( ld
, res
);
478 ok( count
== 1, "got %lu\n", count
);
480 entry
= ldap_first_entry( ld
, res
);
481 ok( res
!= NULL
, "expected entry != NULL\n" );
483 attr
= ldap_first_attributeW( ld
, entry
, &ber
);
484 ok( !wcscmp( attr
, L
"objectClass" ), "got %s\n", wine_dbgstr_w( attr
) );
485 ldap_memfreeW( attr
);
486 attr
= ldap_next_attributeW( ld
, entry
, ber
);
487 ok( !attr
, "got %s\n", wine_dbgstr_w( attr
));
493 res
= (void *)0xdeadbeef;
494 ret
= ldap_get_next_page_s( ld
, search
, NULL
, 1, &count
, &res
);
495 ok( ret
== LDAP_NO_RESULTS_RETURNED
, "got %#lx\n", ret
);
496 ok( !res
, "expected res == NULL\n" );
497 ok( count
== 0, "got %lu\n", count
);
499 ldap_search_abandon_page( ld
, search
);
503 static void test_opt_ssl(void)
506 ULONG ret
, version
= LDAP_VERSION3
, value
;
508 /* Turning on LDAP_OPT_SSL without setting the protocol version does not work */
509 ld
= ldap_initA( (char *)"db.debian.org", 636 );
510 ok( ld
!= NULL
, "ldap_init failed\n" );
511 ret
= ldap_set_optionA( ld
, LDAP_OPT_SSL
, LDAP_OPT_ON
);
512 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
513 ret
= ldap_simple_bind_sA( ld
, NULL
, NULL
);
514 todo_wine
ok( ret
== LDAP_PROTOCOL_ERROR
, "ldap_simple_bind_sA should fail, got %#lx\n", ret
);
517 /* Setting the protocol version to 3 automatically enables SSL when using port 636 */
518 ld
= ldap_initA( (char *)"db.debian.org", 636 );
519 ok( ld
!= NULL
, "ldap_init failed\n" );
520 ret
= ldap_set_optionA( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
521 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
522 ret
= ldap_set_optionA( ld
, LDAP_OPT_SSL
, LDAP_OPT_OFF
);
523 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
524 ret
= ldap_simple_bind_sA( ld
, NULL
, NULL
);
525 todo_wine
ok( !ret
, "ldap_simple_bind_sA should succeed, got %#lx\n", ret
);
528 /* Turning on SSL when the server does not expect it does not work */
529 ld
= ldap_initA( (char *)"db.debian.org", 389 );
530 ok( ld
!= NULL
, "ldap_init failed\n" );
531 ret
= ldap_set_optionA( ld
, LDAP_OPT_SSL
, LDAP_OPT_ON
);
532 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
533 ret
= ldap_simple_bind_sA( ld
, NULL
, NULL
);
534 ok( ret
== LDAP_SERVER_DOWN
, "ldap_simple_bind_sA should fail, got %#lx\n", ret
);
537 /* SSL can also be turned on by passing a pointer to a variable with value 1 */
538 ld
= ldap_initA( (char *)"db.debian.org", 389 );
539 ok( ld
!= NULL
, "ldap_init failed\n" );
541 ret
= ldap_set_optionA( ld
, LDAP_OPT_SSL
, &value
);
542 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
543 ret
= ldap_simple_bind_sA( ld
, NULL
, NULL
);
544 ok( ret
== LDAP_SERVER_DOWN
, "ldap_simple_bind_sA should fail, got %#lx\n", ret
);
547 /* SSL cannot be turned on by passing a pointer to a variable with a bogus value */
548 ld
= ldap_initA( (char *)"db.debian.org", 389 );
549 ok( ld
!= NULL
, "ldap_init failed\n" );
551 ret
= ldap_set_optionA( ld
, LDAP_OPT_SSL
, &value
);
552 ok( ret
== LDAP_PARAM_ERROR
, "ldap_set_optionA should fail, got %#lx\n", ret
);
556 static BOOLEAN CDECL
verify_certificate( LDAP
*ld
, const CERT_CONTEXT
**cert
)
558 CertFreeCertificateContext(*cert
);
562 static void test_opt_server_certificate(void)
565 ULONG ret
, version
= LDAP_VERSION3
;
567 ld
= ldap_initA( (char *)"db.debian.org", 636 );
568 ok( ld
!= NULL
, "ldap_init failed\n" );
569 ret
= ldap_set_optionA( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
570 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
571 ret
= ldap_set_optionA( ld
, LDAP_OPT_SSL
, LDAP_OPT_ON
);
572 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
573 ret
= ldap_set_optionA( ld
, LDAP_OPT_SERVER_CERTIFICATE
, &verify_certificate
);
574 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
575 ret
= ldap_connect( ld
, NULL
);
576 ok( ret
== LDAP_SERVER_DOWN
, "ldap_connect should fail, got %#lx\n", ret
);
577 ret
= ldap_simple_bindA( ld
, NULL
, NULL
);
578 ok( ret
== (ULONG
)-1, "ldap_simple_bindA should fail, got %#lx\n", ret
);
579 ret
= ldap_simple_bind_sA( ld
, NULL
, NULL
);
580 ok( ret
== LDAP_SERVER_DOWN
, "ldap_simple_bind_sA should fail, got %#lx\n", ret
);
583 ld
= ldap_initA( (char *)"db.debian.org", 389 );
584 ok( ld
!= NULL
, "ldap_init failed\n" );
585 ret
= ldap_set_optionA( ld
, LDAP_OPT_PROTOCOL_VERSION
, &version
);
586 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
587 ret
= ldap_set_optionA( ld
, LDAP_OPT_SERVER_CERTIFICATE
, &verify_certificate
);
588 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
589 ret
= ldap_connect( ld
, NULL
);
590 ok( !ret
, "ldap_connect should succeed, got %#lx\n", ret
);
591 ret
= ldap_start_tls_sA( ld
, NULL
, NULL
, NULL
, NULL
);
592 ok( ret
== LDAP_LOCAL_ERROR
, "ldap_start_tls_sA should fail, got %#lx\n", ret
);
596 static void test_opt_auto_reconnect(void)
601 ld
= ldap_initA( (char *)"db.debian.org", 389 );
602 ok( ld
!= NULL
, "ldap_init failed\n" );
604 ret
= ldap_set_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, LDAP_OPT_ON
);
605 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
606 ret
= ldap_get_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
607 ok( !ret
, "ldap_get_optionA should succeed, got %#lx\n", ret
);
608 ok( value
== 1, "got %lu\n", ret
);
610 ret
= ldap_set_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, LDAP_OPT_OFF
);
611 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
612 ret
= ldap_get_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
613 ok( !ret
, "ldap_get_optionA should succeed, got %#lx\n", ret
);
614 ok( value
== 0, "got %lu\n", ret
);
617 ret
= ldap_set_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
618 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
619 ret
= ldap_get_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
620 ok( !ret
, "ldap_get_optionA should succeed, got %#lx\n", ret
);
621 ok( value
== 1, "got %lu\n", ret
);
624 ret
= ldap_set_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
625 ok( !ret
, "ldap_set_optionA should succeed, got %#lx\n", ret
);
626 ret
= ldap_get_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
627 ok( !ret
, "ldap_get_optionA should succeed, got %#lx\n", ret
);
628 ok( value
== 0, "got %lu\n", ret
);
631 ret
= ldap_set_optionA( ld
, LDAP_OPT_AUTO_RECONNECT
, &value
);
632 ok( ret
== LDAP_PARAM_ERROR
, "ldap_set_optionA should fail, got %#lx\n", ret
);
639 test_ldap_paged_search();
640 test_ldap_server_control();
643 test_opt_server_certificate();
644 test_opt_auto_reconnect();
646 ld
= ldap_initA( (char *)"db.debian.org", 389 );
647 ok( ld
!= NULL
, "ldap_init failed\n" );
650 test_ldap_modify( ld
);
651 test_ldap_compare( ld
);
652 test_ldap_delete( ld
);
653 test_ldap_parse_sort_control( ld
);
654 test_ldap_search_extW( ld
);
655 test_opt_referrals( ld
);
656 test_opt_protocol_version( ld
);