18
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
* KIND, either express or implied.
21
* $Id: ldap.c,v 1.49 2005/03/11 05:28:07 danf Exp $
21
* $Id: ldap.c,v 1.51 2005/11/01 16:27:27 giva Exp $
22
22
***************************************************************************/
247
262
char *(__cdecl *ldap_get_dn)(void *, void *);
248
263
char *(__cdecl *ldap_first_attribute)(void *, void *, void **);
249
264
char *(__cdecl *ldap_next_attribute)(void *, void *, void *);
250
char **(__cdecl *ldap_get_values)(void *, void *, const char *);
251
void (__cdecl *ldap_value_free)(char **);
265
void **(__cdecl *ldap_get_values_len)(void *, void *, const char *);
266
void (__cdecl *ldap_value_free_len)(void **);
252
267
void (__cdecl *ldap_memfree)(void *);
253
268
void (__cdecl *ber_free)(void *, int);
269
int (__cdecl *ldap_set_option)(void *, int, void *);
256
272
LDAPURLDesc *ludp = NULL;
272
291
* pointer-to-object (data) and pointer-to-function.
274
293
DYNA_GET_FUNCTION(void *(__cdecl *)(char *, int), ldap_init);
275
DYNA_GET_FUNCTION(int (__cdecl *)(void *, char *, char *), ldap_simple_bind_s);
294
DYNA_GET_FUNCTION(int (__cdecl *)(void *, char *, char *),
276
296
DYNA_GET_FUNCTION(int (__cdecl *)(void *), ldap_unbind_s);
278
298
DYNA_GET_FUNCTION(int (*)(char *, LDAPURLDesc **), ldap_url_parse);
279
299
DYNA_GET_FUNCTION(void (*)(void *), ldap_free_urldesc);
281
301
DYNA_GET_FUNCTION(int (__cdecl *)(void *, char *, int, char *, char **, int,
282
void **), ldap_search_s);
302
void **), ldap_search_s);
283
303
DYNA_GET_FUNCTION(void *(__cdecl *)(void *, void *), ldap_first_entry);
284
304
DYNA_GET_FUNCTION(void *(__cdecl *)(void *, void *), ldap_next_entry);
285
305
DYNA_GET_FUNCTION(char *(__cdecl *)(int), ldap_err2string);
286
306
DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *), ldap_get_dn);
287
DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *, void **), ldap_first_attribute);
288
DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *, void *), ldap_next_attribute);
289
DYNA_GET_FUNCTION(char **(__cdecl *)(void *, void *, const char *), ldap_get_values);
290
DYNA_GET_FUNCTION(void (__cdecl *)(char **), ldap_value_free);
307
DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *, void **),
308
ldap_first_attribute);
309
DYNA_GET_FUNCTION(char *(__cdecl *)(void *, void *, void *),
310
ldap_next_attribute);
311
DYNA_GET_FUNCTION(void **(__cdecl *)(void *, void *, const char *),
312
ldap_get_values_len);
313
DYNA_GET_FUNCTION(void (__cdecl *)(void **), ldap_value_free_len);
291
314
DYNA_GET_FUNCTION(void (__cdecl *)(void *), ldap_memfree);
292
315
DYNA_GET_FUNCTION(void (__cdecl *)(void *, int), ber_free);
316
DYNA_GET_FUNCTION(int (__cdecl *)(void *, int, void *), ldap_set_option);
294
318
server = (*ldap_init)(conn->host.name, (int)conn->port);
295
319
if (server == NULL) {
326
ldap_proto = LDAP_VERSION3;
327
(*ldap_set_option)(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
302
328
rc = (*ldap_simple_bind_s)(server,
303
329
conn->bits.user_passwd ? conn->user : NULL,
304
330
conn->bits.user_passwd ? conn->passwd : NULL);
332
ldap_proto = LDAP_VERSION2;
333
(*ldap_set_option)(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
334
rc = (*ldap_simple_bind_s)(server,
335
conn->bits.user_passwd ? conn->user : NULL,
336
conn->bits.user_passwd ? conn->passwd : NULL);
306
339
failf(data, "LDAP local: %s", (*ldap_err2string)(rc));
307
340
status = CURLE_LDAP_CANNOT_BIND;
347
380
attribute = (*ldap_next_attribute)(server, entryIterator, ber))
349
char **vals = (*ldap_get_values)(server, entryIterator, attribute);
382
struct bv **vals = (struct bv **)
383
(*ldap_get_values_len)(server, entryIterator, attribute);
351
385
if (vals != NULL)
353
387
for (i = 0; (vals[i] != NULL); i++)
355
389
Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
356
Curl_client_write(data, CLIENTWRITE_BODY, (char*) attribute, 0);
390
Curl_client_write(data, CLIENTWRITE_BODY, (char *) attribute, 0);
357
391
Curl_client_write(data, CLIENTWRITE_BODY, (char *)": ", 2);
358
Curl_client_write(data, CLIENTWRITE_BODY, vals[i], 0);
392
if ((strlen(attribute) > 7) &&
395
(strlen((char *)attribute) - 7)) == 0)) {
396
/* Binary attribute, encode to base64. */
397
val_b64_sz = Curl_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
399
if (val_b64_sz > 0) {
400
Curl_client_write(data, CLIENTWRITE_BODY, val_b64, val_b64_sz);
404
Curl_client_write(data, CLIENTWRITE_BODY, vals[i]->bv_val,
359
406
Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
362
409
/* Free memory used to store values */
363
(*ldap_value_free)(vals);
410
(*ldap_value_free_len)((void **)vals);
365
412
Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);