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 {
57 struct tstream_context *conn;
59 struct tevent_queue *outgoing;
60 struct tevent_req **pending;
62 /* For the sync wrappers we need something like get_last_error... */
63 struct tldap_message *last_msg;
66 void (*log_fn)(void *context, enum tldap_debug_level level,
67 const char *fmt, va_list ap);
70 struct tldap_ctx_attribute *ctx_attrs;
73 struct tldap_message {
74 struct asn1_data *data;
81 struct tldap_attribute *attribs;
83 /* Error data sent by the server */
86 char *res_diagnosticmessage;
88 struct tldap_control *res_sctrls;
90 /* Controls sent by the server */
91 struct tldap_control *ctrls;
94 void tldap_set_debug(struct tldap_context *ld,
95 void (*log_fn)(void *log_private,
96 enum tldap_debug_level level,
98 va_list ap) PRINTF_ATTRIBUTE(3,0),
102 ld->log_private = log_private;
105 static void tldap_debug(struct tldap_context *ld,
106 enum tldap_debug_level level,
107 const char *fmt, ...)
113 if (ld->log_fn == NULL) {
117 ld->log_fn(ld->log_private, level, fmt, ap);
121 static int tldap_next_msgid(struct tldap_context *ld)
125 result = ld->msgid++;
126 if (ld->msgid == 2147483647) {
132 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd)
134 struct tldap_context *ctx;
137 ctx = talloc_zero(mem_ctx, struct tldap_context);
141 ret = tstream_bsd_existing_socket(ctx, fd, &ctx->conn);
148 ctx->outgoing = tevent_queue_create(ctx, "tldap_outgoing");
149 if (ctx->outgoing == NULL) {
156 static struct tldap_ctx_attribute *tldap_context_findattr(
157 struct tldap_context *ld, const char *name)
161 num_attrs = talloc_array_length(ld->ctx_attrs);
163 for (i=0; i<num_attrs; i++) {
164 if (strcmp(ld->ctx_attrs[i].name, name) == 0) {
165 return &ld->ctx_attrs[i];
171 bool tldap_context_setattr(struct tldap_context *ld,
172 const char *name, const void *_pptr)
174 struct tldap_ctx_attribute *tmp, *attr;
177 void **pptr = (void **)_pptr;
179 attr = tldap_context_findattr(ld, name);
182 * We don't actually delete attrs, we don't expect tons of
183 * attributes being shuffled around.
185 TALLOC_FREE(attr->ptr);
187 attr->ptr = talloc_move(ld->ctx_attrs, pptr);
193 tmpname = talloc_strdup(ld, name);
194 if (tmpname == NULL) {
198 num_attrs = talloc_array_length(ld->ctx_attrs);
200 tmp = talloc_realloc(ld, ld->ctx_attrs, struct tldap_ctx_attribute,
203 TALLOC_FREE(tmpname);
206 tmp[num_attrs].name = talloc_move(tmp, &tmpname);
208 tmp[num_attrs].ptr = talloc_move(tmp, pptr);
210 tmp[num_attrs].ptr = NULL;
217 void *tldap_context_getattr(struct tldap_context *ld, const char *name)
219 struct tldap_ctx_attribute *attr = tldap_context_findattr(ld, name);
227 struct read_ldap_state {
232 static ssize_t read_ldap_more(uint8_t *buf, size_t buflen, void *private_data)
234 struct read_ldap_state *state = talloc_get_type_abort(
235 private_data, struct read_ldap_state);
240 /* We've been here, we're done */
245 * From ldap.h: LDAP_TAG_MESSAGE is 0x30
247 if (buf[0] != 0x30) {
252 if ((len & 0x80) == 0) {
257 lensize = (len & 0x7f);
261 /* Please get us the full length */
264 if (buflen > 2 + lensize) {
268 if (buflen != 2 + lensize) {
272 for (i=0; i<lensize; i++) {
273 len = (len << 8) | buf[2+i];
278 static void read_ldap_done(struct tevent_req *subreq);
280 static struct tevent_req *read_ldap_send(TALLOC_CTX *mem_ctx,
281 struct tevent_context *ev,
282 struct tstream_context *conn)
284 struct tevent_req *req, *subreq;
285 struct read_ldap_state *state;
287 req = tevent_req_create(mem_ctx, &state, struct read_ldap_state);
293 subreq = tstream_read_packet_send(state, ev, conn, 2, read_ldap_more,
295 if (tevent_req_nomem(subreq, req)) {
296 return tevent_req_post(req, ev);
298 tevent_req_set_callback(subreq, read_ldap_done, req);
302 static void read_ldap_done(struct tevent_req *subreq)
304 struct tevent_req *req = tevent_req_callback_data(
305 subreq, struct tevent_req);
306 struct read_ldap_state *state = tevent_req_data(
307 req, struct read_ldap_state);
311 nread = tstream_read_packet_recv(subreq, state, &state->buf, &err);
314 tevent_req_error(req, err);
317 tevent_req_done(req);
320 static ssize_t read_ldap_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
321 uint8_t **pbuf, int *perrno)
323 struct read_ldap_state *state = tevent_req_data(
324 req, struct read_ldap_state);
326 if (tevent_req_is_unix_error(req, perrno)) {
329 *pbuf = talloc_move(mem_ctx, &state->buf);
330 return talloc_get_size(*pbuf);
333 struct tldap_msg_state {
334 struct tldap_context *ld;
335 struct tevent_context *ev;
339 struct asn1_data *data;
343 static void tldap_push_controls(struct asn1_data *data,
344 struct tldap_control *sctrls,
349 if ((sctrls == NULL) || (num_sctrls == 0)) {
353 asn1_push_tag(data, ASN1_CONTEXT(0));
355 for (i=0; i<num_sctrls; i++) {
356 struct tldap_control *c = &sctrls[i];
357 asn1_push_tag(data, ASN1_SEQUENCE(0));
358 asn1_write_OctetString(data, c->oid, strlen(c->oid));
360 asn1_write_BOOLEAN(data, true);
362 if (c->value.data != NULL) {
363 asn1_write_OctetString(data, c->value.data,
366 asn1_pop_tag(data); /* ASN1_SEQUENCE(0) */
369 asn1_pop_tag(data); /* ASN1_CONTEXT(0) */
372 static void tldap_msg_sent(struct tevent_req *subreq);
373 static void tldap_msg_received(struct tevent_req *subreq);
375 static struct tevent_req *tldap_msg_send(TALLOC_CTX *mem_ctx,
376 struct tevent_context *ev,
377 struct tldap_context *ld,
378 int id, struct asn1_data *data,
379 struct tldap_control *sctrls,
382 struct tevent_req *req, *subreq;
383 struct tldap_msg_state *state;
386 tldap_debug(ld, TLDAP_DEBUG_TRACE, "tldap_msg_send: sending msg %d\n",
389 req = tevent_req_create(mem_ctx, &state, struct tldap_msg_state);
397 tldap_push_controls(data, sctrls, num_sctrls);
401 if (!asn1_blob(data, &blob)) {
402 tevent_req_error(req, TLDAP_ENCODING_ERROR);
403 return tevent_req_post(req, ev);
406 state->iov.iov_base = blob.data;
407 state->iov.iov_len = blob.length;
409 subreq = tstream_writev_queue_send(state, ev, ld->conn, ld->outgoing,
411 if (tevent_req_nomem(subreq, req)) {
412 return tevent_req_post(req, ev);
414 tevent_req_set_callback(subreq, tldap_msg_sent, req);
418 static void tldap_msg_unset_pending(struct tevent_req *req)
420 struct tldap_msg_state *state = tevent_req_data(
421 req, struct tldap_msg_state);
422 struct tldap_context *ld = state->ld;
423 int num_pending = talloc_array_length(ld->pending);
426 if (num_pending == 1) {
427 TALLOC_FREE(ld->pending);
431 for (i=0; i<num_pending; i++) {
432 if (req == ld->pending[i]) {
436 if (i == num_pending) {
438 * Something's seriously broken. Just returning here is the
439 * right thing nevertheless, the point of this routine is to
440 * remove ourselves from cli->pending.
446 * Remove ourselves from the cli->pending array
448 if (num_pending > 1) {
449 ld->pending[i] = ld->pending[num_pending-1];
453 * No NULL check here, we're shrinking by sizeof(void *), and
454 * talloc_realloc just adjusts the size for this.
456 ld->pending = talloc_realloc(NULL, ld->pending, struct tevent_req *,
461 static int tldap_msg_destructor(struct tevent_req *req)
463 tldap_msg_unset_pending(req);
467 static bool tldap_msg_set_pending(struct tevent_req *req)
469 struct tldap_msg_state *state = tevent_req_data(
470 req, struct tldap_msg_state);
471 struct tldap_context *ld;
472 struct tevent_req **pending;
474 struct tevent_req *subreq;
477 num_pending = talloc_array_length(ld->pending);
479 pending = talloc_realloc(ld, ld->pending, struct tevent_req *,
481 if (pending == NULL) {
484 pending[num_pending] = req;
485 ld->pending = pending;
486 talloc_set_destructor(req, tldap_msg_destructor);
488 if (num_pending > 0) {
493 * We're the first ones, add the read_ldap request that waits for the
494 * answer from the server
496 subreq = read_ldap_send(ld->pending, state->ev, ld->conn);
497 if (subreq == NULL) {
498 tldap_msg_unset_pending(req);
501 tevent_req_set_callback(subreq, tldap_msg_received, ld);
505 static void tldap_msg_sent(struct tevent_req *subreq)
507 struct tevent_req *req = tevent_req_callback_data(
508 subreq, struct tevent_req);
512 nwritten = tstream_writev_queue_recv(subreq, &err);
514 if (nwritten == -1) {
515 tevent_req_error(req, TLDAP_SERVER_DOWN);
519 if (!tldap_msg_set_pending(req)) {
520 tevent_req_nomem(NULL, req);
525 static int tldap_msg_msgid(struct tevent_req *req)
527 struct tldap_msg_state *state = tevent_req_data(
528 req, struct tldap_msg_state);
533 static void tldap_msg_received(struct tevent_req *subreq)
535 struct tldap_context *ld = tevent_req_callback_data(
536 subreq, struct tldap_context);
537 struct tevent_req *req;
538 struct tldap_msg_state *state;
539 struct tevent_context *ev;
540 struct asn1_data *data;
549 received = read_ldap_recv(subreq, talloc_tos(), &inbuf, &err);
551 if (received == -1) {
552 status = TLDAP_SERVER_DOWN;
556 data = asn1_init(talloc_tos());
558 status = TLDAP_NO_MEMORY;
561 asn1_load_nocopy(data, inbuf, received);
564 ok &= asn1_start_tag(data, ASN1_SEQUENCE(0));
565 ok &= asn1_read_Integer(data, &id);
566 ok &= asn1_peek_uint8(data, &type);
569 status = TLDAP_PROTOCOL_ERROR;
573 tldap_debug(ld, TLDAP_DEBUG_TRACE, "tldap_msg_received: got msg %d "
574 "type %d\n", id, (int)type);
576 num_pending = talloc_array_length(ld->pending);
578 for (i=0; i<num_pending; i++) {
579 if (id == tldap_msg_msgid(ld->pending[i])) {
583 if (i == num_pending) {
584 /* Dump unexpected reply */
585 tldap_debug(ld, TLDAP_DEBUG_WARNING, "tldap_msg_received: "
586 "No request pending for msg %d\n", id);
591 req = ld->pending[i];
592 state = tevent_req_data(req, struct tldap_msg_state);
594 state->inbuf = talloc_move(state, &inbuf);
595 state->data = talloc_move(state, &data);
599 talloc_set_destructor(req, NULL);
600 tldap_msg_unset_pending(req);
601 num_pending = talloc_array_length(ld->pending);
603 tevent_req_done(req);
606 if (num_pending == 0) {
609 if (talloc_array_length(ld->pending) > num_pending) {
611 * The callback functions called from tevent_req_done() above
612 * have put something on the pending queue. We don't have to
613 * trigger the read_ldap_send(), tldap_msg_set_pending() has
614 * done it for us already.
619 state = tevent_req_data(ld->pending[0], struct tldap_msg_state);
620 subreq = read_ldap_send(ld->pending, state->ev, ld->conn);
621 if (subreq == NULL) {
622 status = TLDAP_NO_MEMORY;
625 tevent_req_set_callback(subreq, tldap_msg_received, ld);
629 while (talloc_array_length(ld->pending) > 0) {
630 req = ld->pending[0];
631 talloc_set_destructor(req, NULL);
632 tldap_msg_destructor(req);
633 tevent_req_error(req, status);
637 static int tldap_msg_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
638 struct tldap_message **pmsg)
640 struct tldap_msg_state *state = tevent_req_data(
641 req, struct tldap_msg_state);
642 struct tldap_message *msg;
646 if (tevent_req_is_ldap_error(req, &err)) {
650 if (!asn1_peek_uint8(state->data, &msgtype)) {
651 return TLDAP_PROTOCOL_ERROR;
655 return TLDAP_SUCCESS;
658 msg = talloc_zero(mem_ctx, struct tldap_message);
660 return TLDAP_NO_MEMORY;
664 msg->inbuf = talloc_move(msg, &state->inbuf);
665 msg->data = talloc_move(msg, &state->data);
669 return TLDAP_SUCCESS;
672 struct tldap_req_state {
674 struct asn1_data *out;
675 struct tldap_message *result;
678 static struct tevent_req *tldap_req_create(TALLOC_CTX *mem_ctx,
679 struct tldap_context *ld,
680 struct tldap_req_state **pstate)
682 struct tevent_req *req;
683 struct tldap_req_state *state;
685 req = tevent_req_create(mem_ctx, &state, struct tldap_req_state);
690 state->out = asn1_init(state);
691 if (state->out == NULL) {
695 state->result = NULL;
696 state->id = tldap_next_msgid(ld);
698 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
699 asn1_write_Integer(state->out, state->id);
705 static void tldap_save_msg(struct tldap_context *ld, struct tevent_req *req)
707 struct tldap_req_state *state = tevent_req_data(
708 req, struct tldap_req_state);
710 TALLOC_FREE(ld->last_msg);
711 ld->last_msg = talloc_move(ld, &state->result);
714 static char *blob2string_talloc(TALLOC_CTX *mem_ctx, DATA_BLOB blob)
716 char *result = talloc_array(mem_ctx, char, blob.length+1);
717 memcpy(result, blob.data, blob.length);
718 result[blob.length] = '\0';
722 static bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx,
723 struct asn1_data *data,
727 if (!asn1_read_OctetString(data, mem_ctx, &string))
729 *result = blob2string_talloc(mem_ctx, string);
730 data_blob_free(&string);
734 static bool tldap_decode_controls(struct tldap_req_state *state);
736 static bool tldap_decode_response(struct tldap_req_state *state)
738 struct asn1_data *data = state->result->data;
739 struct tldap_message *msg = state->result;
742 ok &= asn1_read_enumerated(data, &msg->lderr);
743 ok &= asn1_read_OctetString_talloc(msg, data, &msg->res_matcheddn);
744 ok &= asn1_read_OctetString_talloc(msg, data,
745 &msg->res_diagnosticmessage);
746 if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
747 ok &= asn1_start_tag(data, ASN1_CONTEXT(3));
748 ok &= asn1_read_OctetString_talloc(msg, data,
750 ok &= asn1_end_tag(data);
752 msg->res_referral = NULL;
758 static void tldap_sasl_bind_done(struct tevent_req *subreq);
760 struct tevent_req *tldap_sasl_bind_send(TALLOC_CTX *mem_ctx,
761 struct tevent_context *ev,
762 struct tldap_context *ld,
764 const char *mechanism,
766 struct tldap_control *sctrls,
768 struct tldap_control *cctrls,
771 struct tevent_req *req, *subreq;
772 struct tldap_req_state *state;
774 req = tldap_req_create(mem_ctx, ld, &state);
783 asn1_push_tag(state->out, TLDAP_REQ_BIND);
784 asn1_write_Integer(state->out, ld->ld_version);
785 asn1_write_OctetString(state->out, dn, (dn != NULL) ? strlen(dn) : 0);
787 if (mechanism == NULL) {
788 asn1_push_tag(state->out, ASN1_CONTEXT_SIMPLE(0));
789 asn1_write(state->out, creds->data, creds->length);
790 asn1_pop_tag(state->out);
792 asn1_push_tag(state->out, ASN1_CONTEXT(3));
793 asn1_write_OctetString(state->out, mechanism,
795 if ((creds != NULL) && (creds->data != NULL)) {
796 asn1_write_OctetString(state->out, creds->data,
799 asn1_pop_tag(state->out);
802 if (!asn1_pop_tag(state->out)) {
803 tevent_req_error(req, TLDAP_ENCODING_ERROR);
804 return tevent_req_post(req, ev);
807 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
809 if (tevent_req_nomem(subreq, req)) {
810 return tevent_req_post(req, ev);
812 tevent_req_set_callback(subreq, tldap_sasl_bind_done, req);
816 static void tldap_sasl_bind_done(struct tevent_req *subreq)
818 struct tevent_req *req = tevent_req_callback_data(
819 subreq, struct tevent_req);
820 struct tldap_req_state *state = tevent_req_data(
821 req, struct tldap_req_state);
824 err = tldap_msg_recv(subreq, state, &state->result);
826 if (err != TLDAP_SUCCESS) {
827 tevent_req_error(req, err);
830 if (state->result->type != TLDAP_RES_BIND) {
831 tevent_req_error(req, TLDAP_PROTOCOL_ERROR);
834 if (!asn1_start_tag(state->result->data, state->result->type) ||
835 !tldap_decode_response(state) ||
836 !asn1_end_tag(state->result->data)) {
837 tevent_req_error(req, TLDAP_DECODING_ERROR);
841 * TODO: pull the reply blob
843 if (state->result->lderr != TLDAP_SUCCESS) {
844 tevent_req_error(req, state->result->lderr);
847 tevent_req_done(req);
850 int tldap_sasl_bind_recv(struct tevent_req *req)
854 if (tevent_req_is_ldap_error(req, &err)) {
857 return TLDAP_SUCCESS;
860 int tldap_sasl_bind(struct tldap_context *ld,
862 const char *mechanism,
864 struct tldap_control *sctrls,
866 struct tldap_control *cctrls,
869 TALLOC_CTX *frame = talloc_stackframe();
870 struct tevent_context *ev;
871 struct tevent_req *req;
874 ev = event_context_init(frame);
876 result = TLDAP_NO_MEMORY;
880 req = tldap_sasl_bind_send(frame, ev, ld, dn, mechanism, creds,
881 sctrls, num_sctrls, cctrls, num_cctrls);
883 result = TLDAP_NO_MEMORY;
887 if (!tevent_req_poll(req, ev)) {
888 result = TLDAP_OPERATIONS_ERROR;
892 result = tldap_sasl_bind_recv(req);
893 tldap_save_msg(ld, req);
899 struct tevent_req *tldap_simple_bind_send(TALLOC_CTX *mem_ctx,
900 struct tevent_context *ev,
901 struct tldap_context *ld,
907 if (passwd != NULL) {
908 cred.data = (uint8_t *)passwd;
909 cred.length = strlen(passwd);
911 cred.data = (uint8_t *)"";
914 return tldap_sasl_bind_send(mem_ctx, ev, ld, dn, NULL, &cred, NULL, 0,
918 int tldap_simple_bind_recv(struct tevent_req *req)
920 return tldap_sasl_bind_recv(req);
923 int tldap_simple_bind(struct tldap_context *ld, const char *dn,
928 if (passwd != NULL) {
929 cred.data = (uint8_t *)passwd;
930 cred.length = strlen(passwd);
932 cred.data = (uint8_t *)"";
935 return tldap_sasl_bind(ld, dn, NULL, &cred, NULL, 0, NULL, 0);
938 /*****************************************************************************/
941 * This piece has a dependency on ldb, the ldb_parse_tree() function is used.
942 * In case we want to separate out tldap, we need to copy or rewrite it.
945 #include "lib/ldb/include/ldb.h"
946 #include "lib/ldb/include/ldb_errors.h"
948 static bool ldap_push_filter(struct asn1_data *data,
949 struct ldb_parse_tree *tree)
953 switch (tree->operation) {
957 ASN1_CONTEXT(tree->operation==LDB_OP_AND?0:1));
958 for (i=0; i<tree->u.list.num_elements; i++) {
959 if (!ldap_push_filter(data,
960 tree->u.list.elements[i])) {
968 asn1_push_tag(data, ASN1_CONTEXT(2));
969 if (!ldap_push_filter(data, tree->u.isnot.child)) {
975 case LDB_OP_EQUALITY:
977 asn1_push_tag(data, ASN1_CONTEXT(3));
978 asn1_write_OctetString(data, tree->u.equality.attr,
979 strlen(tree->u.equality.attr));
980 asn1_write_OctetString(data, tree->u.equality.value.data,
981 tree->u.equality.value.length);
985 case LDB_OP_SUBSTRING:
987 SubstringFilter ::= SEQUENCE {
988 type AttributeDescription,
989 -- at least one must be present
990 substrings SEQUENCE OF CHOICE {
991 initial [0] LDAPString,
993 final [2] LDAPString } }
995 asn1_push_tag(data, ASN1_CONTEXT(4));
996 asn1_write_OctetString(data, tree->u.substring.attr,
997 strlen(tree->u.substring.attr));
998 asn1_push_tag(data, ASN1_SEQUENCE(0));
1000 if (!tree->u.substring.start_with_wildcard) {
1001 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
1002 asn1_write_DATA_BLOB_LDAPString(
1003 data, tree->u.substring.chunks[i]);
1007 while (tree->u.substring.chunks[i]) {
1010 if ((!tree->u.substring.chunks[i + 1]) &&
1011 (tree->u.substring.end_with_wildcard == 0)) {
1016 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(ctx));
1017 asn1_write_DATA_BLOB_LDAPString(
1018 data, tree->u.substring.chunks[i]);
1026 case LDB_OP_GREATER:
1027 /* greaterOrEqual test */
1028 asn1_push_tag(data, ASN1_CONTEXT(5));
1029 asn1_write_OctetString(data, tree->u.comparison.attr,
1030 strlen(tree->u.comparison.attr));
1031 asn1_write_OctetString(data, tree->u.comparison.value.data,
1032 tree->u.comparison.value.length);
1037 /* lessOrEqual test */
1038 asn1_push_tag(data, ASN1_CONTEXT(6));
1039 asn1_write_OctetString(data, tree->u.comparison.attr,
1040 strlen(tree->u.comparison.attr));
1041 asn1_write_OctetString(data, tree->u.comparison.value.data,
1042 tree->u.comparison.value.length);
1046 case LDB_OP_PRESENT:
1048 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(7));
1049 asn1_write_LDAPString(data, tree->u.present.attr);
1051 return !data->has_error;
1055 asn1_push_tag(data, ASN1_CONTEXT(8));
1056 asn1_write_OctetString(data, tree->u.comparison.attr,
1057 strlen(tree->u.comparison.attr));
1058 asn1_write_OctetString(data, tree->u.comparison.value.data,
1059 tree->u.comparison.value.length);
1063 case LDB_OP_EXTENDED:
1065 MatchingRuleAssertion ::= SEQUENCE {
1066 matchingRule [1] MatchingRuleID OPTIONAL,
1067 type [2] AttributeDescription OPTIONAL,
1068 matchValue [3] AssertionValue,
1069 dnAttributes [4] BOOLEAN DEFAULT FALSE
1072 asn1_push_tag(data, ASN1_CONTEXT(9));
1073 if (tree->u.extended.rule_id) {
1074 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1));
1075 asn1_write_LDAPString(data, tree->u.extended.rule_id);
1078 if (tree->u.extended.attr) {
1079 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(2));
1080 asn1_write_LDAPString(data, tree->u.extended.attr);
1083 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(3));
1084 asn1_write_DATA_BLOB_LDAPString(data, &tree->u.extended.value);
1086 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(4));
1087 asn1_write_uint8(data, tree->u.extended.dnAttributes);
1095 return !data->has_error;
1098 static bool tldap_push_filter(struct asn1_data *data, const char *filter)
1100 struct ldb_parse_tree *tree;
1103 tree = ldb_parse_tree(talloc_tos(), filter);
1107 ret = ldap_push_filter(data, tree);
1112 /*****************************************************************************/
1114 static void tldap_search_done(struct tevent_req *subreq);
1116 struct tevent_req *tldap_search_send(TALLOC_CTX *mem_ctx,
1117 struct tevent_context *ev,
1118 struct tldap_context *ld,
1119 const char *base, int scope,
1124 struct tldap_control *sctrls,
1126 struct tldap_control *cctrls,
1132 struct tevent_req *req, *subreq;
1133 struct tldap_req_state *state;
1136 req = tldap_req_create(mem_ctx, ld, &state);
1141 asn1_push_tag(state->out, TLDAP_REQ_SEARCH);
1142 asn1_write_OctetString(state->out, base, strlen(base));
1143 asn1_write_enumerated(state->out, scope);
1144 asn1_write_enumerated(state->out, deref);
1145 asn1_write_Integer(state->out, sizelimit);
1146 asn1_write_Integer(state->out, timelimit);
1147 asn1_write_BOOLEAN(state->out, attrsonly);
1149 if (!tldap_push_filter(state->out, filter)) {
1150 goto encoding_error;
1153 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1154 for (i=0; i<num_attrs; i++) {
1155 asn1_write_OctetString(state->out, attrs[i], strlen(attrs[i]));
1157 asn1_pop_tag(state->out);
1158 asn1_pop_tag(state->out);
1160 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1161 sctrls, num_sctrls);
1162 if (tevent_req_nomem(subreq, req)) {
1163 return tevent_req_post(req, ev);
1165 tevent_req_set_callback(subreq, tldap_search_done, req);
1169 tevent_req_error(req, TLDAP_ENCODING_ERROR);
1170 return tevent_req_post(req, ev);
1173 static void tldap_search_done(struct tevent_req *subreq)
1175 struct tevent_req *req = tevent_req_callback_data(
1176 subreq, struct tevent_req);
1177 struct tldap_req_state *state = tevent_req_data(
1178 req, struct tldap_req_state);
1181 err = tldap_msg_recv(subreq, state, &state->result);
1182 if (err != TLDAP_SUCCESS) {
1183 tevent_req_error(req, err);
1186 switch (state->result->type) {
1187 case TLDAP_RES_SEARCH_ENTRY:
1188 case TLDAP_RES_SEARCH_REFERENCE:
1189 tevent_req_notify_callback(req);
1190 if (!tldap_msg_set_pending(subreq)) {
1191 tevent_req_nomem(NULL, req);
1195 case TLDAP_RES_SEARCH_RESULT:
1196 TALLOC_FREE(subreq);
1197 if (!asn1_start_tag(state->result->data,
1198 state->result->type) ||
1199 !tldap_decode_response(state) ||
1200 !asn1_end_tag(state->result->data) ||
1201 !tldap_decode_controls(state)) {
1202 tevent_req_error(req, TLDAP_DECODING_ERROR);
1205 tevent_req_done(req);
1208 tevent_req_error(req, TLDAP_PROTOCOL_ERROR);
1213 int tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
1214 struct tldap_message **pmsg)
1216 struct tldap_req_state *state = tevent_req_data(
1217 req, struct tldap_req_state);
1220 if (!tevent_req_is_in_progress(req)
1221 && tevent_req_is_ldap_error(req, &err)) {
1225 if (tevent_req_is_in_progress(req)) {
1226 switch (state->result->type) {
1227 case TLDAP_RES_SEARCH_ENTRY:
1228 case TLDAP_RES_SEARCH_REFERENCE:
1231 return TLDAP_OPERATIONS_ERROR;
1235 *pmsg = talloc_move(mem_ctx, &state->result);
1236 return TLDAP_SUCCESS;
1239 struct tldap_sync_search_state {
1240 TALLOC_CTX *mem_ctx;
1241 struct tldap_message **entries;
1242 struct tldap_message **refs;
1246 static void tldap_search_cb(struct tevent_req *req)
1248 struct tldap_sync_search_state *state =
1249 (struct tldap_sync_search_state *)
1250 tevent_req_callback_data_void(req);
1251 struct tldap_message *msg, **tmp;
1252 int rc, num_entries, num_refs;
1254 rc = tldap_search_recv(req, talloc_tos(), &msg);
1255 if (rc != TLDAP_SUCCESS) {
1260 switch (tldap_msg_type(msg)) {
1261 case TLDAP_RES_SEARCH_ENTRY:
1262 num_entries = talloc_array_length(state->entries);
1263 tmp = talloc_realloc(state->mem_ctx, state->entries,
1264 struct tldap_message *, num_entries + 1);
1266 state->rc = TLDAP_NO_MEMORY;
1269 state->entries = tmp;
1270 state->entries[num_entries] = talloc_move(state->entries,
1273 case TLDAP_RES_SEARCH_REFERENCE:
1274 num_refs = talloc_array_length(state->refs);
1275 tmp = talloc_realloc(state->mem_ctx, state->refs,
1276 struct tldap_message *, num_refs + 1);
1278 state->rc = TLDAP_NO_MEMORY;
1282 state->refs[num_refs] = talloc_move(state->refs, &msg);
1284 case TLDAP_RES_SEARCH_RESULT:
1285 state->rc = TLDAP_SUCCESS;
1288 state->rc = TLDAP_PROTOCOL_ERROR;
1293 int tldap_search(struct tldap_context *ld,
1294 const char *base, int scope, const char *filter,
1295 const char **attrs, int num_attrs, int attrsonly,
1296 struct tldap_control *sctrls, int num_sctrls,
1297 struct tldap_control *cctrls, int num_cctrls,
1298 int timelimit, int sizelimit, int deref,
1299 TALLOC_CTX *mem_ctx, struct tldap_message ***entries,
1300 struct tldap_message ***refs)
1302 TALLOC_CTX *frame = talloc_stackframe();
1303 struct tevent_context *ev;
1304 struct tevent_req *req;
1305 struct tldap_sync_search_state state;
1308 state.mem_ctx = mem_ctx;
1309 state.rc = TLDAP_SUCCESS;
1311 ev = event_context_init(frame);
1313 state.rc = TLDAP_NO_MEMORY;
1317 req = tldap_search_send(frame, ev, ld, base, scope, filter,
1318 attrs, num_attrs, attrsonly,
1319 sctrls, num_sctrls, cctrls, num_cctrls,
1320 timelimit, sizelimit, deref);
1322 state.rc = TLDAP_NO_MEMORY;
1326 tevent_req_set_callback(req, tldap_search_cb, &state);
1328 while (tevent_req_is_in_progress(req)
1329 && (state.rc == TLDAP_SUCCESS)) {
1330 if (tevent_loop_once(ev) == -1) {
1331 return TLDAP_OPERATIONS_ERROR;
1335 if (state.rc != TLDAP_SUCCESS) {
1339 if (entries != NULL) {
1340 *entries = state.entries;
1342 TALLOC_FREE(state.entries);
1347 TALLOC_FREE(state.refs);
1349 tldap_save_msg(ld, req);
1355 static bool tldap_parse_search_entry(struct tldap_message *msg)
1357 int num_attribs = 0;
1359 asn1_start_tag(msg->data, msg->type);
1363 asn1_read_OctetString_talloc(msg, msg->data, &msg->dn);
1364 if (msg->dn == NULL) {
1369 * Attributes: We overallocate msg->attribs by one, so that while
1370 * looping over the attributes we can directly parse into the last
1371 * array element. Same for the values in the inner loop.
1374 msg->attribs = talloc_array(msg, struct tldap_attribute, 1);
1375 if (msg->attribs == NULL) {
1379 asn1_start_tag(msg->data, ASN1_SEQUENCE(0));
1380 while (asn1_peek_tag(msg->data, ASN1_SEQUENCE(0))) {
1381 struct tldap_attribute *attrib;
1384 attrib = &msg->attribs[num_attribs];
1385 attrib->values = talloc_array(msg->attribs, DATA_BLOB, 1);
1386 if (attrib->values == NULL) {
1389 asn1_start_tag(msg->data, ASN1_SEQUENCE(0));
1390 asn1_read_OctetString_talloc(msg->attribs, msg->data,
1392 asn1_start_tag(msg->data, ASN1_SET);
1394 while (asn1_peek_tag(msg->data, ASN1_OCTET_STRING)) {
1395 asn1_read_OctetString(msg->data, msg,
1396 &attrib->values[num_values]);
1398 attrib->values = talloc_realloc(
1399 msg->attribs, attrib->values, DATA_BLOB,
1401 if (attrib->values == NULL) {
1406 attrib->values = talloc_realloc(msg->attribs, attrib->values,
1407 DATA_BLOB, num_values);
1408 attrib->num_values = num_values;
1410 asn1_end_tag(msg->data); /* ASN1_SET */
1411 asn1_end_tag(msg->data); /* ASN1_SEQUENCE(0) */
1412 msg->attribs = talloc_realloc(
1413 msg, msg->attribs, struct tldap_attribute,
1415 if (msg->attribs == NULL) {
1420 msg->attribs = talloc_realloc(
1421 msg, msg->attribs, struct tldap_attribute, num_attribs);
1422 asn1_end_tag(msg->data);
1423 if (msg->data->has_error) {
1429 bool tldap_entry_dn(struct tldap_message *msg, char **dn)
1431 if ((msg->dn == NULL) && (!tldap_parse_search_entry(msg))) {
1438 bool tldap_entry_attributes(struct tldap_message *msg, int *num_attributes,
1439 struct tldap_attribute **attributes)
1441 if ((msg->dn == NULL) && (!tldap_parse_search_entry(msg))) {
1444 *attributes = msg->attribs;
1445 *num_attributes = talloc_array_length(msg->attribs);
1449 static bool tldap_decode_controls(struct tldap_req_state *state)
1451 struct tldap_message *msg = state->result;
1452 struct asn1_data *data = msg->data;
1453 struct tldap_control *sctrls = NULL;
1454 int num_controls = 0;
1456 msg->res_sctrls = NULL;
1458 if (!asn1_peek_tag(data, ASN1_CONTEXT(0))) {
1462 asn1_start_tag(data, ASN1_CONTEXT(0));
1464 while (asn1_peek_tag(data, ASN1_SEQUENCE(0))) {
1465 struct tldap_control *c;
1468 sctrls = talloc_realloc(msg, sctrls, struct tldap_control,
1470 if (sctrls == NULL) {
1473 c = &sctrls[num_controls];
1475 asn1_start_tag(data, ASN1_SEQUENCE(0));
1476 asn1_read_OctetString_talloc(msg, data, &oid);
1477 if ((data->has_error) || (oid == NULL)) {
1481 if (asn1_peek_tag(data, ASN1_BOOLEAN)) {
1482 asn1_read_BOOLEAN(data, &c->critical);
1484 c->critical = false;
1486 c->value = data_blob_null;
1487 if (asn1_peek_tag(data, ASN1_OCTET_STRING) &&
1488 !asn1_read_OctetString(data, msg, &c->value)) {
1491 asn1_end_tag(data); /* ASN1_SEQUENCE(0) */
1496 asn1_end_tag(data); /* ASN1_CONTEXT(0) */
1498 if (data->has_error) {
1499 TALLOC_FREE(sctrls);
1502 msg->res_sctrls = sctrls;
1506 static void tldap_simple_done(struct tevent_req *subreq, int type)
1508 struct tevent_req *req = tevent_req_callback_data(
1509 subreq, struct tevent_req);
1510 struct tldap_req_state *state = tevent_req_data(
1511 req, struct tldap_req_state);
1514 err = tldap_msg_recv(subreq, state, &state->result);
1515 TALLOC_FREE(subreq);
1516 if (err != TLDAP_SUCCESS) {
1517 tevent_req_error(req, err);
1520 if (state->result->type != type) {
1521 tevent_req_error(req, TLDAP_PROTOCOL_ERROR);
1524 if (!asn1_start_tag(state->result->data, state->result->type) ||
1525 !tldap_decode_response(state) ||
1526 !asn1_end_tag(state->result->data) ||
1527 !tldap_decode_controls(state)) {
1528 tevent_req_error(req, TLDAP_DECODING_ERROR);
1531 if (state->result->lderr != TLDAP_SUCCESS) {
1532 tevent_req_error(req, state->result->lderr);
1535 tevent_req_done(req);
1538 static int tldap_simple_recv(struct tevent_req *req)
1541 if (tevent_req_is_ldap_error(req, &err)) {
1544 return TLDAP_SUCCESS;
1547 static void tldap_add_done(struct tevent_req *subreq);
1549 struct tevent_req *tldap_add_send(TALLOC_CTX *mem_ctx,
1550 struct tevent_context *ev,
1551 struct tldap_context *ld,
1553 struct tldap_mod *attributes,
1555 struct tldap_control *sctrls,
1557 struct tldap_control *cctrls,
1560 struct tevent_req *req, *subreq;
1561 struct tldap_req_state *state;
1564 req = tldap_req_create(mem_ctx, ld, &state);
1569 asn1_push_tag(state->out, TLDAP_REQ_ADD);
1570 asn1_write_OctetString(state->out, dn, strlen(dn));
1571 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1573 for (i=0; i<num_attributes; i++) {
1574 struct tldap_mod *attrib = &attributes[i];
1575 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1576 asn1_write_OctetString(state->out, attrib->attribute,
1577 strlen(attrib->attribute));
1578 asn1_push_tag(state->out, ASN1_SET);
1579 for (j=0; j<attrib->num_values; j++) {
1580 asn1_write_OctetString(state->out,
1581 attrib->values[j].data,
1582 attrib->values[j].length);
1584 asn1_pop_tag(state->out);
1585 asn1_pop_tag(state->out);
1588 asn1_pop_tag(state->out);
1589 asn1_pop_tag(state->out);
1591 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1592 sctrls, num_sctrls);
1593 if (tevent_req_nomem(subreq, req)) {
1594 return tevent_req_post(req, ev);
1596 tevent_req_set_callback(subreq, tldap_add_done, req);
1600 static void tldap_add_done(struct tevent_req *subreq)
1602 return tldap_simple_done(subreq, TLDAP_RES_ADD);
1605 int tldap_add_recv(struct tevent_req *req)
1607 return tldap_simple_recv(req);
1610 int tldap_add(struct tldap_context *ld, const char *dn,
1611 int num_attributes, struct tldap_mod *attributes,
1612 struct tldap_control *sctrls, int num_sctrls,
1613 struct tldap_control *cctrls, int num_cctrls)
1615 TALLOC_CTX *frame = talloc_stackframe();
1616 struct tevent_context *ev;
1617 struct tevent_req *req;
1620 ev = event_context_init(frame);
1622 result = TLDAP_NO_MEMORY;
1626 req = tldap_add_send(frame, ev, ld, dn, attributes, num_attributes,
1627 sctrls, num_sctrls, cctrls, num_cctrls);
1629 result = TLDAP_NO_MEMORY;
1633 if (!tevent_req_poll(req, ev)) {
1634 result = TLDAP_OPERATIONS_ERROR;
1638 result = tldap_add_recv(req);
1639 tldap_save_msg(ld, req);
1645 static void tldap_modify_done(struct tevent_req *subreq);
1647 struct tevent_req *tldap_modify_send(TALLOC_CTX *mem_ctx,
1648 struct tevent_context *ev,
1649 struct tldap_context *ld,
1651 int num_mods, struct tldap_mod *mods,
1652 struct tldap_control *sctrls,
1654 struct tldap_control *cctrls,
1657 struct tevent_req *req, *subreq;
1658 struct tldap_req_state *state;
1661 req = tldap_req_create(mem_ctx, ld, &state);
1666 asn1_push_tag(state->out, TLDAP_REQ_MODIFY);
1667 asn1_write_OctetString(state->out, dn, strlen(dn));
1668 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1670 for (i=0; i<num_mods; i++) {
1671 struct tldap_mod *mod = &mods[i];
1672 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1673 asn1_write_enumerated(state->out, mod->mod_op),
1674 asn1_push_tag(state->out, ASN1_SEQUENCE(0));
1675 asn1_write_OctetString(state->out, mod->attribute,
1676 strlen(mod->attribute));
1677 asn1_push_tag(state->out, ASN1_SET);
1678 for (j=0; j<mod->num_values; j++) {
1679 asn1_write_OctetString(state->out,
1680 mod->values[j].data,
1681 mod->values[j].length);
1683 asn1_pop_tag(state->out);
1684 asn1_pop_tag(state->out);
1685 asn1_pop_tag(state->out);
1688 asn1_pop_tag(state->out);
1689 asn1_pop_tag(state->out);
1691 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1692 sctrls, num_sctrls);
1693 if (tevent_req_nomem(subreq, req)) {
1694 return tevent_req_post(req, ev);
1696 tevent_req_set_callback(subreq, tldap_modify_done, req);
1700 static void tldap_modify_done(struct tevent_req *subreq)
1702 return tldap_simple_done(subreq, TLDAP_RES_MODIFY);
1705 int tldap_modify_recv(struct tevent_req *req)
1707 return tldap_simple_recv(req);
1710 int tldap_modify(struct tldap_context *ld, const char *dn,
1711 int num_mods, struct tldap_mod *mods,
1712 struct tldap_control *sctrls, int num_sctrls,
1713 struct tldap_control *cctrls, int num_cctrls)
1715 TALLOC_CTX *frame = talloc_stackframe();
1716 struct tevent_context *ev;
1717 struct tevent_req *req;
1720 ev = event_context_init(frame);
1722 result = TLDAP_NO_MEMORY;
1726 req = tldap_modify_send(frame, ev, ld, dn, num_mods, mods,
1727 sctrls, num_sctrls, cctrls, num_cctrls);
1729 result = TLDAP_NO_MEMORY;
1733 if (!tevent_req_poll(req, ev)) {
1734 result = TLDAP_OPERATIONS_ERROR;
1738 result = tldap_modify_recv(req);
1739 tldap_save_msg(ld, req);
1745 static void tldap_delete_done(struct tevent_req *subreq);
1747 struct tevent_req *tldap_delete_send(TALLOC_CTX *mem_ctx,
1748 struct tevent_context *ev,
1749 struct tldap_context *ld,
1751 struct tldap_control *sctrls,
1753 struct tldap_control *cctrls,
1756 struct tevent_req *req, *subreq;
1757 struct tldap_req_state *state;
1759 req = tldap_req_create(mem_ctx, ld, &state);
1764 asn1_push_tag(state->out, TLDAP_REQ_DELETE);
1765 asn1_write(state->out, dn, strlen(dn));
1766 asn1_pop_tag(state->out);
1768 subreq = tldap_msg_send(state, ev, ld, state->id, state->out,
1769 sctrls, num_sctrls);
1770 if (tevent_req_nomem(subreq, req)) {
1771 return tevent_req_post(req, ev);
1773 tevent_req_set_callback(subreq, tldap_delete_done, req);
1777 static void tldap_delete_done(struct tevent_req *subreq)
1779 return tldap_simple_done(subreq, TLDAP_RES_DELETE);
1782 int tldap_delete_recv(struct tevent_req *req)
1784 return tldap_simple_recv(req);
1787 int tldap_delete(struct tldap_context *ld, const char *dn,
1788 struct tldap_control *sctrls, int num_sctrls,
1789 struct tldap_control *cctrls, int num_cctrls)
1791 TALLOC_CTX *frame = talloc_stackframe();
1792 struct tevent_context *ev;
1793 struct tevent_req *req;
1796 ev = event_context_init(frame);
1798 result = TLDAP_NO_MEMORY;
1802 req = tldap_delete_send(frame, ev, ld, dn, sctrls, num_sctrls,
1803 cctrls, num_cctrls);
1805 result = TLDAP_NO_MEMORY;
1809 if (!tevent_req_poll(req, ev)) {
1810 result = TLDAP_OPERATIONS_ERROR;
1814 result = tldap_delete_recv(req);
1815 tldap_save_msg(ld, req);
1821 int tldap_msg_id(const struct tldap_message *msg)
1826 int tldap_msg_type(const struct tldap_message *msg)
1831 const char *tldap_msg_matcheddn(struct tldap_message *msg)
1836 return msg->res_matcheddn;
1839 const char *tldap_msg_diagnosticmessage(struct tldap_message *msg)
1844 return msg->res_diagnosticmessage;
1847 const char *tldap_msg_referral(struct tldap_message *msg)
1852 return msg->res_referral;
1855 void tldap_msg_sctrls(struct tldap_message *msg, int *num_sctrls,
1856 struct tldap_control **sctrls)
1862 *sctrls = msg->res_sctrls;
1863 *num_sctrls = talloc_array_length(msg->res_sctrls);
1866 struct tldap_message *tldap_ctx_lastmsg(struct tldap_context *ld)
1868 return ld->last_msg;
1871 const char *tldap_err2string(int rc)
1873 const char *res = NULL;
1876 * This would normally be a table, but the error codes are not fully
1877 * sequential. Let the compiler figure out the optimum implementation
1883 res = "TLDAP_SUCCESS";
1885 case TLDAP_OPERATIONS_ERROR:
1886 res = "TLDAP_OPERATIONS_ERROR";
1888 case TLDAP_PROTOCOL_ERROR:
1889 res = "TLDAP_PROTOCOL_ERROR";
1891 case TLDAP_TIMELIMIT_EXCEEDED:
1892 res = "TLDAP_TIMELIMIT_EXCEEDED";
1894 case TLDAP_SIZELIMIT_EXCEEDED:
1895 res = "TLDAP_SIZELIMIT_EXCEEDED";
1897 case TLDAP_COMPARE_FALSE:
1898 res = "TLDAP_COMPARE_FALSE";
1900 case TLDAP_COMPARE_TRUE:
1901 res = "TLDAP_COMPARE_TRUE";
1903 case TLDAP_STRONG_AUTH_NOT_SUPPORTED:
1904 res = "TLDAP_STRONG_AUTH_NOT_SUPPORTED";
1906 case TLDAP_STRONG_AUTH_REQUIRED:
1907 res = "TLDAP_STRONG_AUTH_REQUIRED";
1909 case TLDAP_REFERRAL:
1910 res = "TLDAP_REFERRAL";
1912 case TLDAP_ADMINLIMIT_EXCEEDED:
1913 res = "TLDAP_ADMINLIMIT_EXCEEDED";
1915 case TLDAP_UNAVAILABLE_CRITICAL_EXTENSION:
1916 res = "TLDAP_UNAVAILABLE_CRITICAL_EXTENSION";
1918 case TLDAP_CONFIDENTIALITY_REQUIRED:
1919 res = "TLDAP_CONFIDENTIALITY_REQUIRED";
1921 case TLDAP_SASL_BIND_IN_PROGRESS:
1922 res = "TLDAP_SASL_BIND_IN_PROGRESS";
1924 case TLDAP_NO_SUCH_ATTRIBUTE:
1925 res = "TLDAP_NO_SUCH_ATTRIBUTE";
1927 case TLDAP_UNDEFINED_TYPE:
1928 res = "TLDAP_UNDEFINED_TYPE";
1930 case TLDAP_INAPPROPRIATE_MATCHING:
1931 res = "TLDAP_INAPPROPRIATE_MATCHING";
1933 case TLDAP_CONSTRAINT_VIOLATION:
1934 res = "TLDAP_CONSTRAINT_VIOLATION";
1936 case TLDAP_TYPE_OR_VALUE_EXISTS:
1937 res = "TLDAP_TYPE_OR_VALUE_EXISTS";
1939 case TLDAP_INVALID_SYNTAX:
1940 res = "TLDAP_INVALID_SYNTAX";
1942 case TLDAP_NO_SUCH_OBJECT:
1943 res = "TLDAP_NO_SUCH_OBJECT";
1945 case TLDAP_ALIAS_PROBLEM:
1946 res = "TLDAP_ALIAS_PROBLEM";
1948 case TLDAP_INVALID_DN_SYNTAX:
1949 res = "TLDAP_INVALID_DN_SYNTAX";
1952 res = "TLDAP_IS_LEAF";
1954 case TLDAP_ALIAS_DEREF_PROBLEM:
1955 res = "TLDAP_ALIAS_DEREF_PROBLEM";
1957 case TLDAP_INAPPROPRIATE_AUTH:
1958 res = "TLDAP_INAPPROPRIATE_AUTH";
1960 case TLDAP_INVALID_CREDENTIALS:
1961 res = "TLDAP_INVALID_CREDENTIALS";
1963 case TLDAP_INSUFFICIENT_ACCESS:
1964 res = "TLDAP_INSUFFICIENT_ACCESS";
1969 case TLDAP_UNAVAILABLE:
1970 res = "TLDAP_UNAVAILABLE";
1972 case TLDAP_UNWILLING_TO_PERFORM:
1973 res = "TLDAP_UNWILLING_TO_PERFORM";
1975 case TLDAP_LOOP_DETECT:
1976 res = "TLDAP_LOOP_DETECT";
1978 case TLDAP_NAMING_VIOLATION:
1979 res = "TLDAP_NAMING_VIOLATION";
1981 case TLDAP_OBJECT_CLASS_VIOLATION:
1982 res = "TLDAP_OBJECT_CLASS_VIOLATION";
1984 case TLDAP_NOT_ALLOWED_ON_NONLEAF:
1985 res = "TLDAP_NOT_ALLOWED_ON_NONLEAF";
1987 case TLDAP_NOT_ALLOWED_ON_RDN:
1988 res = "TLDAP_NOT_ALLOWED_ON_RDN";
1990 case TLDAP_ALREADY_EXISTS:
1991 res = "TLDAP_ALREADY_EXISTS";
1993 case TLDAP_NO_OBJECT_CLASS_MODS:
1994 res = "TLDAP_NO_OBJECT_CLASS_MODS";
1996 case TLDAP_RESULTS_TOO_LARGE:
1997 res = "TLDAP_RESULTS_TOO_LARGE";
1999 case TLDAP_AFFECTS_MULTIPLE_DSAS:
2000 res = "TLDAP_AFFECTS_MULTIPLE_DSAS";
2003 res = "TLDAP_OTHER";
2005 case TLDAP_SERVER_DOWN:
2006 res = "TLDAP_SERVER_DOWN";
2008 case TLDAP_LOCAL_ERROR:
2009 res = "TLDAP_LOCAL_ERROR";
2011 case TLDAP_ENCODING_ERROR:
2012 res = "TLDAP_ENCODING_ERROR";
2014 case TLDAP_DECODING_ERROR:
2015 res = "TLDAP_DECODING_ERROR";
2018 res = "TLDAP_TIMEOUT";
2020 case TLDAP_AUTH_UNKNOWN:
2021 res = "TLDAP_AUTH_UNKNOWN";
2023 case TLDAP_FILTER_ERROR:
2024 res = "TLDAP_FILTER_ERROR";
2026 case TLDAP_USER_CANCELLED:
2027 res = "TLDAP_USER_CANCELLED";
2029 case TLDAP_PARAM_ERROR:
2030 res = "TLDAP_PARAM_ERROR";
2032 case TLDAP_NO_MEMORY:
2033 res = "TLDAP_NO_MEMORY";
2035 case TLDAP_CONNECT_ERROR:
2036 res = "TLDAP_CONNECT_ERROR";
2038 case TLDAP_NOT_SUPPORTED:
2039 res = "TLDAP_NOT_SUPPORTED";
2041 case TLDAP_CONTROL_NOT_FOUND:
2042 res = "TLDAP_CONTROL_NOT_FOUND";
2044 case TLDAP_NO_RESULTS_RETURNED:
2045 res = "TLDAP_NO_RESULTS_RETURNED";
2047 case TLDAP_MORE_RESULTS_TO_RETURN:
2048 res = "TLDAP_MORE_RESULTS_TO_RETURN";
2050 case TLDAP_CLIENT_LOOP:
2051 res = "TLDAP_CLIENT_LOOP";
2053 case TLDAP_REFERRAL_LIMIT_EXCEEDED:
2054 res = "TLDAP_REFERRAL_LIMIT_EXCEEDED";
2057 res = talloc_asprintf(talloc_tos(), "Unknown LDAP Error (%d)",
2062 res = "Unknown LDAP Error";