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";
109 if ( be->be_init != NULL ) {
110 (*be->be_init)( be );
113 if ( foundit == 0 ) {
114 fprintf( stderr, "Unrecognized database type (%s)\n", type );
122 select_backend( char * dn )
124 int i, j, len, dnlen;
126 dnlen = strlen( dn );
127 for ( i = 0; i < nbackends; i++ ) {
128 for ( j = 0; backends[i].be_suffix != NULL &&
129 backends[i].be_suffix[j] != NULL; j++ )
131 len = strlen( backends[i].be_suffix[j] );
137 if ( strcmp( backends[i].be_suffix[j],
138 dn + (dnlen - len) ) == 0 ) {
139 return( &backends[i] );
144 /* if no proper suffix could be found then check for aliases */
145 for ( i = 0; i < nbackends; i++ ) {
147 backends[i].be_suffixAlias != NULL &&
148 backends[i].be_suffixAlias[j] != NULL;
151 len = strlen( backends[i].be_suffixAlias[j] );
157 if ( strcmp( backends[i].be_suffixAlias[j],
158 dn + (dnlen - len) ) == 0 ) {
159 return( &backends[i] );
164 #ifdef LDAP_ALLOW_NULL_SEARCH_BASE
165 /* Add greg@greg.rim.or.jp
166 * It's quick hack for cheap client
167 * Some browser offer a NULL base at ldap_search
169 * Should only be used as a last resort. -Kdz
172 Debug( LDAP_DEBUG_TRACE,
173 "select_backend: use default backend\n", 0, 0, 0 );
174 return( &backends[0] );
176 #endif /* LDAP_ALLOW_NULL_SEARCH_BASE */
189 for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) {
190 if ( strcmp( be->be_suffix[i], suffix ) == 0 ) {
199 be_isroot( Backend *be, char *ndn )
203 if ( ndn == NULL || be->be_root_ndn == NULL ) {
207 rc = strcmp( be->be_root_ndn, ndn ) ? 0 : 1;
213 be_root_dn( Backend *be )
217 if ( be->be_root_dn == NULL ) {
221 return be->be_root_dn;
225 be_isroot_pw( Backend *be, char *ndn, struct berval *cred )
229 if ( ! be_isroot( be, ndn ) ) {
234 ldap_pvt_thread_mutex_lock( &crypt_mutex );
237 result = lutil_passwd( cred->bv_val, be->be_root_pw );
240 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
251 for ( i = 0; i < nbackends; i++ ) {
252 if ( backends[i].be_close != NULL ) {
253 (*backends[i].be_close)( &backends[i] );
267 for ( i = 0; i < nbackends; i++ ) {
268 if ( backends[i].be_unbind != NULL ) {
269 (*backends[i].be_unbind)( &backends[i], conn, op );
274 #ifdef SLAPD_ACLGROUPS
281 char *objectclassValue,
286 return( be->be_group(be, target, gr_ndn, op_ndn,
287 objectclassValue, groupattrName) );