]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/apr-util/ldap/apr_ldap_stub.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / apr-util / ldap / apr_ldap_stub.c
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 #include "apr.h"
18 #include "apu.h"
19 #include "apu_config.h"
20 #include "apr_ldap.h"
21 #include "apu_internal.h"
22 #include "apr_dso.h"
23 #include "apr_errno.h"
24 #include "apr_pools.h"
25 #include "apr_strings.h"
26 #include "apu_version.h"
27
28 #if APR_HAS_LDAP
29
30 #if APU_DSO_BUILD
31
32 static struct apr__ldap_dso_fntable *lfn = NULL;
33
34 static apr_status_t load_ldap(apr_pool_t *pool)
35 {
36     char *modname;
37     apr_dso_handle_sym_t symbol;
38     apr_status_t rv;
39
40     /* deprecate in 2.0 - permit implicit initialization */
41     apu_dso_init(pool);
42
43     rv = apu_dso_mutex_lock();
44     if (rv) {
45         return rv;
46     }
47
48 #if defined(WIN32)
49     modname = "apr_ldap-" APU_STRINGIFY(APU_MAJOR_VERSION) ".dll";
50 #else
51     modname = "apr_ldap-" APU_STRINGIFY(APU_MAJOR_VERSION) ".so";
52 #endif
53     rv = apu_dso_load(NULL, &symbol, modname, "apr__ldap_fns", pool);
54     if (rv == APR_SUCCESS) {
55         lfn = symbol;
56     }
57     apu_dso_mutex_unlock();
58
59     return rv;
60 }
61
62 #define LOAD_LDAP_STUB(pool, failres) \
63     if (!lfn && (load_ldap(pool) != APR_SUCCESS)) \
64         return failres;
65
66 APU_DECLARE_LDAP(int) apr_ldap_info(apr_pool_t *pool,
67                                     apr_ldap_err_t **result_err)
68 {
69     LOAD_LDAP_STUB(pool, -1);
70     return lfn->info(pool, result_err);
71 }
72
73 APU_DECLARE_LDAP(int) apr_ldap_init(apr_pool_t *pool,
74                                     LDAP **ldap,
75                                     const char *hostname,
76                                     int portno,
77                                     int secure,
78                                     apr_ldap_err_t **result_err)
79 {
80     LOAD_LDAP_STUB(pool, -1);
81     return lfn->init(pool, ldap, hostname, portno, secure, result_err);
82 }
83
84 APU_DECLARE_LDAP(int) apr_ldap_ssl_init(apr_pool_t *pool,
85                                         const char *cert_auth_file,
86                                         int cert_file_type,
87                                         apr_ldap_err_t **result_err)
88 {
89     LOAD_LDAP_STUB(pool, -1);
90     return lfn->ssl_init(pool, cert_auth_file, cert_file_type, result_err);
91 }
92
93 APU_DECLARE_LDAP(int) apr_ldap_ssl_deinit(void)
94 {
95     if (!lfn)
96         return -1;
97     return lfn->ssl_deinit();
98 }
99
100 APU_DECLARE_LDAP(int) apr_ldap_get_option(apr_pool_t *pool,
101                                           LDAP *ldap,
102                                           int option,
103                                           void *outvalue,
104                                           apr_ldap_err_t **result_err)
105 {
106     LOAD_LDAP_STUB(pool, -1);
107     return lfn->get_option(pool, ldap, option, outvalue, result_err);
108 }
109
110 APU_DECLARE_LDAP(int) apr_ldap_set_option(apr_pool_t *pool,
111                                           LDAP *ldap,
112                                           int option,
113                                           const void *invalue,
114                                           apr_ldap_err_t **result_err)
115 {
116     LOAD_LDAP_STUB(pool, -1);
117     return lfn->set_option(pool, ldap, option, invalue, result_err);
118 }
119
120 APU_DECLARE_LDAP(apr_status_t) apr_ldap_rebind_init(apr_pool_t *pool)
121 {
122     LOAD_LDAP_STUB(pool, APR_EGENERAL);
123     return lfn->rebind_init(pool);
124 }
125
126 APU_DECLARE_LDAP(apr_status_t) apr_ldap_rebind_add(apr_pool_t *pool,
127                                                    LDAP *ld,
128                                                    const char *bindDN,
129                                                    const char *bindPW)
130 {
131     LOAD_LDAP_STUB(pool, APR_EGENERAL);
132     return lfn->rebind_add(pool, ld, bindDN, bindPW);
133 }
134
135 APU_DECLARE_LDAP(apr_status_t) apr_ldap_rebind_remove(LDAP *ld)
136 {
137     if (!lfn)
138         return APR_EGENERAL;
139     return lfn->rebind_remove(ld);
140 }
141
142 #endif /* APU_DSO_BUILD */
143
144 #endif /* APR_HAS_LDAP */
145