Fix include paths to new location of libutil.
[kai/samba-autobuild/.git] / source4 / ldap_server / ldap_server.c
index 11cb63e07bf2f3d753b11c9cfb576f345cb5f349..f08f24595a470e34dcf9a76c2da4f11d6348f224 100644 (file)
@@ -26,8 +26,8 @@
 #include "auth/auth.h"
 #include "auth/credentials/credentials.h"
 #include "librpc/gen_ndr/ndr_samr.h"
-#include "lib/util/dlinklist.h"
-#include "lib/util/asn1.h"
+#include "../lib/util/dlinklist.h"
+#include "../lib/util/asn1.h"
 #include "ldap_server/ldap_server.h"
 #include "smbd/service_task.h"
 #include "smbd/service_stream.h"
@@ -253,13 +253,11 @@ static int ldapsrv_load_limits(struct ldapsrv_connection *conn)
                goto failed;
        }
 
-       ret = ldb_search(conn->ldb, basedn, LDB_SCOPE_BASE, NULL, attrs, &res);
+       ret = ldb_search(conn->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_BASE, attrs, NULL);
        if (ret != LDB_SUCCESS) {
                goto failed;
        }
 
-       talloc_steal(tmp_ctx, res);
-
        if (res->count != 1) {
                goto failed;
        }
@@ -275,13 +273,11 @@ static int ldapsrv_load_limits(struct ldapsrv_connection *conn)
                goto failed;
        }
 
-       ret = ldb_search(conn->ldb, policy_dn, LDB_SCOPE_BASE, NULL, attrs2, &res);
+       ret = ldb_search(conn->ldb, tmp_ctx, &res, policy_dn, LDB_SCOPE_BASE, attrs2, NULL);
        if (ret != LDB_SUCCESS) {
                goto failed;
        }
 
-       talloc_steal(tmp_ctx, res);
-
        if (res->count != 1) {
                goto failed;
        }
@@ -409,7 +405,7 @@ static void ldapsrv_accept(struct stream_connection *c)
        conn->server_credentials = server_credentials;
 
        /* Connections start out anonymous */
-       if (!NT_STATUS_IS_OK(auth_anonymous_session_info(conn, conn->lp_ctx, &conn->session_info))) {
+       if (!NT_STATUS_IS_OK(auth_anonymous_session_info(conn, c->event.ctx, conn->lp_ctx, &conn->session_info))) {
                ldapsrv_terminate_connection(conn, "failed to setup anonymous session info");
                return;
        }
@@ -477,8 +473,9 @@ static NTSTATUS add_socket(struct event_context *event_context,
                }
        }
 
-       /* Load LDAP database */
-       ldb = samdb_connect(ldap_service, lp_ctx, system_session(ldap_service, lp_ctx));
+       /* Load LDAP database, but only to read our settings */
+       ldb = samdb_connect(ldap_service, ldap_service->task->event_ctx, 
+                           lp_ctx, system_session(ldap_service, lp_ctx));
        if (!ldb) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
@@ -496,6 +493,10 @@ static NTSTATUS add_socket(struct event_context *event_context,
                }
        }
 
+       /* And once we are bound, free the tempoary ldb, it will
+        * connect again on each incoming LDAP connection */
+       talloc_free(ldb);
+
        return status;
 }
 
@@ -524,7 +525,7 @@ static void ldapsrv_task_init(struct task_server *task)
        task_server_set_title(task, "task[ldapsrv]");
 
        /* run the ldap server as a single process */
-       model_ops = process_model_byname("single");
+       model_ops = process_model_startup(task->event_ctx, "single");
        if (!model_ops) goto failed;
 
        ldap_service = talloc_zero(task, struct ldapsrv_service);