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 be->be_startup = ldbm_back_startup;
58 be->be_shutdown = ldbm_back_shutdown;
59 #ifdef SLAPD_ACLGROUPS
60 be->be_group = ldbm_back_group;
68 if ( strcasecmp( type, "passwd" ) == 0 ) {
71 be->be_search = passwd_back_search;
72 be->be_compare = NULL;
77 be->be_abandon = NULL;
78 be->be_config = passwd_back_config;
81 #ifdef SLAPD_ACLGROUPS
84 be->be_type = "passwd";
90 if ( strcasecmp( type, "shell" ) == 0 ) {
91 be->be_bind = shell_back_bind;
92 be->be_unbind = shell_back_unbind;
93 be->be_search = shell_back_search;
94 be->be_compare = shell_back_compare;
95 be->be_modify = shell_back_modify;
96 be->be_modrdn = shell_back_modrdn;
97 be->be_add = shell_back_add;
98 be->be_delete = shell_back_delete;
99 be->be_abandon = shell_back_abandon;
100 be->be_config = shell_back_config;
101 be->be_init = shell_back_init;
103 #ifdef SLAPD_ACLGROUPS
106 be->be_type = "shell";
113 if ( strcasecmp( type, "perl" ) == 0 ) {
115 be->be_abandon = perl_back_abandon;
116 be->be_bind = perl_back_bind;
118 be->be_abandon = NULL;
121 be->be_unbind = perl_back_unbind;
122 be->be_search = perl_back_search;
123 be->be_compare = perl_back_compare;
124 be->be_modify = perl_back_modify;
125 be->be_modrdn = perl_back_modrdn;
126 be->be_add = perl_back_add;
127 be->be_delete = perl_back_delete;
128 be->be_config = perl_back_config;
129 be->be_init = perl_back_init;
130 be->be_close = perl_back_close;
131 be->be_type = "perl";
138 if ( be->be_init != NULL ) {
139 (*be->be_init)( be );
142 if ( foundit == 0 ) {
143 fprintf( stderr, "Unrecognized database type (%s)\n", type );
151 select_backend( char * dn )
153 int i, j, len, dnlen;
155 dnlen = strlen( dn );
156 for ( i = 0; i < nbackends; i++ ) {
157 for ( j = 0; backends[i].be_suffix != NULL &&
158 backends[i].be_suffix[j] != NULL; j++ )
160 len = strlen( backends[i].be_suffix[j] );
166 if ( strcmp( backends[i].be_suffix[j],
167 dn + (dnlen - len) ) == 0 ) {
168 return( &backends[i] );
173 /* if no proper suffix could be found then check for aliases */
174 for ( i = 0; i < nbackends; i++ ) {
176 backends[i].be_suffixAlias != NULL &&
177 backends[i].be_suffixAlias[j] != NULL;
180 len = strlen( backends[i].be_suffixAlias[j] );
186 if ( strcmp( backends[i].be_suffixAlias[j],
187 dn + (dnlen - len) ) == 0 ) {
188 return( &backends[i] );
193 #ifdef LDAP_ALLOW_NULL_SEARCH_BASE
194 /* Add greg@greg.rim.or.jp
195 * It's quick hack for cheap client
196 * Some browser offer a NULL base at ldap_search
198 * Should only be used as a last resort. -Kdz
201 Debug( LDAP_DEBUG_TRACE,
202 "select_backend: use default backend\n", 0, 0, 0 );
203 return( &backends[0] );
205 #endif /* LDAP_ALLOW_NULL_SEARCH_BASE */
218 for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) {
219 if ( strcmp( be->be_suffix[i], suffix ) == 0 ) {
228 be_isroot( Backend *be, char *ndn )
232 if ( ndn == NULL || be->be_root_ndn == NULL ) {
236 rc = strcmp( be->be_root_ndn, ndn ) ? 0 : 1;
242 be_root_dn( Backend *be )
246 if ( be->be_root_dn == NULL ) {
250 return be->be_root_dn;
254 be_isroot_pw( Backend *be, char *ndn, struct berval *cred )
258 if ( ! be_isroot( be, ndn ) ) {
263 ldap_pvt_thread_mutex_lock( &crypt_mutex );
266 result = lutil_passwd( cred->bv_val, be->be_root_pw );
269 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
280 for ( i = 0; i < nbackends; i++ ) {
281 if ( backends[i].be_startup != NULL ) {
282 (*backends[i].be_startup)( &backends[i] );
293 for ( i = 0; i < nbackends; i++ ) {
294 if ( backends[i].be_shutdown != NULL ) {
295 (*backends[i].be_shutdown)( &backends[i] );
306 for ( i = 0; i < nbackends; i++ ) {
307 if ( backends[i].be_close != NULL ) {
308 (*backends[i].be_close)( &backends[i] );
322 for ( i = 0; i < nbackends; i++ ) {
323 if ( backends[i].be_unbind != NULL ) {
324 (*backends[i].be_unbind)( &backends[i], conn, op );
329 #ifdef SLAPD_ACLGROUPS
336 char *objectclassValue,
341 return( be->be_group(be, target, gr_ndn, op_ndn,
342 objectclassValue, groupattrName) );