Skip to content
Snippets Groups Projects
Commit 216049bd authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

New Frontend->Backend Interface

Separates per backend type from per backend database initialization
	and startup.  Also supports per type / per backend shutdown.
New frontend startup/shutdown routines are also provided:
	slap_init() slap_startup() slap_shutdown() slap_destroy()
New frontend->backend startup/shutdown is managed by:
	backend_init() backend_startup() backend_shutdown backend_destroy
backend_init() now calls bi_init() to initial all function pointers
for the backend (excepting bi_init() which is now the only hardcoded
entry point).  New entry points are detailed in slap.h struct
backend_info.  backend_info is a per database type structure.
Besides the new startup/shutdown entry points, the new interface
also supports per backend type configuration options.  One could have:

	backend bdb2	(new Berkeley DB 2 backend)
	bdb2_home	/directory

	database bdb2
	...

	*** This code is fairly experimental ***
	*** Much cleanup and testing is still needed ***

see slap.h for details on struct backend_db and backend_info.
parent cd9ab253
No related branches found
No related tags found
No related merge requests found
Showing
with 415 additions and 60 deletions
......@@ -202,7 +202,9 @@ LDAP_END_DECL
LDAP_BEGIN_DECL
void ldbm_initialize( void );
int ldbm_initialize( void );
int ldbm_shutdown( void );
int ldbm_errno( LDBM ldbm );
LDBM ldbm_open( char *name, int rw, int mode, int dbcachesize );
void ldbm_close( LDBM ldbm );
......
......@@ -48,6 +48,8 @@ ldbm_datum_dup( LDBM ldbm, Datum data )
return( dup );
}
static int ldbm_initialized = 0;
#ifndef HAVE_BERKELEY_DB2
/* Everything but DB2 is non-reentrant */
......@@ -55,13 +57,22 @@ static ldap_pvt_thread_mutex_t ldbm_big_mutex;
#define LDBM_LOCK (ldap_pvt_thread_mutex_lock(&ldbm_big_mutex))
#define LDBM_UNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex))
void ldbm_initialize( void )
int ldbm_initialize( void )
{
static int initialized = 0;
if(initialized++) return;
if(ldbm_initialized++) return 1;
ldap_pvt_thread_mutex_init( &ldbm_big_mutex );
return 0;
}
int ldbm_shutdown( void )
{
if( !ldbm_initialized ) return 1;
ldap_pvt_thread_mutex_destroy( &ldbm_big_mutex );
return 0;
}
#else
......@@ -87,14 +98,12 @@ static DB_ENV ldbm_Env;
#define LDBM_LOCK ((void)0)
#define LDBM_UNLOCK ((void)0)
void ldbm_initialize( void )
int ldbm_initialize( void )
{
static int initialized = 0;
int err;
int envFlags;
if(initialized++) return;
if(ldbm_initialized++) return 1;
memset( &ldbm_Env, 0, sizeof( ldbm_Env ));
......@@ -115,8 +124,19 @@ void ldbm_initialize( void )
syslog( LOG_INFO,
"ldbm_initialize(): FATAL error in db_appinit() : %s\n",
error );
exit( 1 );
return( 1 );
}
return 0;
}
int ldbm_shutdown( void )
{
if( !ldbm_initialized ) return 1;
db_appexit( &ldbm_Env );
return 0;
}
#endif
......
......@@ -356,7 +356,7 @@ acl_access_allowed(
string_expand(buf, sizeof(buf), b->a_group, edn, matches);
(void) dn_normalize_case(buf);
if (be_group(be, e, buf, odn,
if (backend_group(be, e, buf, odn,
b->a_objectclassvalue, b->a_groupattrname) == 0)
{
Debug( LDAP_DEBUG_ACL,
......
......@@ -9,8 +9,8 @@
#include "slap.h"
#include "back-ldbm.h"
void
ldbm_back_close( Backend *be )
int
ldbm_back_db_close( Backend *be )
{
Debug( LDAP_DEBUG_TRACE, "ldbm backend saving nextid\n", 0, 0, 0 );
if ( next_id_save( be ) < 0 ) {
......@@ -20,4 +20,6 @@ ldbm_back_close( Backend *be )
Debug( LDAP_DEBUG_TRACE, "ldbm backend syncing\n", 0, 0, 0 );
ldbm_cache_flush_all( be );
Debug( LDAP_DEBUG_TRACE, "ldbm backend done syncing\n", 0, 0, 0 );
return 0;
}
......@@ -10,8 +10,8 @@
#include "slap.h"
#include "back-ldbm.h"
void
ldbm_back_config(
int
ldbm_back_db_config(
Backend *be,
char *fname,
int lineno,
......@@ -24,7 +24,7 @@ ldbm_back_config(
if ( li == NULL ) {
fprintf( stderr, "%s: line %d: ldbm backend info is null!\n",
fname, lineno );
exit( 1 );
return( 1 );
}
/* directory where database files live */
......@@ -33,7 +33,7 @@ ldbm_back_config(
fprintf( stderr,
"%s: line %d: missing dir in \"directory <dir>\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
}
li->li_directory = ch_strdup( argv[1] );
......@@ -49,7 +49,7 @@ ldbm_back_config(
fprintf( stderr,
"%s: line %d: missing mode in \"mode <mode>\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
}
li->li_mode = strtol( argv[1], NULL, 0 );
......@@ -59,7 +59,7 @@ ldbm_back_config(
fprintf( stderr,
"%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
} else if ( argc > 3 ) {
fprintf( stderr,
"%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
......@@ -73,7 +73,7 @@ ldbm_back_config(
fprintf( stderr,
"%s: line %d: missing size in \"cachesize <size>\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
}
li->li_cache.c_maxsize = atoi( argv[1] );
......@@ -83,7 +83,7 @@ ldbm_back_config(
fprintf( stderr,
"%s: line %d: missing size in \"dbcachesize <size>\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
}
li->li_dbcachesize = atoi( argv[1] );
......@@ -97,4 +97,6 @@ ldbm_back_config(
"%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
fname, lineno, argv[0] );
}
return 0;
}
#ifndef _LDBM_EXTERNAL_H
#define _LDBM_EXTERNAL_H
LDAP_BEGIN_DECL
extern int ldbm_back_initialize LDAP_P(( BackendInfo *bi ));
extern int ldbm_back_open LDAP_P(( BackendInfo *bi ));
extern int ldbm_back_close LDAP_P(( BackendInfo *bi ));
extern int ldbm_back_destroy LDAP_P(( BackendInfo *bi ));
extern int ldbm_back_db_init LDAP_P(( BackendDB *bd ));
extern int ldbm_back_db_open LDAP_P(( BackendDB *bd ));
extern int ldbm_back_db_close LDAP_P(( BackendDB *bd ));
extern int ldbm_back_db_destroy LDAP_P(( BackendDB *bd ));
extern int ldbm_back_db_config LDAP_P(( BackendDB *bd,
char *fname, int lineno, int argc, char **argv ));
extern int ldbm_back_bind LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *dn, int method, struct berval *cred, char** edn ));
extern int ldbm_back_unbind LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op ));
extern int ldbm_back_search LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *base, int scope, int deref, int sizelimit, int timelimit,
Filter *filter, char *filterstr, char **attrs, int attrsonly ));
extern int ldbm_back_compare LDAP_P((BackendDB *bd,
Connection *conn, Operation *op,
char *dn, Ava *ava ));
extern int ldbm_back_modify LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *dn, LDAPModList *ml ));
extern int ldbm_back_modrdn LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *dn, char*newrdn, int deleteoldrdn ));
extern int ldbm_back_add LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op, Entry *e ));
extern int ldbm_back_delete LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op, char *dn ));
extern int ldbm_back_abandon LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op, int msgid ));
extern int ldbm_back_group LDAP_P(( BackendDB *bd,
Entry *target, char* gr_ndn, char* op_ndn,
char* objectclassValue, char* groupattrName));
LDAP_END_DECL
#endif /* _LDBM_EXTERNAL_H */
......@@ -10,8 +10,71 @@
#include "slap.h"
#include "back-ldbm.h"
void
ldbm_back_init(
int
ldbm_back_initialize(
BackendInfo *bi
)
{
bi->bi_open = ldbm_back_open;
bi->bi_config = NULL;
bi->bi_close = ldbm_back_close;
bi->bi_destroy = ldbm_back_destroy;
bi->bi_db_init = ldbm_back_db_init;
bi->bi_db_config = ldbm_back_db_config;
bi->bi_db_open = ldbm_back_db_open;
bi->bi_db_close = ldbm_back_db_close;
bi->bi_db_destroy = ldbm_back_db_destroy;
bi->bi_op_bind = ldbm_back_bind;
bi->bi_op_unbind = ldbm_back_unbind;
bi->bi_op_search = ldbm_back_search;
bi->bi_op_compare = ldbm_back_compare;
bi->bi_op_modify = ldbm_back_modify;
bi->bi_op_modrdn = ldbm_back_modrdn;
bi->bi_op_add = ldbm_back_add;
bi->bi_op_delete = ldbm_back_delete;
bi->bi_op_abandon = ldbm_back_abandon;
bi->bi_acl_group = ldbm_back_group;
return 0;
}
int
ldbm_back_destroy(
BackendInfo *bi
)
{
return 0;
}
int
ldbm_back_open(
BackendInfo *bi
)
{
int rc;
/* initialize the underlying database system */
rc = ldbm_initialize();
return rc;
}
int
ldbm_back_close(
BackendInfo *bi
)
{
/* initialize the underlying database system */
ldbm_shutdown();
return 0;
}
int
ldbm_back_db_init(
Backend *be
)
{
......@@ -19,9 +82,6 @@ ldbm_back_init(
char *argv[ 4 ];
int i;
/* initialize the underlying database system */
ldbm_initialize();
/* allocate backend-specific stuff */
li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
......@@ -78,4 +138,25 @@ ldbm_back_init(
ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
be->be_private = li;
return 0;
}
int
ldbm_back_db_open(
BackendDB *be
)
{
return 0;
}
int
ldbm_back_db_destroy(
BackendDB *be
)
{
/* should free/destroy every in be_private */
free( be->be_private );
be->be_private = NULL;
return 0;
}
......@@ -3,6 +3,8 @@
#include <ldap_cdefs.h>
#include "external.h"
LDAP_BEGIN_DECL
/*
......
XSRCS = version.c
SRCS = search.c config.c
OBJS = search.o config.o
SRCS = search.c config.c init.c
OBJS = search.o config.o init.o
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
......
......@@ -9,10 +9,11 @@
#include <ac/time.h>
#include "slap.h"
#include "external.h"
void
passwd_back_config(
Backend *be,
int
passwd_back_db_config(
BackendDB *be,
char *fname,
int lineno,
int argc,
......@@ -26,7 +27,7 @@ passwd_back_config(
fprintf( stderr,
"%s: line %d: missing filename in \"file <filename>\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
}
be->be_private = ch_strdup( argv[1] );
#else /* HAVE_SETPWFILE */
......@@ -41,4 +42,6 @@ passwd_back_config(
"%s: line %d: unknown directive \"%s\" in passwd database definition (ignored)\n",
fname, lineno, argv[0] );
}
return( 0 );
}
#ifndef _PASSWD_EXTERNAL_H
#define _PASSWD_EXTERNAL_H
LDAP_BEGIN_DECL
extern int passwd_back_initialize LDAP_P(( BackendInfo *bi ));
extern int passwd_back_search LDAP_P(( BackendDB *be,
Connection *c, Operation *o,
char *base, int scope, int deref, int slimit, int tlimit,
Filter *f, char *filterstr, char **attrs, int attrsonly));
extern int passwd_back_db_config LDAP_P((BackendDB *bd,
char *fname, int lineno, int argc, char **argv ));
LDAP_END_DECL
#endif /* _PASSWD_EXTERNAL_H */
/* init.c - initialize passwd backend */
#include "portable.h"
#include <stdio.h>
#include <ac/socket.h>
#include "slap.h"
#include "external.h"
int
passwd_back_initialize(
BackendInfo *bi
)
{
bi->bi_open = NULL;
bi->bi_config = NULL;
bi->bi_close = NULL;
bi->bi_destroy = NULL;
bi->bi_db_init = NULL;
bi->bi_db_config = NULL;
bi->bi_db_open = NULL;
bi->bi_db_close = NULL;
bi->bi_db_destroy = NULL;
bi->bi_op_bind = NULL;
bi->bi_op_unbind = NULL;
bi->bi_op_search = passwd_back_search;
bi->bi_op_compare = NULL;
bi->bi_op_modify = NULL;
bi->bi_op_modrdn = NULL;
bi->bi_op_add = NULL;
bi->bi_op_delete = NULL;
bi->bi_op_abandon = NULL;
bi->bi_acl_group = NULL;
return 0;
}
......@@ -11,6 +11,7 @@
#include <pwd.h>
#include "slap.h"
#include "external.h"
static Entry *pw2entry(Backend *be, struct passwd *pw);
......
......@@ -27,16 +27,38 @@
*
**********************************************************/
void
int
perl_back_close(
Backend *be
BackendInfo *bd
)
{
ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
perl_destruct(perl_interpreter);
perl_free(perl_interpreter);
ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
return 0;
}
int
perl_back_destroy(
BackendInfo *bd
)
{
perl_free(perl_interpreter);
perl_interpreter = NULL;
ldap_pvt_thread_mutex_destroy( &perl_interpreter_mutex );
return 0;
}
int
perl_back_db_destroy(
BackendDB *be
)
{
free( be->be_private );
be->be_private = NULL;
}
......@@ -27,9 +27,9 @@
* Config
*
**********************************************************/
void
perl_back_config(
Backend *be,
int
perl_back_db_config(
BackendDB *be,
char *fname,
int lineno,
int argc,
......@@ -48,7 +48,7 @@ perl_back_config(
Debug( LDAP_DEBUG_ANY,
"%s.pm: line %d: missing module in \"perlModule <module>\" line\n",
fname, lineno, 0 );
exit( 1 );
return( 1 );
}
strncpy(eval_str, argv[1], EVAL_BUF_SIZE );
......@@ -82,7 +82,7 @@ perl_back_config(
fprintf( stderr,
"%s: line %d: missing module in \"PerlModulePath <module>\" line\n",
fname, lineno );
exit( 1 );
return( 1 );
}
sprintf( eval_str, "push @INC, '%s';", argv[1] );
......@@ -94,7 +94,9 @@ perl_back_config(
*/
fprintf( stderr,
"Unknown perl backeng config: %s\n", argv[0]);
exit( 1 );
"Unknown perl backend config: %s\n", argv[0]);
return( 1 );
}
return 0;
}
#ifndef _PERL_EXTERNAL_H
#define _PERL_EXTERNAL_H
LDAP_BEGIN_DECL
extern int perl_back_initialize LDAP_P(( BackendInfo *bi ));
extern int perl_back_open LDAP_P(( BackendInfo *bi ));
extern int perl_back_close LDAP_P(( BackendInfo *bi ));
extern int perl_back_destroy LDAP_P(( BackendInfo *bi ));
extern int perl_back_db_init LDAP_P(( BackendDB *bd ));
extern int perl_back_db_destroy LDAP_P(( BackendDB *bd ));
extern int perl_back_db_config LDAP_P(( BackendDB *bd,
char *fname, int lineno, int argc, char **argv ));
extern int perl_back_bind LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *dn, int method, struct berval *cred, char** edn ));
extern int perl_back_unbind LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op ));
extern int perl_back_search LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *base, int scope, int deref, int sizelimit, int timelimit,
Filter *filter, char *filterstr, char **attrs, int attrsonly ));
extern int perl_back_compare LDAP_P((BackendDB *bd,
Connection *conn, Operation *op,
char *dn, Ava *ava ));
extern int perl_back_modify LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *dn, LDAPModList *ml ));
extern int perl_back_modrdn LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
char *dn, char*newrdn, int deleteoldrdn ));
extern int perl_back_add LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op, Entry *e ));
extern int perl_back_delete LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op, char *dn ));
LDAP_END_DECL
#endif /* _PERL_EXTERNAL_H */
......@@ -33,25 +33,71 @@ ldap_pvt_thread_mutex_t perl_interpreter_mutex;
*
**********************************************************/
void
perl_back_init(
Backend *be
int
perl_back_initialize(
BackendInfo *bi
)
{
char *embedding[] = { "", "-e", "0" };
if( perl_interpreter == NULL ) {
perl_interpreter = perl_alloc();
perl_construct(perl_interpreter);
perl_parse(perl_interpreter, NULL, 3, embedding, (char **)NULL);
perl_run(perl_interpreter);
ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
if( perl_interpreter != NULL ) {
Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
0, 0, 0 );
return 1;
}
perl_interpreter = perl_alloc();
perl_construct(perl_interpreter);
perl_parse(perl_interpreter, NULL, 3, embedding, (char **)NULL);
perl_run(perl_interpreter);
bi->bi_open = perl_back_open;
bi->bi_config = NULL;
bi->bi_close = perl_back_close;
bi->bi_destroy = perl_back_destroy;
bi->bi_db_init = perl_back_db_init;
bi->bi_db_config = perl_back_db_config;
bi->bi_db_open = NULL;
bi->bi_db_close = NULL;
bi->bi_db_destroy = perl_back_db_destroy;
bi->bi_op_bind = perl_back_bind;
bi->bi_op_unbind = perl_back_unbind;
bi->bi_op_search = perl_back_search;
bi->bi_op_compare = perl_back_compare;
bi->bi_op_modify = perl_back_modify;
bi->bi_op_modrdn = perl_back_modrdn;
bi->bi_op_add = perl_back_add;
bi->bi_op_delete = perl_back_delete;
bi->bi_op_abandon = NULL;
bi->bi_acl_group = NULL;
return 0;
}
int
perl_back_open(
BackendInfo *bi
)
{
ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
return 0;
}
int
perl_back_db_init(
Backend *be
)
{
be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
memset(&be->be_private, 0, sizeof(PerlBackend));
Debug( LDAP_DEBUG_ANY, "Here in perl backend\n", 0, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
return 0;
}
#ifndef PERL_BACK_H
#define PERL_BACK_H 1
#include <ldap_cdefs.h>
LDAP_BEGIN_DECL
/*
......@@ -19,4 +17,6 @@ typedef struct perl_backend_instance {
LDAP_END_DECL
#include "external.h"
#endif
......@@ -27,7 +27,7 @@
* UnBind
*
**********************************************************/
void
int
perl_back_unbind(
Backend *be,
Connection *conn,
......@@ -36,6 +36,7 @@ perl_back_unbind(
{
send_ldap_result( conn, op, LDAP_NOT_SUPPORTED,
"", "not yet implemented" );
Debug( LDAP_DEBUG_ANY, "Perl UNBIND\n", 0, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "Perl UNBIND\n", 0, 0, 0 );
return 0;
}
......@@ -11,7 +11,7 @@
#include "slap.h"
#include "shell.h"
void
int
shell_back_abandon(
Backend *be,
Connection *conn,
......@@ -44,11 +44,11 @@ shell_back_abandon(
Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n",
msgid, 0, 0 );
}
return;
return 0;
}
if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
return;
return 0;
}
/* write out the request to the abandon process */
......@@ -59,4 +59,6 @@ shell_back_abandon(
/* no result from abandon */
fclose( rfp );
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment