]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/dynlist.c
ITS#5747: Only use C99 flexible array member when supported
[openldap] / servers / slapd / overlays / dynlist.c
index 9b2ac459c5a2c2e5fd9c790482942ee5f48dca2c..b7f38aa01dd7f058b26d56b69f3638ab5b575d03 100644 (file)
@@ -178,10 +178,10 @@ dynlist_sc_update( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       for ( dlm = dlc->dlc_dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
-               if (dlm->dlm_mapped_ad != NULL)
-                       continue;
-
+       /* if there is only one member_ad, and it's not mapped,
+        * consider it as old-style member listing */
+       dlm = dlc->dlc_dli->dli_dlm;
+       if ( dlm && dlm->dlm_mapped_ad == NULL && dlm->dlm_next == NULL ) {
                /* if access allowed, try to add values, emulating permissive
                 * control to silently ignore duplicates */
                if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
@@ -306,7 +306,9 @@ dynlist_sc_update( Operation *op, SlapReply *rs )
                        ad = a->a_desc;
                        for ( dlm = dlc->dlc_dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
                                if ( dlm->dlm_member_ad == a->a_desc ) {
-                                       ad = dlm->dlm_mapped_ad;
+                                       if ( dlm->dlm_mapped_ad ) {
+                                               ad = dlm->dlm_mapped_ad;
+                                       }
                                        break;
                                }
                        }
@@ -369,8 +371,8 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
 
        /* Don't generate member list if it wasn't requested */
        for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
-               if ( userattrs ||
-                    ad_inlist( dlm->dlm_member_ad, rs->sr_attrs ) ) 
+               AttributeDescription *ad = dlm->dlm_mapped_ad ? dlm->dlm_mapped_ad : dlm->dlm_member_ad;
+               if ( userattrs || ad_inlist( ad, rs->sr_attrs ) ) 
                        break;
        }
        if ( dli->dli_dlm && !dlm )
@@ -421,7 +423,6 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
                int             i, j;
                struct berval   dn;
                int             rc;
-               dynlist_map_t   *dlm;
 
                BER_BVZERO( &o.o_req_dn );
                BER_BVZERO( &o.o_req_ndn );
@@ -498,17 +499,42 @@ dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
                                        if ( o.ors_attrs[j].an_desc != NULL &&
                                                        is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
                                        {
-                                               if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
-                                               {
+                                               if ( !opattrs ) {
                                                        continue;
                                                }
 
+                                               if ( !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) ) {
+                                                       /* lookup if mapped -- linear search,
+                                                        * not very efficient unless list
+                                                        * is very short */
+                                                       for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
+                                                               if ( dlm->dlm_member_ad == o.ors_attrs[j].an_desc ) {
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       if ( dlm == NULL ) {
+                                                               continue;
+                                                       }
+                                               }
+
                                        } else {
                                                if ( !userattrs && 
                                                                o.ors_attrs[j].an_desc != NULL &&
                                                                !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
                                                {
-                                                       continue;
+                                                       /* lookup if mapped -- linear search,
+                                                        * not very efficient unless list
+                                                        * is very short */
+                                                       for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
+                                                               if ( dlm->dlm_member_ad == o.ors_attrs[j].an_desc ) {
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       if ( dlm == NULL ) {
+                                                               continue;
+                                                       }
                                                }
                                        }
                                }
@@ -553,7 +579,7 @@ cleanup:;
                        slap_op_groups_free( &o );
                }
                if ( o.ors_filter ) {
-                       filter_free_x( &o, o.ors_filter );
+                       filter_free_x( &o, o.ors_filter, 1 );
                }
                if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
                                && o.ors_attrs != slap_anlist_no_attrs )
@@ -780,7 +806,7 @@ done:;
 
 release:;
        if ( e != NULL ) {
-               overlay_entry_release_ov( &o, e, 0, on );
+               overlay_entry_release_ov( op, e, 0, on );
        }
 
        return SLAP_CB_CONTINUE;
@@ -851,7 +877,7 @@ dynlist_build_def_filter( dynlist_info_t *dli )
        ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
        ptr = lutil_strcopy( ptr, "))" );
 
-       assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
+       assert( ptr == &dli->dli_default_filter.bv_val[dli->dli_default_filter.bv_len] );
 
        return 0;
 }
@@ -1557,22 +1583,26 @@ 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 */
+       if ( ad_dgIdentity == NULL ) {
+               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 */
+               }
        }
 
-       rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
-       if ( rc != LDAP_SUCCESS ) {
-               snprintf( cr->msg, sizeof( cr->msg),
-                       "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
-                       rc, text );
-               Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
-               /* Just a warning */
+       if ( ad_dgAuthz == NULL ) {
+               rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
+               if ( rc != LDAP_SUCCESS ) {
+                       snprintf( cr->msg, sizeof( cr->msg),
+                               "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
+                               rc, text );
+                       Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
+                       /* Just a warning */
+               }
        }
 
        return 0;