s3:smb2_server: allow logoff, close, unlock, cancel and echo on expired sessions
[Samba.git] / source4 / ldap_server / ldap_backend.c
blob95c7ee7a7f1e778c8b546556d2812aed67882bc4
1 /*
2 Unix SMB/CIFS implementation.
3 LDAP server
4 Copyright (C) Stefan Metzmacher 2004
5 Copyright (C) Matthias Dieter Wallnöfer 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "ldap_server/ldap_server.h"
23 #include "../lib/util/dlinklist.h"
24 #include "auth/credentials/credentials.h"
25 #include "auth/gensec/gensec.h"
26 #include "auth/gensec/gensec_internal.h" /* TODO: remove this */
27 #include "auth/common_auth.h"
28 #include "param/param.h"
29 #include "smbd/service_stream.h"
30 #include "dsdb/samdb/samdb.h"
31 #include <ldb_errors.h>
32 #include <ldb_module.h>
33 #include "ldb_wrap.h"
35 static int map_ldb_error(TALLOC_CTX *mem_ctx, int ldb_err,
36 const char *add_err_string, const char **errstring)
38 WERROR err;
40 /* Certain LDB modules need to return very special WERROR codes. Proof
41 * for them here and if they exist skip the rest of the mapping. */
42 if (add_err_string != NULL) {
43 char *endptr;
44 strtol(add_err_string, &endptr, 16);
45 if (endptr != add_err_string) {
46 *errstring = add_err_string;
47 return ldb_err;
51 /* Otherwise we calculate here a generic, but appropriate WERROR. */
53 switch (ldb_err) {
54 case LDB_SUCCESS:
55 err = WERR_OK;
56 break;
57 case LDB_ERR_OPERATIONS_ERROR:
58 err = WERR_DS_OPERATIONS_ERROR;
59 break;
60 case LDB_ERR_PROTOCOL_ERROR:
61 err = WERR_DS_PROTOCOL_ERROR;
62 break;
63 case LDB_ERR_TIME_LIMIT_EXCEEDED:
64 err = WERR_DS_TIMELIMIT_EXCEEDED;
65 break;
66 case LDB_ERR_SIZE_LIMIT_EXCEEDED:
67 err = WERR_DS_SIZELIMIT_EXCEEDED;
68 break;
69 case LDB_ERR_COMPARE_FALSE:
70 err = WERR_DS_COMPARE_FALSE;
71 break;
72 case LDB_ERR_COMPARE_TRUE:
73 err = WERR_DS_COMPARE_TRUE;
74 break;
75 case LDB_ERR_AUTH_METHOD_NOT_SUPPORTED:
76 err = WERR_DS_AUTH_METHOD_NOT_SUPPORTED;
77 break;
78 case LDB_ERR_STRONG_AUTH_REQUIRED:
79 err = WERR_DS_STRONG_AUTH_REQUIRED;
80 break;
81 case LDB_ERR_REFERRAL:
82 err = WERR_DS_REFERRAL;
83 break;
84 case LDB_ERR_ADMIN_LIMIT_EXCEEDED:
85 err = WERR_DS_ADMIN_LIMIT_EXCEEDED;
86 break;
87 case LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION:
88 err = WERR_DS_UNAVAILABLE_CRIT_EXTENSION;
89 break;
90 case LDB_ERR_CONFIDENTIALITY_REQUIRED:
91 err = WERR_DS_CONFIDENTIALITY_REQUIRED;
92 break;
93 case LDB_ERR_SASL_BIND_IN_PROGRESS:
94 err = WERR_DS_BUSY;
95 break;
96 case LDB_ERR_NO_SUCH_ATTRIBUTE:
97 err = WERR_DS_NO_ATTRIBUTE_OR_VALUE;
98 break;
99 case LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE:
100 err = WERR_DS_ATTRIBUTE_TYPE_UNDEFINED;
101 break;
102 case LDB_ERR_INAPPROPRIATE_MATCHING:
103 err = WERR_DS_INAPPROPRIATE_MATCHING;
104 break;
105 case LDB_ERR_CONSTRAINT_VIOLATION:
106 err = WERR_DS_CONSTRAINT_VIOLATION;
107 break;
108 case LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS:
109 err = WERR_DS_ATTRIBUTE_OR_VALUE_EXISTS;
110 break;
111 case LDB_ERR_INVALID_ATTRIBUTE_SYNTAX:
112 err = WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
113 break;
114 case LDB_ERR_NO_SUCH_OBJECT:
115 err = WERR_DS_NO_SUCH_OBJECT;
116 break;
117 case LDB_ERR_ALIAS_PROBLEM:
118 err = WERR_DS_ALIAS_PROBLEM;
119 break;
120 case LDB_ERR_INVALID_DN_SYNTAX:
121 err = WERR_DS_INVALID_DN_SYNTAX;
122 break;
123 case LDB_ERR_ALIAS_DEREFERENCING_PROBLEM:
124 err = WERR_DS_ALIAS_DEREF_PROBLEM;
125 break;
126 case LDB_ERR_INAPPROPRIATE_AUTHENTICATION:
127 err = WERR_DS_INAPPROPRIATE_AUTH;
128 break;
129 case LDB_ERR_INVALID_CREDENTIALS:
130 err = WERR_ACCESS_DENIED;
131 break;
132 case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
133 err = WERR_DS_INSUFF_ACCESS_RIGHTS;
134 break;
135 case LDB_ERR_BUSY:
136 err = WERR_DS_BUSY;
137 break;
138 case LDB_ERR_UNAVAILABLE:
139 err = WERR_DS_UNAVAILABLE;
140 break;
141 case LDB_ERR_UNWILLING_TO_PERFORM:
142 err = WERR_DS_UNWILLING_TO_PERFORM;
143 break;
144 case LDB_ERR_LOOP_DETECT:
145 err = WERR_DS_LOOP_DETECT;
146 break;
147 case LDB_ERR_NAMING_VIOLATION:
148 err = WERR_DS_NAMING_VIOLATION;
149 break;
150 case LDB_ERR_OBJECT_CLASS_VIOLATION:
151 err = WERR_DS_OBJ_CLASS_VIOLATION;
152 break;
153 case LDB_ERR_NOT_ALLOWED_ON_NON_LEAF:
154 err = WERR_DS_CANT_ON_NON_LEAF;
155 break;
156 case LDB_ERR_NOT_ALLOWED_ON_RDN:
157 err = WERR_DS_CANT_ON_RDN;
158 break;
159 case LDB_ERR_ENTRY_ALREADY_EXISTS:
160 err = WERR_DS_OBJ_STRING_NAME_EXISTS;
161 break;
162 case LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED:
163 err = WERR_DS_CANT_MOD_OBJ_CLASS;
164 break;
165 case LDB_ERR_AFFECTS_MULTIPLE_DSAS:
166 err = WERR_DS_AFFECTS_MULTIPLE_DSAS;
167 break;
168 default:
169 err = WERR_DS_GENERIC_ERROR;
170 break;
173 *errstring = talloc_asprintf(mem_ctx, "%08X: %s", W_ERROR_V(err),
174 add_err_string != NULL ? add_err_string : ldb_strerror(ldb_err));
176 /* result is 1:1 for now */
177 return ldb_err;
181 connect to the sam database
183 int ldapsrv_backend_Init(struct ldapsrv_connection *conn,
184 char **errstring)
186 int ret = samdb_connect_url(conn,
187 conn->connection->event.ctx,
188 conn->lp_ctx,
189 conn->session_info,
190 conn->global_catalog ? LDB_FLG_RDONLY : 0,
191 "sam.ldb", &conn->ldb, errstring);
192 if (ret != LDB_SUCCESS) {
193 return ret;
196 if (conn->server_credentials) {
197 char **sasl_mechs = NULL;
198 const struct gensec_security_ops * const *backends = gensec_security_all();
199 const struct gensec_security_ops **ops
200 = gensec_use_kerberos_mechs(conn, backends, conn->server_credentials);
201 unsigned int i, j = 0;
202 for (i = 0; ops && ops[i]; i++) {
203 if (!lpcfg_parm_bool(conn->lp_ctx, NULL, "gensec", ops[i]->name, ops[i]->enabled))
204 continue;
206 if (ops[i]->sasl_name && ops[i]->server_start) {
207 char *sasl_name = talloc_strdup(conn, ops[i]->sasl_name);
209 if (!sasl_name) {
210 return LDB_ERR_OPERATIONS_ERROR;
212 sasl_mechs = talloc_realloc(conn, sasl_mechs, char *, j + 2);
213 if (!sasl_mechs) {
214 return LDB_ERR_OPERATIONS_ERROR;
216 sasl_mechs[j] = sasl_name;
217 talloc_steal(sasl_mechs, sasl_name);
218 sasl_mechs[j+1] = NULL;
219 j++;
222 talloc_unlink(conn, ops);
224 /* ldb can have a different lifetime to conn, so we
225 need to ensure that sasl_mechs lives as long as the
226 ldb does */
227 talloc_steal(conn->ldb, sasl_mechs);
229 ldb_set_opaque(conn->ldb, "supportedSASLMechanisms", sasl_mechs);
232 ldb_set_opaque(conn->ldb, "remoteAddress",
233 conn->connection->remote_address);
235 return LDB_SUCCESS;
238 struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type)
240 struct ldapsrv_reply *reply;
242 reply = talloc_zero(call, struct ldapsrv_reply);
243 if (!reply) {
244 return NULL;
246 reply->msg = talloc_zero(reply, struct ldap_message);
247 if (reply->msg == NULL) {
248 talloc_free(reply);
249 return NULL;
252 reply->msg->messageid = call->request->messageid;
253 reply->msg->type = type;
254 reply->msg->controls = NULL;
256 return reply;
259 void ldapsrv_queue_reply(struct ldapsrv_call *call, struct ldapsrv_reply *reply)
261 DLIST_ADD_END(call->replies, reply);
264 static NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
266 struct ldapsrv_reply *reply;
267 struct ldap_ExtendedResponse *r;
269 DEBUG(10,("Unwilling type[%d] id[%d]\n", call->request->type, call->request->messageid));
271 reply = ldapsrv_init_reply(call, LDAP_TAG_ExtendedResponse);
272 if (!reply) {
273 return NT_STATUS_NO_MEMORY;
276 r = &reply->msg->r.ExtendedResponse;
277 r->response.resultcode = error;
278 r->response.dn = NULL;
279 r->response.errormessage = NULL;
280 r->response.referral = NULL;
281 r->oid = NULL;
282 r->value = NULL;
284 ldapsrv_queue_reply(call, reply);
285 return NT_STATUS_OK;
288 static int ldapsrv_add_with_controls(struct ldapsrv_call *call,
289 const struct ldb_message *message,
290 struct ldb_control **controls,
291 struct ldb_result *res)
293 struct ldb_context *ldb = call->conn->ldb;
294 struct ldb_request *req;
295 int ret;
297 ret = ldb_msg_sanity_check(ldb, message);
298 if (ret != LDB_SUCCESS) {
299 return ret;
302 ret = ldb_build_add_req(&req, ldb, ldb,
303 message,
304 controls,
305 res,
306 ldb_modify_default_callback,
307 NULL);
309 if (ret != LDB_SUCCESS) return ret;
311 if (call->conn->global_catalog) {
312 return ldb_error(ldb, LDB_ERR_UNWILLING_TO_PERFORM, "modify forbidden on global catalog port");
314 ldb_request_add_control(req, DSDB_CONTROL_NO_GLOBAL_CATALOG, false, NULL);
316 ret = ldb_transaction_start(ldb);
317 if (ret != LDB_SUCCESS) {
318 return ret;
321 if (!call->conn->is_privileged) {
322 ldb_req_mark_untrusted(req);
325 LDB_REQ_SET_LOCATION(req);
327 ret = ldb_request(ldb, req);
328 if (ret == LDB_SUCCESS) {
329 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
332 if (ret == LDB_SUCCESS) {
333 ret = ldb_transaction_commit(ldb);
335 else {
336 ldb_transaction_cancel(ldb);
339 talloc_free(req);
340 return ret;
343 /* create and execute a modify request */
344 static int ldapsrv_mod_with_controls(struct ldapsrv_call *call,
345 const struct ldb_message *message,
346 struct ldb_control **controls,
347 struct ldb_result *res)
349 struct ldb_context *ldb = call->conn->ldb;
350 struct ldb_request *req;
351 int ret;
353 ret = ldb_msg_sanity_check(ldb, message);
354 if (ret != LDB_SUCCESS) {
355 return ret;
358 ret = ldb_build_mod_req(&req, ldb, ldb,
359 message,
360 controls,
361 res,
362 ldb_modify_default_callback,
363 NULL);
365 if (ret != LDB_SUCCESS) {
366 return ret;
369 if (call->conn->global_catalog) {
370 return ldb_error(ldb, LDB_ERR_UNWILLING_TO_PERFORM, "modify forbidden on global catalog port");
372 ldb_request_add_control(req, DSDB_CONTROL_NO_GLOBAL_CATALOG, false, NULL);
374 ret = ldb_transaction_start(ldb);
375 if (ret != LDB_SUCCESS) {
376 return ret;
379 if (!call->conn->is_privileged) {
380 ldb_req_mark_untrusted(req);
383 LDB_REQ_SET_LOCATION(req);
385 ret = ldb_request(ldb, req);
386 if (ret == LDB_SUCCESS) {
387 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
390 if (ret == LDB_SUCCESS) {
391 ret = ldb_transaction_commit(ldb);
393 else {
394 ldb_transaction_cancel(ldb);
397 talloc_free(req);
398 return ret;
401 /* create and execute a delete request */
402 static int ldapsrv_del_with_controls(struct ldapsrv_call *call,
403 struct ldb_dn *dn,
404 struct ldb_control **controls,
405 struct ldb_result *res)
407 struct ldb_context *ldb = call->conn->ldb;
408 struct ldb_request *req;
409 int ret;
411 ret = ldb_build_del_req(&req, ldb, ldb,
413 controls,
414 res,
415 ldb_modify_default_callback,
416 NULL);
418 if (ret != LDB_SUCCESS) return ret;
420 if (call->conn->global_catalog) {
421 return ldb_error(ldb, LDB_ERR_UNWILLING_TO_PERFORM, "modify forbidden on global catalog port");
423 ldb_request_add_control(req, DSDB_CONTROL_NO_GLOBAL_CATALOG, false, NULL);
425 ret = ldb_transaction_start(ldb);
426 if (ret != LDB_SUCCESS) {
427 return ret;
430 if (!call->conn->is_privileged) {
431 ldb_req_mark_untrusted(req);
434 LDB_REQ_SET_LOCATION(req);
436 ret = ldb_request(ldb, req);
437 if (ret == LDB_SUCCESS) {
438 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
441 if (ret == LDB_SUCCESS) {
442 ret = ldb_transaction_commit(ldb);
444 else {
445 ldb_transaction_cancel(ldb);
448 talloc_free(req);
449 return ret;
452 static int ldapsrv_rename_with_controls(struct ldapsrv_call *call,
453 struct ldb_dn *olddn,
454 struct ldb_dn *newdn,
455 struct ldb_control **controls,
456 struct ldb_result *res)
458 struct ldb_context *ldb = call->conn->ldb;
459 struct ldb_request *req;
460 int ret;
462 ret = ldb_build_rename_req(&req, ldb, ldb,
463 olddn,
464 newdn,
465 controls,
466 res,
467 ldb_modify_default_callback,
468 NULL);
470 if (ret != LDB_SUCCESS) return ret;
472 if (call->conn->global_catalog) {
473 return ldb_error(ldb, LDB_ERR_UNWILLING_TO_PERFORM, "modify forbidden on global catalog port");
475 ldb_request_add_control(req, DSDB_CONTROL_NO_GLOBAL_CATALOG, false, NULL);
477 ret = ldb_transaction_start(ldb);
478 if (ret != LDB_SUCCESS) {
479 return ret;
482 if (!call->conn->is_privileged) {
483 ldb_req_mark_untrusted(req);
486 LDB_REQ_SET_LOCATION(req);
488 ret = ldb_request(ldb, req);
489 if (ret == LDB_SUCCESS) {
490 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
493 if (ret == LDB_SUCCESS) {
494 ret = ldb_transaction_commit(ldb);
496 else {
497 ldb_transaction_cancel(ldb);
500 talloc_free(req);
501 return ret;
504 static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
506 struct ldap_SearchRequest *req = &call->request->r.SearchRequest;
507 struct ldap_SearchResEntry *ent;
508 struct ldap_Result *done;
509 struct ldapsrv_reply *ent_r, *done_r;
510 TALLOC_CTX *local_ctx;
511 struct ldb_context *samdb = talloc_get_type(call->conn->ldb, struct ldb_context);
512 struct ldb_dn *basedn;
513 struct ldb_result *res = NULL;
514 struct ldb_request *lreq;
515 struct ldb_control *search_control;
516 struct ldb_search_options_control *search_options;
517 struct ldb_control *extended_dn_control;
518 struct ldb_extended_dn_control *extended_dn_decoded = NULL;
519 struct ldb_control *notification_control = NULL;
520 enum ldb_scope scope = LDB_SCOPE_DEFAULT;
521 const char **attrs = NULL;
522 const char *scope_str, *errstr = NULL;
523 int success_limit = 1;
524 int result = -1;
525 int ldb_ret = -1;
526 unsigned int i, j;
527 int extended_type = 1;
529 DEBUG(10, ("SearchRequest"));
530 DEBUGADD(10, (" basedn: %s", req->basedn));
531 DEBUGADD(10, (" filter: %s\n", ldb_filter_from_tree(call, req->tree)));
533 local_ctx = talloc_new(call);
534 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
536 basedn = ldb_dn_new(local_ctx, samdb, req->basedn);
537 NT_STATUS_HAVE_NO_MEMORY(basedn);
539 DEBUG(10, ("SearchRequest: basedn: [%s]\n", req->basedn));
540 DEBUG(10, ("SearchRequest: filter: [%s]\n", ldb_filter_from_tree(call, req->tree)));
542 switch (req->scope) {
543 case LDAP_SEARCH_SCOPE_BASE:
544 scope_str = "BASE";
545 scope = LDB_SCOPE_BASE;
546 success_limit = 0;
547 break;
548 case LDAP_SEARCH_SCOPE_SINGLE:
549 scope_str = "ONE";
550 scope = LDB_SCOPE_ONELEVEL;
551 success_limit = 0;
552 break;
553 case LDAP_SEARCH_SCOPE_SUB:
554 scope_str = "SUB";
555 scope = LDB_SCOPE_SUBTREE;
556 success_limit = 0;
557 break;
558 default:
559 result = LDAP_PROTOCOL_ERROR;
560 map_ldb_error(local_ctx, LDB_ERR_PROTOCOL_ERROR, NULL,
561 &errstr);
562 errstr = talloc_asprintf(local_ctx,
563 "%s. Invalid scope", errstr);
564 goto reply;
566 DEBUG(10,("SearchRequest: scope: [%s]\n", scope_str));
568 if (req->num_attributes >= 1) {
569 attrs = talloc_array(local_ctx, const char *, req->num_attributes+1);
570 NT_STATUS_HAVE_NO_MEMORY(attrs);
572 for (i=0; i < req->num_attributes; i++) {
573 DEBUG(10,("SearchRequest: attrs: [%s]\n",req->attributes[i]));
574 attrs[i] = req->attributes[i];
576 attrs[i] = NULL;
579 DEBUG(5,("ldb_request %s dn=%s filter=%s\n",
580 scope_str, req->basedn, ldb_filter_from_tree(call, req->tree)));
582 res = talloc_zero(local_ctx, struct ldb_result);
583 NT_STATUS_HAVE_NO_MEMORY(res);
585 ldb_ret = ldb_build_search_req_ex(&lreq, samdb, local_ctx,
586 basedn, scope,
587 req->tree, attrs,
588 call->request->controls,
589 res, ldb_search_default_callback,
590 NULL);
592 if (ldb_ret != LDB_SUCCESS) {
593 goto reply;
596 if (call->conn->global_catalog) {
597 search_control = ldb_request_get_control(lreq, LDB_CONTROL_SEARCH_OPTIONS_OID);
599 search_options = NULL;
600 if (search_control) {
601 search_options = talloc_get_type(search_control->data, struct ldb_search_options_control);
602 search_options->search_options |= LDB_SEARCH_OPTION_PHANTOM_ROOT;
603 } else {
604 search_options = talloc(lreq, struct ldb_search_options_control);
605 NT_STATUS_HAVE_NO_MEMORY(search_options);
606 search_options->search_options = LDB_SEARCH_OPTION_PHANTOM_ROOT;
607 ldb_request_add_control(lreq, LDB_CONTROL_SEARCH_OPTIONS_OID, false, search_options);
609 } else {
610 ldb_request_add_control(lreq, DSDB_CONTROL_NO_GLOBAL_CATALOG, false, NULL);
613 extended_dn_control = ldb_request_get_control(lreq, LDB_CONTROL_EXTENDED_DN_OID);
615 if (extended_dn_control) {
616 if (extended_dn_control->data) {
617 extended_dn_decoded = talloc_get_type(extended_dn_control->data, struct ldb_extended_dn_control);
618 extended_type = extended_dn_decoded->type;
619 } else {
620 extended_type = 0;
624 notification_control = ldb_request_get_control(lreq, LDB_CONTROL_NOTIFICATION_OID);
625 if (notification_control != NULL) {
626 const struct ldapsrv_call *pc = NULL;
627 size_t count = 0;
629 for (pc = call->conn->pending_calls; pc != NULL; pc = pc->next) {
630 count += 1;
633 if (count >= call->conn->limits.max_notifications) {
634 DEBUG(10,("SearchRequest: error MaxNotificationPerConn\n"));
635 result = map_ldb_error(local_ctx,
636 LDB_ERR_ADMIN_LIMIT_EXCEEDED,
637 "MaxNotificationPerConn reached",
638 &errstr);
639 goto reply;
643 * For now we need to do periodic retries on our own.
644 * As the dsdb_notification module will return after each run.
646 call->notification.busy = true;
649 ldb_set_timeout(samdb, lreq, req->timelimit);
651 if (!call->conn->is_privileged) {
652 ldb_req_mark_untrusted(lreq);
655 LDB_REQ_SET_LOCATION(lreq);
657 ldb_ret = ldb_request(samdb, lreq);
659 if (ldb_ret != LDB_SUCCESS) {
660 goto reply;
663 ldb_ret = ldb_wait(lreq->handle, LDB_WAIT_ALL);
665 if (ldb_ret == LDB_SUCCESS) {
666 for (i = 0; i < res->count; i++) {
667 ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
668 NT_STATUS_HAVE_NO_MEMORY(ent_r);
670 /* Better to have the whole message kept here,
671 * than to find someone further up didn't put
672 * a value in the right spot in the talloc tree */
673 talloc_steal(ent_r, res->msgs[i]);
675 ent = &ent_r->msg->r.SearchResultEntry;
676 ent->dn = ldb_dn_get_extended_linearized(ent_r, res->msgs[i]->dn, extended_type);
677 ent->num_attributes = 0;
678 ent->attributes = NULL;
679 if (res->msgs[i]->num_elements == 0) {
680 goto queue_reply;
682 ent->num_attributes = res->msgs[i]->num_elements;
683 ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
684 NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
685 for (j=0; j < ent->num_attributes; j++) {
686 ent->attributes[j].name = res->msgs[i]->elements[j].name;
687 ent->attributes[j].num_values = 0;
688 ent->attributes[j].values = NULL;
689 if (req->attributesonly && (res->msgs[i]->elements[j].num_values == 0)) {
690 continue;
692 ent->attributes[j].num_values = res->msgs[i]->elements[j].num_values;
693 ent->attributes[j].values = res->msgs[i]->elements[j].values;
695 queue_reply:
696 ldapsrv_queue_reply(call, ent_r);
699 if (call->notification.busy) {
700 /* Move/Add it to the end */
701 DLIST_DEMOTE(call->conn->pending_calls, call);
702 call->notification.generation =
703 call->conn->service->notification.generation;
705 if (res->count != 0) {
706 call->notification.generation += 1;
707 ldapsrv_notification_retry_setup(call->conn->service,
708 true);
711 talloc_free(local_ctx);
712 return NT_STATUS_OK;
715 /* Send back referrals if they do exist (search operations) */
716 if (res->refs != NULL) {
717 char **ref;
718 struct ldap_SearchResRef *ent_ref;
720 for (ref = res->refs; *ref != NULL; ++ref) {
721 ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultReference);
722 NT_STATUS_HAVE_NO_MEMORY(ent_r);
724 /* Better to have the whole referrals kept here,
725 * than to find someone further up didn't put
726 * a value in the right spot in the talloc tree
728 talloc_steal(ent_r, *ref);
730 ent_ref = &ent_r->msg->r.SearchResultReference;
731 ent_ref->referral = *ref;
733 ldapsrv_queue_reply(call, ent_r);
738 reply:
739 DLIST_REMOVE(call->conn->pending_calls, call);
740 call->notification.busy = false;
742 done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
743 NT_STATUS_HAVE_NO_MEMORY(done_r);
745 done = &done_r->msg->r.SearchResultDone;
746 done->dn = NULL;
747 done->referral = NULL;
749 if (result != -1) {
750 } else if (ldb_ret == LDB_SUCCESS) {
751 if (res->count >= success_limit) {
752 DEBUG(10,("SearchRequest: results: [%d]\n", res->count));
753 result = LDAP_SUCCESS;
754 errstr = NULL;
756 if (res->controls) {
757 done_r->msg->controls = res->controls;
758 talloc_steal(done_r, res->controls);
760 } else {
761 DEBUG(10,("SearchRequest: error\n"));
762 result = map_ldb_error(local_ctx, ldb_ret, ldb_errstring(samdb),
763 &errstr);
766 done->resultcode = result;
767 done->errormessage = (errstr?talloc_strdup(done_r, errstr):NULL);
769 talloc_free(local_ctx);
771 ldapsrv_queue_reply(call, done_r);
772 return NT_STATUS_OK;
775 static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
777 struct ldap_ModifyRequest *req = &call->request->r.ModifyRequest;
778 struct ldap_Result *modify_result;
779 struct ldapsrv_reply *modify_reply;
780 TALLOC_CTX *local_ctx;
781 struct ldb_context *samdb = call->conn->ldb;
782 struct ldb_message *msg = NULL;
783 struct ldb_dn *dn;
784 const char *errstr = NULL;
785 int result = LDAP_SUCCESS;
786 int ldb_ret;
787 unsigned int i,j;
788 struct ldb_result *res = NULL;
790 DEBUG(10, ("ModifyRequest"));
791 DEBUGADD(10, (" dn: %s\n", req->dn));
793 local_ctx = talloc_named(call, 0, "ModifyRequest local memory context");
794 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
796 dn = ldb_dn_new(local_ctx, samdb, req->dn);
797 NT_STATUS_HAVE_NO_MEMORY(dn);
799 DEBUG(10, ("ModifyRequest: dn: [%s]\n", req->dn));
801 msg = talloc(local_ctx, struct ldb_message);
802 NT_STATUS_HAVE_NO_MEMORY(msg);
804 msg->dn = dn;
805 msg->num_elements = 0;
806 msg->elements = NULL;
808 if (req->num_mods > 0) {
809 msg->num_elements = req->num_mods;
810 msg->elements = talloc_array(msg, struct ldb_message_element, req->num_mods);
811 NT_STATUS_HAVE_NO_MEMORY(msg->elements);
813 for (i=0; i < msg->num_elements; i++) {
814 msg->elements[i].name = discard_const_p(char, req->mods[i].attrib.name);
815 msg->elements[i].num_values = 0;
816 msg->elements[i].values = NULL;
818 switch (req->mods[i].type) {
819 default:
820 result = LDAP_PROTOCOL_ERROR;
821 map_ldb_error(local_ctx,
822 LDB_ERR_PROTOCOL_ERROR, NULL, &errstr);
823 errstr = talloc_asprintf(local_ctx,
824 "%s. Invalid LDAP_MODIFY_* type", errstr);
825 goto reply;
826 case LDAP_MODIFY_ADD:
827 msg->elements[i].flags = LDB_FLAG_MOD_ADD;
828 break;
829 case LDAP_MODIFY_DELETE:
830 msg->elements[i].flags = LDB_FLAG_MOD_DELETE;
831 break;
832 case LDAP_MODIFY_REPLACE:
833 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
834 break;
837 msg->elements[i].num_values = req->mods[i].attrib.num_values;
838 if (msg->elements[i].num_values > 0) {
839 msg->elements[i].values = talloc_array(msg->elements, struct ldb_val,
840 msg->elements[i].num_values);
841 NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);
843 for (j=0; j < msg->elements[i].num_values; j++) {
844 msg->elements[i].values[j].length = req->mods[i].attrib.values[j].length;
845 msg->elements[i].values[j].data = req->mods[i].attrib.values[j].data;
851 reply:
852 modify_reply = ldapsrv_init_reply(call, LDAP_TAG_ModifyResponse);
853 NT_STATUS_HAVE_NO_MEMORY(modify_reply);
855 if (result == LDAP_SUCCESS) {
856 res = talloc_zero(local_ctx, struct ldb_result);
857 NT_STATUS_HAVE_NO_MEMORY(res);
858 ldb_ret = ldapsrv_mod_with_controls(call, msg, call->request->controls, res);
859 result = map_ldb_error(local_ctx, ldb_ret, ldb_errstring(samdb),
860 &errstr);
863 modify_result = &modify_reply->msg->r.ModifyResponse;
864 modify_result->dn = NULL;
865 if ((res != NULL) && (res->refs != NULL)) {
866 modify_result->resultcode = map_ldb_error(local_ctx,
867 LDB_ERR_REFERRAL,
868 NULL, &errstr);
869 modify_result->errormessage = (errstr?talloc_strdup(modify_reply, errstr):NULL);
870 modify_result->referral = talloc_strdup(call, *res->refs);
871 } else {
872 modify_result->resultcode = result;
873 modify_result->errormessage = (errstr?talloc_strdup(modify_reply, errstr):NULL);
874 modify_result->referral = NULL;
876 talloc_free(local_ctx);
878 ldapsrv_queue_reply(call, modify_reply);
879 return NT_STATUS_OK;
883 static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
885 struct ldap_AddRequest *req = &call->request->r.AddRequest;
886 struct ldap_Result *add_result;
887 struct ldapsrv_reply *add_reply;
888 TALLOC_CTX *local_ctx;
889 struct ldb_context *samdb = call->conn->ldb;
890 struct ldb_message *msg = NULL;
891 struct ldb_dn *dn;
892 const char *errstr = NULL;
893 int result = LDAP_SUCCESS;
894 int ldb_ret;
895 unsigned int i,j;
896 struct ldb_result *res = NULL;
898 DEBUG(10, ("AddRequest"));
899 DEBUGADD(10, (" dn: %s\n", req->dn));
901 local_ctx = talloc_named(call, 0, "AddRequest local memory context");
902 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
904 dn = ldb_dn_new(local_ctx, samdb, req->dn);
905 NT_STATUS_HAVE_NO_MEMORY(dn);
907 DEBUG(10, ("AddRequest: dn: [%s]\n", req->dn));
909 msg = talloc(local_ctx, struct ldb_message);
910 NT_STATUS_HAVE_NO_MEMORY(msg);
912 msg->dn = dn;
913 msg->num_elements = 0;
914 msg->elements = NULL;
916 if (req->num_attributes > 0) {
917 msg->num_elements = req->num_attributes;
918 msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements);
919 NT_STATUS_HAVE_NO_MEMORY(msg->elements);
921 for (i=0; i < msg->num_elements; i++) {
922 msg->elements[i].name = discard_const_p(char, req->attributes[i].name);
923 msg->elements[i].flags = 0;
924 msg->elements[i].num_values = 0;
925 msg->elements[i].values = NULL;
927 if (req->attributes[i].num_values > 0) {
928 msg->elements[i].num_values = req->attributes[i].num_values;
929 msg->elements[i].values = talloc_array(msg->elements, struct ldb_val,
930 msg->elements[i].num_values);
931 NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);
933 for (j=0; j < msg->elements[i].num_values; j++) {
934 msg->elements[i].values[j].length = req->attributes[i].values[j].length;
935 msg->elements[i].values[j].data = req->attributes[i].values[j].data;
941 add_reply = ldapsrv_init_reply(call, LDAP_TAG_AddResponse);
942 NT_STATUS_HAVE_NO_MEMORY(add_reply);
944 if (result == LDAP_SUCCESS) {
945 res = talloc_zero(local_ctx, struct ldb_result);
946 NT_STATUS_HAVE_NO_MEMORY(res);
947 ldb_ret = ldapsrv_add_with_controls(call, msg, call->request->controls, res);
948 result = map_ldb_error(local_ctx, ldb_ret, ldb_errstring(samdb),
949 &errstr);
952 add_result = &add_reply->msg->r.AddResponse;
953 add_result->dn = NULL;
954 if ((res != NULL) && (res->refs != NULL)) {
955 add_result->resultcode = map_ldb_error(local_ctx,
956 LDB_ERR_REFERRAL, NULL,
957 &errstr);
958 add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);
959 add_result->referral = talloc_strdup(call, *res->refs);
960 } else {
961 add_result->resultcode = result;
962 add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);
963 add_result->referral = NULL;
965 talloc_free(local_ctx);
967 ldapsrv_queue_reply(call, add_reply);
968 return NT_STATUS_OK;
972 static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
974 struct ldap_DelRequest *req = &call->request->r.DelRequest;
975 struct ldap_Result *del_result;
976 struct ldapsrv_reply *del_reply;
977 TALLOC_CTX *local_ctx;
978 struct ldb_context *samdb = call->conn->ldb;
979 struct ldb_dn *dn;
980 const char *errstr = NULL;
981 int result = LDAP_SUCCESS;
982 int ldb_ret;
983 struct ldb_result *res = NULL;
985 DEBUG(10, ("DelRequest"));
986 DEBUGADD(10, (" dn: %s\n", req->dn));
988 local_ctx = talloc_named(call, 0, "DelRequest local memory context");
989 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
991 dn = ldb_dn_new(local_ctx, samdb, req->dn);
992 NT_STATUS_HAVE_NO_MEMORY(dn);
994 DEBUG(10, ("DelRequest: dn: [%s]\n", req->dn));
996 del_reply = ldapsrv_init_reply(call, LDAP_TAG_DelResponse);
997 NT_STATUS_HAVE_NO_MEMORY(del_reply);
999 if (result == LDAP_SUCCESS) {
1000 res = talloc_zero(local_ctx, struct ldb_result);
1001 NT_STATUS_HAVE_NO_MEMORY(res);
1002 ldb_ret = ldapsrv_del_with_controls(call, dn, call->request->controls, res);
1003 result = map_ldb_error(local_ctx, ldb_ret, ldb_errstring(samdb),
1004 &errstr);
1007 del_result = &del_reply->msg->r.DelResponse;
1008 del_result->dn = NULL;
1009 if ((res != NULL) && (res->refs != NULL)) {
1010 del_result->resultcode = map_ldb_error(local_ctx,
1011 LDB_ERR_REFERRAL, NULL,
1012 &errstr);
1013 del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);
1014 del_result->referral = talloc_strdup(call, *res->refs);
1015 } else {
1016 del_result->resultcode = result;
1017 del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);
1018 del_result->referral = NULL;
1021 talloc_free(local_ctx);
1023 ldapsrv_queue_reply(call, del_reply);
1024 return NT_STATUS_OK;
1027 static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
1029 struct ldap_ModifyDNRequest *req = &call->request->r.ModifyDNRequest;
1030 struct ldap_Result *modifydn;
1031 struct ldapsrv_reply *modifydn_r;
1032 TALLOC_CTX *local_ctx;
1033 struct ldb_context *samdb = call->conn->ldb;
1034 struct ldb_dn *olddn, *newdn=NULL, *newrdn;
1035 struct ldb_dn *parentdn = NULL;
1036 const char *errstr = NULL;
1037 int result = LDAP_SUCCESS;
1038 int ldb_ret;
1039 struct ldb_result *res = NULL;
1041 DEBUG(10, ("ModifyDNRequest"));
1042 DEBUGADD(10, (" dn: %s", req->dn));
1043 DEBUGADD(10, (" newrdn: %s\n", req->newrdn));
1045 local_ctx = talloc_named(call, 0, "ModifyDNRequest local memory context");
1046 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
1048 olddn = ldb_dn_new(local_ctx, samdb, req->dn);
1049 NT_STATUS_HAVE_NO_MEMORY(olddn);
1051 newrdn = ldb_dn_new(local_ctx, samdb, req->newrdn);
1052 NT_STATUS_HAVE_NO_MEMORY(newrdn);
1054 DEBUG(10, ("ModifyDNRequest: olddn: [%s]\n", req->dn));
1055 DEBUG(10, ("ModifyDNRequest: newrdn: [%s]\n", req->newrdn));
1057 if (ldb_dn_get_comp_num(newrdn) == 0) {
1058 result = LDAP_PROTOCOL_ERROR;
1059 map_ldb_error(local_ctx, LDB_ERR_PROTOCOL_ERROR, NULL,
1060 &errstr);
1061 goto reply;
1064 if (ldb_dn_get_comp_num(newrdn) > 1) {
1065 result = LDAP_NAMING_VIOLATION;
1066 map_ldb_error(local_ctx, LDB_ERR_NAMING_VIOLATION, NULL,
1067 &errstr);
1068 goto reply;
1071 /* we can't handle the rename if we should not remove the old dn */
1072 if (!req->deleteolddn) {
1073 result = LDAP_UNWILLING_TO_PERFORM;
1074 map_ldb_error(local_ctx, LDB_ERR_UNWILLING_TO_PERFORM, NULL,
1075 &errstr);
1076 errstr = talloc_asprintf(local_ctx,
1077 "%s. Old RDN must be deleted", errstr);
1078 goto reply;
1081 if (req->newsuperior) {
1082 DEBUG(10, ("ModifyDNRequest: newsuperior: [%s]\n", req->newsuperior));
1083 parentdn = ldb_dn_new(local_ctx, samdb, req->newsuperior);
1086 if (!parentdn) {
1087 parentdn = ldb_dn_get_parent(local_ctx, olddn);
1089 if (!parentdn) {
1090 result = LDAP_NO_SUCH_OBJECT;
1091 map_ldb_error(local_ctx, LDB_ERR_NO_SUCH_OBJECT, NULL, &errstr);
1092 goto reply;
1095 if ( ! ldb_dn_add_child(parentdn, newrdn)) {
1096 result = LDAP_OTHER;
1097 map_ldb_error(local_ctx, LDB_ERR_OTHER, NULL, &errstr);
1098 goto reply;
1100 newdn = parentdn;
1102 reply:
1103 modifydn_r = ldapsrv_init_reply(call, LDAP_TAG_ModifyDNResponse);
1104 NT_STATUS_HAVE_NO_MEMORY(modifydn_r);
1106 if (result == LDAP_SUCCESS) {
1107 res = talloc_zero(local_ctx, struct ldb_result);
1108 NT_STATUS_HAVE_NO_MEMORY(res);
1109 ldb_ret = ldapsrv_rename_with_controls(call, olddn, newdn, call->request->controls, res);
1110 result = map_ldb_error(local_ctx, ldb_ret, ldb_errstring(samdb),
1111 &errstr);
1114 modifydn = &modifydn_r->msg->r.ModifyDNResponse;
1115 modifydn->dn = NULL;
1116 if ((res != NULL) && (res->refs != NULL)) {
1117 modifydn->resultcode = map_ldb_error(local_ctx,
1118 LDB_ERR_REFERRAL, NULL,
1119 &errstr);;
1120 modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);
1121 modifydn->referral = talloc_strdup(call, *res->refs);
1122 } else {
1123 modifydn->resultcode = result;
1124 modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);
1125 modifydn->referral = NULL;
1128 talloc_free(local_ctx);
1130 ldapsrv_queue_reply(call, modifydn_r);
1131 return NT_STATUS_OK;
1134 static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
1136 struct ldap_CompareRequest *req = &call->request->r.CompareRequest;
1137 struct ldap_Result *compare;
1138 struct ldapsrv_reply *compare_r;
1139 TALLOC_CTX *local_ctx;
1140 struct ldb_context *samdb = call->conn->ldb;
1141 struct ldb_result *res = NULL;
1142 struct ldb_dn *dn;
1143 const char *attrs[1];
1144 const char *errstr = NULL;
1145 const char *filter = NULL;
1146 int result = LDAP_SUCCESS;
1147 int ldb_ret;
1149 DEBUG(10, ("CompareRequest"));
1150 DEBUGADD(10, (" dn: %s\n", req->dn));
1152 local_ctx = talloc_named(call, 0, "CompareRequest local_memory_context");
1153 NT_STATUS_HAVE_NO_MEMORY(local_ctx);
1155 dn = ldb_dn_new(local_ctx, samdb, req->dn);
1156 NT_STATUS_HAVE_NO_MEMORY(dn);
1158 DEBUG(10, ("CompareRequest: dn: [%s]\n", req->dn));
1159 filter = talloc_asprintf(local_ctx, "(%s=%*s)", req->attribute,
1160 (int)req->value.length, req->value.data);
1161 NT_STATUS_HAVE_NO_MEMORY(filter);
1163 DEBUGADD(10, ("CompareRequest: attribute: [%s]\n", filter));
1165 attrs[0] = NULL;
1167 compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse);
1168 NT_STATUS_HAVE_NO_MEMORY(compare_r);
1170 if (result == LDAP_SUCCESS) {
1171 ldb_ret = ldb_search(samdb, local_ctx, &res,
1172 dn, LDB_SCOPE_BASE, attrs, "%s", filter);
1173 if (ldb_ret != LDB_SUCCESS) {
1174 result = map_ldb_error(local_ctx, ldb_ret,
1175 ldb_errstring(samdb), &errstr);
1176 DEBUG(10,("CompareRequest: error: %s\n", errstr));
1177 } else if (res->count == 0) {
1178 DEBUG(10,("CompareRequest: doesn't matched\n"));
1179 result = LDAP_COMPARE_FALSE;
1180 errstr = NULL;
1181 } else if (res->count == 1) {
1182 DEBUG(10,("CompareRequest: matched\n"));
1183 result = LDAP_COMPARE_TRUE;
1184 errstr = NULL;
1185 } else if (res->count > 1) {
1186 result = LDAP_OTHER;
1187 map_ldb_error(local_ctx, LDB_ERR_OTHER, NULL, &errstr);
1188 errstr = talloc_asprintf(local_ctx,
1189 "%s. Too many objects match!", errstr);
1190 DEBUG(10,("CompareRequest: %d results: %s\n", res->count, errstr));
1194 compare = &compare_r->msg->r.CompareResponse;
1195 compare->dn = NULL;
1196 compare->resultcode = result;
1197 compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL);
1198 compare->referral = NULL;
1200 talloc_free(local_ctx);
1202 ldapsrv_queue_reply(call, compare_r);
1203 return NT_STATUS_OK;
1206 static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call)
1208 struct ldap_AbandonRequest *req = &call->request->r.AbandonRequest;
1209 struct ldapsrv_call *c = NULL;
1210 struct ldapsrv_call *n = NULL;
1212 DEBUG(10, ("AbandonRequest\n"));
1214 for (c = call->conn->pending_calls; c != NULL; c = n) {
1215 n = c->next;
1217 if (c->request->messageid != req->messageid) {
1218 continue;
1221 DLIST_REMOVE(call->conn->pending_calls, c);
1222 TALLOC_FREE(c);
1225 return NT_STATUS_OK;
1228 NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call)
1230 unsigned int i;
1231 struct ldap_message *msg = call->request;
1232 NTSTATUS status;
1234 /* Check for undecoded critical extensions */
1235 for (i=0; msg->controls && msg->controls[i]; i++) {
1236 if (!msg->controls_decoded[i] &&
1237 msg->controls[i]->critical) {
1238 DEBUG(3, ("ldapsrv_do_call: Critical extension %s is not known to this server\n",
1239 msg->controls[i]->oid));
1240 return ldapsrv_unwilling(call, LDAP_UNAVAILABLE_CRITICAL_EXTENSION);
1244 if (call->conn->authz_logged == false) {
1245 bool log = true;
1248 * We do not want to log anonymous access if the query
1249 * is just for the rootDSE, or it is a startTLS or a
1250 * Bind.
1252 * A rootDSE search could also be done over
1253 * CLDAP anonymously for example, so these don't
1254 * really count.
1255 * Essentially we want to know about
1256 * access beyond that normally done prior to a
1257 * bind.
1260 switch(call->request->type) {
1261 case LDAP_TAG_BindRequest:
1262 case LDAP_TAG_UnbindRequest:
1263 case LDAP_TAG_AbandonRequest:
1264 log = false;
1265 break;
1266 case LDAP_TAG_ExtendedResponse: {
1267 struct ldap_ExtendedRequest *req = &call->request->r.ExtendedRequest;
1268 if (strcmp(req->oid, LDB_EXTENDED_START_TLS_OID) == 0) {
1269 log = false;
1271 break;
1273 case LDAP_TAG_SearchRequest: {
1274 struct ldap_SearchRequest *req = &call->request->r.SearchRequest;
1275 if (req->scope == LDAP_SEARCH_SCOPE_BASE) {
1276 if (req->basedn[0] == '\0') {
1277 log = false;
1280 break;
1282 default:
1283 break;
1286 if (log) {
1287 const char *transport_protection = AUTHZ_TRANSPORT_PROTECTION_NONE;
1288 if (call->conn->sockets.active == call->conn->sockets.tls) {
1289 transport_protection = AUTHZ_TRANSPORT_PROTECTION_TLS;
1292 log_successful_authz_event(call->conn->connection->msg_ctx,
1293 call->conn->connection->lp_ctx,
1294 call->conn->connection->remote_address,
1295 call->conn->connection->local_address,
1296 "LDAP",
1297 "no bind",
1298 transport_protection,
1299 call->conn->session_info);
1301 call->conn->authz_logged = true;
1305 switch(call->request->type) {
1306 case LDAP_TAG_BindRequest:
1307 return ldapsrv_BindRequest(call);
1308 case LDAP_TAG_UnbindRequest:
1309 return ldapsrv_UnbindRequest(call);
1310 case LDAP_TAG_SearchRequest:
1311 return ldapsrv_SearchRequest(call);
1312 case LDAP_TAG_ModifyRequest:
1313 status = ldapsrv_ModifyRequest(call);
1314 break;
1315 case LDAP_TAG_AddRequest:
1316 status = ldapsrv_AddRequest(call);
1317 break;
1318 case LDAP_TAG_DelRequest:
1319 status = ldapsrv_DelRequest(call);
1320 break;
1321 case LDAP_TAG_ModifyDNRequest:
1322 status = ldapsrv_ModifyDNRequest(call);
1323 break;
1324 case LDAP_TAG_CompareRequest:
1325 return ldapsrv_CompareRequest(call);
1326 case LDAP_TAG_AbandonRequest:
1327 return ldapsrv_AbandonRequest(call);
1328 case LDAP_TAG_ExtendedRequest:
1329 status = ldapsrv_ExtendedRequest(call);
1330 break;
1331 default:
1332 return ldapsrv_unwilling(call, LDAP_PROTOCOL_ERROR);
1335 if (NT_STATUS_IS_OK(status)) {
1336 ldapsrv_notification_retry_setup(call->conn->service, true);
1339 return status;