(Maybe I should have posted this to OpenLDAP-Devel, but I'm not an
OpenLDAP developer, and I feel a little bit lazy to subscribe to another
one mailing list ;)

The first patch fixes ITS#3971. It needs to be reviewed; I only ran
"make check" (successfully) after applying this patch, but maybe similar
corrections need to be done in tool section of backglue.
The nature of ITS#3971 is the following; we implicitly make
op->o_req_dn->bv_val equal to gi->gi_n[i]->gn_be->be_suffix[0]->bv_val
(backglue.c:338), and op->o_req_dn->bv_val after that can be freed by
rwm (rwm.c:82), thus filling gi->gi_n[i]->gn_be->be_suffix[0]->bv_val
with garbage and rendering backglue inoperational for further
invocations. Replacing assignment by ber_dupbv fixes this.

In comments to ITS#3971, it is stated that backglue works only with
global rwm. In fact, backglue doesn't work with global rwm at all; see
my previous message
(http://www.openldap.org/lists/openldap-software/200510/msg00019.html).
That hang is caused by double (chained) invocation of rwm_op_search on a
single op instance; rwm callback (which is a singleton) is being
inserted to a callback chain twice (rwm.c:729), thus turning it into a
cycle, and making cleanup code (result.c:462) enter an infinite loop. My
second patch offers a kind of workaround for this: iterate over callback
chain, and if rwm callback instance is already there, do nothing.

Even with this patch backglue and global rwm do not work together in
subordinate relays configuration. That's because glue makes no chance
for a global rwm instance to act on subordinates, after relaying is
done. The nature of this misbehaviour seems to be a little bit deeper,
so I didn't investigate this.

"These censorship operations against schools and libraries are stronger
than ever in the present religio-political climate. They often focus on
fantasy and sf books, which foster that deadly enemy to bigotry and blind
faith, the imagination." -- Ursula K. Le Guin