1 /* backend.c - routines for dealing with back-end databases */
7 #include <sys/socket.h>
12 extern int ldbm_back_bind();
13 extern int ldbm_back_unbind();
14 extern int ldbm_back_search();
15 extern int ldbm_back_compare();
16 extern int ldbm_back_modify();
17 extern int ldbm_back_modrdn();
18 extern int ldbm_back_add();
19 extern int ldbm_back_delete();
20 extern int ldbm_back_abandon();
21 extern int ldbm_back_config();
22 extern int ldbm_back_init();
23 extern int ldbm_back_close();
24 extern int ldbm_back_group();
28 extern int passwd_back_search();
29 extern int passwd_back_config();
33 extern int shell_back_bind();
34 extern int shell_back_unbind();
35 extern int shell_back_search();
36 extern int shell_back_compare();
37 extern int shell_back_modify();
38 extern int shell_back_modrdn();
39 extern int shell_back_add();
40 extern int shell_back_delete();
41 extern int shell_back_abandon();
42 extern int shell_back_config();
43 extern int shell_back_init();
49 #define BACKEND_GRAB_SIZE 10
53 static int maxbackends;
63 if ( nbackends == maxbackends ) {
64 maxbackends += BACKEND_GRAB_SIZE;
65 backends = (Backend *) ch_realloc( (char *) backends,
66 maxbackends * sizeof(Backend) );
67 memset( &backends[nbackends], '\0', BACKEND_GRAB_SIZE *
71 be = &backends[nbackends++];
72 be->be_sizelimit = defsize;
73 be->be_timelimit = deftime;
77 if ( strcasecmp( type, "ldbm" ) == 0 ) {
78 be->be_bind = ldbm_back_bind;
79 be->be_unbind = ldbm_back_unbind;
80 be->be_search = ldbm_back_search;
81 be->be_compare = ldbm_back_compare;
82 be->be_modify = ldbm_back_modify;
83 be->be_modrdn = ldbm_back_modrdn;
84 be->be_add = ldbm_back_add;
85 be->be_delete = ldbm_back_delete;
86 be->be_abandon = ldbm_back_abandon;
87 be->be_config = ldbm_back_config;
88 be->be_init = ldbm_back_init;
89 be->be_close = ldbm_back_close;
91 be->be_group = ldbm_back_group;
99 if ( strcasecmp( type, "passwd" ) == 0 ) {
101 be->be_unbind = NULL;
102 be->be_search = passwd_back_search;
103 be->be_compare = NULL;
104 be->be_modify = NULL;
105 be->be_modrdn = NULL;
107 be->be_delete = NULL;
108 be->be_abandon = NULL;
109 be->be_config = passwd_back_config;
115 be->be_type = "passwd";
121 if ( strcasecmp( type, "shell" ) == 0 ) {
122 be->be_bind = shell_back_bind;
123 be->be_unbind = shell_back_unbind;
124 be->be_search = shell_back_search;
125 be->be_compare = shell_back_compare;
126 be->be_modify = shell_back_modify;
127 be->be_modrdn = shell_back_modrdn;
128 be->be_add = shell_back_add;
129 be->be_delete = shell_back_delete;
130 be->be_abandon = shell_back_abandon;
131 be->be_config = shell_back_config;
132 be->be_init = shell_back_init;
137 be->be_type = "shell";
142 if ( be->be_init != NULL ) {
143 (*be->be_init)( be );
146 if ( foundit == 0 ) {
147 fprintf( stderr, "Unrecognized database type (%s)\n", type );
155 select_backend( char * dn )
157 int i, j, len, dnlen;
159 dnlen = strlen( dn );
160 for ( i = 0; i < nbackends; i++ ) {
161 for ( j = 0; backends[i].be_suffix != NULL &&
162 backends[i].be_suffix[j] != NULL; j++ )
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
170 Debug( LDAP_DEBUG_TRACE,
171 "select_backend: use default backend\n", 0, 0, 0 );
172 return (&backends[i]);
174 #endif /* LDAP_ALLOW_NULL_SEARCH_BASE
176 len = strlen( backends[i].be_suffix[j] );
182 if ( strcasecmp( backends[i].be_suffix[j],
183 dn + (dnlen - len) ) == 0 ) {
184 return( &backends[i] );
200 for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) {
201 if ( strcasecmp( be->be_suffix[i], suffix ) == 0 ) {
210 be_isroot( Backend *be, char *dn )
216 return( be->be_rootdn ? strcasecmp( be->be_rootdn, dn ) == 0
221 be_isroot_pw( Backend *be, char *dn, struct berval *cred )
223 if ( ! be_isroot( be, dn ) || be->be_rootpw == NULL ) {
227 return( strcmp( be->be_rootpw, cred->bv_val ) == 0 );
235 for ( i = 0; i < nbackends; i++ ) {
236 if ( backends[i].be_close != NULL ) {
237 (*backends[i].be_close)( &backends[i] );
251 for ( i = 0; i < nbackends; i++ ) {
252 if ( backends[i].be_unbind != NULL ) {
253 (*backends[i].be_unbind)( &backends[i], conn, op );
260 be_group(Backend *be, char *bdn, char *edn)
263 return(be->be_group(be, bdn, edn));