2 Unix SMB/CIFS implementation.
4 low level WINS replication client code
6 Copyright (C) Andrew Tridgell 2005
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 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/events/events.h"
25 #include "dlinklist.h"
26 #include "lib/socket/socket.h"
27 #include "libcli/wrepl/winsrepl.h"
30 mark all pending requests as dead - called when a socket error happens
32 static void wrepl_socket_dead(struct wrepl_socket *wrepl_socket, NTSTATUS status)
34 talloc_set_destructor(wrepl_socket, NULL);
35 wrepl_socket->dead = True;
37 if (wrepl_socket->fde) {
38 talloc_free(wrepl_socket->fde);
39 wrepl_socket->fde = NULL;
42 if (wrepl_socket->sock) {
43 talloc_free(wrepl_socket->sock);
44 wrepl_socket->sock = NULL;
47 if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) {
48 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
50 while (wrepl_socket->send_queue) {
51 struct wrepl_request *req = wrepl_socket->send_queue;
52 DLIST_REMOVE(wrepl_socket->send_queue, req);
53 req->state = WREPL_REQUEST_ERROR;
59 while (wrepl_socket->recv_queue) {
60 struct wrepl_request *req = wrepl_socket->recv_queue;
61 DLIST_REMOVE(wrepl_socket->recv_queue, req);
62 req->state = WREPL_REQUEST_ERROR;
70 static void wrepl_request_timeout_handler(struct event_context *ev, struct timed_event *te,
71 struct timeval t, void *ptr)
73 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
74 wrepl_socket_dead(req->wrepl_socket, NT_STATUS_IO_TIMEOUT);
80 static void wrepl_handler_send(struct wrepl_socket *wrepl_socket)
82 while (wrepl_socket->send_queue) {
83 struct wrepl_request *req = wrepl_socket->send_queue;
87 status = socket_send(wrepl_socket->sock, &req->buffer, &nsent, 0);
88 if (NT_STATUS_IS_ERR(status)) {
89 wrepl_socket_dead(wrepl_socket, status);
92 if (!NT_STATUS_IS_OK(status) || nsent == 0) return;
94 req->buffer.data += nsent;
95 req->buffer.length -= nsent;
96 if (req->buffer.length != 0) {
100 if (req->disconnect_after_send) {
101 DLIST_REMOVE(wrepl_socket->send_queue, req);
102 req->status = NT_STATUS_OK;
103 req->state = WREPL_REQUEST_DONE;
104 wrepl_socket_dead(wrepl_socket, NT_STATUS_LOCAL_DISCONNECT);
111 if (req->send_only) {
112 DLIST_REMOVE(wrepl_socket->send_queue, req);
113 req->status = NT_STATUS_OK;
114 req->state = WREPL_REQUEST_DONE;
116 EVENT_FD_READABLE(wrepl_socket->fde);
121 DLIST_REMOVE(wrepl_socket->send_queue, req);
122 DLIST_ADD_END(wrepl_socket->recv_queue, req, struct wrepl_request *);
123 req->state = WREPL_REQUEST_RECV;
126 EVENT_FD_READABLE(wrepl_socket->fde);
129 EVENT_FD_NOT_WRITEABLE(wrepl_socket->fde);
136 static void wrepl_handler_recv(struct wrepl_socket *wrepl_socket)
139 struct wrepl_request *req = wrepl_socket->recv_queue;
145 EVENT_FD_NOT_READABLE(wrepl_socket->fde);
147 status = socket_recv(wrepl_socket->sock, NULL, 0, &nread, 0);
148 if (NT_STATUS_EQUAL(NT_STATUS_END_OF_FILE,status)) return;
149 if (NT_STATUS_IS_ERR(status)) {
150 wrepl_socket_dead(wrepl_socket, status);
156 if (req->buffer.length == 0) {
157 req->buffer = data_blob_talloc(req, NULL, 4);
158 if (req->buffer.data == NULL) {
159 req->status = NT_STATUS_NO_MEMORY;
165 /* read in the packet length */
166 if (req->num_read < 4) {
169 req->status = socket_recv(wrepl_socket->sock,
170 req->buffer.data + req->num_read,
173 if (NT_STATUS_IS_ERR(req->status)) {
174 wrepl_socket_dead(wrepl_socket, req->status);
177 if (!NT_STATUS_IS_OK(req->status)) return;
179 req->num_read += nread;
180 if (req->num_read != 4) return;
182 req_length = RIVAL(req->buffer.data, 0) + 4;
184 req->buffer.data = talloc_realloc(req, req->buffer.data,
185 uint8_t, req_length);
186 if (req->buffer.data == NULL) {
187 req->status = NT_STATUS_NO_MEMORY;
190 req->buffer.length = req_length;
193 /* read in the body */
194 req->status = socket_recv(wrepl_socket->sock,
195 req->buffer.data + req->num_read,
196 req->buffer.length - req->num_read,
198 if (NT_STATUS_IS_ERR(req->status)) {
199 wrepl_socket_dead(wrepl_socket, req->status);
202 if (!NT_STATUS_IS_OK(req->status)) return;
204 req->num_read += nread;
205 if (req->num_read != req->buffer.length) return;
207 req->packet = talloc(req, struct wrepl_packet);
208 if (req->packet == NULL) {
209 req->status = NT_STATUS_NO_MEMORY;
213 blob.data = req->buffer.data + 4;
214 blob.length = req->buffer.length - 4;
216 /* we have a full request - parse it */
217 req->status = ndr_pull_struct_blob(&blob,
218 req->packet, req->packet,
219 (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
220 if (!NT_STATUS_IS_OK(req->status)) {
221 DEBUG(2,("Failed to parse incoming WINS packet - %s\n",
222 nt_errstr(req->status)));
223 DEBUG(10,("packet length %d\n", (int)req->buffer.length));
224 NDR_PRINT_DEBUG(wrepl_packet, req->packet);
229 DEBUG(10,("Received WINS packet of length %d\n", (int)req->buffer.length));
230 NDR_PRINT_DEBUG(wrepl_packet, req->packet);
233 DLIST_REMOVE(wrepl_socket->recv_queue, req);
234 req->state = WREPL_REQUEST_DONE;
241 if (req->state == WREPL_REQUEST_RECV) {
242 DLIST_REMOVE(wrepl_socket->recv_queue, req);
244 req->state = WREPL_REQUEST_ERROR;
252 handler for winrepl events
254 static void wrepl_handler(struct event_context *ev, struct fd_event *fde,
255 uint16_t flags, void *private)
257 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
258 struct wrepl_socket);
259 if (flags & EVENT_FD_WRITE) {
260 wrepl_handler_send(wrepl_socket);
262 if (flags & EVENT_FD_READ) {
263 wrepl_handler_recv(wrepl_socket);
269 handler for winrepl connection completion
271 static void wrepl_connect_handler(struct event_context *ev, struct fd_event *fde,
272 uint16_t flags, void *private)
274 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
275 struct wrepl_socket);
276 struct wrepl_request *req = wrepl_socket->recv_queue;
278 talloc_free(wrepl_socket->fde);
279 wrepl_socket->fde = NULL;
281 if (req == NULL) return;
283 req->status = socket_connect_complete(wrepl_socket->sock, 0);
284 if (NT_STATUS_IS_ERR(req->status)) goto failed;
286 if (!NT_STATUS_IS_OK(req->status)) return;
288 wrepl_socket->fde = event_add_fd(wrepl_socket->event_ctx, wrepl_socket,
289 socket_get_fd(wrepl_socket->sock),
291 wrepl_handler, wrepl_socket);
292 if (wrepl_socket->fde == NULL) {
293 req->status = NT_STATUS_NO_MEMORY;
298 DLIST_REMOVE(wrepl_socket->recv_queue, req);
299 if (!NT_STATUS_IS_OK(req->status)) {
300 req->state = WREPL_REQUEST_ERROR;
302 req->state = WREPL_REQUEST_DONE;
310 destroy a wrepl_socket destructor
312 static int wrepl_socket_destructor(void *ptr)
314 struct wrepl_socket *sock = talloc_get_type(ptr, struct wrepl_socket);
315 wrepl_socket_dead(sock, NT_STATUS_LOCAL_DISCONNECT);
320 initialise a wrepl_socket. The event_ctx is optional, if provided then
321 operations will use that event context
323 struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx,
324 struct event_context *event_ctx)
326 struct wrepl_socket *wrepl_socket;
329 wrepl_socket = talloc(mem_ctx, struct wrepl_socket);
330 if (wrepl_socket == NULL) goto failed;
332 if (event_ctx == NULL) {
333 wrepl_socket->event_ctx = event_context_init(wrepl_socket);
335 wrepl_socket->event_ctx = talloc_reference(wrepl_socket, event_ctx);
337 if (wrepl_socket->event_ctx == NULL) goto failed;
339 status = socket_create("ip", SOCKET_TYPE_STREAM, &wrepl_socket->sock, 0);
340 if (!NT_STATUS_IS_OK(status)) goto failed;
342 talloc_steal(wrepl_socket, wrepl_socket->sock);
344 wrepl_socket->send_queue = NULL;
345 wrepl_socket->recv_queue = NULL;
346 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
347 wrepl_socket->dead = False;
349 wrepl_socket->fde = event_add_fd(wrepl_socket->event_ctx, wrepl_socket,
350 socket_get_fd(wrepl_socket->sock),
352 wrepl_connect_handler, wrepl_socket);
353 if (wrepl_socket->fde == NULL) {
357 set_blocking(socket_get_fd(wrepl_socket->sock), False);
359 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
364 talloc_free(wrepl_socket);
369 initialise a wrepl_socket from an already existing connection
371 struct wrepl_socket *wrepl_socket_merge(TALLOC_CTX *mem_ctx,
372 struct event_context *event_ctx,
373 struct socket_context *socket)
375 struct wrepl_socket *wrepl_socket;
377 wrepl_socket = talloc(mem_ctx, struct wrepl_socket);
378 if (wrepl_socket == NULL) goto failed;
380 wrepl_socket->event_ctx = talloc_reference(wrepl_socket, event_ctx);
381 if (wrepl_socket->event_ctx == NULL) goto failed;
383 wrepl_socket->sock = socket;
384 talloc_steal(wrepl_socket, wrepl_socket->sock);
386 wrepl_socket->send_queue = NULL;
387 wrepl_socket->recv_queue = NULL;
388 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
389 wrepl_socket->dead = False;
391 wrepl_socket->fde = event_add_fd(wrepl_socket->event_ctx, wrepl_socket,
392 socket_get_fd(wrepl_socket->sock),
394 wrepl_handler, wrepl_socket);
395 if (wrepl_socket->fde == NULL) {
399 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
404 talloc_free(wrepl_socket);
409 destroy a wrepl_request
411 static int wrepl_request_destructor(void *ptr)
413 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
414 if (req->state == WREPL_REQUEST_SEND) {
415 DLIST_REMOVE(req->wrepl_socket->send_queue, req);
417 if (req->state == WREPL_REQUEST_RECV) {
418 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
420 req->state = WREPL_REQUEST_ERROR;
425 wait for a request to complete
427 static NTSTATUS wrepl_request_wait(struct wrepl_request *req)
429 NT_STATUS_HAVE_NO_MEMORY(req);
430 while (req->state < WREPL_REQUEST_DONE) {
431 event_loop_once(req->wrepl_socket->event_ctx);
436 static void wrepl_request_trigger(struct wrepl_request *req);
439 connect a wrepl_socket to a WINS server
441 struct wrepl_request *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
442 const char *our_ip, const char *peer_ip)
444 struct wrepl_request *req;
447 req = talloc_zero(wrepl_socket, struct wrepl_request);
448 if (req == NULL) goto failed;
450 req->wrepl_socket = wrepl_socket;
451 req->state = WREPL_REQUEST_RECV;
453 DLIST_ADD(wrepl_socket->recv_queue, req);
455 talloc_set_destructor(req, wrepl_request_destructor);
458 our_ip = iface_best_ip(peer_ip);
461 status = socket_connect(wrepl_socket->sock, our_ip, 0, peer_ip,
462 WINS_REPLICATION_PORT, 0);
463 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
464 req->wrepl_socket = wrepl_socket;
465 req->state = WREPL_REQUEST_ERROR;
466 req->status = status;
467 wrepl_request_trigger(req);
479 connect a wrepl_socket to a WINS server - recv side
481 NTSTATUS wrepl_connect_recv(struct wrepl_request *req)
483 return wrepl_request_wait(req);
488 connect a wrepl_socket to a WINS server - sync API
490 NTSTATUS wrepl_connect(struct wrepl_socket *wrepl_socket, const char *our_ip, const char *peer_ip)
492 struct wrepl_request *req = wrepl_connect_send(wrepl_socket, our_ip, peer_ip);
493 return wrepl_connect_recv(req);
497 callback from wrepl_request_trigger()
499 static void wrepl_request_trigger_handler(struct event_context *ev, struct timed_event *te,
500 struct timeval t, void *ptr)
502 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
509 trigger an immediate event on a wrepl_request
511 static void wrepl_request_trigger(struct wrepl_request *req)
513 /* a zero timeout means immediate */
514 event_add_timed(req->wrepl_socket->event_ctx,
516 wrepl_request_trigger_handler, req);
521 send a generic wins replication request
523 struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
524 struct wrepl_packet *packet)
526 struct wrepl_request *req;
527 struct wrepl_wrap wrap;
529 req = talloc_zero(wrepl_socket, struct wrepl_request);
530 if (req == NULL) goto failed;
532 if (wrepl_socket->dead) {
533 req->wrepl_socket = wrepl_socket;
534 req->state = WREPL_REQUEST_ERROR;
535 req->status = NT_STATUS_INVALID_CONNECTION;
536 wrepl_request_trigger(req);
540 req->wrepl_socket = wrepl_socket;
541 req->state = WREPL_REQUEST_SEND;
543 wrap.packet = *packet;
544 req->status = ndr_push_struct_blob(&req->buffer, req, &wrap,
545 (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
546 if (!NT_STATUS_IS_OK(req->status)) goto failed;
549 DEBUG(10,("Sending WINS packet of length %d\n", (int)req->buffer.length));
550 NDR_PRINT_DEBUG(wrepl_packet, &wrap.packet);
553 DLIST_ADD(wrepl_socket->send_queue, req);
555 talloc_set_destructor(req, wrepl_request_destructor);
557 if (wrepl_socket->request_timeout > 0) {
558 req->te = event_add_timed(wrepl_socket->event_ctx, req,
559 timeval_current_ofs(wrepl_socket->request_timeout, 0),
560 wrepl_request_timeout_handler, req);
563 EVENT_FD_WRITEABLE(wrepl_socket->fde);
573 receive a generic WINS replication reply
575 NTSTATUS wrepl_request_recv(struct wrepl_request *req,
577 struct wrepl_packet **packet)
579 NTSTATUS status = wrepl_request_wait(req);
580 if (NT_STATUS_IS_OK(status)) {
581 *packet = talloc_steal(mem_ctx, req->packet);
588 a full WINS replication request/response
590 NTSTATUS wrepl_request(struct wrepl_socket *wrepl_socket,
592 struct wrepl_packet *req_packet,
593 struct wrepl_packet **reply_packet)
595 struct wrepl_request *req = wrepl_request_send(wrepl_socket, req_packet);
596 return wrepl_request_recv(req, mem_ctx, reply_packet);
601 setup an association - send
603 struct wrepl_request *wrepl_associate_send(struct wrepl_socket *wrepl_socket,
604 struct wrepl_associate *io)
606 struct wrepl_packet *packet;
607 struct wrepl_request *req;
609 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
610 if (packet == NULL) return NULL;
612 packet->opcode = WREPL_OPCODE_BITS;
613 packet->mess_type = WREPL_START_ASSOCIATION;
614 packet->message.start.minor_version = 2;
615 packet->message.start.major_version = 5;
617 req = wrepl_request_send(wrepl_socket, packet);
625 setup an association - recv
627 NTSTATUS wrepl_associate_recv(struct wrepl_request *req,
628 struct wrepl_associate *io)
630 struct wrepl_packet *packet=NULL;
632 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
633 NT_STATUS_NOT_OK_RETURN(status);
634 if (packet->mess_type != WREPL_START_ASSOCIATION_REPLY) {
635 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
637 if (NT_STATUS_IS_OK(status)) {
638 io->out.assoc_ctx = packet->message.start_reply.assoc_ctx;
645 setup an association - sync api
647 NTSTATUS wrepl_associate(struct wrepl_socket *wrepl_socket,
648 struct wrepl_associate *io)
650 struct wrepl_request *req = wrepl_associate_send(wrepl_socket, io);
651 return wrepl_associate_recv(req, io);
656 stop an association - send
658 struct wrepl_request *wrepl_associate_stop_send(struct wrepl_socket *wrepl_socket,
659 struct wrepl_associate_stop *io)
661 struct wrepl_packet *packet;
662 struct wrepl_request *req;
664 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
665 if (packet == NULL) return NULL;
667 packet->opcode = WREPL_OPCODE_BITS;
668 packet->assoc_ctx = io->in.assoc_ctx;
669 packet->mess_type = WREPL_STOP_ASSOCIATION;
670 packet->message.stop.reason = io->in.reason;
672 req = wrepl_request_send(wrepl_socket, packet);
674 if (req && io->in.reason == 0) {
675 req->send_only = True;
676 req->disconnect_after_send = True;
685 stop an association - recv
687 NTSTATUS wrepl_associate_stop_recv(struct wrepl_request *req,
688 struct wrepl_associate_stop *io)
690 struct wrepl_packet *packet=NULL;
692 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
693 NT_STATUS_NOT_OK_RETURN(status);
699 setup an association - sync api
701 NTSTATUS wrepl_associate_stop(struct wrepl_socket *wrepl_socket,
702 struct wrepl_associate_stop *io)
704 struct wrepl_request *req = wrepl_associate_stop_send(wrepl_socket, io);
705 return wrepl_associate_stop_recv(req, io);
709 fetch the partner tables - send
711 struct wrepl_request *wrepl_pull_table_send(struct wrepl_socket *wrepl_socket,
712 struct wrepl_pull_table *io)
714 struct wrepl_packet *packet;
715 struct wrepl_request *req;
717 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
718 if (packet == NULL) return NULL;
720 packet->opcode = WREPL_OPCODE_BITS;
721 packet->assoc_ctx = io->in.assoc_ctx;
722 packet->mess_type = WREPL_REPLICATION;
723 packet->message.replication.command = WREPL_REPL_TABLE_QUERY;
725 req = wrepl_request_send(wrepl_socket, packet);
734 fetch the partner tables - recv
736 NTSTATUS wrepl_pull_table_recv(struct wrepl_request *req,
738 struct wrepl_pull_table *io)
740 struct wrepl_packet *packet=NULL;
742 struct wrepl_table *table;
745 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
746 NT_STATUS_NOT_OK_RETURN(status);
747 if (packet->mess_type != WREPL_REPLICATION) {
748 status = NT_STATUS_NETWORK_ACCESS_DENIED;
749 } else if (packet->message.replication.command != WREPL_REPL_TABLE_REPLY) {
750 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
752 if (!NT_STATUS_IS_OK(status)) goto failed;
754 table = &packet->message.replication.info.table;
755 io->out.num_partners = table->partner_count;
756 io->out.partners = talloc_steal(mem_ctx, table->partners);
757 for (i=0;i<io->out.num_partners;i++) {
758 talloc_steal(io->out.partners, io->out.partners[i].address);
768 fetch the partner table - sync api
770 NTSTATUS wrepl_pull_table(struct wrepl_socket *wrepl_socket,
772 struct wrepl_pull_table *io)
774 struct wrepl_request *req = wrepl_pull_table_send(wrepl_socket, io);
775 return wrepl_pull_table_recv(req, mem_ctx, io);
780 fetch the names for a WINS partner - send
782 struct wrepl_request *wrepl_pull_names_send(struct wrepl_socket *wrepl_socket,
783 struct wrepl_pull_names *io)
785 struct wrepl_packet *packet;
786 struct wrepl_request *req;
788 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
789 if (packet == NULL) return NULL;
791 packet->opcode = WREPL_OPCODE_BITS;
792 packet->assoc_ctx = io->in.assoc_ctx;
793 packet->mess_type = WREPL_REPLICATION;
794 packet->message.replication.command = WREPL_REPL_SEND_REQUEST;
795 packet->message.replication.info.owner = io->in.partner;
797 req = wrepl_request_send(wrepl_socket, packet);
805 fetch the names for a WINS partner - recv
807 NTSTATUS wrepl_pull_names_recv(struct wrepl_request *req,
809 struct wrepl_pull_names *io)
811 struct wrepl_packet *packet=NULL;
815 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
816 NT_STATUS_NOT_OK_RETURN(status);
817 if (packet->mess_type != WREPL_REPLICATION ||
818 packet->message.replication.command != WREPL_REPL_SEND_REPLY) {
819 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
821 if (!NT_STATUS_IS_OK(status)) goto failed;
823 io->out.num_names = packet->message.replication.info.reply.num_names;
825 io->out.names = talloc_array(packet, struct wrepl_name, io->out.num_names);
826 if (io->out.names == NULL) goto nomem;
828 /* convert the list of names and addresses to a sane format */
829 for (i=0;i<io->out.num_names;i++) {
830 struct wrepl_wins_name *wname = &packet->message.replication.info.reply.names[i];
831 struct wrepl_name *name = &io->out.names[i];
833 name->name = *wname->name;
834 talloc_steal(io->out.names, wname->name);
835 name->type = WREPL_NAME_TYPE(wname->flags);
836 name->state = WREPL_NAME_STATE(wname->flags);
837 name->node = WREPL_NAME_NODE(wname->flags);
838 name->is_static = WREPL_NAME_IS_STATIC(wname->flags);
839 name->raw_flags = wname->flags;
840 name->version_id= wname->id;
841 name->owner = talloc_strdup(io->out.names, io->in.partner.address);
842 if (name->owner == NULL) goto nomem;
844 /* trying to save 1 or 2 bytes on the wire isn't a good idea */
845 if (wname->flags & 2) {
848 name->num_addresses = wname->addresses.addresses.num_ips;
849 name->addresses = talloc_array(io->out.names,
850 struct wrepl_address,
851 name->num_addresses);
852 if (name->addresses == NULL) goto nomem;
853 for (j=0;j<name->num_addresses;j++) {
854 name->addresses[j].owner =
855 talloc_steal(name->addresses,
856 wname->addresses.addresses.ips[j].owner);
857 name->addresses[j].address =
858 talloc_steal(name->addresses,
859 wname->addresses.addresses.ips[j].ip);
862 name->num_addresses = 1;
863 name->addresses = talloc(io->out.names, struct wrepl_address);
864 if (name->addresses == NULL) goto nomem;
865 name->addresses[0].owner = talloc_strdup(name->addresses,io->in.partner.address);
866 if (name->addresses[0].owner == NULL) goto nomem;
867 name->addresses[0].address = talloc_steal(name->addresses,
868 wname->addresses.ip);
872 talloc_steal(mem_ctx, io->out.names);
876 status = NT_STATUS_NO_MEMORY;
885 fetch the names for a WINS partner - sync api
887 NTSTATUS wrepl_pull_names(struct wrepl_socket *wrepl_socket,
889 struct wrepl_pull_names *io)
891 struct wrepl_request *req = wrepl_pull_names_send(wrepl_socket, io);
892 return wrepl_pull_names_recv(req, mem_ctx, io);