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