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