~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr-util/ldap/apr_ldap_init.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
/*
 
18
 * apr_ldap_init.c: LDAP v2/v3 common initialise
 
19
 * 
 
20
 * Original code from auth_ldap module for Apache v1.3:
 
21
 * Copyright 1998, 1999 Enbridge Pipelines Inc. 
 
22
 * Copyright 1999-2001 Dave Carrigan
 
23
 */
 
24
 
 
25
#include "apr.h"
 
26
#include "apu.h"
 
27
#include "apr_ldap.h"
 
28
#include "apr_errno.h"
 
29
#include "apr_pools.h"
 
30
#include "apr_strings.h"
 
31
 
 
32
#if APR_HAS_LDAP
 
33
 
 
34
/**
 
35
 * APR LDAP SSL Initialise function
 
36
 *
 
37
 * This function initialises SSL on the underlying LDAP toolkit
 
38
 * if this is necessary.
 
39
 *
 
40
 * If a CA certificate is provided, this is set, however the setting
 
41
 * of certificates via this method has been deprecated and will be removed in
 
42
 * APR v2.0.
 
43
 *
 
44
 * The apr_ldap_set_option() function with the APR_LDAP_OPT_TLS_CERT option
 
45
 * should be used instead to set certificates.
 
46
 *
 
47
 * If SSL support is not available on this platform, or a problem
 
48
 * was encountered while trying to set the certificate, the function
 
49
 * will return APR_EGENERAL. Further LDAP specific error information
 
50
 * can be found in result_err.
 
51
 */
 
52
APU_DECLARE(int) apr_ldap_ssl_init(apr_pool_t *pool,
 
53
                                   const char *cert_auth_file,
 
54
                                   int cert_file_type,
 
55
                                   apr_ldap_err_t **result_err) {
 
56
 
 
57
    apr_ldap_err_t *result = (apr_ldap_err_t *)apr_pcalloc(pool, sizeof(apr_ldap_err_t));
 
58
    *result_err = result;
 
59
 
 
60
#if APR_HAS_LDAP_SSL /* compiled with ssl support */
 
61
 
 
62
    /* Novell */
 
63
#if APR_HAS_NOVELL_LDAPSDK
 
64
    ldapssl_client_init(NULL, NULL);
 
65
#endif
 
66
 
 
67
    /* if a certificate was specified, set it */
 
68
    if (cert_auth_file) {
 
69
        apr_ldap_opt_tls_cert_t *cert = (apr_ldap_opt_tls_cert_t *)apr_pcalloc(pool, sizeof(apr_ldap_opt_tls_cert_t));
 
70
        cert->type = cert_file_type;
 
71
        cert->path = cert_auth_file;
 
72
        return apr_ldap_set_option(pool, NULL, APR_LDAP_OPT_TLS_CERT, (void *)cert, result_err);
 
73
    }
 
74
 
 
75
#else  /* not compiled with SSL Support */
 
76
    if (cert_auth_file) {
 
77
        result->reason = "LDAP: Attempt to set certificate store failed. "
 
78
                         "Not built with SSL support";
 
79
        result->rc = -1;
 
80
    }
 
81
#endif /* APR_HAS_LDAP_SSL */
 
82
 
 
83
    if (result->rc != -1) {
 
84
        result->msg = ldap_err2string(result->rc);
 
85
    }
 
86
 
 
87
    if (LDAP_SUCCESS != result->rc) {
 
88
        return APR_EGENERAL;
 
89
    }
 
90
 
 
91
    return APR_SUCCESS;
 
92
 
 
93
 
94
 
 
95
 
 
96
/**
 
97
 * APR LDAP SSL De-Initialise function
 
98
 *
 
99
 * This function tears down any SSL certificate setup previously
 
100
 * set using apr_ldap_ssl_init(). It should be called to clean
 
101
 * up if a graceful restart of a service is attempted.
 
102
 *
 
103
 * This function only does anything on Netware.
 
104
 *
 
105
 * @todo currently we do not check whether apr_ldap_ssl_init()
 
106
 * has been called first - should we?
 
107
 */
 
108
APU_DECLARE(int) apr_ldap_ssl_deinit(void) {
 
109
 
 
110
#if APR_HAS_LDAP_SSL && APR_HAS_LDAPSSL_CLIENT_DEINIT
 
111
    ldapssl_client_deinit();
 
112
#endif
 
113
    return APR_SUCCESS;
 
114
 
 
115
}
 
116
 
 
117
 
 
118
/**
 
119
 * APR LDAP initialise function
 
120
 *
 
121
 * This function is responsible for initialising an LDAP
 
122
 * connection in a toolkit independant way. It does the
 
123
 * job of ldap_init() from the C api.
 
124
 *
 
125
 * It handles both the SSL and non-SSL case, and attempts
 
126
 * to hide the complexity setup from the user. This function
 
127
 * assumes that any certificate setup necessary has already
 
128
 * been done.
 
129
 *
 
130
 * If SSL or STARTTLS needs to be enabled, and the underlying
 
131
 * toolkit supports it, the following values are accepted for
 
132
 * secure:
 
133
 *
 
134
 * APR_LDAP_NONE: No encryption
 
135
 * APR_LDAP_SSL: SSL encryption (ldaps://)
 
136
 * APR_LDAP_STARTTLS: Force STARTTLS on ldap://
 
137
 */
 
138
APU_DECLARE(int) apr_ldap_init(apr_pool_t *pool,
 
139
                               LDAP **ldap,
 
140
                               const char *hostname,
 
141
                               int portno,
 
142
                               int secure,
 
143
                               apr_ldap_err_t **result_err) {
 
144
 
 
145
    apr_ldap_err_t *result = (apr_ldap_err_t *)apr_pcalloc(pool, sizeof(apr_ldap_err_t));
 
146
    *result_err = result;
 
147
 
 
148
#if APR_HAS_LDAPSSL_INIT
 
149
    *ldap = ldapssl_init(hostname, portno, 0);
 
150
#elif APR_HAS_LDAP_SSLINIT
 
151
    *ldap = ldap_sslinit((char *)hostname, portno, 0);
 
152
#else
 
153
    *ldap = ldap_init((char *)hostname, portno);
 
154
#endif
 
155
    if (*ldap != NULL) {
 
156
        return apr_ldap_set_option(pool, *ldap, APR_LDAP_OPT_TLS, &secure, result_err);
 
157
    }
 
158
    else {
 
159
        /* handle the error case */
 
160
        apr_ldap_err_t *result = (apr_ldap_err_t *)apr_pcalloc(pool, sizeof(apr_ldap_err_t));
 
161
        *result_err = result;
 
162
 
 
163
        result->reason = "APR LDAP: Unable to initialize the LDAP connection";
 
164
        result->rc = -1;
 
165
        return APR_EGENERAL;
 
166
    }
 
167
 
 
168
}
 
169
 
 
170
 
 
171
/**
 
172
 * APR LDAP info function
 
173
 *
 
174
 * This function returns a string describing the LDAP toolkit
 
175
 * currently in use. The string is placed inside result_err->reason.
 
176
 */
 
177
APU_DECLARE(int) apr_ldap_info(apr_pool_t *pool, apr_ldap_err_t **result_err)
 
178
{
 
179
    apr_ldap_err_t *result = (apr_ldap_err_t *)apr_pcalloc(pool, sizeof(apr_ldap_err_t));
 
180
    *result_err = result;
 
181
 
 
182
    result->reason = "APR LDAP: Built with "
 
183
                     LDAP_VENDOR_NAME
 
184
                     " LDAP SDK";
 
185
    return APR_SUCCESS;
 
186
    
 
187
}
 
188
 
 
189
#endif /* APR_HAS_LDAP */