2 Unix SMB/CIFS implementation.
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 "libcli/dgram/libdgram.h"
24 #include "lib/socket/socket.h"
25 #include "lib/events/events.h"
26 #include "torture/rpc/torture_rpc.h"
27 #include "libcli/resolve/resolve.h"
28 #include "system/network.h"
29 #include "lib/socket/netif.h"
30 #include "param/param.h"
32 #define TEST_NAME "TORTURE_TEST"
35 reply handler for netlogon request
37 static void netlogon_handler(struct dgram_mailslot_handler
*dgmslot
,
38 struct nbt_dgram_packet
*packet
,
39 struct socket_address
*src
)
42 struct nbt_netlogon_response
*netlogon
= dgmslot
->private_data
;
44 dgmslot
->private_data
= netlogon
= talloc(dgmslot
, struct nbt_netlogon_response
);
46 if (!dgmslot
->private_data
) {
50 printf("netlogon reply from %s:%d\n", src
->addr
, src
->port
);
52 /* Fills in the netlogon pointer */
53 status
= dgram_mailslot_netlogon_parse_response(dgmslot
, netlogon
, packet
, netlogon
);
54 if (!NT_STATUS_IS_OK(status
)) {
55 printf("Failed to parse netlogon packet from %s:%d\n",
56 src
->addr
, src
->port
);
63 /* test UDP/138 netlogon requests */
64 static bool nbt_test_netlogon(struct torture_context
*tctx
)
66 struct dgram_mailslot_handler
*dgmslot
;
67 struct nbt_dgram_socket
*dgmsock
= nbt_dgram_socket_init(tctx
, tctx
->ev
);
68 struct socket_address
*dest
;
69 const char *myaddress
;
70 struct nbt_netlogon_packet logon
;
71 struct nbt_netlogon_response
*response
;
72 struct nbt_name myname
;
74 struct timeval tv
= timeval_current();
76 struct socket_address
*socket_address
;
81 struct interface
*ifaces
;
83 name
.name
= lpcfg_workgroup(tctx
->lp_ctx
);
84 name
.type
= NBT_NAME_LOGON
;
87 /* do an initial name resolution to find its IP */
88 torture_assert_ntstatus_ok(tctx
,
89 resolve_name_ex(lpcfg_resolve_context(tctx
->lp_ctx
),
91 &name
, tctx
, &address
, tctx
->ev
),
92 talloc_asprintf(tctx
, "Failed to resolve %s", name
.name
));
94 load_interface_list(tctx
, tctx
->lp_ctx
, &ifaces
);
95 myaddress
= talloc_strdup(dgmsock
, iface_list_best_ip(ifaces
, address
));
98 socket_address
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
99 myaddress
, lpcfg_dgram_port(tctx
->lp_ctx
));
100 torture_assert(tctx
, socket_address
!= NULL
, "Error getting address");
102 /* try receiving replies on port 138 first, which will only
103 work if we are root and smbd/nmbd are not running - fall
104 back to listening on any port, which means replies from
105 most windows versions won't be seen */
106 status
= socket_listen(dgmsock
->sock
, socket_address
, 0, 0);
107 if (!NT_STATUS_IS_OK(status
)) {
108 talloc_free(socket_address
);
109 socket_address
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
111 torture_assert(tctx
, socket_address
!= NULL
, "Error getting address");
113 socket_listen(dgmsock
->sock
, socket_address
, 0, 0);
116 /* setup a temporary mailslot listener for replies */
117 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
118 netlogon_handler
, NULL
);
119 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
122 logon
.command
= LOGON_PRIMARY_QUERY
;
123 logon
.req
.pdc
.computer_name
= TEST_NAME
;
124 logon
.req
.pdc
.mailslot_name
= dgmslot
->mailslot_name
;
125 logon
.req
.pdc
.unicode_name
= TEST_NAME
;
126 logon
.req
.pdc
.nt_version
= 1;
127 logon
.req
.pdc
.lmnt_token
= 0xFFFF;
128 logon
.req
.pdc
.lm20_token
= 0xFFFF;
130 make_nbt_name_client(&myname
, TEST_NAME
);
132 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
133 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
134 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
136 status
= dgram_mailslot_netlogon_send(dgmsock
, &name
, dest
,
137 NBT_MAILSLOT_NETLOGON
,
139 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send netlogon request");
141 while (timeval_elapsed(&tv
) < 5 && !dgmslot
->private_data
) {
142 event_loop_once(dgmsock
->event_ctx
);
145 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
147 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
149 torture_assert(tctx
, response
->response_type
== NETLOGON_GET_PDC
, "Got incorrect type of netlogon response");
150 torture_assert(tctx
, response
->data
.get_pdc
.command
== NETLOGON_RESPONSE_FROM_PDC
, "Got incorrect netlogon response command");
156 /* test UDP/138 netlogon requests */
157 static bool nbt_test_netlogon2(struct torture_context
*tctx
)
159 struct dgram_mailslot_handler
*dgmslot
;
160 struct nbt_dgram_socket
*dgmsock
= nbt_dgram_socket_init(tctx
, tctx
->ev
);
161 struct socket_address
*dest
;
162 const char *myaddress
;
163 struct nbt_netlogon_packet logon
;
164 struct nbt_netlogon_response
*response
;
165 struct nbt_name myname
;
167 struct timeval tv
= timeval_current();
169 struct socket_address
*socket_address
;
172 struct nbt_name name
;
174 struct interface
*ifaces
;
175 struct test_join
*join_ctx
;
176 struct cli_credentials
*machine_credentials
;
177 const struct dom_sid
*dom_sid
;
179 name
.name
= lpcfg_workgroup(tctx
->lp_ctx
);
180 name
.type
= NBT_NAME_LOGON
;
183 /* do an initial name resolution to find its IP */
184 torture_assert_ntstatus_ok(tctx
,
185 resolve_name_ex(lpcfg_resolve_context(tctx
->lp_ctx
),
187 &name
, tctx
, &address
, tctx
->ev
),
188 talloc_asprintf(tctx
, "Failed to resolve %s", name
.name
));
190 load_interface_list(tctx
, tctx
->lp_ctx
, &ifaces
);
191 myaddress
= talloc_strdup(dgmsock
, iface_list_best_ip(ifaces
, address
));
193 socket_address
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
194 myaddress
, lpcfg_dgram_port(tctx
->lp_ctx
));
195 torture_assert(tctx
, socket_address
!= NULL
, "Error getting address");
197 /* try receiving replies on port 138 first, which will only
198 work if we are root and smbd/nmbd are not running - fall
199 back to listening on any port, which means replies from
200 some windows versions won't be seen */
201 status
= socket_listen(dgmsock
->sock
, socket_address
, 0, 0);
202 if (!NT_STATUS_IS_OK(status
)) {
203 talloc_free(socket_address
);
204 socket_address
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
206 torture_assert(tctx
, socket_address
!= NULL
, "Error getting address");
208 socket_listen(dgmsock
->sock
, socket_address
, 0, 0);
211 /* setup a temporary mailslot listener for replies */
212 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
213 netlogon_handler
, NULL
);
214 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
217 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
218 logon
.req
.logon
.request_count
= 0;
219 logon
.req
.logon
.computer_name
= TEST_NAME
;
220 logon
.req
.logon
.user_name
= "";
221 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
222 logon
.req
.logon
.nt_version
= NETLOGON_NT_VERSION_5EX_WITH_IP
|NETLOGON_NT_VERSION_5
|NETLOGON_NT_VERSION_1
;
223 logon
.req
.logon
.lmnt_token
= 0xFFFF;
224 logon
.req
.logon
.lm20_token
= 0xFFFF;
226 make_nbt_name_client(&myname
, TEST_NAME
);
228 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
229 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
231 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
232 status
= dgram_mailslot_netlogon_send(dgmsock
, &name
, dest
,
233 NBT_MAILSLOT_NETLOGON
,
235 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send netlogon request");
237 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
238 event_loop_once(dgmsock
->event_ctx
);
241 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
243 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
245 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
246 map_netlogon_samlogon_response(&response
->data
.samlogon
);
248 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_RESPONSE_EX
, "Got incorrect netlogon response command");
249 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.nt_version
, NETLOGON_NT_VERSION_5EX_WITH_IP
|NETLOGON_NT_VERSION_5EX
|NETLOGON_NT_VERSION_1
, "Got incorrect netlogon response command");
251 /* setup (another) temporary mailslot listener for replies */
252 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
253 netlogon_handler
, NULL
);
254 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
257 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
258 logon
.req
.logon
.request_count
= 0;
259 logon
.req
.logon
.computer_name
= TEST_NAME
;
260 logon
.req
.logon
.user_name
= TEST_NAME
"$";
261 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
262 logon
.req
.logon
.nt_version
= 1;
263 logon
.req
.logon
.lmnt_token
= 0xFFFF;
264 logon
.req
.logon
.lm20_token
= 0xFFFF;
266 make_nbt_name_client(&myname
, TEST_NAME
);
268 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
269 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
271 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
272 status
= dgram_mailslot_netlogon_send(dgmsock
, &name
, dest
,
273 NBT_MAILSLOT_NETLOGON
,
275 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send netlogon request");
277 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
278 event_loop_once(dgmsock
->event_ctx
);
281 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
283 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
285 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
286 map_netlogon_samlogon_response(&response
->data
.samlogon
);
288 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_USER_UNKNOWN
, "Got incorrect netlogon response command");
290 torture_assert_str_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.user_name
, TEST_NAME
"$", "Got incorrect user in netlogon response");
292 join_ctx
= torture_join_domain(tctx
, TEST_NAME
,
293 ACB_WSTRUST
, &machine_credentials
);
295 torture_assert(tctx
, join_ctx
!= NULL
,
296 talloc_asprintf(tctx
, "Failed to join domain %s as %s\n",
297 lpcfg_workgroup(tctx
->lp_ctx
), TEST_NAME
));
299 dom_sid
= torture_join_sid(join_ctx
);
301 /* setup (another) temporary mailslot listener for replies */
302 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
303 netlogon_handler
, NULL
);
304 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
307 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
308 logon
.req
.logon
.request_count
= 0;
309 logon
.req
.logon
.computer_name
= TEST_NAME
;
310 logon
.req
.logon
.user_name
= TEST_NAME
"$";
311 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
312 logon
.req
.logon
.sid
= *dom_sid
;
313 logon
.req
.logon
.nt_version
= 1;
314 logon
.req
.logon
.lmnt_token
= 0xFFFF;
315 logon
.req
.logon
.lm20_token
= 0xFFFF;
317 make_nbt_name_client(&myname
, TEST_NAME
);
319 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
320 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
322 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
323 status
= dgram_mailslot_netlogon_send(dgmsock
, &name
, dest
,
324 NBT_MAILSLOT_NETLOGON
,
326 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send netlogon request");
329 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
330 event_loop_once(dgmsock
->event_ctx
);
333 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
335 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
337 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
338 map_netlogon_samlogon_response(&response
->data
.samlogon
);
340 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_USER_UNKNOWN
, "Got incorrect netlogon response command");
342 /* setup (another) temporary mailslot listener for replies */
343 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
344 netlogon_handler
, NULL
);
345 torture_assert(tctx
, dgmslot
!= NULL
, "Error getting a Mailslot for GetDC reply");
348 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
349 logon
.req
.logon
.request_count
= 0;
350 logon
.req
.logon
.computer_name
= TEST_NAME
;
351 logon
.req
.logon
.user_name
= TEST_NAME
"$";
352 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
353 logon
.req
.logon
.sid
= *dom_sid
;
354 logon
.req
.logon
.acct_control
= ACB_WSTRUST
;
355 logon
.req
.logon
.nt_version
= 1;
356 logon
.req
.logon
.lmnt_token
= 0xFFFF;
357 logon
.req
.logon
.lm20_token
= 0xFFFF;
359 make_nbt_name_client(&myname
, TEST_NAME
);
361 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
362 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
364 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
365 status
= dgram_mailslot_netlogon_send(dgmsock
, &name
, dest
,
366 NBT_MAILSLOT_NETLOGON
,
368 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send netlogon request");
371 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
372 event_loop_once(dgmsock
->event_ctx
);
375 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
377 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
379 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
380 map_netlogon_samlogon_response(&response
->data
.samlogon
);
382 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_RESPONSE
, "Got incorrect netlogon response command");
384 dgmslot
->private_data
= NULL
;
387 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
388 logon
.req
.logon
.request_count
= 0;
389 logon
.req
.logon
.computer_name
= TEST_NAME
;
390 logon
.req
.logon
.user_name
= TEST_NAME
"$";
391 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
392 logon
.req
.logon
.sid
= *dom_sid
;
393 logon
.req
.logon
.acct_control
= ACB_NORMAL
;
394 logon
.req
.logon
.nt_version
= 1;
395 logon
.req
.logon
.lmnt_token
= 0xFFFF;
396 logon
.req
.logon
.lm20_token
= 0xFFFF;
398 make_nbt_name_client(&myname
, TEST_NAME
);
400 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
401 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
403 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
404 status
= dgram_mailslot_netlogon_send(dgmsock
, &name
, dest
,
405 NBT_MAILSLOT_NETLOGON
,
407 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send netlogon request");
410 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
411 event_loop_once(dgmsock
->event_ctx
);
414 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
416 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
418 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
419 map_netlogon_samlogon_response(&response
->data
.samlogon
);
421 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_USER_UNKNOWN
, "Got incorrect netlogon response command");
423 torture_leave_domain(tctx
, join_ctx
);
428 /* test UDP/138 ntlogon requests */
429 static bool nbt_test_ntlogon(struct torture_context
*tctx
)
431 struct dgram_mailslot_handler
*dgmslot
;
432 struct nbt_dgram_socket
*dgmsock
= nbt_dgram_socket_init(tctx
, tctx
->ev
);
433 struct socket_address
*dest
;
434 struct test_join
*join_ctx
;
435 const struct dom_sid
*dom_sid
;
436 struct cli_credentials
*machine_credentials
;
438 const char *myaddress
;
439 struct nbt_netlogon_packet logon
;
440 struct nbt_netlogon_response
*response
;
441 struct nbt_name myname
;
443 struct timeval tv
= timeval_current();
445 struct socket_address
*socket_address
;
447 struct nbt_name name
;
449 struct interface
*ifaces
;
451 name
.name
= lpcfg_workgroup(tctx
->lp_ctx
);
452 name
.type
= NBT_NAME_LOGON
;
455 /* do an initial name resolution to find its IP */
456 torture_assert_ntstatus_ok(tctx
,
457 resolve_name_ex(lpcfg_resolve_context(tctx
->lp_ctx
),
458 0, 0, &name
, tctx
, &address
, tctx
->ev
),
459 talloc_asprintf(tctx
, "Failed to resolve %s", name
.name
));
461 load_interface_list(tctx
, tctx
->lp_ctx
, &ifaces
);
462 myaddress
= talloc_strdup(dgmsock
, iface_list_best_ip(ifaces
, address
));
464 socket_address
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
465 myaddress
, lpcfg_dgram_port(tctx
->lp_ctx
));
466 torture_assert(tctx
, socket_address
!= NULL
, "Error getting address");
468 /* try receiving replies on port 138 first, which will only
469 work if we are root and smbd/nmbd are not running - fall
470 back to listening on any port, which means replies from
471 most windows versions won't be seen */
472 status
= socket_listen(dgmsock
->sock
, socket_address
, 0, 0);
473 if (!NT_STATUS_IS_OK(status
)) {
474 talloc_free(socket_address
);
475 socket_address
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
477 torture_assert(tctx
, socket_address
!= NULL
, "Error getting address");
479 socket_listen(dgmsock
->sock
, socket_address
, 0, 0);
482 join_ctx
= torture_join_domain(tctx
, TEST_NAME
,
483 ACB_WSTRUST
, &machine_credentials
);
484 dom_sid
= torture_join_sid(join_ctx
);
486 torture_assert(tctx
, join_ctx
!= NULL
,
487 talloc_asprintf(tctx
, "Failed to join domain %s as %s\n",
488 lpcfg_workgroup(tctx
->lp_ctx
), TEST_NAME
));
490 /* setup a temporary mailslot listener for replies */
491 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
492 netlogon_handler
, NULL
);
493 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
496 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
497 logon
.req
.logon
.request_count
= 0;
498 logon
.req
.logon
.computer_name
= TEST_NAME
;
499 logon
.req
.logon
.user_name
= TEST_NAME
"$";
500 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
501 logon
.req
.logon
.acct_control
= ACB_WSTRUST
;
502 /* Try with a SID this time */
503 logon
.req
.logon
.sid
= *dom_sid
;
504 logon
.req
.logon
.nt_version
= 1;
505 logon
.req
.logon
.lmnt_token
= 0xFFFF;
506 logon
.req
.logon
.lm20_token
= 0xFFFF;
508 make_nbt_name_client(&myname
, TEST_NAME
);
510 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
511 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
512 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
513 status
= dgram_mailslot_netlogon_send(dgmsock
,
515 NBT_MAILSLOT_NTLOGON
,
517 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send ntlogon request");
519 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
520 event_loop_once(dgmsock
->event_ctx
);
523 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
525 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
527 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
528 map_netlogon_samlogon_response(&response
->data
.samlogon
);
530 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_RESPONSE
, "Got incorrect netlogon response command");
532 torture_assert_str_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.user_name
, TEST_NAME
"$", "Got incorrect user in netlogon response");
535 /* setup a temporary mailslot listener for replies */
536 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
537 netlogon_handler
, NULL
);
538 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
541 logon
.command
= LOGON_SAM_LOGON_REQUEST
;
542 logon
.req
.logon
.request_count
= 0;
543 logon
.req
.logon
.computer_name
= TEST_NAME
;
544 logon
.req
.logon
.user_name
= TEST_NAME
"$";
545 logon
.req
.logon
.mailslot_name
= dgmslot
->mailslot_name
;
546 logon
.req
.logon
.acct_control
= ACB_WSTRUST
;
547 /* Leave sid as all zero */
548 logon
.req
.logon
.nt_version
= 1;
549 logon
.req
.logon
.lmnt_token
= 0xFFFF;
550 logon
.req
.logon
.lm20_token
= 0xFFFF;
552 make_nbt_name_client(&myname
, TEST_NAME
);
554 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
555 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
556 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
557 status
= dgram_mailslot_netlogon_send(dgmsock
,
559 NBT_MAILSLOT_NTLOGON
,
561 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send ntlogon request");
563 while (timeval_elapsed(&tv
) < 5 && dgmslot
->private_data
== NULL
) {
564 event_loop_once(dgmsock
->event_ctx
);
567 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
569 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
571 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_SAMLOGON
, "Got incorrect type of netlogon response");
572 map_netlogon_samlogon_response(&response
->data
.samlogon
);
574 torture_assert_int_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.command
, LOGON_SAM_LOGON_RESPONSE
, "Got incorrect netlogon response command");
576 torture_assert_str_equal(tctx
, response
->data
.samlogon
.data
.nt5_ex
.user_name
, TEST_NAME
"$", "Got incorrect user in netlogon response");
579 /* setup (another) temporary mailslot listener for replies */
580 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
581 netlogon_handler
, NULL
);
582 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
585 logon
.command
= LOGON_PRIMARY_QUERY
;
586 logon
.req
.pdc
.computer_name
= TEST_NAME
;
587 logon
.req
.pdc
.mailslot_name
= dgmslot
->mailslot_name
;
588 logon
.req
.pdc
.unicode_name
= TEST_NAME
;
589 logon
.req
.pdc
.nt_version
= 1;
590 logon
.req
.pdc
.lmnt_token
= 0xFFFF;
591 logon
.req
.pdc
.lm20_token
= 0xFFFF;
593 make_nbt_name_client(&myname
, TEST_NAME
);
595 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
596 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
597 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
598 status
= dgram_mailslot_netlogon_send(dgmsock
,
600 NBT_MAILSLOT_NTLOGON
,
602 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send ntlogon request");
604 while (timeval_elapsed(&tv
) < 5 && !dgmslot
->private_data
) {
605 event_loop_once(dgmsock
->event_ctx
);
608 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
610 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
612 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_GET_PDC
, "Got incorrect type of ntlogon response");
613 torture_assert_int_equal(tctx
, response
->data
.get_pdc
.command
, NETLOGON_RESPONSE_FROM_PDC
, "Got incorrect ntlogon response command");
615 torture_leave_domain(tctx
, join_ctx
);
617 /* setup (another) temporary mailslot listener for replies */
618 dgmslot
= dgram_mailslot_temp(dgmsock
, NBT_MAILSLOT_GETDC
,
619 netlogon_handler
, NULL
);
620 torture_assert(tctx
, dgmslot
!= NULL
, "Error temporary mailslot for GetDC");
623 logon
.command
= LOGON_PRIMARY_QUERY
;
624 logon
.req
.pdc
.computer_name
= TEST_NAME
;
625 logon
.req
.pdc
.mailslot_name
= dgmslot
->mailslot_name
;
626 logon
.req
.pdc
.unicode_name
= TEST_NAME
;
627 logon
.req
.pdc
.nt_version
= 1;
628 logon
.req
.pdc
.lmnt_token
= 0xFFFF;
629 logon
.req
.pdc
.lm20_token
= 0xFFFF;
631 make_nbt_name_client(&myname
, TEST_NAME
);
633 dest
= socket_address_from_strings(dgmsock
, dgmsock
->sock
->backend_name
,
634 address
, lpcfg_dgram_port(tctx
->lp_ctx
));
635 torture_assert(tctx
, dest
!= NULL
, "Error getting address");
636 status
= dgram_mailslot_netlogon_send(dgmsock
,
638 NBT_MAILSLOT_NTLOGON
,
640 torture_assert_ntstatus_ok(tctx
, status
, "Failed to send ntlogon request");
642 while (timeval_elapsed(&tv
) < 5 && !dgmslot
->private_data
) {
643 event_loop_once(dgmsock
->event_ctx
);
646 response
= talloc_get_type(dgmslot
->private_data
, struct nbt_netlogon_response
);
648 torture_assert(tctx
, response
!= NULL
, "Failed to receive a netlogon reply packet");
650 torture_assert_int_equal(tctx
, response
->response_type
, NETLOGON_GET_PDC
, "Got incorrect type of ntlogon response");
651 torture_assert_int_equal(tctx
, response
->data
.get_pdc
.command
, NETLOGON_RESPONSE_FROM_PDC
, "Got incorrect ntlogon response command");
659 test nbt dgram operations
661 struct torture_suite
*torture_nbt_dgram(TALLOC_CTX
*mem_ctx
)
663 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "dgram");
665 torture_suite_add_simple_test(suite
, "netlogon", nbt_test_netlogon
);
666 torture_suite_add_simple_test(suite
, "netlogon2", nbt_test_netlogon2
);
667 torture_suite_add_simple_test(suite
, "ntlogon", nbt_test_ntlogon
);