2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
7 Copyright (C) Stefan Metzmacher 2009
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 see RFC1798 for details of CLDAP
27 - carried over UDP on port 389
28 - request and response matched by message ID
29 - request consists of only a single searchRequest element
30 - response can be in one of two forms
31 - a single searchResponse, followed by a searchResult
32 - a single searchResult
37 #include "../lib/util/dlinklist.h"
38 #include "../libcli/ldap/ldap_message.h"
39 #include "../libcli/ldap/ldap_ndr.h"
40 #include "../libcli/cldap/cldap.h"
41 #include "../lib/tsocket/tsocket.h"
42 #include "../libcli/security/dom_sid.h"
43 #include "../librpc/gen_ndr/ndr_nbt.h"
44 #include "../lib/util/asn1.h"
45 #include "../lib/util/tevent_ntstatus.h"
50 context structure for operations on cldap packets
53 /* the low level socket */
54 struct tdgram_context
*sock
;
57 * Are we in connected mode, which means
58 * we get ICMP errors back instead of timing
59 * out requests. And we can only send requests
60 * to the connected peer.
65 * we allow sync requests only, if the caller
66 * did not pass an event context to cldap_socket_init()
70 struct tevent_context
*ctx
;
73 /* the queue for outgoing dgrams */
74 struct tevent_queue
*send_queue
;
76 /* do we have an async tsocket_recvfrom request pending */
77 struct tevent_req
*recv_subreq
;
80 /* a queue of pending search requests */
81 struct cldap_search_state
*list
;
83 /* mapping from message_id to pending request */
84 struct idr_context
*idr
;
87 /* what to do with incoming request packets */
89 void (*handler
)(struct cldap_socket
*,
91 struct cldap_incoming
*);
96 struct cldap_search_state
{
97 struct cldap_search_state
*prev
, *next
;
100 struct cldap_socket
*cldap
;
109 struct tsocket_address
*dest
;
114 struct cldap_incoming
*in
;
115 struct asn1_data
*asn1
;
118 struct tevent_req
*req
;
121 static int cldap_socket_destructor(struct cldap_socket
*c
)
123 while (c
->searches
.list
) {
124 struct cldap_search_state
*s
= c
->searches
.list
;
125 DLIST_REMOVE(c
->searches
.list
, s
);
126 ZERO_STRUCT(s
->caller
);
129 talloc_free(c
->recv_subreq
);
130 talloc_free(c
->send_queue
);
131 talloc_free(c
->sock
);
135 static void cldap_recvfrom_done(struct tevent_req
*subreq
);
137 static bool cldap_recvfrom_setup(struct cldap_socket
*c
)
139 if (c
->recv_subreq
) {
143 if (!c
->searches
.list
&& !c
->incoming
.handler
) {
147 c
->recv_subreq
= tdgram_recvfrom_send(c
, c
->event
.ctx
, c
->sock
);
148 if (!c
->recv_subreq
) {
151 tevent_req_set_callback(c
->recv_subreq
, cldap_recvfrom_done
, c
);
156 static void cldap_recvfrom_stop(struct cldap_socket
*c
)
158 if (!c
->recv_subreq
) {
162 if (c
->searches
.list
|| c
->incoming
.handler
) {
166 talloc_free(c
->recv_subreq
);
167 c
->recv_subreq
= NULL
;
170 static bool cldap_socket_recv_dgram(struct cldap_socket
*c
,
171 struct cldap_incoming
*in
);
173 static void cldap_recvfrom_done(struct tevent_req
*subreq
)
175 struct cldap_socket
*c
= tevent_req_callback_data(subreq
,
176 struct cldap_socket
);
177 struct cldap_incoming
*in
= NULL
;
181 c
->recv_subreq
= NULL
;
183 in
= talloc_zero(c
, struct cldap_incoming
);
188 ret
= tdgram_recvfrom_recv(subreq
,
198 if (ret
== -1 && in
->recv_errno
== 0) {
199 in
->recv_errno
= EIO
;
202 /* this function should free or steal 'in' */
203 setup_done
= cldap_socket_recv_dgram(c
, in
);
206 if (!setup_done
&& !cldap_recvfrom_setup(c
)) {
215 /*TODO: call a dead socket handler */
220 handle recv events on a cldap socket
222 static bool cldap_socket_recv_dgram(struct cldap_socket
*c
,
223 struct cldap_incoming
*in
)
226 struct asn1_data
*asn1
;
228 struct cldap_search_state
*search
;
231 if (in
->recv_errno
!= 0) {
235 blob
= data_blob_const(in
->buf
, in
->len
);
237 asn1
= asn1_init(in
);
242 if (!asn1_load(asn1
, blob
)) {
246 in
->ldap_msg
= talloc(in
, struct ldap_message
);
247 if (in
->ldap_msg
== NULL
) {
251 /* this initial decode is used to find the message id */
252 status
= ldap_decode(asn1
, NULL
, in
->ldap_msg
);
253 if (!NT_STATUS_IS_OK(status
)) {
257 /* find the pending request */
258 p
= idr_find(c
->searches
.idr
, in
->ldap_msg
->messageid
);
260 if (!c
->incoming
.handler
) {
264 /* this function should free or steal 'in' */
265 c
->incoming
.handler(c
, c
->incoming
.private_data
, in
);
269 search
= talloc_get_type(p
, struct cldap_search_state
);
270 search
->response
.in
= talloc_move(search
, &in
);
271 search
->response
.asn1
= asn1
;
272 search
->response
.asn1
->ofs
= 0;
274 DLIST_REMOVE(c
->searches
.list
, search
);
276 cldap_recvfrom_setup(c
);
278 tevent_req_done(search
->req
);
282 in
->recv_errno
= ENOMEM
;
284 status
= map_nt_error_from_unix(in
->recv_errno
);
287 /* in connected mode the first pending search gets the error */
289 /* otherwise we just ignore the error */
292 if (!c
->searches
.list
) {
295 cldap_recvfrom_setup(c
);
296 tevent_req_nterror(c
->searches
.list
->req
, status
);
304 initialise a cldap_sock
306 NTSTATUS
cldap_socket_init(TALLOC_CTX
*mem_ctx
,
307 struct tevent_context
*ev
,
308 const struct tsocket_address
*local_addr
,
309 const struct tsocket_address
*remote_addr
,
310 struct cldap_socket
**_cldap
)
312 struct cldap_socket
*c
= NULL
;
313 struct tsocket_address
*any
= NULL
;
316 const char *fam
= NULL
;
318 if (local_addr
== NULL
&& remote_addr
== NULL
) {
319 return NT_STATUS_INVALID_PARAMETER_MIX
;
326 is_ipv4
= tsocket_address_is_inet(remote_addr
, "ipv4");
327 is_ipv6
= tsocket_address_is_inet(remote_addr
, "ipv6");
331 } else if (is_ipv6
) {
334 return NT_STATUS_INVALID_ADDRESS
;
338 c
= talloc_zero(mem_ctx
, struct cldap_socket
);
344 ev
= tevent_context_init(c
);
348 c
->event
.allow_poll
= true;
354 * Here we know the address family of the remote address.
357 return NT_STATUS_INVALID_PARAMETER_MIX
;
360 ret
= tsocket_address_inet_from_strings(c
, fam
,
364 status
= map_nt_error_from_unix(errno
);
370 c
->searches
.idr
= idr_init(c
);
371 if (!c
->searches
.idr
) {
375 ret
= tdgram_inet_udp_socket(local_addr
, remote_addr
,
378 status
= map_nt_error_from_unix(errno
);
387 c
->send_queue
= tevent_queue_create(c
, "cldap_send_queue");
388 if (!c
->send_queue
) {
392 talloc_set_destructor(c
, cldap_socket_destructor
);
398 status
= NT_STATUS_NO_MEMORY
;
405 setup a handler for incoming requests
407 NTSTATUS
cldap_set_incoming_handler(struct cldap_socket
*c
,
408 void (*handler
)(struct cldap_socket
*,
410 struct cldap_incoming
*),
414 return NT_STATUS_PIPE_CONNECTED
;
417 /* if sync requests are allowed, we don't allow an incoming handler */
418 if (c
->event
.allow_poll
) {
419 return NT_STATUS_INVALID_PIPE_STATE
;
422 c
->incoming
.handler
= handler
;
423 c
->incoming
.private_data
= private_data
;
425 if (!cldap_recvfrom_setup(c
)) {
426 ZERO_STRUCT(c
->incoming
);
427 return NT_STATUS_NO_MEMORY
;
433 struct cldap_reply_state
{
434 struct tsocket_address
*dest
;
438 static void cldap_reply_state_destroy(struct tevent_req
*subreq
);
441 queue a cldap reply for send
443 NTSTATUS
cldap_reply_send(struct cldap_socket
*cldap
, struct cldap_reply
*io
)
445 struct cldap_reply_state
*state
= NULL
;
446 struct ldap_message
*msg
;
447 DATA_BLOB blob1
, blob2
;
449 struct tevent_req
*subreq
;
451 if (cldap
->connected
) {
452 return NT_STATUS_PIPE_CONNECTED
;
456 return NT_STATUS_INVALID_ADDRESS
;
459 state
= talloc(cldap
, struct cldap_reply_state
);
460 NT_STATUS_HAVE_NO_MEMORY(state
);
462 state
->dest
= tsocket_address_copy(io
->dest
, state
);
467 msg
= talloc(state
, struct ldap_message
);
472 msg
->messageid
= io
->messageid
;
473 msg
->controls
= NULL
;
476 msg
->type
= LDAP_TAG_SearchResultEntry
;
477 msg
->r
.SearchResultEntry
= *io
->response
;
479 if (!ldap_encode(msg
, NULL
, &blob1
, state
)) {
480 status
= NT_STATUS_INVALID_PARAMETER
;
484 blob1
= data_blob(NULL
, 0);
487 msg
->type
= LDAP_TAG_SearchResultDone
;
488 msg
->r
.SearchResultDone
= *io
->result
;
490 if (!ldap_encode(msg
, NULL
, &blob2
, state
)) {
491 status
= NT_STATUS_INVALID_PARAMETER
;
496 state
->blob
= data_blob_talloc(state
, NULL
, blob1
.length
+ blob2
.length
);
497 if (!state
->blob
.data
) {
501 memcpy(state
->blob
.data
, blob1
.data
, blob1
.length
);
502 memcpy(state
->blob
.data
+blob1
.length
, blob2
.data
, blob2
.length
);
503 data_blob_free(&blob1
);
504 data_blob_free(&blob2
);
506 subreq
= tdgram_sendto_queue_send(state
,
516 /* the callback will just free the state, as we don't need a result */
517 tevent_req_set_callback(subreq
, cldap_reply_state_destroy
, state
);
522 status
= NT_STATUS_NO_MEMORY
;
528 static void cldap_reply_state_destroy(struct tevent_req
*subreq
)
530 struct cldap_reply_state
*state
= tevent_req_callback_data(subreq
,
531 struct cldap_reply_state
);
533 /* we don't want to know the result here, we just free the state */
538 static int cldap_search_state_destructor(struct cldap_search_state
*s
)
540 if (s
->caller
.cldap
) {
541 if (s
->message_id
!= -1) {
542 idr_remove(s
->caller
.cldap
->searches
.idr
, s
->message_id
);
545 DLIST_REMOVE(s
->caller
.cldap
->searches
.list
, s
);
546 cldap_recvfrom_stop(s
->caller
.cldap
);
547 ZERO_STRUCT(s
->caller
);
553 static void cldap_search_state_queue_done(struct tevent_req
*subreq
);
554 static void cldap_search_state_wakeup_done(struct tevent_req
*subreq
);
557 queue a cldap reply for send
559 struct tevent_req
*cldap_search_send(TALLOC_CTX
*mem_ctx
,
560 struct cldap_socket
*cldap
,
561 const struct cldap_search
*io
)
563 struct tevent_req
*req
, *subreq
;
564 struct cldap_search_state
*state
= NULL
;
565 struct ldap_message
*msg
;
566 struct ldap_SearchRequest
*search
;
572 req
= tevent_req_create(mem_ctx
, &state
,
573 struct cldap_search_state
);
579 state
->caller
.cldap
= cldap
;
580 state
->message_id
= -1;
582 talloc_set_destructor(state
, cldap_search_state_destructor
);
584 if (io
->in
.dest_address
) {
585 if (cldap
->connected
) {
586 tevent_req_nterror(req
, NT_STATUS_PIPE_CONNECTED
);
589 ret
= tsocket_address_inet_from_strings(state
,
593 &state
->request
.dest
);
595 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
599 if (!cldap
->connected
) {
600 tevent_req_nterror(req
, NT_STATUS_INVALID_ADDRESS
);
603 state
->request
.dest
= NULL
;
606 state
->message_id
= idr_get_new_random(cldap
->searches
.idr
,
608 if (state
->message_id
== -1) {
609 tevent_req_nterror(req
, NT_STATUS_INSUFFICIENT_RESOURCES
);
613 msg
= talloc(state
, struct ldap_message
);
614 if (tevent_req_nomem(msg
, req
)) {
618 msg
->messageid
= state
->message_id
;
619 msg
->type
= LDAP_TAG_SearchRequest
;
620 msg
->controls
= NULL
;
621 search
= &msg
->r
.SearchRequest
;
624 search
->scope
= LDAP_SEARCH_SCOPE_BASE
;
625 search
->deref
= LDAP_DEREFERENCE_NEVER
;
626 search
->timelimit
= 0;
627 search
->sizelimit
= 0;
628 search
->attributesonly
= false;
629 search
->num_attributes
= str_list_length(io
->in
.attributes
);
630 search
->attributes
= io
->in
.attributes
;
631 search
->tree
= ldb_parse_tree(msg
, io
->in
.filter
);
632 if (tevent_req_nomem(search
->tree
, req
)) {
636 if (!ldap_encode(msg
, NULL
, &state
->request
.blob
, state
)) {
637 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
642 state
->request
.idx
= 0;
643 state
->request
.delay
= 10*1000*1000;
644 state
->request
.count
= 3;
645 if (io
->in
.timeout
> 0) {
646 state
->request
.delay
= io
->in
.timeout
* 1000 * 1000;
647 state
->request
.count
= io
->in
.retries
+ 1;
650 now
= tevent_timeval_current();
652 for (i
= 0; i
< state
->request
.count
; i
++) {
653 end
= tevent_timeval_add(&end
, 0, state
->request
.delay
);
656 if (!tevent_req_set_endtime(req
, state
->caller
.cldap
->event
.ctx
, end
)) {
657 tevent_req_nomem(NULL
, req
);
661 subreq
= tdgram_sendto_queue_send(state
,
662 state
->caller
.cldap
->event
.ctx
,
663 state
->caller
.cldap
->sock
,
664 state
->caller
.cldap
->send_queue
,
665 state
->request
.blob
.data
,
666 state
->request
.blob
.length
,
667 state
->request
.dest
);
668 if (tevent_req_nomem(subreq
, req
)) {
671 tevent_req_set_callback(subreq
, cldap_search_state_queue_done
, req
);
673 DLIST_ADD_END(cldap
->searches
.list
, state
, struct cldap_search_state
*);
678 return tevent_req_post(req
, cldap
->event
.ctx
);
681 static void cldap_search_state_queue_done(struct tevent_req
*subreq
)
683 struct tevent_req
*req
= tevent_req_callback_data(subreq
,
685 struct cldap_search_state
*state
= tevent_req_data(req
,
686 struct cldap_search_state
);
691 ret
= tdgram_sendto_queue_recv(subreq
, &sys_errno
);
695 status
= map_nt_error_from_unix(sys_errno
);
696 DLIST_REMOVE(state
->caller
.cldap
->searches
.list
, state
);
697 ZERO_STRUCT(state
->caller
.cldap
);
698 tevent_req_nterror(req
, status
);
702 state
->request
.idx
++;
704 /* wait for incoming traffic */
705 if (!cldap_recvfrom_setup(state
->caller
.cldap
)) {
706 tevent_req_nomem(NULL
, req
);
710 if (state
->request
.idx
> state
->request
.count
) {
711 /* we just wait for the response or a timeout */
715 next
= tevent_timeval_current_ofs(0, state
->request
.delay
);
716 subreq
= tevent_wakeup_send(state
,
717 state
->caller
.cldap
->event
.ctx
,
719 if (tevent_req_nomem(subreq
, req
)) {
722 tevent_req_set_callback(subreq
, cldap_search_state_wakeup_done
, req
);
725 static void cldap_search_state_wakeup_done(struct tevent_req
*subreq
)
727 struct tevent_req
*req
= tevent_req_callback_data(subreq
,
729 struct cldap_search_state
*state
= tevent_req_data(req
,
730 struct cldap_search_state
);
733 ok
= tevent_wakeup_recv(subreq
);
736 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
740 subreq
= tdgram_sendto_queue_send(state
,
741 state
->caller
.cldap
->event
.ctx
,
742 state
->caller
.cldap
->sock
,
743 state
->caller
.cldap
->send_queue
,
744 state
->request
.blob
.data
,
745 state
->request
.blob
.length
,
746 state
->request
.dest
);
747 if (tevent_req_nomem(subreq
, req
)) {
750 tevent_req_set_callback(subreq
, cldap_search_state_queue_done
, req
);
754 receive a cldap reply
756 NTSTATUS
cldap_search_recv(struct tevent_req
*req
,
758 struct cldap_search
*io
)
760 struct cldap_search_state
*state
= tevent_req_data(req
,
761 struct cldap_search_state
);
762 struct ldap_message
*ldap_msg
;
765 if (tevent_req_is_nterror(req
, &status
)) {
769 ldap_msg
= talloc(mem_ctx
, struct ldap_message
);
774 status
= ldap_decode(state
->response
.asn1
, NULL
, ldap_msg
);
775 if (!NT_STATUS_IS_OK(status
)) {
779 ZERO_STRUCT(io
->out
);
781 /* the first possible form has a search result in first place */
782 if (ldap_msg
->type
== LDAP_TAG_SearchResultEntry
) {
783 io
->out
.response
= talloc(mem_ctx
, struct ldap_SearchResEntry
);
784 if (!io
->out
.response
) {
787 *io
->out
.response
= ldap_msg
->r
.SearchResultEntry
;
789 /* decode the 2nd part */
790 status
= ldap_decode(state
->response
.asn1
, NULL
, ldap_msg
);
791 if (!NT_STATUS_IS_OK(status
)) {
796 if (ldap_msg
->type
!= LDAP_TAG_SearchResultDone
) {
797 status
= NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR
);
801 io
->out
.result
= talloc(mem_ctx
, struct ldap_Result
);
802 if (!io
->out
.result
) {
805 *io
->out
.result
= ldap_msg
->r
.SearchResultDone
;
807 if (io
->out
.result
->resultcode
!= LDAP_SUCCESS
) {
808 status
= NT_STATUS_LDAP(io
->out
.result
->resultcode
);
812 tevent_req_received(req
);
816 status
= NT_STATUS_NO_MEMORY
;
818 tevent_req_received(req
);
824 synchronous cldap search
826 NTSTATUS
cldap_search(struct cldap_socket
*cldap
,
828 struct cldap_search
*io
)
830 struct tevent_req
*req
;
833 if (!cldap
->event
.allow_poll
) {
834 return NT_STATUS_INVALID_PIPE_STATE
;
837 if (cldap
->searches
.list
) {
838 return NT_STATUS_PIPE_BUSY
;
841 req
= cldap_search_send(mem_ctx
, cldap
, io
);
842 NT_STATUS_HAVE_NO_MEMORY(req
);
844 if (!tevent_req_poll(req
, cldap
->event
.ctx
)) {
846 return NT_STATUS_INTERNAL_ERROR
;
849 status
= cldap_search_recv(req
, mem_ctx
, io
);
855 struct cldap_netlogon_state
{
856 struct cldap_search search
;
859 static void cldap_netlogon_state_done(struct tevent_req
*subreq
);
861 queue a cldap netlogon for send
863 struct tevent_req
*cldap_netlogon_send(TALLOC_CTX
*mem_ctx
,
864 struct cldap_socket
*cldap
,
865 const struct cldap_netlogon
*io
)
867 struct tevent_req
*req
, *subreq
;
868 struct cldap_netlogon_state
*state
;
870 static const char * const attr
[] = { "NetLogon", NULL
};
872 req
= tevent_req_create(mem_ctx
, &state
,
873 struct cldap_netlogon_state
);
878 filter
= talloc_asprintf(state
, "(&(NtVer=%s)",
879 ldap_encode_ndr_uint32(state
, io
->in
.version
));
880 if (tevent_req_nomem(filter
, req
)) {
884 filter
= talloc_asprintf_append_buffer(filter
, "(User=%s)", io
->in
.user
);
885 if (tevent_req_nomem(filter
, req
)) {
890 filter
= talloc_asprintf_append_buffer(filter
, "(Host=%s)", io
->in
.host
);
891 if (tevent_req_nomem(filter
, req
)) {
896 filter
= talloc_asprintf_append_buffer(filter
, "(DnsDomain=%s)", io
->in
.realm
);
897 if (tevent_req_nomem(filter
, req
)) {
901 if (io
->in
.acct_control
!= -1) {
902 filter
= talloc_asprintf_append_buffer(filter
, "(AAC=%s)",
903 ldap_encode_ndr_uint32(state
, io
->in
.acct_control
));
904 if (tevent_req_nomem(filter
, req
)) {
908 if (io
->in
.domain_sid
) {
909 struct dom_sid
*sid
= dom_sid_parse_talloc(state
, io
->in
.domain_sid
);
910 if (tevent_req_nomem(sid
, req
)) {
913 filter
= talloc_asprintf_append_buffer(filter
, "(domainSid=%s)",
914 ldap_encode_ndr_dom_sid(state
, sid
));
915 if (tevent_req_nomem(filter
, req
)) {
919 if (io
->in
.domain_guid
) {
922 status
= GUID_from_string(io
->in
.domain_guid
, &guid
);
923 if (tevent_req_nterror(req
, status
)) {
926 filter
= talloc_asprintf_append_buffer(filter
, "(DomainGuid=%s)",
927 ldap_encode_ndr_GUID(state
, &guid
));
928 if (tevent_req_nomem(filter
, req
)) {
932 filter
= talloc_asprintf_append_buffer(filter
, ")");
933 if (tevent_req_nomem(filter
, req
)) {
937 if (io
->in
.dest_address
) {
938 state
->search
.in
.dest_address
= talloc_strdup(state
,
939 io
->in
.dest_address
);
940 if (tevent_req_nomem(state
->search
.in
.dest_address
, req
)) {
943 state
->search
.in
.dest_port
= io
->in
.dest_port
;
945 state
->search
.in
.dest_address
= NULL
;
946 state
->search
.in
.dest_port
= 0;
948 state
->search
.in
.filter
= filter
;
949 state
->search
.in
.attributes
= attr
;
950 state
->search
.in
.timeout
= 2;
951 state
->search
.in
.retries
= 2;
953 subreq
= cldap_search_send(state
, cldap
, &state
->search
);
954 if (tevent_req_nomem(subreq
, req
)) {
957 tevent_req_set_callback(subreq
, cldap_netlogon_state_done
, req
);
961 return tevent_req_post(req
, cldap
->event
.ctx
);
964 static void cldap_netlogon_state_done(struct tevent_req
*subreq
)
966 struct tevent_req
*req
= tevent_req_callback_data(subreq
,
968 struct cldap_netlogon_state
*state
= tevent_req_data(req
,
969 struct cldap_netlogon_state
);
972 status
= cldap_search_recv(subreq
, state
, &state
->search
);
975 if (tevent_req_nterror(req
, status
)) {
979 tevent_req_done(req
);
983 receive a cldap netlogon reply
985 NTSTATUS
cldap_netlogon_recv(struct tevent_req
*req
,
987 struct cldap_netlogon
*io
)
989 struct cldap_netlogon_state
*state
= tevent_req_data(req
,
990 struct cldap_netlogon_state
);
994 if (tevent_req_is_nterror(req
, &status
)) {
998 if (state
->search
.out
.response
== NULL
) {
999 status
= NT_STATUS_NOT_FOUND
;
1003 if (state
->search
.out
.response
->num_attributes
!= 1 ||
1004 strcasecmp(state
->search
.out
.response
->attributes
[0].name
, "netlogon") != 0 ||
1005 state
->search
.out
.response
->attributes
[0].num_values
!= 1 ||
1006 state
->search
.out
.response
->attributes
[0].values
->length
< 2) {
1007 status
= NT_STATUS_UNEXPECTED_NETWORK_ERROR
;
1010 data
= state
->search
.out
.response
->attributes
[0].values
;
1012 status
= pull_netlogon_samlogon_response(data
, mem_ctx
,
1014 if (!NT_STATUS_IS_OK(status
)) {
1018 if (io
->in
.map_response
) {
1019 map_netlogon_samlogon_response(&io
->out
.netlogon
);
1022 status
= NT_STATUS_OK
;
1024 tevent_req_received(req
);
1029 sync cldap netlogon search
1031 NTSTATUS
cldap_netlogon(struct cldap_socket
*cldap
,
1032 TALLOC_CTX
*mem_ctx
,
1033 struct cldap_netlogon
*io
)
1035 struct tevent_req
*req
;
1038 if (!cldap
->event
.allow_poll
) {
1039 return NT_STATUS_INVALID_PIPE_STATE
;
1042 if (cldap
->searches
.list
) {
1043 return NT_STATUS_PIPE_BUSY
;
1046 req
= cldap_netlogon_send(mem_ctx
, cldap
, io
);
1047 NT_STATUS_HAVE_NO_MEMORY(req
);
1049 if (!tevent_req_poll(req
, cldap
->event
.ctx
)) {
1051 return NT_STATUS_INTERNAL_ERROR
;
1054 status
= cldap_netlogon_recv(req
, mem_ctx
, io
);
1062 send an empty reply (used on any error, so the client doesn't keep waiting
1063 or send the bad request again)
1065 NTSTATUS
cldap_empty_reply(struct cldap_socket
*cldap
,
1066 uint32_t message_id
,
1067 struct tsocket_address
*dest
)
1070 struct cldap_reply reply
;
1071 struct ldap_Result result
;
1073 reply
.messageid
= message_id
;
1075 reply
.response
= NULL
;
1076 reply
.result
= &result
;
1078 ZERO_STRUCT(result
);
1080 status
= cldap_reply_send(cldap
, &reply
);
1086 send an error reply (used on any error, so the client doesn't keep waiting
1087 or send the bad request again)
1089 NTSTATUS
cldap_error_reply(struct cldap_socket
*cldap
,
1090 uint32_t message_id
,
1091 struct tsocket_address
*dest
,
1093 const char *errormessage
)
1096 struct cldap_reply reply
;
1097 struct ldap_Result result
;
1099 reply
.messageid
= message_id
;
1101 reply
.response
= NULL
;
1102 reply
.result
= &result
;
1104 ZERO_STRUCT(result
);
1105 result
.resultcode
= resultcode
;
1106 result
.errormessage
= errormessage
;
1108 status
= cldap_reply_send(cldap
, &reply
);
1115 send a netlogon reply
1117 NTSTATUS
cldap_netlogon_reply(struct cldap_socket
*cldap
,
1118 uint32_t message_id
,
1119 struct tsocket_address
*dest
,
1121 struct netlogon_samlogon_response
*netlogon
)
1124 struct cldap_reply reply
;
1125 struct ldap_SearchResEntry response
;
1126 struct ldap_Result result
;
1127 TALLOC_CTX
*tmp_ctx
= talloc_new(cldap
);
1130 status
= push_netlogon_samlogon_response(&blob
, tmp_ctx
,
1132 if (!NT_STATUS_IS_OK(status
)) {
1133 talloc_free(tmp_ctx
);
1136 reply
.messageid
= message_id
;
1138 reply
.response
= &response
;
1139 reply
.result
= &result
;
1141 ZERO_STRUCT(result
);
1144 response
.num_attributes
= 1;
1145 response
.attributes
= talloc(tmp_ctx
, struct ldb_message_element
);
1146 NT_STATUS_HAVE_NO_MEMORY(response
.attributes
);
1147 response
.attributes
->name
= "netlogon";
1148 response
.attributes
->num_values
= 1;
1149 response
.attributes
->values
= &blob
;
1151 status
= cldap_reply_send(cldap
, &reply
);
1153 talloc_free(tmp_ctx
);