2 Unix SMB/CIFS implementation.
4 WINS replication testing
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 "libcli/nbt/libnbt.h"
25 #include "libcli/wins/winsrepl.h"
27 #define CHECK_STATUS(status, correct) do { \
28 if (!NT_STATUS_EQUAL(status, correct)) { \
29 printf("(%s) Incorrect status %s - should be %s\n", \
30 __location__, nt_errstr(status), nt_errstr(correct)); \
35 #define CHECK_VALUE(v, correct) do { \
36 if ((v) != (correct)) { \
37 printf("(%s) Incorrect value %s=%d - should be %d\n", \
38 __location__, #v, v, correct); \
44 extract a nbt_name from a name buffer
46 static struct nbt_name *wrepl_extract_name(TALLOC_CTX *mem_ctx,
47 uint8_t *name, uint32_t len)
49 struct nbt_name *ret = talloc_zero(mem_ctx, struct nbt_name);
51 /* oh wow, what a nasty bug in windows ... */
52 if (name[0] == 0x1b && len >= 16) {
57 if (ret == NULL) return NULL;
59 ret->name = talloc_strndup(ret, name, len);
61 char *s = talloc_strndup(ret, name, 15);
62 trim_string(s, NULL, " ");
66 ret->scope = talloc_strndup(ret, name+17, len-17);
73 display a replication entry
75 static void display_entry(TALLOC_CTX *mem_ctx, struct wrepl_wins_name *wname)
77 struct nbt_name *name = wrepl_extract_name(mem_ctx,
81 printf("%s\n", nbt_name_string(mem_ctx, name));
82 if (wname->flags & 2) {
83 for (i=0;i<wname->addresses.addresses.num_ips;i++) {
85 wname->addresses.addresses.ips[i].owner,
86 wname->addresses.addresses.ips[i].ip);
90 wname->addresses.address.owner,
91 wname->addresses.address.ip);
96 test a full replication dump from a WINS server
98 static BOOL nbt_test_wins_replication(TALLOC_CTX *mem_ctx, const char *address)
101 struct wrepl_socket *wrepl_socket;
103 struct wrepl_packet request, *reply;
105 struct wrepl_table *table;
107 wrepl_socket = wrepl_socket_init(mem_ctx, NULL);
109 status = wrepl_connect(wrepl_socket, address);
110 CHECK_STATUS(status, NT_STATUS_OK);
112 printf("Send a start association request\n");
114 ZERO_STRUCT(request);
115 request.opcode = WREPL_OPCODE_BITS;
116 request.mess_type = WREPL_START_ASSOCIATION;
117 request.message.start.minor_version = 2;
118 request.message.start.major_version = 5;
119 request.padding = data_blob_talloc_zero(mem_ctx, 0);
121 status = wrepl_request(wrepl_socket, mem_ctx, &request, &reply);
122 CHECK_STATUS(status, NT_STATUS_OK);
123 CHECK_VALUE(reply->mess_type, WREPL_START_ASSOCIATION_REPLY);
125 request.assoc_ctx = reply->message.start_reply.assoc_ctx;
126 printf("association context: 0x%x\n", request.assoc_ctx);
128 printf("Send a replication table query\n");
129 request.mess_type = WREPL_REPLICATION;
130 request.message.replication.command = WREPL_REPL_TABLE_QUERY;
132 status = wrepl_request(wrepl_socket, mem_ctx, &request, &reply);
133 CHECK_STATUS(status, NT_STATUS_OK);
134 CHECK_VALUE(reply->mess_type, WREPL_REPLICATION);
135 CHECK_VALUE(reply->message.replication.command, WREPL_REPL_TABLE_REPLY);
137 table = &reply->message.replication.info.table;
139 printf("Found %d replication partners\n", table->partner_count);
141 for (i=0;i<table->partner_count;i++) {
142 printf("%s max_version=%6llu min_version=%6llu type=%d\n",
143 table->partners[i].address,
144 table->partners[i].max_version,
145 table->partners[i].min_version,
146 table->partners[i].type);
148 request.message.replication.command = WREPL_REPL_SEND_REQUEST;
149 request.message.replication.info.owner = table->partners[i];
151 status = wrepl_request(wrepl_socket, mem_ctx, &request, &reply);
152 CHECK_STATUS(status, NT_STATUS_OK);
153 CHECK_VALUE(reply->mess_type, WREPL_REPLICATION);
154 CHECK_VALUE(reply->message.replication.command, WREPL_REPL_SEND_REPLY);
156 printf("Received %d names\n",
157 reply->message.replication.info.reply.num_names);
159 for (j=0;j<reply->message.replication.info.reply.num_names;j++) {
160 display_entry(mem_ctx,
161 &reply->message.replication.info.reply.names[j]);
166 talloc_free(wrepl_socket);
171 test WINS replication operations
173 BOOL torture_nbt_winsreplication(void)
176 struct nbt_name name;
177 TALLOC_CTX *mem_ctx = talloc_new(NULL);
181 name.name = lp_parm_string(-1, "torture", "host");
182 name.type = NBT_NAME_SERVER;
185 /* do an initial name resolution to find its IP */
186 status = resolve_name(&name, mem_ctx, &address);
187 if (!NT_STATUS_IS_OK(status)) {
188 printf("Failed to resolve %s - %s\n",
189 name.name, nt_errstr(status));
190 talloc_free(mem_ctx);
194 ret &= nbt_test_wins_replication(mem_ctx, address);
196 talloc_free(mem_ctx);