s4/ldap: Fix nested searches SEGFAULT bug
[ira/wip.git] / source4 / lib / ldb / ldb_ildap / ldb_ildap.c
index 352b7696d698fa47492bfb6b93e2de4f54e1368f..6eb2e1719c8b2b50abe52506037b9263e01c1e74 100644 (file)
@@ -278,6 +278,13 @@ static void ildb_callback(struct ldap_request *req)
                break;
 
        case LDAP_TAG_SearchRequest:
+               /* check if we are already processing this request */
+               if (req->in_dispatch_replies) {
+                       return;
+               }
+
+               req->in_dispatch_replies = true;
+
                /* loop over all messages */
                for (i = 0; i < req->num_replies; i++) {
 
@@ -327,6 +334,7 @@ static void ildb_callback(struct ldap_request *req)
                                if (ret != LDB_SUCCESS) {
                                        callback_failed = true;
                                }
+
                                break;
 
                        case LDAP_TAG_SearchResultReference:
@@ -337,6 +345,7 @@ static void ildb_callback(struct ldap_request *req)
                                if (ret != LDB_SUCCESS) {
                                        callback_failed = true;
                                }
+
                                break;
 
                        default:
@@ -350,6 +359,8 @@ static void ildb_callback(struct ldap_request *req)
                        }
                }
 
+               req->in_dispatch_replies = false;
+
                talloc_free(req->replies);
                req->replies = NULL;
                req->num_replies = 0;
@@ -513,6 +524,7 @@ static int ildb_add(struct ildb_context *ac)
        for (i = 0; i < n; i++) {
                msg->r.AddRequest.attributes[i] = mods[i]->attrib;
        }
+       msg->controls = req->controls;
 
        return ildb_request_send(ac, msg);
 }
@@ -556,7 +568,7 @@ static int ildb_modify(struct ildb_context *ac)
        for (i = 0; i < n; i++) {
                msg->r.ModifyRequest.mods[i] = *mods[i];
        }
-
+       msg->controls = req->controls;
        return ildb_request_send(ac, msg);
 }
 
@@ -580,6 +592,7 @@ static int ildb_delete(struct ildb_context *ac)
                talloc_free(msg);
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
+       msg->controls = req->controls;
 
        return ildb_request_send(ac, msg);
 }
@@ -629,6 +642,7 @@ static int ildb_rename(struct ildb_context *ac)
        }
 
        msg->r.ModifyDNRequest.deleteolddn = true;
+       msg->controls = req->controls;
 
        return ildb_request_send(ac, msg);
 }
@@ -771,7 +785,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url,
        struct loadparm_context *lp_ctx;
 
        module = ldb_module_new(ldb, ldb, "ldb_ildap backend", &ildb_ops);
-       if (!module) return -1;
+       if (!module) return LDB_ERR_OPERATIONS_ERROR;
 
        ildb = talloc(module, struct ildb_private);
        if (!ildb) {
@@ -833,11 +847,11 @@ static int ildb_connect(struct ldb_context *ldb, const char *url,
        }
 
        *_module = module;
-       return 0;
+       return LDB_SUCCESS;
 
 failed:
        talloc_free(module);
-       return -1;
+       return LDB_ERR_OPERATIONS_ERROR;
 }
 
 _PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = {