]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/init.c
Fix compare op
[openldap] / servers / slapd / back-meta / init.c
index 9bfeb4fe2de75717577cab60e5f97969e44f00b7..f5cb37935c25e4bfd6a14b719755dcb528ccc800 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2007 The OpenLDAP Foundation.
+ * Copyright 1999-2009 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * Portions Copyright 1999-2003 Howard Chu.
  * All rights reserved.
@@ -23,6 +23,7 @@
 #include <ac/socket.h>
 
 #include "slap.h"
+#include "config.h"
 #include "../back-ldap/back-ldap.h"
 #include "back-meta.h"
 
@@ -52,7 +53,10 @@ meta_back_initialize(
                SLAP_BFLAG_DYNAMIC |
 #endif /* LDAP_DYNAMIC_OBJECTS */
 #endif
-               0;
+
+               /* back-meta recognizes RFC4525 increment;
+                * let the remote server complain, if needed (ITS#5912) */
+               SLAP_BFLAG_INCREMENT;
 
        bi->bi_open = meta_back_open;
        bi->bi_config = 0;
@@ -87,16 +91,30 @@ meta_back_initialize(
 
 int
 meta_back_db_init(
-       Backend         *be )
+       Backend         *be,
+       ConfigReply     *cr)
 {
        metainfo_t      *mi;
        int             i;
+       BackendInfo     *bi;
+
+       bi = backend_info( "ldap" );
+       if ( !bi || !bi->bi_extra ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "meta_back_db_init: needs back-ldap\n",
+                       0, 0, 0 );
+               return 1;
+       }
 
        mi = ch_calloc( 1, sizeof( metainfo_t ) );
        if ( mi == NULL ) {
                return -1;
        }
 
+       /* set default flags */
+       mi->mi_flags =
+               META_BACK_F_DEFER_ROOTDN_BIND;
+
        /*
         * At present the default is no default target;
         * this may change
@@ -121,6 +139,8 @@ meta_back_db_init(
        }
        mi->mi_conn_priv_max = LDAP_BACK_CONN_PRIV_DEFAULT;
        
+       mi->mi_ldap_extra = (ldap_extra_t *)bi->bi_extra;
+
        be->be_private = mi;
 
        return 0;
@@ -128,18 +148,30 @@ meta_back_db_init(
 
 int
 meta_back_db_open(
-       Backend         *be )
+       Backend         *be,
+       ConfigReply     *cr )
 {
        metainfo_t      *mi = (metainfo_t *)be->be_private;
 
        int             i,
                        not_always = 0,
+                       not_always_anon_proxyauthz = 0,
+                       not_always_anon_non_prescriptive = 0,
                        rc;
 
+       if ( mi->mi_ntargets == 0 ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "meta_back_db_open: no targets defined\n",
+                       0, 0, 0 );
+               return 1;
+       }
+
        for ( i = 0; i < mi->mi_ntargets; i++ ) {
                slap_bindconf   sb = { BER_BVNULL };
                metatarget_t    *mt = mi->mi_targets[ i ];
 
+               struct berval mapped;
+
                ber_str2bv( mt->mt_uri, 0, 0, &sb.sb_uri );
                sb.sb_version = mt->mt_version;
                sb.sb_method = LDAP_AUTH_SIMPLE;
@@ -165,17 +197,64 @@ meta_back_db_open(
 
                if ( not_always == 0 ) {
                        if ( !( mt->mt_idassert_flags & LDAP_BACK_AUTH_OVERRIDE )
-                               || !( mt->mt_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
+                               || mt->mt_idassert_authz != NULL )
                        {
                                not_always = 1;
                        }
                }
+
+               if ( ( mt->mt_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL )
+                       && !( mt->mt_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) )
+               {
+                       Debug( LDAP_DEBUG_ANY, "meta_back_db_open(%s): "
+                               "target #%d inconsistent idassert configuration "
+                               "(likely authz=\"*\" used with \"non-prescriptive\" flag)\n",
+                               be->be_suffix[ 0 ].bv_val, i, 0 );
+                       return 1;
+               }
+
+               if ( not_always_anon_proxyauthz == 0 ) {
+                       if ( !( mt->mt_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
+                       {
+                               not_always_anon_proxyauthz = 1;
+                       }
+               }
+
+               if ( not_always_anon_non_prescriptive == 0 ) {
+                       if ( ( mt->mt_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) )
+                       {
+                               not_always_anon_non_prescriptive = 1;
+                       }
+               }
+
+               BER_BVZERO( &mapped );
+               ldap_back_map( &mt->mt_rwmap.rwm_at, 
+                       &slap_schema.si_ad_entryDN->ad_cname, &mapped,
+                       BACKLDAP_REMAP );
+               if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
+                       mt->mt_rep_flags |= REP_NO_ENTRYDN;
+               }
+
+               BER_BVZERO( &mapped );
+               ldap_back_map( &mt->mt_rwmap.rwm_at, 
+                       &slap_schema.si_ad_subschemaSubentry->ad_cname, &mapped,
+                       BACKLDAP_REMAP );
+               if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
+                       mt->mt_rep_flags |= REP_NO_SUBSCHEMA;
+               }
        }
 
        if ( not_always == 0 ) {
                mi->mi_flags |= META_BACK_F_PROXYAUTHZ_ALWAYS;
        }
 
+       if ( not_always_anon_proxyauthz == 0 ) {
+               mi->mi_flags |= META_BACK_F_PROXYAUTHZ_ANON;
+
+       } else if ( not_always_anon_non_prescriptive == 0 ) {
+               mi->mi_flags |= META_BACK_F_PROXYAUTHZ_NOANON;
+       }
+
        return 0;
 }
 
@@ -288,7 +367,8 @@ target_free(
 
 int
 meta_back_db_destroy(
-       Backend         *be )
+       Backend         *be,
+       ConfigReply     *cr )
 {
        metainfo_t      *mi;
 
@@ -325,7 +405,7 @@ meta_back_db_destroy(
                                if ( META_BACK_TGT_QUARANTINE( mt ) ) {
                                        if ( mt->mt_quarantine.ri_num != mi->mi_quarantine.ri_num )
                                        {
-                                               slap_retry_info_destroy( &mt->mt_quarantine );
+                                               mi->mi_ldap_extra->retry_info_destroy( &mt->mt_quarantine );
                                        }
 
                                        ldap_pvt_thread_mutex_destroy( &mt->mt_quarantine_mutex );
@@ -353,7 +433,7 @@ meta_back_db_destroy(
                }
 
                if ( META_BACK_QUARANTINE( mi ) ) {
-                       slap_retry_info_destroy( &mi->mi_quarantine );
+                       mi->mi_ldap_extra->retry_info_destroy( &mi->mi_quarantine );
                }
        }