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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "lib/events/events.h"
24 #include "lib/util/dlinklist.h"
25 #include "lib/socket/socket.h"
26 #include "libcli/wrepl/winsrepl.h"
27 #include "librpc/gen_ndr/ndr_winsrepl.h"
28 #include "lib/stream/packet.h"
29 #include "libcli/composite/composite.h"
30 #include "system/network.h"
31 #include "lib/socket/netif.h"
32 #include "param/param.h"
33 #include "libcli/resolve/resolve.h"
35 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status);
38 mark all pending requests as dead - called when a socket error happens
40 static void wrepl_socket_dead(struct wrepl_socket *wrepl_socket, NTSTATUS status)
42 wrepl_socket->dead = true;
44 if (wrepl_socket->packet) {
45 packet_recv_disable(wrepl_socket->packet);
46 packet_set_fde(wrepl_socket->packet, NULL);
47 packet_set_socket(wrepl_socket->packet, NULL);
50 if (wrepl_socket->event.fde) {
51 talloc_free(wrepl_socket->event.fde);
52 wrepl_socket->event.fde = NULL;
55 if (wrepl_socket->sock) {
56 talloc_free(wrepl_socket->sock);
57 wrepl_socket->sock = NULL;
60 if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) {
61 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
63 while (wrepl_socket->recv_queue) {
64 struct wrepl_request *req = wrepl_socket->recv_queue;
65 DLIST_REMOVE(wrepl_socket->recv_queue, req);
66 wrepl_request_finished(req, status);
69 talloc_set_destructor(wrepl_socket, NULL);
70 if (wrepl_socket->free_skipped) {
71 talloc_free(wrepl_socket);
75 static void wrepl_request_timeout_handler(struct event_context *ev, struct timed_event *te,
76 struct timeval t, void *ptr)
78 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
79 wrepl_socket_dead(req->wrepl_socket, NT_STATUS_IO_TIMEOUT);
85 static NTSTATUS wrepl_finish_recv(void *private, DATA_BLOB packet_blob_in)
87 struct wrepl_socket *wrepl_socket = talloc_get_type(private, struct wrepl_socket);
88 struct wrepl_request *req = wrepl_socket->recv_queue;
90 enum ndr_err_code ndr_err;
93 DEBUG(1,("Received unexpected WINS packet of length %u!\n",
94 (unsigned)packet_blob_in.length));
95 return NT_STATUS_INVALID_NETWORK_RESPONSE;
98 req->packet = talloc(req, struct wrepl_packet);
99 NT_STATUS_HAVE_NO_MEMORY(req->packet);
101 blob.data = packet_blob_in.data + 4;
102 blob.length = packet_blob_in.length - 4;
104 /* we have a full request - parse it */
105 ndr_err = ndr_pull_struct_blob(&blob,
106 req->packet, req->packet,
107 (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
108 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
109 NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
110 wrepl_request_finished(req, status);
115 DEBUG(10,("Received WINS packet of length %u\n",
116 (unsigned)packet_blob_in.length));
117 NDR_PRINT_DEBUG(wrepl_packet, req->packet);
120 wrepl_request_finished(req, NT_STATUS_OK);
125 handler for winrepl events
127 static void wrepl_handler(struct event_context *ev, struct fd_event *fde,
128 uint16_t flags, void *private)
130 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
131 struct wrepl_socket);
132 if (flags & EVENT_FD_READ) {
133 packet_recv(wrepl_socket->packet);
136 if (flags & EVENT_FD_WRITE) {
137 packet_queue_run(wrepl_socket->packet);
141 static void wrepl_error(void *private, NTSTATUS status)
143 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
144 struct wrepl_socket);
145 wrepl_socket_dead(wrepl_socket, status);
150 destroy a wrepl_socket destructor
152 static int wrepl_socket_destructor(struct wrepl_socket *sock)
155 sock->free_skipped = true;
158 wrepl_socket_dead(sock, NT_STATUS_LOCAL_DISCONNECT);
163 initialise a wrepl_socket. The event_ctx is optional, if provided then
164 operations will use that event context
166 struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx,
167 struct event_context *event_ctx)
169 struct wrepl_socket *wrepl_socket;
172 wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
173 if (!wrepl_socket) return NULL;
175 if (event_ctx == NULL) {
176 wrepl_socket->event.ctx = event_context_init(wrepl_socket);
178 wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx);
180 if (!wrepl_socket->event.ctx) goto failed;
182 status = socket_create("ip", SOCKET_TYPE_STREAM, &wrepl_socket->sock, 0);
183 if (!NT_STATUS_IS_OK(status)) goto failed;
185 talloc_steal(wrepl_socket, wrepl_socket->sock);
187 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
189 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
194 talloc_free(wrepl_socket);
199 initialise a wrepl_socket from an already existing connection
201 struct wrepl_socket *wrepl_socket_merge(TALLOC_CTX *mem_ctx,
202 struct event_context *event_ctx,
203 struct socket_context *sock,
204 struct packet_context *pack)
206 struct wrepl_socket *wrepl_socket;
208 wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
209 if (wrepl_socket == NULL) goto failed;
211 wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx);
212 if (wrepl_socket->event.ctx == NULL) goto failed;
214 wrepl_socket->sock = sock;
215 talloc_steal(wrepl_socket, wrepl_socket->sock);
218 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
220 wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
221 socket_get_fd(wrepl_socket->sock),
223 wrepl_handler, wrepl_socket);
224 if (wrepl_socket->event.fde == NULL) {
228 wrepl_socket->packet = pack;
229 talloc_steal(wrepl_socket, wrepl_socket->packet);
230 packet_set_private(wrepl_socket->packet, wrepl_socket);
231 packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
232 packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
233 packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
234 packet_set_error_handler(wrepl_socket->packet, wrepl_error);
235 packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
236 packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
237 packet_set_serialise(wrepl_socket->packet);
239 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
244 talloc_free(wrepl_socket);
249 destroy a wrepl_request
251 static int wrepl_request_destructor(struct wrepl_request *req)
253 if (req->state == WREPL_REQUEST_RECV) {
254 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
256 req->state = WREPL_REQUEST_ERROR;
261 wait for a request to complete
263 static NTSTATUS wrepl_request_wait(struct wrepl_request *req)
265 NT_STATUS_HAVE_NO_MEMORY(req);
266 while (req->state < WREPL_REQUEST_DONE) {
267 event_loop_once(req->wrepl_socket->event.ctx);
272 struct wrepl_connect_state {
273 struct composite_context *result;
274 struct wrepl_socket *wrepl_socket;
275 struct composite_context *creq;
279 handler for winrepl connection completion
281 static void wrepl_connect_handler(struct composite_context *creq)
283 struct wrepl_connect_state *state = talloc_get_type(creq->async.private_data,
284 struct wrepl_connect_state);
285 struct wrepl_socket *wrepl_socket = state->wrepl_socket;
286 struct composite_context *result = state->result;
288 result->status = socket_connect_recv(state->creq);
289 if (!composite_is_ok(result)) return;
291 wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
292 socket_get_fd(wrepl_socket->sock),
294 wrepl_handler, wrepl_socket);
295 if (composite_nomem(wrepl_socket->event.fde, result)) return;
297 /* setup the stream -> packet parser */
298 wrepl_socket->packet = packet_init(wrepl_socket);
299 if (composite_nomem(wrepl_socket->packet, result)) return;
300 packet_set_private(wrepl_socket->packet, wrepl_socket);
301 packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
302 packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
303 packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
304 packet_set_error_handler(wrepl_socket->packet, wrepl_error);
305 packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
306 packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
307 packet_set_serialise(wrepl_socket->packet);
309 composite_done(result);
313 connect a wrepl_socket to a WINS server
315 struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
316 const char *our_ip, const char *peer_ip)
318 struct composite_context *result;
319 struct wrepl_connect_state *state;
320 struct socket_address *peer, *us;
322 result = talloc_zero(wrepl_socket, struct composite_context);
323 if (!result) return NULL;
325 result->state = COMPOSITE_STATE_IN_PROGRESS;
326 result->event_ctx = wrepl_socket->event.ctx;
328 state = talloc_zero(result, struct wrepl_connect_state);
329 if (composite_nomem(state, result)) return result;
330 result->private_data = state;
331 state->result = result;
332 state->wrepl_socket = wrepl_socket;
335 our_ip = iface_best_ip(global_loadparm, peer_ip);
338 us = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
340 if (composite_nomem(us, result)) return result;
342 peer = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
343 peer_ip, WINS_REPLICATION_PORT);
344 if (composite_nomem(peer, result)) return result;
346 state->creq = socket_connect_send(wrepl_socket->sock, us, peer,
347 0, lp_resolve_context(global_loadparm),
348 wrepl_socket->event.ctx);
349 composite_continue(result, state->creq, wrepl_connect_handler, state);
354 connect a wrepl_socket to a WINS server - recv side
356 NTSTATUS wrepl_connect_recv(struct composite_context *result)
358 struct wrepl_connect_state *state = talloc_get_type(result->private_data,
359 struct wrepl_connect_state);
360 struct wrepl_socket *wrepl_socket = state->wrepl_socket;
361 NTSTATUS status = composite_wait(result);
363 if (!NT_STATUS_IS_OK(status)) {
364 wrepl_socket_dead(wrepl_socket, status);
372 connect a wrepl_socket to a WINS server - sync API
374 NTSTATUS wrepl_connect(struct wrepl_socket *wrepl_socket, const char *our_ip, const char *peer_ip)
376 struct composite_context *c_req = wrepl_connect_send(wrepl_socket, our_ip, peer_ip);
377 return wrepl_connect_recv(c_req);
381 callback from wrepl_request_trigger()
383 static void wrepl_request_trigger_handler(struct event_context *ev, struct timed_event *te,
384 struct timeval t, void *ptr)
386 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
393 trigger an immediate event on a wrepl_request
394 the return value should only be used in wrepl_request_send()
395 this is the only place where req->trigger is true
397 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status)
399 struct timed_event *te;
401 if (req->state == WREPL_REQUEST_RECV) {
402 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
405 if (!NT_STATUS_IS_OK(status)) {
406 req->state = WREPL_REQUEST_ERROR;
408 req->state = WREPL_REQUEST_DONE;
411 req->status = status;
414 req->trigger = false;
415 /* a zero timeout means immediate */
416 te = event_add_timed(req->wrepl_socket->event.ctx,
418 wrepl_request_trigger_handler, req);
432 struct wrepl_send_ctrl_state {
433 struct wrepl_send_ctrl ctrl;
434 struct wrepl_request *req;
435 struct wrepl_socket *wrepl_sock;
438 static int wrepl_send_ctrl_destructor(struct wrepl_send_ctrl_state *s)
440 struct wrepl_request *req = s->wrepl_sock->recv_queue;
442 /* check if the request is still in WREPL_STATE_RECV,
443 * we need this here because the caller has may called
444 * talloc_free(req) and wrepl_send_ctrl_state isn't
445 * a talloc child of the request, so our s->req pointer
448 for (; req; req = req->next) {
449 if (req == s->req) break;
453 /* here, we need to make sure the async request handler is called
454 * later in the next event_loop and now now
457 wrepl_request_finished(req, NT_STATUS_OK);
459 if (s->ctrl.disconnect_after_send) {
460 wrepl_socket_dead(s->wrepl_sock, NT_STATUS_LOCAL_DISCONNECT);
467 send a generic wins replication request
469 struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
470 struct wrepl_packet *packet,
471 struct wrepl_send_ctrl *ctrl)
473 struct wrepl_request *req;
474 struct wrepl_wrap wrap;
477 enum ndr_err_code ndr_err;
479 req = talloc_zero(wrepl_socket, struct wrepl_request);
480 if (!req) return NULL;
481 req->wrepl_socket = wrepl_socket;
482 req->state = WREPL_REQUEST_RECV;
485 DLIST_ADD_END(wrepl_socket->recv_queue, req, struct wrepl_request *);
486 talloc_set_destructor(req, wrepl_request_destructor);
488 if (wrepl_socket->dead) {
489 return wrepl_request_finished(req, NT_STATUS_INVALID_CONNECTION);
492 wrap.packet = *packet;
493 ndr_err = ndr_push_struct_blob(&blob, req, &wrap,
494 (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
495 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
496 status = ndr_map_error2ntstatus(ndr_err);
497 return wrepl_request_finished(req, status);
501 DEBUG(10,("Sending WINS packet of length %u\n",
502 (unsigned)blob.length));
503 NDR_PRINT_DEBUG(wrepl_packet, &wrap.packet);
506 if (wrepl_socket->request_timeout > 0) {
507 req->te = event_add_timed(wrepl_socket->event.ctx, req,
508 timeval_current_ofs(wrepl_socket->request_timeout, 0),
509 wrepl_request_timeout_handler, req);
510 if (!req->te) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
513 if (ctrl && (ctrl->send_only || ctrl->disconnect_after_send)) {
514 struct wrepl_send_ctrl_state *s = talloc(blob.data, struct wrepl_send_ctrl_state);
515 if (!s) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
518 s->wrepl_sock = wrepl_socket;
519 talloc_set_destructor(s, wrepl_send_ctrl_destructor);
522 status = packet_send(wrepl_socket->packet, blob);
523 if (!NT_STATUS_IS_OK(status)) {
524 return wrepl_request_finished(req, status);
527 req->trigger = false;
532 receive a generic WINS replication reply
534 NTSTATUS wrepl_request_recv(struct wrepl_request *req,
536 struct wrepl_packet **packet)
538 NTSTATUS status = wrepl_request_wait(req);
539 if (NT_STATUS_IS_OK(status) && packet) {
540 *packet = talloc_steal(mem_ctx, req->packet);
547 a full WINS replication request/response
549 NTSTATUS wrepl_request(struct wrepl_socket *wrepl_socket,
551 struct wrepl_packet *req_packet,
552 struct wrepl_packet **reply_packet)
554 struct wrepl_request *req = wrepl_request_send(wrepl_socket, req_packet, NULL);
555 return wrepl_request_recv(req, mem_ctx, reply_packet);
560 setup an association - send
562 struct wrepl_request *wrepl_associate_send(struct wrepl_socket *wrepl_socket,
563 struct wrepl_associate *io)
565 struct wrepl_packet *packet;
566 struct wrepl_request *req;
568 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
569 if (packet == NULL) return NULL;
571 packet->opcode = WREPL_OPCODE_BITS;
572 packet->mess_type = WREPL_START_ASSOCIATION;
573 packet->message.start.minor_version = 2;
574 packet->message.start.major_version = 5;
577 * nt4 uses 41 bytes for the start_association call
578 * so do it the same and as we don't know th emeanings of this bytes
579 * we just send zeros and nt4, w2k and w2k3 seems to be happy with this
581 * if we don't do this nt4 uses an old version of the wins replication protocol
582 * and that would break nt4 <-> samba replication
584 packet->padding = data_blob_talloc(packet, NULL, 21);
585 if (packet->padding.data == NULL) {
589 memset(packet->padding.data, 0, packet->padding.length);
591 req = wrepl_request_send(wrepl_socket, packet, NULL);
599 setup an association - recv
601 NTSTATUS wrepl_associate_recv(struct wrepl_request *req,
602 struct wrepl_associate *io)
604 struct wrepl_packet *packet=NULL;
606 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
607 NT_STATUS_NOT_OK_RETURN(status);
608 if (packet->mess_type != WREPL_START_ASSOCIATION_REPLY) {
609 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
611 if (NT_STATUS_IS_OK(status)) {
612 io->out.assoc_ctx = packet->message.start_reply.assoc_ctx;
619 setup an association - sync api
621 NTSTATUS wrepl_associate(struct wrepl_socket *wrepl_socket,
622 struct wrepl_associate *io)
624 struct wrepl_request *req = wrepl_associate_send(wrepl_socket, io);
625 return wrepl_associate_recv(req, io);
630 stop an association - send
632 struct wrepl_request *wrepl_associate_stop_send(struct wrepl_socket *wrepl_socket,
633 struct wrepl_associate_stop *io)
635 struct wrepl_packet *packet;
636 struct wrepl_request *req;
637 struct wrepl_send_ctrl ctrl;
639 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
640 if (packet == NULL) return NULL;
642 packet->opcode = WREPL_OPCODE_BITS;
643 packet->assoc_ctx = io->in.assoc_ctx;
644 packet->mess_type = WREPL_STOP_ASSOCIATION;
645 packet->message.stop.reason = io->in.reason;
648 if (io->in.reason == 0) {
649 ctrl.send_only = true;
650 ctrl.disconnect_after_send = true;
653 req = wrepl_request_send(wrepl_socket, packet, &ctrl);
661 stop an association - recv
663 NTSTATUS wrepl_associate_stop_recv(struct wrepl_request *req,
664 struct wrepl_associate_stop *io)
666 struct wrepl_packet *packet=NULL;
668 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
669 NT_STATUS_NOT_OK_RETURN(status);
675 setup an association - sync api
677 NTSTATUS wrepl_associate_stop(struct wrepl_socket *wrepl_socket,
678 struct wrepl_associate_stop *io)
680 struct wrepl_request *req = wrepl_associate_stop_send(wrepl_socket, io);
681 return wrepl_associate_stop_recv(req, io);
685 fetch the partner tables - send
687 struct wrepl_request *wrepl_pull_table_send(struct wrepl_socket *wrepl_socket,
688 struct wrepl_pull_table *io)
690 struct wrepl_packet *packet;
691 struct wrepl_request *req;
693 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
694 if (packet == NULL) return NULL;
696 packet->opcode = WREPL_OPCODE_BITS;
697 packet->assoc_ctx = io->in.assoc_ctx;
698 packet->mess_type = WREPL_REPLICATION;
699 packet->message.replication.command = WREPL_REPL_TABLE_QUERY;
701 req = wrepl_request_send(wrepl_socket, packet, NULL);
710 fetch the partner tables - recv
712 NTSTATUS wrepl_pull_table_recv(struct wrepl_request *req,
714 struct wrepl_pull_table *io)
716 struct wrepl_packet *packet=NULL;
718 struct wrepl_table *table;
721 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
722 NT_STATUS_NOT_OK_RETURN(status);
723 if (packet->mess_type != WREPL_REPLICATION) {
724 status = NT_STATUS_NETWORK_ACCESS_DENIED;
725 } else if (packet->message.replication.command != WREPL_REPL_TABLE_REPLY) {
726 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
728 if (!NT_STATUS_IS_OK(status)) goto failed;
730 table = &packet->message.replication.info.table;
731 io->out.num_partners = table->partner_count;
732 io->out.partners = talloc_steal(mem_ctx, table->partners);
733 for (i=0;i<io->out.num_partners;i++) {
734 talloc_steal(io->out.partners, io->out.partners[i].address);
744 fetch the partner table - sync api
746 NTSTATUS wrepl_pull_table(struct wrepl_socket *wrepl_socket,
748 struct wrepl_pull_table *io)
750 struct wrepl_request *req = wrepl_pull_table_send(wrepl_socket, io);
751 return wrepl_pull_table_recv(req, mem_ctx, io);
756 fetch the names for a WINS partner - send
758 struct wrepl_request *wrepl_pull_names_send(struct wrepl_socket *wrepl_socket,
759 struct wrepl_pull_names *io)
761 struct wrepl_packet *packet;
762 struct wrepl_request *req;
764 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
765 if (packet == NULL) return NULL;
767 packet->opcode = WREPL_OPCODE_BITS;
768 packet->assoc_ctx = io->in.assoc_ctx;
769 packet->mess_type = WREPL_REPLICATION;
770 packet->message.replication.command = WREPL_REPL_SEND_REQUEST;
771 packet->message.replication.info.owner = io->in.partner;
773 req = wrepl_request_send(wrepl_socket, packet, NULL);
781 fetch the names for a WINS partner - recv
783 NTSTATUS wrepl_pull_names_recv(struct wrepl_request *req,
785 struct wrepl_pull_names *io)
787 struct wrepl_packet *packet=NULL;
791 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
792 NT_STATUS_NOT_OK_RETURN(status);
793 if (packet->mess_type != WREPL_REPLICATION ||
794 packet->message.replication.command != WREPL_REPL_SEND_REPLY) {
795 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
797 if (!NT_STATUS_IS_OK(status)) goto failed;
799 io->out.num_names = packet->message.replication.info.reply.num_names;
801 io->out.names = talloc_array(packet, struct wrepl_name, io->out.num_names);
802 if (io->out.names == NULL) goto nomem;
804 /* convert the list of names and addresses to a sane format */
805 for (i=0;i<io->out.num_names;i++) {
806 struct wrepl_wins_name *wname = &packet->message.replication.info.reply.names[i];
807 struct wrepl_name *name = &io->out.names[i];
809 name->name = *wname->name;
810 talloc_steal(io->out.names, wname->name);
811 name->type = WREPL_NAME_TYPE(wname->flags);
812 name->state = WREPL_NAME_STATE(wname->flags);
813 name->node = WREPL_NAME_NODE(wname->flags);
814 name->is_static = WREPL_NAME_IS_STATIC(wname->flags);
815 name->raw_flags = wname->flags;
816 name->version_id= wname->id;
817 name->owner = talloc_strdup(io->out.names, io->in.partner.address);
818 if (name->owner == NULL) goto nomem;
820 /* trying to save 1 or 2 bytes on the wire isn't a good idea */
821 if (wname->flags & 2) {
824 name->num_addresses = wname->addresses.addresses.num_ips;
825 name->addresses = talloc_array(io->out.names,
826 struct wrepl_address,
827 name->num_addresses);
828 if (name->addresses == NULL) goto nomem;
829 for (j=0;j<name->num_addresses;j++) {
830 name->addresses[j].owner =
831 talloc_steal(name->addresses,
832 wname->addresses.addresses.ips[j].owner);
833 name->addresses[j].address =
834 talloc_steal(name->addresses,
835 wname->addresses.addresses.ips[j].ip);
838 name->num_addresses = 1;
839 name->addresses = talloc(io->out.names, struct wrepl_address);
840 if (name->addresses == NULL) goto nomem;
841 name->addresses[0].owner = talloc_strdup(name->addresses,io->in.partner.address);
842 if (name->addresses[0].owner == NULL) goto nomem;
843 name->addresses[0].address = talloc_steal(name->addresses,
844 wname->addresses.ip);
848 talloc_steal(mem_ctx, io->out.names);
852 status = NT_STATUS_NO_MEMORY;
861 fetch the names for a WINS partner - sync api
863 NTSTATUS wrepl_pull_names(struct wrepl_socket *wrepl_socket,
865 struct wrepl_pull_names *io)
867 struct wrepl_request *req = wrepl_pull_names_send(wrepl_socket, io);
868 return wrepl_pull_names_recv(req, mem_ctx, io);