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 ( strcasecmp( 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 ( strcasecmp( 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 ( strcasecmp( be->be_suffix[i], suffix ) == 0 ) {
226 be_isroot( Backend *be, char *dn )
232 return( be->be_rootdn != NULL
233 ? strcasecmp( be->be_rootdn, dn ) == 0
238 be_isroot_pw( Backend *be, char *dn, struct berval *cred )
242 if ( ! be_isroot( be, dn ) ) {
247 pthread_mutex_lock( &crypt_mutex );
250 result = lutil_passwd( cred->bv_val, be->be_rootpw );
253 pthread_mutex_unlock( &crypt_mutex );
264 for ( i = 0; i < nbackends; i++ ) {
265 if ( backends[i].be_close != NULL ) {
266 (*backends[i].be_close)( &backends[i] );
280 for ( i = 0; i < nbackends; i++ ) {
281 if ( backends[i].be_unbind != NULL ) {
282 (*backends[i].be_unbind)( &backends[i], conn, op );
287 #ifdef SLAPD_ACLGROUPS
294 char *objectclassValue,
299 return(be->be_group(be, e, bdn, edn,
300 objectclassValue, groupattrName));