2 Unix SMB/CIFS implementation.
4 NBT name registration 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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "lib/socket/socket.h"
24 #include "libcli/resolve/resolve.h"
25 #include "system/network.h"
26 #include "lib/socket/netif.h"
27 #include "torture/torture.h"
28 #include "torture/nbt/proto.h"
30 #define CHECK_VALUE(tctx, v, correct) \
31 torture_assert_int_equal(tctx, v, correct, "Incorrect value")
33 #define CHECK_STRING(tctx, v, correct) \
34 torture_assert_casestr_equal(tctx, v, correct, "Incorrect value")
40 test that a server responds correctly to attempted registrations of its name
42 static bool nbt_register_own(struct torture_context
*tctx
)
44 struct nbt_name_register io
;
46 struct nbt_name_socket
*nbtsock
= nbt_name_socket_init(tctx
, NULL
);
47 struct socket_address
*socket_address
;
50 const char *myaddress
;
52 if (!torture_nbt_get_name(tctx
, &name
, &address
))
55 myaddress
= iface_best_ip(address
);
57 socket_address
= socket_address_from_strings(tctx
, nbtsock
->sock
->backend_name
,
59 torture_assert(tctx
, socket_address
!= NULL
, "Unable to get address");
61 status
= socket_listen(nbtsock
->sock
, socket_address
, 0, 0);
62 torture_assert_ntstatus_ok(tctx
, status
,
63 "socket_listen for nbt_register_own failed");
65 torture_comment(tctx
, "Testing name defense to name registration\n");
68 io
.in
.dest_addr
= address
;
69 io
.in
.address
= myaddress
;
70 io
.in
.nb_flags
= NBT_NODE_B
| NBT_NM_ACTIVE
;
71 io
.in
.register_demand
= False
;
72 io
.in
.broadcast
= True
;
73 io
.in
.multi_homed
= False
;
78 status
= nbt_name_register(nbtsock
, tctx
, &io
);
79 torture_assert_ntstatus_ok(tctx
, status
,
80 talloc_asprintf(tctx
, "Bad response from %s for name register",
83 CHECK_STRING(tctx
, io
.out
.name
.name
, name
.name
);
84 CHECK_VALUE(tctx
, io
.out
.name
.type
, name
.type
);
85 CHECK_VALUE(tctx
, io
.out
.rcode
, NBT_RCODE_ACT
);
87 /* check a register demand */
88 io
.in
.address
= myaddress
;
89 io
.in
.register_demand
= True
;
91 status
= nbt_name_register(nbtsock
, tctx
, &io
);
93 torture_assert_ntstatus_ok(tctx
, status
,
94 talloc_asprintf(tctx
, "Bad response from %s for name register demand", address
));
96 CHECK_STRING(tctx
, io
.out
.name
.name
, name
.name
);
97 CHECK_VALUE(tctx
, io
.out
.name
.type
, name
.type
);
98 CHECK_VALUE(tctx
, io
.out
.rcode
, NBT_RCODE_ACT
);
105 test that a server responds correctly to attempted name refresh requests
107 static bool nbt_refresh_own(struct torture_context
*tctx
)
109 struct nbt_name_refresh io
;
111 struct nbt_name_socket
*nbtsock
= nbt_name_socket_init(tctx
, NULL
);
112 const char *myaddress
;
113 struct socket_address
*socket_address
;
114 struct nbt_name name
;
117 if (!torture_nbt_get_name(tctx
, &name
, &address
))
120 myaddress
= iface_best_ip(address
);
122 socket_address
= socket_address_from_strings(tctx
, nbtsock
->sock
->backend_name
,
124 torture_assert(tctx
, socket_address
!= NULL
,
125 "Can't parse socket address");
127 status
= socket_listen(nbtsock
->sock
, socket_address
, 0, 0);
128 torture_assert_ntstatus_ok(tctx
, status
,
129 "socket_listen for nbt_referesh_own failed");
131 torture_comment(tctx
, "Testing name defense to name refresh\n");
134 io
.in
.dest_addr
= address
;
135 io
.in
.address
= myaddress
;
136 io
.in
.nb_flags
= NBT_NODE_B
| NBT_NM_ACTIVE
;
137 io
.in
.broadcast
= False
;
142 status
= nbt_name_refresh(nbtsock
, tctx
, &io
);
144 torture_assert_ntstatus_ok(tctx
, status
,
145 talloc_asprintf(tctx
, "Bad response from %s for name refresh", address
));
147 CHECK_STRING(tctx
, io
.out
.name
.name
, name
.name
);
148 CHECK_VALUE(tctx
, io
.out
.name
.type
, name
.type
);
149 CHECK_VALUE(tctx
, io
.out
.rcode
, NBT_RCODE_ACT
);
156 test name registration to a server
158 struct torture_suite
*torture_nbt_register(TALLOC_CTX
*mem_ctx
)
160 struct torture_suite
*suite
;
162 suite
= torture_suite_create(mem_ctx
, "REGISTER");
163 torture_suite_add_simple_test(suite
, "register_own", nbt_register_own
);
164 torture_suite_add_simple_test(suite
, "refresh_own", nbt_refresh_own
);