r25026: Move param/param.h out of includes.h
[ira/wip.git] / source4 / libcli / cldap / cldap.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    cldap client library
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 /*
23   see RFC1798 for details of CLDAP
24
25   basic properties
26     - carried over UDP on port 389
27     - request and response matched by message ID
28     - request consists of only a single searchRequest element
29     - response can be in one of two forms
30        - a single searchResponse, followed by a searchResult
31        - a single searchResult
32 */
33
34 #include "includes.h"
35 #include "lib/events/events.h"
36 #include "lib/util/dlinklist.h"
37 #include "libcli/ldap/ldap.h"
38 #include "libcli/cldap/cldap.h"
39 #include "lib/socket/socket.h"
40 #include "libcli/security/security.h"
41 #include "librpc/gen_ndr/ndr_nbt.h"
42 #include "param/param.h"
43
44 /*
45   destroy a pending request
46 */
47 static int cldap_request_destructor(struct cldap_request *req)
48 {
49         if (req->state == CLDAP_REQUEST_SEND) {
50                 DLIST_REMOVE(req->cldap->send_queue, req);
51         }
52         if (!req->is_reply && req->message_id != 0) {
53                 idr_remove(req->cldap->idr, req->message_id);
54                 req->message_id = 0;
55         }
56         return 0;
57 }
58
59 /*
60   handle recv events on a cldap socket
61 */
62 static void cldap_socket_recv(struct cldap_socket *cldap)
63 {
64         TALLOC_CTX *tmp_ctx = talloc_new(cldap);
65         NTSTATUS status;
66         struct socket_address *src;
67         DATA_BLOB blob;
68         size_t nread, dsize;
69         struct asn1_data *asn1 = asn1_init(tmp_ctx);
70         struct ldap_message *ldap_msg;
71         struct cldap_request *req;
72
73         if (!asn1) return;
74
75         status = socket_pending(cldap->sock, &dsize);
76         if (!NT_STATUS_IS_OK(status)) {
77                 talloc_free(tmp_ctx);
78                 return;
79         }
80
81         blob = data_blob_talloc(tmp_ctx, NULL, dsize);
82         if (blob.data == NULL) {
83                 talloc_free(tmp_ctx);
84                 return;
85         }
86
87         status = socket_recvfrom(cldap->sock, blob.data, blob.length, &nread,
88                                  tmp_ctx, &src);
89         if (!NT_STATUS_IS_OK(status)) {
90                 talloc_free(tmp_ctx);
91                 return;
92         }
93         blob.length = nread;
94
95         DEBUG(2,("Received cldap packet of length %d from %s:%d\n", 
96                  (int)blob.length, src->addr, src->port));
97
98         if (!asn1_load(asn1, blob)) {
99                 DEBUG(2,("Failed to setup for asn.1 decode\n"));
100                 talloc_free(tmp_ctx);
101                 return;
102         }
103
104         ldap_msg = talloc(tmp_ctx, struct ldap_message);
105         if (ldap_msg == NULL) {
106                 talloc_free(tmp_ctx);
107                 return;
108         }
109
110         /* this initial decode is used to find the message id */
111         status = ldap_decode(asn1, ldap_msg);
112         if (!NT_STATUS_IS_OK(status)) {
113                 DEBUG(2,("Failed to decode ldap message: %s\n", nt_errstr(status)));
114                 talloc_free(tmp_ctx);
115                 return;
116         }
117
118         /* find the pending request */
119         req = idr_find(cldap->idr, ldap_msg->messageid);
120         if (req == NULL) {
121                 if (cldap->incoming.handler) {
122                         cldap->incoming.handler(cldap, ldap_msg, src);
123                 } else {
124                         DEBUG(2,("Mismatched cldap reply %u from %s:%d\n",
125                                  ldap_msg->messageid, src->addr, src->port));
126                 }
127                 talloc_free(tmp_ctx);
128                 return;
129         }
130
131         req->asn1 = talloc_steal(req, asn1);
132         req->asn1->ofs = 0;
133
134         req->state = CLDAP_REQUEST_DONE;
135         talloc_free(req->te);
136
137         talloc_free(tmp_ctx);
138
139         if (req->async.fn) {
140                 req->async.fn(req);
141         }
142 }
143
144 /*
145   handle request timeouts
146 */
147 static void cldap_request_timeout(struct event_context *event_ctx, 
148                                   struct timed_event *te, struct timeval t,
149                                   void *private)
150 {
151         struct cldap_request *req = talloc_get_type(private, struct cldap_request);
152
153         /* possibly try again */
154         if (req->num_retries != 0) {
155                 size_t len = req->encoded.length;
156
157                 req->num_retries--;
158
159                 socket_sendto(req->cldap->sock, &req->encoded, &len, 
160                               req->dest);
161
162                 req->te = event_add_timed(req->cldap->event_ctx, req, 
163                                           timeval_current_ofs(req->timeout, 0),
164                                           cldap_request_timeout, req);
165                 return;
166         }
167
168         req->state = CLDAP_REQUEST_ERROR;
169         req->status = NT_STATUS_IO_TIMEOUT;
170         if (req->async.fn) {
171                 req->async.fn(req);
172         }
173 }
174
175 /*
176   handle send events on a cldap socket
177 */
178 static void cldap_socket_send(struct cldap_socket *cldap)
179 {
180         struct cldap_request *req;
181         NTSTATUS status;
182
183         while ((req = cldap->send_queue)) {
184                 size_t len;
185                 
186                 len = req->encoded.length;
187                 status = socket_sendto(cldap->sock, &req->encoded, &len,
188                                        req->dest);
189                 if (NT_STATUS_IS_ERR(status)) {
190                         DEBUG(0,("Failed to send cldap request of length %u to %s:%d\n",
191                                  (unsigned)req->encoded.length, req->dest->addr, req->dest->port));
192                         DLIST_REMOVE(cldap->send_queue, req);
193                         req->state = CLDAP_REQUEST_ERROR;
194                         req->status = status;
195                         if (req->async.fn) {
196                                 req->async.fn(req);
197                         }
198                         continue;
199                 }
200
201                 if (!NT_STATUS_IS_OK(status)) return;
202
203                 DLIST_REMOVE(cldap->send_queue, req);
204
205                 if (req->is_reply) {
206                         talloc_free(req);
207                 } else {
208                         req->state = CLDAP_REQUEST_WAIT;
209
210                         req->te = event_add_timed(cldap->event_ctx, req, 
211                                                   timeval_current_ofs(req->timeout, 0),
212                                                   cldap_request_timeout, req);
213
214                         EVENT_FD_READABLE(cldap->fde);
215                 }
216         }
217
218         EVENT_FD_NOT_WRITEABLE(cldap->fde);
219         return;
220 }
221
222
223 /*
224   handle fd events on a cldap_socket
225 */
226 static void cldap_socket_handler(struct event_context *ev, struct fd_event *fde,
227                                  uint16_t flags, void *private)
228 {
229         struct cldap_socket *cldap = talloc_get_type(private, struct cldap_socket);
230         if (flags & EVENT_FD_WRITE) {
231                 cldap_socket_send(cldap);
232         } 
233         if (flags & EVENT_FD_READ) {
234                 cldap_socket_recv(cldap);
235         }
236 }
237
238 /*
239   initialise a cldap_socket. The event_ctx is optional, if provided
240   then operations will use that event context
241 */
242 struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx, 
243                                        struct event_context *event_ctx)
244 {
245         struct cldap_socket *cldap;
246         NTSTATUS status;
247
248         cldap = talloc(mem_ctx, struct cldap_socket);
249         if (cldap == NULL) goto failed;
250
251         if (event_ctx == NULL) {
252                 cldap->event_ctx = event_context_init(cldap);
253         } else {
254                 cldap->event_ctx = talloc_reference(cldap, event_ctx);
255         }
256         if (cldap->event_ctx == NULL) goto failed;
257
258         cldap->idr = idr_init(cldap);
259         if (cldap->idr == NULL) goto failed;
260
261         status = socket_create("ip", SOCKET_TYPE_DGRAM, &cldap->sock, 0);
262         if (!NT_STATUS_IS_OK(status)) goto failed;
263
264         talloc_steal(cldap, cldap->sock);
265
266         cldap->fde = event_add_fd(cldap->event_ctx, cldap, 
267                                       socket_get_fd(cldap->sock), 0,
268                                       cldap_socket_handler, cldap);
269
270         cldap->send_queue = NULL;
271         cldap->incoming.handler = NULL;
272         
273         return cldap;
274
275 failed:
276         talloc_free(cldap);
277         return NULL;
278 }
279
280
281 /*
282   setup a handler for incoming requests
283 */
284 NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
285                                   void (*handler)(struct cldap_socket *, struct ldap_message *, 
286                                                   struct socket_address *),
287                                   void *private)
288 {
289         cldap->incoming.handler = handler;
290         cldap->incoming.private = private;
291         EVENT_FD_READABLE(cldap->fde);
292         return NT_STATUS_OK;
293 }
294
295 /*
296   queue a cldap request for send
297 */
298 struct cldap_request *cldap_search_send(struct cldap_socket *cldap, 
299                                         struct cldap_search *io)
300 {
301         struct ldap_message *msg;
302         struct cldap_request *req;
303         struct ldap_SearchRequest *search;
304
305         req = talloc_zero(cldap, struct cldap_request);
306         if (req == NULL) goto failed;
307
308         req->cldap       = cldap;
309         req->state       = CLDAP_REQUEST_SEND;
310         req->timeout     = io->in.timeout;
311         req->num_retries = io->in.retries;
312         req->is_reply    = False;
313         req->asn1        = asn1_init(req);
314         if (!req->asn1) {
315                 goto failed;
316         }
317
318         req->dest = socket_address_from_strings(req, cldap->sock->backend_name,
319                                                 io->in.dest_address, 
320                                                 lp_cldap_port());
321         if (!req->dest) goto failed;
322
323         req->message_id = idr_get_new_random(cldap->idr, req, UINT16_MAX);
324         if (req->message_id == -1) goto failed;
325
326         talloc_set_destructor(req, cldap_request_destructor);
327
328         msg = talloc(req, struct ldap_message);
329         if (msg == NULL) goto failed;
330         msg->messageid       = req->message_id;
331         msg->type            = LDAP_TAG_SearchRequest;
332         msg->controls        = NULL;
333         search = &msg->r.SearchRequest;
334
335         search->basedn         = "";
336         search->scope          = LDAP_SEARCH_SCOPE_BASE;
337         search->deref          = LDAP_DEREFERENCE_NEVER;
338         search->timelimit      = 0;
339         search->sizelimit      = 0;
340         search->attributesonly = False;
341         search->num_attributes = str_list_length(io->in.attributes);
342         search->attributes     = io->in.attributes;
343         search->tree           = ldb_parse_tree(req, io->in.filter);
344         if (search->tree == NULL) {
345                 goto failed;
346         }
347
348         if (!ldap_encode(msg, &req->encoded, req)) {
349                 DEBUG(0,("Failed to encode cldap message to %s:%d\n",
350                          req->dest->addr, req->dest->port));
351                 goto failed;
352         }
353
354         DLIST_ADD_END(cldap->send_queue, req, struct cldap_request *);
355
356         EVENT_FD_WRITEABLE(cldap->fde);
357
358         return req;
359
360 failed:
361         talloc_free(req);
362         return NULL;
363 }
364
365
366 /*
367   queue a cldap reply for send
368 */
369 NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
370 {
371         struct ldap_message *msg;
372         struct cldap_request *req;
373         DATA_BLOB blob1, blob2;
374         NTSTATUS status = NT_STATUS_NO_MEMORY;
375
376         req = talloc_zero(cldap, struct cldap_request);
377         if (req == NULL) goto failed;
378
379         req->cldap       = cldap;
380         req->state       = CLDAP_REQUEST_SEND;
381         req->is_reply    = True;
382         req->asn1        = asn1_init(req);
383         if (!req->asn1) {
384                 goto failed;
385         }
386
387         req->dest        = io->dest;
388         if (talloc_reference(req, io->dest) == NULL) goto failed;
389
390         talloc_set_destructor(req, cldap_request_destructor);
391
392         msg = talloc(req, struct ldap_message);
393         if (msg == NULL) goto failed;
394         msg->messageid       = io->messageid;
395         msg->controls        = NULL;
396         
397         if (io->response) {
398                 msg->type = LDAP_TAG_SearchResultEntry;
399                 msg->r.SearchResultEntry = *io->response;
400
401                 if (!ldap_encode(msg, &blob1, req)) {
402                         DEBUG(0,("Failed to encode cldap message to %s:%d\n",
403                                  req->dest->addr, req->dest->port));
404                         status = NT_STATUS_INVALID_PARAMETER;
405                         goto failed;
406                 }
407         } else {
408                 blob1 = data_blob(NULL, 0);
409         }
410
411         msg->type = LDAP_TAG_SearchResultDone;
412         msg->r.SearchResultDone = *io->result;
413
414         if (!ldap_encode(msg, &blob2, req)) {
415                 DEBUG(0,("Failed to encode cldap message to %s:%d\n",
416                          req->dest->addr, req->dest->port));
417                 status = NT_STATUS_INVALID_PARAMETER;
418                 goto failed;
419         }
420
421         req->encoded = data_blob_talloc(req, NULL, blob1.length + blob2.length);
422         if (req->encoded.data == NULL) goto failed;
423
424         memcpy(req->encoded.data, blob1.data, blob1.length);
425         memcpy(req->encoded.data+blob1.length, blob2.data, blob2.length);
426
427         DLIST_ADD_END(cldap->send_queue, req, struct cldap_request *);
428
429         EVENT_FD_WRITEABLE(cldap->fde);
430
431         return NT_STATUS_OK;
432
433 failed:
434         talloc_free(req);
435         return status;
436 }
437
438 /*
439   receive a cldap reply
440 */
441 NTSTATUS cldap_search_recv(struct cldap_request *req, 
442                            TALLOC_CTX *mem_ctx, 
443                            struct cldap_search *io)
444 {
445         struct ldap_message *ldap_msg;
446         NTSTATUS status;
447
448         if (req == NULL) {
449                 return NT_STATUS_NO_MEMORY;
450         }
451
452         while (req->state < CLDAP_REQUEST_DONE) {
453                 if (event_loop_once(req->cldap->event_ctx) != 0) {
454                         talloc_free(req);
455                         return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
456                 }
457         }
458
459         if (req->state == CLDAP_REQUEST_ERROR) {
460                 status = req->status;
461                 talloc_free(req);
462                 return status;
463         }
464
465         ldap_msg = talloc(mem_ctx, struct ldap_message);
466         NT_STATUS_HAVE_NO_MEMORY(ldap_msg);
467
468         status = ldap_decode(req->asn1, ldap_msg);
469         if (!NT_STATUS_IS_OK(status)) {
470                 DEBUG(2,("Failed to decode cldap search reply: %s\n", nt_errstr(status)));
471                 talloc_free(req);
472                 return status;
473         }
474
475         ZERO_STRUCT(io->out);
476
477         /* the first possible form has a search result in first place */
478         if (ldap_msg->type == LDAP_TAG_SearchResultEntry) {
479                 io->out.response = talloc(mem_ctx, struct ldap_SearchResEntry);
480                 NT_STATUS_HAVE_NO_MEMORY(io->out.response);
481                 *io->out.response = ldap_msg->r.SearchResultEntry;
482
483                 /* decode the 2nd part */
484                 status = ldap_decode(req->asn1, ldap_msg);
485                 if (!NT_STATUS_IS_OK(status)) {
486                         DEBUG(2,("Failed to decode cldap search result entry: %s\n", nt_errstr(status)));
487                         talloc_free(req);
488                         return status;
489                 }
490         }
491
492         if (ldap_msg->type != LDAP_TAG_SearchResultDone) {
493                 talloc_free(req);
494                 return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
495         }
496
497         io->out.result = talloc(mem_ctx, struct ldap_Result);
498         NT_STATUS_HAVE_NO_MEMORY(io->out.result);
499         *io->out.result = ldap_msg->r.SearchResultDone;
500
501         talloc_free(req);
502
503         if (io->out.result->resultcode != LDAP_SUCCESS) {
504                 return NT_STATUS_LDAP(io->out.result->resultcode);
505         }
506         return NT_STATUS_OK;
507 }
508
509
510 /*
511   synchronous cldap search
512 */
513 NTSTATUS cldap_search(struct cldap_socket *cldap, 
514                       TALLOC_CTX *mem_ctx, 
515                       struct cldap_search *io)
516 {
517         struct cldap_request *req = cldap_search_send(cldap, io);
518         return cldap_search_recv(req, mem_ctx, io);
519 }
520
521
522
523 /*
524   queue a cldap netlogon for send
525 */
526 struct cldap_request *cldap_netlogon_send(struct cldap_socket *cldap, 
527                                           struct cldap_netlogon *io)
528 {
529         struct cldap_search search;
530         char *filter;
531         struct cldap_request *req;
532         const char *attr[] = { "NetLogon", NULL };
533         TALLOC_CTX *tmp_ctx = talloc_new(cldap);
534
535         filter = talloc_asprintf(tmp_ctx, "(&(NtVer=%s)", 
536                                  ldap_encode_ndr_uint32(tmp_ctx, io->in.version));
537         if (filter == NULL) goto failed;
538         if (io->in.user) {
539                 filter = talloc_asprintf_append(filter, "(User=%s)", io->in.user);
540                 if (filter == NULL) goto failed;
541         }
542         if (io->in.host) {
543                 filter = talloc_asprintf_append(filter, "(Host=%s)", io->in.host);
544                 if (filter == NULL) goto failed;
545         }
546         if (io->in.realm) {
547                 filter = talloc_asprintf_append(filter, "(DnsDomain=%s)", io->in.realm);
548                 if (filter == NULL) goto failed;
549         }
550         if (io->in.acct_control != -1) {
551                 filter = talloc_asprintf_append(filter, "(AAC=%s)", 
552                                                 ldap_encode_ndr_uint32(tmp_ctx, io->in.acct_control));
553                 if (filter == NULL) goto failed;
554         }
555         if (io->in.domain_sid) {
556                 struct dom_sid *sid = dom_sid_parse_talloc(tmp_ctx, io->in.domain_sid);
557                 if (sid == NULL) goto failed;
558                 filter = talloc_asprintf_append(filter, "(domainSid=%s)",
559                                                 ldap_encode_ndr_dom_sid(tmp_ctx, sid));
560                 if (filter == NULL) goto failed;
561         }
562         if (io->in.domain_guid) {
563                 struct GUID guid;
564                 NTSTATUS status;
565                 status = GUID_from_string(io->in.domain_guid, &guid);
566                 if (!NT_STATUS_IS_OK(status)) goto failed;
567                 filter = talloc_asprintf_append(filter, "(DomainGuid=%s)",
568                                                 ldap_encode_ndr_GUID(tmp_ctx, &guid));
569                 if (filter == NULL) goto failed;
570         }
571         filter = talloc_asprintf_append(filter, ")");
572         if (filter == NULL) goto failed;
573
574         search.in.dest_address = io->in.dest_address;
575         search.in.filter       = filter;
576         search.in.attributes   = attr;
577         search.in.timeout      = 2;
578         search.in.retries      = 2;
579
580         req = cldap_search_send(cldap, &search);
581
582         talloc_free(tmp_ctx);
583         return req;
584 failed:
585         talloc_free(tmp_ctx);
586         return NULL;
587 }
588
589
590 /*
591   receive a cldap netlogon reply
592 */
593 NTSTATUS cldap_netlogon_recv(struct cldap_request *req, 
594                              TALLOC_CTX *mem_ctx, 
595                              struct cldap_netlogon *io)
596 {
597         NTSTATUS status;
598         struct cldap_search search;
599         DATA_BLOB *data;
600
601         status = cldap_search_recv(req, mem_ctx, &search);
602         if (!NT_STATUS_IS_OK(status)) {
603                 return status;
604         }
605         if (search.out.response == NULL) {
606                 return NT_STATUS_NOT_FOUND;
607         }
608
609         if (search.out.response->num_attributes != 1 ||
610             strcasecmp(search.out.response->attributes[0].name, "netlogon") != 0 ||
611             search.out.response->attributes[0].num_values != 1 ||
612             search.out.response->attributes[0].values->length < 2) {
613                 return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
614         }
615         data = search.out.response->attributes[0].values;
616
617         status = ndr_pull_union_blob(data, mem_ctx, &io->out.netlogon, 
618                                      io->in.version & 0xF,
619                                      (ndr_pull_flags_fn_t)ndr_pull_nbt_cldap_netlogon);
620         if (!NT_STATUS_IS_OK(status)) {
621                 DEBUG(2,("cldap failed to parse netlogon response of type 0x%02x\n",
622                          SVAL(data->data, 0)));
623                 dump_data(10, data->data, data->length);
624         }
625
626         return status;
627 }
628
629 /*
630   sync cldap netlogon search
631 */
632 NTSTATUS cldap_netlogon(struct cldap_socket *cldap, 
633                         TALLOC_CTX *mem_ctx, struct cldap_netlogon *io)
634 {
635         struct cldap_request *req = cldap_netlogon_send(cldap, io);
636         return cldap_netlogon_recv(req, mem_ctx, io);
637 }
638
639
640 /*
641   send an empty reply (used on any error, so the client doesn't keep waiting
642   or send the bad request again)
643 */
644 NTSTATUS cldap_empty_reply(struct cldap_socket *cldap, 
645                            uint32_t message_id,
646                            struct socket_address *src)
647 {
648         NTSTATUS status;
649         struct cldap_reply reply;
650         struct ldap_Result result;
651
652         reply.messageid    = message_id;
653         reply.dest         = src;
654         reply.response     = NULL;
655         reply.result       = &result;
656
657         ZERO_STRUCT(result);
658
659         status = cldap_reply_send(cldap, &reply);
660
661         return status;
662 }
663
664 /*
665   send an error reply (used on any error, so the client doesn't keep waiting
666   or send the bad request again)
667 */
668 NTSTATUS cldap_error_reply(struct cldap_socket *cldap, 
669                            uint32_t message_id,
670                            struct socket_address *src,
671                            int resultcode,
672                            const char *errormessage)
673 {
674         NTSTATUS status;
675         struct cldap_reply reply;
676         struct ldap_Result result;
677
678         reply.messageid    = message_id;
679         reply.dest         = src;
680         reply.response     = NULL;
681         reply.result       = &result;
682
683         ZERO_STRUCT(result);
684         result.resultcode       = resultcode;
685         result.errormessage     = errormessage;
686
687         status = cldap_reply_send(cldap, &reply);
688
689         return status;
690 }
691
692
693 /*
694   send a netlogon reply 
695 */
696 NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap, 
697                               uint32_t message_id,
698                               struct socket_address *src,
699                               uint32_t version,
700                               union nbt_cldap_netlogon *netlogon)
701 {
702         NTSTATUS status;
703         struct cldap_reply reply;
704         struct ldap_SearchResEntry response;
705         struct ldap_Result result;
706         TALLOC_CTX *tmp_ctx = talloc_new(cldap);
707         DATA_BLOB blob;
708
709         status = ndr_push_union_blob(&blob, tmp_ctx, netlogon, version & 0xF, 
710                                      (ndr_push_flags_fn_t)ndr_push_nbt_cldap_netlogon);
711         if (!NT_STATUS_IS_OK(status)) {
712                 talloc_free(tmp_ctx);
713                 return status;
714         }
715
716         reply.messageid    = message_id;
717         reply.dest         = src;
718         reply.response     = &response;
719         reply.result       = &result;
720
721         ZERO_STRUCT(result);
722
723         response.dn = "";
724         response.num_attributes = 1;
725         response.attributes = talloc(tmp_ctx, struct ldb_message_element);
726         NT_STATUS_HAVE_NO_MEMORY(response.attributes);
727         response.attributes->name = "netlogon";
728         response.attributes->num_values = 1;
729         response.attributes->values = &blob;
730
731         status = cldap_reply_send(cldap, &reply);
732
733         talloc_free(tmp_ctx);
734
735         return status;
736 }
737
738