1998-08-09 08:43:13 +08:00
|
|
|
/* backend.c - routines for dealing with back-end databases */
|
|
|
|
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/stat.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define BACKEND_GRAB_SIZE 10
|
|
|
|
|
|
|
|
int nbackends;
|
|
|
|
Backend *backends;
|
|
|
|
static int maxbackends;
|
|
|
|
|
|
|
|
Backend *
|
|
|
|
new_backend(
|
|
|
|
char *type
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Backend *be;
|
|
|
|
int foundit;
|
|
|
|
|
|
|
|
if ( nbackends == maxbackends ) {
|
|
|
|
maxbackends += BACKEND_GRAB_SIZE;
|
|
|
|
backends = (Backend *) ch_realloc( (char *) backends,
|
|
|
|
maxbackends * sizeof(Backend) );
|
|
|
|
memset( &backends[nbackends], '\0', BACKEND_GRAB_SIZE *
|
|
|
|
sizeof(Backend) );
|
|
|
|
}
|
|
|
|
|
|
|
|
be = &backends[nbackends++];
|
|
|
|
be->be_sizelimit = defsize;
|
|
|
|
be->be_timelimit = deftime;
|
|
|
|
foundit = 0;
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_LDBM
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( strcasecmp( type, "ldbm" ) == 0 ) {
|
|
|
|
be->be_bind = ldbm_back_bind;
|
|
|
|
be->be_unbind = ldbm_back_unbind;
|
|
|
|
be->be_search = ldbm_back_search;
|
|
|
|
be->be_compare = ldbm_back_compare;
|
|
|
|
be->be_modify = ldbm_back_modify;
|
|
|
|
be->be_modrdn = ldbm_back_modrdn;
|
|
|
|
be->be_add = ldbm_back_add;
|
|
|
|
be->be_delete = ldbm_back_delete;
|
|
|
|
be->be_abandon = ldbm_back_abandon;
|
|
|
|
be->be_config = ldbm_back_config;
|
|
|
|
be->be_init = ldbm_back_init;
|
|
|
|
be->be_close = ldbm_back_close;
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_ACLGROUPS
|
1998-08-21 14:33:42 +08:00
|
|
|
be->be_group = ldbm_back_group;
|
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
be->be_type = "ldbm";
|
|
|
|
foundit = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_PASSWD
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( strcasecmp( type, "passwd" ) == 0 ) {
|
|
|
|
be->be_bind = NULL;
|
|
|
|
be->be_unbind = NULL;
|
|
|
|
be->be_search = passwd_back_search;
|
|
|
|
be->be_compare = NULL;
|
|
|
|
be->be_modify = NULL;
|
|
|
|
be->be_modrdn = NULL;
|
|
|
|
be->be_add = NULL;
|
|
|
|
be->be_delete = NULL;
|
|
|
|
be->be_abandon = NULL;
|
|
|
|
be->be_config = passwd_back_config;
|
|
|
|
be->be_init = NULL;
|
|
|
|
be->be_close = NULL;
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_ACLGROUPS
|
1998-08-21 14:33:42 +08:00
|
|
|
be->be_group = NULL;
|
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
be->be_type = "passwd";
|
|
|
|
foundit = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_SHELL
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( strcasecmp( type, "shell" ) == 0 ) {
|
|
|
|
be->be_bind = shell_back_bind;
|
|
|
|
be->be_unbind = shell_back_unbind;
|
|
|
|
be->be_search = shell_back_search;
|
|
|
|
be->be_compare = shell_back_compare;
|
|
|
|
be->be_modify = shell_back_modify;
|
|
|
|
be->be_modrdn = shell_back_modrdn;
|
|
|
|
be->be_add = shell_back_add;
|
|
|
|
be->be_delete = shell_back_delete;
|
|
|
|
be->be_abandon = shell_back_abandon;
|
|
|
|
be->be_config = shell_back_config;
|
|
|
|
be->be_init = shell_back_init;
|
|
|
|
be->be_close = NULL;
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_ACLGROUPS
|
1998-08-21 14:33:42 +08:00
|
|
|
be->be_group = NULL;
|
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
be->be_type = "shell";
|
|
|
|
foundit = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( be->be_init != NULL ) {
|
|
|
|
(*be->be_init)( be );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( foundit == 0 ) {
|
|
|
|
fprintf( stderr, "Unrecognized database type (%s)\n", type );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( be );
|
|
|
|
}
|
|
|
|
|
|
|
|
Backend *
|
|
|
|
select_backend( char * dn )
|
|
|
|
{
|
|
|
|
int i, j, len, dnlen;
|
|
|
|
|
|
|
|
dnlen = strlen( dn );
|
|
|
|
for ( i = 0; i < nbackends; i++ ) {
|
|
|
|
for ( j = 0; backends[i].be_suffix != NULL &&
|
1998-09-06 04:33:22 +08:00
|
|
|
backends[i].be_suffix[j] != NULL; j++ )
|
|
|
|
{
|
|
|
|
#ifdef LDAP_ALLOW_NULL_SEARCH_BASE
|
|
|
|
/* Add greg@greg.rim.or.jp
|
|
|
|
* It's quick hack for cheap client
|
|
|
|
* Some browser offer a NULL base at ldap_search
|
|
|
|
*/
|
|
|
|
if(dnlen == 0) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"select_backend: use default backend\n", 0, 0, 0 );
|
|
|
|
return (&backends[i]);
|
|
|
|
}
|
1998-09-07 16:32:30 +08:00
|
|
|
#endif /* LDAP_ALLOW_NULL_SEARCH_BASE */
|
1998-09-06 04:33:22 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
len = strlen( backends[i].be_suffix[j] );
|
|
|
|
|
|
|
|
if ( len > dnlen ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( backends[i].be_suffix[j],
|
|
|
|
dn + (dnlen - len) ) == 0 ) {
|
|
|
|
return( &backends[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-24 10:42:38 +08:00
|
|
|
/* if no proper suffix could be found then check for aliases */
|
|
|
|
for ( i = 0; i < nbackends; i++ ) {
|
|
|
|
for ( j = 0;
|
|
|
|
backends[i].be_suffixAlias != NULL &&
|
|
|
|
backends[i].be_suffixAlias[j] != NULL;
|
|
|
|
j += 2 )
|
|
|
|
{
|
|
|
|
len = strlen( backends[i].be_suffixAlias[j] );
|
|
|
|
|
|
|
|
if ( len > dnlen ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( backends[i].be_suffixAlias[j],
|
|
|
|
dn + (dnlen - len) ) == 0 ) {
|
|
|
|
return( &backends[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
be_issuffix(
|
|
|
|
Backend *be,
|
|
|
|
char *suffix
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) {
|
|
|
|
if ( strcasecmp( be->be_suffix[i], suffix ) == 0 ) {
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
be_isroot( Backend *be, char *dn )
|
|
|
|
{
|
|
|
|
if ( dn == NULL ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
return( be->be_rootdn != NULL
|
|
|
|
? strcasecmp( be->be_rootdn, dn ) == 0
|
1998-08-09 08:43:13 +08:00
|
|
|
: 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
be_isroot_pw( Backend *be, char *dn, struct berval *cred )
|
|
|
|
{
|
1998-12-01 11:36:37 +08:00
|
|
|
if ( ! be_isroot( be, dn ) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
1998-12-01 11:36:37 +08:00
|
|
|
return( lutil_passwd( cred->bv_val, be->be_rootpw ) == 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
be_close( void )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < nbackends; i++ ) {
|
|
|
|
if ( backends[i].be_close != NULL ) {
|
|
|
|
(*backends[i].be_close)( &backends[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
be_unbind(
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < nbackends; i++ ) {
|
|
|
|
if ( backends[i].be_unbind != NULL ) {
|
|
|
|
(*backends[i].be_unbind)( &backends[i], conn, op );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef SLAPD_ACLGROUPS
|
1998-08-21 14:33:42 +08:00
|
|
|
int
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
be_group(
|
|
|
|
Backend *be,
|
|
|
|
char *bdn,
|
|
|
|
char *edn,
|
|
|
|
char *objectclassValue,
|
|
|
|
char *groupattrName
|
|
|
|
)
|
1998-08-21 14:33:42 +08:00
|
|
|
{
|
|
|
|
if (be->be_group)
|
1998-10-27 10:07:12 +08:00
|
|
|
return(be->be_group(be, bdn, edn, objectclassValue, groupattrName));
|
1998-08-21 14:33:42 +08:00
|
|
|
else
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#endif
|