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/wrepl/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 test how assoc_ctx's are only usable on the connection
47 static BOOL test_assoc_ctx1(TALLOC_CTX *mem_ctx, const char *address)
50 struct wrepl_request *req;
51 struct wrepl_socket *wrepl_socket1;
52 struct wrepl_associate associate1;
53 struct wrepl_socket *wrepl_socket2;
54 struct wrepl_associate associate2;
55 struct wrepl_pull_table pull_table;
58 printf("Test if assoc_ctx is only valid on the conection it was created on\n");
60 wrepl_socket1 = wrepl_socket_init(mem_ctx, NULL);
61 wrepl_socket2 = wrepl_socket_init(mem_ctx, NULL);
63 printf("Setup 2 wrepl connections\n");
64 status = wrepl_connect(wrepl_socket1, address);
65 CHECK_STATUS(status, NT_STATUS_OK);
67 status = wrepl_connect(wrepl_socket2, address);
68 CHECK_STATUS(status, NT_STATUS_OK);
70 printf("Send a start association request (conn1)\n");
71 status = wrepl_associate(wrepl_socket1, &associate1);
72 CHECK_STATUS(status, NT_STATUS_OK);
74 printf("association context (conn1): 0x%x\n", associate1.out.assoc_ctx);
76 printf("Send a start association request (conn2)\n");
77 status = wrepl_associate(wrepl_socket2, &associate2);
78 CHECK_STATUS(status, NT_STATUS_OK);
80 printf("association context (conn2): 0x%x\n", associate2.out.assoc_ctx);
82 printf("Send a replication table query, with assoc 1 (conn2), should be ignored\n");
83 pull_table.in.assoc_ctx = associate1.out.assoc_ctx;
84 req = wrepl_pull_table_send(wrepl_socket2, &pull_table);
87 printf("Send a association request (conn2), to make sure the last request was ignored\n");
88 status = wrepl_associate(wrepl_socket2, &associate2);
89 CHECK_STATUS(status, NT_STATUS_OK);
92 printf("Close 2 wrepl connections\n");
93 talloc_free(wrepl_socket1);
94 talloc_free(wrepl_socket2);
99 display a replication entry
101 static void display_entry(TALLOC_CTX *mem_ctx, struct wrepl_name *name)
105 printf("%s\n", nbt_name_string(mem_ctx, &name->name));
106 for (i=0;i<name->num_addresses;i++) {
108 name->addresses[i].owner, name->addresses[i].address);
113 test a full replication dump from a WINS server
115 static BOOL test_wins_replication(TALLOC_CTX *mem_ctx, const char *address)
118 struct wrepl_socket *wrepl_socket;
121 struct wrepl_associate associate;
122 struct wrepl_pull_table pull_table;
123 struct wrepl_pull_names pull_names;
125 printf("Test one pull replication cycle\n");
127 wrepl_socket = wrepl_socket_init(mem_ctx, NULL);
129 printf("Setup wrepl connections\n");
130 status = wrepl_connect(wrepl_socket, address);
131 CHECK_STATUS(status, NT_STATUS_OK);
133 printf("Send a start association request\n");
135 status = wrepl_associate(wrepl_socket, &associate);
136 CHECK_STATUS(status, NT_STATUS_OK);
138 printf("association context: 0x%x\n", associate.out.assoc_ctx);
140 printf("Send a replication table query\n");
141 pull_table.in.assoc_ctx = associate.out.assoc_ctx;
143 status = wrepl_pull_table(wrepl_socket, mem_ctx, &pull_table);
144 if (NT_STATUS_EQUAL(NT_STATUS_NETWORK_ACCESS_DENIED,status)) {
145 struct wrepl_packet packet;
146 struct wrepl_request *req;
148 printf("We are not a valid pull partner for the server\n");
151 packet.opcode = WREPL_OPCODE_BITS;
152 packet.assoc_ctx = associate.out.assoc_ctx;
153 packet.mess_type = WREPL_STOP_ASSOCIATION;
154 packet.message.stop.reason = 0;
156 req = wrepl_request_send(wrepl_socket, &packet);
161 CHECK_STATUS(status, NT_STATUS_OK);
163 printf("Found %d replication partners\n", pull_table.out.num_partners);
165 for (i=0;i<pull_table.out.num_partners;i++) {
166 struct wrepl_wins_owner *partner = &pull_table.out.partners[i];
167 printf("%s max_version=%6llu min_version=%6llu type=%d\n",
169 partner->max_version,
170 partner->min_version,
173 pull_names.in.assoc_ctx = associate.out.assoc_ctx;
174 pull_names.in.partner = *partner;
176 status = wrepl_pull_names(wrepl_socket, mem_ctx, &pull_names);
177 CHECK_STATUS(status, NT_STATUS_OK);
179 printf("Received %d names\n", pull_names.out.num_names);
181 for (j=0;j<pull_names.out.num_names;j++) {
182 display_entry(mem_ctx, &pull_names.out.names[j]);
187 printf("Close wrepl connections\n");
188 talloc_free(wrepl_socket);
193 test WINS replication operations
195 BOOL torture_nbt_winsreplication(void)
198 struct nbt_name name;
199 TALLOC_CTX *mem_ctx = talloc_new(NULL);
203 make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
205 /* do an initial name resolution to find its IP */
206 status = resolve_name(&name, mem_ctx, &address, NULL);
207 if (!NT_STATUS_IS_OK(status)) {
208 printf("Failed to resolve %s - %s\n",
209 name.name, nt_errstr(status));
210 talloc_free(mem_ctx);
214 ret &= test_assoc_ctx1(mem_ctx, address);
216 ret &= test_wins_replication(mem_ctx, address);
218 talloc_free(mem_ctx);