wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Browse service
|
||||
|
||||
(C) Jelmer Vernooij 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "librpc/gen_ndr/nbt.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "torture/torture.h"
|
||||
|
||||
/*
|
||||
test nbt dgram operations
|
||||
*/
|
||||
BOOL torture_nbt_browse(struct torture_context *torture)
|
||||
{
|
||||
const char *address;
|
||||
struct nbt_name name;
|
||||
TALLOC_CTX *mem_ctx = talloc_new(NULL);
|
||||
NTSTATUS status;
|
||||
BOOL ret = True;
|
||||
|
||||
name.name = lp_workgroup();
|
||||
name.type = NBT_NAME_BROWSER;
|
||||
name.scope = NULL;
|
||||
|
||||
/* do an initial name resolution to find its IP */
|
||||
status = resolve_name(&name, mem_ctx, &address, NULL);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
printf("Failed to resolve %s - %s\n",
|
||||
name.name, nt_errstr(status));
|
||||
talloc_free(mem_ctx);
|
||||
return False;
|
||||
}
|
||||
|
||||
talloc_free(mem_ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
NBT dgram testing
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "libcli/dgram/libdgram.h"
|
||||
#include "librpc/gen_ndr/samr.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
#include "librpc/gen_ndr/ndr_netlogon.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "torture/rpc/rpc.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "system/network.h"
|
||||
#include "lib/socket/netif.h"
|
||||
|
||||
#define TEST_NAME "TORTURE_TEST"
|
||||
|
||||
/*
|
||||
reply handler for netlogon request
|
||||
*/
|
||||
static void netlogon_handler(struct dgram_mailslot_handler *dgmslot,
|
||||
struct nbt_dgram_packet *packet,
|
||||
struct socket_address *src)
|
||||
{
|
||||
NTSTATUS status;
|
||||
struct nbt_netlogon_packet netlogon;
|
||||
int *replies = dgmslot->private;
|
||||
|
||||
printf("netlogon reply from %s:%d\n", src->addr, src->port);
|
||||
|
||||
status = dgram_mailslot_netlogon_parse(dgmslot, dgmslot, packet, &netlogon);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
printf("Failed to parse netlogon packet from %s:%d\n",
|
||||
src->addr, src->port);
|
||||
return;
|
||||
}
|
||||
|
||||
NDR_PRINT_DEBUG(nbt_netlogon_packet, &netlogon);
|
||||
|
||||
(*replies)++;
|
||||
}
|
||||
|
||||
|
||||
/* test UDP/138 netlogon requests */
|
||||
static bool nbt_test_netlogon(struct torture_context *tctx)
|
||||
{
|
||||
struct dgram_mailslot_handler *dgmslot;
|
||||
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
|
||||
struct socket_address *dest;
|
||||
const char *myaddress;
|
||||
struct nbt_netlogon_packet logon;
|
||||
struct nbt_name myname;
|
||||
NTSTATUS status;
|
||||
struct timeval tv = timeval_current();
|
||||
int replies = 0;
|
||||
|
||||
struct socket_address *socket_address;
|
||||
|
||||
const char *address;
|
||||
struct nbt_name name;
|
||||
|
||||
name.name = lp_workgroup();
|
||||
name.type = NBT_NAME_LOGON;
|
||||
name.scope = NULL;
|
||||
|
||||
/* do an initial name resolution to find its IP */
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
resolve_name(&name, tctx, &address, event_context_find(tctx)),
|
||||
talloc_asprintf(tctx, "Failed to resolve %s", name.name));
|
||||
|
||||
myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
|
||||
|
||||
|
||||
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
myaddress, lp_dgram_port());
|
||||
torture_assert(tctx, socket_address != NULL, "Error getting address");
|
||||
|
||||
/* try receiving replies on port 138 first, which will only
|
||||
work if we are root and smbd/nmbd are not running - fall
|
||||
back to listening on any port, which means replies from
|
||||
some windows versions won't be seen */
|
||||
status = socket_listen(dgmsock->sock, socket_address, 0, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(socket_address);
|
||||
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
myaddress, 0);
|
||||
torture_assert(tctx, socket_address != NULL, "Error getting address");
|
||||
|
||||
socket_listen(dgmsock->sock, socket_address, 0, 0);
|
||||
}
|
||||
|
||||
/* setup a temporary mailslot listener for replies */
|
||||
dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC,
|
||||
netlogon_handler, &replies);
|
||||
|
||||
ZERO_STRUCT(logon);
|
||||
logon.command = NETLOGON_QUERY_FOR_PDC;
|
||||
logon.req.pdc.computer_name = TEST_NAME;
|
||||
logon.req.pdc.mailslot_name = dgmslot->mailslot_name;
|
||||
logon.req.pdc.unicode_name = TEST_NAME;
|
||||
logon.req.pdc.nt_version = 1;
|
||||
logon.req.pdc.lmnt_token = 0xFFFF;
|
||||
logon.req.pdc.lm20_token = 0xFFFF;
|
||||
|
||||
make_nbt_name_client(&myname, TEST_NAME);
|
||||
|
||||
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
address, 0);
|
||||
torture_assert(tctx, dest != NULL, "Error getting address");
|
||||
|
||||
status = dgram_mailslot_netlogon_send(dgmsock, &name, dest,
|
||||
&myname, &logon);
|
||||
torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request");
|
||||
|
||||
while (timeval_elapsed(&tv) < 5 && replies == 0) {
|
||||
event_loop_once(dgmsock->event_ctx);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* test UDP/138 netlogon requests */
|
||||
static bool nbt_test_netlogon2(struct torture_context *tctx)
|
||||
{
|
||||
struct dgram_mailslot_handler *dgmslot;
|
||||
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
|
||||
struct socket_address *dest;
|
||||
const char *myaddress;
|
||||
struct nbt_netlogon_packet logon;
|
||||
struct nbt_name myname;
|
||||
NTSTATUS status;
|
||||
struct timeval tv = timeval_current();
|
||||
int replies = 0;
|
||||
|
||||
struct socket_address *socket_address;
|
||||
|
||||
const char *address;
|
||||
struct nbt_name name;
|
||||
|
||||
name.name = lp_workgroup();
|
||||
name.type = NBT_NAME_LOGON;
|
||||
name.scope = NULL;
|
||||
|
||||
/* do an initial name resolution to find its IP */
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
resolve_name(&name, tctx, &address, event_context_find(tctx)),
|
||||
talloc_asprintf(tctx, "Failed to resolve %s", name.name));
|
||||
|
||||
myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
|
||||
|
||||
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
myaddress, lp_dgram_port());
|
||||
torture_assert(tctx, socket_address != NULL, "Error getting address");
|
||||
|
||||
/* try receiving replies on port 138 first, which will only
|
||||
work if we are root and smbd/nmbd are not running - fall
|
||||
back to listening on any port, which means replies from
|
||||
some windows versions won't be seen */
|
||||
status = socket_listen(dgmsock->sock, socket_address, 0, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(socket_address);
|
||||
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
myaddress, 0);
|
||||
torture_assert(tctx, socket_address != NULL, "Error getting address");
|
||||
|
||||
socket_listen(dgmsock->sock, socket_address, 0, 0);
|
||||
}
|
||||
|
||||
/* setup a temporary mailslot listener for replies */
|
||||
dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC,
|
||||
netlogon_handler, &replies);
|
||||
|
||||
|
||||
ZERO_STRUCT(logon);
|
||||
logon.command = NETLOGON_QUERY_FOR_PDC2;
|
||||
logon.req.pdc2.request_count = 0;
|
||||
logon.req.pdc2.computer_name = TEST_NAME;
|
||||
logon.req.pdc2.user_name = "";
|
||||
logon.req.pdc2.mailslot_name = dgmslot->mailslot_name;
|
||||
logon.req.pdc2.nt_version = 11;
|
||||
logon.req.pdc2.lmnt_token = 0xFFFF;
|
||||
logon.req.pdc2.lm20_token = 0xFFFF;
|
||||
|
||||
make_nbt_name_client(&myname, TEST_NAME);
|
||||
|
||||
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
address, 0);
|
||||
|
||||
torture_assert(tctx, dest != NULL, "Error getting address");
|
||||
status = dgram_mailslot_netlogon_send(dgmsock, &name, dest,
|
||||
&myname, &logon);
|
||||
torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request");
|
||||
|
||||
while (timeval_elapsed(&tv) < 5 && replies == 0) {
|
||||
event_loop_once(dgmsock->event_ctx);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
reply handler for ntlogon request
|
||||
*/
|
||||
static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot,
|
||||
struct nbt_dgram_packet *packet,
|
||||
struct socket_address *src)
|
||||
{
|
||||
NTSTATUS status;
|
||||
struct nbt_ntlogon_packet ntlogon;
|
||||
int *replies = dgmslot->private;
|
||||
|
||||
printf("ntlogon reply from %s:%d\n", src->addr, src->port);
|
||||
|
||||
status = dgram_mailslot_ntlogon_parse(dgmslot, dgmslot, packet, &ntlogon);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
printf("Failed to parse ntlogon packet from %s:%d\n",
|
||||
src->addr, src->port);
|
||||
return;
|
||||
}
|
||||
|
||||
NDR_PRINT_DEBUG(nbt_ntlogon_packet, &ntlogon);
|
||||
|
||||
(*replies)++;
|
||||
}
|
||||
|
||||
|
||||
/* test UDP/138 ntlogon requests */
|
||||
static bool nbt_test_ntlogon(struct torture_context *tctx)
|
||||
{
|
||||
struct dgram_mailslot_handler *dgmslot;
|
||||
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
|
||||
struct socket_address *dest;
|
||||
struct test_join *join_ctx;
|
||||
struct cli_credentials *machine_credentials;
|
||||
const struct dom_sid *dom_sid;
|
||||
|
||||
const char *myaddress;
|
||||
struct nbt_ntlogon_packet logon;
|
||||
struct nbt_name myname;
|
||||
NTSTATUS status;
|
||||
struct timeval tv = timeval_current();
|
||||
int replies = 0;
|
||||
|
||||
struct socket_address *socket_address;
|
||||
const char *address;
|
||||
struct nbt_name name;
|
||||
|
||||
name.name = lp_workgroup();
|
||||
name.type = NBT_NAME_LOGON;
|
||||
name.scope = NULL;
|
||||
|
||||
/* do an initial name resolution to find its IP */
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
resolve_name(&name, tctx, &address, event_context_find(tctx)),
|
||||
talloc_asprintf(tctx, "Failed to resolve %s", name.name));
|
||||
|
||||
myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
|
||||
|
||||
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
myaddress, lp_dgram_port());
|
||||
torture_assert(tctx, socket_address != NULL, "Error getting address");
|
||||
|
||||
/* try receiving replies on port 138 first, which will only
|
||||
work if we are root and smbd/nmbd are not running - fall
|
||||
back to listening on any port, which means replies from
|
||||
some windows versions won't be seen */
|
||||
status = socket_listen(dgmsock->sock, socket_address, 0, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(socket_address);
|
||||
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
myaddress, 0);
|
||||
torture_assert(tctx, socket_address != NULL, "Error getting address");
|
||||
|
||||
socket_listen(dgmsock->sock, socket_address, 0, 0);
|
||||
}
|
||||
|
||||
join_ctx = torture_join_domain(TEST_NAME,
|
||||
ACB_WSTRUST, &machine_credentials);
|
||||
torture_assert(tctx, join_ctx != NULL,
|
||||
talloc_asprintf(tctx, "Failed to join domain %s as %s\n",
|
||||
lp_workgroup(), TEST_NAME));
|
||||
|
||||
dom_sid = torture_join_sid(join_ctx);
|
||||
|
||||
/* setup a temporary mailslot listener for replies */
|
||||
dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC,
|
||||
ntlogon_handler, &replies);
|
||||
|
||||
|
||||
ZERO_STRUCT(logon);
|
||||
logon.command = NTLOGON_SAM_LOGON;
|
||||
logon.req.logon.request_count = 0;
|
||||
logon.req.logon.computer_name = TEST_NAME;
|
||||
logon.req.logon.user_name = TEST_NAME"$";
|
||||
logon.req.logon.mailslot_name = dgmslot->mailslot_name;
|
||||
logon.req.logon.acct_control = ACB_WSTRUST;
|
||||
logon.req.logon.sid = *dom_sid;
|
||||
logon.req.logon.nt_version = 1;
|
||||
logon.req.logon.lmnt_token = 0xFFFF;
|
||||
logon.req.logon.lm20_token = 0xFFFF;
|
||||
|
||||
make_nbt_name_client(&myname, TEST_NAME);
|
||||
|
||||
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
|
||||
address, 0);
|
||||
torture_assert(tctx, dest != NULL, "Error getting address");
|
||||
status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE,
|
||||
&name, dest, &myname, &logon);
|
||||
torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request");
|
||||
|
||||
while (timeval_elapsed(&tv) < 5 && replies == 0) {
|
||||
event_loop_once(dgmsock->event_ctx);
|
||||
}
|
||||
|
||||
torture_leave_domain(join_ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test nbt dgram operations
|
||||
*/
|
||||
struct torture_suite *torture_nbt_dgram(void)
|
||||
{
|
||||
struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DGRAM");
|
||||
|
||||
torture_suite_add_simple_test(suite, "netlogon", nbt_test_netlogon);
|
||||
torture_suite_add_simple_test(suite, "netlogon2", nbt_test_netlogon2);
|
||||
torture_suite_add_simple_test(suite, "ntlogon", nbt_test_ntlogon);
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
SMB torture tester
|
||||
Copyright (C) Jelmer Vernooij 2006
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "torture/torture.h"
|
||||
#include "torture/nbt/proto.h"
|
||||
#include "torture/ui.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
|
||||
bool torture_nbt_get_name(struct torture_context *tctx,
|
||||
struct nbt_name *name,
|
||||
const char **address)
|
||||
{
|
||||
make_nbt_name_server(name, strupper_talloc(tctx,
|
||||
torture_setting_string(tctx, "host", NULL)));
|
||||
|
||||
/* do an initial name resolution to find its IP */
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
resolve_name(name, tctx, address, NULL),
|
||||
talloc_asprintf(tctx,
|
||||
"Failed to resolve %s", name->name));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NTSTATUS torture_nbt_init(void)
|
||||
{
|
||||
struct torture_suite *suite = torture_suite_create(
|
||||
talloc_autofree_context(),
|
||||
"NBT");
|
||||
/* nbt tests */
|
||||
torture_suite_add_suite(suite, torture_nbt_register());
|
||||
torture_suite_add_suite(suite, torture_nbt_wins());
|
||||
torture_suite_add_suite(suite, torture_nbt_dgram());
|
||||
torture_suite_add_suite(suite, torture_nbt_winsreplication());
|
||||
torture_suite_add_suite(suite, torture_bench_nbt());
|
||||
torture_suite_add_suite(suite, torture_bench_wins());
|
||||
|
||||
suite->description = talloc_strdup(suite,
|
||||
"NetBIOS over TCP/IP and WINS tests");
|
||||
|
||||
torture_register_suite(suite);
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
NBT name query testing
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "torture/torture.h"
|
||||
#include "torture/nbt/proto.h"
|
||||
|
||||
struct result_struct {
|
||||
int num_pass;
|
||||
int num_fail;
|
||||
};
|
||||
|
||||
static void increment_handler(struct nbt_name_request *req)
|
||||
{
|
||||
struct result_struct *v = talloc_get_type(req->async.private, struct result_struct);
|
||||
if (req->state != NBT_REQUEST_DONE) {
|
||||
v->num_fail++;
|
||||
} else {
|
||||
v->num_pass++;
|
||||
}
|
||||
talloc_free(req);
|
||||
}
|
||||
|
||||
/*
|
||||
benchmark simple name queries
|
||||
*/
|
||||
static bool bench_namequery(struct torture_context *tctx)
|
||||
{
|
||||
struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
|
||||
int num_sent=0;
|
||||
struct result_struct *result;
|
||||
struct nbt_name_query io;
|
||||
struct timeval tv = timeval_current();
|
||||
int timelimit = torture_setting_int(tctx, "timelimit", 10);
|
||||
|
||||
const char *address;
|
||||
struct nbt_name name;
|
||||
|
||||
if (!torture_nbt_get_name(tctx, &name, &address))
|
||||
return false;
|
||||
|
||||
io.in.name = name;
|
||||
io.in.dest_addr = address;
|
||||
io.in.broadcast = False;
|
||||
io.in.wins_lookup = False;
|
||||
io.in.timeout = 1;
|
||||
|
||||
result = talloc_zero(tctx, struct result_struct);
|
||||
|
||||
torture_comment(tctx, "Running for %d seconds\n", timelimit);
|
||||
while (timeval_elapsed(&tv) < timelimit) {
|
||||
while (num_sent - (result->num_pass+result->num_fail) < 10) {
|
||||
struct nbt_name_request *req;
|
||||
req = nbt_name_query_send(nbtsock, &io);
|
||||
torture_assert(tctx, req != NULL, "Failed to setup request!");
|
||||
req->async.fn = increment_handler;
|
||||
req->async.private = result;
|
||||
num_sent++;
|
||||
if (num_sent % 1000 == 0) {
|
||||
torture_comment(tctx, "%.1f queries per second (%d failures) \r",
|
||||
result->num_pass / timeval_elapsed(&tv),
|
||||
result->num_fail);
|
||||
}
|
||||
}
|
||||
|
||||
event_loop_once(nbtsock->event_ctx);
|
||||
}
|
||||
|
||||
while (num_sent != (result->num_pass + result->num_fail)) {
|
||||
event_loop_once(nbtsock->event_ctx);
|
||||
}
|
||||
|
||||
torture_comment(tctx, "%.1f queries per second (%d failures) \n",
|
||||
result->num_pass / timeval_elapsed(&tv),
|
||||
result->num_fail);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
benchmark how fast a server can respond to name queries
|
||||
*/
|
||||
struct torture_suite *torture_bench_nbt(void)
|
||||
{
|
||||
struct torture_suite *suite = torture_suite_create(talloc_autofree_context(),
|
||||
"BENCH");
|
||||
torture_suite_add_simple_test(suite, "namequery", bench_namequery);
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
NBT name registration testing
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "system/network.h"
|
||||
#include "lib/socket/netif.h"
|
||||
#include "torture/torture.h"
|
||||
#include "torture/nbt/proto.h"
|
||||
|
||||
#define CHECK_VALUE(tctx, v, correct) \
|
||||
torture_assert_int_equal(tctx, v, correct, "Incorrect value")
|
||||
|
||||
#define CHECK_STRING(tctx, v, correct) \
|
||||
torture_assert_casestr_equal(tctx, v, correct, "Incorrect value")
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
test that a server responds correctly to attempted registrations of its name
|
||||
*/
|
||||
static bool nbt_register_own(struct torture_context *tctx)
|
||||
{
|
||||
struct nbt_name_register io;
|
||||
NTSTATUS status;
|
||||
struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
|
||||
struct socket_address *socket_address;
|
||||
struct nbt_name name;
|
||||
const char *address;
|
||||
const char *myaddress;
|
||||
|
||||
if (!torture_nbt_get_name(tctx, &name, &address))
|
||||
return false;
|
||||
|
||||
myaddress = iface_best_ip(address);
|
||||
|
||||
socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name,
|
||||
myaddress, 0);
|
||||
torture_assert(tctx, socket_address != NULL, "Unable to get address");
|
||||
|
||||
status = socket_listen(nbtsock->sock, socket_address, 0, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
"socket_listen for nbt_register_own failed");
|
||||
|
||||
torture_comment(tctx, "Testing name defense to name registration\n");
|
||||
|
||||
io.in.name = name;
|
||||
io.in.dest_addr = address;
|
||||
io.in.address = myaddress;
|
||||
io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE;
|
||||
io.in.register_demand = False;
|
||||
io.in.broadcast = True;
|
||||
io.in.multi_homed = False;
|
||||
io.in.ttl = 1234;
|
||||
io.in.timeout = 3;
|
||||
io.in.retries = 0;
|
||||
|
||||
status = nbt_name_register(nbtsock, tctx, &io);
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
talloc_asprintf(tctx, "Bad response from %s for name register",
|
||||
address));
|
||||
|
||||
CHECK_STRING(tctx, io.out.name.name, name.name);
|
||||
CHECK_VALUE(tctx, io.out.name.type, name.type);
|
||||
CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
|
||||
|
||||
/* check a register demand */
|
||||
io.in.address = myaddress;
|
||||
io.in.register_demand = True;
|
||||
|
||||
status = nbt_name_register(nbtsock, tctx, &io);
|
||||
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
talloc_asprintf(tctx, "Bad response from %s for name register demand", address));
|
||||
|
||||
CHECK_STRING(tctx, io.out.name.name, name.name);
|
||||
CHECK_VALUE(tctx, io.out.name.type, name.type);
|
||||
CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test that a server responds correctly to attempted name refresh requests
|
||||
*/
|
||||
static bool nbt_refresh_own(struct torture_context *tctx)
|
||||
{
|
||||
struct nbt_name_refresh io;
|
||||
NTSTATUS status;
|
||||
struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
|
||||
const char *myaddress;
|
||||
struct socket_address *socket_address;
|
||||
struct nbt_name name;
|
||||
const char *address;
|
||||
|
||||
if (!torture_nbt_get_name(tctx, &name, &address))
|
||||
return false;
|
||||
|
||||
myaddress = iface_best_ip(address);
|
||||
|
||||
socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name,
|
||||
myaddress, 0);
|
||||
torture_assert(tctx, socket_address != NULL,
|
||||
"Can't parse socket address");
|
||||
|
||||
status = socket_listen(nbtsock->sock, socket_address, 0, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
"socket_listen for nbt_referesh_own failed");
|
||||
|
||||
torture_comment(tctx, "Testing name defense to name refresh\n");
|
||||
|
||||
io.in.name = name;
|
||||
io.in.dest_addr = address;
|
||||
io.in.address = myaddress;
|
||||
io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE;
|
||||
io.in.broadcast = False;
|
||||
io.in.ttl = 1234;
|
||||
io.in.timeout = 3;
|
||||
io.in.retries = 0;
|
||||
|
||||
status = nbt_name_refresh(nbtsock, tctx, &io);
|
||||
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
talloc_asprintf(tctx, "Bad response from %s for name refresh", address));
|
||||
|
||||
CHECK_STRING(tctx, io.out.name.name, name.name);
|
||||
CHECK_VALUE(tctx, io.out.name.type, name.type);
|
||||
CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
test name registration to a server
|
||||
*/
|
||||
struct torture_suite *torture_nbt_register(void)
|
||||
{
|
||||
struct torture_suite *suite;
|
||||
|
||||
suite = torture_suite_create(talloc_autofree_context(), "REGISTER");
|
||||
torture_suite_add_simple_test(suite, "register_own", nbt_register_own);
|
||||
torture_suite_add_simple_test(suite, "refresh_own", nbt_refresh_own);
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
NBT WINS server testing
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "system/network.h"
|
||||
#include "lib/socket/netif.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
#include "torture/torture.h"
|
||||
#include "torture/nbt/proto.h"
|
||||
|
||||
#define CHECK_VALUE(tctx, v, correct) \
|
||||
torture_assert_int_equal(tctx, v, correct, "Incorrect value")
|
||||
|
||||
#define CHECK_STRING(tctx, v, correct) \
|
||||
torture_assert_casestr_equal(tctx, v, correct, "Incorrect value")
|
||||
|
||||
#define CHECK_NAME(tctx, _name, correct) do { \
|
||||
CHECK_STRING(tctx, (_name).name, (correct).name); \
|
||||
CHECK_VALUE(tctx, (uint8_t)(_name).type, (uint8_t)(correct).type); \
|
||||
CHECK_STRING(tctx, (_name).scope, (correct).scope); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
test operations against a WINS server
|
||||
*/
|
||||
static bool nbt_test_wins_name(struct torture_context *tctx, const char *address,
|
||||
struct nbt_name *name, uint16_t nb_flags)
|
||||
{
|
||||
struct nbt_name_register_wins io;
|
||||
struct nbt_name_query query;
|
||||
struct nbt_name_refresh_wins refresh;
|
||||
struct nbt_name_release release;
|
||||
NTSTATUS status;
|
||||
struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
|
||||
const char *myaddress = talloc_strdup(tctx, iface_best_ip(address));
|
||||
struct socket_address *socket_address;
|
||||
|
||||
socket_address = socket_address_from_strings(tctx,
|
||||
nbtsock->sock->backend_name,
|
||||
myaddress, 0);
|
||||
torture_assert(tctx, socket_address != NULL,
|
||||
"Error getting address");
|
||||
|
||||
/* we do the listen here to ensure the WINS server receives the packets from
|
||||
the right IP */
|
||||
status = socket_listen(nbtsock->sock, socket_address, 0, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
"socket_listen for WINS failed");
|
||||
talloc_free(socket_address);
|
||||
|
||||
torture_comment(tctx, "Testing name registration to WINS with name %s at %s nb_flags=0x%x\n",
|
||||
nbt_name_string(tctx, name), myaddress, nb_flags);
|
||||
|
||||
torture_comment(tctx, "release the name\n");
|
||||
release.in.name = *name;
|
||||
release.in.dest_addr = address;
|
||||
release.in.address = myaddress;
|
||||
release.in.nb_flags = nb_flags;
|
||||
release.in.broadcast = False;
|
||||
release.in.timeout = 3;
|
||||
release.in.retries = 0;
|
||||
|
||||
status = nbt_name_release(nbtsock, tctx, &release);
|
||||
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name query", address));
|
||||
CHECK_VALUE(tctx, release.out.rcode, 0);
|
||||
|
||||
torture_comment(tctx, "register the name\n");
|
||||
io.in.name = *name;
|
||||
io.in.wins_servers = str_list_make(tctx, address, NULL);
|
||||
io.in.addresses = str_list_make(tctx, myaddress, NULL);
|
||||
io.in.nb_flags = nb_flags;
|
||||
io.in.ttl = 300000;
|
||||
|
||||
status = nbt_name_register_wins(nbtsock, tctx, &io);
|
||||
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name register", address));
|
||||
|
||||
CHECK_STRING(tctx, io.out.wins_server, address);
|
||||
CHECK_VALUE(tctx, io.out.rcode, 0);
|
||||
|
||||
if (name->type != NBT_NAME_MASTER &&
|
||||
name->type != NBT_NAME_LOGON &&
|
||||
name->type != NBT_NAME_BROWSER &&
|
||||
(nb_flags & NBT_NM_GROUP)) {
|
||||
torture_comment(tctx, "Try to register as non-group\n");
|
||||
io.in.nb_flags &= ~NBT_NM_GROUP;
|
||||
status = nbt_name_register_wins(nbtsock, tctx, &io);
|
||||
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name register\n",
|
||||
address));
|
||||
CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
|
||||
}
|
||||
|
||||
torture_comment(tctx, "query the name to make sure its there\n");
|
||||
query.in.name = *name;
|
||||
query.in.dest_addr = address;
|
||||
query.in.broadcast = False;
|
||||
query.in.wins_lookup = True;
|
||||
query.in.timeout = 3;
|
||||
query.in.retries = 0;
|
||||
|
||||
status = nbt_name_query(nbtsock, tctx, &query);
|
||||
if (name->type == NBT_NAME_MASTER) {
|
||||
torture_assert_ntstatus_equal(
|
||||
tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
|
||||
talloc_asprintf(tctx, "Bad response from %s for name query", address));
|
||||
return true;
|
||||
}
|
||||
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name query", address));
|
||||
|
||||
CHECK_NAME(tctx, query.out.name, *name);
|
||||
CHECK_VALUE(tctx, query.out.num_addrs, 1);
|
||||
if (name->type != NBT_NAME_LOGON &&
|
||||
(nb_flags & NBT_NM_GROUP)) {
|
||||
CHECK_STRING(tctx, query.out.reply_addrs[0], "255.255.255.255");
|
||||
} else {
|
||||
CHECK_STRING(tctx, query.out.reply_addrs[0], myaddress);
|
||||
}
|
||||
|
||||
|
||||
query.in.name.name = strupper_talloc(tctx, name->name);
|
||||
if (query.in.name.name &&
|
||||
strcmp(query.in.name.name, name->name) != 0) {
|
||||
torture_comment(tctx, "check case sensitivity\n");
|
||||
status = nbt_name_query(nbtsock, tctx, &query);
|
||||
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, talloc_asprintf(tctx, "Bad response from %s for name query", address));
|
||||
}
|
||||
|
||||
query.in.name = *name;
|
||||
if (name->scope) {
|
||||
query.in.name.scope = strupper_talloc(tctx, name->scope);
|
||||
}
|
||||
if (query.in.name.scope &&
|
||||
strcmp(query.in.name.scope, name->scope) != 0) {
|
||||
torture_comment(tctx, "check case sensitivity on scope\n");
|
||||
status = nbt_name_query(nbtsock, tctx, &query);
|
||||
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, talloc_asprintf(tctx, "Bad response from %s for name query", address));
|
||||
}
|
||||
|
||||
torture_comment(tctx, "refresh the name\n");
|
||||
refresh.in.name = *name;
|
||||
refresh.in.wins_servers = str_list_make(tctx, address, NULL);
|
||||
refresh.in.addresses = str_list_make(tctx, myaddress, NULL);
|
||||
refresh.in.nb_flags = nb_flags;
|
||||
refresh.in.ttl = 12345;
|
||||
|
||||
status = nbt_name_refresh_wins(nbtsock, tctx, &refresh);
|
||||
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name refresh", address));
|
||||
|
||||
CHECK_STRING(tctx, refresh.out.wins_server, address);
|
||||
CHECK_VALUE(tctx, refresh.out.rcode, 0);
|
||||
|
||||
torture_comment(tctx, "release the name\n");
|
||||
release.in.name = *name;
|
||||
release.in.dest_addr = address;
|
||||
release.in.address = myaddress;
|
||||
release.in.nb_flags = nb_flags;
|
||||
release.in.broadcast = False;
|
||||
release.in.timeout = 3;
|
||||
release.in.retries = 0;
|
||||
|
||||
status = nbt_name_release(nbtsock, tctx, &release);
|
||||
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name query", address));
|
||||
|
||||
CHECK_NAME(tctx, release.out.name, *name);
|
||||
CHECK_VALUE(tctx, release.out.rcode, 0);
|
||||
|
||||
torture_comment(tctx, "release again\n");
|
||||
status = nbt_name_release(nbtsock, tctx, &release);
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
talloc_asprintf(tctx, "Bad response from %s for name query",
|
||||
address));
|
||||
|
||||
CHECK_NAME(tctx, release.out.name, *name);
|
||||
CHECK_VALUE(tctx, release.out.rcode, 0);
|
||||
|
||||
|
||||
torture_comment(tctx, "query the name to make sure its gone\n");
|
||||
query.in.name = *name;
|
||||
status = nbt_name_query(nbtsock, tctx, &query);
|
||||
if (name->type != NBT_NAME_LOGON &&
|
||||
(nb_flags & NBT_NM_GROUP)) {
|
||||
torture_assert_ntstatus_ok(tctx, status,
|
||||
"ERROR: Name query failed after group release");
|
||||
} else {
|
||||
torture_assert_ntstatus_equal(tctx, status,
|
||||
NT_STATUS_OBJECT_NAME_NOT_FOUND,
|
||||
"Incorrect response to name query");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
test operations against a WINS server
|
||||
*/
|
||||
static bool nbt_test_wins(struct torture_context *tctx)
|
||||
{
|
||||
struct nbt_name name;
|
||||
uint32_t r = (uint32_t)(random() % (100000));
|
||||
const char *address;
|
||||
bool ret = true;
|
||||
|
||||
if (!torture_nbt_get_name(tctx, &name, &address))
|
||||
return false;
|
||||
|
||||
name.name = talloc_asprintf(tctx, "_TORTURE-%5u", r);
|
||||
|
||||
name.type = NBT_NAME_CLIENT;
|
||||
name.scope = NULL;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.type = NBT_NAME_MASTER;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
|
||||
|
||||
name.type = NBT_NAME_SERVER;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.type = NBT_NAME_LOGON;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
|
||||
|
||||
name.type = NBT_NAME_BROWSER;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
|
||||
|
||||
name.type = NBT_NAME_PDC;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.type = 0xBF;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.type = 0xBE;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.scope = "example";
|
||||
name.type = 0x72;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.scope = "example";
|
||||
name.type = 0x71;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
|
||||
|
||||
name.scope = "foo.example.com";
|
||||
name.type = 0x72;
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.name = talloc_asprintf(tctx, "_T\01-%5u.foo", r);
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.name = "";
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.name = talloc_asprintf(tctx, ".");
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
name.name = talloc_asprintf(tctx, "%5u-\377\200\300FOO", r);
|
||||
ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
test WINS operations
|
||||
*/
|
||||
struct torture_suite *torture_nbt_wins(void)
|
||||
{
|
||||
struct torture_suite *suite = torture_suite_create(talloc_autofree_context(),
|
||||
"WINS");
|
||||
|
||||
torture_suite_add_simple_test(suite, "wins", nbt_test_wins);
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
WINS benchmark test
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "system/network.h"
|
||||
#include "lib/socket/netif.h"
|
||||
#include "torture/torture.h"
|
||||
#include "torture/nbt/proto.h"
|
||||
|
||||
struct wins_state {
|
||||
int num_names;
|
||||
bool *registered;
|
||||
int pass_count;
|
||||
int fail_count;
|
||||
const char *wins_server;
|
||||
const char *my_ip;
|
||||
uint32_t ttl;
|
||||
};
|
||||
|
||||
struct idx_state {
|
||||
int idx;
|
||||
struct wins_state *state;
|
||||
};
|
||||
|
||||
struct nbt_name generate_name(TALLOC_CTX *tctx, int idx)
|
||||
{
|
||||
struct nbt_name name;
|
||||
name.name = talloc_asprintf(tctx, "WINSBench%6u", idx);
|
||||
name.type = 0x4;
|
||||
name.scope = NULL;
|
||||
return name;
|
||||
}
|
||||
|
||||
static void register_handler(struct nbt_name_request *req)
|
||||
{
|
||||
struct idx_state *istate = talloc_get_type(req->async.private, struct idx_state);
|
||||
struct wins_state *state = istate->state;
|
||||
struct nbt_name_register io;
|
||||
NTSTATUS status;
|
||||
|
||||
status = nbt_name_register_recv(req, istate, &io);
|
||||
if (!NT_STATUS_IS_OK(status) || io.out.rcode != NBT_RCODE_OK) {
|
||||
state->fail_count++;
|
||||
} else {
|
||||
state->pass_count++;
|
||||
state->registered[istate->idx] = true;
|
||||
}
|
||||
talloc_free(istate);
|
||||
}
|
||||
|
||||
/*
|
||||
generate a registration
|
||||
*/
|
||||
static void generate_register(struct nbt_name_socket *nbtsock, struct wins_state *state, int idx)
|
||||
{
|
||||
struct nbt_name_register io;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(state);
|
||||
struct nbt_name_request *req;
|
||||
struct idx_state *istate;
|
||||
|
||||
istate = talloc(nbtsock, struct idx_state);
|
||||
istate->idx = idx;
|
||||
istate->state = state;
|
||||
|
||||
io.in.name = generate_name(tmp_ctx, idx);
|
||||
io.in.dest_addr = state->wins_server;
|
||||
io.in.address = state->my_ip;
|
||||
io.in.nb_flags = NBT_NODE_H;
|
||||
io.in.register_demand = false;
|
||||
io.in.broadcast = false;
|
||||
io.in.multi_homed = false;
|
||||
io.in.ttl = state->ttl;
|
||||
io.in.timeout = 2;
|
||||
io.in.retries = 1;
|
||||
|
||||
req = nbt_name_register_send(nbtsock, &io);
|
||||
|
||||
req->async.fn = register_handler;
|
||||
req->async.private = istate;
|
||||
|
||||
talloc_free(tmp_ctx);
|
||||
}
|
||||
|
||||
|
||||
static void release_handler(struct nbt_name_request *req)
|
||||
{
|
||||
struct idx_state *istate = talloc_get_type(req->async.private, struct idx_state);
|
||||
struct wins_state *state = istate->state;
|
||||
struct nbt_name_release io;
|
||||
NTSTATUS status;
|
||||
|
||||
status = nbt_name_release_recv(req, istate, &io);
|
||||
if (state->registered[istate->idx] &&
|
||||
(!NT_STATUS_IS_OK(status) || io.out.rcode != NBT_RCODE_OK)) {
|
||||
state->fail_count++;
|
||||
} else {
|
||||
state->pass_count++;
|
||||
state->registered[istate->idx] = false;
|
||||
}
|
||||
talloc_free(istate);
|
||||
}
|
||||
|
||||
/*
|
||||
generate a name release
|
||||
*/
|
||||
static void generate_release(struct nbt_name_socket *nbtsock, struct wins_state *state, int idx)
|
||||
{
|
||||
struct nbt_name_release io;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(state);
|
||||
struct nbt_name_request *req;
|
||||
struct idx_state *istate;
|
||||
|
||||
istate = talloc(nbtsock, struct idx_state);
|
||||
istate->idx = idx;
|
||||
istate->state = state;
|
||||
|
||||
io.in.name = generate_name(tmp_ctx, idx);
|
||||
io.in.dest_addr = state->wins_server;
|
||||
io.in.address = state->my_ip;
|
||||
io.in.nb_flags = NBT_NODE_H;
|
||||
io.in.broadcast = false;
|
||||
io.in.timeout = 2;
|
||||
io.in.retries = 1;
|
||||
|
||||
req = nbt_name_release_send(nbtsock, &io);
|
||||
|
||||
req->async.fn = release_handler;
|
||||
req->async.private = istate;
|
||||
|
||||
talloc_free(tmp_ctx);
|
||||
}
|
||||
|
||||
|
||||
static void query_handler(struct nbt_name_request *req)
|
||||
{
|
||||
struct idx_state *istate = talloc_get_type(req->async.private, struct idx_state);
|
||||
struct wins_state *state = istate->state;
|
||||
struct nbt_name_query io;
|
||||
NTSTATUS status;
|
||||
|
||||
status = nbt_name_query_recv(req, istate, &io);
|
||||
if (!NT_STATUS_IS_OK(status) && state->registered[istate->idx]) {
|
||||
state->fail_count++;
|
||||
} else {
|
||||
state->pass_count++;
|
||||
}
|
||||
talloc_free(istate);
|
||||
}
|
||||
|
||||
/*
|
||||
generate a name query
|
||||
*/
|
||||
static void generate_query(struct nbt_name_socket *nbtsock, struct wins_state *state, int idx)
|
||||
{
|
||||
struct nbt_name_query io;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(state);
|
||||
struct nbt_name_request *req;
|
||||
struct idx_state *istate;
|
||||
|
||||
istate = talloc(nbtsock, struct idx_state);
|
||||
istate->idx = idx;
|
||||
istate->state = state;
|
||||
|
||||
io.in.name = generate_name(tmp_ctx, idx);
|
||||
io.in.dest_addr = state->wins_server;
|
||||
io.in.broadcast = false;
|
||||
io.in.wins_lookup = true;
|
||||
io.in.timeout = 2;
|
||||
io.in.retries = 1;
|
||||
|
||||
req = nbt_name_query_send(nbtsock, &io);
|
||||
|
||||
req->async.fn = query_handler;
|
||||
req->async.private = istate;
|
||||
|
||||
talloc_free(tmp_ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
generate one WINS request
|
||||
*/
|
||||
static void generate_request(struct nbt_name_socket *nbtsock, struct wins_state *state, int idx)
|
||||
{
|
||||
if (random() % 5 == 0) {
|
||||
generate_register(nbtsock, state, idx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (random() % 20 == 0) {
|
||||
generate_release(nbtsock, state, idx);
|
||||
return;
|
||||
}
|
||||
|
||||
generate_query(nbtsock, state, idx);
|
||||
}
|
||||
|
||||
/*
|
||||
benchmark simple name queries
|
||||
*/
|
||||
static bool bench_wins(struct torture_context *tctx)
|
||||
{
|
||||
struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
|
||||
int num_sent=0;
|
||||
struct timeval tv = timeval_current();
|
||||
bool ret = true;
|
||||
int timelimit = torture_setting_int(tctx, "timelimit", 10);
|
||||
struct wins_state *state;
|
||||
extern int torture_entries;
|
||||
struct socket_address *my_ip;
|
||||
struct nbt_name name;
|
||||
const char *address;
|
||||
|
||||
if (!torture_nbt_get_name(tctx, &name, &address))
|
||||
return false;
|
||||
|
||||
state = talloc_zero(nbtsock, struct wins_state);
|
||||
|
||||
state->num_names = torture_entries;
|
||||
state->registered = talloc_zero_array(state, bool, state->num_names);
|
||||
state->wins_server = address;
|
||||
state->my_ip = talloc_strdup(tctx, iface_best_ip(address));
|
||||
state->ttl = timelimit;
|
||||
|
||||
my_ip = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name,
|
||||
state->my_ip, 0);
|
||||
|
||||
socket_listen(nbtsock->sock, my_ip, 0, 0);
|
||||
|
||||
torture_comment(tctx, "Running for %d seconds\n", timelimit);
|
||||
while (timeval_elapsed(&tv) < timelimit) {
|
||||
while (num_sent - (state->pass_count+state->fail_count) < 10) {
|
||||
generate_request(nbtsock, state, num_sent % state->num_names);
|
||||
num_sent++;
|
||||
if (num_sent % 50 == 0) {
|
||||
torture_comment(tctx, "%.1f queries per second (%d failures) \r",
|
||||
state->pass_count / timeval_elapsed(&tv),
|
||||
state->fail_count);
|
||||
}
|
||||
}
|
||||
|
||||
event_loop_once(nbtsock->event_ctx);
|
||||
}
|
||||
|
||||
while (num_sent != (state->pass_count + state->fail_count)) {
|
||||
event_loop_once(nbtsock->event_ctx);
|
||||
}
|
||||
|
||||
torture_comment(tctx, "%.1f queries per second (%d failures) \n",
|
||||
state->pass_count / timeval_elapsed(&tv),
|
||||
state->fail_count);
|
||||
|
||||
talloc_free(nbtsock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
benchmark how fast a WINS server can respond to a mixture of
|
||||
registration/refresh/release and name query requests
|
||||
*/
|
||||
struct torture_suite *torture_bench_wins(void)
|
||||
{
|
||||
struct torture_suite *suite = torture_suite_create(
|
||||
talloc_autofree_context(),
|
||||
"BENCH-WINS");
|
||||
|
||||
torture_suite_add_simple_test(suite, "wins", bench_wins);
|
||||
|
||||
return suite;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user