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 display a replication entry
46 static void display_entry(TALLOC_CTX *mem_ctx, struct wrepl_name *name)
50 printf("%s\n", nbt_name_string(mem_ctx, &name->name));
51 for (i=0;i<name->num_addresses;i++) {
53 name->addresses[i].owner, name->addresses[i].address);
58 test a full replication dump from a WINS server
60 static BOOL nbt_test_wins_replication(TALLOC_CTX *mem_ctx, const char *address)
63 struct wrepl_socket *wrepl_socket;
66 struct wrepl_associate associate;
67 struct wrepl_pull_table pull_table;
68 struct wrepl_pull_names pull_names;
70 wrepl_socket = wrepl_socket_init(mem_ctx, NULL);
72 status = wrepl_connect(wrepl_socket, address);
73 CHECK_STATUS(status, NT_STATUS_OK);
75 printf("Send a start association request\n");
77 status = wrepl_associate(wrepl_socket, &associate);
78 CHECK_STATUS(status, NT_STATUS_OK);
80 printf("association context: 0x%x\n", associate.out.assoc_ctx);
82 printf("Send a replication table query\n");
83 pull_table.in.assoc_ctx = associate.out.assoc_ctx;
85 status = wrepl_pull_table(wrepl_socket, mem_ctx, &pull_table);
86 CHECK_STATUS(status, NT_STATUS_OK);
88 printf("Found %d replication partners\n", pull_table.out.num_partners);
90 for (i=0;i<pull_table.out.num_partners;i++) {
91 struct wrepl_wins_owner *partner = &pull_table.out.partners[i];
92 printf("%s max_version=%6llu min_version=%6llu type=%d\n",
98 pull_names.in.assoc_ctx = associate.out.assoc_ctx;
99 pull_names.in.partner = *partner;
101 status = wrepl_pull_names(wrepl_socket, mem_ctx, &pull_names);
102 CHECK_STATUS(status, NT_STATUS_OK);
104 printf("Received %d names\n", pull_names.out.num_names);
106 for (j=0;j<pull_names.out.num_names;j++) {
107 display_entry(mem_ctx, &pull_names.out.names[j]);
112 talloc_free(wrepl_socket);
117 test WINS replication operations
119 BOOL torture_nbt_winsreplication(void)
122 struct nbt_name name;
123 TALLOC_CTX *mem_ctx = talloc_new(NULL);
127 name.name = lp_parm_string(-1, "torture", "host");
128 name.type = NBT_NAME_SERVER;
131 /* do an initial name resolution to find its IP */
132 status = resolve_name(&name, mem_ctx, &address);
133 if (!NT_STATUS_IS_OK(status)) {
134 printf("Failed to resolve %s - %s\n",
135 name.name, nt_errstr(status));
136 talloc_free(mem_ctx);
140 ret &= nbt_test_wins_replication(mem_ctx, address);
142 talloc_free(mem_ctx);