]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/init.c
ac306acef0e0183c48b1b3b107c632da49a06377
[openldap] / servers / slapd / back-ldap / init.c
1 /* init.c - initialize ldap backend */
2 /* $OpenLDAP$ */
3
4 /*
5  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
6  * 
7  * Permission is granted to anyone to use this software for any purpose
8  * on any computer system, and to alter it and redistribute it, subject
9  * to the following restrictions:
10  * 
11  * 1. The author is not responsible for the consequences of use of this
12  *    software, no matter how awful, even if they arise from flaws in it.
13  * 
14  * 2. The origin of this software must not be misrepresented, either by
15  *    explicit claim or by omission.  Since few users ever read sources,
16  *    credits should appear in the documentation.
17  * 
18  * 3. Altered versions must be plainly marked as such, and must not be
19  *    misrepresented as being the original software.  Since few users
20  *    ever read sources, credits should appear in the documentation.
21  * 
22  * 4. This notice may not be removed or altered.
23  */
24
25 #include "portable.h"
26
27 #include <stdio.h>
28
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33
34 #ifdef SLAPD_LDAP_DYNAMIC
35
36 int back_ldap_LTX_init_module(int argc, char *argv[]) {
37     BackendInfo bi;
38
39     memset( &bi, '\0', sizeof(bi) );
40     bi.bi_type = "ldap";
41     bi.bi_init = ldap_back_initialize;
42
43     backend_add(&bi);
44     return 0;
45 }
46
47 #endif /* SLAPD_LDAP_DYNAMIC */
48
49 int
50 ldap_back_initialize(
51     BackendInfo *bi
52 )
53 {
54         bi->bi_open = 0;
55         bi->bi_config = 0;
56         bi->bi_close = 0;
57         bi->bi_destroy = 0;
58
59         bi->bi_db_init = ldap_back_db_init;
60         bi->bi_db_config = ldap_back_db_config;
61         bi->bi_db_open = 0;
62         bi->bi_db_close = 0;
63         bi->bi_db_destroy = ldap_back_db_destroy;
64
65         bi->bi_op_bind = ldap_back_bind;
66         bi->bi_op_unbind = 0;
67         bi->bi_op_search = ldap_back_search;
68         bi->bi_op_compare = ldap_back_compare;
69         bi->bi_op_modify = ldap_back_modify;
70         bi->bi_op_modrdn = ldap_back_modrdn;
71         bi->bi_op_add = ldap_back_add;
72         bi->bi_op_delete = ldap_back_delete;
73         bi->bi_op_abandon = 0;
74
75         bi->bi_extended = 0;
76
77         bi->bi_acl_group = ldap_back_group;
78         bi->bi_acl_attribute = 0;
79         bi->bi_chk_referrals = 0;
80
81 #ifdef HAVE_CYRUS_SASL
82         bi->bi_sasl_authorize = 0;
83         bi->bi_sasl_getsecret = 0;
84         bi->bi_sasl_putsecret = 0;
85 #endif /* HAVE_CYRUS_SASL */
86
87         bi->bi_connection_init = 0;
88         bi->bi_connection_destroy = ldap_back_conn_destroy;
89
90         return 0;
91 }
92
93 int
94 ldap_back_db_init(
95     Backend     *be
96 )
97 {
98         struct ldapinfo *li;
99
100         li = (struct ldapinfo *) ch_calloc( 1, sizeof(struct ldapinfo) );
101         ldap_pvt_thread_mutex_init( &li->conn_mutex );
102
103         be->be_private = li;
104
105         return li == NULL;
106 }
107
108 int
109 ldap_back_db_destroy(
110     Backend     *be
111 )
112 {
113         struct ldapinfo *li;
114
115         if (be->be_private) {
116                 li = (struct ldapinfo *)be->be_private;
117                 if (li->url) {
118                         free(li->url);
119                         li->url = NULL;
120                 }
121                 if (li->binddn) {
122                         free(li->binddn);
123                         li->binddn = NULL;
124                 }
125                 if (li->bindpw) {
126                         free(li->bindpw);
127                         li->bindpw = NULL;
128                 }
129                 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
130         }
131
132         free( be->be_private );
133         return 0;
134 }