2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2004
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "ldap_server/ldap_server.h"
23 #include "lib/util/dlinklist.h"
24 #include "libcli/ldap/ldap.h"
25 #include "lib/ldb/include/ldb.h"
26 #include "lib/ldb/include/ldb_errors.h"
27 #include "lib/db_wrap.h"
28 #include "auth/credentials/credentials.h"
29 #include "auth/gensec/gensec.h"
31 #define VALID_DN_SYNTAX(dn,i) do {\
33 return NT_STATUS_NO_MEMORY;\
34 } else if (ldb_dn_get_comp_num(dn) < (i)) {\
35 result = LDAP_INVALID_DN_SYNTAX;\
36 errstr = "Invalid DN (" #i " components needed for '" #dn "')";\
41 static int map_ldb_error(struct ldb_context *ldb, int err, const char **errstring)
43 *errstring = ldb_errstring(ldb);
50 connect to the sam database
52 NTSTATUS ldapsrv_backend_Init(struct ldapsrv_connection *conn)
54 conn->ldb = ldb_wrap_connect(conn, lp_sam_url(), conn->session_info,
55 NULL, conn->global_catalog ? LDB_FLG_RDONLY : 0, NULL);
56 if (conn->ldb == NULL) {
57 return NT_STATUS_INTERNAL_DB_CORRUPTION;
60 if (conn->server_credentials) {
61 char **sasl_mechs = NULL;
62 struct gensec_security_ops **backends = gensec_security_all();
63 enum credentials_use_kerberos use_kerberos
64 = cli_credentials_get_kerberos_state(conn->server_credentials);
65 struct gensec_security_ops **ops
66 = gensec_use_kerberos_mechs(conn, backends, use_kerberos);
68 for (i = 0; ops && ops[i]; i++) {
69 if (ops[i]->sasl_name && ops[i]->server_start) {
70 char *sasl_name = talloc_strdup(conn, ops[i]->sasl_name);
73 return NT_STATUS_NO_MEMORY;
75 sasl_mechs = talloc_realloc(conn, sasl_mechs, char *, j + 2);
77 return NT_STATUS_NO_MEMORY;
79 sasl_mechs[j] = sasl_name;
80 talloc_steal(sasl_mechs, sasl_name);
81 sasl_mechs[j+1] = NULL;
86 ldb_set_opaque(conn->ldb, "supportedSASLMechanims", sasl_mechs);
89 if (conn->global_catalog) {
90 ldb_set_opaque(conn->ldb, "global_catalog", (void *)(-1));
96 struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type)
98 struct ldapsrv_reply *reply;
100 reply = talloc(call, struct ldapsrv_reply);
104 reply->msg = talloc(reply, struct ldap_message);
105 if (reply->msg == NULL) {
110 reply->msg->messageid = call->request->messageid;
111 reply->msg->type = type;
112 reply->msg->controls = NULL;
117 void ldapsrv_queue_reply(struct ldapsrv_call *call, struct ldapsrv_reply *reply)
119 DLIST_ADD_END(call->replies, reply, struct ldapsrv_reply *);
122 NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
124 struct ldapsrv_reply *reply;
125 struct ldap_ExtendedResponse *r;
127 DEBUG(10,("Unwilling type[%d] id[%d]\n", call->request->type, call->request->messageid));
129 reply = ldapsrv_init_reply(call, LDAP_TAG_ExtendedResponse);
131 return NT_STATUS_NO_MEMORY;
134 r = &reply->msg->r.ExtendedResponse;
135 r->response.resultcode = error;
136 r->response.dn = NULL;
137 r->response.errormessage = NULL;
138 r->response.referral = NULL;
142 ldapsrv_queue_reply(call, reply);
146 static int ldapsrv_SearchCallback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
148 struct ldb_result *res;
151 if (!context || !ares) {
152 DEBUG(3, ("NULL Context or Ares in ldapsrv_SearchCallback"));
153 return LDB_ERR_OPERATIONS_ERROR;
156 res = talloc_get_type(context, struct ldb_result);
158 if (ares->type == LDB_REPLY_ENTRY) {
159 res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2);
164 res->msgs[res->count + 1] = NULL;
166 res->msgs[res->count] = talloc_steal(res->msgs, ares->message);
167 if (! res->msgs[res->count]) {
174 if (ares->type == LDB_REPLY_REFERRAL) {
176 for (n = 0; res->refs[n]; n++) /*noop*/ ;
181 res->refs = talloc_realloc(res, res->refs, char *, n + 2);
186 res->refs[n] = talloc_steal(res->refs, ares->referral);
187 res->refs[n + 1] = NULL;
190 if (ares->controls) {
191 res->controls = talloc_steal(res, ares->controls);
192 if (! res->controls) {
202 return LDB_ERR_OPERATIONS_ERROR;
205 static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
207 struct ldap_SearchRequest *req = &call->request->r.SearchRequest;
208 struct ldap_SearchResEntry *ent;
209 struct ldap_Result *done;
210 struct ldapsrv_reply *ent_r, *done_r;
212 struct ldb_context *samdb = talloc_get_type(call->conn->ldb, struct ldb_context);
213 struct ldb_dn *basedn;
214 struct ldb_result *res = NULL;
215 struct ldb_request *lreq;
216 enum ldb_scope scope = LDB_SCOPE_DEFAULT;
217 const char **attrs = NULL;
218 const char *errstr = NULL;
219 int success_limit = 1;
224 DEBUG(10, ("SearchRequest"));
225 DEBUGADD(10, (" basedn: %s", req->basedn));
226 DEBUGADD(10, (" filter: %s\n", ldb_filter_from_tree(call, req->tree)));
228 local_ctx = talloc_new(call);
229 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
231 basedn = ldb_dn_explode(local_ctx, req->basedn);
232 VALID_DN_SYNTAX(basedn, 0);
234 DEBUG(10, ("SearchRequest: basedn: [%s]\n", req->basedn));
235 DEBUG(10, ("SearchRequest: filter: [%s]\n", ldb_filter_from_tree(call, req->tree)));
237 switch (req->scope) {
238 case LDAP_SEARCH_SCOPE_BASE:
239 DEBUG(10,("SearchRequest: scope: [BASE]\n"));
240 scope = LDB_SCOPE_BASE;
243 case LDAP_SEARCH_SCOPE_SINGLE:
244 DEBUG(10,("SearchRequest: scope: [ONE]\n"));
245 scope = LDB_SCOPE_ONELEVEL;
248 case LDAP_SEARCH_SCOPE_SUB:
249 DEBUG(10,("SearchRequest: scope: [SUB]\n"));
250 scope = LDB_SCOPE_SUBTREE;
254 result = LDAP_PROTOCOL_ERROR;
255 errstr = "Invalid scope";
259 if (req->num_attributes >= 1) {
260 attrs = talloc_array(samdb, const char *, req->num_attributes+1);
261 NT_STATUS_HAVE_NO_MEMORY(attrs);
263 for (i=0; i < req->num_attributes; i++) {
264 DEBUG(10,("SearchRequest: attrs: [%s]\n",req->attributes[i]));
265 attrs[i] = req->attributes[i];
270 DEBUG(5,("ldb_request dn=%s filter=%s\n",
271 req->basedn, ldb_filter_from_tree(call, req->tree)));
273 lreq = talloc(local_ctx, struct ldb_request);
274 NT_STATUS_HAVE_NO_MEMORY(lreq);
276 res = talloc_zero(local_ctx, struct ldb_result);
277 NT_STATUS_HAVE_NO_MEMORY(res);
279 lreq->operation = LDB_SEARCH;
280 lreq->op.search.base = basedn;
281 lreq->op.search.scope = scope;
282 lreq->op.search.tree = req->tree;
283 lreq->op.search.attrs = attrs;
285 lreq->controls = call->request->controls;
288 lreq->callback = ldapsrv_SearchCallback;
290 /* Copy the timeout from the incoming call */
291 ldb_set_timeout(samdb, lreq, req->timelimit);
293 ldb_ret = ldb_request(samdb, lreq);
295 if (ldb_ret != LDB_SUCCESS) {
299 ldb_ret = ldb_wait(lreq->handle, LDB_WAIT_ALL);
301 if (ldb_ret == LDB_SUCCESS) {
302 for (i = 0; i < res->count; i++) {
303 ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
304 NT_STATUS_HAVE_NO_MEMORY(ent_r);
306 ent = &ent_r->msg->r.SearchResultEntry;
307 ent->dn = ldb_dn_linearize(ent_r, res->msgs[i]->dn);
308 ent->num_attributes = 0;
309 ent->attributes = NULL;
310 if (res->msgs[i]->num_elements == 0) {
313 ent->num_attributes = res->msgs[i]->num_elements;
314 ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
315 NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
316 for (j=0; j < ent->num_attributes; j++) {
317 ent->attributes[j].name = talloc_steal(ent->attributes, res->msgs[i]->elements[j].name);
318 ent->attributes[j].num_values = 0;
319 ent->attributes[j].values = NULL;
320 if (req->attributesonly && (res->msgs[i]->elements[j].num_values == 0)) {
323 ent->attributes[j].num_values = res->msgs[i]->elements[j].num_values;
324 ent->attributes[j].values = res->msgs[i]->elements[j].values;
325 talloc_steal(ent->attributes, res->msgs[i]->elements[j].values);
328 ldapsrv_queue_reply(call, ent_r);
333 done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
334 NT_STATUS_HAVE_NO_MEMORY(done_r);
336 done = &done_r->msg->r.SearchResultDone;
338 done->referral = NULL;
341 } else if (ldb_ret == LDB_SUCCESS) {
342 if (res->count >= success_limit) {
343 DEBUG(10,("SearchRequest: results: [%d]\n", res->count));
344 result = LDAP_SUCCESS;
346 } else if (res->count == 0) {
347 DEBUG(10,("SearchRequest: no results\n"));
348 result = LDAP_NO_SUCH_OBJECT;
349 errstr = ldb_errstring(samdb);
352 done_r->msg->controls = res->controls;
353 talloc_steal(done_r, res->controls);
356 DEBUG(10,("SearchRequest: error\n"));
357 result = map_ldb_error(samdb, ldb_ret, &errstr);
360 done->resultcode = result;
361 done->errormessage = (errstr?talloc_strdup(done_r, errstr):NULL);
363 talloc_free(local_ctx);
365 ldapsrv_queue_reply(call, done_r);
369 static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
371 struct ldap_ModifyRequest *req = &call->request->r.ModifyRequest;
372 struct ldap_Result *modify_result;
373 struct ldapsrv_reply *modify_reply;
375 struct ldb_context *samdb = call->conn->ldb;
376 struct ldb_message *msg = NULL;
378 const char *errstr = NULL;
379 int result = LDAP_SUCCESS;
383 DEBUG(10, ("ModifyRequest"));
384 DEBUGADD(10, (" dn: %s", req->dn));
386 local_ctx = talloc_named(call, 0, "ModifyRequest local memory context");
387 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
389 dn = ldb_dn_explode(local_ctx, req->dn);
390 VALID_DN_SYNTAX(dn, 1);
392 DEBUG(10, ("ModifyRequest: dn: [%s]\n", req->dn));
394 msg = talloc(local_ctx, struct ldb_message);
395 NT_STATUS_HAVE_NO_MEMORY(msg);
398 msg->private_data = NULL;
399 msg->num_elements = 0;
400 msg->elements = NULL;
402 if (req->num_mods > 0) {
403 msg->num_elements = req->num_mods;
404 msg->elements = talloc_array(msg, struct ldb_message_element, req->num_mods);
405 NT_STATUS_HAVE_NO_MEMORY(msg->elements);
407 for (i=0; i < msg->num_elements; i++) {
408 msg->elements[i].name = discard_const_p(char, req->mods[i].attrib.name);
409 msg->elements[i].num_values = 0;
410 msg->elements[i].values = NULL;
412 switch (req->mods[i].type) {
414 result = LDAP_PROTOCOL_ERROR;
415 errstr = "Invalid LDAP_MODIFY_* type";
417 case LDAP_MODIFY_ADD:
418 msg->elements[i].flags = LDB_FLAG_MOD_ADD;
420 case LDAP_MODIFY_DELETE:
421 msg->elements[i].flags = LDB_FLAG_MOD_DELETE;
423 case LDAP_MODIFY_REPLACE:
424 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
428 msg->elements[i].num_values = req->mods[i].attrib.num_values;
429 if (msg->elements[i].num_values > 0) {
430 msg->elements[i].values = talloc_array(msg, struct ldb_val, msg->elements[i].num_values);
431 NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);
433 for (j=0; j < msg->elements[i].num_values; j++) {
434 if (!(req->mods[i].attrib.values[j].length > 0)) {
436 errstr = "Empty attribute values are not allowed";
439 msg->elements[i].values[j].length = req->mods[i].attrib.values[j].length;
440 msg->elements[i].values[j].data = req->mods[i].attrib.values[j].data;
446 errstr = "No mods are not allowed";
451 modify_reply = ldapsrv_init_reply(call, LDAP_TAG_ModifyResponse);
452 NT_STATUS_HAVE_NO_MEMORY(modify_reply);
454 if (result == LDAP_SUCCESS) {
455 ldb_ret = ldb_modify(samdb, msg);
456 result = map_ldb_error(samdb, ldb_ret, &errstr);
459 modify_result = &modify_reply->msg->r.AddResponse;
460 modify_result->dn = NULL;
461 modify_result->resultcode = result;
462 modify_result->errormessage = (errstr?talloc_strdup(modify_reply, errstr):NULL);
463 modify_result->referral = NULL;
465 talloc_free(local_ctx);
467 ldapsrv_queue_reply(call, modify_reply);
472 static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
474 struct ldap_AddRequest *req = &call->request->r.AddRequest;
475 struct ldap_Result *add_result;
476 struct ldapsrv_reply *add_reply;
478 struct ldb_context *samdb = call->conn->ldb;
479 struct ldb_message *msg = NULL;
481 const char *errstr = NULL;
482 int result = LDAP_SUCCESS;
486 DEBUG(10, ("AddRequest"));
487 DEBUGADD(10, (" dn: %s", req->dn));
489 local_ctx = talloc_named(call, 0, "AddRequest local memory context");
490 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
492 dn = ldb_dn_explode(local_ctx, req->dn);
493 VALID_DN_SYNTAX(dn,1);
495 DEBUG(10, ("AddRequest: dn: [%s]\n", req->dn));
497 msg = talloc(local_ctx, struct ldb_message);
498 NT_STATUS_HAVE_NO_MEMORY(msg);
501 msg->private_data = NULL;
502 msg->num_elements = 0;
503 msg->elements = NULL;
505 if (req->num_attributes > 0) {
506 msg->num_elements = req->num_attributes;
507 msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements);
508 NT_STATUS_HAVE_NO_MEMORY(msg->elements);
510 for (i=0; i < msg->num_elements; i++) {
511 msg->elements[i].name = discard_const_p(char, req->attributes[i].name);
512 msg->elements[i].flags = 0;
513 msg->elements[i].num_values = 0;
514 msg->elements[i].values = NULL;
516 if (req->attributes[i].num_values > 0) {
517 msg->elements[i].num_values = req->attributes[i].num_values;
518 msg->elements[i].values = talloc_array(msg, struct ldb_val, msg->elements[i].num_values);
519 NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);
521 for (j=0; j < msg->elements[i].num_values; j++) {
522 if (!(req->attributes[i].values[j].length > 0)) {
524 errstr = "Empty attribute values are not allowed";
527 msg->elements[i].values[j].length = req->attributes[i].values[j].length;
528 msg->elements[i].values[j].data = req->attributes[i].values[j].data;
532 errstr = "No attribute values are not allowed";
538 errstr = "No attributes are not allowed";
543 add_reply = ldapsrv_init_reply(call, LDAP_TAG_AddResponse);
544 NT_STATUS_HAVE_NO_MEMORY(add_reply);
546 if (result == LDAP_SUCCESS) {
547 ldb_ret = ldb_add(samdb, msg);
548 result = map_ldb_error(samdb, ldb_ret, &errstr);
551 add_result = &add_reply->msg->r.AddResponse;
552 add_result->dn = NULL;
553 add_result->resultcode = result;
554 add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);
555 add_result->referral = NULL;
557 talloc_free(local_ctx);
559 ldapsrv_queue_reply(call, add_reply);
564 static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
566 struct ldap_DelRequest *req = &call->request->r.DelRequest;
567 struct ldap_Result *del_result;
568 struct ldapsrv_reply *del_reply;
570 struct ldb_context *samdb = call->conn->ldb;
572 const char *errstr = NULL;
573 int result = LDAP_SUCCESS;
576 DEBUG(10, ("DelRequest"));
577 DEBUGADD(10, (" dn: %s", req->dn));
579 local_ctx = talloc_named(call, 0, "DelRequest local memory context");
580 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
582 dn = ldb_dn_explode(local_ctx, req->dn);
583 VALID_DN_SYNTAX(dn,1);
585 DEBUG(10, ("DelRequest: dn: [%s]\n", req->dn));
588 del_reply = ldapsrv_init_reply(call, LDAP_TAG_DelResponse);
589 NT_STATUS_HAVE_NO_MEMORY(del_reply);
591 if (result == LDAP_SUCCESS) {
592 ldb_ret = ldb_delete(samdb, dn);
593 result = map_ldb_error(samdb, ldb_ret, &errstr);
596 del_result = &del_reply->msg->r.DelResponse;
597 del_result->dn = NULL;
598 del_result->resultcode = result;
599 del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);
600 del_result->referral = NULL;
602 talloc_free(local_ctx);
604 ldapsrv_queue_reply(call, del_reply);
608 static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
610 struct ldap_ModifyDNRequest *req = &call->request->r.ModifyDNRequest;
611 struct ldap_Result *modifydn;
612 struct ldapsrv_reply *modifydn_r;
614 struct ldb_context *samdb = call->conn->ldb;
615 struct ldb_dn *olddn, *newdn=NULL, *newrdn;
616 struct ldb_dn *parentdn = NULL;
617 const char *errstr = NULL;
618 int result = LDAP_SUCCESS;
621 DEBUG(10, ("ModifyDNRequrest"));
622 DEBUGADD(10, (" dn: %s", req->dn));
623 DEBUGADD(10, (" newrdn: %s", req->newrdn));
625 local_ctx = talloc_named(call, 0, "ModifyDNRequest local memory context");
626 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
628 olddn = ldb_dn_explode(local_ctx, req->dn);
629 VALID_DN_SYNTAX(olddn, 2);
631 newrdn = ldb_dn_explode(local_ctx, req->newrdn);
632 VALID_DN_SYNTAX(newrdn, 1);
634 DEBUG(10, ("ModifyDNRequest: olddn: [%s]\n", req->dn));
635 DEBUG(10, ("ModifyDNRequest: newrdn: [%s]\n", req->newrdn));
637 /* we can't handle the rename if we should not remove the old dn */
638 if (!req->deleteolddn) {
639 result = LDAP_UNWILLING_TO_PERFORM;
640 errstr = "Old RDN must be deleted";
644 if (ldb_dn_get_comp_num(newrdn) > 1) {
645 result = LDAP_NAMING_VIOLATION;
646 errstr = "Error new RDN invalid";
650 if (req->newsuperior) {
651 parentdn = ldb_dn_explode(local_ctx, req->newsuperior);
652 VALID_DN_SYNTAX(parentdn, 0);
653 DEBUG(10, ("ModifyDNRequest: newsuperior: [%s]\n", req->newsuperior));
655 if (ldb_dn_get_comp_num(parentdn) < 1) {
656 result = LDAP_AFFECTS_MULTIPLE_DSAS;
657 errstr = "Error new Superior DN invalid";
663 parentdn = ldb_dn_get_parent(local_ctx, olddn);
664 NT_STATUS_HAVE_NO_MEMORY(parentdn);
667 newdn = ldb_dn_build_child(local_ctx,
668 ldb_dn_get_rdn_name(newrdn),
669 (char *)ldb_dn_get_rdn_val(newrdn)->data,
671 NT_STATUS_HAVE_NO_MEMORY(newdn);
674 modifydn_r = ldapsrv_init_reply(call, LDAP_TAG_ModifyDNResponse);
675 NT_STATUS_HAVE_NO_MEMORY(modifydn_r);
677 if (result == LDAP_SUCCESS) {
678 ldb_ret = ldb_rename(samdb, olddn, newdn);
679 result = map_ldb_error(samdb, ldb_ret, &errstr);
682 modifydn = &modifydn_r->msg->r.ModifyDNResponse;
684 modifydn->resultcode = result;
685 modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);
686 modifydn->referral = NULL;
688 talloc_free(local_ctx);
690 ldapsrv_queue_reply(call, modifydn_r);
694 static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
696 struct ldap_CompareRequest *req = &call->request->r.CompareRequest;
697 struct ldap_Result *compare;
698 struct ldapsrv_reply *compare_r;
700 struct ldb_context *samdb = call->conn->ldb;
701 struct ldb_result *res = NULL;
703 const char *attrs[1];
704 const char *errstr = NULL;
705 const char *filter = NULL;
706 int result = LDAP_SUCCESS;
709 DEBUG(10, ("CompareRequest"));
710 DEBUGADD(10, (" dn: %s", req->dn));
712 local_ctx = talloc_named(call, 0, "CompareRequest local_memory_context");
713 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
715 dn = ldb_dn_explode(local_ctx, req->dn);
716 VALID_DN_SYNTAX(dn, 1);
718 DEBUG(10, ("CompareRequest: dn: [%s]\n", req->dn));
719 filter = talloc_asprintf(local_ctx, "(%s=%*s)", req->attribute,
720 (int)req->value.length, req->value.data);
721 NT_STATUS_HAVE_NO_MEMORY(filter);
723 DEBUGADD(10, ("CompareRequest: attribute: [%s]\n", filter));
728 compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse);
729 NT_STATUS_HAVE_NO_MEMORY(compare_r);
731 if (result == LDAP_SUCCESS) {
732 ldb_ret = ldb_search(samdb, dn, LDB_SCOPE_BASE, filter, attrs, &res);
733 talloc_steal(samdb, res);
734 if (ldb_ret != LDB_SUCCESS) {
735 result = map_ldb_error(samdb, ldb_ret, &errstr);
736 DEBUG(10,("CompareRequest: error: %s\n", errstr));
737 } else if (res->count == 0) {
738 DEBUG(10,("CompareRequest: doesn't matched\n"));
739 result = LDAP_COMPARE_FALSE;
741 } else if (res->count == 1) {
742 DEBUG(10,("CompareRequest: matched\n"));
743 result = LDAP_COMPARE_TRUE;
745 } else if (res->count > 1) {
747 errstr = "too many objects match";
748 DEBUG(10,("CompareRequest: %d results: %s\n", res->count, errstr));
752 compare = &compare_r->msg->r.CompareResponse;
754 compare->resultcode = result;
755 compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL);
756 compare->referral = NULL;
758 talloc_free(local_ctx);
760 ldapsrv_queue_reply(call, compare_r);
764 static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call)
766 /* struct ldap_AbandonRequest *req = &call->request.r.AbandonRequest;*/
767 DEBUG(10, ("AbandonRequest\n"));
771 NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call)
773 switch(call->request->type) {
774 case LDAP_TAG_BindRequest:
775 return ldapsrv_BindRequest(call);
776 case LDAP_TAG_UnbindRequest:
777 return ldapsrv_UnbindRequest(call);
778 case LDAP_TAG_SearchRequest:
779 return ldapsrv_SearchRequest(call);
780 case LDAP_TAG_ModifyRequest:
781 return ldapsrv_ModifyRequest(call);
782 case LDAP_TAG_AddRequest:
783 return ldapsrv_AddRequest(call);
784 case LDAP_TAG_DelRequest:
785 return ldapsrv_DelRequest(call);
786 case LDAP_TAG_ModifyDNRequest:
787 return ldapsrv_ModifyDNRequest(call);
788 case LDAP_TAG_CompareRequest:
789 return ldapsrv_CompareRequest(call);
790 case LDAP_TAG_AbandonRequest:
791 return ldapsrv_AbandonRequest(call);
792 case LDAP_TAG_ExtendedRequest:
793 return ldapsrv_ExtendedRequest(call);
795 return ldapsrv_unwilling(call, 2);