]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/dynlist.c
ITS5261
[openldap] / servers / slapd / overlays / dynlist.c
index 4338efd33f3ec1f0a793ea47eba9b414c403077a..4150659d24ee8370edafcb931efc71b70dea67ef 100644 (file)
@@ -58,6 +58,8 @@ static AttributeName anlist_no_attrs[] = {
 static AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
 #endif
 
+static AttributeDescription *ad_dgIdentity;
+
 typedef struct dynlist_info_t {
        ObjectClass             *dli_oc;
        AttributeDescription    *dli_ad;
@@ -90,10 +92,10 @@ dynlist_is_dynlist_next( Operation *op, SlapReply *rs, dynlist_info_t *old_dli )
        }
 
        for ( ; dli; dli = dli->dli_next ) {
-               if ( value_find_ex( slap_schema.si_ad_objectClass, 
+               if ( attr_valfind( a,
                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                               a->a_nvals, &dli->dli_oc->soc_cname,
+                               &dli->dli_oc->soc_cname, NULL,
                                op->o_tmpmemctx ) == 0 )
                {
                        return dli;
@@ -187,6 +189,7 @@ dynlist_sc_update( Operation *op, SlapReply *rs )
                        mod.sm_type = dlc->dlc_dli->dli_member_ad->ad_cname;
                        mod.sm_values = vals;
                        mod.sm_nvalues = nvals;
+                       mod.sm_numvals = 1;
 
                        (void)modify_add_values( e, &mod, /* permissive */ 1,
                                        &text, textbuf, sizeof( textbuf ) );
@@ -246,8 +249,7 @@ dynlist_sc_update( Operation *op, SlapReply *rs )
                }
 
                /* test access to attribute */
-               for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
-                       /* just count */ ;
+               i = a->a_numvals;
 
                vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
                if ( a->a_nvals != a->a_vals ) {
@@ -291,6 +293,7 @@ dynlist_sc_update( Operation *op, SlapReply *rs )
                        mod.sm_type = a->a_desc->ad_cname;
                        mod.sm_values = vals;
                        mod.sm_nvalues = nvals;
+                       mod.sm_numvals = j;
 
                        (void)modify_add_values( e, &mod, /* permissive */ 1,
                                        &text, textbuf, sizeof( textbuf ) );
@@ -315,7 +318,7 @@ done:;
 static int
 dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
 {
-       Attribute       *a;
+       Attribute       *a, *id = NULL;
        slap_callback   cb;
        Operation       o = *op;
        SlapReply       r = { REP_SEARCH };
@@ -332,6 +335,19 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
                return SLAP_CB_CONTINUE;
        }
 
+#ifndef SLAP_OPATTRS
+       opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
+       userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
+#else /* SLAP_OPATTRS */
+       opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
+       userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
+#endif /* SLAP_OPATTRS */
+
+       /* Don't generate member list if it wasn't requested */
+       if ( dli->dli_member_ad && !userattrs && !ad_inlist( dli->dli_member_ad, rs->sr_attrs ) ) {
+               return SLAP_CB_CONTINUE;
+       }
+
        if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
                e = entry_dup( rs->sr_entry );
        } else {
@@ -339,6 +355,12 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
        }
        e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
 
+       if ( ad_dgIdentity && ( id = attrs_find( e->e_attrs, ad_dgIdentity ))) {
+               o.o_dn = id->a_vals[0];
+               o.o_ndn = id->a_nvals[0];
+               o.o_groups = NULL;
+       }
+
        dlc.dlc_e = e;
        dlc.dlc_dli = dli;
        cb.sc_private = &dlc;
@@ -352,14 +374,6 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
        o.ors_tlimit = SLAP_NO_LIMIT;
        o.ors_slimit = SLAP_NO_LIMIT;
 
-#ifndef SLAP_OPATTRS
-       opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
-       userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
-#else /* SLAP_OPATTRS */
-       opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
-       userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
-#endif /* SLAP_OPATTRS */
-
        for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
                LDAPURLDesc     *lud = NULL;
                int             i, j;
@@ -486,6 +500,9 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
                }
 
 cleanup:;
+               if ( id ) {
+                       slap_op_groups_free( &o );
+               }
                if ( o.ors_filter ) {
                        filter_free_x( &o, o.ors_filter );
                }
@@ -531,6 +548,8 @@ dynlist_compare( Operation *op, SlapReply *rs )
 {
        slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
        dynlist_info_t  *dli = (dynlist_info_t *)on->on_bi.bi_private;
+       Operation o = *op;
+       Entry *e = NULL;
 
        for ( ; dli != NULL; dli = dli->dli_next ) {
                if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
@@ -538,12 +557,18 @@ dynlist_compare( Operation *op, SlapReply *rs )
                         * interested in. We'll use slapd's existing dyngroup
                         * evaluator to get the answer we want.
                         */
-                       int cache = op->o_do_not_cache;
-                               
-                       op->o_do_not_cache = 1;
-                       rs->sr_err = backend_group( op, NULL, &op->o_req_ndn,
-                               &op->oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
-                       op->o_do_not_cache = cache;
+                       struct berval *id = NULL;
+
+                       o.o_do_not_cache = 1;
+
+                       if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
+                               ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS ) {
+                               o.o_dn = *id;
+                               o.o_ndn = *id;
+                               o.o_groups = NULL; /* authz changed, invalidate cached groups */
+                       }
+                       rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
+                               &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
                        switch ( rs->sr_err ) {
                        case LDAP_SUCCESS:
                                rs->sr_err = LDAP_COMPARE_TRUE;
@@ -561,45 +586,35 @@ dynlist_compare( Operation *op, SlapReply *rs )
                                break;
                        }
 
+                       if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
+
                        return SLAP_CB_CONTINUE;
                }
        }
 
+       if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
+               LDAP_SUCCESS || e == NULL ) {
+               return SLAP_CB_CONTINUE;
+       }
+       if ( ad_dgIdentity ) {
+               Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
+               if ( id ) {
+                       o.o_dn = id->a_vals[0];
+                       o.o_ndn = id->a_nvals[0];
+                       o.o_groups = NULL;
+               }
+       }
        dli = (dynlist_info_t *)on->on_bi.bi_private;
        for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
                Attribute       *a;
                slap_callback   cb;
-               Operation       o = *op;
                SlapReply       r = { REP_SEARCH };
                AttributeName   an[2];
                int             rc;
                dynlist_sc_t    dlc = { 0 };
-               Entry           *e;
-
-               int cache = op->o_do_not_cache;
-               struct berval   op_dn = op->o_dn,
-                               op_ndn = op->o_ndn;
-               BackendDB       *op_bd = op->o_bd;
-
-               /* fetch the entry as rootdn (a hack to see if it exists
-                * and if it has the right objectClass) */
-               op->o_do_not_cache = 1;
-               op->o_dn = op->o_bd->be_rootdn;
-               op->o_ndn = op->o_bd->be_rootndn;
-               op->o_bd = select_backend( &op->o_req_ndn, 0 );
-
-               r.sr_err = be_entry_get_rw( op, &op->o_req_ndn,
-                       dli->dli_oc, NULL, 0, &e );
-               if ( e != NULL ) {
-                       be_entry_release_r( op, e );
-               }
-               op->o_do_not_cache = cache;
-               op->o_dn = op_dn;
-               op->o_ndn = op_ndn;
-               op->o_bd = op_bd;
-               if ( r.sr_err != LDAP_SUCCESS ) {
+
+               if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
                        continue;
-               }
 
                /* if the entry has the right objectClass, generate
                 * the dynamic list and compare */
@@ -617,15 +632,11 @@ dynlist_compare( Operation *op, SlapReply *rs )
 
                o.o_bd = select_backend( &o.o_req_ndn, 1 );
                if ( !o.o_bd || !o.o_bd->be_search ) {
-                       return SLAP_CB_CONTINUE;
+                       goto release;
                }
 
-               BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
-               o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
-               if ( o.ors_filter == NULL ) {
-                       /* FIXME: error? */
-                       return SLAP_CB_CONTINUE;
-               }
+               o.ors_filterstr = *slap_filterstr_objectClass_pres;
+               o.ors_filter = (Filter *) slap_filter_objectClass_pres;
 
                o.ors_scope = LDAP_SCOPE_BASE;
                o.ors_deref = LDAP_DEREF_NEVER;
@@ -638,10 +649,13 @@ dynlist_compare( Operation *op, SlapReply *rs )
                o.o_acl_priv = ACL_COMPARE;
 
                rc = o.o_bd->be_search( &o, &r );
-               filter_free_x( &o, o.ors_filter );
+
+               if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
+                       slap_op_groups_free( &o );
+               }
 
                if ( rc != 0 ) {
-                       return rc;
+                       goto release;
                }
 
                if ( dlc.dlc_e != NULL ) {
@@ -650,7 +664,7 @@ dynlist_compare( Operation *op, SlapReply *rs )
 
                if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
                        /* error? */
-                       return SLAP_CB_CONTINUE;
+                       goto release;
                }
 
                for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
@@ -660,10 +674,10 @@ dynlist_compare( Operation *op, SlapReply *rs )
                        /* if we're here, we got a match... */
                        rs->sr_err = LDAP_COMPARE_FALSE;
 
-                       if ( value_find_ex( op->orc_ava->aa_desc,
+                       if ( attr_valfind( a,
                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                        SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                               a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
+                               &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
                        {
                                rs->sr_err = LDAP_COMPARE_TRUE;
                                break;
@@ -675,6 +689,11 @@ dynlist_compare( Operation *op, SlapReply *rs )
                }
        }
 
+release:;
+       if ( e != NULL ) {
+               overlay_entry_release_ov( &o, e, 0, on );
+       }
+
        return SLAP_CB_CONTINUE;
 }
 
@@ -1062,7 +1081,7 @@ dl_cfgen( ConfigArgs *c )
                        break;
                }
 
-               return 1;       /* FIXME */
+               return rc;
        }
 
        switch( c->type ) {
@@ -1279,6 +1298,8 @@ dynlist_db_open(
        dynlist_info_t          *dli = (dynlist_info_t *)on->on_bi.bi_private;
        ObjectClass             *oc = NULL;
        AttributeDescription    *ad = NULL;
+       const char      *text;
+       int rc;
 
        if ( dli == NULL ) {
                dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
@@ -1286,16 +1307,13 @@ dynlist_db_open(
        }
 
        for ( ; dli; dli = dli->dli_next ) {
-               const char      *text;
-               int             rc;
-
                if ( dli->dli_oc == NULL ) {
                        if ( oc == NULL ) {
                                oc = oc_find( "groupOfURLs" );
                                if ( oc == NULL ) {
-                                       Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
-                                               "unable to fetch objectClass \"groupOfURLs\".\n",
-                                               0, 0, 0 );
+                                       snprintf( cr->msg, sizeof( cr->msg),
+                                               "unable to fetch objectClass \"groupOfURLs\"" );
+                                       Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
                                        return 1;
                                }
                        }
@@ -1307,9 +1325,10 @@ dynlist_db_open(
                        if ( ad == NULL ) {
                                rc = slap_str2ad( "memberURL", &ad, &text );
                                if ( rc != LDAP_SUCCESS ) {
-                                       Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
-                                               "unable to fetch attributeDescription \"memberURL\": %d (%s).\n",
-                                               rc, text, 0 );
+                                       snprintf( cr->msg, sizeof( cr->msg),
+                                               "unable to fetch attributeDescription \"memberURL\": %d (%s)",
+                                               rc, text );
+                                       Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
                                        return 1;
                                }
                        }
@@ -1325,6 +1344,15 @@ dynlist_db_open(
                }
        }
 
+       rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
+       if ( rc != LDAP_SUCCESS ) {
+               snprintf( cr->msg, sizeof( cr->msg),
+                       "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
+                       rc, text );
+               Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
+               /* Just a warning */
+       }
+
        return 0;
 }