]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/init.c
fix entry DN free
[openldap] / servers / slapd / back-ldap / init.c
index ce2711258681be62bc944ea05c5144f09a1739ab..02c9ad0b114a5053f72b7aeb90a0b5d490403c79 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.
@@ -30,7 +30,6 @@
 
 #include "slap.h"
 #include "back-ldap.h"
-#include "external.h"
 
 int
 ldap_back_open( BackendInfo    *bi )
@@ -71,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;
 }
 
@@ -84,10 +87,13 @@ ldap_back_db_init( Backend *be )
                return -1;
        }
 
+       BER_BVZERO( &li->acl_authcID );
        BER_BVZERO( &li->acl_authcDN );
        BER_BVZERO( &li->acl_passwd );
 
-#ifdef LDAP_BACK_PROXY_AUTHZ
+       li->acl_authmethod = LDAP_AUTH_SIMPLE;
+       BER_BVZERO( &li->acl_sasl_mech );
+
        li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
 
        BER_BVZERO( &li->idassert_authcID );
@@ -95,18 +101,20 @@ ldap_back_db_init( Backend *be )
        BER_BVZERO( &li->idassert_passwd );
 
        BER_BVZERO( &li->idassert_authzID );
-       li->idassert_authz = NULL;
 
        li->idassert_authmethod = LDAP_AUTH_SIMPLE;
-       li->idassert_sasl_flags = LDAP_SASL_QUIET;
        BER_BVZERO( &li->idassert_sasl_mech );
-       BER_BVZERO( &li->idassert_sasl_realm );
-
-       li->idassert_ppolicy = 0;
 
        /* by default, use proxyAuthz control on each operation */
        li->idassert_flags = LDAP_BACK_AUTH_NONE;
-#endif /* LDAP_BACK_PROXY_AUTHZ */
+
+       li->idassert_authz = NULL;
+
+       /* initialize flags */
+       li->flags = LDAP_BACK_F_CHASE_REFERRALS;
+
+       /* initialize version */
+       li->version = LDAP_VERSION3;
 
        ldap_pvt_thread_mutex_init( &li->conn_mutex );
 
@@ -122,9 +130,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:
@@ -137,21 +145,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;
@@ -162,9 +173,24 @@ 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 */
 
+       if ( li->flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) {
+               int             rc;
+
+               li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
+
+               rc = slap_discover_feature( li->url, li->version,
+                               slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
+                               LDAP_FEATURE_ABSOLUTE_FILTERS );
+               if ( rc == LDAP_COMPARE_TRUE ) {
+                       li->flags |= LDAP_BACK_F_SUPPORT_T_F;
+               }
+       }
+
        return 0;
 }
 
@@ -200,7 +226,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;
                }
@@ -208,6 +234,10 @@ ldap_back_db_destroy(
                        ldap_free_urldesc( li->lud );
                        li->lud = NULL;
                }
+               if ( !BER_BVISNULL( &li->acl_authcID ) ) {
+                       ch_free( li->acl_authcID.bv_val );
+                       BER_BVZERO( &li->acl_authcID );
+               }
                if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
                        ch_free( li->acl_authcDN.bv_val );
                        BER_BVZERO( &li->acl_authcDN );
@@ -216,7 +246,14 @@ 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->acl_sasl_mech ) ) {
+                       ch_free( li->acl_sasl_mech.bv_val );
+                       BER_BVZERO( &li->acl_sasl_mech );
+               }
+               if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
+                       ch_free( li->acl_sasl_realm.bv_val );
+                       BER_BVZERO( &li->acl_sasl_realm );
+               }
                if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
                        ch_free( li->idassert_authcID.bv_val );
                        BER_BVZERO( &li->idassert_authcID );
@@ -241,7 +278,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 );
                }
@@ -257,19 +293,8 @@ ldap_back_db_destroy(
 
 #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;
-}
+/* conditionally define the init_module() function */
+SLAP_BACKEND_INIT_MODULE( ldap )
 
-#endif /* SLAPD_LDAP */
+#endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */