Apache HTTPD
framework
httpd-2.4.62
srclib
apr-util
ldap
apr_ldap_init.c
Go to the documentation of this file.
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. 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 "apu_config.h"
28
29
#if APU_DSO_BUILD
30
#define APU_DSO_LDAP_BUILD
31
#endif
32
33
#include "apr_ldap.h"
34
#include "
apu_internal.h
"
35
#include "
apr_errno.h
"
36
#include "
apr_pools.h
"
37
#include "
apr_strings.h
"
38
39
#if APR_HAS_LDAP
40
59
APU_DECLARE_LDAP
(
int
)
apr_ldap_ssl_init
(
apr_pool_t
*
pool
,
60
const
char
*
cert_auth_file
,
61
int
cert_file_type
,
62
apr_ldap_err_t
**
result_err
)
63
{
64
65
apr_ldap_err_t
*
result
= (
apr_ldap_err_t
*)
apr_pcalloc
(
pool
,
sizeof
(
apr_ldap_err_t
));
66
*
result_err
=
result
;
67
68
#if APR_HAS_LDAP_SSL
/* compiled with ssl support */
69
70
/* Novell */
71
#if APR_HAS_NOVELL_LDAPSDK
72
ldapssl_client_init
(
NULL
,
NULL
);
73
#endif
74
75
/* if a certificate was specified, set it */
76
if
(
cert_auth_file
) {
77
apr_ldap_opt_tls_cert_t
*
cert
= (
apr_ldap_opt_tls_cert_t
*)
apr_pcalloc
(
pool
,
sizeof
(
apr_ldap_opt_tls_cert_t
));
78
cert
->type =
cert_file_type
;
79
cert
->path =
cert_auth_file
;
80
return
apr_ldap_set_option
(
pool
,
NULL
,
APR_LDAP_OPT_TLS_CERT
, (
void
*)
cert
,
result_err
);
81
}
82
83
#else
/* not compiled with SSL Support */
84
if
(
cert_auth_file
) {
85
result
->reason =
"LDAP: Attempt to set certificate store failed. "
86
"Not built with SSL support"
;
87
result
->rc = -1;
88
}
89
#endif
/* APR_HAS_LDAP_SSL */
90
91
if
(
result
->rc != -1) {
92
result
->msg =
ldap_err2string
(
result
->rc);
93
}
94
95
if
(
LDAP_SUCCESS
!=
result
->rc) {
96
return
APR_EGENERAL
;
97
}
98
99
return
APR_SUCCESS
;
100
101
}
102
103
116
APU_DECLARE_LDAP
(
int
)
apr_ldap_ssl_deinit
(
void
)
117
{
118
119
#if APR_HAS_LDAP_SSL && APR_HAS_LDAPSSL_CLIENT_DEINIT
120
ldapssl_client_deinit
();
121
#endif
122
return
APR_SUCCESS
;
123
124
}
125
126
147
APU_DECLARE_LDAP
(
int
)
apr_ldap_init
(
apr_pool_t
*
pool
,
148
LDAP
**
ldap
,
149
const
char
*
hostname
,
150
int
portno
,
151
int
secure,
152
apr_ldap_err_t
**
result_err
)
153
{
154
155
apr_ldap_err_t
*
result
= (
apr_ldap_err_t
*)
apr_pcalloc
(
pool
,
sizeof
(
apr_ldap_err_t
));
156
*
result_err
=
result
;
157
158
#if APR_HAS_LDAPSSL_INIT
159
#if APR_HAS_SOLARIS_LDAPSDK
160
/*
161
* Using the secure argument should aways be possible. But as LDAP SDKs
162
* tend to have different quirks and bugs, this needs to be tested for
163
* for each of them, first. For Solaris LDAP it works, and the method
164
* with ldap_set_option doesn't.
165
*/
166
*
ldap
=
ldapssl_init
(
hostname
,
portno
, secure ==
APR_LDAP_SSL
);
167
#else
168
*
ldap
=
ldapssl_init
(
hostname
,
portno
, 0);
169
#endif
170
#elif APR_HAS_LDAP_SSLINIT
171
*
ldap
=
ldap_sslinit
((
char
*)
hostname
,
portno
, 0);
172
#else
173
*
ldap
=
ldap_init
((
char
*)
hostname
,
portno
);
174
#endif
175
176
if
(*
ldap
!=
NULL
) {
177
#if APR_HAS_SOLARIS_LDAPSDK
178
if
(secure ==
APR_LDAP_SSL
)
179
return
APR_SUCCESS
;
180
else
181
#endif
182
return
apr_ldap_set_option
(
pool
, *
ldap
,
APR_LDAP_OPT_TLS
, &secure,
result_err
);
183
}
184
else
{
185
/* handle the error case */
186
apr_ldap_err_t
*
result
= (
apr_ldap_err_t
*)
apr_pcalloc
(
pool
,
sizeof
(
apr_ldap_err_t
));
187
*
result_err
=
result
;
188
189
result
->reason =
"APR LDAP: Unable to initialize the LDAP connection"
;
190
result
->rc = -1;
191
return
APR_EGENERAL
;
192
}
193
194
}
195
196
203
APU_DECLARE_LDAP
(
int
)
apr_ldap_info
(
apr_pool_t
*
pool
,
204
apr_ldap_err_t
**
result_err
)
205
{
206
apr_ldap_err_t
*
result
= (
apr_ldap_err_t
*)
apr_pcalloc
(
pool
,
sizeof
(
apr_ldap_err_t
));
207
*
result_err
=
result
;
208
209
result
->reason =
"APR LDAP: Built with "
210
LDAP_VENDOR_NAME
211
" LDAP SDK"
;
212
return
APR_SUCCESS
;
213
214
}
215
216
#if APU_DSO_BUILD
217
218
/* For DSO builds, export the table of entry points into the apr_ldap DSO
219
* See include/private/apu_internal.h for the corresponding declarations
220
*/
221
APU_MODULE_DECLARE_DATA
struct
apr__ldap_dso_fntable
apr__ldap_fns
= {
222
apr_ldap_info
,
223
apr_ldap_init
,
224
apr_ldap_ssl_init
,
225
apr_ldap_ssl_deinit
,
226
apr_ldap_get_option
,
227
apr_ldap_set_option
,
228
apr_ldap_rebind_init
,
229
apr_ldap_rebind_add
,
230
apr_ldap_rebind_remove
231
};
232
233
#endif
/* APU_DSO_BUILD */
234
235
#endif
/* APR_HAS_LDAP */
apr_errno.h
APR Error Codes.
apr_pools.h
APR memory allocation.
apr_strings.h
APR Strings library.
apu_internal.h
hostname
const char * hostname
Definition
http_config.h:1184
APR_EGENERAL
#define APR_EGENERAL
Definition
apr_errno.h:313
size
apr_size_t size
Definition
apr_allocator.h:115
pool
const char int apr_pool_t * pool
Definition
apr_cstr.h:84
APR_SUCCESS
#define APR_SUCCESS
Definition
apr_errno.h:225
result
apr_array_header_t ** result
Definition
apr_fnmatch.h:144
apr_pcalloc
#define apr_pcalloc(p, size)
Definition
apr_pools.h:465
NULL
return NULL
Definition
mod_so.c:359
apr_pool_t
Definition
apr_pools.c:562
Generated by
1.9.8