1 /* backend.c - routines for dealing with back-end databases */
16 #define BACKEND_GRAB_SIZE 10
20 static int maxbackends;
30 if ( nbackends == maxbackends ) {
31 maxbackends += BACKEND_GRAB_SIZE;
32 backends = (Backend *) ch_realloc( (char *) backends,
33 maxbackends * sizeof(Backend) );
34 memset( &backends[nbackends], '\0', BACKEND_GRAB_SIZE *
38 be = &backends[nbackends++];
39 be->be_sizelimit = defsize;
40 be->be_timelimit = deftime;
44 if ( strcasecmp( type, "ldbm" ) == 0 ) {
45 be->be_bind = ldbm_back_bind;
46 be->be_unbind = ldbm_back_unbind;
47 be->be_search = ldbm_back_search;
48 be->be_compare = ldbm_back_compare;
49 be->be_modify = ldbm_back_modify;
50 be->be_modrdn = ldbm_back_modrdn;
51 be->be_add = ldbm_back_add;
52 be->be_delete = ldbm_back_delete;
53 be->be_abandon = ldbm_back_abandon;
54 be->be_config = ldbm_back_config;
55 be->be_init = ldbm_back_init;
56 be->be_close = ldbm_back_close;
57 #ifdef SLAPD_ACLGROUPS
58 be->be_group = ldbm_back_group;
66 if ( strcasecmp( type, "passwd" ) == 0 ) {
69 be->be_search = passwd_back_search;
70 be->be_compare = NULL;
75 be->be_abandon = NULL;
76 be->be_config = passwd_back_config;
79 #ifdef SLAPD_ACLGROUPS
82 be->be_type = "passwd";
88 if ( strcasecmp( type, "shell" ) == 0 ) {
89 be->be_bind = shell_back_bind;
90 be->be_unbind = shell_back_unbind;
91 be->be_search = shell_back_search;
92 be->be_compare = shell_back_compare;
93 be->be_modify = shell_back_modify;
94 be->be_modrdn = shell_back_modrdn;
95 be->be_add = shell_back_add;
96 be->be_delete = shell_back_delete;
97 be->be_abandon = shell_back_abandon;
98 be->be_config = shell_back_config;
99 be->be_init = shell_back_init;
101 #ifdef SLAPD_ACLGROUPS
104 be->be_type = "shell";
111 if ( strcasecmp( type, "perl" ) == 0 ) {
113 be->be_abandon = perl_back_abandon;
114 be->be_bind = perl_back_bind;
116 be->be_abandon = NULL;
119 be->be_unbind = perl_back_unbind;
120 be->be_search = perl_back_search;
121 be->be_compare = perl_back_compare;
122 be->be_modify = perl_back_modify;
123 be->be_modrdn = perl_back_modrdn;
124 be->be_add = perl_back_add;
125 be->be_delete = perl_back_delete;
126 be->be_config = perl_back_config;
127 be->be_init = perl_back_init;
128 be->be_close = perl_back_close;
129 be->be_type = "perl";
136 if ( be->be_init != NULL ) {
137 (*be->be_init)( be );
140 if ( foundit == 0 ) {
141 fprintf( stderr, "Unrecognized database type (%s)\n", type );
149 select_backend( char * dn )
151 int i, j, len, dnlen;
153 dnlen = strlen( dn );
154 for ( i = 0; i < nbackends; i++ ) {
155 for ( j = 0; backends[i].be_suffix != NULL &&
156 backends[i].be_suffix[j] != NULL; j++ )
158 len = strlen( backends[i].be_suffix[j] );
164 if ( strcmp( backends[i].be_suffix[j],
165 dn + (dnlen - len) ) == 0 ) {
166 return( &backends[i] );
171 /* if no proper suffix could be found then check for aliases */
172 for ( i = 0; i < nbackends; i++ ) {
174 backends[i].be_suffixAlias != NULL &&
175 backends[i].be_suffixAlias[j] != NULL;
178 len = strlen( backends[i].be_suffixAlias[j] );
184 if ( strcmp( backends[i].be_suffixAlias[j],
185 dn + (dnlen - len) ) == 0 ) {
186 return( &backends[i] );
191 #ifdef LDAP_ALLOW_NULL_SEARCH_BASE
192 /* Add greg@greg.rim.or.jp
193 * It's quick hack for cheap client
194 * Some browser offer a NULL base at ldap_search
196 * Should only be used as a last resort. -Kdz
199 Debug( LDAP_DEBUG_TRACE,
200 "select_backend: use default backend\n", 0, 0, 0 );
201 return( &backends[0] );
203 #endif /* LDAP_ALLOW_NULL_SEARCH_BASE */
216 for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) {
217 if ( strcmp( be->be_suffix[i], suffix ) == 0 ) {
226 be_isroot( Backend *be, char *ndn )
230 if ( ndn == NULL || be->be_root_ndn == NULL ) {
234 rc = strcmp( be->be_root_ndn, ndn ) ? 0 : 1;
240 be_root_dn( Backend *be )
244 if ( be->be_root_dn == NULL ) {
248 return be->be_root_dn;
252 be_isroot_pw( Backend *be, char *ndn, struct berval *cred )
256 if ( ! be_isroot( be, ndn ) ) {
261 ldap_pvt_thread_mutex_lock( &crypt_mutex );
264 result = lutil_passwd( cred->bv_val, be->be_root_pw );
267 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
278 for ( i = 0; i < nbackends; i++ ) {
279 if ( backends[i].be_close != NULL ) {
280 (*backends[i].be_close)( &backends[i] );
294 for ( i = 0; i < nbackends; i++ ) {
295 if ( backends[i].be_unbind != NULL ) {
296 (*backends[i].be_unbind)( &backends[i], conn, op );
301 #ifdef SLAPD_ACLGROUPS
308 char *objectclassValue,
313 return( be->be_group(be, target, gr_ndn, op_ndn,
314 objectclassValue, groupattrName) );