1 /* backend.c - routines for dealing with back-end databases */
16 extern int ldbm_back_bind();
17 extern int ldbm_back_unbind();
18 extern int ldbm_back_search();
19 extern int ldbm_back_compare();
20 extern int ldbm_back_modify();
21 extern int ldbm_back_modrdn();
22 extern int ldbm_back_add();
23 extern int ldbm_back_delete();
24 extern int ldbm_back_abandon();
25 extern int ldbm_back_config();
26 extern int ldbm_back_init();
27 extern int ldbm_back_close();
28 extern int ldbm_back_group();
32 extern int passwd_back_search();
33 extern int passwd_back_config();
37 extern int shell_back_bind();
38 extern int shell_back_unbind();
39 extern int shell_back_search();
40 extern int shell_back_compare();
41 extern int shell_back_modify();
42 extern int shell_back_modrdn();
43 extern int shell_back_add();
44 extern int shell_back_delete();
45 extern int shell_back_abandon();
46 extern int shell_back_config();
47 extern int shell_back_init();
53 #define BACKEND_GRAB_SIZE 10
57 static int maxbackends;
67 if ( nbackends == maxbackends ) {
68 maxbackends += BACKEND_GRAB_SIZE;
69 backends = (Backend *) ch_realloc( (char *) backends,
70 maxbackends * sizeof(Backend) );
71 memset( &backends[nbackends], '\0', BACKEND_GRAB_SIZE *
75 be = &backends[nbackends++];
76 be->be_sizelimit = defsize;
77 be->be_timelimit = deftime;
81 if ( strcasecmp( type, "ldbm" ) == 0 ) {
82 be->be_bind = ldbm_back_bind;
83 be->be_unbind = ldbm_back_unbind;
84 be->be_search = ldbm_back_search;
85 be->be_compare = ldbm_back_compare;
86 be->be_modify = ldbm_back_modify;
87 be->be_modrdn = ldbm_back_modrdn;
88 be->be_add = ldbm_back_add;
89 be->be_delete = ldbm_back_delete;
90 be->be_abandon = ldbm_back_abandon;
91 be->be_config = ldbm_back_config;
92 be->be_init = ldbm_back_init;
93 be->be_close = ldbm_back_close;
94 #ifdef SLAPD_ACLGROUPS
95 be->be_group = ldbm_back_group;
103 if ( strcasecmp( type, "passwd" ) == 0 ) {
105 be->be_unbind = NULL;
106 be->be_search = passwd_back_search;
107 be->be_compare = NULL;
108 be->be_modify = NULL;
109 be->be_modrdn = NULL;
111 be->be_delete = NULL;
112 be->be_abandon = NULL;
113 be->be_config = passwd_back_config;
116 #ifdef SLAPD_ACLGROUPS
119 be->be_type = "passwd";
125 if ( strcasecmp( type, "shell" ) == 0 ) {
126 be->be_bind = shell_back_bind;
127 be->be_unbind = shell_back_unbind;
128 be->be_search = shell_back_search;
129 be->be_compare = shell_back_compare;
130 be->be_modify = shell_back_modify;
131 be->be_modrdn = shell_back_modrdn;
132 be->be_add = shell_back_add;
133 be->be_delete = shell_back_delete;
134 be->be_abandon = shell_back_abandon;
135 be->be_config = shell_back_config;
136 be->be_init = shell_back_init;
138 #ifdef SLAPD_ACLGROUPS
141 be->be_type = "shell";
146 if ( be->be_init != NULL ) {
147 (*be->be_init)( be );
150 if ( foundit == 0 ) {
151 fprintf( stderr, "Unrecognized database type (%s)\n", type );
159 select_backend( char * dn )
161 int i, j, len, dnlen;
163 dnlen = strlen( dn );
164 for ( i = 0; i < nbackends; i++ ) {
165 for ( j = 0; backends[i].be_suffix != NULL &&
166 backends[i].be_suffix[j] != NULL; j++ )
168 #ifdef LDAP_ALLOW_NULL_SEARCH_BASE
169 /* Add greg@greg.rim.or.jp
170 * It's quick hack for cheap client
171 * Some browser offer a NULL base at ldap_search
174 Debug( LDAP_DEBUG_TRACE,
175 "select_backend: use default backend\n", 0, 0, 0 );
176 return (&backends[i]);
178 #endif /* LDAP_ALLOW_NULL_SEARCH_BASE */
180 len = strlen( backends[i].be_suffix[j] );
186 if ( strcasecmp( backends[i].be_suffix[j],
187 dn + (dnlen - len) ) == 0 ) {
188 return( &backends[i] );
193 /* if no proper suffix could be found then check for aliases */
194 for ( i = 0; i < nbackends; i++ ) {
196 backends[i].be_suffixAlias != NULL &&
197 backends[i].be_suffixAlias[j] != NULL;
200 len = strlen( backends[i].be_suffixAlias[j] );
206 if ( strcasecmp( backends[i].be_suffixAlias[j],
207 dn + (dnlen - len) ) == 0 ) {
208 return( &backends[i] );
225 for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) {
226 if ( strcasecmp( be->be_suffix[i], suffix ) == 0 ) {
235 be_isroot( Backend *be, char *dn )
241 return( be->be_rootdn ? strcasecmp( be->be_rootdn, dn ) == 0
246 be_isroot_pw( Backend *be, char *dn, struct berval *cred )
248 if ( ! be_isroot( be, dn ) || be->be_rootpw == NULL ) {
252 return( strcmp( be->be_rootpw, cred->bv_val ) == 0 );
260 for ( i = 0; i < nbackends; i++ ) {
261 if ( backends[i].be_close != NULL ) {
262 (*backends[i].be_close)( &backends[i] );
276 for ( i = 0; i < nbackends; i++ ) {
277 if ( backends[i].be_unbind != NULL ) {
278 (*backends[i].be_unbind)( &backends[i], conn, op );
283 #ifdef SLAPD_ACLGROUPS
285 be_group(Backend *be, char *bdn, char *edn)
288 return(be->be_group(be, bdn, edn));