~ubuntu-branches/ubuntu/natty/curl/natty-security

« back to all changes in this revision

Viewing changes to lib/ldap.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-06-20 13:56:28 UTC
  • mfrom: (3.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100620135628-e30tp9jldq6hq985
Tags: 7.21.0-1ubuntu1
* Merge from debian unstable.  Remaining changes: LP: #596334
  - Keep build deps in main:
    - Drop build dependencies: stunnel, libssh2-1-dev
    - Add build-dependency on openssh-server
    - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                | (__| |_| |  _ <| |___
6
6
 *                 \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2010, 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.101 2009-11-02 20:04:18 yangtse Exp $
22
21
 ***************************************************************************/
23
22
 
24
23
#include "setup.h"
25
24
 
26
 
#ifndef CURL_DISABLE_LDAP
 
25
#if !defined(CURL_DISABLE_LDAP) && !defined(USE_OPENLDAP)
 
26
 
 
27
/*
 
28
 * Notice that USE_OPENLDAP is only a source code selection switch. When
 
29
 * libcurl is built with USE_OPENLDAP defined the libcurl source code that
 
30
 * gets compiled is the code from openldap.c, otherwise the code that gets
 
31
 * compiled is the code from ldap.c.
 
32
 *
 
33
 * When USE_OPENLDAP is defined a recent version of the OpenLDAP library
 
34
 * might be required for compilation and runtime. In order to use ancient
 
35
 * OpenLDAP library versions, USE_OPENLDAP shall not be defined.
 
36
 */
 
37
 
27
38
/* -- WIN32 approved -- */
28
39
#include <stdio.h>
29
40
#include <string.h>
32
43
#include <ctype.h>
33
44
#include <errno.h>
34
45
 
35
 
#ifdef CURL_LDAP_HYBRID         /* If W$ definitions are needed. */
36
 
# include <windows.h>
37
 
  /* Remember we are NOT in a W$ compiler! */
38
 
# undef WIN32
39
 
# undef _WIN32
40
 
# undef __WIN32__
41
 
#endif
42
 
 
43
 
#ifdef CURL_LDAP_WIN            /* Use W$ LDAP implementation. */
 
46
#ifdef CURL_LDAP_WIN            /* Use Windows LDAP implementation. */
44
47
# include <winldap.h>
45
48
# ifndef LDAP_VENDOR_NAME
46
49
#  error Your Platform SDK is NOT sufficient for LDAP support! Update your Platform SDK, or disable LDAP support!
48
51
#  include <winber.h>
49
52
# endif
50
53
#else
51
 
#define LDAP_DEPRECATED 1       /* Be sure ldap_init() is defined. */
52
 
#ifdef HAVE_LBER_H
53
 
# include <lber.h>
54
 
#endif
 
54
# define LDAP_DEPRECATED 1      /* Be sure ldap_init() is defined. */
 
55
# ifdef HAVE_LBER_H
 
56
#  include <lber.h>
 
57
# endif
55
58
# include <ldap.h>
56
 
#if (defined(HAVE_LDAP_SSL) && defined(HAVE_LDAP_SSL_H))
57
 
# include <ldap_ssl.h>
58
 
#endif /* HAVE_LDAP_SSL && HAVE_LDAP_SSL_H */
 
59
# if (defined(HAVE_LDAP_SSL) && defined(HAVE_LDAP_SSL_H))
 
60
#  include <ldap_ssl.h>
 
61
# endif /* HAVE_LDAP_SSL && HAVE_LDAP_SSL_H */
59
62
#endif
60
63
 
61
64
#ifdef HAVE_UNISTD_H
200
203
  }
201
204
 
202
205
  /* Get the URL scheme ( either ldap or ldaps ) */
203
 
  if(Curl_raw_equal(conn->protostr, "LDAPS"))
 
206
  if(conn->protocol & PROT_SSL)
204
207
    ldap_ssl = 1;
205
208
  infof(data, "LDAP local: trying to establish %s connection\n",
206
209
          ldap_ssl ? "encrypted" : "cleartext");
262
265
    }
263
266
    server = ldapssl_init(conn->host.name, (int)conn->port, 1);
264
267
    if(server == NULL) {
265
 
      failf(data, "LDAP local: Cannot connect to %s:%d",
 
268
      failf(data, "LDAP local: Cannot connect to %s:%hu",
266
269
              conn->host.name, conn->port);
267
270
      status = CURLE_COULDNT_CONNECT;
268
271
      goto quit;
302
305
    }
303
306
    server = ldap_init(conn->host.name, (int)conn->port);
304
307
    if(server == NULL) {
305
 
      failf(data, "LDAP local: Cannot connect to %s:%d",
 
308
      failf(data, "LDAP local: Cannot connect to %s:%hu",
306
309
              conn->host.name, conn->port);
307
310
      status = CURLE_COULDNT_CONNECT;
308
311
      goto quit;
337
340
  } else {
338
341
    server = ldap_init(conn->host.name, (int)conn->port);
339
342
    if(server == NULL) {
340
 
      failf(data, "LDAP local: Cannot connect to %s:%d",
 
343
      failf(data, "LDAP local: Cannot connect to %s:%hu",
341
344
              conn->host.name, conn->port);
342
345
      status = CURLE_COULDNT_CONNECT;
343
346
      goto quit;
488
491
 */
489
492
static int str2scope (const char *p)
490
493
{
491
 
  if(!stricmp(p, "one"))
492
 
     return LDAP_SCOPE_ONELEVEL;
493
 
  if(!stricmp(p, "onetree"))
494
 
     return LDAP_SCOPE_ONELEVEL;
495
 
  if(!stricmp(p, "base"))
 
494
  if(strequal(p, "one"))
 
495
     return LDAP_SCOPE_ONELEVEL;
 
496
  if(strequal(p, "onetree"))
 
497
     return LDAP_SCOPE_ONELEVEL;
 
498
  if(strequal(p, "base"))
496
499
     return LDAP_SCOPE_BASE;
497
 
  if(!stricmp(p, "sub"))
 
500
  if(strequal(p, "sub"))
498
501
     return LDAP_SCOPE_SUBTREE;
499
 
  if(!stricmp( p, "subtree"))
 
502
  if(strequal( p, "subtree"))
500
503
     return LDAP_SCOPE_SUBTREE;
501
504
  return (-1);
502
505
}
582
585
  if(!conn->data ||
583
586
      !conn->data->state.path ||
584
587
      conn->data->state.path[0] != '/' ||
585
 
      !checkprefix(conn->protostr, conn->data->change.url))
 
588
      !checkprefix("LDAP", conn->data->change.url))
586
589
    return LDAP_INVALID_SYNTAX;
587
590
 
588
591
  ludp->lud_scope = LDAP_SCOPE_BASE;
673
676
static int _ldap_url_parse (const struct connectdata *conn,
674
677
                            LDAPURLDesc **ludpp)
675
678
{
676
 
  LDAPURLDesc *ludp = calloc(sizeof(*ludp), 1);
 
679
  LDAPURLDesc *ludp = calloc(1, sizeof(*ludp));
677
680
  int rc;
678
681
 
679
682
  *ludpp = NULL;
716
719
  free (ludp);
717
720
}
718
721
#endif  /* !HAVE_LDAP_URL_PARSE */
719
 
#endif  /* CURL_DISABLE_LDAP */
 
722
#endif  /* !CURL_DISABLE_LDAP && !USE_OPENLDAP */