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 "lib/util/dlinklist.h"
26 #include "lib/socket/socket.h"
27 #include "libcli/wrepl/winsrepl.h"
28 #include "librpc/gen_ndr/ndr_winsrepl.h"
29 #include "lib/stream/packet.h"
30 #include "libcli/composite/composite.h"
31 #include "system/network.h"
32 #include "lib/socket/netif.h"
34 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status);
37 mark all pending requests as dead - called when a socket error happens
39 static void wrepl_socket_dead(struct wrepl_socket *wrepl_socket, NTSTATUS status)
41 wrepl_socket->dead = True;
43 if (wrepl_socket->packet) {
44 packet_recv_disable(wrepl_socket->packet);
45 packet_set_fde(wrepl_socket->packet, NULL);
46 packet_set_socket(wrepl_socket->packet, NULL);
49 if (wrepl_socket->event.fde) {
50 talloc_free(wrepl_socket->event.fde);
51 wrepl_socket->event.fde = NULL;
54 if (wrepl_socket->sock) {
55 talloc_free(wrepl_socket->sock);
56 wrepl_socket->sock = NULL;
59 if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) {
60 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
62 while (wrepl_socket->recv_queue) {
63 struct wrepl_request *req = wrepl_socket->recv_queue;
64 DLIST_REMOVE(wrepl_socket->recv_queue, req);
65 wrepl_request_finished(req, status);
68 talloc_set_destructor(wrepl_socket, NULL);
69 if (wrepl_socket->free_skipped) {
70 talloc_free(wrepl_socket);
74 static void wrepl_request_timeout_handler(struct event_context *ev, struct timed_event *te,
75 struct timeval t, void *ptr)
77 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
78 wrepl_socket_dead(req->wrepl_socket, NT_STATUS_IO_TIMEOUT);
84 static NTSTATUS wrepl_finish_recv(void *private, DATA_BLOB packet_blob_in)
86 struct wrepl_socket *wrepl_socket = talloc_get_type(private, struct wrepl_socket);
87 struct wrepl_request *req = wrepl_socket->recv_queue;
91 DEBUG(1,("Received unexpected WINS packet of length %u!\n",
92 (unsigned)packet_blob_in.length));
93 return NT_STATUS_INVALID_NETWORK_RESPONSE;
96 req->packet = talloc(req, struct wrepl_packet);
97 NT_STATUS_HAVE_NO_MEMORY(req->packet);
99 blob.data = packet_blob_in.data + 4;
100 blob.length = packet_blob_in.length - 4;
102 /* we have a full request - parse it */
103 req->status = ndr_pull_struct_blob(&blob,
104 req->packet, req->packet,
105 (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
106 if (!NT_STATUS_IS_OK(req->status)) {
107 wrepl_request_finished(req, req->status);
112 DEBUG(10,("Received WINS packet of length %u\n",
113 (unsigned)packet_blob_in.length));
114 NDR_PRINT_DEBUG(wrepl_packet, req->packet);
117 wrepl_request_finished(req, req->status);
122 handler for winrepl events
124 static void wrepl_handler(struct event_context *ev, struct fd_event *fde,
125 uint16_t flags, void *private)
127 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
128 struct wrepl_socket);
129 if (flags & EVENT_FD_READ) {
130 packet_recv(wrepl_socket->packet);
133 if (flags & EVENT_FD_WRITE) {
134 packet_queue_run(wrepl_socket->packet);
138 static void wrepl_error(void *private, NTSTATUS status)
140 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
141 struct wrepl_socket);
142 wrepl_socket_dead(wrepl_socket, status);
147 destroy a wrepl_socket destructor
149 static int wrepl_socket_destructor(struct wrepl_socket *sock)
152 sock->free_skipped = True;
155 wrepl_socket_dead(sock, NT_STATUS_LOCAL_DISCONNECT);
160 initialise a wrepl_socket. The event_ctx is optional, if provided then
161 operations will use that event context
163 struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx,
164 struct event_context *event_ctx)
166 struct wrepl_socket *wrepl_socket;
169 wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
170 if (!wrepl_socket) return NULL;
172 if (event_ctx == NULL) {
173 wrepl_socket->event.ctx = event_context_init(wrepl_socket);
175 wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx);
177 if (!wrepl_socket->event.ctx) goto failed;
179 status = socket_create("ip", SOCKET_TYPE_STREAM, &wrepl_socket->sock, 0);
180 if (!NT_STATUS_IS_OK(status)) goto failed;
182 talloc_steal(wrepl_socket, wrepl_socket->sock);
184 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
186 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
191 talloc_free(wrepl_socket);
196 initialise a wrepl_socket from an already existing connection
198 struct wrepl_socket *wrepl_socket_merge(TALLOC_CTX *mem_ctx,
199 struct event_context *event_ctx,
200 struct socket_context *sock,
201 struct packet_context *pack)
203 struct wrepl_socket *wrepl_socket;
205 wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
206 if (wrepl_socket == NULL) goto failed;
208 wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx);
209 if (wrepl_socket->event.ctx == NULL) goto failed;
211 wrepl_socket->sock = sock;
212 talloc_steal(wrepl_socket, wrepl_socket->sock);
215 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
217 wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
218 socket_get_fd(wrepl_socket->sock),
220 wrepl_handler, wrepl_socket);
221 if (wrepl_socket->event.fde == NULL) {
225 wrepl_socket->packet = pack;
226 talloc_steal(wrepl_socket, wrepl_socket->packet);
227 packet_set_private(wrepl_socket->packet, wrepl_socket);
228 packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
229 packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
230 packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
231 packet_set_error_handler(wrepl_socket->packet, wrepl_error);
232 packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
233 packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
234 packet_set_serialise(wrepl_socket->packet);
236 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
241 talloc_free(wrepl_socket);
246 destroy a wrepl_request
248 static int wrepl_request_destructor(struct wrepl_request *req)
250 if (req->state == WREPL_REQUEST_RECV) {
251 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
253 req->state = WREPL_REQUEST_ERROR;
258 wait for a request to complete
260 static NTSTATUS wrepl_request_wait(struct wrepl_request *req)
262 NT_STATUS_HAVE_NO_MEMORY(req);
263 while (req->state < WREPL_REQUEST_DONE) {
264 event_loop_once(req->wrepl_socket->event.ctx);
269 struct wrepl_connect_state {
270 struct composite_context *result;
271 struct wrepl_socket *wrepl_socket;
272 struct composite_context *creq;
276 handler for winrepl connection completion
278 static void wrepl_connect_handler(struct composite_context *creq)
280 struct wrepl_connect_state *state = talloc_get_type(creq->async.private_data,
281 struct wrepl_connect_state);
282 struct wrepl_socket *wrepl_socket = state->wrepl_socket;
283 struct composite_context *result = state->result;
285 result->status = socket_connect_recv(state->creq);
286 if (!composite_is_ok(result)) return;
288 wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
289 socket_get_fd(wrepl_socket->sock),
291 wrepl_handler, wrepl_socket);
292 if (composite_nomem(wrepl_socket->event.fde, result)) return;
294 /* setup the stream -> packet parser */
295 wrepl_socket->packet = packet_init(wrepl_socket);
296 if (composite_nomem(wrepl_socket->packet, result)) return;
297 packet_set_private(wrepl_socket->packet, wrepl_socket);
298 packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
299 packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
300 packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
301 packet_set_error_handler(wrepl_socket->packet, wrepl_error);
302 packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
303 packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
304 packet_set_serialise(wrepl_socket->packet);
306 composite_done(result);
310 connect a wrepl_socket to a WINS server
312 struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
313 const char *our_ip, const char *peer_ip)
315 struct composite_context *result;
316 struct wrepl_connect_state *state;
317 struct socket_address *peer, *us;
319 result = talloc_zero(wrepl_socket, struct composite_context);
320 if (!result) return NULL;
322 result->state = COMPOSITE_STATE_IN_PROGRESS;
323 result->event_ctx = wrepl_socket->event.ctx;
325 state = talloc_zero(result, struct wrepl_connect_state);
326 if (composite_nomem(state, result)) return result;
327 result->private_data = state;
328 state->result = result;
329 state->wrepl_socket = wrepl_socket;
332 our_ip = iface_best_ip(peer_ip);
335 us = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
337 if (composite_nomem(us, result)) return result;
339 peer = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
340 peer_ip, WINS_REPLICATION_PORT);
341 if (composite_nomem(peer, result)) return result;
343 state->creq = socket_connect_send(wrepl_socket->sock, us, peer,
344 0, wrepl_socket->event.ctx);
345 composite_continue(result, state->creq, wrepl_connect_handler, state);
350 connect a wrepl_socket to a WINS server - recv side
352 NTSTATUS wrepl_connect_recv(struct composite_context *result)
354 struct wrepl_connect_state *state = talloc_get_type(result->private_data,
355 struct wrepl_connect_state);
356 struct wrepl_socket *wrepl_socket = state->wrepl_socket;
357 NTSTATUS status = composite_wait(result);
359 if (!NT_STATUS_IS_OK(status)) {
360 wrepl_socket_dead(wrepl_socket, status);
368 connect a wrepl_socket to a WINS server - sync API
370 NTSTATUS wrepl_connect(struct wrepl_socket *wrepl_socket, const char *our_ip, const char *peer_ip)
372 struct composite_context *c_req = wrepl_connect_send(wrepl_socket, our_ip, peer_ip);
373 return wrepl_connect_recv(c_req);
377 callback from wrepl_request_trigger()
379 static void wrepl_request_trigger_handler(struct event_context *ev, struct timed_event *te,
380 struct timeval t, void *ptr)
382 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
389 trigger an immediate event on a wrepl_request
390 the return value should only be used in wrepl_request_send()
391 this is the only place where req->trigger is True
393 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status)
395 struct timed_event *te;
397 if (req->state == WREPL_REQUEST_RECV) {
398 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
401 if (!NT_STATUS_IS_OK(status)) {
402 req->state = WREPL_REQUEST_ERROR;
404 req->state = WREPL_REQUEST_DONE;
407 req->status = status;
410 req->trigger = False;
411 /* a zero timeout means immediate */
412 te = event_add_timed(req->wrepl_socket->event.ctx,
414 wrepl_request_trigger_handler, req);
428 struct wrepl_send_ctrl_state {
429 struct wrepl_send_ctrl ctrl;
430 struct wrepl_request *req;
431 struct wrepl_socket *wrepl_sock;
434 static int wrepl_send_ctrl_destructor(struct wrepl_send_ctrl_state *s)
436 struct wrepl_request *req = s->wrepl_sock->recv_queue;
438 /* check if the request is still in WREPL_STATE_RECV,
439 * we need this here because the caller has may called
440 * talloc_free(req) and wrepl_send_ctrl_state isn't
441 * a talloc child of the request, so our s->req pointer
444 for (; req; req = req->next) {
445 if (req == s->req) break;
449 /* here, we need to make sure the async request handler is called
450 * later in the next event_loop and now now
453 wrepl_request_finished(req, NT_STATUS_OK);
455 if (s->ctrl.disconnect_after_send) {
456 wrepl_socket_dead(s->wrepl_sock, NT_STATUS_LOCAL_DISCONNECT);
463 send a generic wins replication request
465 struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
466 struct wrepl_packet *packet,
467 struct wrepl_send_ctrl *ctrl)
469 struct wrepl_request *req;
470 struct wrepl_wrap wrap;
473 req = talloc_zero(wrepl_socket, struct wrepl_request);
474 if (!req) return NULL;
475 req->wrepl_socket = wrepl_socket;
476 req->state = WREPL_REQUEST_RECV;
479 DLIST_ADD_END(wrepl_socket->recv_queue, req, struct wrepl_request *);
480 talloc_set_destructor(req, wrepl_request_destructor);
482 if (wrepl_socket->dead) {
483 return wrepl_request_finished(req, NT_STATUS_INVALID_CONNECTION);
486 wrap.packet = *packet;
487 req->status = ndr_push_struct_blob(&blob, req, &wrap,
488 (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
489 if (!NT_STATUS_IS_OK(req->status)) {
490 return wrepl_request_finished(req, req->status);
494 DEBUG(10,("Sending WINS packet of length %u\n",
495 (unsigned)blob.length));
496 NDR_PRINT_DEBUG(wrepl_packet, &wrap.packet);
499 if (wrepl_socket->request_timeout > 0) {
500 req->te = event_add_timed(wrepl_socket->event.ctx, req,
501 timeval_current_ofs(wrepl_socket->request_timeout, 0),
502 wrepl_request_timeout_handler, req);
503 if (!req->te) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
506 if (ctrl && (ctrl->send_only || ctrl->disconnect_after_send)) {
507 struct wrepl_send_ctrl_state *s = talloc(blob.data, struct wrepl_send_ctrl_state);
508 if (!s) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
511 s->wrepl_sock = wrepl_socket;
512 talloc_set_destructor(s, wrepl_send_ctrl_destructor);
515 req->status = packet_send(wrepl_socket->packet, blob);
516 if (!NT_STATUS_IS_OK(req->status)) {
517 return wrepl_request_finished(req, req->status);
520 req->trigger = False;
525 receive a generic WINS replication reply
527 NTSTATUS wrepl_request_recv(struct wrepl_request *req,
529 struct wrepl_packet **packet)
531 NTSTATUS status = wrepl_request_wait(req);
532 if (NT_STATUS_IS_OK(status) && packet) {
533 *packet = talloc_steal(mem_ctx, req->packet);
540 a full WINS replication request/response
542 NTSTATUS wrepl_request(struct wrepl_socket *wrepl_socket,
544 struct wrepl_packet *req_packet,
545 struct wrepl_packet **reply_packet)
547 struct wrepl_request *req = wrepl_request_send(wrepl_socket, req_packet, NULL);
548 return wrepl_request_recv(req, mem_ctx, reply_packet);
553 setup an association - send
555 struct wrepl_request *wrepl_associate_send(struct wrepl_socket *wrepl_socket,
556 struct wrepl_associate *io)
558 struct wrepl_packet *packet;
559 struct wrepl_request *req;
561 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
562 if (packet == NULL) return NULL;
564 packet->opcode = WREPL_OPCODE_BITS;
565 packet->mess_type = WREPL_START_ASSOCIATION;
566 packet->message.start.minor_version = 2;
567 packet->message.start.major_version = 5;
570 * nt4 uses 41 bytes for the start_association call
571 * so do it the same and as we don't know th emeanings of this bytes
572 * we just send zeros and nt4, w2k and w2k3 seems to be happy with this
574 * if we don't do this nt4 uses an old version of the wins replication protocol
575 * and that would break nt4 <-> samba replication
577 packet->padding = data_blob_talloc(packet, NULL, 21);
578 if (packet->padding.data == NULL) {
582 memset(packet->padding.data, 0, packet->padding.length);
584 req = wrepl_request_send(wrepl_socket, packet, NULL);
592 setup an association - recv
594 NTSTATUS wrepl_associate_recv(struct wrepl_request *req,
595 struct wrepl_associate *io)
597 struct wrepl_packet *packet=NULL;
599 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
600 NT_STATUS_NOT_OK_RETURN(status);
601 if (packet->mess_type != WREPL_START_ASSOCIATION_REPLY) {
602 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
604 if (NT_STATUS_IS_OK(status)) {
605 io->out.assoc_ctx = packet->message.start_reply.assoc_ctx;
612 setup an association - sync api
614 NTSTATUS wrepl_associate(struct wrepl_socket *wrepl_socket,
615 struct wrepl_associate *io)
617 struct wrepl_request *req = wrepl_associate_send(wrepl_socket, io);
618 return wrepl_associate_recv(req, io);
623 stop an association - send
625 struct wrepl_request *wrepl_associate_stop_send(struct wrepl_socket *wrepl_socket,
626 struct wrepl_associate_stop *io)
628 struct wrepl_packet *packet;
629 struct wrepl_request *req;
630 struct wrepl_send_ctrl ctrl;
632 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
633 if (packet == NULL) return NULL;
635 packet->opcode = WREPL_OPCODE_BITS;
636 packet->assoc_ctx = io->in.assoc_ctx;
637 packet->mess_type = WREPL_STOP_ASSOCIATION;
638 packet->message.stop.reason = io->in.reason;
641 if (io->in.reason == 0) {
642 ctrl.send_only = True;
643 ctrl.disconnect_after_send = True;
646 req = wrepl_request_send(wrepl_socket, packet, &ctrl);
654 stop an association - recv
656 NTSTATUS wrepl_associate_stop_recv(struct wrepl_request *req,
657 struct wrepl_associate_stop *io)
659 struct wrepl_packet *packet=NULL;
661 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
662 NT_STATUS_NOT_OK_RETURN(status);
668 setup an association - sync api
670 NTSTATUS wrepl_associate_stop(struct wrepl_socket *wrepl_socket,
671 struct wrepl_associate_stop *io)
673 struct wrepl_request *req = wrepl_associate_stop_send(wrepl_socket, io);
674 return wrepl_associate_stop_recv(req, io);
678 fetch the partner tables - send
680 struct wrepl_request *wrepl_pull_table_send(struct wrepl_socket *wrepl_socket,
681 struct wrepl_pull_table *io)
683 struct wrepl_packet *packet;
684 struct wrepl_request *req;
686 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
687 if (packet == NULL) return NULL;
689 packet->opcode = WREPL_OPCODE_BITS;
690 packet->assoc_ctx = io->in.assoc_ctx;
691 packet->mess_type = WREPL_REPLICATION;
692 packet->message.replication.command = WREPL_REPL_TABLE_QUERY;
694 req = wrepl_request_send(wrepl_socket, packet, NULL);
703 fetch the partner tables - recv
705 NTSTATUS wrepl_pull_table_recv(struct wrepl_request *req,
707 struct wrepl_pull_table *io)
709 struct wrepl_packet *packet=NULL;
711 struct wrepl_table *table;
714 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
715 NT_STATUS_NOT_OK_RETURN(status);
716 if (packet->mess_type != WREPL_REPLICATION) {
717 status = NT_STATUS_NETWORK_ACCESS_DENIED;
718 } else if (packet->message.replication.command != WREPL_REPL_TABLE_REPLY) {
719 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
721 if (!NT_STATUS_IS_OK(status)) goto failed;
723 table = &packet->message.replication.info.table;
724 io->out.num_partners = table->partner_count;
725 io->out.partners = talloc_steal(mem_ctx, table->partners);
726 for (i=0;i<io->out.num_partners;i++) {
727 talloc_steal(io->out.partners, io->out.partners[i].address);
737 fetch the partner table - sync api
739 NTSTATUS wrepl_pull_table(struct wrepl_socket *wrepl_socket,
741 struct wrepl_pull_table *io)
743 struct wrepl_request *req = wrepl_pull_table_send(wrepl_socket, io);
744 return wrepl_pull_table_recv(req, mem_ctx, io);
749 fetch the names for a WINS partner - send
751 struct wrepl_request *wrepl_pull_names_send(struct wrepl_socket *wrepl_socket,
752 struct wrepl_pull_names *io)
754 struct wrepl_packet *packet;
755 struct wrepl_request *req;
757 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
758 if (packet == NULL) return NULL;
760 packet->opcode = WREPL_OPCODE_BITS;
761 packet->assoc_ctx = io->in.assoc_ctx;
762 packet->mess_type = WREPL_REPLICATION;
763 packet->message.replication.command = WREPL_REPL_SEND_REQUEST;
764 packet->message.replication.info.owner = io->in.partner;
766 req = wrepl_request_send(wrepl_socket, packet, NULL);
774 fetch the names for a WINS partner - recv
776 NTSTATUS wrepl_pull_names_recv(struct wrepl_request *req,
778 struct wrepl_pull_names *io)
780 struct wrepl_packet *packet=NULL;
784 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
785 NT_STATUS_NOT_OK_RETURN(status);
786 if (packet->mess_type != WREPL_REPLICATION ||
787 packet->message.replication.command != WREPL_REPL_SEND_REPLY) {
788 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
790 if (!NT_STATUS_IS_OK(status)) goto failed;
792 io->out.num_names = packet->message.replication.info.reply.num_names;
794 io->out.names = talloc_array(packet, struct wrepl_name, io->out.num_names);
795 if (io->out.names == NULL) goto nomem;
797 /* convert the list of names and addresses to a sane format */
798 for (i=0;i<io->out.num_names;i++) {
799 struct wrepl_wins_name *wname = &packet->message.replication.info.reply.names[i];
800 struct wrepl_name *name = &io->out.names[i];
802 name->name = *wname->name;
803 talloc_steal(io->out.names, wname->name);
804 name->type = WREPL_NAME_TYPE(wname->flags);
805 name->state = WREPL_NAME_STATE(wname->flags);
806 name->node = WREPL_NAME_NODE(wname->flags);
807 name->is_static = WREPL_NAME_IS_STATIC(wname->flags);
808 name->raw_flags = wname->flags;
809 name->version_id= wname->id;
810 name->owner = talloc_strdup(io->out.names, io->in.partner.address);
811 if (name->owner == NULL) goto nomem;
813 /* trying to save 1 or 2 bytes on the wire isn't a good idea */
814 if (wname->flags & 2) {
817 name->num_addresses = wname->addresses.addresses.num_ips;
818 name->addresses = talloc_array(io->out.names,
819 struct wrepl_address,
820 name->num_addresses);
821 if (name->addresses == NULL) goto nomem;
822 for (j=0;j<name->num_addresses;j++) {
823 name->addresses[j].owner =
824 talloc_steal(name->addresses,
825 wname->addresses.addresses.ips[j].owner);
826 name->addresses[j].address =
827 talloc_steal(name->addresses,
828 wname->addresses.addresses.ips[j].ip);
831 name->num_addresses = 1;
832 name->addresses = talloc(io->out.names, struct wrepl_address);
833 if (name->addresses == NULL) goto nomem;
834 name->addresses[0].owner = talloc_strdup(name->addresses,io->in.partner.address);
835 if (name->addresses[0].owner == NULL) goto nomem;
836 name->addresses[0].address = talloc_steal(name->addresses,
837 wname->addresses.ip);
841 talloc_steal(mem_ctx, io->out.names);
845 status = NT_STATUS_NO_MEMORY;
854 fetch the names for a WINS partner - sync api
856 NTSTATUS wrepl_pull_names(struct wrepl_socket *wrepl_socket,
858 struct wrepl_pull_names *io)
860 struct wrepl_request *req = wrepl_pull_names_send(wrepl_socket, io);
861 return wrepl_pull_names_recv(req, mem_ctx, io);