summaryrefslogtreecommitdiff
path: root/source4/ldap_server
diff options
context:
space:
mode:
Diffstat (limited to 'source4/ldap_server')
-rw-r--r--source4/ldap_server/ldap_backend.c14
-rw-r--r--source4/ldap_server/ldap_bind.c1
-rw-r--r--source4/ldap_server/ldap_server.h16
-rw-r--r--source4/ldap_server/ldap_simple_ldb.c77
4 files changed, 80 insertions, 28 deletions
diff --git a/source4/ldap_server/ldap_backend.c b/source4/ldap_server/ldap_backend.c
index 637ce7bd63..1e6d05a9bd 100644
--- a/source4/ldap_server/ldap_backend.c
+++ b/source4/ldap_server/ldap_backend.c
@@ -21,6 +21,7 @@
#include "includes.h"
#include "ldap_server/ldap_server.h"
#include "dlinklist.h"
+#include "libcli/ldap/ldap.h"
struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type)
@@ -39,6 +40,7 @@ struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type
reply->msg->messageid = call->request->messageid;
reply->msg->type = type;
+ reply->msg->controls = NULL;
return reply;
}
@@ -108,7 +110,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
return NT_STATUS_OK;
}
- return part->ops->Search(part, call, req);
+ return part->ops->Search(part, call);
}
static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
@@ -125,7 +127,7 @@ static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
return ldapsrv_unwilling(call, 53);
}
- return part->ops->Modify(part, call, req);
+ return part->ops->Modify(part, call);
}
static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
@@ -142,7 +144,7 @@ static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
return ldapsrv_unwilling(call, 53);
}
- return part->ops->Add(part, call, req);
+ return part->ops->Add(part, call);
}
static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
@@ -159,7 +161,7 @@ static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
return ldapsrv_unwilling(call, 53);
}
- return part->ops->Del(part, call, req);
+ return part->ops->Del(part, call);
}
static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
@@ -177,7 +179,7 @@ static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
return ldapsrv_unwilling(call, 53);
}
- return part->ops->ModifyDN(part, call, req);
+ return part->ops->ModifyDN(part, call);
}
static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
@@ -194,7 +196,7 @@ static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
return ldapsrv_unwilling(call, 53);
}
- return part->ops->Compare(part, call, req);
+ return part->ops->Compare(part, call);
}
static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call)
diff --git a/source4/ldap_server/ldap_bind.c b/source4/ldap_server/ldap_bind.c
index feb36135a8..4a0ee0044d 100644
--- a/source4/ldap_server/ldap_bind.c
+++ b/source4/ldap_server/ldap_bind.c
@@ -21,6 +21,7 @@
#include "includes.h"
#include "ldap_server/ldap_server.h"
#include "auth/auth.h"
+#include "libcli/ldap/ldap.h"
#include "smbd/service_stream.h"
#include "dsdb/samdb/samdb.h"
diff --git a/source4/ldap_server/ldap_server.h b/source4/ldap_server/ldap_server.h
index d25f52bf4e..267b6fb9a7 100644
--- a/source4/ldap_server/ldap_server.h
+++ b/source4/ldap_server/ldap_server.h
@@ -53,14 +53,14 @@ struct ldapsrv_partition_ops {
const char *name;
NTSTATUS (*Init)(struct ldapsrv_partition *partition, struct ldapsrv_connection *conn);
NTSTATUS (*Bind)(struct ldapsrv_partition *partition, struct ldapsrv_connection *conn);
- NTSTATUS (*Search)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_SearchRequest *r);
- NTSTATUS (*Modify)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_ModifyRequest *r);
- NTSTATUS (*Add)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_AddRequest *r);
- NTSTATUS (*Del)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_DelRequest *r);
- NTSTATUS (*ModifyDN)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_ModifyDNRequest *r);
- NTSTATUS (*Compare)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_CompareRequest *r);
- NTSTATUS (*Abandon)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_AbandonRequest *r);
- NTSTATUS (*Extended)(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_ExtendedRequest *r);
+ NTSTATUS (*Search)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*Modify)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*Add)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*Del)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*ModifyDN)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*Compare)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*Abandon)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
+ NTSTATUS (*Extended)(struct ldapsrv_partition *partition, struct ldapsrv_call *call);
};
struct ldapsrv_partition {
diff --git a/source4/ldap_server/ldap_simple_ldb.c b/source4/ldap_server/ldap_simple_ldb.c
index 0421bb42ab..fd89a19737 100644
--- a/source4/ldap_server/ldap_simple_ldb.c
+++ b/source4/ldap_server/ldap_simple_ldb.c
@@ -21,6 +21,7 @@
#include "includes.h"
#include "ldap_server/ldap_server.h"
+#include "lib/ldb/include/ldb.h"
#include "lib/ldb/include/ldb_errors.h"
#include "dsdb/samdb/samdb.h"
@@ -49,6 +50,41 @@ static int sldb_map_error(struct ldapsrv_partition *partition, int ldb_ret,
return ldb_ret;
}
+static int sldb_get_ldb_controls(void *mem_ctx, struct ldap_Control **controls, struct ldb_control ***lcontrols)
+{
+ struct ldb_control **lctrl;
+ int i, l;
+
+ if (controls == NULL || controls[0] == NULL) {
+ *lcontrols = NULL;
+ return LDB_SUCCESS;
+ }
+
+ l = 0;
+ lctrl = NULL;
+ *lcontrols = NULL;
+
+ for (i = 0; controls[i] != NULL; i++) {
+ lctrl = talloc_realloc(mem_ctx, lctrl, struct ldb_control *, l + 2);
+ if (lctrl == NULL) {
+ return LDB_ERR_OTHER;
+ }
+ lctrl[l] = talloc(lctrl, struct ldb_control);
+ if (lctrl[l] == NULL) {
+ return LDB_ERR_OTHER;
+ }
+ lctrl[l]->oid = controls[i]->oid;
+ lctrl[l]->critical = controls[i]->critical;
+ lctrl[l]->data = controls[i]->value;
+ l++;
+ }
+ lctrl[l] = NULL;
+
+ *lcontrols = lctrl;
+
+ return LDB_SUCCESS;
+}
+
/*
connect to the sam database
*/
@@ -86,9 +122,9 @@ NTSTATUS sldb_Bind(struct ldapsrv_partition *partition, struct ldapsrv_connectio
return status;
}
-static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
- struct ldap_SearchRequest *r)
+static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_call *call)
{
+ struct ldap_SearchRequest *r = &call->request->r.SearchRequest;
void *local_ctx;
struct ldb_dn *basedn;
struct ldap_Result *done;
@@ -153,6 +189,14 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
lreq.op.search.scope = scope;
lreq.op.search.tree = r->tree;
lreq.op.search.attrs = attrs;
+ ret = sldb_get_ldb_controls(local_ctx, call->request->controls, &lreq.controls);
+
+ if (ret != LDB_SUCCESS) {
+ /* get_ldb_controls fails only on a critical internal error or when
+ * a control is defined as critical but it is not supported
+ */
+ goto reply;
+ }
ret = ldb_request(samdb, &lreq);
@@ -199,6 +243,10 @@ reply:
done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
NT_STATUS_HAVE_NO_MEMORY(done_r);
+ done = &done_r->msg->r.SearchResultDone;
+ done->dn = NULL;
+ done->referral = NULL;
+
if (ret == LDB_SUCCESS) {
if (res->count >= success_limit) {
DEBUG(10,("sldb_Search: results: [%d]\n", res->count));
@@ -209,17 +257,17 @@ reply:
result = LDAP_NO_SUCH_OBJECT;
errstr = ldb_errstring(samdb);
}
+ if (res->controls) {
+ done_r->msg->controls = (struct ldap_Control **)(res->controls);
+ }
} else {
DEBUG(10,("sldb_Search: error\n"));
result = ret;
errstr = ldb_errstring(samdb);
}
- done = &done_r->msg->r.SearchResultDone;
- done->dn = NULL;
done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r, errstr):NULL);
- done->referral = NULL;
talloc_free(local_ctx);
@@ -227,9 +275,9 @@ reply:
return NT_STATUS_OK;
}
-static NTSTATUS sldb_Add(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
- struct ldap_AddRequest *r)
+static NTSTATUS sldb_Add(struct ldapsrv_partition *partition, struct ldapsrv_call *call)
{
+ struct ldap_AddRequest *r = &call->request->r.AddRequest;
void *local_ctx;
struct ldb_dn *dn;
struct ldap_Result *add_result;
@@ -317,9 +365,9 @@ reply:
return NT_STATUS_OK;
}
-static NTSTATUS sldb_Del(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
- struct ldap_DelRequest *r)
+static NTSTATUS sldb_Del(struct ldapsrv_partition *partition, struct ldapsrv_call *call)
{
+ struct ldap_DelRequest *r = &call->request->r.DelRequest;
void *local_ctx;
struct ldb_dn *dn;
struct ldap_Result *del_result;
@@ -360,9 +408,9 @@ reply:
return NT_STATUS_OK;
}
-static NTSTATUS sldb_Modify(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
- struct ldap_ModifyRequest *r)
+static NTSTATUS sldb_Modify(struct ldapsrv_partition *partition, struct ldapsrv_call *call)
{
+ struct ldap_ModifyRequest *r = &call->request->r.ModifyRequest;
void *local_ctx;
struct ldb_dn *dn;
struct ldap_Result *modify_result;
@@ -461,9 +509,9 @@ reply:
return NT_STATUS_OK;
}
-static NTSTATUS sldb_Compare(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
- struct ldap_CompareRequest *r)
+static NTSTATUS sldb_Compare(struct ldapsrv_partition *partition, struct ldapsrv_call *call)
{
+ struct ldap_CompareRequest *r = &call->request->r.CompareRequest;
void *local_ctx;
struct ldb_dn *dn;
struct ldap_Result *compare;
@@ -531,8 +579,9 @@ reply:
return NT_STATUS_OK;
}
-static NTSTATUS sldb_ModifyDN(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_ModifyDNRequest *r)
+static NTSTATUS sldb_ModifyDN(struct ldapsrv_partition *partition, struct ldapsrv_call *call)
{
+ struct ldap_ModifyDNRequest *r = &call->request->r.ModifyDNRequest;
void *local_ctx;
struct ldb_dn *olddn, *newdn, *newrdn;
struct ldb_dn *parentdn = NULL;