On Tue, 2009-08-25 at 08:46 +0200, Stefan (metze) Metzmacher wrote:
> Hi Andrew,
> 
> >  static int show_deleted_search(struct ldb_module *module, struct 
> > ldb_request *req)
> >  {
> >     struct ldb_context *ldb;
> >     struct ldb_control *control;
> >     struct ldb_control **saved_controls;
> > -   struct show_deleted_search_request *ar;
> >     struct ldb_request *down_req;
> > -   char *old_filter;
> > -   char *new_filter;
> > +   struct ldb_parse_tree *nodeleted_tree;
> > +   struct ldb_parse_tree *new_tree = req->op.search.tree;
> >     int ret;
> >  
> >     ldb = ldb_module_get_ctx(module);
> >  
> > -   ar = talloc_zero(req, struct show_deleted_search_request);
> > -   if (ar == NULL) {
> > -           return LDB_ERR_OPERATIONS_ERROR;
> > -   }
> > -   ar->module = module;
> > -   ar->req = req;
> > -
> >     /* check if there's a show deleted control */
> >     control = ldb_request_get_control(req, LDB_CONTROL_SHOW_DELETED_OID);
> >  
> > -   if ( ! control) {
> > -           old_filter = ldb_filter_from_tree(ar, req->op.search.tree);
> > -           new_filter = talloc_asprintf(ar, "(&(!(isDeleted=TRUE))%s)",
> > -                                            old_filter);
> > -
> > -           ret = ldb_build_search_req(&down_req, ldb, ar,
> > -                                      req->op.search.base,
> > -                                      req->op.search.scope,
> > -                                      new_filter,
> > -                                      req->op.search.attrs,
> > -                                      req->controls,
> > -                                      ar, show_deleted_search_callback,
> > -                                      req);
> > -
> > -   } else {
> > -           ret = ldb_build_search_req_ex(&down_req, ldb, ar,
> > -                                         req->op.search.base,
> > -                                         req->op.search.scope,
> > -                                         req->op.search.tree,
> > -                                         req->op.search.attrs,
> > -                                         req->controls,
> > -                                         ar, show_deleted_search_callback,
> > -                                         req);
> > +   if (! control) {
> > +           nodeleted_tree = 
> > talloc_get_type(ldb_module_get_private(module), 
> > +                                            struct ldb_parse_tree);
> > +           if (nodeleted_tree) {
> > +                   new_tree = talloc(req, struct ldb_parse_tree);
> > +                   if (!new_tree) {
> > +                           ldb_oom(ldb);
> > +                           return LDB_ERR_OPERATIONS_ERROR;
> > +                   }
> > +                   *new_tree = *nodeleted_tree;
> > +                   /* Replace dummy part of 'and' with the old, tree,
> > +                      without a parse step */
> > +                   new_tree->u.list.elements[0] = req->op.search.tree;
> > +           }
> >     }
> > +   
> > +   ret = ldb_build_search_req_ex(&down_req, ldb, req,
> > +                                 req->op.search.base,
> > +                                 req->op.search.scope,
> > +                                 new_tree,
> > +                                 req->op.search.attrs,
> > +                                 req->controls,
> > +                                 req->context, req->callback,
> > +                                 req);
> >     if (ret != LDB_SUCCESS) {
> >             return ret;
> >     }
> > @@ -138,10 +93,20 @@ static int show_deleted_search(struct ldb_module 
> > *module, struct ldb_request *re
> >  static int show_deleted_init(struct ldb_module *module)
> >  {
> >     struct ldb_context *ldb;
> > +   struct ldb_parse_tree *nodeleted_tree;
> >     int ret;
> >  
> >     ldb = ldb_module_get_ctx(module);
> >  
> > +   nodeleted_tree = ldb_parse_tree(module, 
> > "(&(replace=me)(!(isDeleted=TRUE)))");
> > +   if (!nodeleted_tree) {
> > +           ldb_debug(ldb, LDB_DEBUG_ERROR,
> > +                   "show_deleted: Unable to parse isDeleted master 
> > expression!\n");
> > +           return LDB_ERR_OPERATIONS_ERROR;
> > +   }
> > +
> > +   ldb_module_set_private(module, nodeleted_tree);
> 
> Why do we need to keep that as a "global" variable?
> That doesn't play nicely together with multiple async searches.
> I'd prefer to let each search request build its own parse tree.

We use structure assignment to create a local copy of this that we then
insert the original tree into.  I'll see about using a deep copy of the
template if that would make you happier. 

Andrew Bartlett

-- 
Andrew Bartlett
http://samba.org/~abartlet/
Authentication Developer, Samba Team           http://samba.org
Samba Developer, Cisco Inc.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to