Re: Modifying the modification

Howard Chu <[email protected]> Thu, 12 Feb 2026 15:25:33 +0000
Newsgroups gmane.network.openldap.devel
Message-ID <[email protected]>
Emmanuel Dreyfus wrote:
> Hello
> 
> In an overlay, I want to alter a modification operation so that
> modification to an attribute is not done.
> 
> I crafted the code below, which seems to work, but is it right? 
> There are XXX places where I expected another behavior, did I
> miss something?
> 
> And after "Modifying the modification", I also have "Modifying
> an add", just below, with the same questions.

Modify is fine. For add, you should use attr_free(), not attr_clean() + free().

> /* Modifying the modification */
> static void
> supann_rm_mods(Modifications *mods, Modifications **mods_prevp)
> {
>         Modifications *mods_next = mods->sml_next;
>         int freeit = 0;
>                         
>         /* XXX Setting freeit to 1 crashes */
>         slap_mod_free(&mods->sml_mod, freeit);
>         mods->sml_numvals = 0;
> 
>         free(mods);
>         *mods_prevp = mods_next;
> 
>         return;
> }
> 
> And this how it is used (of course removeit is a more complex
> logic, it is removed here for the sake of clarity)
> 
>         Modifications *mods;
>         Modifications **mods_prev;
>         Modifications *mods_next;
>  
>         mods_prev = &op->orm_modlist;
>         for (mods = op->orm_modlist; mods; mods = mods_next) {
>                 short sm_op = mods->sml_op;
>                 Attribute a;
> 
>                 mods_next = mods->sml_next;
> 
>                 if (remove_it)
>                         supann_rm_mods(mods, mods_prev);
>                 else
>                         mods_prev = &mods->sml_next;
> 	}
> 
> Same question, for add oprations:
> 
> /* Modifying the add */
> static void     
> supann_rm_attr(Attribute *a, Attribute **a_prevp)
> {               
>         Attribute *a_next = a->a_next;
>                 
>         attr_clean(a);
>                 
> #if 0
>         /* XXX This crashes */
>         free(a);
> #endif
>         *a_prevp = a_next;
> 
>         return;
> }
> 
> And its usage:
>         Attribute **a_prev;
>         Attribute *a_next;
> 
>         a_prev = &op->ora_e->e_attrs;
>         for (a = op->ora_e->e_attrs; a; a = a_next) {
>                 a_next = a->a_next;
> 
>                 if (removeit)
>                         supann_rm_attr(a, a_prev);
>                 else
>                         a_prev = &a->a_next;
> 	}
> 
> 
> 
> 


-- 
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/