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 static 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_context
{
54 struct tevent_queue
*outgoing
;
55 struct tevent_req
**pending
;
57 /* For the sync wrappers we need something like get_last_error... */
60 char *res_diagnosticmessage
;
64 void (*log_fn
)(void *context
, enum tldap_debug_level level
,
65 const char *fmt
, va_list ap
);
69 struct tldap_message
{
70 struct asn1_data
*data
;
77 struct tldap_attribute
*attribs
;
80 void tldap_set_debug(struct tldap_context
*ld
,
81 void (*log_fn
)(void *log_private
,
82 enum tldap_debug_level level
,
84 va_list ap
) PRINTF_ATTRIBUTE(3,0),
88 ld
->log_private
= log_private
;
91 static void tldap_debug(struct tldap_context
*ld
,
92 enum tldap_debug_level level
,
99 if (ld
->log_fn
== NULL
) {
103 ld
->log_fn(ld
->log_private
, level
, fmt
, ap
);
107 static int tldap_next_msgid(struct tldap_context
*ld
)
111 result
= ld
->msgid
++;
112 if (ld
->msgid
== 2147483647) {
118 struct tldap_context
*tldap_context_create(TALLOC_CTX
*mem_ctx
, int fd
)
120 struct tldap_context
*ctx
;
122 ctx
= talloc_zero(mem_ctx
, struct tldap_context
);
129 ctx
->outgoing
= tevent_queue_create(ctx
, "tldap_outgoing");
130 if (ctx
->outgoing
== NULL
) {
137 struct read_ldap_state
{
142 static ssize_t
read_ldap_more(uint8_t *buf
, size_t buflen
, void *private_data
)
144 struct read_ldap_state
*state
= talloc_get_type_abort(
145 private_data
, struct read_ldap_state
);
150 /* We've been here, we're done */
155 * From ldap.h: LDAP_TAG_MESSAGE is 0x30
157 if (buf
[0] != 0x30) {
162 if ((len
& 0x80) == 0) {
167 lensize
= (len
& 0x7f);
171 /* Please get us the full length */
174 if (buflen
> 2 + lensize
) {
178 if (buflen
!= 2 + lensize
) {
182 for (i
=0; i
<lensize
; i
++) {
183 len
= (len
<< 8) | buf
[2+i
];
188 static void read_ldap_done(struct tevent_req
*subreq
);
190 static struct tevent_req
*read_ldap_send(TALLOC_CTX
*mem_ctx
,
191 struct tevent_context
*ev
,
194 struct tevent_req
*req
, *subreq
;
195 struct read_ldap_state
*state
;
197 req
= tevent_req_create(mem_ctx
, &state
, struct read_ldap_state
);
203 subreq
= read_packet_send(state
, ev
, fd
, 2, read_ldap_more
, state
);
204 if (tevent_req_nomem(subreq
, req
)) {
205 return tevent_req_post(req
, ev
);
207 tevent_req_set_callback(subreq
, read_ldap_done
, req
);
211 static void read_ldap_done(struct tevent_req
*subreq
)
213 struct tevent_req
*req
= tevent_req_callback_data(
214 subreq
, struct tevent_req
);
215 struct read_ldap_state
*state
= tevent_req_data(
216 req
, struct read_ldap_state
);
220 nread
= read_packet_recv(subreq
, state
, &state
->buf
, &err
);
223 tevent_req_error(req
, err
);
226 tevent_req_done(req
);
229 static ssize_t
read_ldap_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
230 uint8_t **pbuf
, int *perrno
)
232 struct read_ldap_state
*state
= tevent_req_data(
233 req
, struct read_ldap_state
);
235 if (tevent_req_is_unix_error(req
, perrno
)) {
238 *pbuf
= talloc_move(mem_ctx
, &state
->buf
);
239 return talloc_get_size(*pbuf
);
242 static bool asn1_blob(const struct asn1_data
*asn1
, DATA_BLOB
*blob
)
244 if (asn1
->has_error
) {
247 if (asn1
->nesting
!= NULL
) {
250 blob
->data
= asn1
->data
;
251 blob
->length
= asn1
->length
;
255 static void asn1_load_nocopy(struct asn1_data
*data
, uint8_t *buf
, size_t len
)
262 struct tldap_msg_state
{
263 struct tldap_context
*ld
;
264 struct tevent_context
*ev
;
268 struct asn1_data
*data
;
272 static void tldap_msg_sent(struct tevent_req
*subreq
);
273 static void tldap_msg_received(struct tevent_req
*subreq
);
275 static struct tevent_req
*tldap_msg_send(TALLOC_CTX
*mem_ctx
,
276 struct tevent_context
*ev
,
277 struct tldap_context
*ld
,
278 int id
, struct asn1_data
*data
)
280 struct tevent_req
*req
, *subreq
;
281 struct tldap_msg_state
*state
;
284 tldap_debug(ld
, TLDAP_DEBUG_TRACE
, "tldap_msg_send: sending msg %d\n",
287 req
= tevent_req_create(mem_ctx
, &state
, struct tldap_msg_state
);
297 if (!asn1_blob(data
, &blob
)) {
298 tevent_req_error(req
, TLDAP_ENCODING_ERROR
);
299 return tevent_req_post(req
, ev
);
302 state
->iov
.iov_base
= blob
.data
;
303 state
->iov
.iov_len
= blob
.length
;
305 subreq
= writev_send(state
, ev
, ld
->outgoing
, ld
->fd
, false,
307 if (tevent_req_nomem(subreq
, req
)) {
308 return tevent_req_post(req
, ev
);
310 tevent_req_set_callback(subreq
, tldap_msg_sent
, req
);
314 static void tldap_msg_unset_pending(struct tevent_req
*req
)
316 struct tldap_msg_state
*state
= tevent_req_data(
317 req
, struct tldap_msg_state
);
318 struct tldap_context
*ld
= state
->ld
;
319 int num_pending
= talloc_array_length(ld
->pending
);
322 if (num_pending
== 1) {
323 TALLOC_FREE(ld
->pending
);
327 for (i
=0; i
<num_pending
; i
++) {
328 if (req
== ld
->pending
[i
]) {
332 if (i
== num_pending
) {
334 * Something's seriously broken. Just returning here is the
335 * right thing nevertheless, the point of this routine is to
336 * remove ourselves from cli->pending.
342 * Remove ourselves from the cli->pending array
344 if (num_pending
> 1) {
345 ld
->pending
[i
] = ld
->pending
[num_pending
-1];
349 * No NULL check here, we're shrinking by sizeof(void *), and
350 * talloc_realloc just adjusts the size for this.
352 ld
->pending
= talloc_realloc(NULL
, ld
->pending
, struct tevent_req
*,
357 static int tldap_msg_destructor(struct tevent_req
*req
)
359 tldap_msg_unset_pending(req
);
363 static bool tldap_msg_set_pending(struct tevent_req
*req
)
365 struct tldap_msg_state
*state
= tevent_req_data(
366 req
, struct tldap_msg_state
);
367 struct tldap_context
*ld
;
368 struct tevent_req
**pending
;
370 struct tevent_req
*subreq
;
373 num_pending
= talloc_array_length(ld
->pending
);
375 pending
= talloc_realloc(ld
, ld
->pending
, struct tevent_req
*,
377 if (pending
== NULL
) {
380 pending
[num_pending
] = req
;
381 ld
->pending
= pending
;
382 talloc_set_destructor(req
, tldap_msg_destructor
);
384 if (num_pending
> 0) {
389 * We're the first ones, add the read_ldap request that waits for the
390 * answer from the server
392 subreq
= read_ldap_send(ld
->pending
, state
->ev
, ld
->fd
);
393 if (subreq
== NULL
) {
394 tldap_msg_unset_pending(req
);
397 tevent_req_set_callback(subreq
, tldap_msg_received
, ld
);
401 static void tldap_msg_sent(struct tevent_req
*subreq
)
403 struct tevent_req
*req
= tevent_req_callback_data(
404 subreq
, struct tevent_req
);
408 nwritten
= writev_recv(subreq
, &err
);
410 if (nwritten
== -1) {
411 tevent_req_error(req
, TLDAP_SERVER_DOWN
);
415 if (!tldap_msg_set_pending(req
)) {
416 tevent_req_nomem(NULL
, req
);
421 static int tldap_msg_msgid(struct tevent_req
*req
)
423 struct tldap_msg_state
*state
= tevent_req_data(
424 req
, struct tldap_msg_state
);
429 static void tldap_msg_received(struct tevent_req
*subreq
)
431 struct tldap_context
*ld
= tevent_req_callback_data(
432 subreq
, struct tldap_context
);
433 struct tevent_req
*req
;
434 struct tldap_msg_state
*state
;
435 struct tevent_context
*ev
;
436 struct asn1_data
*data
;
445 received
= read_ldap_recv(subreq
, talloc_tos(), &inbuf
, &err
);
447 if (received
== -1) {
448 status
= TLDAP_SERVER_DOWN
;
452 data
= asn1_init(talloc_tos());
454 status
= TLDAP_NO_MEMORY
;
457 asn1_load_nocopy(data
, inbuf
, received
);
460 ok
&= asn1_start_tag(data
, ASN1_SEQUENCE(0));
461 ok
&= asn1_read_Integer(data
, &id
);
462 ok
&= asn1_peek_uint8(data
, &type
);
465 status
= TLDAP_PROTOCOL_ERROR
;
469 tldap_debug(ld
, TLDAP_DEBUG_TRACE
, "tldap_msg_received: got msg %d "
470 "type %d\n", id
, (int)type
);
472 num_pending
= talloc_array_length(ld
->pending
);
474 for (i
=0; i
<num_pending
; i
++) {
475 if (id
== tldap_msg_msgid(ld
->pending
[i
])) {
479 if (i
== num_pending
) {
480 /* Dump unexpected reply */
481 tldap_debug(ld
, TLDAP_DEBUG_WARNING
, "tldap_msg_received: "
482 "No request pending for msg %d\n", id
);
487 req
= ld
->pending
[i
];
488 state
= tevent_req_data(req
, struct tldap_msg_state
);
490 state
->inbuf
= talloc_move(state
, &inbuf
);
491 state
->data
= talloc_move(state
, &data
);
495 talloc_set_destructor(req
, NULL
);
496 tldap_msg_destructor(req
);
497 tevent_req_done(req
);
500 if (talloc_array_length(ld
->pending
) > 0) {
501 state
= tevent_req_data(ld
->pending
[0],
502 struct tldap_msg_state
);
503 subreq
= read_ldap_send(ld
->pending
, state
->ev
, ld
->fd
);
504 if (subreq
== NULL
) {
505 status
= TLDAP_NO_MEMORY
;
508 tevent_req_set_callback(subreq
, tldap_msg_received
, ld
);
513 while (talloc_array_length(ld
->pending
) > 0) {
514 req
= ld
->pending
[0];
515 talloc_set_destructor(req
, NULL
);
516 tldap_msg_destructor(req
);
517 tevent_req_error(req
, status
);
521 static int tldap_msg_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
522 struct tldap_message
**pmsg
)
524 struct tldap_msg_state
*state
= tevent_req_data(
525 req
, struct tldap_msg_state
);
526 struct tldap_message
*msg
;
530 if (tevent_req_is_ldap_error(req
, &err
)) {
534 if (!asn1_peek_uint8(state
->data
, &msgtype
)) {
535 return TLDAP_PROTOCOL_ERROR
;
539 return TLDAP_SUCCESS
;
542 msg
= talloc_zero(mem_ctx
, struct tldap_message
);
544 return TLDAP_NO_MEMORY
;
548 msg
->inbuf
= talloc_move(msg
, &state
->inbuf
);
549 msg
->data
= talloc_move(msg
, &state
->data
);
553 return TLDAP_SUCCESS
;
556 struct tldap_req_state
{
558 struct asn1_data
*out
;
559 struct tldap_message
*result
;
563 char *res_diagnosticmessage
;
567 static struct tevent_req
*tldap_req_create(TALLOC_CTX
*mem_ctx
,
568 struct tldap_context
*ld
,
569 struct tldap_req_state
**pstate
)
571 struct tevent_req
*req
;
572 struct tldap_req_state
*state
;
574 req
= tevent_req_create(mem_ctx
, &state
, struct tldap_req_state
);
579 state
->out
= asn1_init(state
);
580 if (state
->out
== NULL
) {
584 state
->result
= NULL
;
585 state
->id
= tldap_next_msgid(ld
);
587 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
588 asn1_write_Integer(state
->out
, state
->id
);
594 static void tldap_save_errors(struct tldap_context
*ctx
,
595 struct tevent_req
*req
)
597 struct tldap_req_state
*state
= tevent_req_data(
598 req
, struct tldap_req_state
);
600 TALLOC_FREE(ctx
->res_matcheddn
);
601 TALLOC_FREE(ctx
->res_diagnosticmessage
);
602 TALLOC_FREE(ctx
->res_referral
);
604 ctx
->lderr
= state
->lderr
;
605 ctx
->res_matcheddn
= talloc_move(ctx
, &state
->res_matcheddn
);
606 ctx
->res_diagnosticmessage
= talloc_move(
607 ctx
, &state
->res_diagnosticmessage
);
608 ctx
->res_referral
= talloc_move(ctx
, &state
->res_referral
);
611 static char *blob2string_talloc(TALLOC_CTX
*mem_ctx
, DATA_BLOB blob
)
613 char *result
= talloc_array(mem_ctx
, char, blob
.length
+1);
614 memcpy(result
, blob
.data
, blob
.length
);
615 result
[blob
.length
] = '\0';
619 static bool asn1_read_OctetString_talloc(TALLOC_CTX
*mem_ctx
,
620 struct asn1_data
*data
,
624 if (!asn1_read_OctetString(data
, mem_ctx
, &string
))
626 *result
= blob2string_talloc(mem_ctx
, string
);
627 data_blob_free(&string
);
631 static bool tldap_decode_response(struct tldap_req_state
*state
)
633 struct asn1_data
*data
= state
->result
->data
;
636 ok
&= asn1_read_enumerated(data
, &state
->lderr
);
637 ok
&= asn1_read_OctetString_talloc(state
, data
, &state
->res_matcheddn
);
638 ok
&= asn1_read_OctetString_talloc(state
, data
,
639 &state
->res_diagnosticmessage
);
640 if (asn1_peek_tag(data
, ASN1_CONTEXT(3))) {
641 ok
&= asn1_start_tag(data
, ASN1_CONTEXT(3));
642 ok
&= asn1_read_OctetString_talloc(
643 state
, data
, &state
->res_referral
);
644 ok
&= asn1_end_tag(data
);
646 state
->res_referral
= NULL
;
652 static void tldap_sasl_bind_done(struct tevent_req
*subreq
);
654 struct tevent_req
*tldap_sasl_bind_send(TALLOC_CTX
*mem_ctx
,
655 struct tevent_context
*ev
,
656 struct tldap_context
*ld
,
658 const char *mechanism
,
660 struct tldap_control
**sctrls
,
661 struct tldap_control
**cctrls
)
663 struct tevent_req
*req
, *subreq
;
664 struct tldap_req_state
*state
;
666 req
= tldap_req_create(mem_ctx
, ld
, &state
);
675 asn1_push_tag(state
->out
, TLDAP_REQ_BIND
);
676 asn1_write_Integer(state
->out
, ld
->ld_version
);
677 asn1_write_OctetString(state
->out
, dn
, (dn
!= NULL
) ? strlen(dn
) : 0);
679 if (mechanism
== NULL
) {
680 asn1_push_tag(state
->out
, ASN1_CONTEXT_SIMPLE(0));
681 asn1_write(state
->out
, creds
->data
, creds
->length
);
682 asn1_pop_tag(state
->out
);
684 asn1_push_tag(state
->out
, ASN1_CONTEXT(3));
685 asn1_write_OctetString(state
->out
, mechanism
,
687 if ((creds
!= NULL
) && (creds
->data
!= NULL
)) {
688 asn1_write_OctetString(state
->out
, creds
->data
,
691 asn1_pop_tag(state
->out
);
694 if (!asn1_pop_tag(state
->out
)) {
695 tevent_req_error(req
, TLDAP_ENCODING_ERROR
);
696 return tevent_req_post(req
, ev
);
699 subreq
= tldap_msg_send(state
, ev
, ld
, state
->id
, state
->out
);
700 if (tevent_req_nomem(subreq
, req
)) {
701 return tevent_req_post(req
, ev
);
703 tevent_req_set_callback(subreq
, tldap_sasl_bind_done
, req
);
707 static void tldap_sasl_bind_done(struct tevent_req
*subreq
)
709 struct tevent_req
*req
= tevent_req_callback_data(
710 subreq
, struct tevent_req
);
711 struct tldap_req_state
*state
= tevent_req_data(
712 req
, struct tldap_req_state
);
715 err
= tldap_msg_recv(subreq
, state
, &state
->result
);
717 if (err
!= TLDAP_SUCCESS
) {
718 tevent_req_error(req
, err
);
721 if (state
->result
->type
!= TLDAP_RES_BIND
) {
722 tevent_req_error(req
, TLDAP_PROTOCOL_ERROR
);
725 if (!asn1_start_tag(state
->result
->data
, state
->result
->type
) ||
726 !tldap_decode_response(state
) ||
727 !asn1_end_tag(state
->result
->data
)) {
728 tevent_req_error(req
, TLDAP_DECODING_ERROR
);
732 * TODO: pull the reply blob
734 if (state
->lderr
!= TLDAP_SUCCESS
) {
735 tevent_req_error(req
, state
->lderr
);
738 tevent_req_done(req
);
741 int tldap_sasl_bind_recv(struct tevent_req
*req
)
745 if (tevent_req_is_ldap_error(req
, &err
)) {
748 return TLDAP_SUCCESS
;
751 int tldap_sasl_bind(struct tldap_context
*ld
,
753 const char *mechanism
,
755 struct tldap_control
**sctrls
,
756 struct tldap_control
**cctrls
)
758 TALLOC_CTX
*frame
= talloc_stackframe();
759 struct tevent_context
*ev
;
760 struct tevent_req
*req
;
763 ev
= event_context_init(frame
);
765 result
= TLDAP_NO_MEMORY
;
769 req
= tldap_sasl_bind_send(frame
, ev
, ld
, dn
, mechanism
, creds
,
772 result
= TLDAP_NO_MEMORY
;
776 if (!tevent_req_poll(req
, ev
)) {
777 result
= TLDAP_OPERATIONS_ERROR
;
781 result
= tldap_sasl_bind_recv(req
);
782 tldap_save_errors(ld
, req
);
788 struct tevent_req
*tldap_simple_bind_send(TALLOC_CTX
*mem_ctx
,
789 struct tevent_context
*ev
,
790 struct tldap_context
*ld
,
796 if (passwd
!= NULL
) {
797 cred
.data
= (uint8_t *)passwd
;
798 cred
.length
= strlen(passwd
);
800 cred
.data
= (uint8_t *)"";
803 return tldap_sasl_bind_send(mem_ctx
, ev
, ld
, dn
, NULL
, &cred
, NULL
,
807 int tldap_simple_bind_recv(struct tevent_req
*req
)
809 return tldap_sasl_bind_recv(req
);
812 int tldap_simple_bind(struct tldap_context
*ld
, const char *dn
,
817 if (passwd
!= NULL
) {
818 cred
.data
= (uint8_t *)passwd
;
819 cred
.length
= strlen(passwd
);
821 cred
.data
= (uint8_t *)"";
824 return tldap_sasl_bind(ld
, dn
, NULL
, &cred
, NULL
, NULL
);
827 /*****************************************************************************/
830 * This piece has a dependency on ldb, the ldb_parse_tree() function is used.
831 * In case we want to separate out tldap, we need to copy or rewrite it.
834 #include "lib/ldb/include/ldb.h"
835 #include "lib/ldb/include/ldb_errors.h"
837 static bool ldap_push_filter(struct asn1_data
*data
,
838 struct ldb_parse_tree
*tree
)
842 switch (tree
->operation
) {
846 ASN1_CONTEXT(tree
->operation
==LDB_OP_AND
?0:1));
847 for (i
=0; i
<tree
->u
.list
.num_elements
; i
++) {
848 if (!ldap_push_filter(data
,
849 tree
->u
.list
.elements
[i
])) {
857 asn1_push_tag(data
, ASN1_CONTEXT(2));
858 if (!ldap_push_filter(data
, tree
->u
.isnot
.child
)) {
864 case LDB_OP_EQUALITY
:
866 asn1_push_tag(data
, ASN1_CONTEXT(3));
867 asn1_write_OctetString(data
, tree
->u
.equality
.attr
,
868 strlen(tree
->u
.equality
.attr
));
869 asn1_write_OctetString(data
, tree
->u
.equality
.value
.data
,
870 tree
->u
.equality
.value
.length
);
874 case LDB_OP_SUBSTRING
:
876 SubstringFilter ::= SEQUENCE {
877 type AttributeDescription,
878 -- at least one must be present
879 substrings SEQUENCE OF CHOICE {
880 initial [0] LDAPString,
882 final [2] LDAPString } }
884 asn1_push_tag(data
, ASN1_CONTEXT(4));
885 asn1_write_OctetString(data
, tree
->u
.substring
.attr
,
886 strlen(tree
->u
.substring
.attr
));
887 asn1_push_tag(data
, ASN1_SEQUENCE(0));
889 if (!tree
->u
.substring
.start_with_wildcard
) {
890 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(0));
891 asn1_write_DATA_BLOB_LDAPString(
892 data
, tree
->u
.substring
.chunks
[i
]);
896 while (tree
->u
.substring
.chunks
[i
]) {
899 if ((!tree
->u
.substring
.chunks
[i
+ 1]) &&
900 (tree
->u
.substring
.end_with_wildcard
== 0)) {
905 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(ctx
));
906 asn1_write_DATA_BLOB_LDAPString(
907 data
, tree
->u
.substring
.chunks
[i
]);
916 /* greaterOrEqual test */
917 asn1_push_tag(data
, ASN1_CONTEXT(5));
918 asn1_write_OctetString(data
, tree
->u
.comparison
.attr
,
919 strlen(tree
->u
.comparison
.attr
));
920 asn1_write_OctetString(data
, tree
->u
.comparison
.value
.data
,
921 tree
->u
.comparison
.value
.length
);
926 /* lessOrEqual test */
927 asn1_push_tag(data
, ASN1_CONTEXT(6));
928 asn1_write_OctetString(data
, tree
->u
.comparison
.attr
,
929 strlen(tree
->u
.comparison
.attr
));
930 asn1_write_OctetString(data
, tree
->u
.comparison
.value
.data
,
931 tree
->u
.comparison
.value
.length
);
937 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(7));
938 asn1_write_LDAPString(data
, tree
->u
.present
.attr
);
940 return !data
->has_error
;
944 asn1_push_tag(data
, ASN1_CONTEXT(8));
945 asn1_write_OctetString(data
, tree
->u
.comparison
.attr
,
946 strlen(tree
->u
.comparison
.attr
));
947 asn1_write_OctetString(data
, tree
->u
.comparison
.value
.data
,
948 tree
->u
.comparison
.value
.length
);
952 case LDB_OP_EXTENDED
:
954 MatchingRuleAssertion ::= SEQUENCE {
955 matchingRule [1] MatchingRuleID OPTIONAL,
956 type [2] AttributeDescription OPTIONAL,
957 matchValue [3] AssertionValue,
958 dnAttributes [4] BOOLEAN DEFAULT FALSE
961 asn1_push_tag(data
, ASN1_CONTEXT(9));
962 if (tree
->u
.extended
.rule_id
) {
963 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(1));
964 asn1_write_LDAPString(data
, tree
->u
.extended
.rule_id
);
967 if (tree
->u
.extended
.attr
) {
968 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(2));
969 asn1_write_LDAPString(data
, tree
->u
.extended
.attr
);
972 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(3));
973 asn1_write_DATA_BLOB_LDAPString(data
, &tree
->u
.extended
.value
);
975 asn1_push_tag(data
, ASN1_CONTEXT_SIMPLE(4));
976 asn1_write_uint8(data
, tree
->u
.extended
.dnAttributes
);
984 return !data
->has_error
;
987 static bool tldap_push_filter(struct asn1_data
*data
, const char *filter
)
989 struct ldb_parse_tree
*tree
;
992 tree
= ldb_parse_tree(talloc_tos(), filter
);
996 ret
= ldap_push_filter(data
, tree
);
1001 /*****************************************************************************/
1003 static void tldap_search_done(struct tevent_req
*subreq
);
1005 struct tevent_req
*tldap_search_send(TALLOC_CTX
*mem_ctx
,
1006 struct tevent_context
*ev
,
1007 struct tldap_context
*ld
,
1008 const char *base
, int scope
,
1013 struct tldap_control
**sctrls
,
1014 struct tldap_control
**cctrls
,
1019 struct tevent_req
*req
, *subreq
;
1020 struct tldap_req_state
*state
;
1023 req
= tldap_req_create(mem_ctx
, ld
, &state
);
1028 asn1_push_tag(state
->out
, TLDAP_REQ_SEARCH
);
1029 asn1_write_OctetString(state
->out
, base
, strlen(base
));
1030 asn1_write_enumerated(state
->out
, scope
);
1031 asn1_write_enumerated(state
->out
, deref
);
1032 asn1_write_Integer(state
->out
, sizelimit
);
1033 asn1_write_Integer(state
->out
, timelimit
);
1034 asn1_write_BOOLEAN(state
->out
, attrsonly
);
1036 if (!tldap_push_filter(state
->out
, filter
)) {
1037 goto encoding_error
;
1040 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
1041 for (i
=0; i
<num_attrs
; i
++) {
1042 asn1_write_OctetString(state
->out
, attrs
[i
], strlen(attrs
[i
]));
1044 asn1_pop_tag(state
->out
);
1045 asn1_pop_tag(state
->out
);
1047 subreq
= tldap_msg_send(state
, ev
, ld
, state
->id
, state
->out
);
1048 if (tevent_req_nomem(subreq
, req
)) {
1049 return tevent_req_post(req
, ev
);
1051 tevent_req_set_callback(subreq
, tldap_search_done
, req
);
1055 tevent_req_error(req
, TLDAP_ENCODING_ERROR
);
1056 return tevent_req_post(req
, ev
);
1059 static void tldap_search_done(struct tevent_req
*subreq
)
1061 struct tevent_req
*req
= tevent_req_callback_data(
1062 subreq
, struct tevent_req
);
1063 struct tldap_req_state
*state
= tevent_req_data(
1064 req
, struct tldap_req_state
);
1067 err
= tldap_msg_recv(subreq
, state
, &state
->result
);
1068 if (err
!= TLDAP_SUCCESS
) {
1069 tevent_req_error(req
, err
);
1072 switch (state
->result
->type
) {
1073 case TLDAP_RES_SEARCH_ENTRY
:
1074 case TLDAP_RES_SEARCH_REFERENCE
:
1075 tevent_req_notify_callback(req
);
1076 if (!tldap_msg_set_pending(subreq
)) {
1077 tevent_req_nomem(NULL
, req
);
1081 case TLDAP_RES_SEARCH_RESULT
:
1082 TALLOC_FREE(subreq
);
1083 if (!asn1_start_tag(state
->result
->data
,
1084 state
->result
->type
) ||
1085 !tldap_decode_response(state
) ||
1086 !asn1_end_tag(state
->result
->data
)) {
1087 tevent_req_error(req
, TLDAP_DECODING_ERROR
);
1090 tevent_req_done(req
);
1093 tevent_req_error(req
, TLDAP_PROTOCOL_ERROR
);
1098 int tldap_search_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
1099 struct tldap_message
**pmsg
)
1101 struct tldap_req_state
*state
= tevent_req_data(
1102 req
, struct tldap_req_state
);
1105 if (!tevent_req_is_in_progress(req
)
1106 && tevent_req_is_ldap_error(req
, &err
)) {
1110 if (tevent_req_is_in_progress(req
)) {
1111 switch (state
->result
->type
) {
1112 case TLDAP_RES_SEARCH_ENTRY
:
1113 case TLDAP_RES_SEARCH_REFERENCE
:
1116 return TLDAP_OPERATIONS_ERROR
;
1120 *pmsg
= state
->result
;
1121 return TLDAP_SUCCESS
;
1124 struct tldap_sync_search_state
{
1125 TALLOC_CTX
*mem_ctx
;
1126 struct tldap_message
**entries
;
1127 struct tldap_message
**refs
;
1131 static void tldap_search_cb(struct tevent_req
*req
)
1133 struct tldap_sync_search_state
*state
=
1134 (struct tldap_sync_search_state
*)
1135 tevent_req_callback_data_void(req
);
1136 struct tldap_message
*msg
, **tmp
;
1137 int rc
, num_entries
, num_refs
;
1139 rc
= tldap_search_recv(req
, talloc_tos(), &msg
);
1140 if (rc
!= TLDAP_SUCCESS
) {
1145 switch (tldap_msg_type(msg
)) {
1146 case TLDAP_RES_SEARCH_ENTRY
:
1147 num_entries
= talloc_array_length(state
->entries
);
1148 tmp
= talloc_realloc(state
->mem_ctx
, state
->entries
,
1149 struct tldap_message
*, num_entries
+ 1);
1151 state
->rc
= TLDAP_NO_MEMORY
;
1154 state
->entries
= tmp
;
1155 state
->entries
[num_entries
] = talloc_move(state
->entries
,
1158 case TLDAP_RES_SEARCH_REFERENCE
:
1159 num_refs
= talloc_array_length(state
->refs
);
1160 tmp
= talloc_realloc(state
->mem_ctx
, state
->refs
,
1161 struct tldap_message
*, num_refs
+ 1);
1163 state
->rc
= TLDAP_NO_MEMORY
;
1167 state
->refs
[num_refs
] = talloc_move(state
->refs
, &msg
);
1169 case TLDAP_RES_SEARCH_RESULT
:
1170 state
->rc
= TLDAP_SUCCESS
;
1173 state
->rc
= TLDAP_PROTOCOL_ERROR
;
1178 int tldap_search(struct tldap_context
*ld
,
1179 const char *base
, int scope
, const char *filter
,
1180 const char **attrs
, int num_attrs
, int attrsonly
,
1181 struct tldap_control
**sctrls
, struct tldap_control
**cctrls
,
1182 int timelimit
, int sizelimit
, int deref
,
1183 TALLOC_CTX
*mem_ctx
, struct tldap_message
***entries
,
1184 struct tldap_message
***refs
)
1186 TALLOC_CTX
*frame
= talloc_stackframe();
1187 struct tevent_context
*ev
;
1188 struct tevent_req
*req
;
1189 struct tldap_sync_search_state state
;
1192 state
.mem_ctx
= mem_ctx
;
1193 state
.rc
= TLDAP_SUCCESS
;
1195 ev
= event_context_init(frame
);
1197 state
.rc
= TLDAP_NO_MEMORY
;
1201 req
= tldap_search_send(frame
, ev
, ld
, base
, scope
, filter
,
1202 attrs
, num_attrs
, attrsonly
,
1203 sctrls
, cctrls
, timelimit
,
1206 state
.rc
= TLDAP_NO_MEMORY
;
1210 tevent_req_set_callback(req
, tldap_search_cb
, &state
);
1212 while (tevent_req_is_in_progress(req
)
1213 && (state
.rc
== TLDAP_SUCCESS
)) {
1214 if (tevent_loop_once(ev
) == -1) {
1215 return TLDAP_OPERATIONS_ERROR
;
1219 if (state
.rc
!= TLDAP_SUCCESS
) {
1223 if (entries
!= NULL
) {
1224 *entries
= state
.entries
;
1226 TALLOC_FREE(state
.entries
);
1231 TALLOC_FREE(state
.refs
);
1233 tldap_save_errors(ld
, req
);
1239 static bool tldap_parse_search_entry(struct tldap_message
*msg
)
1241 int num_attribs
= 0;
1243 asn1_start_tag(msg
->data
, msg
->type
);
1247 asn1_read_OctetString_talloc(msg
, msg
->data
, &msg
->dn
);
1248 if (msg
->dn
== NULL
) {
1253 * Attributes: We overallocate msg->attribs by one, so that while
1254 * looping over the attributes we can directly parse into the last
1255 * array element. Same for the values in the inner loop.
1258 msg
->attribs
= talloc_array(msg
, struct tldap_attribute
, 1);
1259 if (msg
->attribs
== NULL
) {
1263 asn1_start_tag(msg
->data
, ASN1_SEQUENCE(0));
1264 while (asn1_peek_tag(msg
->data
, ASN1_SEQUENCE(0))) {
1265 struct tldap_attribute
*attrib
;
1268 attrib
= &msg
->attribs
[num_attribs
];
1269 attrib
->values
= talloc_array(msg
->attribs
, DATA_BLOB
, 1);
1270 if (attrib
->values
== NULL
) {
1273 asn1_start_tag(msg
->data
, ASN1_SEQUENCE(0));
1274 asn1_read_OctetString_talloc(msg
->attribs
, msg
->data
,
1276 asn1_start_tag(msg
->data
, ASN1_SET
);
1278 while (asn1_peek_tag(msg
->data
, ASN1_OCTET_STRING
)) {
1279 asn1_read_OctetString(msg
->data
, msg
,
1280 &attrib
->values
[num_values
]);
1282 attrib
->values
= talloc_realloc(
1283 msg
->attribs
, attrib
->values
, DATA_BLOB
,
1285 if (attrib
->values
== NULL
) {
1290 attrib
->values
= talloc_realloc(msg
->attribs
, attrib
->values
,
1291 DATA_BLOB
, num_values
);
1292 attrib
->num_values
= num_values
;
1294 asn1_end_tag(msg
->data
); /* ASN1_SET */
1295 asn1_end_tag(msg
->data
); /* ASN1_SEQUENCE(0) */
1296 msg
->attribs
= talloc_realloc(
1297 msg
, msg
->attribs
, struct tldap_attribute
,
1299 if (msg
->attribs
== NULL
) {
1304 msg
->attribs
= talloc_realloc(
1305 msg
, msg
->attribs
, struct tldap_attribute
, num_attribs
);
1306 asn1_end_tag(msg
->data
);
1307 if (msg
->data
->has_error
) {
1313 bool tldap_entry_dn(struct tldap_message
*msg
, char **dn
)
1315 if ((msg
->dn
== NULL
) && (!tldap_parse_search_entry(msg
))) {
1322 bool tldap_entry_attributes(struct tldap_message
*msg
, int *num_attributes
,
1323 struct tldap_attribute
**attributes
)
1325 if ((msg
->dn
== NULL
) && (!tldap_parse_search_entry(msg
))) {
1328 *attributes
= msg
->attribs
;
1329 *num_attributes
= talloc_array_length(msg
->attribs
);
1333 static void tldap_simple_done(struct tevent_req
*subreq
, int type
)
1335 struct tevent_req
*req
= tevent_req_callback_data(
1336 subreq
, struct tevent_req
);
1337 struct tldap_req_state
*state
= tevent_req_data(
1338 req
, struct tldap_req_state
);
1341 err
= tldap_msg_recv(subreq
, state
, &state
->result
);
1342 TALLOC_FREE(subreq
);
1343 if (err
!= TLDAP_SUCCESS
) {
1344 tevent_req_error(req
, err
);
1347 if (state
->result
->type
!= type
) {
1348 tevent_req_error(req
, TLDAP_PROTOCOL_ERROR
);
1351 if (!asn1_start_tag(state
->result
->data
, state
->result
->type
) ||
1352 !tldap_decode_response(state
) ||
1353 !asn1_end_tag(state
->result
->data
)) {
1354 tevent_req_error(req
, TLDAP_DECODING_ERROR
);
1357 if (state
->lderr
!= TLDAP_SUCCESS
) {
1358 tevent_req_error(req
, state
->lderr
);
1361 tevent_req_done(req
);
1364 static int tldap_simple_recv(struct tevent_req
*req
)
1367 if (tevent_req_is_ldap_error(req
, &err
)) {
1370 return TLDAP_SUCCESS
;
1373 static void tldap_add_done(struct tevent_req
*subreq
);
1375 struct tevent_req
*tldap_add_send(TALLOC_CTX
*mem_ctx
,
1376 struct tevent_context
*ev
,
1377 struct tldap_context
*ld
,
1380 struct tldap_mod
*attributes
,
1381 struct tldap_control
**sctrls
,
1382 struct tldap_control
**cctrls
)
1384 struct tevent_req
*req
, *subreq
;
1385 struct tldap_req_state
*state
;
1388 req
= tldap_req_create(mem_ctx
, ld
, &state
);
1393 asn1_push_tag(state
->out
, TLDAP_REQ_ADD
);
1394 asn1_write_OctetString(state
->out
, dn
, strlen(dn
));
1395 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
1397 for (i
=0; i
<num_attributes
; i
++) {
1398 struct tldap_mod
*attrib
= &attributes
[i
];
1399 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
1400 asn1_write_OctetString(state
->out
, attrib
->attribute
,
1401 strlen(attrib
->attribute
));
1402 asn1_push_tag(state
->out
, ASN1_SET
);
1403 for (j
=0; j
<attrib
->num_values
; j
++) {
1404 asn1_write_OctetString(state
->out
,
1405 attrib
->values
[j
].data
,
1406 attrib
->values
[j
].length
);
1408 asn1_pop_tag(state
->out
);
1409 asn1_pop_tag(state
->out
);
1412 asn1_pop_tag(state
->out
);
1413 asn1_pop_tag(state
->out
);
1415 subreq
= tldap_msg_send(state
, ev
, ld
, state
->id
, state
->out
);
1416 if (tevent_req_nomem(subreq
, req
)) {
1417 return tevent_req_post(req
, ev
);
1419 tevent_req_set_callback(subreq
, tldap_add_done
, req
);
1424 static void tldap_add_done(struct tevent_req
*subreq
)
1426 return tldap_simple_done(subreq
, TLDAP_RES_ADD
);
1429 int tldap_add_recv(struct tevent_req
*req
)
1431 return tldap_simple_recv(req
);
1434 int tldap_add(struct tldap_context
*ld
, const char *dn
,
1435 int num_attributes
, struct tldap_mod
*attributes
,
1436 struct tldap_control
**sctrls
, struct tldap_control
**cctrls
)
1438 TALLOC_CTX
*frame
= talloc_stackframe();
1439 struct tevent_context
*ev
;
1440 struct tevent_req
*req
;
1443 ev
= event_context_init(frame
);
1445 result
= TLDAP_NO_MEMORY
;
1449 req
= tldap_add_send(frame
, ev
, ld
, dn
, num_attributes
, attributes
,
1452 result
= TLDAP_NO_MEMORY
;
1456 if (!tevent_req_poll(req
, ev
)) {
1457 result
= TLDAP_OPERATIONS_ERROR
;
1461 result
= tldap_add_recv(req
);
1462 tldap_save_errors(ld
, req
);
1468 static void tldap_modify_done(struct tevent_req
*subreq
);
1470 struct tevent_req
*tldap_modify_send(TALLOC_CTX
*mem_ctx
,
1471 struct tevent_context
*ev
,
1472 struct tldap_context
*ld
,
1474 int num_mods
, struct tldap_mod
*mods
,
1475 struct tldap_control
**sctrls
,
1476 struct tldap_control
**cctrls
)
1478 struct tevent_req
*req
, *subreq
;
1479 struct tldap_req_state
*state
;
1482 req
= tldap_req_create(mem_ctx
, ld
, &state
);
1487 asn1_push_tag(state
->out
, TLDAP_REQ_MODIFY
);
1488 asn1_write_OctetString(state
->out
, dn
, strlen(dn
));
1489 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
1491 for (i
=0; i
<num_mods
; i
++) {
1492 struct tldap_mod
*mod
= &mods
[i
];
1493 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
1494 asn1_write_enumerated(state
->out
, mod
->mod_op
),
1495 asn1_push_tag(state
->out
, ASN1_SEQUENCE(0));
1496 asn1_write_OctetString(state
->out
, mod
->attribute
,
1497 strlen(mod
->attribute
));
1498 asn1_push_tag(state
->out
, ASN1_SET
);
1499 for (j
=0; j
<mod
->num_values
; j
++) {
1500 asn1_write_OctetString(state
->out
,
1501 mod
->values
[j
].data
,
1502 mod
->values
[j
].length
);
1504 asn1_pop_tag(state
->out
);
1505 asn1_pop_tag(state
->out
);
1506 asn1_pop_tag(state
->out
);
1509 asn1_pop_tag(state
->out
);
1510 asn1_pop_tag(state
->out
);
1512 subreq
= tldap_msg_send(state
, ev
, ld
, state
->id
, state
->out
);
1513 if (tevent_req_nomem(subreq
, req
)) {
1514 return tevent_req_post(req
, ev
);
1516 tevent_req_set_callback(subreq
, tldap_modify_done
, req
);
1521 static void tldap_modify_done(struct tevent_req
*subreq
)
1523 return tldap_simple_done(subreq
, TLDAP_RES_MODIFY
);
1526 int tldap_modify_recv(struct tevent_req
*req
)
1528 return tldap_simple_recv(req
);
1531 int tldap_modify(struct tldap_context
*ld
, const char *dn
,
1532 int num_mods
, struct tldap_mod
*mods
,
1533 struct tldap_control
**sctrls
, struct tldap_control
**cctrls
)
1535 TALLOC_CTX
*frame
= talloc_stackframe();
1536 struct tevent_context
*ev
;
1537 struct tevent_req
*req
;
1540 ev
= event_context_init(frame
);
1542 result
= TLDAP_NO_MEMORY
;
1546 req
= tldap_modify_send(frame
, ev
, ld
, dn
, num_mods
, mods
,
1549 result
= TLDAP_NO_MEMORY
;
1553 if (!tevent_req_poll(req
, ev
)) {
1554 result
= TLDAP_OPERATIONS_ERROR
;
1558 result
= tldap_modify_recv(req
);
1559 tldap_save_errors(ld
, req
);
1565 static void tldap_delete_done(struct tevent_req
*subreq
);
1567 struct tevent_req
*tldap_delete_send(TALLOC_CTX
*mem_ctx
,
1568 struct tevent_context
*ev
,
1569 struct tldap_context
*ld
,
1571 struct tldap_control
**sctrls
,
1572 struct tldap_control
**cctrls
)
1574 struct tevent_req
*req
, *subreq
;
1575 struct tldap_req_state
*state
;
1577 req
= tldap_req_create(mem_ctx
, ld
, &state
);
1582 asn1_push_tag(state
->out
, TLDAP_REQ_DELETE
);
1583 asn1_write(state
->out
, dn
, strlen(dn
));
1584 asn1_pop_tag(state
->out
);
1586 subreq
= tldap_msg_send(state
, ev
, ld
, state
->id
, state
->out
);
1587 if (tevent_req_nomem(subreq
, req
)) {
1588 return tevent_req_post(req
, ev
);
1590 tevent_req_set_callback(subreq
, tldap_delete_done
, req
);
1595 static void tldap_delete_done(struct tevent_req
*subreq
)
1597 return tldap_simple_done(subreq
, TLDAP_RES_DELETE
);
1600 int tldap_delete_recv(struct tevent_req
*req
)
1602 return tldap_simple_recv(req
);
1605 int tldap_delete(struct tldap_context
*ld
, const char *dn
,
1606 struct tldap_control
**sctrls
, struct tldap_control
**cctrls
)
1608 TALLOC_CTX
*frame
= talloc_stackframe();
1609 struct tevent_context
*ev
;
1610 struct tevent_req
*req
;
1613 ev
= event_context_init(frame
);
1615 result
= TLDAP_NO_MEMORY
;
1619 req
= tldap_delete_send(frame
, ev
, ld
, dn
, sctrls
, cctrls
);
1621 result
= TLDAP_NO_MEMORY
;
1625 if (!tevent_req_poll(req
, ev
)) {
1626 result
= TLDAP_OPERATIONS_ERROR
;
1630 result
= tldap_delete_recv(req
);
1631 tldap_save_errors(ld
, req
);
1637 int tldap_msg_id(const struct tldap_message
*msg
)
1642 int tldap_msg_type(const struct tldap_message
*msg
)
1647 const char *tldap_req_matcheddn(struct tevent_req
*req
)
1649 struct tldap_req_state
*state
= tevent_req_data(
1650 req
, struct tldap_req_state
);
1651 return state
->res_matcheddn
;
1654 const char *tldap_req_diagnosticmessage(struct tevent_req
*req
)
1656 struct tldap_req_state
*state
= tevent_req_data(
1657 req
, struct tldap_req_state
);
1658 return state
->res_diagnosticmessage
;
1661 const char *tldap_req_referral(struct tevent_req
*req
)
1663 struct tldap_req_state
*state
= tevent_req_data(
1664 req
, struct tldap_req_state
);
1665 return state
->res_referral
;
1668 const char *tldap_ctx_matcheddn(struct tldap_context
*ctx
)
1670 return ctx
->res_matcheddn
;
1673 const char *tldap_ctx_diagnosticmessage(struct tldap_context
*ctx
)
1675 return ctx
->res_diagnosticmessage
;
1678 const char *tldap_ctx_referral(struct tldap_context
*ctx
)
1680 return ctx
->res_referral
;
1683 const char *tldap_err2string(int rc
)
1685 const char *res
= NULL
;
1688 * This would normally be a table, but the error codes are not fully
1689 * sequential. Let the compiler figure out the optimum implementation
1695 res
= "TLDAP_SUCCESS";
1697 case TLDAP_OPERATIONS_ERROR
:
1698 res
= "TLDAP_OPERATIONS_ERROR";
1700 case TLDAP_PROTOCOL_ERROR
:
1701 res
= "TLDAP_PROTOCOL_ERROR";
1703 case TLDAP_TIMELIMIT_EXCEEDED
:
1704 res
= "TLDAP_TIMELIMIT_EXCEEDED";
1706 case TLDAP_SIZELIMIT_EXCEEDED
:
1707 res
= "TLDAP_SIZELIMIT_EXCEEDED";
1709 case TLDAP_COMPARE_FALSE
:
1710 res
= "TLDAP_COMPARE_FALSE";
1712 case TLDAP_COMPARE_TRUE
:
1713 res
= "TLDAP_COMPARE_TRUE";
1715 case TLDAP_STRONG_AUTH_NOT_SUPPORTED
:
1716 res
= "TLDAP_STRONG_AUTH_NOT_SUPPORTED";
1718 case TLDAP_STRONG_AUTH_REQUIRED
:
1719 res
= "TLDAP_STRONG_AUTH_REQUIRED";
1721 case TLDAP_REFERRAL
:
1722 res
= "TLDAP_REFERRAL";
1724 case TLDAP_ADMINLIMIT_EXCEEDED
:
1725 res
= "TLDAP_ADMINLIMIT_EXCEEDED";
1727 case TLDAP_UNAVAILABLE_CRITICAL_EXTENSION
:
1728 res
= "TLDAP_UNAVAILABLE_CRITICAL_EXTENSION";
1730 case TLDAP_CONFIDENTIALITY_REQUIRED
:
1731 res
= "TLDAP_CONFIDENTIALITY_REQUIRED";
1733 case TLDAP_SASL_BIND_IN_PROGRESS
:
1734 res
= "TLDAP_SASL_BIND_IN_PROGRESS";
1736 case TLDAP_NO_SUCH_ATTRIBUTE
:
1737 res
= "TLDAP_NO_SUCH_ATTRIBUTE";
1739 case TLDAP_UNDEFINED_TYPE
:
1740 res
= "TLDAP_UNDEFINED_TYPE";
1742 case TLDAP_INAPPROPRIATE_MATCHING
:
1743 res
= "TLDAP_INAPPROPRIATE_MATCHING";
1745 case TLDAP_CONSTRAINT_VIOLATION
:
1746 res
= "TLDAP_CONSTRAINT_VIOLATION";
1748 case TLDAP_TYPE_OR_VALUE_EXISTS
:
1749 res
= "TLDAP_TYPE_OR_VALUE_EXISTS";
1751 case TLDAP_INVALID_SYNTAX
:
1752 res
= "TLDAP_INVALID_SYNTAX";
1754 case TLDAP_NO_SUCH_OBJECT
:
1755 res
= "TLDAP_NO_SUCH_OBJECT";
1757 case TLDAP_ALIAS_PROBLEM
:
1758 res
= "TLDAP_ALIAS_PROBLEM";
1760 case TLDAP_INVALID_DN_SYNTAX
:
1761 res
= "TLDAP_INVALID_DN_SYNTAX";
1764 res
= "TLDAP_IS_LEAF";
1766 case TLDAP_ALIAS_DEREF_PROBLEM
:
1767 res
= "TLDAP_ALIAS_DEREF_PROBLEM";
1769 case TLDAP_INAPPROPRIATE_AUTH
:
1770 res
= "TLDAP_INAPPROPRIATE_AUTH";
1772 case TLDAP_INVALID_CREDENTIALS
:
1773 res
= "TLDAP_INVALID_CREDENTIALS";
1775 case TLDAP_INSUFFICIENT_ACCESS
:
1776 res
= "TLDAP_INSUFFICIENT_ACCESS";
1781 case TLDAP_UNAVAILABLE
:
1782 res
= "TLDAP_UNAVAILABLE";
1784 case TLDAP_UNWILLING_TO_PERFORM
:
1785 res
= "TLDAP_UNWILLING_TO_PERFORM";
1787 case TLDAP_LOOP_DETECT
:
1788 res
= "TLDAP_LOOP_DETECT";
1790 case TLDAP_NAMING_VIOLATION
:
1791 res
= "TLDAP_NAMING_VIOLATION";
1793 case TLDAP_OBJECT_CLASS_VIOLATION
:
1794 res
= "TLDAP_OBJECT_CLASS_VIOLATION";
1796 case TLDAP_NOT_ALLOWED_ON_NONLEAF
:
1797 res
= "TLDAP_NOT_ALLOWED_ON_NONLEAF";
1799 case TLDAP_NOT_ALLOWED_ON_RDN
:
1800 res
= "TLDAP_NOT_ALLOWED_ON_RDN";
1802 case TLDAP_ALREADY_EXISTS
:
1803 res
= "TLDAP_ALREADY_EXISTS";
1805 case TLDAP_NO_OBJECT_CLASS_MODS
:
1806 res
= "TLDAP_NO_OBJECT_CLASS_MODS";
1808 case TLDAP_RESULTS_TOO_LARGE
:
1809 res
= "TLDAP_RESULTS_TOO_LARGE";
1811 case TLDAP_AFFECTS_MULTIPLE_DSAS
:
1812 res
= "TLDAP_AFFECTS_MULTIPLE_DSAS";
1815 res
= "TLDAP_OTHER";
1817 case TLDAP_SERVER_DOWN
:
1818 res
= "TLDAP_SERVER_DOWN";
1820 case TLDAP_LOCAL_ERROR
:
1821 res
= "TLDAP_LOCAL_ERROR";
1823 case TLDAP_ENCODING_ERROR
:
1824 res
= "TLDAP_ENCODING_ERROR";
1826 case TLDAP_DECODING_ERROR
:
1827 res
= "TLDAP_DECODING_ERROR";
1830 res
= "TLDAP_TIMEOUT";
1832 case TLDAP_AUTH_UNKNOWN
:
1833 res
= "TLDAP_AUTH_UNKNOWN";
1835 case TLDAP_FILTER_ERROR
:
1836 res
= "TLDAP_FILTER_ERROR";
1838 case TLDAP_USER_CANCELLED
:
1839 res
= "TLDAP_USER_CANCELLED";
1841 case TLDAP_PARAM_ERROR
:
1842 res
= "TLDAP_PARAM_ERROR";
1844 case TLDAP_NO_MEMORY
:
1845 res
= "TLDAP_NO_MEMORY";
1847 case TLDAP_CONNECT_ERROR
:
1848 res
= "TLDAP_CONNECT_ERROR";
1850 case TLDAP_NOT_SUPPORTED
:
1851 res
= "TLDAP_NOT_SUPPORTED";
1853 case TLDAP_CONTROL_NOT_FOUND
:
1854 res
= "TLDAP_CONTROL_NOT_FOUND";
1856 case TLDAP_NO_RESULTS_RETURNED
:
1857 res
= "TLDAP_NO_RESULTS_RETURNED";
1859 case TLDAP_MORE_RESULTS_TO_RETURN
:
1860 res
= "TLDAP_MORE_RESULTS_TO_RETURN";
1862 case TLDAP_CLIENT_LOOP
:
1863 res
= "TLDAP_CLIENT_LOOP";
1865 case TLDAP_REFERRAL_LIMIT_EXCEEDED
:
1866 res
= "TLDAP_REFERRAL_LIMIT_EXCEEDED";
1869 res
= talloc_asprintf(talloc_tos(), "Unknown LDAP Error (%d)",
1874 res
= "Unknown LDAP Error";