X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fbackend.c;h=c8d30afd066efce744304c112c6d58a149fb9c74;hb=48b63d4f165269f29c35f89cceddd880c3966ef5;hp=ed106c23e02d25d3f723070d50f180b5f81bb791;hpb=62aa401bd74b3f98312de5232463ec644012292f;p=openldap diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index ed106c23e0..c8d30afd06 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -13,6 +13,11 @@ #include "slap.h" #include "lutil.h" +#include "ldap_defaults.h" + +#ifdef SLAPD_LDAP +#include "back-ldap/external.h" +#endif #ifdef SLAPD_LDBM #include "back-ldbm/external.h" #endif @@ -33,22 +38,25 @@ #endif static BackendInfo binfo[] = { -#ifdef SLAPD_LDBM +#if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC) + {"ldap", ldap_back_initialize}, +#endif +#if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC) {"ldbm", ldbm_back_initialize}, #endif -#ifdef SLAPD_BDB2 +#if defined(SLAPD_BDB2) && !defined(SLAPD_BDB2_DYNAMIC) {"bdb2", bdb2_back_initialize}, #endif -#ifdef SLAPD_PASSWD +#if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC) {"passwd", passwd_back_initialize}, #endif -#ifdef SLAPD_PERL +#if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC) {"perl", perl_back_initialize}, #endif -#ifdef SLAPD_SHELL +#if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC) {"shell", shell_back_initialize}, #endif -#ifdef SLAPD_TCL +#if defined(SLAPD_TCL) && !defined(SLAPD_LDAP_TCL) {"tcl", tcl_back_initialize}, #endif {NULL} @@ -102,11 +110,48 @@ int backend_init(void) return 0; } +#ifdef SLAPD_MODULES + return 0; +#else Debug( LDAP_DEBUG_ANY, "backend_init: failed\n", 0, 0, 0 ); return rc; +#endif /* SLAPD_MODULES */ +} + +int backend_add(BackendInfo *aBackendInfo) +{ + int rc = 0; + + if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) { + Debug( LDAP_DEBUG_ANY, + "backend_add: initialization for type \"%s\" failed\n", + aBackendInfo->bi_type, 0, 0 ); + return rc; + } + + /* now add the backend type to the Backend Info List */ + { + BackendInfo *newBackendInfo = 0; + + /* if backendInfo == binfo no deallocation of old backendInfo */ + if (backendInfo == binfo) { + newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo)); + memcpy(newBackendInfo, backendInfo, sizeof(BackendInfo) * + nBackendInfo); + } else { + newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) * + (nBackendInfo + 1)); + } + memcpy(&newBackendInfo[nBackendInfo], aBackendInfo, + sizeof(BackendInfo)); + backendInfo = newBackendInfo; + nBackendInfo++; + + return 0; + } } int backend_startup(int n) @@ -289,6 +334,15 @@ int backend_destroy(void) } } +#ifdef SLAPD_MODULES + if (backendInfo != binfo) { + free(backendInfo); + } +#endif /* SLAPD_MODULES */ + + nBackendInfo = 0; + backendInfo = NULL; + return 0; } @@ -333,6 +387,9 @@ backend_db_init( be->be_sizelimit = defsize; be->be_timelimit = deftime; + be->be_realm = global_realm != NULL + ? ch_strdup( global_realm ) : NULL; + if(bi->bi_db_init) { rc = bi->bi_db_init( be ); } @@ -366,42 +423,22 @@ select_backend( char * dn ) dnlen = strlen( dn ); for ( i = 0; i < nbackends; i++ ) { - for ( j = 0; backends[i].be_suffix != NULL && - backends[i].be_suffix[j] != NULL; j++ ) + for ( j = 0; backends[i].be_nsuffix != NULL && + backends[i].be_nsuffix[j] != NULL; j++ ) { - len = strlen( backends[i].be_suffix[j] ); + len = strlen( backends[i].be_nsuffix[j] ); if ( len > dnlen ) { continue; } - if ( strcmp( backends[i].be_suffix[j], + if ( strcmp( backends[i].be_nsuffix[j], dn + (dnlen - len) ) == 0 ) { return( &backends[i] ); } } } - /* 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 ( strcmp( backends[i].be_suffixAlias[j], - dn + (dnlen - len) ) == 0 ) { - return( &backends[i] ); - } - } - } - #ifdef LDAP_ALLOW_NULL_SEARCH_BASE /* Add greg@greg.rim.or.jp * It's quick hack for cheap client @@ -427,8 +464,8 @@ be_issuffix( { int i; - for ( i = 0; be->be_suffix != NULL && be->be_suffix[i] != NULL; i++ ) { - if ( strcmp( be->be_suffix[i], suffix ) == 0 ) { + for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i] != NULL; i++ ) { + if ( strcmp( be->be_nsuffix[i], suffix ) == 0 ) { return( 1 ); } } @@ -473,7 +510,7 @@ be_isroot_pw( Backend *be, char *ndn, struct berval *cred ) ldap_pvt_thread_mutex_lock( &crypt_mutex ); #endif - result = lutil_passwd( cred->bv_val, be->be_root_pw ); + result = lutil_passwd( cred->bv_val, be->be_root_pw, NULL ); #ifdef SLAPD_CRYPT ldap_pvt_thread_mutex_unlock( &crypt_mutex ); @@ -485,8 +522,6 @@ be_isroot_pw( Backend *be, char *ndn, struct berval *cred ) int be_entry_release_rw( Backend *be, Entry *e, int rw ) { - int rc; - if ( be->be_release ) { /* free and release entry from backend */ return be->be_release( be, e, rw ); @@ -514,7 +549,38 @@ backend_unbind( return 0; } -#ifdef SLAPD_ACLGROUPS +int +backend_connection_init( + Connection *conn +) +{ + int i; + + for ( i = 0; i < nbackends; i++ ) { + if ( backends[i].be_connection_init ) { + (*backends[i].be_connection_init)( &backends[i], conn); + } + } + + return 0; +} + +int +backend_connection_destroy( + Connection *conn +) +{ + int i; + + for ( i = 0; i < nbackends; i++ ) { + if ( backends[i].be_connection_destroy ) { + (*backends[i].be_connection_destroy)( &backends[i], conn); + } + } + + return 0; +} + int backend_group( Backend *be, @@ -531,4 +597,22 @@ backend_group( else return(1); } + +#ifdef SLAPD_SCHEMA_DN +Attribute *backend_subschemasubentry( Backend *be ) +{ + /* should be backend specific */ + static struct berval ss_val = { + sizeof(SLAPD_SCHEMA_DN)-1, + SLAPD_SCHEMA_DN }; + static struct berval *ss_vals[2] = { &ss_val, NULL }; + static Attribute ss_attr = { + "subschemasubentry", + ss_vals, + SYNTAX_DN | SYNTAX_CIS, + NULL + }; + + return &ss_attr; +} #endif