]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/init.c
make referrals chasing optional (default is to chase them)
[openldap] / servers / slapd / back-ldap / init.c
index 240fdcd65406a6ff7cf3318eff406a7d9de5e727..08767a481123c2e4264e0c34ffd67c5a10518f20 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2004 The OpenLDAP Foundation.
+ * Copyright 2003-2005 The OpenLDAP Foundation.
  * Portions Copyright 1999-2003 Howard Chu.
  * Portions Copyright 2000-2003 Pierangelo Masarati.
  * All rights reserved.
 
 #include "slap.h"
 #include "back-ldap.h"
-#include "external.h"
-
-#if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
-int
-init_module( int argc, char *argv[] )
-{
-       BackendInfo     bi;
-
-       memset( &bi, '\0', sizeof( bi ) );
-       bi.bi_type = "ldap";
-       bi.bi_init = ldap_back_initialize;
-
-       backend_add( &bi );
-    
-       return 0;
-}
-
-#endif /* SLAPD_LDAP */
 
 int
 ldap_back_open( BackendInfo    *bi )
@@ -88,6 +70,10 @@ ldap_back_initialize( BackendInfo *bi )
        bi->bi_connection_init = 0;
        bi->bi_connection_destroy = ldap_back_conn_destroy;
 
+       if ( chain_init( ) ) {
+               return -1;
+       }
+
        return 0;
 }
 
@@ -104,7 +90,6 @@ ldap_back_db_init( Backend *be )
        BER_BVZERO( &li->acl_authcDN );
        BER_BVZERO( &li->acl_passwd );
 
-#ifdef LDAP_BACK_PROXY_AUTHZ
        li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
 
        BER_BVZERO( &li->idassert_authcID );
@@ -123,7 +108,9 @@ ldap_back_db_init( Backend *be )
 
        /* by default, use proxyAuthz control on each operation */
        li->idassert_flags = LDAP_BACK_AUTH_NONE;
-#endif /* LDAP_BACK_PROXY_AUTHZ */
+
+       /* initialize flags */
+       li->flags = LDAP_BACK_F_CHASE_REFERRALS;
 
        ldap_pvt_thread_mutex_init( &li->conn_mutex );
 
@@ -139,9 +126,9 @@ ldap_back_db_open( BackendDB *be )
        struct ldapinfo *li = (struct ldapinfo *)be->be_private;
 
        Debug( LDAP_DEBUG_TRACE,
-               "ldap_back_db_open: URI=%s\n", li->url, 0, 0 );
+               "ldap_back_db_open: URI=%s\n",
+               li->url != NULL ? li->url : "", 0, 0 );
 
-#ifdef LDAP_BACK_PROXY_AUTHZ
        /* by default, use proxyAuthz control on each operation */
        switch ( li->idassert_mode ) {
        case LDAP_BACK_IDASSERT_LEGACY:
@@ -154,21 +141,24 @@ ldap_back_db_open( BackendDB *be )
        default:
                break;
        }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
 
 #if 0 && defined(SLAPD_MONITOR)
        {
+               /* FIXME: disabled because namingContexts doesn't have
+                * a matching rule, and using an MRA filter doesn't work
+                * because the normalized assertion is compared to the 
+                * non-normalized value, which in general differs from
+                * the normalized one.  See ITS#3406 */
                struct berval   filter,
-                               base = BER_BVC( "cn=Databases,cn=Monitor" );
-               const char      *text;
+                               base = BER_BVC( "cn=Databases," SLAPD_MONITOR );
                struct berval   vals[ 2 ];
                Attribute       a = { 0 };
 
-               filter.bv_len = STRLENOF( "(&(namingContexts=)(monitoredInfo=ldap))" )
+               filter.bv_len = STRLENOF( "(&(namingContexts:distinguishedNameMatch:=)(monitoredInfo=ldap))" )
                        + be->be_nsuffix[ 0 ].bv_len;
                filter.bv_val = ch_malloc( filter.bv_len + 1 );
                snprintf( filter.bv_val, filter.bv_len + 1,
-                               "(&(namingContexts=%s)(monitoredInfo=ldap))",
+                               "(&(namingContexts:distinguishedNameMatch:=%s)(monitoredInfo=ldap))",
                                be->be_nsuffix[ 0 ].bv_val );
 
                a.a_desc = slap_schema.si_ad_labeledURI;
@@ -179,6 +169,8 @@ ldap_back_db_open( BackendDB *be )
                if ( monitor_back_register_entry_attrs( NULL, &a, NULL, &base, LDAP_SCOPE_SUBTREE, &filter ) ) {
                        /* error */
                }
+
+               ch_free( filter.bv_val );
        }
 #endif /* SLAPD_MONITOR */
 
@@ -217,7 +209,7 @@ ldap_back_db_destroy(
 
                ldap_pvt_thread_mutex_lock( &li->conn_mutex );
 
-               if ( li->url ) {
+               if ( li->url != NULL ) {
                        ch_free( li->url );
                        li->url = NULL;
                }
@@ -233,7 +225,6 @@ ldap_back_db_destroy(
                        ch_free( li->acl_passwd.bv_val );
                        BER_BVZERO( &li->acl_passwd );
                }
-#ifdef LDAP_BACK_PROXY_AUTHZ
                if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
                        ch_free( li->idassert_authcID.bv_val );
                        BER_BVZERO( &li->idassert_authcID );
@@ -258,7 +249,6 @@ ldap_back_db_destroy(
                        ch_free( li->idassert_sasl_realm.bv_val );
                        BER_BVZERO( &li->idassert_sasl_realm );
                }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
                 if ( li->conntree ) {
                        avl_free( li->conntree, ldap_back_conn_free );
                }
@@ -271,3 +261,11 @@ ldap_back_db_destroy(
 
        return 0;
 }
+
+#if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
+
+/* conditionally define the init_module() function */
+SLAP_BACKEND_INIT_MODULE( ldap )
+
+#endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */
+