2 Unix SMB/CIFS implementation.
3 Infrastructure for async ldap client requests
4 Copyright (C) Volker Lendecke 2009
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 3 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, see <http://www.gnu.org/licenses/>.
22 bool tevent_req_is_ldap_error(struct tevent_req *req, int *perr)
24 enum tevent_req_state state;
27 if (!tevent_req_is_error(req, &state, &err)) {
31 case TEVENT_REQ_TIMED_OUT:
32 *perr = TLDAP_TIMEOUT;
34 case TEVENT_REQ_NO_MEMORY:
35 *perr = TLDAP_NO_MEMORY;
37 case TEVENT_REQ_USER_ERROR:
41 *perr = TLDAP_OPERATIONS_ERROR;
47 struct tldap_ctx_attribute {
52 struct tldap_context {
59 struct tevent_queue *outgoing;
60 struct tevent_req **pending;
62 /* For the sync wrappers we need something like get_last_error... */
65 char *res_diagnosticmessage;
67 struct tldap_control *res_sctrls;
70 void (*log_fn)(void *context, enum tldap_debug_level level,
71 const char *fmt, va_list ap);
74 struct tldap_ctx_attribute *ctx_attrs;
77 struct tldap_message {
78 struct asn1_data *data;
85 struct tldap_attribute *attribs;
88 void tldap_set_debug(struct tldap_context *ld,
89 void (*log_fn)(void *log_private,
90 enum tldap_debug_level level,
92 va_list ap) PRINTF_ATTRIBUTE(3,0),
96 ld->log_private = log_private;
99 static void tldap_debug(struct tldap_context *ld,
100 enum tldap_debug_level level,
101 const char *fmt, ...)
107 if (ld->log_fn == NULL) {
111 ld->log_fn(ld->log_private, level, fmt, ap);
115 static int tldap_next_msgid(struct tldap_context *ld)
119 result = ld->msgid++;
120 if (ld->msgid == 2147483647) {
126 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd)
128 struct tldap_context *ctx;
130 ctx = talloc_zero(mem_ctx, struct tldap_context);
137 ctx->outgoing = tevent_queue_create(ctx, "tldap_outgoing");
138 if (ctx->outgoing == NULL) {
145 static struct tldap_ctx_attribute *tldap_context_findattr(
146 struct tldap_context *ld, const char *name)
150 num_attrs = talloc_array_length(ld->ctx_attrs);
152 for (i=0; i<num_attrs; i++) {
153 if (strcmp(ld->ctx_attrs[i].name, name) == 0) {
154 return &ld->ctx_attrs[i];
160 bool tldap_context_setattr(struct tldap_context *ld,
161 const char *name, const void *_pptr)
163 struct tldap_ctx_attribute *tmp, *attr;
166 void **pptr = (void **)_pptr;
168 attr = tldap_context_findattr(ld, name);
171 * We don't actually delete attrs, we don't expect tons of
172 * attributes being shuffled around.
174 TALLOC_FREE(attr->ptr);
176 attr->ptr = talloc_move(ld->ctx_attrs, pptr);
182 tmpname = talloc_strdup(ld, name);
183 if (tmpname == NULL) {
187 num_attrs = talloc_array_length(ld->ctx_attrs);
189 tmp = talloc_realloc(ld, ld->ctx_attrs, struct tldap_ctx_attribute,
192 TALLOC_FREE(tmpname);
195 tmp[num_attrs].name = talloc_move(tmp, &tmpname);
197 tmp[num_attrs].ptr = talloc_move(tmp, pptr);
199 tmp[num_attrs].ptr = NULL;
206 void *tldap_context_getattr(struct tldap_context *ld, const char *name)
208 struct tldap_ctx_attribute *attr = tldap_context_findattr(ld, name);
216 struct read_ldap_state {
221 static ssize_t read_ldap_more(uint8_t *buf, size_t buflen, void *private_data)
223 struct read_ldap_state *state = talloc_get_type_abort(
224 private_data, struct read_ldap_state);
229 /* We've been here, we're done */
234 * From ldap.h: LDAP_TAG_MESSAGE is 0x30
236 if (buf[0] != 0x30) {
241 if ((len & 0x80) == 0) {
246 lensize = (len & 0x7f);
250 /* Please get us the full length */
253 if (buflen > 2 + lensize) {
257 if (buflen != 2 + lensize) {
261 for (i=0; i<lensize; i++) {
262 len = (len << 8) | buf[2+i];
267 static void read_ldap_done(struct tevent_req *subreq);
269 static struct tevent_req *read_ldap_send(TALLOC_CTX *mem_ctx,
270 struct tevent_context *ev,
273 struct tevent_req *req, *subreq;
274 struct read_ldap_state *state;
276 req = tevent_req_create(mem_ctx, &state, struct read_ldap_state);
282 subreq = read_packet_send(state, ev, fd, 2, read_ldap_more, state);
283 if (tevent_req_nomem(subreq, req)) {
284 return tevent_req_post(req, ev);
286 tevent_req_set_callback(subreq, read_ldap_done, req);
290 static void read_ldap_done(struct tevent_req *subreq)
292 struct tevent_req *req = tevent_req_callback_data(
293 subreq, struct tevent_req);
294 struct read_ldap_state *state = tevent_req_data(
295 req, struct read_ldap_state);
299 nread = read_packet_recv(subreq, state, &state->buf, &err);
302 tevent_req_error(req, err);
305 tevent_req_done(req);
308 static ssize_t read_ldap_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
309 uint8_t **pbuf, int *perrno)
311 struct read_ldap_state *state = tevent_req_data(
312 req, struct read_ldap_state);
314 if (tevent_req_is_unix_error(req, perrno)) {
317 *pbuf = talloc_move(mem_ctx, &state->buf);
318 return talloc_get_size(*pbuf);
321 struct tldap_msg_state {
322 struct tldap_context *ld;
323 struct tevent_context *ev;
327 struct asn1_data *data;
331 static void tldap_push_controls(struct asn1_data *data,
332 struct tldap_control *sctrls,
337 if ((sctrls == NULL) || (num_sctrls == 0)) {
341 asn1_push_tag(data, ASN1_CONTEXT(0));
343 for (i=0; i<num_sctrls; i++) {
344 struct tldap_control *c = &sctrls[i];
345 asn1_push_tag(data, ASN1_SEQUENCE(0));
346 asn1_write_OctetString(data, c->oid, strlen(c->oid));
348 asn1_write_BOOLEAN(data, true);
350 if (c->value.data != NULL) {
351 asn1_write_OctetString(data, c->value.data,
354 asn1_pop_tag(data); /* ASN1_SEQUENCE(0) */
357 asn1_pop_tag(data); /* ASN1_CONTEXT(0) */
360 static void tldap_msg_sent(struct tevent_req *subreq);
361 static void tldap_msg_received(struct tevent_req *subreq);
363 static struct tevent_req *tldap_msg_send(TALLOC_CTX *mem_ctx,
364 struct tevent_context *ev,
365 struct tldap_context *ld,
366 int id, struct asn1_data *data,
367 struct tldap_control *sctrls,
370 struct tevent_req *req, *subreq;
371 struct tldap_msg_state *state;
374 tldap_debug(ld, TLDAP_DEBUG_TRACE, "tldap_msg_send: sending msg %d\n",
377 req = tevent_req_create(mem_ctx, &state, struct tldap_msg_state);
385 tldap_push_controls(data, sctrls, num_sctrls);
389 if (!asn1_blob(data, &blob)) {
390 tevent_req_error(req, TLDAP_ENCODING_ERROR);
391 return tevent_req_post(req, ev);
394 state->iov.iov_base = blob.data;
395 state->iov.iov_len = blob.length;
397 subreq = writev_send(state, ev, ld->outgoing, ld->fd, false,
399 if (tevent_req_nomem(subreq, req)) {
400 return tevent_req_post(req, ev);
402 tevent_req_set_callback(subreq, tldap_msg_sent, req);
406 static void tldap_msg_unset_pending(struct tevent_req *req)
408 struct tldap_msg_state *state = tevent_req_data(
409 req, struct tldap_msg_state);
410 struct tldap_context *ld = state->ld;
411 int num_pending = talloc_array_length(ld->pending);
414 if (num_pending == 1) {
415 TALLOC_FREE(ld->pending);
419 for (i=0; i<num_pending; i++) {
420 if (req == ld->pending[i]) {
424 if (i == num_pending) {
426 * Something's seriously broken. Just returning here is the
427 * right thing nevertheless, the point of this routine is to
428 * remove ourselves from cli->pending.
434 * Remove ourselves from the cli->pending array
436 if (num_pending > 1) {
437 ld->pending[i] = ld->pending[num_pending-1];
441 * No NULL check here, we're shrinking by sizeof(void *), and
442 * talloc_realloc just adjusts the size for this.
444 ld->pending = talloc_realloc(NULL, ld->pending, struct tevent_req *,
449 static int tldap_msg_destructor(struct tevent_req *req)
451 tldap_msg_unset_pending(req);
455 static bool tldap_msg_set_pending(struct tevent_req *req)
457 struct tldap_msg_state *state = tevent_req_data(
458 req, struct tldap_msg_state);
459 struct tldap_context *ld;
460 struct tevent_req **pending;
462 struct tevent_req *subreq;
465 num_pending = talloc_array_length(ld->pending);
467 pending = talloc_realloc(ld, ld->pending, struct tevent_req *,
469 if (pending == NULL) {
472 pending[num_pending] = req;
473 ld->pending = pending;
474 talloc_set_destructor(req, tldap_msg_destructor);
476 if (num_pending > 0) {
481 * We're the first ones, add the read_ldap request that waits for the
482 * answer from the server
484 subreq = read_ldap_send(ld->pending, state->ev, ld->fd);
485 if (subreq == NULL) {
486 tldap_msg_unset_pending(req);
489 tevent_req_set_callback(subreq, tldap_msg_received, ld);
493 static void tldap_msg_sent(struct tevent_req *subreq)
495 struct tevent_req *req = tevent_req_callback_data(
496 subreq, struct tevent_req);
500 nwritten = writev_recv(subreq, &err);
502 if (nwritten == -1) {
503 tevent_req_error(req, TLDAP_SERVER_DOWN);
507 if (!tldap_msg_set_pending(req)) {
508 tevent_req_nomem(NULL, req);
513 static int tldap_msg_msgid(struct tevent_req *req)
515 struct tldap_msg_state *state = tevent_req_data(
516 req, struct tldap_msg_state);
521 static void tldap_msg_received(struct tevent_req *subreq)
523 struct tldap_context *ld = tevent_req_callback_data(
524 subreq, struct tldap_context);
525 struct tevent_req *req;
526 struct tldap_msg_state *state;
527 struct tevent_context *ev;
528 struct asn1_data *data;
537 received = read_ldap_recv(subreq, talloc_tos(), &inbuf, &err);
539 if (received == -1) {
540 status = TLDAP_SERVER_DOWN;
544 data = asn1_init(talloc_tos());
546 status = TLDAP_NO_MEMORY;
549 asn1_load_nocopy(data, inbuf, received);
552 ok &= asn1_start_tag(data, ASN1_SEQUENCE(0));
553 ok &= asn1_read_Integer(data, &id);
554 ok &= asn1_peek_uint8(data, &type);
557 status = TLDAP_PROTOCOL_ERROR;
561 tldap_debug(ld, TLDAP_DEBUG_TRACE, "tldap_msg_received: got msg %d "
562 "type %d\n", id, (int)type);
564 num_pending = talloc_array_length(ld->pending);
566 for (i=0; i<num_pending; i++) {
567 if (id == tldap_msg_msgid(ld->pending[i])) {
571 if (i == num_pending) {
572 /* Dump unexpected reply */
573 tldap_debug(ld, TLDAP_DEBUG_WARNING, "tldap_msg_received: "
574 "No request pending for msg %d\n", id);
579 req = ld->pending[i];
580 state = tevent_req_data(req, struct tldap_msg_state);
582 state->inbuf = talloc_move(state, &inbuf);
583 state->data = talloc_move(state, &data);
587 talloc_set_destructor(req, NULL);
588 tldap_msg_destructor(req);
589 tevent_req_done(req);
592 if (talloc_array_length(ld->pending) > 0) {
593 state = tevent_req_data(ld->pending[0],
594 struct tldap_msg_state);
595 subreq = read_ldap_send(ld->pending, state->ev, ld->fd);
596 if (subreq == NULL) {
597 status = TLDAP_NO_MEMORY;
600 tevent_req_set_callback(subreq, tldap_msg_received, ld);
605 while (talloc_array_length(ld->pending) > 0) {
606 req = ld->pending[0];
607 talloc_set_destructor(req, NULL);
608 tldap_msg_destructor(req);
609 tevent_req_error(req, status);
613 static int tldap_msg_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
614 struct tldap_message **pmsg)
616 struct tldap_msg_state *state = tevent_req_data(
617 req, struct tldap_msg_state);
618 struct tldap_message *msg;
622 if (tevent_req_is_ldap_error(req, &err)) {
626 if (!asn1_peek_uint8(state->data, &msgtype)) {
627 return TLDAP_PROTOCOL_ERROR;
631 return TLDAP_SUCCESS;
634 msg = talloc_zero(mem_ctx, struct tldap_message);
636 return TLDAP_NO_MEMORY;
640 msg->inbuf = talloc_move(msg, &state->inbuf);
641 msg->data = talloc_move(msg, &state->data);
645 return TLDAP_SUCCESS;
648 struct tldap_req_state {
650 struct asn1_data *out;
651 struct tldap_message *result;
655 char *res_diagnosticmessage;
657 struct tldap_control *res_sctrls;
660 static struct tevent_req *tldap_req_create(TALLOC_CTX *mem_ctx,
661 struct tldap_context *ld,
662 struct tldap_req_state **pstate)
664 struct tevent_req *req;
665 struct tldap_req_state *state;
667 req = tevent_req_create(mem_ctx, &state, struct tldap_req_state);
672 state->out = asn1_init(state);
673 if (state->out == NULL) {
677 state->result = NULL;
678 state->id = tldap_next_msgid(ld);
680 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
681 asn1_write_Integer(state->out, state->id);
687 static void tldap_save_errors(struct tldap_context *ctx,
688 struct tevent_req *req)
690 struct tldap_req_state *state = tevent_req_data(
691 req, struct tldap_req_state);
693 TALLOC_FREE(ctx->res_matcheddn);
694 TALLOC_FREE(ctx->res_diagnosticmessage);
695 TALLOC_FREE(ctx->res_referral);
696 TALLOC_FREE(ctx->res_sctrls);
698 ctx->lderr = state->lderr;
699 ctx->res_matcheddn = talloc_move(ctx, &state->res_matcheddn);
700 ctx->res_diagnosticmessage = talloc_move(
701 ctx, &state->res_diagnosticmessage);
702 ctx->res_referral = talloc_move(ctx, &state->res_referral);
703 ctx->res_sctrls = talloc_move(ctx, &state->res_sctrls);
706 static char *blob2string_talloc(TALLOC_CTX *mem_ctx, DATA_BLOB blob)
708 char *result = talloc_array(mem_ctx, char, blob.length+1);
709 memcpy(result, blob.data, blob.length);
710 result[blob.length] = '\0';
714 static bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx,
715 struct asn1_data *data,
719 if (!asn1_read_OctetString(data, mem_ctx, &string))
721 *result = blob2string_talloc(mem_ctx, string);
722 data_blob_free(&string);
726 static bool tldap_decode_response(struct tldap_req_state *state)
728 struct asn1_data *data = state->result->data;
731 ok &= asn1_read_enumerated(data, &state->lderr);
732 ok &= asn1_read_OctetString_talloc(state, data, &state->res_matcheddn);
733 ok &= asn1_read_OctetString_talloc(state, data,
734 &state->res_diagnosticmessage);
735 if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
736 ok &= asn1_start_tag(data, ASN1_CONTEXT(3));
737 ok &= asn1_read_OctetString_talloc(
738 state, data, &state->res_referral);
739 ok &= asn1_end_tag(data);
741 state->res_referral = NULL;
747 static void tldap_sasl_bind_done(struct tevent_req *subreq);
749 struct tevent_req *tldap_sasl_bind_send(TALLOC_CTX *mem_ctx,
750 struct tevent_context *ev,
751 struct tldap_context *ld,
753 const char *mechanism,
755 struct tldap_control *sctrls,
757 struct tldap_control *cctrls,
760 struct tevent_req *req, *subreq;
761 struct tldap_req_state *state;
763 req = tldap_req_create(mem_ctx, ld, &state);
772 asn1_push_tag(state->out, TLDAP_REQ_BIND);
773 asn1_write_Integer(state->out, ld->ld_version);
774 asn1_write_OctetString(state->out, dn, (dn != NULL) ? strlen(dn) : 0);
776 if (mechanism == NULL) {
777 asn1_push_tag(state->out, ASN1_CONTEXT_SIMPLE(0));
778 asn1_write(state->out, creds->data, creds->length);
779 asn1_pop_tag(state->out);
781 asn1_push_tag(state->out, ASN1_CONTEXT(3));
782 asn1_write_OctetString(state->out, mechanism,
784 if ((creds != NULL) && (creds->data != NULL)) {
785 asn1_write_OctetString(state->out, creds->data,
788 asn1_pop_tag(state->out);
791 if (!asn1_pop_tag(state->out)) {
792 tevent_req_error(req, TLDAP_ENCODING_ERROR);
793 return tevent_req_post(req, ev);
796 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
798 if (tevent_req_nomem(subreq, req)) {
799 return tevent_req_post(req, ev);
801 tevent_req_set_callback(subreq, tldap_sasl_bind_done, req);
805 static void tldap_sasl_bind_done(struct tevent_req *subreq)
807 struct tevent_req *req = tevent_req_callback_data(
808 subreq, struct tevent_req);
809 struct tldap_req_state *state = tevent_req_data(
810 req, struct tldap_req_state);
813 err = tldap_msg_recv(subreq, state, &state->result);
815 if (err != TLDAP_SUCCESS) {
816 tevent_req_error(req, err);
819 if (state->result->type != TLDAP_RES_BIND) {
820 tevent_req_error(req, TLDAP_PROTOCOL_ERROR);
823 if (!asn1_start_tag(state->result->data, state->result->type) ||
824 !tldap_decode_response(state) ||
825 !asn1_end_tag(state->result->data)) {
826 tevent_req_error(req, TLDAP_DECODING_ERROR);
830 * TODO: pull the reply blob
832 if (state->lderr != TLDAP_SUCCESS) {
833 tevent_req_error(req, state->lderr);
836 tevent_req_done(req);
839 int tldap_sasl_bind_recv(struct tevent_req *req)
843 if (tevent_req_is_ldap_error(req, &err)) {
846 return TLDAP_SUCCESS;
849 int tldap_sasl_bind(struct tldap_context *ld,
851 const char *mechanism,
853 struct tldap_control *sctrls,
855 struct tldap_control *cctrls,
858 TALLOC_CTX *frame = talloc_stackframe();
859 struct tevent_context *ev;
860 struct tevent_req *req;
863 ev = event_context_init(frame);
865 result = TLDAP_NO_MEMORY;
869 req = tldap_sasl_bind_send(frame, ev, ld, dn, mechanism, creds,
870 sctrls, num_sctrls, cctrls, num_cctrls);
872 result = TLDAP_NO_MEMORY;
876 if (!tevent_req_poll(req, ev)) {
877 result = TLDAP_OPERATIONS_ERROR;
881 result = tldap_sasl_bind_recv(req);
882 tldap_save_errors(ld, req);
888 struct tevent_req *tldap_simple_bind_send(TALLOC_CTX *mem_ctx,
889 struct tevent_context *ev,
890 struct tldap_context *ld,
896 if (passwd != NULL) {
897 cred.data = (uint8_t *)passwd;
898 cred.length = strlen(passwd);
900 cred.data = (uint8_t *)"";
903 return tldap_sasl_bind_send(mem_ctx, ev, ld, dn, NULL, &cred, NULL, 0,
907 int tldap_simple_bind_recv(struct tevent_req *req)
909 return tldap_sasl_bind_recv(req);
912 int tldap_simple_bind(struct tldap_context *ld, const char *dn,
917 if (passwd != NULL) {
918 cred.data = (uint8_t *)passwd;
919 cred.length = strlen(passwd);
921 cred.data = (uint8_t *)"";
924 return tldap_sasl_bind(ld, dn, NULL, &cred, NULL, 0, NULL, 0);
927 /*****************************************************************************/
930 * This piece has a dependency on ldb, the ldb_parse_tree() function is used.
931 * In case we want to separate out tldap, we need to copy or rewrite it.
934 #include "lib/ldb/include/ldb.h"
935 #include "lib/ldb/include/ldb_errors.h"
937 static bool ldap_push_filter(struct asn1_data *data,
938 struct ldb_parse_tree *tree)
942 switch (tree->operation) {
946 ASN1_CONTEXT(tree->operation==LDB_OP_AND?0:1));
947 for (i=0; i<tree->u.list.num_elements; i++) {
948 if (!ldap_push_filter(data,
949 tree->u.list.elements[i])) {
957 asn1_push_tag(data, ASN1_CONTEXT(2));
958 if (!ldap_push_filter(data, tree->u.isnot.child)) {
964 case LDB_OP_EQUALITY:
966 asn1_push_tag(data, ASN1_CONTEXT(3));
967 asn1_write_OctetString(data, tree->u.equality.attr,
968 strlen(tree->u.equality.attr));
969 asn1_write_OctetString(data, tree->u.equality.value.data,
970 tree->u.equality.value.length);
974 case LDB_OP_SUBSTRING:
976 SubstringFilter ::= SEQUENCE {
977 type AttributeDescription,
978 -- at least one must be present
979 substrings SEQUENCE OF CHOICE {
980 initial [0] LDAPString,
982 final [2] LDAPString } }
984 asn1_push_tag(data, ASN1_CONTEXT(4));
985 asn1_write_OctetString(data, tree->u.substring.attr,
986 strlen(tree->u.substring.attr));
987 asn1_push_tag(data, ASN1_SEQUENCE(0));
989 if (!tree->u.substring.start_with_wildcard) {
990 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
991 asn1_write_DATA_BLOB_LDAPString(
992 data, tree->u.substring.chunks[i]);
996 while (tree->u.substring.chunks[i]) {
999 if ((!tree->u.substring.chunks[i + 1]) &&
1000 (tree->u.substring.end_with_wildcard == 0)) {
1005 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(ctx));
1006 asn1_write_DATA_BLOB_LDAPString(
1007 data, tree->u.substring.chunks[i]);
1015 case LDB_OP_GREATER:
1016 /* greaterOrEqual test */
1017 asn1_push_tag(data, ASN1_CONTEXT(5));
1018 asn1_write_OctetString(data, tree->u.comparison.attr,
1019 strlen(tree->u.comparison.attr));
1020 asn1_write_OctetString(data, tree->u.comparison.value.data,
1021 tree->u.comparison.value.length);
1026 /* lessOrEqual test */
1027 asn1_push_tag(data, ASN1_CONTEXT(6));
1028 asn1_write_OctetString(data, tree->u.comparison.attr,
1029 strlen(tree->u.comparison.attr));
1030 asn1_write_OctetString(data, tree->u.comparison.value.data,
1031 tree->u.comparison.value.length);
1035 case LDB_OP_PRESENT:
1037 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(7));
1038 asn1_write_LDAPString(data, tree->u.present.attr);
1040 return !data->has_error;
1044 asn1_push_tag(data, ASN1_CONTEXT(8));
1045 asn1_write_OctetString(data, tree->u.comparison.attr,
1046 strlen(tree->u.comparison.attr));
1047 asn1_write_OctetString(data, tree->u.comparison.value.data,
1048 tree->u.comparison.value.length);
1052 case LDB_OP_EXTENDED:
1054 MatchingRuleAssertion ::= SEQUENCE {
1055 matchingRule [1] MatchingRuleID OPTIONAL,
1056 type [2] AttributeDescription OPTIONAL,
1057 matchValue [3] AssertionValue,
1058 dnAttributes [4] BOOLEAN DEFAULT FALSE
1061 asn1_push_tag(data, ASN1_CONTEXT(9));
1062 if (tree->u.extended.rule_id) {
1063 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1));
1064 asn1_write_LDAPString(data, tree->u.extended.rule_id);
1067 if (tree->u.extended.attr) {
1068 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(2));
1069 asn1_write_LDAPString(data, tree->u.extended.attr);
1072 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(3));
1073 asn1_write_DATA_BLOB_LDAPString(data, &tree->u.extended.value);
1075 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(4));
1076 asn1_write_uint8(data, tree->u.extended.dnAttributes);
1084 return !data->has_error;
1087 static bool tldap_push_filter(struct asn1_data *data, const char *filter)
1089 struct ldb_parse_tree *tree;
1092 tree = ldb_parse_tree(talloc_tos(), filter);
1096 ret = ldap_push_filter(data, tree);
1101 /*****************************************************************************/
1103 static void tldap_search_done(struct tevent_req *subreq);
1105 struct tevent_req *tldap_search_send(TALLOC_CTX *mem_ctx,
1106 struct tevent_context *ev,
1107 struct tldap_context *ld,
1108 const char *base, int scope,
1113 struct tldap_control *sctrls,
1115 struct tldap_control *cctrls,
1121 struct tevent_req *req, *subreq;
1122 struct tldap_req_state *state;
1125 req = tldap_req_create(mem_ctx, ld, &state);
1130 asn1_push_tag(state->out, TLDAP_REQ_SEARCH);
1131 asn1_write_OctetString(state->out, base, strlen(base));
1132 asn1_write_enumerated(state->out, scope);
1133 asn1_write_enumerated(state->out, deref);
1134 asn1_write_Integer(state->out, sizelimit);
1135 asn1_write_Integer(state->out, timelimit);
1136 asn1_write_BOOLEAN(state->out, attrsonly);
1138 if (!tldap_push_filter(state->out, filter)) {
1139 goto encoding_error;
1142 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1143 for (i=0; i<num_attrs; i++) {
1144 asn1_write_OctetString(state->out, attrs[i], strlen(attrs[i]));
1146 asn1_pop_tag(state->out);
1147 asn1_pop_tag(state->out);
1149 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1150 sctrls, num_sctrls);
1151 if (tevent_req_nomem(subreq, req)) {
1152 return tevent_req_post(req, ev);
1154 tevent_req_set_callback(subreq, tldap_search_done, req);
1158 tevent_req_error(req, TLDAP_ENCODING_ERROR);
1159 return tevent_req_post(req, ev);
1162 static void tldap_search_done(struct tevent_req *subreq)
1164 struct tevent_req *req = tevent_req_callback_data(
1165 subreq, struct tevent_req);
1166 struct tldap_req_state *state = tevent_req_data(
1167 req, struct tldap_req_state);
1170 err = tldap_msg_recv(subreq, state, &state->result);
1171 if (err != TLDAP_SUCCESS) {
1172 tevent_req_error(req, err);
1175 switch (state->result->type) {
1176 case TLDAP_RES_SEARCH_ENTRY:
1177 case TLDAP_RES_SEARCH_REFERENCE:
1178 tevent_req_notify_callback(req);
1179 if (!tldap_msg_set_pending(subreq)) {
1180 tevent_req_nomem(NULL, req);
1184 case TLDAP_RES_SEARCH_RESULT:
1185 TALLOC_FREE(subreq);
1186 if (!asn1_start_tag(state->result->data,
1187 state->result->type) ||
1188 !tldap_decode_response(state) ||
1189 !asn1_end_tag(state->result->data)) {
1190 tevent_req_error(req, TLDAP_DECODING_ERROR);
1193 tevent_req_done(req);
1196 tevent_req_error(req, TLDAP_PROTOCOL_ERROR);
1201 int tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
1202 struct tldap_message **pmsg)
1204 struct tldap_req_state *state = tevent_req_data(
1205 req, struct tldap_req_state);
1208 if (!tevent_req_is_in_progress(req)
1209 && tevent_req_is_ldap_error(req, &err)) {
1213 if (tevent_req_is_in_progress(req)) {
1214 switch (state->result->type) {
1215 case TLDAP_RES_SEARCH_ENTRY:
1216 case TLDAP_RES_SEARCH_REFERENCE:
1219 return TLDAP_OPERATIONS_ERROR;
1223 *pmsg = talloc_move(mem_ctx, &state->result);
1224 return TLDAP_SUCCESS;
1227 struct tldap_sync_search_state {
1228 TALLOC_CTX *mem_ctx;
1229 struct tldap_message **entries;
1230 struct tldap_message **refs;
1234 static void tldap_search_cb(struct tevent_req *req)
1236 struct tldap_sync_search_state *state =
1237 (struct tldap_sync_search_state *)
1238 tevent_req_callback_data_void(req);
1239 struct tldap_message *msg, **tmp;
1240 int rc, num_entries, num_refs;
1242 rc = tldap_search_recv(req, talloc_tos(), &msg);
1243 if (rc != TLDAP_SUCCESS) {
1248 switch (tldap_msg_type(msg)) {
1249 case TLDAP_RES_SEARCH_ENTRY:
1250 num_entries = talloc_array_length(state->entries);
1251 tmp = talloc_realloc(state->mem_ctx, state->entries,
1252 struct tldap_message *, num_entries + 1);
1254 state->rc = TLDAP_NO_MEMORY;
1257 state->entries = tmp;
1258 state->entries[num_entries] = talloc_move(state->entries,
1261 case TLDAP_RES_SEARCH_REFERENCE:
1262 num_refs = talloc_array_length(state->refs);
1263 tmp = talloc_realloc(state->mem_ctx, state->refs,
1264 struct tldap_message *, num_refs + 1);
1266 state->rc = TLDAP_NO_MEMORY;
1270 state->refs[num_refs] = talloc_move(state->refs, &msg);
1272 case TLDAP_RES_SEARCH_RESULT:
1273 state->rc = TLDAP_SUCCESS;
1276 state->rc = TLDAP_PROTOCOL_ERROR;
1281 int tldap_search(struct tldap_context *ld,
1282 const char *base, int scope, const char *filter,
1283 const char **attrs, int num_attrs, int attrsonly,
1284 struct tldap_control *sctrls, int num_sctrls,
1285 struct tldap_control *cctrls, int num_cctrls,
1286 int timelimit, int sizelimit, int deref,
1287 TALLOC_CTX *mem_ctx, struct tldap_message ***entries,
1288 struct tldap_message ***refs)
1290 TALLOC_CTX *frame = talloc_stackframe();
1291 struct tevent_context *ev;
1292 struct tevent_req *req;
1293 struct tldap_sync_search_state state;
1296 state.mem_ctx = mem_ctx;
1297 state.rc = TLDAP_SUCCESS;
1299 ev = event_context_init(frame);
1301 state.rc = TLDAP_NO_MEMORY;
1305 req = tldap_search_send(frame, ev, ld, base, scope, filter,
1306 attrs, num_attrs, attrsonly,
1307 sctrls, num_sctrls, cctrls, num_cctrls,
1308 timelimit, sizelimit, deref);
1310 state.rc = TLDAP_NO_MEMORY;
1314 tevent_req_set_callback(req, tldap_search_cb, &state);
1316 while (tevent_req_is_in_progress(req)
1317 && (state.rc == TLDAP_SUCCESS)) {
1318 if (tevent_loop_once(ev) == -1) {
1319 return TLDAP_OPERATIONS_ERROR;
1323 if (state.rc != TLDAP_SUCCESS) {
1327 if (entries != NULL) {
1328 *entries = state.entries;
1330 TALLOC_FREE(state.entries);
1335 TALLOC_FREE(state.refs);
1337 tldap_save_errors(ld, req);
1343 static bool tldap_parse_search_entry(struct tldap_message *msg)
1345 int num_attribs = 0;
1347 asn1_start_tag(msg->data, msg->type);
1351 asn1_read_OctetString_talloc(msg, msg->data, &msg->dn);
1352 if (msg->dn == NULL) {
1357 * Attributes: We overallocate msg->attribs by one, so that while
1358 * looping over the attributes we can directly parse into the last
1359 * array element. Same for the values in the inner loop.
1362 msg->attribs = talloc_array(msg, struct tldap_attribute, 1);
1363 if (msg->attribs == NULL) {
1367 asn1_start_tag(msg->data, ASN1_SEQUENCE(0));
1368 while (asn1_peek_tag(msg->data, ASN1_SEQUENCE(0))) {
1369 struct tldap_attribute *attrib;
1372 attrib = &msg->attribs[num_attribs];
1373 attrib->values = talloc_array(msg->attribs, DATA_BLOB, 1);
1374 if (attrib->values == NULL) {
1377 asn1_start_tag(msg->data, ASN1_SEQUENCE(0));
1378 asn1_read_OctetString_talloc(msg->attribs, msg->data,
1380 asn1_start_tag(msg->data, ASN1_SET);
1382 while (asn1_peek_tag(msg->data, ASN1_OCTET_STRING)) {
1383 asn1_read_OctetString(msg->data, msg,
1384 &attrib->values[num_values]);
1386 attrib->values = talloc_realloc(
1387 msg->attribs, attrib->values, DATA_BLOB,
1389 if (attrib->values == NULL) {
1394 attrib->values = talloc_realloc(msg->attribs, attrib->values,
1395 DATA_BLOB, num_values);
1396 attrib->num_values = num_values;
1398 asn1_end_tag(msg->data); /* ASN1_SET */
1399 asn1_end_tag(msg->data); /* ASN1_SEQUENCE(0) */
1400 msg->attribs = talloc_realloc(
1401 msg, msg->attribs, struct tldap_attribute,
1403 if (msg->attribs == NULL) {
1408 msg->attribs = talloc_realloc(
1409 msg, msg->attribs, struct tldap_attribute, num_attribs);
1410 asn1_end_tag(msg->data);
1411 if (msg->data->has_error) {
1417 bool tldap_entry_dn(struct tldap_message *msg, char **dn)
1419 if ((msg->dn == NULL) && (!tldap_parse_search_entry(msg))) {
1426 bool tldap_entry_attributes(struct tldap_message *msg, int *num_attributes,
1427 struct tldap_attribute **attributes)
1429 if ((msg->dn == NULL) && (!tldap_parse_search_entry(msg))) {
1432 *attributes = msg->attribs;
1433 *num_attributes = talloc_array_length(msg->attribs);
1437 static bool tldap_decode_controls(struct tldap_req_state *state)
1439 struct asn1_data *data = state->result->data;
1440 struct tldap_control *sctrls = NULL;
1441 int num_controls = 0;
1443 state->res_sctrls = NULL;
1445 if (!asn1_peek_tag(data, ASN1_CONTEXT(0))) {
1449 asn1_start_tag(data, ASN1_CONTEXT(0));
1451 while (asn1_peek_tag(data, ASN1_SEQUENCE(0))) {
1452 struct tldap_control *c;
1455 sctrls = talloc_realloc(state, sctrls, struct tldap_control,
1457 if (sctrls == NULL) {
1460 c = &sctrls[num_controls];
1462 asn1_start_tag(data, ASN1_SEQUENCE(0));
1463 asn1_read_OctetString_talloc(state, data, &oid);
1464 if ((data->has_error) || (oid == NULL)) {
1468 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
1469 asn1_read_BOOLEAN(data, &c->critical);
1471 c->critical = false;
1473 c->value = data_blob_null;
1474 if (asn1_peek_tag(data, ASN1_OCTET_STRING) &&
1475 !asn1_read_OctetString(data, state, &c->value)) {
1478 asn1_end_tag(data); /* ASN1_SEQUENCE(0) */
1483 asn1_end_tag(data); /* ASN1_CONTEXT(0) */
1485 if (data->has_error) {
1486 TALLOC_FREE(sctrls);
1489 state->res_sctrls = sctrls;
1493 static void tldap_simple_done(struct tevent_req *subreq, int type)
1495 struct tevent_req *req = tevent_req_callback_data(
1496 subreq, struct tevent_req);
1497 struct tldap_req_state *state = tevent_req_data(
1498 req, struct tldap_req_state);
1501 err = tldap_msg_recv(subreq, state, &state->result);
1502 TALLOC_FREE(subreq);
1503 if (err != TLDAP_SUCCESS) {
1504 tevent_req_error(req, err);
1507 if (state->result->type != type) {
1508 tevent_req_error(req, TLDAP_PROTOCOL_ERROR);
1511 if (!asn1_start_tag(state->result->data, state->result->type) ||
1512 !tldap_decode_response(state) ||
1513 !asn1_end_tag(state->result->data) ||
1514 !tldap_decode_controls(state)) {
1515 tevent_req_error(req, TLDAP_DECODING_ERROR);
1518 if (state->lderr != TLDAP_SUCCESS) {
1519 tevent_req_error(req, state->lderr);
1522 tevent_req_done(req);
1525 static int tldap_simple_recv(struct tevent_req *req)
1528 if (tevent_req_is_ldap_error(req, &err)) {
1531 return TLDAP_SUCCESS;
1534 static void tldap_add_done(struct tevent_req *subreq);
1536 struct tevent_req *tldap_add_send(TALLOC_CTX *mem_ctx,
1537 struct tevent_context *ev,
1538 struct tldap_context *ld,
1540 struct tldap_mod *attributes,
1542 struct tldap_control *sctrls,
1544 struct tldap_control *cctrls,
1547 struct tevent_req *req, *subreq;
1548 struct tldap_req_state *state;
1551 req = tldap_req_create(mem_ctx, ld, &state);
1556 asn1_push_tag(state->out, TLDAP_REQ_ADD);
1557 asn1_write_OctetString(state->out, dn, strlen(dn));
1558 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1560 for (i=0; i<num_attributes; i++) {
1561 struct tldap_mod *attrib = &attributes[i];
1562 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1563 asn1_write_OctetString(state->out, attrib->attribute,
1564 strlen(attrib->attribute));
1565 asn1_push_tag(state->out, ASN1_SET);
1566 for (j=0; j<attrib->num_values; j++) {
1567 asn1_write_OctetString(state->out,
1568 attrib->values[j].data,
1569 attrib->values[j].length);
1571 asn1_pop_tag(state->out);
1572 asn1_pop_tag(state->out);
1575 asn1_pop_tag(state->out);
1576 asn1_pop_tag(state->out);
1578 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1579 sctrls, num_sctrls);
1580 if (tevent_req_nomem(subreq, req)) {
1581 return tevent_req_post(req, ev);
1583 tevent_req_set_callback(subreq, tldap_add_done, req);
1587 static void tldap_add_done(struct tevent_req *subreq)
1589 return tldap_simple_done(subreq, TLDAP_RES_ADD);
1592 int tldap_add_recv(struct tevent_req *req)
1594 return tldap_simple_recv(req);
1597 int tldap_add(struct tldap_context *ld, const char *dn,
1598 int num_attributes, struct tldap_mod *attributes,
1599 struct tldap_control *sctrls, int num_sctrls,
1600 struct tldap_control *cctrls, int num_cctrls)
1602 TALLOC_CTX *frame = talloc_stackframe();
1603 struct tevent_context *ev;
1604 struct tevent_req *req;
1607 ev = event_context_init(frame);
1609 result = TLDAP_NO_MEMORY;
1613 req = tldap_add_send(frame, ev, ld, dn, attributes, num_attributes,
1614 sctrls, num_sctrls, cctrls, num_cctrls);
1616 result = TLDAP_NO_MEMORY;
1620 if (!tevent_req_poll(req, ev)) {
1621 result = TLDAP_OPERATIONS_ERROR;
1625 result = tldap_add_recv(req);
1626 tldap_save_errors(ld, req);
1632 static void tldap_modify_done(struct tevent_req *subreq);
1634 struct tevent_req *tldap_modify_send(TALLOC_CTX *mem_ctx,
1635 struct tevent_context *ev,
1636 struct tldap_context *ld,
1638 int num_mods, struct tldap_mod *mods,
1639 struct tldap_control *sctrls,
1641 struct tldap_control *cctrls,
1644 struct tevent_req *req, *subreq;
1645 struct tldap_req_state *state;
1648 req = tldap_req_create(mem_ctx, ld, &state);
1653 asn1_push_tag(state->out, TLDAP_REQ_MODIFY);
1654 asn1_write_OctetString(state->out, dn, strlen(dn));
1655 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1657 for (i=0; i<num_mods; i++) {
1658 struct tldap_mod *mod = &mods[i];
1659 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1660 asn1_write_enumerated(state->out, mod->mod_op),
1661 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1662 asn1_write_OctetString(state->out, mod->attribute,
1663 strlen(mod->attribute));
1664 asn1_push_tag(state->out, ASN1_SET);
1665 for (j=0; j<mod->num_values; j++) {
1666 asn1_write_OctetString(state->out,
1667 mod->values[j].data,
1668 mod->values[j].length);
1670 asn1_pop_tag(state->out);
1671 asn1_pop_tag(state->out);
1672 asn1_pop_tag(state->out);
1675 asn1_pop_tag(state->out);
1676 asn1_pop_tag(state->out);
1678 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1679 sctrls, num_sctrls);
1680 if (tevent_req_nomem(subreq, req)) {
1681 return tevent_req_post(req, ev);
1683 tevent_req_set_callback(subreq, tldap_modify_done, req);
1687 static void tldap_modify_done(struct tevent_req *subreq)
1689 return tldap_simple_done(subreq, TLDAP_RES_MODIFY);
1692 int tldap_modify_recv(struct tevent_req *req)
1694 return tldap_simple_recv(req);
1697 int tldap_modify(struct tldap_context *ld, const char *dn,
1698 int num_mods, struct tldap_mod *mods,
1699 struct tldap_control *sctrls, int num_sctrls,
1700 struct tldap_control *cctrls, int num_cctrls)
1702 TALLOC_CTX *frame = talloc_stackframe();
1703 struct tevent_context *ev;
1704 struct tevent_req *req;
1707 ev = event_context_init(frame);
1709 result = TLDAP_NO_MEMORY;
1713 req = tldap_modify_send(frame, ev, ld, dn, num_mods, mods,
1714 sctrls, num_sctrls, cctrls, num_cctrls);
1716 result = TLDAP_NO_MEMORY;
1720 if (!tevent_req_poll(req, ev)) {
1721 result = TLDAP_OPERATIONS_ERROR;
1725 result = tldap_modify_recv(req);
1726 tldap_save_errors(ld, req);
1732 static void tldap_delete_done(struct tevent_req *subreq);
1734 struct tevent_req *tldap_delete_send(TALLOC_CTX *mem_ctx,
1735 struct tevent_context *ev,
1736 struct tldap_context *ld,
1738 struct tldap_control *sctrls,
1740 struct tldap_control *cctrls,
1743 struct tevent_req *req, *subreq;
1744 struct tldap_req_state *state;
1746 req = tldap_req_create(mem_ctx, ld, &state);
1751 asn1_push_tag(state->out, TLDAP_REQ_DELETE);
1752 asn1_write(state->out, dn, strlen(dn));
1753 asn1_pop_tag(state->out);
1755 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1756 sctrls, num_sctrls);
1757 if (tevent_req_nomem(subreq, req)) {
1758 return tevent_req_post(req, ev);
1760 tevent_req_set_callback(subreq, tldap_delete_done, req);
1764 static void tldap_delete_done(struct tevent_req *subreq)
1766 return tldap_simple_done(subreq, TLDAP_RES_DELETE);
1769 int tldap_delete_recv(struct tevent_req *req)
1771 return tldap_simple_recv(req);
1774 int tldap_delete(struct tldap_context *ld, const char *dn,
1775 struct tldap_control *sctrls, int num_sctrls,
1776 struct tldap_control *cctrls, int num_cctrls)
1778 TALLOC_CTX *frame = talloc_stackframe();
1779 struct tevent_context *ev;
1780 struct tevent_req *req;
1783 ev = event_context_init(frame);
1785 result = TLDAP_NO_MEMORY;
1789 req = tldap_delete_send(frame, ev, ld, dn, sctrls, num_sctrls,
1790 cctrls, num_cctrls);
1792 result = TLDAP_NO_MEMORY;
1796 if (!tevent_req_poll(req, ev)) {
1797 result = TLDAP_OPERATIONS_ERROR;
1801 result = tldap_delete_recv(req);
1802 tldap_save_errors(ld, req);
1808 int tldap_msg_id(const struct tldap_message *msg)
1813 int tldap_msg_type(const struct tldap_message *msg)
1818 const char *tldap_req_matcheddn(struct tevent_req *req)
1820 struct tldap_req_state *state = tevent_req_data(
1821 req, struct tldap_req_state);
1822 return state->res_matcheddn;
1825 const char *tldap_req_diagnosticmessage(struct tevent_req *req)
1827 struct tldap_req_state *state = tevent_req_data(
1828 req, struct tldap_req_state);
1829 return state->res_diagnosticmessage;
1832 const char *tldap_req_referral(struct tevent_req *req)
1834 struct tldap_req_state *state = tevent_req_data(
1835 req, struct tldap_req_state);
1836 return state->res_referral;
1839 void tldap_req_sctrls(struct tevent_req *req, int *num_sctrls,
1840 struct tldap_control **sctrls)
1842 struct tldap_req_state *state = tevent_req_data(
1843 req, struct tldap_req_state);
1844 *sctrls = state->res_sctrls;
1845 *num_sctrls = talloc_array_length(state->res_sctrls);
1848 const char *tldap_ctx_matcheddn(struct tldap_context *ctx)
1850 return ctx->res_matcheddn;
1853 const char *tldap_ctx_diagnosticmessage(struct tldap_context *ctx)
1855 return ctx->res_diagnosticmessage;
1858 const char *tldap_ctx_referral(struct tldap_context *ctx)
1860 return ctx->res_referral;
1863 void tldap_ctx_sctrls(struct tldap_context *ctx, int *num_sctrls,
1864 struct tldap_control **sctrls)
1866 *sctrls = ctx->res_sctrls;
1867 *num_sctrls = talloc_array_length(ctx->res_sctrls);
1870 const char *tldap_err2string(int rc)
1872 const char *res = NULL;
1875 * This would normally be a table, but the error codes are not fully
1876 * sequential. Let the compiler figure out the optimum implementation
1882 res = "TLDAP_SUCCESS";
1884 case TLDAP_OPERATIONS_ERROR:
1885 res = "TLDAP_OPERATIONS_ERROR";
1887 case TLDAP_PROTOCOL_ERROR:
1888 res = "TLDAP_PROTOCOL_ERROR";
1890 case TLDAP_TIMELIMIT_EXCEEDED:
1891 res = "TLDAP_TIMELIMIT_EXCEEDED";
1893 case TLDAP_SIZELIMIT_EXCEEDED:
1894 res = "TLDAP_SIZELIMIT_EXCEEDED";
1896 case TLDAP_COMPARE_FALSE:
1897 res = "TLDAP_COMPARE_FALSE";
1899 case TLDAP_COMPARE_TRUE:
1900 res = "TLDAP_COMPARE_TRUE";
1902 case TLDAP_STRONG_AUTH_NOT_SUPPORTED:
1903 res = "TLDAP_STRONG_AUTH_NOT_SUPPORTED";
1905 case TLDAP_STRONG_AUTH_REQUIRED:
1906 res = "TLDAP_STRONG_AUTH_REQUIRED";
1908 case TLDAP_REFERRAL:
1909 res = "TLDAP_REFERRAL";
1911 case TLDAP_ADMINLIMIT_EXCEEDED:
1912 res = "TLDAP_ADMINLIMIT_EXCEEDED";
1914 case TLDAP_UNAVAILABLE_CRITICAL_EXTENSION:
1915 res = "TLDAP_UNAVAILABLE_CRITICAL_EXTENSION";
1917 case TLDAP_CONFIDENTIALITY_REQUIRED:
1918 res = "TLDAP_CONFIDENTIALITY_REQUIRED";
1920 case TLDAP_SASL_BIND_IN_PROGRESS:
1921 res = "TLDAP_SASL_BIND_IN_PROGRESS";
1923 case TLDAP_NO_SUCH_ATTRIBUTE:
1924 res = "TLDAP_NO_SUCH_ATTRIBUTE";
1926 case TLDAP_UNDEFINED_TYPE:
1927 res = "TLDAP_UNDEFINED_TYPE";
1929 case TLDAP_INAPPROPRIATE_MATCHING:
1930 res = "TLDAP_INAPPROPRIATE_MATCHING";
1932 case TLDAP_CONSTRAINT_VIOLATION:
1933 res = "TLDAP_CONSTRAINT_VIOLATION";
1935 case TLDAP_TYPE_OR_VALUE_EXISTS:
1936 res = "TLDAP_TYPE_OR_VALUE_EXISTS";
1938 case TLDAP_INVALID_SYNTAX:
1939 res = "TLDAP_INVALID_SYNTAX";
1941 case TLDAP_NO_SUCH_OBJECT:
1942 res = "TLDAP_NO_SUCH_OBJECT";
1944 case TLDAP_ALIAS_PROBLEM:
1945 res = "TLDAP_ALIAS_PROBLEM";
1947 case TLDAP_INVALID_DN_SYNTAX:
1948 res = "TLDAP_INVALID_DN_SYNTAX";
1951 res = "TLDAP_IS_LEAF";
1953 case TLDAP_ALIAS_DEREF_PROBLEM:
1954 res = "TLDAP_ALIAS_DEREF_PROBLEM";
1956 case TLDAP_INAPPROPRIATE_AUTH:
1957 res = "TLDAP_INAPPROPRIATE_AUTH";
1959 case TLDAP_INVALID_CREDENTIALS:
1960 res = "TLDAP_INVALID_CREDENTIALS";
1962 case TLDAP_INSUFFICIENT_ACCESS:
1963 res = "TLDAP_INSUFFICIENT_ACCESS";
1968 case TLDAP_UNAVAILABLE:
1969 res = "TLDAP_UNAVAILABLE";
1971 case TLDAP_UNWILLING_TO_PERFORM:
1972 res = "TLDAP_UNWILLING_TO_PERFORM";
1974 case TLDAP_LOOP_DETECT:
1975 res = "TLDAP_LOOP_DETECT";
1977 case TLDAP_NAMING_VIOLATION:
1978 res = "TLDAP_NAMING_VIOLATION";
1980 case TLDAP_OBJECT_CLASS_VIOLATION:
1981 res = "TLDAP_OBJECT_CLASS_VIOLATION";
1983 case TLDAP_NOT_ALLOWED_ON_NONLEAF:
1984 res = "TLDAP_NOT_ALLOWED_ON_NONLEAF";
1986 case TLDAP_NOT_ALLOWED_ON_RDN:
1987 res = "TLDAP_NOT_ALLOWED_ON_RDN";
1989 case TLDAP_ALREADY_EXISTS:
1990 res = "TLDAP_ALREADY_EXISTS";
1992 case TLDAP_NO_OBJECT_CLASS_MODS:
1993 res = "TLDAP_NO_OBJECT_CLASS_MODS";
1995 case TLDAP_RESULTS_TOO_LARGE:
1996 res = "TLDAP_RESULTS_TOO_LARGE";
1998 case TLDAP_AFFECTS_MULTIPLE_DSAS:
1999 res = "TLDAP_AFFECTS_MULTIPLE_DSAS";
2002 res = "TLDAP_OTHER";
2004 case TLDAP_SERVER_DOWN:
2005 res = "TLDAP_SERVER_DOWN";
2007 case TLDAP_LOCAL_ERROR:
2008 res = "TLDAP_LOCAL_ERROR";
2010 case TLDAP_ENCODING_ERROR:
2011 res = "TLDAP_ENCODING_ERROR";
2013 case TLDAP_DECODING_ERROR:
2014 res = "TLDAP_DECODING_ERROR";
2017 res = "TLDAP_TIMEOUT";
2019 case TLDAP_AUTH_UNKNOWN:
2020 res = "TLDAP_AUTH_UNKNOWN";
2022 case TLDAP_FILTER_ERROR:
2023 res = "TLDAP_FILTER_ERROR";
2025 case TLDAP_USER_CANCELLED:
2026 res = "TLDAP_USER_CANCELLED";
2028 case TLDAP_PARAM_ERROR:
2029 res = "TLDAP_PARAM_ERROR";
2031 case TLDAP_NO_MEMORY:
2032 res = "TLDAP_NO_MEMORY";
2034 case TLDAP_CONNECT_ERROR:
2035 res = "TLDAP_CONNECT_ERROR";
2037 case TLDAP_NOT_SUPPORTED:
2038 res = "TLDAP_NOT_SUPPORTED";
2040 case TLDAP_CONTROL_NOT_FOUND:
2041 res = "TLDAP_CONTROL_NOT_FOUND";
2043 case TLDAP_NO_RESULTS_RETURNED:
2044 res = "TLDAP_NO_RESULTS_RETURNED";
2046 case TLDAP_MORE_RESULTS_TO_RETURN:
2047 res = "TLDAP_MORE_RESULTS_TO_RETURN";
2049 case TLDAP_CLIENT_LOOP:
2050 res = "TLDAP_CLIENT_LOOP";
2052 case TLDAP_REFERRAL_LIMIT_EXCEEDED:
2053 res = "TLDAP_REFERRAL_LIMIT_EXCEEDED";
2056 res = talloc_asprintf(talloc_tos(), "Unknown LDAP Error (%d)",
2061 res = "Unknown LDAP Error";