]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/init.c
7e4fabca09e0194690f5f7cccd1287f72df2e5c3
[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 #include "portable.h"
30
31 #include <stdio.h>
32
33 #include <ac/socket.h>
34
35 #include "slap.h"
36 #include "back-ldap.h"
37
38 #ifdef SLAPD_LDAP_DYNAMIC
39
40 int back_ldap_LTX_init_module(int argc, char *argv[]) {
41     BackendInfo bi;
42
43     memset( &bi, '\0', sizeof(bi) );
44     bi.bi_type = "ldap";
45     bi.bi_init = ldap_back_initialize;
46
47     backend_add(&bi);
48     return 0;
49 }
50
51 #endif /* SLAPD_LDAP_DYNAMIC */
52
53 int
54 ldap_back_initialize(
55     BackendInfo *bi
56 )
57 {
58         bi->bi_open = 0;
59         bi->bi_config = 0;
60         bi->bi_close = 0;
61         bi->bi_destroy = 0;
62
63         bi->bi_db_init = ldap_back_db_init;
64         bi->bi_db_config = ldap_back_db_config;
65         bi->bi_db_open = 0;
66         bi->bi_db_close = 0;
67         bi->bi_db_destroy = ldap_back_db_destroy;
68
69         bi->bi_op_bind = ldap_back_bind;
70         bi->bi_op_unbind = 0;
71         bi->bi_op_search = ldap_back_search;
72         bi->bi_op_compare = ldap_back_compare;
73         bi->bi_op_modify = ldap_back_modify;
74         bi->bi_op_modrdn = ldap_back_modrdn;
75         bi->bi_op_add = ldap_back_add;
76         bi->bi_op_delete = ldap_back_delete;
77         bi->bi_op_abandon = 0;
78
79         bi->bi_extended = 0;
80
81         bi->bi_acl_group = ldap_back_group;
82         bi->bi_acl_attribute = ldap_back_attribute;
83         bi->bi_chk_referrals = 0;
84
85         bi->bi_connection_init = 0;
86         bi->bi_connection_destroy = ldap_back_conn_destroy;
87
88         return 0;
89 }
90
91 int
92 ldap_back_db_init(
93     Backend     *be
94 )
95 {
96         struct ldapinfo *li;
97
98         li = (struct ldapinfo *) ch_calloc( 1, sizeof(struct ldapinfo) );
99         ldap_pvt_thread_mutex_init( &li->conn_mutex );
100
101         be->be_private = li;
102
103         return li == NULL;
104 }
105
106 int
107 ldap_back_db_destroy(
108     Backend     *be
109 )
110 {
111         struct ldapinfo *li;
112
113         if (be->be_private) {
114                 li = (struct ldapinfo *)be->be_private;
115                 if (li->url) {
116                         free(li->url);
117                         li->url = NULL;
118                 }
119                 if (li->binddn) {
120                         free(li->binddn);
121                         li->binddn = NULL;
122                 }
123                 if (li->bindpw) {
124                         free(li->bindpw);
125                         li->bindpw = NULL;
126                 }
127                 ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
128         }
129
130         free( be->be_private );
131         return 0;
132 }