~ubuntu-branches/ubuntu/intrepid/curl/intrepid

« back to all changes in this revision

Viewing changes to lib/ldap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-16 15:16:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070516151654-jo48r81zempo1qav
Tags: 7.16.2-3ubuntu1
* Merge with Debian; remaining changes:
  - Drop the stunnel build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  Project         ___| | | |  _ \| |
4
4
 *                 / __| | | | |_) | |
5
5
 *                | (__| |_| |  _ <| |___
6
 
 *                \___|\___/|_| \_\_____|
 
6
 *                 \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: ldap.c,v 1.57 2006-07-25 13:49:50 yangtse Exp $
 
21
 * $Id: ldap.c,v 1.69 2007-03-12 05:09:25 yangtse Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
30
30
#include <stdarg.h>
31
31
#include <stdlib.h>
32
32
#include <ctype.h>
33
 
#ifdef HAVE_SYS_TYPES_H
34
 
#include <sys/types.h>
35
 
#endif
36
 
#ifdef HAVE_SYS_STAT_H
37
 
#include <sys/stat.h>
38
 
#endif
39
33
#ifdef NEED_MALLOC_H
40
34
#include <malloc.h>
41
35
#endif
115
109
#undef HAVE_LIBDL
116
110
#endif
117
111
 
 
112
/*
 
113
 * We use this ZERO_NULL to avoid picky compiler warnings,
 
114
 * when assigning a NULL pointer to a function pointer var.
 
115
 */
 
116
 
 
117
#define ZERO_NULL 0
 
118
 
118
119
typedef void * (*dynafunc)(void *input);
119
120
 
120
121
/***********************************************************************
189
190
 
190
191
static dynafunc DynaGetFunction(const char *name)
191
192
{
192
 
  dynafunc func = (dynafunc)NULL;
 
193
  dynafunc func = (dynafunc)ZERO_NULL;
193
194
 
194
195
#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
195
196
  if (libldap) {
199
200
     * compilers! */
200
201
    *(void**) (&func) = dlsym(libldap, name);
201
202
  }
 
203
#ifdef DL_LBER_FILE
 
204
  if (!func && liblber) {
 
205
    *(void**) (&func) = dlsym(liblber, name);
 
206
  }
 
207
#endif
202
208
#elif defined(WIN32)
203
209
  if (libldap) {
204
210
    func = (dynafunc)GetProcAddress((HINSTANCE)libldap, name);
372
378
    char  *dn = (*ldap_get_dn)(server, entryIterator);
373
379
    int i;
374
380
 
375
 
    Curl_client_write(data, CLIENTWRITE_BODY, (char *)"DN: ", 4);
376
 
    Curl_client_write(data, CLIENTWRITE_BODY, (char *)dn, 0);
377
 
    Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
 
381
    Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"DN: ", 4);
 
382
    Curl_client_write(conn, CLIENTWRITE_BODY, (char *)dn, 0);
 
383
    Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
378
384
 
379
385
    for (attribute = (*ldap_first_attribute)(server, entryIterator, &ber);
380
386
         attribute;
387
393
      {
388
394
        for (i = 0; (vals[i] != NULL); i++)
389
395
        {
390
 
          Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
391
 
          Curl_client_write(data, CLIENTWRITE_BODY, (char *) attribute, 0);
392
 
          Curl_client_write(data, CLIENTWRITE_BODY, (char *)": ", 2);
 
396
          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1);
 
397
          Curl_client_write(conn, CLIENTWRITE_BODY, (char *) attribute, 0);
 
398
          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)": ", 2);
393
399
          if ((strlen(attribute) > 7) &&
394
400
              (strcmp(";binary",
395
401
                      (char *)attribute +
396
402
                      (strlen((char *)attribute) - 7)) == 0)) {
397
403
            /* Binary attribute, encode to base64. */
398
 
            val_b64_sz = Curl_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
 
404
            val_b64_sz = Curl_base64_encode(conn->data,
 
405
                                            vals[i]->bv_val,
 
406
                                            vals[i]->bv_len,
399
407
                                            &val_b64);
400
408
            if (val_b64_sz > 0) {
401
 
              Curl_client_write(data, CLIENTWRITE_BODY, val_b64, val_b64_sz);
 
409
              Curl_client_write(conn, CLIENTWRITE_BODY, val_b64, val_b64_sz);
402
410
              free(val_b64);
403
411
            }
404
412
          } else
405
 
            Curl_client_write(data, CLIENTWRITE_BODY, vals[i]->bv_val,
 
413
            Curl_client_write(conn, CLIENTWRITE_BODY, vals[i]->bv_val,
406
414
                              vals[i]->bv_len);
407
 
          Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
 
415
          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 0);
408
416
        }
409
417
 
410
418
        /* Free memory used to store values */
411
419
        (*ldap_value_free_len)((void **)vals);
412
420
      }
413
 
      Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
 
421
      Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
414
422
 
415
423
      (*ldap_memfree)(attribute);
416
424
    }
431
439
  DynaClose();
432
440
 
433
441
  /* no data to transfer */
434
 
  Curl_Transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
 
442
  Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
435
443
  conn->bits.close = TRUE;
436
444
 
437
445
  return status;
541
549
 *
542
550
 * <hostname> already known from 'conn->host.name'.
543
551
 * <port>     already known from 'conn->remote_port'.
544
 
 * extract the rest from 'conn->path+1'. All fields are optional. e.g.
545
 
 *   ldap://<hostname>:<port>/?<attributes>?<scope>?<filter> yields ludp->lud_dn = "".
 
552
 * extract the rest from 'conn->data->reqdata.path+1'. All fields are optional.
 
553
 * e.g.
 
554
 *   ldap://<hostname>:<port>/?<attributes>?<scope>?<filter>
 
555
 * yields ludp->lud_dn = "".
546
556
 *
547
557
 * Ref. http://developer.netscape.com/docs/manuals/dirsdk/csdk30/url.htm#2831915
548
558
 */
551
561
  char *p, *q;
552
562
  int i;
553
563
 
554
 
  if (!conn->path || conn->path[0] != '/' ||
 
564
  if (!conn->data ||
 
565
      !conn->data->reqdata.path ||
 
566
       conn->data->reqdata.path[0] != '/' ||
555
567
      !checkprefix(conn->protostr, conn->data->change.url))
556
568
     return LDAP_INVALID_SYNTAX;
557
569
 
561
573
 
562
574
  /* parse DN (Distinguished Name).
563
575
   */
564
 
  ludp->lud_dn = strdup(conn->path+1);
 
576
  ludp->lud_dn = strdup(conn->data->reqdata.path+1);
565
577
  if (!ludp->lud_dn)
566
578
     return LDAP_NO_MEMORY;
567
579