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"
28 #include "lib/stream/packet.h"
29 #include "libcli/composite/composite.h"
31 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status);
34 mark all pending requests as dead - called when a socket error happens
36 static void wrepl_socket_dead(struct wrepl_socket *wrepl_socket, NTSTATUS status)
38 wrepl_socket->dead = True;
40 if (wrepl_socket->packet) {
41 packet_recv_disable(wrepl_socket->packet);
42 packet_set_fde(wrepl_socket->packet, NULL);
43 packet_set_socket(wrepl_socket->packet, NULL);
46 if (wrepl_socket->event.fde) {
47 talloc_free(wrepl_socket->event.fde);
48 wrepl_socket->event.fde = NULL;
51 if (wrepl_socket->sock) {
52 talloc_free(wrepl_socket->sock);
53 wrepl_socket->sock = NULL;
56 if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) {
57 status = NT_STATUS_UNEXPECTED_NETWORK_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 wrepl_request_finished(req, status);
65 talloc_set_destructor(wrepl_socket, NULL);
66 if (wrepl_socket->free_skipped) {
67 talloc_free(wrepl_socket);
71 static void wrepl_request_timeout_handler(struct event_context *ev, struct timed_event *te,
72 struct timeval t, void *ptr)
74 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
75 wrepl_socket_dead(req->wrepl_socket, NT_STATUS_IO_TIMEOUT);
81 static NTSTATUS wrepl_finish_recv(void *private, DATA_BLOB packet_blob_in)
83 struct wrepl_socket *wrepl_socket = talloc_get_type(private, struct wrepl_socket);
84 struct wrepl_request *req = wrepl_socket->recv_queue;
88 DEBUG(1,("Received unexpected WINS packet of length %u!\n", packet_blob_in.length));
89 return NT_STATUS_INVALID_NETWORK_RESPONSE;
92 req->packet = talloc(req, struct wrepl_packet);
93 NT_STATUS_HAVE_NO_MEMORY(req->packet);
95 blob.data = packet_blob_in.data + 4;
96 blob.length = packet_blob_in.length - 4;
98 /* we have a full request - parse it */
99 req->status = ndr_pull_struct_blob(&blob,
100 req->packet, req->packet,
101 (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
102 if (!NT_STATUS_IS_OK(req->status)) {
103 wrepl_request_finished(req, req->status);
108 DEBUG(10,("Received WINS packet of length %u\n", packet_blob_in.length));
109 NDR_PRINT_DEBUG(wrepl_packet, req->packet);
112 wrepl_request_finished(req, req->status);
117 handler for winrepl events
119 static void wrepl_handler(struct event_context *ev, struct fd_event *fde,
120 uint16_t flags, void *private)
122 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
123 struct wrepl_socket);
124 if (flags & EVENT_FD_READ) {
125 packet_recv(wrepl_socket->packet);
128 if (flags & EVENT_FD_WRITE) {
129 packet_queue_run(wrepl_socket->packet);
133 static void wrepl_error(void *private, NTSTATUS status)
135 struct wrepl_socket *wrepl_socket = talloc_get_type(private,
136 struct wrepl_socket);
137 wrepl_socket_dead(wrepl_socket, status);
142 destroy a wrepl_socket destructor
144 static int wrepl_socket_destructor(void *ptr)
146 struct wrepl_socket *sock = talloc_get_type(ptr, struct wrepl_socket);
148 sock->free_skipped = True;
151 wrepl_socket_dead(sock, NT_STATUS_LOCAL_DISCONNECT);
156 initialise a wrepl_socket. The event_ctx is optional, if provided then
157 operations will use that event context
159 struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx,
160 struct event_context *event_ctx)
162 struct wrepl_socket *wrepl_socket;
165 wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
166 if (!wrepl_socket) return NULL;
168 if (event_ctx == NULL) {
169 wrepl_socket->event.ctx = event_context_init(wrepl_socket);
171 wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx);
173 if (!wrepl_socket->event.ctx) goto failed;
175 status = socket_create("ip", SOCKET_TYPE_STREAM, &wrepl_socket->sock, 0);
176 if (!NT_STATUS_IS_OK(status)) goto failed;
178 talloc_steal(wrepl_socket, wrepl_socket->sock);
180 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
182 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
187 talloc_free(wrepl_socket);
192 initialise a wrepl_socket from an already existing connection
194 struct wrepl_socket *wrepl_socket_merge(TALLOC_CTX *mem_ctx,
195 struct event_context *event_ctx,
196 struct socket_context *sock,
197 struct packet_context *pack)
199 struct wrepl_socket *wrepl_socket;
201 wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
202 if (wrepl_socket == NULL) goto failed;
204 wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx);
205 if (wrepl_socket->event.ctx == NULL) goto failed;
207 wrepl_socket->sock = sock;
208 talloc_steal(wrepl_socket, wrepl_socket->sock);
211 wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT;
213 wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
214 socket_get_fd(wrepl_socket->sock),
216 wrepl_handler, wrepl_socket);
217 if (wrepl_socket->event.fde == NULL) {
221 wrepl_socket->packet = pack;
222 talloc_steal(wrepl_socket, wrepl_socket->packet);
223 packet_set_private(wrepl_socket->packet, wrepl_socket);
224 packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
225 packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
226 packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
227 packet_set_error_handler(wrepl_socket->packet, wrepl_error);
228 packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
229 packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
230 packet_set_serialise(wrepl_socket->packet);
232 talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
237 talloc_free(wrepl_socket);
242 destroy a wrepl_request
244 static int wrepl_request_destructor(void *ptr)
246 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
247 if (req->state == WREPL_REQUEST_RECV) {
248 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
250 req->state = WREPL_REQUEST_ERROR;
255 wait for a request to complete
257 static NTSTATUS wrepl_request_wait(struct wrepl_request *req)
259 NT_STATUS_HAVE_NO_MEMORY(req);
260 while (req->state < WREPL_REQUEST_DONE) {
261 event_loop_once(req->wrepl_socket->event.ctx);
266 struct wrepl_connect_state {
267 struct composite_context *result;
268 struct wrepl_socket *wrepl_socket;
269 struct composite_context *creq;
273 handler for winrepl connection completion
275 static void wrepl_connect_handler(struct composite_context *creq)
277 struct wrepl_connect_state *state = talloc_get_type(creq->async.private_data,
278 struct wrepl_connect_state);
279 struct wrepl_socket *wrepl_socket = state->wrepl_socket;
280 struct composite_context *result = state->result;
282 result->status = socket_connect_recv(state->creq);
283 if (!composite_is_ok(result)) return;
285 wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
286 socket_get_fd(wrepl_socket->sock),
288 wrepl_handler, wrepl_socket);
289 if (composite_nomem(wrepl_socket->event.fde, result)) return;
291 /* setup the stream -> packet parser */
292 wrepl_socket->packet = packet_init(wrepl_socket);
293 if (composite_nomem(wrepl_socket->packet, result)) return;
294 packet_set_private(wrepl_socket->packet, wrepl_socket);
295 packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
296 packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
297 packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
298 packet_set_error_handler(wrepl_socket->packet, wrepl_error);
299 packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
300 packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
301 packet_set_serialise(wrepl_socket->packet);
303 composite_done(result);
307 connect a wrepl_socket to a WINS server
309 struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
310 const char *our_ip, const char *peer_ip)
312 struct composite_context *result;
313 struct wrepl_connect_state *state;
314 struct socket_address *peer, *us;
316 result = talloc_zero(wrepl_socket, struct composite_context);
317 if (!result) return NULL;
319 result->state = COMPOSITE_STATE_IN_PROGRESS;
320 result->event_ctx = wrepl_socket->event.ctx;
322 state = talloc_zero(result, struct wrepl_connect_state);
323 if (composite_nomem(state, result)) return result;
324 result->private_data = state;
325 state->result = result;
326 state->wrepl_socket = wrepl_socket;
329 our_ip = iface_best_ip(peer_ip);
332 us = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
334 if (composite_nomem(us, result)) return result;
336 peer = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
337 peer_ip, WINS_REPLICATION_PORT);
338 if (composite_nomem(peer, result)) return result;
340 state->creq = socket_connect_send(wrepl_socket->sock, us, peer,
341 0, wrepl_socket->event.ctx);
342 composite_continue(result, state->creq, wrepl_connect_handler, state);
347 connect a wrepl_socket to a WINS server - recv side
349 NTSTATUS wrepl_connect_recv(struct composite_context *result)
351 struct wrepl_connect_state *state = talloc_get_type(result->private_data,
352 struct wrepl_connect_state);
353 struct wrepl_socket *wrepl_socket = state->wrepl_socket;
354 NTSTATUS status = composite_wait(result);
356 if (!NT_STATUS_IS_OK(status)) {
357 wrepl_socket_dead(wrepl_socket, status);
365 connect a wrepl_socket to a WINS server - sync API
367 NTSTATUS wrepl_connect(struct wrepl_socket *wrepl_socket, const char *our_ip, const char *peer_ip)
369 struct composite_context *c_req = wrepl_connect_send(wrepl_socket, our_ip, peer_ip);
370 return wrepl_connect_recv(c_req);
374 callback from wrepl_request_trigger()
376 static void wrepl_request_trigger_handler(struct event_context *ev, struct timed_event *te,
377 struct timeval t, void *ptr)
379 struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
386 trigger an immediate event on a wrepl_request
387 the return value should only be used in wrepl_request_send()
388 this is the only place where req->trigger is True
390 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status)
392 struct timed_event *te;
394 if (req->state == WREPL_REQUEST_RECV) {
395 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
398 if (!NT_STATUS_IS_OK(status)) {
399 req->state = WREPL_REQUEST_ERROR;
401 req->state = WREPL_REQUEST_DONE;
404 req->status = status;
407 req->trigger = False;
408 /* a zero timeout means immediate */
409 te = event_add_timed(req->wrepl_socket->event.ctx,
411 wrepl_request_trigger_handler, req);
425 struct wrepl_send_ctrl_state {
426 struct wrepl_send_ctrl ctrl;
427 struct wrepl_request *req;
428 struct wrepl_socket *wrepl_sock;
431 static int wrepl_send_ctrl_destructor(void *ptr)
433 struct wrepl_send_ctrl_state *s = talloc_get_type(ptr, struct wrepl_send_ctrl_state);
434 struct wrepl_request *req = s->wrepl_sock->recv_queue;
436 /* check if the request is still in WREPL_STATE_RECV,
437 * we need this here because the caller has may called
438 * talloc_free(req) and wrepl_send_ctrl_state isn't
439 * a talloc child of the request, so our s->req pointer
442 for (; req; req = req->next) {
443 if (req == s->req) break;
447 /* here, we need to make sure the async request handler is called
448 * later in the next event_loop and now now
451 wrepl_request_finished(req, NT_STATUS_OK);
453 if (s->ctrl.disconnect_after_send) {
454 wrepl_socket_dead(s->wrepl_sock, NT_STATUS_LOCAL_DISCONNECT);
461 send a generic wins replication request
463 struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
464 struct wrepl_packet *packet,
465 struct wrepl_send_ctrl *ctrl)
467 struct wrepl_request *req;
468 struct wrepl_wrap wrap;
471 req = talloc_zero(wrepl_socket, struct wrepl_request);
472 if (!req) return NULL;
473 req->wrepl_socket = wrepl_socket;
474 req->state = WREPL_REQUEST_RECV;
477 DLIST_ADD_END(wrepl_socket->recv_queue, req, struct wrepl_request *);
478 talloc_set_destructor(req, wrepl_request_destructor);
480 if (wrepl_socket->dead) {
481 return wrepl_request_finished(req, NT_STATUS_INVALID_CONNECTION);
484 wrap.packet = *packet;
485 req->status = ndr_push_struct_blob(&blob, req, &wrap,
486 (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
487 if (!NT_STATUS_IS_OK(req->status)) {
488 return wrepl_request_finished(req, req->status);
492 DEBUG(10,("Sending WINS packet of length %u\n", blob.length));
493 NDR_PRINT_DEBUG(wrepl_packet, &wrap.packet);
496 if (wrepl_socket->request_timeout > 0) {
497 req->te = event_add_timed(wrepl_socket->event.ctx, req,
498 timeval_current_ofs(wrepl_socket->request_timeout, 0),
499 wrepl_request_timeout_handler, req);
500 if (!req->te) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
503 if (ctrl && (ctrl->send_only || ctrl->disconnect_after_send)) {
504 struct wrepl_send_ctrl_state *s = talloc(blob.data, struct wrepl_send_ctrl_state);
505 if (!s) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
508 s->wrepl_sock = wrepl_socket;
509 talloc_set_destructor(s, wrepl_send_ctrl_destructor);
512 req->status = packet_send(wrepl_socket->packet, blob);
513 if (!NT_STATUS_IS_OK(req->status)) {
514 return wrepl_request_finished(req, req->status);
517 req->trigger = False;
522 receive a generic WINS replication reply
524 NTSTATUS wrepl_request_recv(struct wrepl_request *req,
526 struct wrepl_packet **packet)
528 NTSTATUS status = wrepl_request_wait(req);
529 if (NT_STATUS_IS_OK(status) && packet) {
530 *packet = talloc_steal(mem_ctx, req->packet);
537 a full WINS replication request/response
539 NTSTATUS wrepl_request(struct wrepl_socket *wrepl_socket,
541 struct wrepl_packet *req_packet,
542 struct wrepl_packet **reply_packet)
544 struct wrepl_request *req = wrepl_request_send(wrepl_socket, req_packet, NULL);
545 return wrepl_request_recv(req, mem_ctx, reply_packet);
550 setup an association - send
552 struct wrepl_request *wrepl_associate_send(struct wrepl_socket *wrepl_socket,
553 struct wrepl_associate *io)
555 struct wrepl_packet *packet;
556 struct wrepl_request *req;
558 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
559 if (packet == NULL) return NULL;
561 packet->opcode = WREPL_OPCODE_BITS;
562 packet->mess_type = WREPL_START_ASSOCIATION;
563 packet->message.start.minor_version = 2;
564 packet->message.start.major_version = 5;
567 * nt4 uses 41 bytes for the start_association call
568 * so do it the same and as we don't know th emeanings of this bytes
569 * we just send zeros and nt4, w2k and w2k3 seems to be happy with this
571 * if we don't do this nt4 uses an old version of the wins replication protocol
572 * and that would break nt4 <-> samba replication
574 packet->padding = data_blob_talloc(packet, NULL, 21);
575 if (packet->padding.data == NULL) {
579 memset(packet->padding.data, 0, packet->padding.length);
581 req = wrepl_request_send(wrepl_socket, packet, NULL);
589 setup an association - recv
591 NTSTATUS wrepl_associate_recv(struct wrepl_request *req,
592 struct wrepl_associate *io)
594 struct wrepl_packet *packet=NULL;
596 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
597 NT_STATUS_NOT_OK_RETURN(status);
598 if (packet->mess_type != WREPL_START_ASSOCIATION_REPLY) {
599 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
601 if (NT_STATUS_IS_OK(status)) {
602 io->out.assoc_ctx = packet->message.start_reply.assoc_ctx;
609 setup an association - sync api
611 NTSTATUS wrepl_associate(struct wrepl_socket *wrepl_socket,
612 struct wrepl_associate *io)
614 struct wrepl_request *req = wrepl_associate_send(wrepl_socket, io);
615 return wrepl_associate_recv(req, io);
620 stop an association - send
622 struct wrepl_request *wrepl_associate_stop_send(struct wrepl_socket *wrepl_socket,
623 struct wrepl_associate_stop *io)
625 struct wrepl_packet *packet;
626 struct wrepl_request *req;
627 struct wrepl_send_ctrl ctrl;
629 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
630 if (packet == NULL) return NULL;
632 packet->opcode = WREPL_OPCODE_BITS;
633 packet->assoc_ctx = io->in.assoc_ctx;
634 packet->mess_type = WREPL_STOP_ASSOCIATION;
635 packet->message.stop.reason = io->in.reason;
638 if (io->in.reason == 0) {
639 ctrl.send_only = True;
640 ctrl.disconnect_after_send = True;
643 req = wrepl_request_send(wrepl_socket, packet, &ctrl);
651 stop an association - recv
653 NTSTATUS wrepl_associate_stop_recv(struct wrepl_request *req,
654 struct wrepl_associate_stop *io)
656 struct wrepl_packet *packet=NULL;
658 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
659 NT_STATUS_NOT_OK_RETURN(status);
665 setup an association - sync api
667 NTSTATUS wrepl_associate_stop(struct wrepl_socket *wrepl_socket,
668 struct wrepl_associate_stop *io)
670 struct wrepl_request *req = wrepl_associate_stop_send(wrepl_socket, io);
671 return wrepl_associate_stop_recv(req, io);
675 fetch the partner tables - send
677 struct wrepl_request *wrepl_pull_table_send(struct wrepl_socket *wrepl_socket,
678 struct wrepl_pull_table *io)
680 struct wrepl_packet *packet;
681 struct wrepl_request *req;
683 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
684 if (packet == NULL) return NULL;
686 packet->opcode = WREPL_OPCODE_BITS;
687 packet->assoc_ctx = io->in.assoc_ctx;
688 packet->mess_type = WREPL_REPLICATION;
689 packet->message.replication.command = WREPL_REPL_TABLE_QUERY;
691 req = wrepl_request_send(wrepl_socket, packet, NULL);
700 fetch the partner tables - recv
702 NTSTATUS wrepl_pull_table_recv(struct wrepl_request *req,
704 struct wrepl_pull_table *io)
706 struct wrepl_packet *packet=NULL;
708 struct wrepl_table *table;
711 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
712 NT_STATUS_NOT_OK_RETURN(status);
713 if (packet->mess_type != WREPL_REPLICATION) {
714 status = NT_STATUS_NETWORK_ACCESS_DENIED;
715 } else if (packet->message.replication.command != WREPL_REPL_TABLE_REPLY) {
716 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
718 if (!NT_STATUS_IS_OK(status)) goto failed;
720 table = &packet->message.replication.info.table;
721 io->out.num_partners = table->partner_count;
722 io->out.partners = talloc_steal(mem_ctx, table->partners);
723 for (i=0;i<io->out.num_partners;i++) {
724 talloc_steal(io->out.partners, io->out.partners[i].address);
734 fetch the partner table - sync api
736 NTSTATUS wrepl_pull_table(struct wrepl_socket *wrepl_socket,
738 struct wrepl_pull_table *io)
740 struct wrepl_request *req = wrepl_pull_table_send(wrepl_socket, io);
741 return wrepl_pull_table_recv(req, mem_ctx, io);
746 fetch the names for a WINS partner - send
748 struct wrepl_request *wrepl_pull_names_send(struct wrepl_socket *wrepl_socket,
749 struct wrepl_pull_names *io)
751 struct wrepl_packet *packet;
752 struct wrepl_request *req;
754 packet = talloc_zero(wrepl_socket, struct wrepl_packet);
755 if (packet == NULL) return NULL;
757 packet->opcode = WREPL_OPCODE_BITS;
758 packet->assoc_ctx = io->in.assoc_ctx;
759 packet->mess_type = WREPL_REPLICATION;
760 packet->message.replication.command = WREPL_REPL_SEND_REQUEST;
761 packet->message.replication.info.owner = io->in.partner;
763 req = wrepl_request_send(wrepl_socket, packet, NULL);
771 fetch the names for a WINS partner - recv
773 NTSTATUS wrepl_pull_names_recv(struct wrepl_request *req,
775 struct wrepl_pull_names *io)
777 struct wrepl_packet *packet=NULL;
781 status = wrepl_request_recv(req, req->wrepl_socket, &packet);
782 NT_STATUS_NOT_OK_RETURN(status);
783 if (packet->mess_type != WREPL_REPLICATION ||
784 packet->message.replication.command != WREPL_REPL_SEND_REPLY) {
785 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
787 if (!NT_STATUS_IS_OK(status)) goto failed;
789 io->out.num_names = packet->message.replication.info.reply.num_names;
791 io->out.names = talloc_array(packet, struct wrepl_name, io->out.num_names);
792 if (io->out.names == NULL) goto nomem;
794 /* convert the list of names and addresses to a sane format */
795 for (i=0;i<io->out.num_names;i++) {
796 struct wrepl_wins_name *wname = &packet->message.replication.info.reply.names[i];
797 struct wrepl_name *name = &io->out.names[i];
799 name->name = *wname->name;
800 talloc_steal(io->out.names, wname->name);
801 name->type = WREPL_NAME_TYPE(wname->flags);
802 name->state = WREPL_NAME_STATE(wname->flags);
803 name->node = WREPL_NAME_NODE(wname->flags);
804 name->is_static = WREPL_NAME_IS_STATIC(wname->flags);
805 name->raw_flags = wname->flags;
806 name->version_id= wname->id;
807 name->owner = talloc_strdup(io->out.names, io->in.partner.address);
808 if (name->owner == NULL) goto nomem;
810 /* trying to save 1 or 2 bytes on the wire isn't a good idea */
811 if (wname->flags & 2) {
814 name->num_addresses = wname->addresses.addresses.num_ips;
815 name->addresses = talloc_array(io->out.names,
816 struct wrepl_address,
817 name->num_addresses);
818 if (name->addresses == NULL) goto nomem;
819 for (j=0;j<name->num_addresses;j++) {
820 name->addresses[j].owner =
821 talloc_steal(name->addresses,
822 wname->addresses.addresses.ips[j].owner);
823 name->addresses[j].address =
824 talloc_steal(name->addresses,
825 wname->addresses.addresses.ips[j].ip);
828 name->num_addresses = 1;
829 name->addresses = talloc(io->out.names, struct wrepl_address);
830 if (name->addresses == NULL) goto nomem;
831 name->addresses[0].owner = talloc_strdup(name->addresses,io->in.partner.address);
832 if (name->addresses[0].owner == NULL) goto nomem;
833 name->addresses[0].address = talloc_steal(name->addresses,
834 wname->addresses.ip);
838 talloc_steal(mem_ctx, io->out.names);
842 status = NT_STATUS_NO_MEMORY;
851 fetch the names for a WINS partner - sync api
853 NTSTATUS wrepl_pull_names(struct wrepl_socket *wrepl_socket,
855 struct wrepl_pull_names *io)
857 struct wrepl_request *req = wrepl_pull_names_send(wrepl_socket, io);
858 return wrepl_pull_names_recv(req, mem_ctx, io);