1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained

output in the testsuite rather than just True or False for a
set of tests.

The aim is to use this for:
 * known failure lists (run all tests and detect tests that
						started working or started failing). This
   would allow us to get rid of the RPC-SAMBA3-* tests
 * nicer torture output
 * simplification of the testsuite system
 * compatibility with other unit testing systems
 * easier usage of smbtorture (being able to run one test
						and automatically set up the environment for that)

This is still a work-in-progress; expect more updates over the next couple of
days.
(This used to be commit 0eb6097305)
This commit is contained in:
Jelmer Vernooij 2006-10-16 13:06:41 +00:00 committed by Gerald (Jerry) Carter
parent 0f2347e417
commit 8773e743c5
75 changed files with 5390 additions and 6574 deletions

View File

@ -399,7 +399,7 @@ NTSTATUS gensec_sasl_init(void)
if (oldmech) { if (oldmech) {
continue; continue;
} }
newmech = talloc(NULL, struct gensec_security_ops); newmech = talloc(talloc_autofree_context(), struct gensec_security_ops);
if (!newmech) { if (!newmech) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }

View File

@ -299,7 +299,7 @@ typedef struct MprVar {
#if 0 && !BLD_DEBUG && !LINUX && !VXWORKS #if 0 && !BLD_DEBUG && !LINUX && !VXWORKS
union { union {
#endif #endif
int boolean; /* Use int for speed */ bool boolean;
#if BLD_FEATURE_FLOATING_POINT #if BLD_FEATURE_FLOATING_POINT
double floating; double floating;
#endif #endif

View File

@ -17,6 +17,7 @@
*/ */
#include "includes.h" #include "includes.h"
#include "torture/ui.h"
#include "lib/crypto/crypto.h" #include "lib/crypto/crypto.h"
@ -50,7 +51,8 @@ static const char *resultarray[4] =
"DE A3 56 A2 CD DD 90 C7 A7 EC ED C5 EB B5 63 93 4F 46 04 52 " "DE A3 56 A2 CD DD 90 C7 A7 EC ED C5 EB B5 63 93 4F 46 04 52 "
}; };
BOOL torture_local_crypto_sha1(struct torture_context *torture)
bool torture_local_crypto_sha1(struct torture_context *tctx)
{ {
struct SHA1Context sha; struct SHA1Context sha;
int i, j, err; int i, j, err;
@ -64,52 +66,33 @@ BOOL torture_local_crypto_sha1(struct torture_context *torture)
for(j = 0; j < 4; ++j) for(j = 0; j < 4; ++j)
{ {
ZERO_STRUCT(tmp); ZERO_STRUCT(tmp);
printf( "\nTest %d: %d, '%s'\n", torture_comment(tctx, "Test %d: %d, '%s'\n",
j+1, j+1,
repeatcount[j], repeatcount[j],
testarray[j]); testarray[j]);
err = SHA1Init(&sha); err = SHA1Init(&sha);
if (err) torture_assert_int_equal(tctx, err, 0, "SHA1Init Error");
{
fprintf(stderr, "SHA1Init Error %d.\n", err );
ret = False;
break; /* out of for j loop */
}
for(i = 0; i < repeatcount[j]; ++i) for(i = 0; i < repeatcount[j]; ++i)
{ {
err = SHA1Update(&sha, err = SHA1Update(&sha,
(const unsigned char *) testarray[j], (const unsigned char *) testarray[j],
strlen(testarray[j])); strlen(testarray[j]));
if (err) torture_assert_int_equal(tctx, err, 0, "SHA1Update Error");
{
fprintf(stderr, "SHA1Update Error %d.\n", err );
ret = False;
break; /* out of for i loop */
}
} }
err = SHA1Final(Message_Digest, &sha); err = SHA1Final(Message_Digest, &sha);
if (err) torture_assert_int_equal(tctx, err, 0,
"SHA1Result Error, could not compute message digest.");
torture_comment(tctx, "\t");
for(i = 0; i < 20 ; ++i)
{ {
fprintf(stderr,
"SHA1Result Error %d, could not compute message digest.\n",
err );
ret = False;
}
else
{
printf("\t");
for(i = 0; i < 20 ; ++i)
{
snprintf(tmp+(i*3), sizeof(tmp) - (i*3),"%02X ", Message_Digest[i]); snprintf(tmp+(i*3), sizeof(tmp) - (i*3),"%02X ", Message_Digest[i]);
printf("%02X ", Message_Digest[i]); torture_comment(tctx, "%02X ", Message_Digest[i]);
}
printf("\n");
} }
printf("Should match:\n"); torture_comment(tctx, "\n");
printf("\t%s\n", resultarray[j]); torture_comment(tctx, "Should match:\n\t%s\n", resultarray[j]);
if (strcmp(resultarray[j], tmp) != 0) { if (strcmp(resultarray[j], tmp) != 0) {
ret = False; ret = False;
} }
@ -117,10 +100,11 @@ BOOL torture_local_crypto_sha1(struct torture_context *torture)
/* Test some error returns */ /* Test some error returns */
err = SHA1Update(&sha,(const unsigned char *) testarray[1], 1); err = SHA1Update(&sha,(const unsigned char *) testarray[1], 1);
if (err != shaStateError) ret = False; torture_assert_int_equal(tctx, err, shaStateError, "SHA1Update failed");
printf ("\nError %d. Should be %d.\n", err, shaStateError );
err = SHA1Init(0); err = SHA1Init(0);
if (err != shaNull) ret = False; torture_assert_int_equal(tctx, err, shaNull, "SHA1Init failed");
printf ("\nError %d. Should be %d.\n", err, shaNull );
return ret; return true;
} }

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ static NTSTATUS echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *
static NTSTATUS echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r) static NTSTATUS echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r)
{ {
*r->out.s2 = talloc_strdup(mem_ctx, "this is a test string"); *r->out.s2 = talloc_strdup(mem_ctx, r->in.s1);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -22,8 +22,7 @@ testit "nmblookup -U $SERVER $SERVER" bin/nmblookup $TORTURE_OPTIONS -U $SERVER
testit "nmblookup $SERVER" bin/nmblookup $TORTURE_OPTIONS $SERVER || failed=`expr $failed + 1` testit "nmblookup $SERVER" bin/nmblookup $TORTURE_OPTIONS $SERVER || failed=`expr $failed + 1`
NBT_TESTS="NBT-REGISTER NBT-WINS" NBT_TESTS="NBT-REGISTER NBT-WINS"
NBT_TESTS="$NBT_TESTS NBT-WINSREPLICATION-SIMPLE" NBT_TESTS="$NBT_TESTS NBT-WINSREPLICATION"
NBT_TESTS="$NBT_TESTS NBT-WINSREPLICATION-REPLICA"
# if [ "$TORTURE_QUICK"x != "yes"x ]; then # if [ "$TORTURE_QUICK"x != "yes"x ]; then
# NBT_TESTS="$NBT_TESTS NBT-WINSREPLICATION-OWNED" # NBT_TESTS="$NBT_TESTS NBT-WINSREPLICATION-OWNED"
# fi # fi

View File

@ -27,8 +27,8 @@ incdir=`dirname $0`
# #
base="BASE-ATTR BASE-CHARSET BASE-CHKPATH BASE-DEFER_OPEN BASE-DELAYWRITE BASE-DELETE" base="BASE-ATTR BASE-CHARSET BASE-CHKPATH BASE-DEFER_OPEN BASE-DELAYWRITE BASE-DELETE"
base="$base BASE-DENY1 BASE-DENY2 BASE-DENY3 BASE-DENYDOS BASE-DIR1 BASE-DIR2" base="$base BASE-DENY1 BASE-DENY2 BASE-DENY3 BASE-DENYDOS BASE-DIR1 BASE-DIR2"
base="$base BASE-DISCONNECT BASE-FDPASS BASE-LOCK1 BASE-LOCK2 BASE-LOCK3 BASE-LOCK4" base="$base BASE-DISCONNECT BASE-FDPASS BASE-LOCK "
base="$base BASE-LOCK5 BASE-LOCK6 BASE-LOCK7 BASE-MANGLE BASE-NEGNOWAIT BASE-NTDENY1" base="$base BASE-MANGLE BASE-NEGNOWAIT BASE-NTDENY1"
base="$base BASE-NTDENY2 BASE-OPEN BASE-OPENATTR BASE-PROPERTIES BASE-RENAME BASE-RW1" base="$base BASE-NTDENY2 BASE-OPEN BASE-OPENATTR BASE-PROPERTIES BASE-RENAME BASE-RW1"
base="$base BASE-SECLEAK BASE-TCON BASE-TCONDEV BASE-TRANS2 BASE-UNLINK BASE-VUID" base="$base BASE-SECLEAK BASE-TCON BASE-TCONDEV BASE-TRANS2 BASE-UNLINK BASE-VUID"
base="$base BASE-XCOPY" base="$base BASE-XCOPY"

View File

@ -19,8 +19,8 @@ ADDARGS="$*"
incdir=`dirname $0` incdir=`dirname $0`
. $incdir/test_functions.sh . $incdir/test_functions.sh
tests="BASE-FDPASS BASE-LOCK1 BASE-LOCK2 BASE-LOCK3 BASE-LOCK4" tests="BASE-FDPASS BASE-LOCK "
tests="$tests BASE-LOCK5 BASE-LOCK6 BASE-LOCK7 BASE-UNLINK BASE-ATTR" tests="$tests BASE-UNLINK BASE-ATTR"
tests="$tests BASE-DIR1 BASE-DIR2 BASE-VUID" tests="$tests BASE-DIR1 BASE-DIR2 BASE-VUID"
tests="$tests BASE-TCON BASE-TCONDEV BASE-RW1" tests="$tests BASE-TCON BASE-TCONDEV BASE-RW1"
tests="$tests BASE-DENY3 BASE-XCOPY BASE-OPEN BASE-DENYDOS" tests="$tests BASE-DENY3 BASE-XCOPY BASE-OPEN BASE-DENYDOS"

View File

@ -68,7 +68,7 @@ int main(int argc, const char **argv)
if (ejsOpen(NULL, NULL, NULL) != 0) { if (ejsOpen(NULL, NULL, NULL) != 0) {
fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " fprintf(stderr, "smbscript: ejsOpen(): unable to initialise "
"EJ subsystem\n"); "EJS subsystem\n");
exit(127); exit(127);
} }

View File

@ -24,16 +24,16 @@
#include "lib/cmdline/popt_common.h" #include "lib/cmdline/popt_common.h"
#include "torture/torture.h" #include "torture/torture.h"
static BOOL torture_ntlmssp_self_check(struct torture_context *test, static bool torture_ntlmssp_self_check(struct torture_context *tctx)
const void *_data)
{ {
struct gensec_security *gensec_security; struct gensec_security *gensec_security;
struct gensec_ntlmssp_state *gensec_ntlmssp_state; struct gensec_ntlmssp_state *gensec_ntlmssp_state;
DATA_BLOB data; DATA_BLOB data;
DATA_BLOB sig, expected_sig; DATA_BLOB sig, expected_sig;
TALLOC_CTX *mem_ctx = tctx;
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
gensec_client_start(test, &gensec_security, NULL), gensec_client_start(mem_ctx, &gensec_security, NULL),
"gensec client start"); "gensec client start");
gensec_set_credentials(gensec_security, cmdline_credentials); gensec_set_credentials(gensec_security, cmdline_credentials);
@ -41,7 +41,7 @@ static BOOL torture_ntlmssp_self_check(struct torture_context *test,
gensec_want_feature(gensec_security, GENSEC_FEATURE_SIGN); gensec_want_feature(gensec_security, GENSEC_FEATURE_SIGN);
gensec_want_feature(gensec_security, GENSEC_FEATURE_SEAL); gensec_want_feature(gensec_security, GENSEC_FEATURE_SEAL);
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
gensec_start_mech_by_oid(gensec_security, GENSEC_OID_NTLMSSP), gensec_start_mech_by_oid(gensec_security, GENSEC_OID_NTLMSSP),
"Failed to start GENSEC for NTLMSSP"); "Failed to start GENSEC for NTLMSSP");
@ -54,7 +54,7 @@ static BOOL torture_ntlmssp_self_check(struct torture_context *test,
gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2; gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2;
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
ntlmssp_sign_init(gensec_ntlmssp_state), ntlmssp_sign_init(gensec_ntlmssp_state),
"Failed to sign_init"); "Failed to sign_init");
@ -67,19 +67,15 @@ static BOOL torture_ntlmssp_self_check(struct torture_context *test,
dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length); dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length);
dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length); dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
if (sig.length != expected_sig.length) { torture_assert_int_equal(tctx, sig.length, expected_sig.length, "Wrong sig length");
torture_fail(test, "Wrong sig length: %d != %d",
(int)sig.length, (int)expected_sig.length);
return False;
}
torture_assert(test, 0 == memcmp(sig.data, expected_sig.data, sig.length), torture_assert(tctx, 0 == memcmp(sig.data, expected_sig.data, sig.length),
"data mismatch"); "data mismatch");
talloc_free(gensec_security); talloc_free(gensec_security);
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
gensec_client_start(test, &gensec_security, NULL), gensec_client_start(mem_ctx, &gensec_security, NULL),
"Failed to start GENSEC for NTLMSSP"); "Failed to start GENSEC for NTLMSSP");
gensec_set_credentials(gensec_security, cmdline_credentials); gensec_set_credentials(gensec_security, cmdline_credentials);
@ -87,7 +83,7 @@ static BOOL torture_ntlmssp_self_check(struct torture_context *test,
gensec_want_feature(gensec_security, GENSEC_FEATURE_SIGN); gensec_want_feature(gensec_security, GENSEC_FEATURE_SIGN);
gensec_want_feature(gensec_security, GENSEC_FEATURE_SEAL); gensec_want_feature(gensec_security, GENSEC_FEATURE_SEAL);
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
gensec_start_mech_by_oid(gensec_security, GENSEC_OID_NTLMSSP), gensec_start_mech_by_oid(gensec_security, GENSEC_OID_NTLMSSP),
"GENSEC start mech by oid"); "GENSEC start mech by oid");
@ -100,7 +96,7 @@ static BOOL torture_ntlmssp_self_check(struct torture_context *test,
gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH; gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH;
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
ntlmssp_sign_init(gensec_ntlmssp_state), ntlmssp_sign_init(gensec_ntlmssp_state),
"Failed to sign_init"); "Failed to sign_init");
@ -113,28 +109,22 @@ static BOOL torture_ntlmssp_self_check(struct torture_context *test,
dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length); dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length);
dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length); dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
if (sig.length != expected_sig.length) { torture_assert_int_equal(tctx, sig.length, expected_sig.length, "Wrong sig length");
torture_fail(test, "Wrong sig length: %d != %d",
(int)sig.length, (int)expected_sig.length);
return False;
}
torture_assert(test, torture_assert(tctx, 0 == memcmp(sig.data+8, expected_sig.data+8, sig.length-8),
0 == memcmp(sig.data+8, expected_sig.data+8, sig.length-8),
"data mismatch"); "data mismatch");
talloc_free(gensec_security); talloc_free(gensec_security);
return true;
return True;
} }
struct torture_suite *torture_ntlmssp(TALLOC_CTX *mem_ctx) struct torture_suite *torture_ntlmssp(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, struct torture_suite *suite = torture_suite_create(mem_ctx,
"LOCAL-NTLMSSP"); "NTLMSSP");
torture_suite_add_simple_tcase(suite, "NTLMSSP self check", torture_suite_add_simple_test(suite, "NTLMSSP self check",
torture_ntlmssp_self_check, NULL); torture_ntlmssp_self_check);
return suite; return suite;
} }

View File

@ -30,8 +30,7 @@
#include "libcli/security/security.h" #include "libcli/security/security.h"
#include "torture/torture.h" #include "torture/torture.h"
static BOOL torture_pac_self_check(struct torture_context *test, static bool torture_pac_self_check(struct torture_context *tctx)
const void *_data)
{ {
NTSTATUS nt_status; NTSTATUS nt_status;
DATA_BLOB tmp_blob; DATA_BLOB tmp_blob;
@ -55,7 +54,9 @@ static BOOL torture_pac_self_check(struct torture_context *test,
krb5_principal client_principal; krb5_principal client_principal;
time_t logon_time = time(NULL); time_t logon_time = time(NULL);
torture_assert(test, 0 == smb_krb5_init_context(test, &smb_krb5_context), TALLOC_CTX *mem_ctx = tctx;
torture_assert(tctx, 0 == smb_krb5_init_context(mem_ctx, &smb_krb5_context),
"smb_krb5_init_context"); "smb_krb5_init_context");
generate_random_buffer(server_bytes, 16); generate_random_buffer(server_bytes, 16);
@ -65,52 +66,49 @@ static BOOL torture_pac_self_check(struct torture_context *test,
ENCTYPE_ARCFOUR_HMAC, ENCTYPE_ARCFOUR_HMAC,
server_bytes, sizeof(server_bytes), server_bytes, sizeof(server_bytes),
&server_keyblock); &server_keyblock);
if (ret) { torture_assert(tctx, !ret, talloc_asprintf(tctx,
torture_fail(test, "(self test) Server Keyblock encoding failed: %s", "(self test) Server Keyblock encoding failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context, smb_get_krb5_error_message(smb_krb5_context->krb5_context,
ret, test)); ret, mem_ctx)));
return False;
}
ret = krb5_keyblock_init(smb_krb5_context->krb5_context, ret = krb5_keyblock_init(smb_krb5_context->krb5_context,
ENCTYPE_ARCFOUR_HMAC, ENCTYPE_ARCFOUR_HMAC,
krbtgt_bytes, sizeof(krbtgt_bytes), krbtgt_bytes, sizeof(krbtgt_bytes),
&krbtgt_keyblock); &krbtgt_keyblock);
if (ret) { if (ret) {
torture_fail(test, "(self test) KRBTGT Keyblock encoding failed: %s", char *err = smb_get_krb5_error_message(smb_krb5_context->krb5_context,
smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, mem_ctx);
ret, test));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return False;
torture_fail(tctx, talloc_asprintf(tctx,
"(self test) KRBTGT Keyblock encoding failed: %s", err));
} }
/* We need an input, and this one requires no underlying database */ /* We need an input, and this one requires no underlying database */
nt_status = auth_anonymous_server_info(test, &server_info); nt_status = auth_anonymous_server_info(mem_ctx, &server_info);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
return False; torture_fail(tctx, "auth_anonymous_server_info");
} }
ret = krb5_parse_name_norealm(smb_krb5_context->krb5_context, ret = krb5_parse_name_norealm(smb_krb5_context->krb5_context,
server_info->account_name, &client_principal); server_info->account_name, &client_principal);
if (ret) { if (ret) {
torture_fail(test, "krb5_parse_name_norealm");
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
return False; torture_fail(tctx, "krb5_parse_name_norealm");
} }
/* OK, go ahead and make a PAC */ /* OK, go ahead and make a PAC */
ret = kerberos_create_pac(test, server_info, ret = kerberos_create_pac(mem_ctx, server_info,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
&server_keyblock, &server_keyblock,
@ -119,23 +117,23 @@ static BOOL torture_pac_self_check(struct torture_context *test,
&tmp_blob); &tmp_blob);
if (ret) { if (ret) {
torture_fail(test, "(self test) PAC encoding failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context,
ret, test));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, krb5_free_principal(smb_krb5_context->krb5_context,
client_principal); client_principal);
return False;
torture_fail(tctx, talloc_asprintf(tctx,
"(self test) PAC encoding failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context,
ret, mem_ctx)));
} }
dump_data(10,tmp_blob.data,tmp_blob.length); dump_data(10,tmp_blob.data,tmp_blob.length);
/* Now check that we can read it back */ /* Now check that we can read it back */
nt_status = kerberos_decode_pac(test, &pac_data, nt_status = kerberos_decode_pac(mem_ctx, &pac_data,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -144,9 +142,6 @@ static BOOL torture_pac_self_check(struct torture_context *test,
logon_time, NULL); logon_time, NULL);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
torture_fail(test, "(self test) PAC decoding failed: %s",
nt_errstr(nt_status));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
@ -154,11 +149,13 @@ static BOOL torture_pac_self_check(struct torture_context *test,
krb5_free_principal(smb_krb5_context->krb5_context, krb5_free_principal(smb_krb5_context->krb5_context,
client_principal); client_principal);
return False; torture_fail(tctx, talloc_asprintf(tctx,
"(self test) PAC decoding failed: %s",
nt_errstr(nt_status)));
} }
/* Now check that we can read it back */ /* Now check that we can read it back */
nt_status = kerberos_pac_logon_info(test, &logon_info, nt_status = kerberos_pac_logon_info(mem_ctx, &logon_info,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -168,10 +165,6 @@ static BOOL torture_pac_self_check(struct torture_context *test,
NULL); NULL);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
torture_fail(test,
"(self test) PAC decoding (for logon info) failed: %s",
nt_errstr(nt_status));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
@ -179,7 +172,10 @@ static BOOL torture_pac_self_check(struct torture_context *test,
krb5_free_principal(smb_krb5_context->krb5_context, krb5_free_principal(smb_krb5_context->krb5_context,
client_principal); client_principal);
return False; torture_fail(tctx,
talloc_asprintf(tctx,
"(self test) PAC decoding (for logon info) failed: %s",
nt_errstr(nt_status)));
} }
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
@ -190,28 +186,26 @@ static BOOL torture_pac_self_check(struct torture_context *test,
client_principal); client_principal);
validation.sam3 = &logon_info->info3; validation.sam3 = &logon_info->info3;
nt_status = make_server_info_netlogon_validation(test, nt_status = make_server_info_netlogon_validation(mem_ctx,
"", "",
3, &validation, 3, &validation,
&server_info_out); &server_info_out);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
torture_fail(test, torture_fail(tctx,
talloc_asprintf(tctx,
"(self test) PAC decoding (make server info) failed: %s", "(self test) PAC decoding (make server info) failed: %s",
nt_errstr(nt_status)); nt_errstr(nt_status)));
return False;
} }
if (!dom_sid_equal(server_info->account_sid, if (!dom_sid_equal(server_info->account_sid,
server_info_out->account_sid)) { server_info_out->account_sid)) {
torture_fail(test, torture_fail(tctx,
talloc_asprintf(tctx,
"(self test) PAC Decode resulted in *different* domain SID: %s != %s", "(self test) PAC Decode resulted in *different* domain SID: %s != %s",
dom_sid_string(test, server_info->account_sid), dom_sid_string(mem_ctx, server_info->account_sid),
dom_sid_string(test, server_info_out->account_sid)); dom_sid_string(mem_ctx, server_info_out->account_sid)));
return False;
} }
return true;
return True;
} }
@ -262,8 +256,7 @@ static const uint8_t saved_pac[] = {
}; };
/* Check with a known 'well formed' PAC, from my test server */ /* Check with a known 'well formed' PAC, from my test server */
static BOOL torture_pac_saved_check(struct torture_context *test, static bool torture_pac_saved_check(struct torture_context *tctx)
const void *_data)
{ {
NTSTATUS nt_status; NTSTATUS nt_status;
DATA_BLOB tmp_blob, validate_blob; DATA_BLOB tmp_blob, validate_blob;
@ -284,125 +277,108 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
krb5_principal client_principal; krb5_principal client_principal;
const char *authtime_string; const char *authtime_string;
time_t authtime; time_t authtime;
TALLOC_CTX *mem_ctx = tctx;
torture_assert(test, 0 == smb_krb5_init_context(test, &smb_krb5_context), torture_assert(tctx, 0 == smb_krb5_init_context(mem_ctx, &smb_krb5_context),
"smb_krb5_init_context"); "smb_krb5_init_context");
pac_kdc_key = lp_parm_string(-1,"torture","pac_kdc_key"); pac_kdc_key = torture_setting_string(tctx, "pac_kdc_key",
if (pac_kdc_key == NULL) { "B286757148AF7FD252C53603A150B7E7");
pac_kdc_key = "B286757148AF7FD252C53603A150B7E7";
}
pac_member_key = lp_parm_string(-1,"torture","pac_member_key"); pac_member_key = torture_setting_string(tctx, "pac_member_key",
if (pac_member_key == NULL) { "D217FAEAE5E6B5F95CCC94077AB8A5FC");
pac_member_key = "D217FAEAE5E6B5F95CCC94077AB8A5FC";
}
torture_comment(test, "Using pac_kdc_key '%s'", pac_kdc_key); torture_comment(tctx, "Using pac_kdc_key '%s'\n", pac_kdc_key);
torture_comment(test, "Using pac_member_key '%s'", pac_member_key); torture_comment(tctx, "Using pac_member_key '%s'\n", pac_member_key);
/* The krbtgt key in use when the above PAC was generated. /* The krbtgt key in use when the above PAC was generated.
* This is an arcfour-hmac-md5 key, extracted with our 'net * This is an arcfour-hmac-md5 key, extracted with our 'net
* samdump' tool. */ * samdump' tool. */
krbtgt_bytes = smbpasswd_gethexpwd(test, pac_kdc_key); krbtgt_bytes = smbpasswd_gethexpwd(mem_ctx, pac_kdc_key);
if (!krbtgt_bytes) { if (!krbtgt_bytes) {
torture_fail(test, "(saved test) Could not interpret krbtgt key"); torture_fail(tctx, "(saved test) Could not interpret krbtgt key");
return False;
} }
krbsrv_bytes = smbpasswd_gethexpwd(test, pac_member_key); krbsrv_bytes = smbpasswd_gethexpwd(mem_ctx, pac_member_key);
if (!krbsrv_bytes) { if (!krbsrv_bytes) {
torture_fail(test, "(saved test) Could not interpret krbsrv key"); torture_fail(tctx, "(saved test) Could not interpret krbsrv key");
return False;
} }
ret = krb5_keyblock_init(smb_krb5_context->krb5_context, ret = krb5_keyblock_init(smb_krb5_context->krb5_context,
ENCTYPE_ARCFOUR_HMAC, ENCTYPE_ARCFOUR_HMAC,
krbsrv_bytes->hash, sizeof(krbsrv_bytes->hash), krbsrv_bytes->hash, sizeof(krbsrv_bytes->hash),
&server_keyblock); &server_keyblock);
if (ret) { torture_assert(tctx, !ret,
torture_fail(test, talloc_asprintf(tctx,
"(saved test) Server Keyblock encoding failed: %s", "(saved test) Server Keyblock encoding failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context, smb_get_krb5_error_message(smb_krb5_context->krb5_context,
ret, test)); ret, mem_ctx)));
return False;
}
ret = krb5_keyblock_init(smb_krb5_context->krb5_context, ret = krb5_keyblock_init(smb_krb5_context->krb5_context,
ENCTYPE_ARCFOUR_HMAC, ENCTYPE_ARCFOUR_HMAC,
krbtgt_bytes->hash, sizeof(krbtgt_bytes->hash), krbtgt_bytes->hash, sizeof(krbtgt_bytes->hash),
&krbtgt_keyblock); &krbtgt_keyblock);
if (ret) { if (ret) {
torture_fail(test,
"(saved test) Server Keyblock encoding failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context,
ret, test));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return False; torture_fail(tctx,
talloc_asprintf(tctx,
"(saved test) Server Keyblock encoding failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context,
ret, mem_ctx)));
} }
pac_file = lp_parm_string(-1,"torture","pac_file"); pac_file = torture_setting_string(tctx, "pac_file", NULL);
if (pac_file) { if (pac_file) {
tmp_blob.data = (uint8_t *)file_load(pac_file, &tmp_blob.length, test); tmp_blob.data = (uint8_t *)file_load(pac_file, &tmp_blob.length, mem_ctx);
torture_comment(test, "(saved test) Loaded pac of size %ld from %s", (long)tmp_blob.length, pac_file); torture_comment(tctx, "(saved test) Loaded pac of size %ld from %s\n", (long)tmp_blob.length, pac_file);
} else { } else {
tmp_blob = data_blob_talloc(test, saved_pac, sizeof(saved_pac)); tmp_blob = data_blob_talloc(mem_ctx, saved_pac, sizeof(saved_pac));
} }
dump_data(10,tmp_blob.data,tmp_blob.length); dump_data(10,tmp_blob.data,tmp_blob.length);
principal_string = lp_parm_string(-1,"torture","pac_client_principal"); principal_string = torture_setting_string(tctx, "pac_client_principal",
if (!principal_string) { "w2003final$@WIN2K3.THINKER.LOCAL");
principal_string = "w2003final$@WIN2K3.THINKER.LOCAL";
}
authtime_string = lp_parm_string(-1,"torture","pac_authtime"); authtime_string = torture_setting_string(tctx, "pac_authtime", "1120440609");
if (!authtime_string) { authtime = strtoull(authtime_string, NULL, 0);
authtime = 1120440609;
} else {
authtime = strtoull(authtime_string, NULL, 0);
}
ret = krb5_parse_name(smb_krb5_context->krb5_context, principal_string, ret = krb5_parse_name(smb_krb5_context->krb5_context, principal_string,
&client_principal); &client_principal);
if (ret) { if (ret) {
torture_fail(test,
"(saved test) parsing of client principal [%s] failed: %s",
principal_string,
smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, test));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return False; torture_fail(tctx,
talloc_asprintf(tctx,
"(saved test) parsing of client principal [%s] failed: %s",
principal_string,
smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, mem_ctx)));
} }
/* Decode and verify the signaure on the PAC */ /* Decode and verify the signaure on the PAC */
nt_status = kerberos_decode_pac(test, &pac_data, nt_status = kerberos_decode_pac(mem_ctx, &pac_data,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
&server_keyblock, &server_keyblock,
client_principal, authtime, NULL); client_principal, authtime, NULL);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
torture_fail(test, "(saved test) PAC decoding failed: %s",
nt_errstr(nt_status));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
return False; torture_fail(tctx, talloc_asprintf(tctx,
"(saved test) PAC decoding failed: %s",
nt_errstr(nt_status)));
} }
/* Parse the PAC again, for the logon info this time */ /* Parse the PAC again, for the logon info this time */
nt_status = kerberos_pac_logon_info(test, &logon_info, nt_status = kerberos_pac_logon_info(mem_ctx, &logon_info,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -416,15 +392,14 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, torture_fail(tctx,
talloc_asprintf(tctx,
"(saved test) PAC decoding (for logon info) failed: %s", "(saved test) PAC decoding (for logon info) failed: %s",
nt_errstr(nt_status)); nt_errstr(nt_status)));
return False;
} }
validation.sam3 = &logon_info->info3; validation.sam3 = &logon_info->info3;
nt_status = make_server_info_netlogon_validation(test, nt_status = make_server_info_netlogon_validation(mem_ctx,
"", "",
3, &validation, 3, &validation,
&server_info_out); &server_info_out);
@ -435,15 +410,14 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, torture_fail(tctx,
talloc_asprintf(tctx,
"(saved test) PAC decoding (make server info) failed: %s", "(saved test) PAC decoding (make server info) failed: %s",
nt_errstr(nt_status)); nt_errstr(nt_status)));
return False;
} }
if (!pac_file && if (!pac_file &&
!dom_sid_equal(dom_sid_parse_talloc(test, !dom_sid_equal(dom_sid_parse_talloc(mem_ctx,
"S-1-5-21-3048156945-3961193616-3706469200-1005"), "S-1-5-21-3048156945-3961193616-3706469200-1005"),
server_info_out->account_sid)) { server_info_out->account_sid)) {
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
@ -452,14 +426,14 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, torture_fail(tctx,
talloc_asprintf(tctx,
"(saved test) PAC Decode resulted in *different* domain SID: %s != %s", "(saved test) PAC Decode resulted in *different* domain SID: %s != %s",
"S-1-5-21-3048156945-3961193616-3706469200-1005", "S-1-5-21-3048156945-3961193616-3706469200-1005",
dom_sid_string(test, server_info_out->account_sid)); dom_sid_string(mem_ctx, server_info_out->account_sid)));
return False;
} }
ret = kerberos_encode_pac(test, ret = kerberos_encode_pac(mem_ctx,
pac_data, pac_data,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -473,8 +447,7 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, "(saved test) PAC push failed"); torture_fail(tctx, "(saved test) PAC push failed");
return False;
} }
dump_data(10, validate_blob.data, validate_blob.length); dump_data(10, validate_blob.data, validate_blob.length);
@ -490,10 +463,10 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, torture_fail(tctx,
talloc_asprintf(tctx,
"(saved test) PAC push failed: original buffer length[%u] != created buffer length[%u]", "(saved test) PAC push failed: original buffer length[%u] != created buffer length[%u]",
(unsigned)tmp_blob.length, (unsigned)validate_blob.length); (unsigned)tmp_blob.length, (unsigned)validate_blob.length));
return False;
} }
if (memcmp(tmp_blob.data, validate_blob.data, tmp_blob.length) != 0) { if (memcmp(tmp_blob.data, validate_blob.data, tmp_blob.length) != 0) {
@ -503,16 +476,15 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, "(saved test) PAC push failed: length[%u] matches, but data does not", (unsigned)tmp_blob.length);
DEBUG(0, ("tmp_data:\n")); DEBUG(0, ("tmp_data:\n"));
dump_data(0, tmp_blob.data, tmp_blob.length); dump_data(0, tmp_blob.data, tmp_blob.length);
DEBUG(0, ("validate_blob:\n")); DEBUG(0, ("validate_blob:\n"));
dump_data(0, validate_blob.data, validate_blob.length); dump_data(0, validate_blob.data, validate_blob.length);
return False; torture_fail(tctx, talloc_asprintf(tctx, "(saved test) PAC push failed: length[%u] matches, but data does not", (unsigned)tmp_blob.length));
} }
ret = kerberos_create_pac(test, ret = kerberos_create_pac(mem_ctx,
server_info_out, server_info_out,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -527,8 +499,7 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, "(saved test) regnerated PAC create failed"); torture_fail(tctx, "(saved test) regnerated PAC create failed");
return False;
} }
dump_data(10,validate_blob.data,validate_blob.length); dump_data(10,validate_blob.data,validate_blob.length);
@ -538,9 +509,9 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
* pointer, padding etc algorithms as win2k3. * pointer, padding etc algorithms as win2k3.
*/ */
if (tmp_blob.length != validate_blob.length) { if (tmp_blob.length != validate_blob.length) {
nt_status = ndr_pull_struct_blob(&validate_blob, test, &pac_data2, nt_status = ndr_pull_struct_blob(&validate_blob, mem_ctx, &pac_data2,
(ndr_pull_flags_fn_t)ndr_pull_PAC_DATA); (ndr_pull_flags_fn_t)ndr_pull_PAC_DATA);
torture_assert_ntstatus_ok(test, nt_status, "can't parse the PAC"); torture_assert_ntstatus_ok(tctx, nt_status, "can't parse the PAC");
NDR_PRINT_DEBUG(PAC_DATA, pac_data); NDR_PRINT_DEBUG(PAC_DATA, pac_data);
@ -552,15 +523,15 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, "(saved test) PAC regenerate failed: original buffer length[%u] != created buffer length[%u]", torture_fail(tctx, talloc_asprintf(tctx,
(unsigned)tmp_blob.length, (unsigned)validate_blob.length); "(saved test) PAC regenerate failed: original buffer length[%u] != created buffer length[%u]",
return False; (unsigned)tmp_blob.length, (unsigned)validate_blob.length));
} }
if (memcmp(tmp_blob.data, validate_blob.data, tmp_blob.length) != 0) { if (memcmp(tmp_blob.data, validate_blob.data, tmp_blob.length) != 0) {
nt_status = ndr_pull_struct_blob(&validate_blob, test, &pac_data2, nt_status = ndr_pull_struct_blob(&validate_blob, mem_ctx, &pac_data2,
(ndr_pull_flags_fn_t)ndr_pull_PAC_DATA); (ndr_pull_flags_fn_t)ndr_pull_PAC_DATA);
torture_assert_ntstatus_ok(test, nt_status, "can't parse the PAC"); torture_assert_ntstatus_ok(tctx, nt_status, "can't parse the PAC");
NDR_PRINT_DEBUG(PAC_DATA, pac_data); NDR_PRINT_DEBUG(PAC_DATA, pac_data);
@ -572,17 +543,17 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
torture_fail(test, "(saved test) PAC regenerate failed: length[%u] matches, but data does not", (unsigned)tmp_blob.length);
DEBUG(0, ("tmp_data:\n")); DEBUG(0, ("tmp_data:\n"));
dump_data(0, tmp_blob.data, tmp_blob.length); dump_data(0, tmp_blob.data, tmp_blob.length);
DEBUG(0, ("validate_blob:\n")); DEBUG(0, ("validate_blob:\n"));
dump_data(0, validate_blob.data, validate_blob.length); dump_data(0, validate_blob.data, validate_blob.length);
return False; torture_fail(tctx, talloc_asprintf(tctx,
"(saved test) PAC regenerate failed: length[%u] matches, but data does not", (unsigned)tmp_blob.length));
} }
/* Break the auth time, to ensure we check this vital detail (not setting this caused all the pain in the first place... */ /* Break the auth time, to ensure we check this vital detail (not setting this caused all the pain in the first place... */
nt_status = kerberos_decode_pac(test, &pac_data, nt_status = kerberos_decode_pac(mem_ctx, &pac_data,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -590,14 +561,13 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
client_principal, client_principal,
authtime + 1, NULL); authtime + 1, NULL);
if (NT_STATUS_IS_OK(nt_status)) { if (NT_STATUS_IS_OK(nt_status)) {
torture_fail(test, "(saved test) PAC decoding DID NOT fail on broken auth time (time + 1)");
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
krb5_free_principal(smb_krb5_context->krb5_context, client_principal); krb5_free_principal(smb_krb5_context->krb5_context, client_principal);
return False; torture_fail(tctx, "(saved test) PAC decoding DID NOT fail on broken auth time (time + 1)");
} }
/* Break the client principal */ /* Break the client principal */
@ -606,17 +576,17 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
ret = krb5_parse_name(smb_krb5_context->krb5_context, ret = krb5_parse_name(smb_krb5_context->krb5_context,
"not the right principal", &client_principal); "not the right principal", &client_principal);
if (ret) { if (ret) {
torture_fail(test, "(saved test) parsing of bogus client principal failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, test));
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return False; torture_fail(tctx, talloc_asprintf(tctx,
"(saved test) parsing of bogus client principal failed: %s",
smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, mem_ctx)));
} }
nt_status = kerberos_decode_pac(test, &pac_data, nt_status = kerberos_decode_pac(mem_ctx, &pac_data,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -624,19 +594,17 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
client_principal, client_principal,
authtime, NULL); authtime, NULL);
if (NT_STATUS_IS_OK(nt_status)) { if (NT_STATUS_IS_OK(nt_status)) {
torture_fail(test, "(saved test) PAC decoding DID NOT fail on modified principal");
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return False; torture_fail(tctx, "(saved test) PAC decoding DID NOT fail on modified principal");
} }
/* Finally... Bugger up the signature, and check we fail the checksum */ /* Finally... Bugger up the signature, and check we fail the checksum */
tmp_blob.data[tmp_blob.length - 2]++; tmp_blob.data[tmp_blob.length - 2]++;
nt_status = kerberos_decode_pac(test, &pac_data, nt_status = kerberos_decode_pac(mem_ctx, &pac_data,
tmp_blob, tmp_blob,
smb_krb5_context->krb5_context, smb_krb5_context->krb5_context,
&krbtgt_keyblock, &krbtgt_keyblock,
@ -644,32 +612,29 @@ static BOOL torture_pac_saved_check(struct torture_context *test,
client_principal, client_principal,
authtime, NULL); authtime, NULL);
if (NT_STATUS_IS_OK(nt_status)) { if (NT_STATUS_IS_OK(nt_status)) {
torture_fail(test, "(saved test) PAC decoding DID NOT fail on broken checksum");
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return False; torture_fail(tctx, "(saved test) PAC decoding DID NOT fail on broken checksum");
} }
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&krbtgt_keyblock); &krbtgt_keyblock);
krb5_free_keyblock_contents(smb_krb5_context->krb5_context, krb5_free_keyblock_contents(smb_krb5_context->krb5_context,
&server_keyblock); &server_keyblock);
return true;
return True;
} }
struct torture_suite *torture_pac(TALLOC_CTX *mem_ctx) struct torture_suite *torture_pac(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-PAC"); struct torture_suite *suite = torture_suite_create(mem_ctx, "PAC");
torture_suite_add_simple_tcase(suite, "self check", torture_suite_add_simple_test(suite, "self check",
torture_pac_self_check, NULL); torture_pac_self_check);
torture_suite_add_simple_tcase(suite, "saved check", torture_suite_add_simple_test(suite, "saved check",
torture_pac_saved_check, NULL); torture_pac_saved_check);
return suite; return suite;
} }

View File

@ -34,62 +34,62 @@ struct trans2_blobs {
}; };
/* look for aliases for a query */ /* look for aliases for a query */
static void gen_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int level_offset) static bool gen_aliases(struct torture_context *tctx,
struct smbcli_state *cli, struct smb_trans2 *t2,
int level_offset)
{ {
TALLOC_CTX *mem_ctx;
uint16_t level; uint16_t level;
struct trans2_blobs *alias_blobs = NULL; struct trans2_blobs *alias_blobs = NULL;
struct trans2_blobs *t2b, *t2b2; struct trans2_blobs *t2b, *t2b2;
int count=0, alias_count=0; int count=0, alias_count=0;
mem_ctx = talloc_init("aliases");
for (level=0;level<2000;level++) { for (level=0;level<2000;level++) {
NTSTATUS status; NTSTATUS status;
SSVAL(t2->in.params.data, level_offset, level); SSVAL(t2->in.params.data, level_offset, level);
status = smb_raw_trans2(cli->tree, mem_ctx, t2); status = smb_raw_trans2(cli->tree, tctx, t2);
if (!NT_STATUS_IS_OK(status)) continue; if (!NT_STATUS_IS_OK(status)) continue;
t2b = talloc(mem_ctx, struct trans2_blobs); t2b = talloc(tctx, struct trans2_blobs);
t2b->level = level; t2b->level = level;
t2b->params = t2->out.params; t2b->params = t2->out.params;
t2b->data = t2->out.data; t2b->data = t2->out.data;
DLIST_ADD(alias_blobs, t2b); DLIST_ADD(alias_blobs, t2b);
d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", torture_comment(tctx,
"\tFound level %4u (0x%03x) of size %3d (0x%02x)\n",
level, level, level, level,
(int)t2b->data.length, (int)t2b->data.length); (int)t2b->data.length, (int)t2b->data.length);
count++; count++;
} }
d_printf("Found %d levels with success status\n", count); torture_comment(tctx, "Found %d levels with success status\n", count);
for (t2b=alias_blobs; t2b; t2b=t2b->next) { for (t2b=alias_blobs; t2b; t2b=t2b->next) {
for (t2b2=alias_blobs; t2b2; t2b2=t2b2->next) { for (t2b2=alias_blobs; t2b2; t2b2=t2b2->next) {
if (t2b->level >= t2b2->level) continue; if (t2b->level >= t2b2->level) continue;
if (data_blob_equal(&t2b->params, &t2b2->params) && if (data_blob_equal(&t2b->params, &t2b2->params) &&
data_blob_equal(&t2b->data, &t2b2->data)) { data_blob_equal(&t2b->data, &t2b2->data)) {
printf("\tLevel %u (0x%x) and level %u (0x%x) are possible aliases\n", torture_comment(tctx,
"\tLevel %u (0x%x) and level %u (0x%x) are possible aliases\n",
t2b->level, t2b->level, t2b2->level, t2b2->level); t2b->level, t2b->level, t2b2->level, t2b2->level);
alias_count++; alias_count++;
} }
} }
} }
d_printf("Found %d aliased levels\n", alias_count); torture_comment(tctx, "Found %d aliased levels\n", alias_count);
talloc_free(mem_ctx); return true;
} }
/* look for qfsinfo aliases */ /* look for qfsinfo aliases */
static void qfsinfo_aliases(struct smbcli_state *cli) static bool qfsinfo_aliases(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smb_trans2 t2; struct smb_trans2 t2;
uint16_t setup = TRANSACT2_QFSINFO; uint16_t setup = TRANSACT2_QFSINFO;
d_printf("\nChecking for QFSINFO aliases\n");
t2.in.max_param = 0; t2.in.max_param = 0;
t2.in.max_data = smb_raw_max_trans_data(cli->tree, 0); t2.in.max_data = smb_raw_max_trans_data(cli->tree, 0);
t2.in.max_setup = 0; t2.in.max_setup = 0;
@ -100,19 +100,18 @@ static void qfsinfo_aliases(struct smbcli_state *cli)
t2.in.params = data_blob(NULL, 2); t2.in.params = data_blob(NULL, 2);
t2.in.data = data_blob(NULL, 0); t2.in.data = data_blob(NULL, 0);
gen_aliases(cli, &t2, 0); return gen_aliases(tctx, cli, &t2, 0);
} }
/* look for qfileinfo aliases */ /* look for qfileinfo aliases */
static void qfileinfo_aliases(struct smbcli_state *cli) static bool qfileinfo_aliases(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smb_trans2 t2; struct smb_trans2 t2;
uint16_t setup = TRANSACT2_QFILEINFO; uint16_t setup = TRANSACT2_QFILEINFO;
const char *fname = "\\qfileinfo_aliases.txt"; const char *fname = "\\qfileinfo_aliases.txt";
int fnum; int fnum;
d_printf("\nChecking for QFILEINFO aliases\n");
t2.in.max_param = 2; t2.in.max_param = 2;
t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2); t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2);
t2.in.max_setup = 0; t2.in.max_setup = 0;
@ -125,33 +124,32 @@ static void qfileinfo_aliases(struct smbcli_state *cli)
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { torture_assert(tctx, fnum != -1, talloc_asprintf(tctx,
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); "open of %s failed (%s)", fname,
} smbcli_errstr(cli->tree)));
smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
SSVAL(t2.in.params.data, 0, fnum); SSVAL(t2.in.params.data, 0, fnum);
gen_aliases(cli, &t2, 2); if (!gen_aliases(tctx, cli, &t2, 2))
return false;
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
return true;
} }
/* look for qpathinfo aliases */ /* look for qpathinfo aliases */
static void qpathinfo_aliases(struct smbcli_state *cli) static bool qpathinfo_aliases(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smb_trans2 t2; struct smb_trans2 t2;
uint16_t setup = TRANSACT2_QPATHINFO; uint16_t setup = TRANSACT2_QPATHINFO;
const char *fname = "\\qpathinfo_aliases.txt"; const char *fname = "\\qpathinfo_aliases.txt";
int fnum; int fnum;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init("qpathinfo");
d_printf("\nChecking for QPATHINFO aliases\n");
t2.in.max_param = 2; t2.in.max_param = 2;
t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2); t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2);
@ -160,42 +158,40 @@ static void qpathinfo_aliases(struct smbcli_state *cli)
t2.in.timeout = 0; t2.in.timeout = 0;
t2.in.setup_count = 1; t2.in.setup_count = 1;
t2.in.setup = &setup; t2.in.setup = &setup;
t2.in.params = data_blob_talloc(mem_ctx, NULL, 6); t2.in.params = data_blob_talloc(tctx, NULL, 6);
t2.in.data = data_blob(NULL, 0); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { torture_assert(tctx, fnum != -1, talloc_asprintf(tctx,
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); "open of %s failed (%s)", fname,
} smbcli_errstr(cli->tree)));
smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
SIVAL(t2.in.params.data, 2, 0); SIVAL(t2.in.params.data, 2, 0);
smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params, smbcli_blob_append_string(cli->session, tctx, &t2.in.params,
fname, STR_TERMINATE); fname, STR_TERMINATE);
gen_aliases(cli, &t2, 0); if (!gen_aliases(tctx, cli, &t2, 0))
return false;
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
talloc_free(mem_ctx);
return true;
} }
/* look for trans2 findfirst aliases */ /* look for trans2 findfirst aliases */
static void findfirst_aliases(struct smbcli_state *cli) static bool findfirst_aliases(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smb_trans2 t2; struct smb_trans2 t2;
uint16_t setup = TRANSACT2_FINDFIRST; uint16_t setup = TRANSACT2_FINDFIRST;
const char *fname = "\\findfirst_aliases.txt"; const char *fname = "\\findfirst_aliases.txt";
int fnum; int fnum;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init("findfirst");
d_printf("\nChecking for FINDFIRST aliases\n");
t2.in.max_param = 16; t2.in.max_param = 16;
t2.in.max_data = smb_raw_max_trans_data(cli->tree, 16); t2.in.max_data = smb_raw_max_trans_data(cli->tree, 16);
@ -204,14 +200,14 @@ static void findfirst_aliases(struct smbcli_state *cli)
t2.in.timeout = 0; t2.in.timeout = 0;
t2.in.setup_count = 1; t2.in.setup_count = 1;
t2.in.setup = &setup; t2.in.setup = &setup;
t2.in.params = data_blob_talloc(mem_ctx, NULL, 12); t2.in.params = data_blob_talloc(tctx, NULL, 12);
t2.in.data = data_blob(NULL, 0); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { torture_assert(tctx, fnum != -1, talloc_asprintf(tctx,
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); "open of %s failed (%s)", fname,
} smbcli_errstr(cli->tree)));
smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
@ -222,28 +218,29 @@ static void findfirst_aliases(struct smbcli_state *cli)
SSVAL(t2.in.params.data, 6, 0); SSVAL(t2.in.params.data, 6, 0);
SIVAL(t2.in.params.data, 8, 0); SIVAL(t2.in.params.data, 8, 0);
smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params, smbcli_blob_append_string(cli->session, tctx, &t2.in.params,
fname, STR_TERMINATE); fname, STR_TERMINATE);
gen_aliases(cli, &t2, 6); if (!gen_aliases(tctx, cli, &t2, 6))
return false;
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
talloc_free(mem_ctx);
return true;
} }
/* look for aliases for a set function */ /* look for aliases for a set function */
static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int level_offset) static bool gen_set_aliases(struct torture_context *tctx,
struct smbcli_state *cli,
struct smb_trans2 *t2, int level_offset)
{ {
TALLOC_CTX *mem_ctx;
uint16_t level; uint16_t level;
struct trans2_blobs *alias_blobs = NULL; struct trans2_blobs *alias_blobs = NULL;
struct trans2_blobs *t2b; struct trans2_blobs *t2b;
int count=0, dsize; int count=0, dsize;
mem_ctx = talloc_init("aliases");
for (level=1;level<1100;level++) { for (level=1;level<1100;level++) {
NTSTATUS status, status1; NTSTATUS status, status1;
SSVAL(t2->in.params.data, level_offset, level); SSVAL(t2->in.params.data, level_offset, level);
@ -254,7 +251,7 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int
data_blob_free(&t2->in.data); data_blob_free(&t2->in.data);
t2->in.data = data_blob(NULL, dsize); t2->in.data = data_blob(NULL, dsize);
data_blob_clear(&t2->in.data); data_blob_clear(&t2->in.data);
status = smb_raw_trans2(cli->tree, mem_ctx, t2); status = smb_raw_trans2(cli->tree, tctx, t2);
/* some error codes mean that this whole level doesn't exist */ /* some error codes mean that this whole level doesn't exist */
if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, status) || if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, status) ||
NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS, status) || NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS, status) ||
@ -274,7 +271,7 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int
} }
if (!NT_STATUS_EQUAL(status, status1)) { if (!NT_STATUS_EQUAL(status, status1)) {
printf("level=%d size=%d %s\n", level, dsize, nt_errstr(status)); torture_comment(tctx, "level=%d size=%d %s\n", level, dsize, nt_errstr(status));
} }
status1 = status; status1 = status;
} }
@ -282,33 +279,34 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int
if (!NT_STATUS_IS_OK(status) && if (!NT_STATUS_IS_OK(status) &&
!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue; !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue;
t2b = talloc(mem_ctx, struct trans2_blobs); t2b = talloc(tctx, struct trans2_blobs);
t2b->level = level; t2b->level = level;
t2b->params = t2->out.params; t2b->params = t2->out.params;
t2b->data = t2->out.data; t2b->data = t2->out.data;
DLIST_ADD(alias_blobs, t2b); DLIST_ADD(alias_blobs, t2b);
d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", torture_comment(tctx,
"\tFound level %4u (0x%03x) of size %3d (0x%02x)\n",
level, level, level, level,
(int)t2->in.data.length, (int)t2->in.data.length); (int)t2->in.data.length, (int)t2->in.data.length);
count++; count++;
} }
d_printf("Found %d valid levels\n", count); torture_comment(tctx, "Found %d valid levels\n", count);
talloc_free(mem_ctx);
return true;
} }
/* look for setfileinfo aliases */ /* look for setfileinfo aliases */
static void setfileinfo_aliases(struct smbcli_state *cli) static bool setfileinfo_aliases(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smb_trans2 t2; struct smb_trans2 t2;
uint16_t setup = TRANSACT2_SETFILEINFO; uint16_t setup = TRANSACT2_SETFILEINFO;
const char *fname = "\\setfileinfo_aliases.txt"; const char *fname = "\\setfileinfo_aliases.txt";
int fnum; int fnum;
d_printf("\nChecking for SETFILEINFO aliases\n");
t2.in.max_param = 2; t2.in.max_param = 2;
t2.in.max_data = 0; t2.in.max_data = 0;
t2.in.max_setup = 0; t2.in.max_setup = 0;
@ -321,33 +319,31 @@ static void setfileinfo_aliases(struct smbcli_state *cli)
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { torture_assert(tctx, fnum != -1, talloc_asprintf(tctx,
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); "open of %s failed (%s)", fname,
} smbcli_errstr(cli->tree)));
smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
SSVAL(t2.in.params.data, 0, fnum); SSVAL(t2.in.params.data, 0, fnum);
SSVAL(t2.in.params.data, 4, 0); SSVAL(t2.in.params.data, 4, 0);
gen_set_aliases(cli, &t2, 2); gen_set_aliases(tctx, cli, &t2, 2);
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
return true;
} }
/* look for setpathinfo aliases */ /* look for setpathinfo aliases */
static void setpathinfo_aliases(struct smbcli_state *cli) static bool setpathinfo_aliases(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smb_trans2 t2; struct smb_trans2 t2;
uint16_t setup = TRANSACT2_SETPATHINFO; uint16_t setup = TRANSACT2_SETPATHINFO;
const char *fname = "\\setpathinfo_aliases.txt"; const char *fname = "\\setpathinfo_aliases.txt";
int fnum; int fnum;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init("findfirst");
d_printf("\nChecking for SETPATHINFO aliases\n");
t2.in.max_param = 32; t2.in.max_param = 32;
t2.in.max_data = smb_raw_max_trans_data(cli->tree, 32); t2.in.max_data = smb_raw_max_trans_data(cli->tree, 32);
@ -356,53 +352,50 @@ static void setpathinfo_aliases(struct smbcli_state *cli)
t2.in.timeout = 0; t2.in.timeout = 0;
t2.in.setup_count = 1; t2.in.setup_count = 1;
t2.in.setup = &setup; t2.in.setup = &setup;
t2.in.params = data_blob_talloc(mem_ctx, NULL, 4); t2.in.params = data_blob_talloc(tctx, NULL, 4);
t2.in.data = data_blob(NULL, 0); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { torture_assert(tctx, fnum != -1, talloc_asprintf(tctx,
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); "open of %s failed (%s)", fname,
} smbcli_errstr(cli->tree)));
smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2));
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
SSVAL(t2.in.params.data, 2, 0); SSVAL(t2.in.params.data, 2, 0);
smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params, smbcli_blob_append_string(cli->session, tctx, &t2.in.params,
fname, STR_TERMINATE); fname, STR_TERMINATE);
gen_set_aliases(cli, &t2, 0); if (!gen_set_aliases(tctx, cli, &t2, 0))
return false;
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { torture_assert_ntstatus_ok(tctx, smbcli_unlink(cli->tree, fname),
printf("unlink: %s\n", smbcli_errstr(cli->tree)); talloc_asprintf(tctx, "unlink: %s", smbcli_errstr(cli->tree)));
}
talloc_free(mem_ctx); return true;
} }
/* look for aliased info levels in trans2 calls */ /* look for aliased info levels in trans2 calls */
BOOL torture_trans2_aliases(struct torture_context *torture) struct torture_suite *torture_trans2_aliases(void)
{ {
struct smbcli_state *cli; struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"ALIASES");
if (!torture_open_connection(&cli, 0)) { torture_suite_add_1smb_test(suite, "QFILEINFO aliases",
return False; qfsinfo_aliases);
} torture_suite_add_1smb_test(suite, "QFSINFO aliases", qfileinfo_aliases);
torture_suite_add_1smb_test(suite, "QPATHINFO aliases", qpathinfo_aliases);
torture_suite_add_1smb_test(suite, "FINDFIRST aliases", findfirst_aliases);
torture_suite_add_1smb_test(suite, "setfileinfo_aliases",
setfileinfo_aliases);
torture_suite_add_1smb_test(suite, "setpathinfo_aliases",
setpathinfo_aliases);
return suite;
qfsinfo_aliases(cli);
qfileinfo_aliases(cli);
qpathinfo_aliases(cli);
findfirst_aliases(cli);
setfileinfo_aliases(cli);
setpathinfo_aliases(cli);
if (!torture_close_connection(cli)) {
return False;
}
return True;
} }

View File

@ -87,22 +87,15 @@ static const struct trunc_open_results attr_results[] = {
}; };
BOOL torture_openattrtest(struct torture_context *torture) BOOL torture_openattrtest(struct torture_context *tctx,
struct smbcli_state *cli1)
{ {
struct smbcli_state *cli1;
const char *fname = "\\openattr.file"; const char *fname = "\\openattr.file";
int fnum1; int fnum1;
BOOL correct = True;
uint16_t attr; uint16_t attr;
uint_t i, j, k, l; uint_t i, j, k, l;
int failures = 0; int failures = 0;
printf("starting open attr test\n");
if (!torture_open_connection(&cli1, 0)) {
return False;
}
for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) { for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
smbcli_setatr(cli1->tree, fname, 0, 0); smbcli_setatr(cli1->tree, fname, 0, 0);
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
@ -111,15 +104,13 @@ BOOL torture_openattrtest(struct torture_context *torture)
open_attrs_table[i], open_attrs_table[i],
NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
if (fnum1 == -1) { torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open %d (1) of %s failed (%s)", i,
printf("open %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree)); fname, smbcli_errstr(cli1->tree)));
return False;
}
if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { torture_assert_ntstatus_ok(tctx,
printf("close %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree)); smbcli_close(cli1->tree, fnum1),
return False; talloc_asprintf(tctx, "close %d (1) of %s failed (%s)", i, fname,
} smbcli_errstr(cli1->tree)));
for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) { for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
@ -132,40 +123,37 @@ BOOL torture_openattrtest(struct torture_context *torture)
if (fnum1 == -1) { if (fnum1 == -1) {
for (l = 0; l < ARRAY_SIZE(attr_results); l++) { for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
if (attr_results[l].num == k) { if (attr_results[l].num == k) {
printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)\n", torture_comment(tctx, "[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)\n",
k, open_attrs_table[i], k, open_attrs_table[i],
open_attrs_table[j], open_attrs_table[j],
fname, smbcli_errstr(cli1->tree)); fname, smbcli_errstr(cli1->tree));
correct = False;
CHECK_MAX_FAILURES(error_exit); CHECK_MAX_FAILURES(error_exit);
} }
} }
if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_ACCESS_DENIED)) { torture_assert_ntstatus_equal(tctx,
printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n", smbcli_nt_error(cli1->tree), NT_STATUS_ACCESS_DENIED,
talloc_asprintf(tctx, "[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s",
k, open_attrs_table[i], open_attrs_table[j], k, open_attrs_table[i], open_attrs_table[j],
smbcli_errstr(cli1->tree)); smbcli_errstr(cli1->tree)));
correct = False;
CHECK_MAX_FAILURES(error_exit); CHECK_MAX_FAILURES(error_exit);
}
#if 0 #if 0
printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]); torture_comment(tctx, "[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
#endif #endif
k++; k++;
continue; continue;
} }
if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { torture_assert_ntstatus_ok(tctx,
printf("close %d (2) of %s failed (%s)\n", j, fname, smbcli_errstr(cli1->tree)); smbcli_close(cli1->tree, fnum1),
return False; talloc_asprintf(tctx, "close %d (2) of %s failed (%s)", j,
} fname, smbcli_errstr(cli1->tree)));
if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL))) { torture_assert_ntstatus_ok(tctx,
printf("getatr(2) failed (%s)\n", smbcli_errstr(cli1->tree)); smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL),
return False; talloc_asprintf(tctx, "getatr(2) failed (%s)", smbcli_errstr(cli1->tree)));
}
#if 0 #if 0
printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n", torture_comment(tctx, "[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
k, open_attrs_table[i], open_attrs_table[j], attr ); k, open_attrs_table[i], open_attrs_table[j], attr );
#endif #endif
@ -174,12 +162,11 @@ BOOL torture_openattrtest(struct torture_context *torture)
if (attr != attr_results[l].result_attr || if (attr != attr_results[l].result_attr ||
open_attrs_table[i] != attr_results[l].init_attr || open_attrs_table[i] != attr_results[l].init_attr ||
open_attrs_table[j] != attr_results[l].trunc_attr) { open_attrs_table[j] != attr_results[l].trunc_attr) {
printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n", torture_comment(tctx, "[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
k, open_attrs_table[i], k, open_attrs_table[i],
open_attrs_table[j], open_attrs_table[j],
(uint_t)attr, (uint_t)attr,
attr_results[l].result_attr); attr_results[l].result_attr);
correct = False;
CHECK_MAX_FAILURES(error_exit); CHECK_MAX_FAILURES(error_exit);
} }
break; break;
@ -192,11 +179,6 @@ error_exit:
smbcli_setatr(cli1->tree, fname, 0, 0); smbcli_setatr(cli1->tree, fname, 0, 0);
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
printf("open attr test %s.\n", correct ? "passed" : "failed"); return true;
if (!torture_close_connection(cli1)) {
correct = False;
}
return correct;
} }

File diff suppressed because it is too large Load Diff

View File

@ -26,14 +26,15 @@
#include "libcli/libcli.h" #include "libcli/libcli.h"
#include "torture/util.h" #include "torture/util.h"
#define BASEDIR "\\chartest" #define BASEDIR "\\chartest\\"
/* /*
open a file using a set of unicode code points for the name open a file using a set of unicode code points for the name
the prefix BASEDIR is added before the name the prefix BASEDIR is added before the name
*/ */
static NTSTATUS unicode_open(struct smbcli_tree *tree, static NTSTATUS unicode_open(struct torture_context *tctx,
struct smbcli_tree *tree,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
uint32_t open_disposition, uint32_t open_disposition,
const uint32_t *u_name, const uint32_t *u_name,
@ -57,12 +58,12 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
i = convert_string_talloc(ucs_name, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname); i = convert_string_talloc(ucs_name, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname);
if (i == -1) { if (i == -1) {
printf("Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n"); torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
talloc_free(ucs_name); talloc_free(ucs_name);
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
fname2 = talloc_asprintf(ucs_name, "%s\\%s", BASEDIR, fname); fname2 = talloc_asprintf(ucs_name, "%s%s", BASEDIR, fname);
if (!fname2) { if (!fname2) {
talloc_free(ucs_name); talloc_free(ucs_name);
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
@ -93,7 +94,8 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
/* /*
see if the server recognises composed characters see if the server recognises composed characters
*/ */
static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_composed(struct torture_context *tctx,
struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
{ {
const uint32_t name1[] = {0x61, 0x308}; const uint32_t name1[] = {0x61, 0x308};
const uint32_t name2[] = {0xe4}; const uint32_t name2[] = {0xe4};
@ -101,14 +103,14 @@ static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("Testing composite character (a umlaut)\n"); printf("Testing composite character (a umlaut)\n");
status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 2); status1 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 2);
if (!NT_STATUS_IS_OK(status1)) { if (!NT_STATUS_IS_OK(status1)) {
printf("Failed to create composed name - %s\n", printf("Failed to create composed name - %s\n",
nt_errstr(status1)); nt_errstr(status1));
return False; return False;
} }
status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); status2 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
if (!NT_STATUS_IS_OK(status2)) { if (!NT_STATUS_IS_OK(status2)) {
printf("Failed to create accented character - %s\n", printf("Failed to create accented character - %s\n",
@ -122,7 +124,8 @@ static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
/* /*
see if the server recognises a naked diacritical see if the server recognises a naked diacritical
*/ */
static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_diacritical(struct torture_context *tctx,
struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
{ {
const uint32_t name1[] = {0x308}; const uint32_t name1[] = {0x308};
const uint32_t name2[] = {0x308, 0x308}; const uint32_t name2[] = {0x308, 0x308};
@ -130,7 +133,7 @@ static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("Testing naked diacritical (umlaut)\n"); printf("Testing naked diacritical (umlaut)\n");
status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); status1 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
if (!NT_STATUS_IS_OK(status1)) { if (!NT_STATUS_IS_OK(status1)) {
printf("Failed to create naked diacritical - %s\n", printf("Failed to create naked diacritical - %s\n",
@ -139,7 +142,7 @@ static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
} }
/* try a double diacritical */ /* try a double diacritical */
status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 2); status2 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 2);
if (!NT_STATUS_IS_OK(status2)) { if (!NT_STATUS_IS_OK(status2)) {
printf("Failed to create double naked diacritical - %s\n", printf("Failed to create double naked diacritical - %s\n",
@ -153,7 +156,8 @@ static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
/* /*
see if the server recognises a partial surrogate pair see if the server recognises a partial surrogate pair
*/ */
static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_surrogate(struct torture_context *tctx,
struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
{ {
const uint32_t name1[] = {0xd800}; const uint32_t name1[] = {0xd800};
const uint32_t name2[] = {0xdc00}; const uint32_t name2[] = {0xdc00};
@ -162,7 +166,7 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("Testing partial surrogate\n"); printf("Testing partial surrogate\n");
status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("Failed to create partial surrogate 1 - %s\n", printf("Failed to create partial surrogate 1 - %s\n",
@ -170,7 +174,7 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
return False; return False;
} }
status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("Failed to create partial surrogate 2 - %s\n", printf("Failed to create partial surrogate 2 - %s\n",
@ -178,7 +182,7 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
return False; return False;
} }
status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 2); status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("Failed to create full surrogate - %s\n", printf("Failed to create full surrogate - %s\n",
@ -192,7 +196,8 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
/* /*
see if the server recognises wide-a characters see if the server recognises wide-a characters
*/ */
static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_widea(struct torture_context *tctx,
struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
{ {
const uint32_t name1[] = {'a'}; const uint32_t name1[] = {'a'};
const uint32_t name2[] = {0xff41}; const uint32_t name2[] = {0xff41};
@ -201,7 +206,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("Testing wide-a\n"); printf("Testing wide-a\n");
status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("Failed to create 'a' - %s\n", printf("Failed to create 'a' - %s\n",
@ -209,7 +214,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
return False; return False;
} }
status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("Failed to create wide-a - %s\n", printf("Failed to create wide-a - %s\n",
@ -217,7 +222,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
return False; return False;
} }
status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 1); status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 1);
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) { if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
printf("Expected %s creating wide-A - %s\n", printf("Expected %s creating wide-A - %s\n",
@ -229,37 +234,30 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
return True; return True;
} }
BOOL torture_charset(struct torture_context *torture) BOOL torture_charset(struct torture_context *tctx, struct smbcli_state *cli)
{ {
static struct smbcli_state *cli;
BOOL ret = True; BOOL ret = True;
TALLOC_CTX *mem_ctx; TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init("torture_charset"); mem_ctx = talloc_init("torture_charset");
if (!torture_open_connection(&cli, 0)) {
return False;
}
printf("Starting charset tests\n");
if (!torture_setup_dir(cli, BASEDIR)) { if (!torture_setup_dir(cli, BASEDIR)) {
return False; return False;
} }
if (!test_composed(cli, mem_ctx)) { if (!test_composed(tctx, cli, mem_ctx)) {
ret = False; ret = False;
} }
if (!test_diacritical(cli, mem_ctx)) { if (!test_diacritical(tctx, cli, mem_ctx)) {
ret = False; ret = False;
} }
if (!test_surrogate(cli, mem_ctx)) { if (!test_surrogate(tctx, cli, mem_ctx)) {
ret = False; ret = False;
} }
if (!test_widea(cli, mem_ctx)) { if (!test_widea(tctx, cli, mem_ctx)) {
ret = False; ret = False;
} }

View File

@ -32,7 +32,7 @@
#define BASEDIR "\\delaywrite" #define BASEDIR "\\delaywrite"
static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli)
{ {
union smb_fileinfo finfo1, finfo2; union smb_fileinfo finfo1, finfo2;
const char *fname = BASEDIR "\\torture_file.txt"; const char *fname = BASEDIR "\\torture_file.txt";
@ -42,15 +42,13 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_
ssize_t written; ssize_t written;
time_t t; time_t t;
printf("Testing delayed update of write time\n");
if (!torture_setup_dir(cli, BASEDIR)) { if (!torture_setup_dir(cli, BASEDIR)) {
return False; return False;
} }
fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
if (fnum1 == -1) { if (fnum1 == -1) {
printf("Failed to open %s\n", fname); torture_comment(tctx, "Failed to open %s\n", fname);
return False; return False;
} }
@ -58,15 +56,15 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_
finfo1.basic_info.in.file.fnum = fnum1; finfo1.basic_info.in.file.fnum = fnum1;
finfo2 = finfo1; finfo2 = finfo1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("Initial write time %s\n", torture_comment(tctx, "Initial write time %s\n",
nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); nt_time_string(tctx, finfo1.basic_info.out.write_time));
/* 3 second delay to ensure we get past any 2 second time /* 3 second delay to ensure we get past any 2 second time
granularity (older systems may have that) */ granularity (older systems may have that) */
@ -75,7 +73,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_
written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
if (written != 1) { if (written != 1) {
printf("write failed - wrote %d bytes (%s)\n", torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
(int)written, __location__); (int)written, __location__);
return False; return False;
} }
@ -83,17 +81,17 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_
t = time(NULL); t = time(NULL);
while (time(NULL) < t+120) { while (time(NULL) < t+120) {
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
ret = False; ret = False;
break; break;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time after %d seconds\n", torture_comment(tctx, "Server updated write_time after %d seconds\n",
(int)(time(NULL) - t)); (int)(time(NULL) - t));
break; break;
} }
@ -102,7 +100,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_
} }
if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
printf("Server did not update write time?!\n"); torture_comment(tctx, "Server did not update write time?!\n");
ret = False; ret = False;
} }
@ -119,9 +117,9 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_
* Do as above, but using 2 connections. * Do as above, but using 2 connections.
*/ */
static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli,
struct smbcli_state *cli2)
{ {
struct smbcli_state *cli2=NULL;
union smb_fileinfo finfo1, finfo2; union smb_fileinfo finfo1, finfo2;
const char *fname = BASEDIR "\\torture_file.txt"; const char *fname = BASEDIR "\\torture_file.txt";
NTSTATUS status; NTSTATUS status;
@ -132,19 +130,13 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
time_t t; time_t t;
union smb_flush flsh; union smb_flush flsh;
printf("Testing delayed update of write time using 2 connections\n");
if (!torture_open_connection(&cli2, 1)) {
return False;
}
if (!torture_setup_dir(cli, BASEDIR)) { if (!torture_setup_dir(cli, BASEDIR)) {
return False; return False;
} }
fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
if (fnum1 == -1) { if (fnum1 == -1) {
printf("Failed to open %s\n", fname); torture_comment(tctx, "Failed to open %s\n", fname);
return False; return False;
} }
@ -152,15 +144,15 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
finfo1.basic_info.in.file.fnum = fnum1; finfo1.basic_info.in.file.fnum = fnum1;
finfo2 = finfo1; finfo2 = finfo1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("Initial write time %s\n", torture_comment(tctx, "Initial write time %s\n",
nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); nt_time_string(tctx, finfo1.basic_info.out.write_time));
/* 3 second delay to ensure we get past any 2 second time /* 3 second delay to ensure we get past any 2 second time
granularity (older systems may have that) */ granularity (older systems may have that) */
@ -198,17 +190,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
while (time(NULL) < t+120) { while (time(NULL) < t+120) {
finfo2.basic_info.in.file.path = fname; finfo2.basic_info.in.file.path = fname;
status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
ret = False; ret = False;
break; break;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time after %d seconds\n", torture_comment(tctx, "Server updated write_time after %d seconds\n",
(int)(time(NULL) - t)); (int)(time(NULL) - t));
break; break;
} }
@ -217,7 +209,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
} }
if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
printf("Server did not update write time?!\n"); torture_comment(tctx, "Server did not update write time?!\n");
ret = False; ret = False;
} }
@ -227,23 +219,23 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
finfo1.basic_info.in.file.fnum = fnum1; finfo1.basic_info.in.file.fnum = fnum1;
finfo2 = finfo1; finfo2 = finfo1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("Modified write time %s\n", torture_comment(tctx, "Modified write time %s\n",
nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); nt_time_string(tctx, finfo1.basic_info.out.write_time));
printf("Doing a 10 byte write to extend the file and see if this changes the last write time.\n"); torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n");
written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10);
if (written != 10) { if (written != 10) {
printf("write failed - wrote %d bytes (%s)\n", torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
(int)written, __location__); (int)written, __location__);
return False; return False;
} }
@ -251,7 +243,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
/* Just to prove to tridge that the an smbflush has no effect on /* Just to prove to tridge that the an smbflush has no effect on
the write time :-). The setfileinfo IS STICKY. JRA. */ the write time :-). The setfileinfo IS STICKY. JRA. */
printf("Doing flush after write\n"); torture_comment(tctx, "Doing flush after write\n");
flsh.flush.level = RAW_FLUSH_FLUSH; flsh.flush.level = RAW_FLUSH_FLUSH;
flsh.flush.in.file.fnum = fnum1; flsh.flush.in.file.fnum = fnum1;
@ -267,17 +259,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
don't have any effect. But make sure. */ don't have any effect. But make sure. */
while (time(NULL) < t+15) { while (time(NULL) < t+15) {
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
ret = False; ret = False;
break; break;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time after %d seconds\n", torture_comment(tctx, "Server updated write_time after %d seconds\n",
(int)(time(NULL) - t)); (int)(time(NULL) - t));
break; break;
} }
@ -286,47 +278,47 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
} }
if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
printf("Server did not update write time\n"); torture_comment(tctx, "Server did not update write time\n");
} }
fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) { if (fnum2 == -1) {
printf("Failed to open %s\n", fname); torture_comment(tctx, "Failed to open %s\n", fname);
return False; return False;
} }
printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n");
written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10); written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10);
if (written != 10) { if (written != 10) {
printf("write failed - wrote %d bytes (%s)\n", torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
(int)written, __location__); (int)written, __location__);
return False; return False;
} }
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time\n"); torture_comment(tctx, "Server updated write_time\n");
} }
printf("Closing the first fd to see if write time updated.\n"); torture_comment(tctx, "Closing the first fd to see if write time updated.\n");
smbcli_close(cli->tree, fnum1); smbcli_close(cli->tree, fnum1);
fnum1 = -1; fnum1 = -1;
printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n");
written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10); written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10);
if (written != 10) { if (written != 10) {
printf("write failed - wrote %d bytes (%s)\n", torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
(int)written, __location__); (int)written, __location__);
return False; return False;
} }
@ -334,16 +326,16 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
finfo1.basic_info.in.file.fnum = fnum2; finfo1.basic_info.in.file.fnum = fnum2;
finfo2 = finfo1; finfo2 = finfo1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time\n"); torture_comment(tctx, "Server updated write_time\n");
} }
t = time(NULL); t = time(NULL);
@ -352,17 +344,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
don't have any effect. But make sure. */ don't have any effect. But make sure. */
while (time(NULL) < t+15) { while (time(NULL) < t+15) {
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
ret = False; ret = False;
break; break;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time after %d seconds\n", torture_comment(tctx, "Server updated write_time after %d seconds\n",
(int)(time(NULL) - t)); (int)(time(NULL) - t));
break; break;
} }
@ -371,17 +363,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
} }
if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
printf("Server did not update write time\n"); torture_comment(tctx, "Server did not update write time\n");
} }
printf("Closing both fd's to see if write time updated.\n"); torture_comment(tctx, "Closing both fd's to see if write time updated.\n");
smbcli_close(cli->tree, fnum2); smbcli_close(cli->tree, fnum2);
fnum2 = -1; fnum2 = -1;
fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
if (fnum1 == -1) { if (fnum1 == -1) {
printf("Failed to open %s\n", fname); torture_comment(tctx, "Failed to open %s\n", fname);
return False; return False;
} }
@ -389,23 +381,23 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
finfo1.basic_info.in.file.fnum = fnum1; finfo1.basic_info.in.file.fnum = fnum1;
finfo2 = finfo1; finfo2 = finfo1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("Second open initial write time %s\n", torture_comment(tctx, "Second open initial write time %s\n",
nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); nt_time_string(tctx, finfo1.basic_info.out.write_time));
sleep(10); sleep(10);
printf("Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n");
written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10);
if (written != 10) { if (written != 10) {
printf("write failed - wrote %d bytes (%s)\n", torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
(int)written, __location__); (int)written, __location__);
return False; return False;
} }
@ -413,16 +405,16 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
finfo1.basic_info.in.file.fnum = fnum1; finfo1.basic_info.in.file.fnum = fnum1;
finfo2 = finfo1; finfo2 = finfo1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
return False; return False;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time\n"); torture_comment(tctx, "Server updated write_time\n");
} }
t = time(NULL); t = time(NULL);
@ -431,17 +423,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
don't have any effect. But make sure. */ don't have any effect. But make sure. */
while (time(NULL) < t+15) { while (time(NULL) < t+15) {
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
ret = False; ret = False;
break; break;
} }
printf("write time %s\n", torture_comment(tctx, "write time %s\n",
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
printf("Server updated write_time after %d seconds\n", torture_comment(tctx, "Server updated write_time after %d seconds\n",
(int)(time(NULL) - t)); (int)(time(NULL) - t));
break; break;
} }
@ -450,7 +442,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
} }
if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
printf("Server did not update write time\n"); torture_comment(tctx, "Server did not update write time\n");
} }
@ -458,9 +450,6 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
second connection to ensure it's the same. This is very easy for a Windows second connection to ensure it's the same. This is very easy for a Windows
server but a bastard to get right on a POSIX server. JRA. */ server but a bastard to get right on a POSIX server. JRA. */
if (cli2 != NULL) {
torture_close_connection(cli2);
}
if (fnum1 != -1) if (fnum1 != -1)
smbcli_close(cli->tree, fnum1); smbcli_close(cli->tree, fnum1);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
@ -480,7 +469,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem
* nasty.... * nasty....
*/ */
static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli,
struct smbcli_state *cli2)
{ {
union smb_fileinfo finfo1, finfo2; union smb_fileinfo finfo1, finfo2;
const char *fname = BASEDIR "\\torture_file.txt"; const char *fname = BASEDIR "\\torture_file.txt";
@ -489,9 +479,6 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
int fnum2; int fnum2;
BOOL ret = True; BOOL ret = True;
ssize_t written; ssize_t written;
struct smbcli_state *cli2=NULL;
printf("Testing finfo update on close\n");
if (!torture_setup_dir(cli, BASEDIR)) { if (!torture_setup_dir(cli, BASEDIR)) {
return False; return False;
@ -506,7 +493,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
finfo1.basic_info.in.file.fnum = fnum1; finfo1.basic_info.in.file.fnum = fnum1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
@ -519,19 +506,15 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
if (written != 1) { if (written != 1) {
printf("(%s) written gave %d - should have been 1\n", torture_comment(tctx, "(%s) written gave %d - should have been 1\n",
__location__, (int)written); __location__, (int)written);
ret = False; ret = False;
goto done; goto done;
} }
if (!torture_open_connection(&cli2, 1)) {
return False;
}
fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) { if (fnum2 == -1) {
printf("(%s) failed to open 2nd time - %s\n", torture_comment(tctx, "(%s) failed to open 2nd time - %s\n",
__location__, smbcli_errstr(cli2->tree)); __location__, smbcli_errstr(cli2->tree));
ret = False; ret = False;
goto done; goto done;
@ -540,7 +523,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1); written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
if (written != 1) { if (written != 1) {
printf("(%s) written gave %d - should have been 1\n", torture_comment(tctx, "(%s) written gave %d - should have been 1\n",
__location__, (int)written); __location__, (int)written);
ret = False; ret = False;
goto done; goto done;
@ -549,7 +532,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
finfo2.basic_info.in.file.path = fname; finfo2.basic_info.in.file.path = fname;
status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("(%s) fileinfo failed: %s\n", DEBUG(0, ("(%s) fileinfo failed: %s\n",
@ -560,31 +543,31 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
if (finfo1.basic_info.out.create_time != if (finfo1.basic_info.out.create_time !=
finfo2.basic_info.out.create_time) { finfo2.basic_info.out.create_time) {
printf("(%s) create_time changed\n", __location__); torture_comment(tctx, "(%s) create_time changed\n", __location__);
ret = False; ret = False;
goto done; goto done;
} }
if (finfo1.basic_info.out.access_time != if (finfo1.basic_info.out.access_time !=
finfo2.basic_info.out.access_time) { finfo2.basic_info.out.access_time) {
printf("(%s) access_time changed\n", __location__); torture_comment(tctx, "(%s) access_time changed\n", __location__);
ret = False; ret = False;
goto done; goto done;
} }
if (finfo1.basic_info.out.write_time != if (finfo1.basic_info.out.write_time !=
finfo2.basic_info.out.write_time) { finfo2.basic_info.out.write_time) {
printf("(%s) write_time changed\n", __location__); torture_comment(tctx, "(%s) write_time changed\n", __location__);
printf("write time conn 1 = %s, conn 2 = %s\n", torture_comment(tctx, "write time conn 1 = %s, conn 2 = %s\n",
nt_time_string(mem_ctx, finfo1.basic_info.out.write_time), nt_time_string(tctx, finfo1.basic_info.out.write_time),
nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); nt_time_string(tctx, finfo2.basic_info.out.write_time));
ret = False; ret = False;
goto done; goto done;
} }
if (finfo1.basic_info.out.change_time != if (finfo1.basic_info.out.change_time !=
finfo2.basic_info.out.change_time) { finfo2.basic_info.out.change_time) {
printf("(%s) change_time changed\n", __location__); torture_comment(tctx, "(%s) change_time changed\n", __location__);
ret = False; ret = False;
goto done; goto done;
} }
@ -595,14 +578,13 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
* *not* have updated the stat on disk */ * *not* have updated the stat on disk */
smbcli_close(cli2->tree, fnum2); smbcli_close(cli2->tree, fnum2);
torture_close_connection(cli2);
cli2 = NULL; cli2 = NULL;
/* This call is only for the people looking at ethereal :-) */ /* This call is only for the people looking at ethereal :-) */
finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
finfo2.basic_info.in.file.path = fname; finfo2.basic_info.in.file.path = fname;
status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); status = smb_raw_pathinfo(cli->tree, tctx, &finfo2);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
@ -615,9 +597,6 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
smbcli_close(cli->tree, fnum1); smbcli_close(cli->tree, fnum1);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
smbcli_deltree(cli->tree, BASEDIR); smbcli_deltree(cli->tree, BASEDIR);
if (cli2 != NULL) {
torture_close_connection(cli2);
}
return ret; return ret;
} }
@ -626,23 +605,13 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
/* /*
testing of delayed update of write_time testing of delayed update of write_time
*/ */
BOOL torture_delay_write(struct torture_context *torture) struct torture_suite *torture_delay_write(void)
{ {
struct smbcli_state *cli; struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE");
BOOL ret = True;
TALLOC_CTX *mem_ctx;
if (!torture_open_connection(&cli, 0)) { torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
return False; torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
} torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2);
mem_ctx = talloc_init("torture_delay_write"); return suite;
ret &= test_finfo_after_write(cli, mem_ctx);
ret &= test_delayed_write_update(cli, mem_ctx);
ret &= test_delayed_write_update2(cli, mem_ctx);
torture_close_connection(cli);
talloc_free(mem_ctx);
return ret;
} }

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,6 @@
#include "libcli/libcli.h" #include "libcli/libcli.h"
#include "torture/util.h" #include "torture/util.h"
extern BOOL torture_showall;
extern int torture_failures; extern int torture_failures;
#define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0) #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
@ -1401,18 +1400,18 @@ static const struct {
}; };
static void progress_bar(uint_t i, uint_t total) static void progress_bar(struct torture_context *tctx, uint_t i, uint_t total)
{ {
printf("%5d/%5d\r", i, total); torture_comment(tctx, "%5d/%5d\r", i, total);
fflush(stdout); fflush(stdout);
} }
/* /*
this produces a matrix of deny mode behaviour for 1 connection this produces a matrix of deny mode behaviour for 1 connection
*/ */
BOOL torture_denytest1(struct torture_context *torture) BOOL torture_denytest1(struct torture_context *tctx,
struct smbcli_state *cli1)
{ {
static struct smbcli_state *cli1;
int fnum1, fnum2; int fnum1, fnum2;
int i; int i;
BOOL correct = True; BOOL correct = True;
@ -1420,13 +1419,7 @@ BOOL torture_denytest1(struct torture_context *torture)
const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"}; const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
int failures=0; int failures=0;
if (!torture_open_connection(&cli1, 0)) { torture_comment(tctx, "Testing deny modes with 1 connection\n");
return False;
}
printf("starting denytest1\n");
printf("Testing deny modes with 1 connection\n");
for (i=0;i<2;i++) { for (i=0;i<2;i++) {
smbcli_unlink(cli1->tree, fnames[i]); smbcli_unlink(cli1->tree, fnames[i]);
@ -1435,7 +1428,7 @@ BOOL torture_denytest1(struct torture_context *torture)
smbcli_close(cli1->tree, fnum1); smbcli_close(cli1->tree, fnum1);
} }
printf("testing %d entries\n", (int)ARRAY_SIZE(denytable1)); torture_comment(tctx, "testing %d entries\n", (int)ARRAY_SIZE(denytable1));
GetTimeOfDay(&tv_start); GetTimeOfDay(&tv_start);
@ -1443,7 +1436,7 @@ BOOL torture_denytest1(struct torture_context *torture)
enum deny_result res; enum deny_result res;
const char *fname = fnames[denytable1[i].isexe]; const char *fname = fnames[denytable1[i].isexe];
progress_bar(i, ARRAY_SIZE(denytable1)); progress_bar(tctx, i, ARRAY_SIZE(denytable1));
fnum1 = smbcli_open(cli1->tree, fname, fnum1 = smbcli_open(cli1->tree, fname,
denytable1[i].mode1, denytable1[i].mode1,
@ -1467,12 +1460,13 @@ BOOL torture_denytest1(struct torture_context *torture)
} }
} }
if (torture_showall || res != denytable1[i].result) { if (lp_parm_bool(-1, "torture", "showall", False) ||
res != denytable1[i].result) {
int64_t tdif; int64_t tdif;
GetTimeOfDay(&tv); GetTimeOfDay(&tv);
tdif = usec_time_diff(&tv, &tv_start); tdif = usec_time_diff(&tv, &tv_start);
tdif /= 1000; tdif /= 1000;
printf("%lld: %s %8s %10s %8s %10s %s (correct=%s)\n", torture_comment(tctx, "%lld: %s %8s %10s %8s %10s %s (correct=%s)\n",
(long long)tdif, (long long)tdif,
fname, fname,
denystr(denytable1[i].deny1), denystr(denytable1[i].deny1),
@ -1497,11 +1491,7 @@ failed:
smbcli_unlink(cli1->tree, fnames[i]); smbcli_unlink(cli1->tree, fnames[i]);
} }
if (!torture_close_connection(cli1)) { torture_comment(tctx, "finshed denytest1 (%d failures)\n", failures);
correct = False;
}
printf("finshed denytest1 (%d failures)\n", failures);
return correct; return correct;
} }
@ -1509,9 +1499,10 @@ failed:
/* /*
this produces a matrix of deny mode behaviour with 2 connections this produces a matrix of deny mode behaviour with 2 connections
*/ */
BOOL torture_denytest2(struct torture_context *torture) BOOL torture_denytest2(struct torture_context *tctx,
struct smbcli_state *cli1,
struct smbcli_state *cli2)
{ {
static struct smbcli_state *cli1, *cli2;
int fnum1, fnum2; int fnum1, fnum2;
int i; int i;
BOOL correct = True; BOOL correct = True;
@ -1519,15 +1510,6 @@ BOOL torture_denytest2(struct torture_context *torture)
struct timeval tv, tv_start; struct timeval tv, tv_start;
int failures=0; int failures=0;
if (!torture_open_connection(&cli1, 0) ||
!torture_open_connection(&cli2, 1)) {
return False;
}
printf("starting denytest2\n");
printf("Testing deny modes with 2 connections\n");
for (i=0;i<2;i++) { for (i=0;i<2;i++) {
smbcli_unlink(cli1->tree, fnames[i]); smbcli_unlink(cli1->tree, fnames[i]);
fnum1 = smbcli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE); fnum1 = smbcli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
@ -1541,7 +1523,7 @@ BOOL torture_denytest2(struct torture_context *torture)
enum deny_result res; enum deny_result res;
const char *fname = fnames[denytable2[i].isexe]; const char *fname = fnames[denytable2[i].isexe];
progress_bar(i, ARRAY_SIZE(denytable1)); progress_bar(tctx, i, ARRAY_SIZE(denytable1));
fnum1 = smbcli_open(cli1->tree, fname, fnum1 = smbcli_open(cli1->tree, fname,
denytable2[i].mode1, denytable2[i].mode1,
@ -1565,12 +1547,13 @@ BOOL torture_denytest2(struct torture_context *torture)
} }
} }
if (torture_showall || res != denytable2[i].result) { if (lp_parm_bool(-1, "torture", "showall", False) ||
res != denytable2[i].result) {
int64_t tdif; int64_t tdif;
GetTimeOfDay(&tv); GetTimeOfDay(&tv);
tdif = usec_time_diff(&tv, &tv_start); tdif = usec_time_diff(&tv, &tv_start);
tdif /= 1000; tdif /= 1000;
printf("%lld: %s %8s %10s %8s %10s %s (correct=%s)\n", torture_comment(tctx, "%lld: %s %8s %10s %8s %10s %s (correct=%s)\n",
(long long)tdif, (long long)tdif,
fname, fname,
denystr(denytable2[i].deny1), denystr(denytable2[i].deny1),
@ -1595,14 +1578,7 @@ failed:
smbcli_unlink(cli1->tree, fnames[i]); smbcli_unlink(cli1->tree, fnames[i]);
} }
if (!torture_close_connection(cli1)) { torture_comment(tctx, "finshed denytest2 (%d failures)\n", failures);
correct = False;
}
if (!torture_close_connection(cli2)) {
correct = False;
}
printf("finshed denytest2 (%d failures)\n", failures);
return correct; return correct;
} }
@ -1611,23 +1587,13 @@ failed:
/* /*
simple test harness for playing with deny modes simple test harness for playing with deny modes
*/ */
BOOL torture_denytest3(struct torture_context *torture) BOOL torture_denytest3(struct torture_context *tctx,
struct smbcli_state *cli1,
struct smbcli_state *cli2)
{ {
struct smbcli_state *cli1, *cli2;
int fnum1, fnum2; int fnum1, fnum2;
const char *fname; const char *fname;
printf("starting deny3 test\n");
printf("Testing simple deny modes\n");
if (!torture_open_connection(&cli1, 0)) {
return False;
}
if (!torture_open_connection(&cli2, 1)) {
return False;
}
fname = "\\deny_dos1.dat"; fname = "\\deny_dos1.dat";
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
@ -1636,7 +1602,7 @@ BOOL torture_denytest3(struct torture_context *torture)
if (fnum1 != -1) smbcli_close(cli1->tree, fnum1); if (fnum1 != -1) smbcli_close(cli1->tree, fnum1);
if (fnum2 != -1) smbcli_close(cli1->tree, fnum2); if (fnum2 != -1) smbcli_close(cli1->tree, fnum2);
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
fname = "\\deny_dos2.dat"; fname = "\\deny_dos2.dat";
@ -1647,11 +1613,7 @@ BOOL torture_denytest3(struct torture_context *torture)
if (fnum1 != -1) smbcli_close(cli1->tree, fnum1); if (fnum1 != -1) smbcli_close(cli1->tree, fnum1);
if (fnum2 != -1) smbcli_close(cli2->tree, fnum2); if (fnum2 != -1) smbcli_close(cli2->tree, fnum2);
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
torture_close_connection(cli1);
torture_close_connection(cli2);
return True; return True;
} }
@ -1758,7 +1720,8 @@ static NTSTATUS predict_share_conflict(uint32_t sa1, uint32_t am1, uint32_t sa2,
/* /*
a denytest for ntcreatex a denytest for ntcreatex
*/ */
static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *cli2, int client) static BOOL torture_ntdenytest(struct torture_context *tctx,
struct smbcli_state *cli1, struct smbcli_state *cli2, int client)
{ {
const struct bit_value share_access_bits[] = { const struct bit_value share_access_bits[] = {
{ NTCREATEX_SHARE_ACCESS_READ, "S_R" }, { NTCREATEX_SHARE_ACCESS_READ, "S_R" },
@ -1787,7 +1750,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
int failures = 0; int failures = 0;
uint8_t buf[1]; uint8_t buf[1];
printf("format: server correct\n"); torture_comment(tctx, "format: server correct\n");
ZERO_STRUCT(buf); ZERO_STRUCT(buf);
@ -1812,7 +1775,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
io1.ntcreatex.in.fname = fname; io1.ntcreatex.in.fname = fname;
io2 = io1; io2 = io1;
printf("testing %d entries on %s\n", torture_numops, fname); torture_comment(tctx, "testing %d entries on %s\n", torture_numops, fname);
for (i=0;i<torture_numops;i++) { for (i=0;i<torture_numops;i++) {
NTSTATUS status1, status2, status2_p; NTSTATUS status1, status2, status2_p;
@ -1825,7 +1788,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
int b_am2 = random() & ((1<<nbits2)-1); int b_am2 = random() & ((1<<nbits2)-1);
BOOL read_for_execute; BOOL read_for_execute;
progress_bar(i, torture_numops); progress_bar(tctx, i, torture_numops);
io1.ntcreatex.in.share_access = map_bits(share_access_bits, b_sa1, nbits1); io1.ntcreatex.in.share_access = map_bits(share_access_bits, b_sa1, nbits1);
io1.ntcreatex.in.access_mask = map_bits(access_mask_bits, b_am1, nbits2); io1.ntcreatex.in.access_mask = map_bits(access_mask_bits, b_am1, nbits2);
@ -1889,10 +1852,10 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
GetTimeOfDay(&tv); GetTimeOfDay(&tv);
tdif = usec_time_diff(&tv, &tv_start); tdif = usec_time_diff(&tv, &tv_start);
tdif /= 1000; tdif /= 1000;
if (torture_showall || if (lp_parm_bool(-1, "torture", "showall", False) ||
!NT_STATUS_EQUAL(status2, status2_p) || !NT_STATUS_EQUAL(status2, status2_p) ||
res != res2) { res != res2) {
printf("\n%-20s %-70s\n%-20s %-70s %4s %4s %s/%s\n", torture_comment(tctx, "\n%-20s %-70s\n%-20s %-70s %4s %4s %s/%s\n",
bit_string(mem_ctx, share_access_bits, b_sa1, nbits1), bit_string(mem_ctx, share_access_bits, b_sa1, nbits1),
bit_string(mem_ctx, access_mask_bits, b_am1, nbits2), bit_string(mem_ctx, access_mask_bits, b_am1, nbits2),
bit_string(mem_ctx, share_access_bits, b_sa2, nbits1), bit_string(mem_ctx, share_access_bits, b_sa2, nbits1),
@ -1916,7 +1879,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
failed: failed:
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
printf("finshed ntdenytest (%d failures)\n", failures); torture_comment(tctx, "finshed ntdenytest (%d failures)\n", failures);
return correct; return correct;
} }
@ -1925,47 +1888,31 @@ failed:
/* /*
a denytest for ntcreatex a denytest for ntcreatex
*/ */
BOOL torture_ntdenytest1(struct smbcli_state *cli, int client) BOOL torture_ntdenytest1(struct torture_context *tctx, struct smbcli_state *cli, int client)
{ {
extern int torture_seed; extern int torture_seed;
srandom(torture_seed + client); srandom(torture_seed + client);
printf("starting ntdenytest1 client %d\n", client); torture_comment(tctx, "starting ntdenytest1 client %d\n", client);
return torture_ntdenytest(cli, cli, client); return torture_ntdenytest(tctx, cli, cli, client);
} }
/* /*
a denytest for ntcreatex a denytest for ntcreatex
*/ */
BOOL torture_ntdenytest2(struct torture_context *torture) BOOL torture_ntdenytest2(struct torture_context *torture,
struct smbcli_state *cli1,
struct smbcli_state *cli2)
{ {
struct smbcli_state *cli1, *cli2; return torture_ntdenytest(torture, cli1, cli2, 0);
BOOL ret;
if (!torture_open_connection(&cli1, 0)) {
return False;
}
if (!torture_open_connection(&cli2, 1)) {
return False;
}
printf("starting ntdenytest2\n");
ret = torture_ntdenytest(cli1, cli2, 0);
torture_close_connection(cli1);
torture_close_connection(cli2);
return ret;
} }
#define CHECK_STATUS(status, correct) do { \ #define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \ if (!NT_STATUS_EQUAL(status, correct)) { \
printf("(%s) Incorrect status %s - should be %s\n", \ torture_comment(tctx, "(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \ __location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \ ret = False; \
goto done; \ goto done; \
@ -1973,7 +1920,7 @@ BOOL torture_ntdenytest2(struct torture_context *torture)
#define CHECK_VAL(v, correct) do { \ #define CHECK_VAL(v, correct) do { \
if ((v) != (correct)) { \ if ((v) != (correct)) { \
printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \ torture_comment(tctx, "(%s) wrong value for %s 0x%x - should be 0x%x\n", \
__location__, #v, (int)(v), (int)correct); \ __location__, #v, (int)(v), (int)correct); \
ret = False; \ ret = False; \
}} while (0) }} while (0)
@ -1981,9 +1928,9 @@ BOOL torture_ntdenytest2(struct torture_context *torture)
/* /*
test sharing of handles with DENY_DOS on a single connection test sharing of handles with DENY_DOS on a single connection
*/ */
BOOL torture_denydos_sharing(struct torture_context *torture) BOOL torture_denydos_sharing(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smbcli_state *cli;
union smb_open io; union smb_open io;
union smb_fileinfo finfo; union smb_fileinfo finfo;
const char *fname = "\\torture_denydos.txt"; const char *fname = "\\torture_denydos.txt";
@ -1993,13 +1940,9 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
union smb_setfileinfo sfinfo; union smb_setfileinfo sfinfo;
TALLOC_CTX *mem_ctx; TALLOC_CTX *mem_ctx;
if (!torture_open_connection(&cli, 0)) {
return False;
}
mem_ctx = talloc_new(cli); mem_ctx = talloc_new(cli);
printf("Checking DENY_DOS shared handle semantics\n"); torture_comment(tctx, "Checking DENY_DOS shared handle semantics\n");
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
io.openx.level = RAW_OPEN_OPENX; io.openx.level = RAW_OPEN_OPENX;
@ -2013,7 +1956,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
io.openx.in.size = 0; io.openx.in.size = 0;
io.openx.in.timeout = 0; io.openx.in.timeout = 0;
printf("openx twice with RDWR/DENY_DOS\n"); torture_comment(tctx, "openx twice with RDWR/DENY_DOS\n");
status = smb_raw_open(cli->tree, mem_ctx, &io); status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK); CHECK_STATUS(status, NT_STATUS_OK);
fnum1 = io.openx.out.file.fnum; fnum1 = io.openx.out.file.fnum;
@ -2022,7 +1965,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
CHECK_STATUS(status, NT_STATUS_OK); CHECK_STATUS(status, NT_STATUS_OK);
fnum2 = io.openx.out.file.fnum; fnum2 = io.openx.out.file.fnum;
printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION; sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
sfinfo.position_information.in.file.fnum = fnum1; sfinfo.position_information.in.file.fnum = fnum1;
@ -2030,7 +1973,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
status = smb_raw_setfileinfo(cli->tree, &sfinfo); status = smb_raw_setfileinfo(cli->tree, &sfinfo);
CHECK_STATUS(status, NT_STATUS_OK); CHECK_STATUS(status, NT_STATUS_OK);
printf("two handles should be same file handle\n"); torture_comment(tctx, "two handles should be same file handle\n");
finfo.position_information.level = RAW_FILEINFO_POSITION_INFORMATION; finfo.position_information.level = RAW_FILEINFO_POSITION_INFORMATION;
finfo.position_information.in.file.fnum = fnum1; finfo.position_information.in.file.fnum = fnum1;
status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo); status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
@ -2046,7 +1989,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
smbcli_close(cli->tree, fnum1); smbcli_close(cli->tree, fnum1);
smbcli_close(cli->tree, fnum2); smbcli_close(cli->tree, fnum2);
printf("openx twice with RDWR/DENY_NONE\n"); torture_comment(tctx, "openx twice with RDWR/DENY_NONE\n");
io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE; io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
status = smb_raw_open(cli->tree, mem_ctx, &io); status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK); CHECK_STATUS(status, NT_STATUS_OK);
@ -2057,9 +2000,9 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
CHECK_STATUS(status, NT_STATUS_OK); CHECK_STATUS(status, NT_STATUS_OK);
fnum2 = io.openx.out.file.fnum; fnum2 = io.openx.out.file.fnum;
printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
printf("two handles should be separate\n"); torture_comment(tctx, "two handles should be separate\n");
sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION; sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
sfinfo.position_information.in.file.fnum = fnum1; sfinfo.position_information.in.file.fnum = fnum1;
sfinfo.position_information.in.position = 1000; sfinfo.position_information.in.position = 1000;

View File

@ -34,22 +34,16 @@ static void list_fn(struct clilist_file_info *finfo, const char *name, void *sta
/* /*
test directory listing speed test directory listing speed
*/ */
BOOL torture_dirtest1(struct torture_context *torture) BOOL torture_dirtest1(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
int i; int i;
struct smbcli_state *cli;
int fnum; int fnum;
BOOL correct = True; BOOL correct = True;
extern int torture_numops; extern int torture_numops;
struct timeval tv; struct timeval tv;
printf("starting dirtest1\n"); torture_comment(tctx, "Creating %d random filenames\n", torture_numops);
if (!torture_open_connection(&cli, 0)) {
return False;
}
printf("Creating %d random filenames\n", torture_numops);
srandom(0); srandom(0);
tv = timeval_current(); tv = timeval_current();
@ -66,11 +60,11 @@ BOOL torture_dirtest1(struct torture_context *torture)
free(fname); free(fname);
} }
printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
printf("dirtest core %g seconds\n", timeval_elapsed(&tv)); torture_comment(tctx, "dirtest core %g seconds\n", timeval_elapsed(&tv));
srandom(0); srandom(0);
for (i=0;i<torture_numops;i++) { for (i=0;i<torture_numops;i++) {
@ -80,34 +74,22 @@ BOOL torture_dirtest1(struct torture_context *torture)
free(fname); free(fname);
} }
if (!torture_close_connection(cli)) {
correct = False;
}
printf("finished dirtest1\n");
return correct; return correct;
} }
BOOL torture_dirtest2(struct torture_context *torture) BOOL torture_dirtest2(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
int i; int i;
struct smbcli_state *cli;
int fnum, num_seen; int fnum, num_seen;
BOOL correct = True; BOOL correct = True;
extern int torture_entries; extern int torture_entries;
printf("starting dirtest2\n");
if (!torture_open_connection(&cli, 0)) {
return False;
}
if (!torture_setup_dir(cli, "\\LISTDIR")) { if (!torture_setup_dir(cli, "\\LISTDIR")) {
return False; return False;
} }
printf("Creating %d files\n", torture_entries); torture_comment(tctx, "Creating %d files\n", torture_entries);
/* Create torture_entries files and torture_entries directories. */ /* Create torture_entries files and torture_entries directories. */
for (i=0;i<torture_entries;i++) { for (i=0;i<torture_entries;i++) {
@ -139,7 +121,7 @@ BOOL torture_dirtest2(struct torture_context *torture)
/* Now ensure that doing an old list sees both files and directories. */ /* Now ensure that doing an old list sees both files and directories. */
num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
printf("num_seen = %d\n", num_seen ); torture_comment(tctx, "num_seen = %d\n", num_seen );
/* We should see (torture_entries) each of files & directories + . and .. */ /* We should see (torture_entries) each of files & directories + . and .. */
if (num_seen != (2*torture_entries)+2) { if (num_seen != (2*torture_entries)+2) {
correct = False; correct = False;
@ -152,7 +134,7 @@ BOOL torture_dirtest2(struct torture_context *torture)
* relevant entries. * relevant entries.
*/ */
num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
printf("num_seen = %d\n", num_seen ); torture_comment(tctx, "num_seen = %d\n", num_seen );
if (num_seen != torture_entries+2) { if (num_seen != torture_entries+2) {
correct = False; correct = False;
fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
@ -160,7 +142,7 @@ BOOL torture_dirtest2(struct torture_context *torture)
} }
num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
printf("num_seen = %d\n", num_seen ); torture_comment(tctx, "num_seen = %d\n", num_seen );
if (num_seen != torture_entries) { if (num_seen != torture_entries) {
correct = False; correct = False;
fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
@ -175,16 +157,10 @@ BOOL torture_dirtest2(struct torture_context *torture)
} }
#if 0 #if 0
printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
#endif #endif
if (!torture_close_connection(cli)) {
correct = False;
}
printf("finished dirtest1\n");
return correct; return correct;
} }

View File

@ -129,11 +129,11 @@ static BOOL test_disconnect_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
*/ */
BOOL torture_disconnect(struct torture_context *torture) BOOL torture_disconnect(struct torture_context *torture)
{ {
struct smbcli_state *cli;
BOOL ret = True; BOOL ret = True;
TALLOC_CTX *mem_ctx; TALLOC_CTX *mem_ctx;
int i; int i;
extern int torture_numops; extern int torture_numops;
struct smbcli_state *cli;
mem_ctx = talloc_init("torture_raw_mux"); mem_ctx = talloc_init("torture_raw_mux");
@ -169,7 +169,6 @@ BOOL torture_disconnect(struct torture_context *torture)
smb_raw_exit(cli->session); smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR); smbcli_deltree(cli->tree, BASEDIR);
torture_close_connection(cli);
talloc_free(mem_ctx); talloc_free(mem_ctx);
return ret; return ret;
} }

File diff suppressed because it is too large Load Diff

View File

@ -155,18 +155,12 @@ static void gen_name(char *name)
} }
BOOL torture_mangle(struct torture_context *torture) BOOL torture_mangle(struct torture_context *torture,
struct smbcli_state *cli)
{ {
extern int torture_numops; extern int torture_numops;
static struct smbcli_state *cli;
int i; int i;
printf("starting mangle test\n");
if (!torture_open_connection(&cli, 0)) {
return False;
}
/* we will use an internal tdb to store the names we have used */ /* we will use an internal tdb to store the names we have used */
tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0);
if (!tdb) { if (!tdb) {
@ -203,8 +197,5 @@ BOOL torture_mangle(struct torture_context *torture)
printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n",
collisions, total, (100.0*collisions) / total, failures); collisions, total, (100.0*collisions) / total, failures);
torture_close_connection(cli);
printf("mangle test finished\n");
return (failures == 0); return (failures == 0);
} }

View File

@ -36,7 +36,7 @@
#include "libcli/composite/composite.h" #include "libcli/composite/composite.h"
extern struct cli_credentials *cmdline_credentials; extern struct cli_credentials *cmdline_credentials;
void benchrw_callback(struct smbcli_request *req); static void benchrw_callback(struct smbcli_request *req);
enum benchrw_stage { enum benchrw_stage {
START, START,
OPEN_CONNECTION, OPEN_CONNECTION,
@ -53,6 +53,7 @@ enum benchrw_stage {
}; };
struct benchrw_state{ struct benchrw_state{
struct torture_context *tctx;
char *dname; char *dname;
char *fname; char *fname;
uint16_t fnum; uint16_t fnum;
@ -87,7 +88,7 @@ static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_
} }
static BOOL rw_torture(struct smbcli_state *c) static BOOL rw_torture(struct torture_context *tctx, struct smbcli_state *c)
{ {
const char *lockfname = "\\torture.lck"; const char *lockfname = "\\torture.lck";
char *fname; char *fname;
@ -103,7 +104,7 @@ static BOOL rw_torture(struct smbcli_state *c)
if (fnum2 == -1) if (fnum2 == -1)
fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE); fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
if (fnum2 == -1) { if (fnum2 == -1) {
printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree)); torture_comment(tctx, "open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
return False; return False;
} }
@ -111,7 +112,7 @@ static BOOL rw_torture(struct smbcli_state *c)
for (i=0;i<torture_numops;i++) { for (i=0;i<torture_numops;i++) {
uint_t n = (uint_t)random()%10; uint_t n = (uint_t)random()%10;
if (i % 10 == 0) { if (i % 10 == 0) {
printf("%d\r", i); fflush(stdout); torture_comment(tctx, "%d\r", i); fflush(stdout);
} }
asprintf(&fname, "\\torture.%u", n); asprintf(&fname, "\\torture.%u", n);
@ -121,13 +122,13 @@ static BOOL rw_torture(struct smbcli_state *c)
fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL); fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
if (fnum == -1) { if (fnum == -1) {
printf("open failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "open failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
break; break;
} }
if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) { if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) {
printf("write failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
} }
@ -135,7 +136,7 @@ static BOOL rw_torture(struct smbcli_state *c)
if (smbcli_write(c->tree, fnum, 0, buf, if (smbcli_write(c->tree, fnum, 0, buf,
sizeof(pid)+(j*sizeof(buf)), sizeof(pid)+(j*sizeof(buf)),
sizeof(buf)) != sizeof(buf)) { sizeof(buf)) != sizeof(buf)) {
printf("write failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
} }
} }
@ -143,27 +144,27 @@ static BOOL rw_torture(struct smbcli_state *c)
pid2 = 0; pid2 = 0;
if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) { if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) {
printf("read failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
} }
if (pid2 != pid) { if (pid2 != pid) {
printf("data corruption!\n"); torture_comment(tctx, "data corruption!\n");
correct = False; correct = False;
} }
if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) { if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
printf("close failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
} }
if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) { if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
printf("unlink failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "unlink failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
} }
if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) { if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
printf("unlock failed (%s)\n", smbcli_errstr(c->tree)); torture_comment(tctx, "unlock failed (%s)\n", smbcli_errstr(c->tree));
correct = False; correct = False;
} }
free(fname); free(fname);
@ -172,55 +173,41 @@ static BOOL rw_torture(struct smbcli_state *c)
smbcli_close(c->tree, fnum2); smbcli_close(c->tree, fnum2);
smbcli_unlink(c->tree, lockfname); smbcli_unlink(c->tree, lockfname);
printf("%d\n", i); torture_comment(tctx, "%d\n", i);
return correct; return correct;
} }
static BOOL run_torture(struct smbcli_state *cli, int dummy) BOOL run_torture(struct torture_context *tctx, struct smbcli_state *cli, int dummy)
{ {
BOOL ret; return rw_torture(tctx, cli);
ret = rw_torture(cli);
if (!torture_close_connection(cli)) {
ret = False;
}
return ret;
} }
/* /*
see how many RPC pipes we can open at once see how many RPC pipes we can open at once
*/ */
static BOOL run_pipe_number(struct torture_context *torture) BOOL run_pipe_number(struct torture_context *tctx,
struct smbcli_state *cli1)
{ {
struct smbcli_state *cli1;
const char *pipe_name = "\\WKSSVC"; const char *pipe_name = "\\WKSSVC";
int fnum; int fnum;
int num_pipes = 0; int num_pipes = 0;
printf("starting pipenumber test\n");
if (!torture_open_connection(&cli1, 0)) {
return False;
}
while(1) { while(1) {
fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0); NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
if (fnum == -1) { if (fnum == -1) {
printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree)); torture_comment(tctx, "Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
break; break;
} }
num_pipes++; num_pipes++;
printf("%d\r", num_pipes); torture_comment(tctx, "%d\r", num_pipes);
fflush(stdout); fflush(stdout);
} }
printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name ); torture_comment(tctx, "pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
torture_close_connection(cli1);
return True; return True;
} }
@ -232,13 +219,13 @@ static BOOL run_pipe_number(struct torture_context *torture)
used for testing performance when there are N idle users used for testing performance when there are N idle users
already connected already connected
*/ */
static BOOL torture_holdcon(struct torture_context *torture) BOOL torture_holdcon(struct torture_context *tctx)
{ {
int i; int i;
struct smbcli_state **cli; struct smbcli_state **cli;
int num_dead = 0; int num_dead = 0;
printf("Opening %d connections\n", torture_numops); torture_comment(tctx, "Opening %d connections\n", torture_numops);
cli = malloc_array_p(struct smbcli_state *, torture_numops); cli = malloc_array_p(struct smbcli_state *, torture_numops);
@ -246,11 +233,11 @@ static BOOL run_pipe_number(struct torture_context *torture)
if (!torture_open_connection(&cli[i], i)) { if (!torture_open_connection(&cli[i], i)) {
return False; return False;
} }
printf("opened %d connections\r", i); torture_comment(tctx, "opened %d connections\r", i);
fflush(stdout); fflush(stdout);
} }
printf("\nStarting pings\n"); torture_comment(tctx, "\nStarting pings\n");
while (1) { while (1) {
for (i=0;i<torture_numops;i++) { for (i=0;i<torture_numops;i++) {
@ -258,7 +245,7 @@ static BOOL run_pipe_number(struct torture_context *torture)
if (cli[i]) { if (cli[i]) {
status = smbcli_chkpath(cli[i]->tree, "\\"); status = smbcli_chkpath(cli[i]->tree, "\\");
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("Connection %d is dead\n", i); torture_comment(tctx, "Connection %d is dead\n", i);
cli[i] = NULL; cli[i] = NULL;
num_dead++; num_dead++;
} }
@ -267,11 +254,11 @@ static BOOL run_pipe_number(struct torture_context *torture)
} }
if (num_dead == torture_numops) { if (num_dead == torture_numops) {
printf("All connections dead - finishing\n"); torture_comment(tctx, "All connections dead - finishing\n");
break; break;
} }
printf("."); torture_comment(tctx, ".");
fflush(stdout); fflush(stdout);
} }
@ -281,7 +268,7 @@ static BOOL run_pipe_number(struct torture_context *torture)
/* /*
test how many open files this server supports on the one socket test how many open files this server supports on the one socket
*/ */
static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy) BOOL run_maxfidtest(struct torture_context *tctx, struct smbcli_state *cli, int dummy)
{ {
#define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d" #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
char *fname; char *fname;
@ -290,28 +277,28 @@ static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
BOOL correct = True; BOOL correct = True;
if (retries <= 0) { if (retries <= 0) {
printf("failed to connect\n"); torture_comment(tctx, "failed to connect\n");
return False; return False;
} }
if (smbcli_deltree(cli->tree, "\\maxfid") == -1) { if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
printf("Failed to deltree \\maxfid - %s\n", torture_comment(tctx, "Failed to deltree \\maxfid - %s\n",
smbcli_errstr(cli->tree)); smbcli_errstr(cli->tree));
return False; return False;
} }
if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) { if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
printf("Failed to mkdir \\maxfid, error=%s\n", torture_comment(tctx, "Failed to mkdir \\maxfid, error=%s\n",
smbcli_errstr(cli->tree)); smbcli_errstr(cli->tree));
return False; return False;
} }
printf("Testing maximum number of open files\n"); torture_comment(tctx, "Testing maximum number of open files\n");
for (i=0; i<0x11000; i++) { for (i=0; i<0x11000; i++) {
if (i % 1000 == 0) { if (i % 1000 == 0) {
asprintf(&fname, "\\maxfid\\fid%d", i/1000); asprintf(&fname, "\\maxfid\\fid%d", i/1000);
if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) { if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
printf("Failed to mkdir %s, error=%s\n", torture_comment(tctx, "Failed to mkdir %s, error=%s\n",
fname, smbcli_errstr(cli->tree)); fname, smbcli_errstr(cli->tree));
return False; return False;
} }
@ -321,27 +308,27 @@ static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
if ((fnums[i] = smbcli_open(cli->tree, fname, if ((fnums[i] = smbcli_open(cli->tree, fname,
O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
-1) { -1) {
printf("open of %s failed (%s)\n", torture_comment(tctx, "open of %s failed (%s)\n",
fname, smbcli_errstr(cli->tree)); fname, smbcli_errstr(cli->tree));
printf("maximum fnum is %d\n", i); torture_comment(tctx, "maximum fnum is %d\n", i);
break; break;
} }
free(fname); free(fname);
printf("%6d\r", i); torture_comment(tctx, "%6d\r", i);
} }
printf("%6d\n", i); torture_comment(tctx, "%6d\n", i);
i--; i--;
maxfid = i; maxfid = i;
printf("cleaning up\n"); torture_comment(tctx, "cleaning up\n");
for (i=0;i<maxfid/2;i++) { for (i=0;i<maxfid/2;i++) {
asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid()); asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) { if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree)); torture_comment(tctx, "Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
} }
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
printf("unlink of %s failed (%s)\n", torture_comment(tctx, "unlink of %s failed (%s)\n",
fname, smbcli_errstr(cli->tree)); fname, smbcli_errstr(cli->tree));
correct = False; correct = False;
} }
@ -349,26 +336,26 @@ static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid()); asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) { if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree)); torture_comment(tctx, "Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
} }
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
printf("unlink of %s failed (%s)\n", torture_comment(tctx, "unlink of %s failed (%s)\n",
fname, smbcli_errstr(cli->tree)); fname, smbcli_errstr(cli->tree));
correct = False; correct = False;
} }
free(fname); free(fname);
printf("%6d %6d\r", i, maxfid-i); torture_comment(tctx, "%6d %6d\r", i, maxfid-i);
} }
printf("%6d\n", 0); torture_comment(tctx, "%6d\n", 0);
if (smbcli_deltree(cli->tree, "\\maxfid") == -1) { if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
printf("Failed to deltree \\maxfid - %s\n", torture_comment(tctx, "Failed to deltree \\maxfid - %s\n",
smbcli_errstr(cli->tree)); smbcli_errstr(cli->tree));
return False; return False;
} }
printf("maxfid test finished\n"); torture_comment(tctx, "maxfid test finished\n");
if (!torture_close_connection(cli)) { if (!torture_close_connection(cli)) {
correct = False; correct = False;
} }
@ -381,9 +368,9 @@ static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
/* /*
sees what IOCTLs are supported sees what IOCTLs are supported
*/ */
static BOOL torture_ioctl_test(struct torture_context *torture) BOOL torture_ioctl_test(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smbcli_state *cli;
uint16_t device, function; uint16_t device, function;
int fnum; int fnum;
const char *fname = "\\ioctl.dat"; const char *fname = "\\ioctl.dat";
@ -391,19 +378,13 @@ static BOOL torture_ioctl_test(struct torture_context *torture)
union smb_ioctl parms; union smb_ioctl parms;
TALLOC_CTX *mem_ctx; TALLOC_CTX *mem_ctx;
if (!torture_open_connection(&cli, 0)) { mem_ctx = talloc_named_const(tctx, 0, "ioctl_test");
return False;
}
mem_ctx = talloc_named_const(torture, 0, "ioctl_test");
printf("starting ioctl test\n");
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum == -1) { if (fnum == -1) {
printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
return False; return False;
} }
@ -411,25 +392,21 @@ static BOOL torture_ioctl_test(struct torture_context *torture)
parms.ioctl.in.file.fnum = fnum; parms.ioctl.in.file.fnum = fnum;
parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO; parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
status = smb_raw_ioctl(cli->tree, mem_ctx, &parms); status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
printf("ioctl job info: %s\n", smbcli_errstr(cli->tree)); torture_comment(tctx, "ioctl job info: %s\n", smbcli_errstr(cli->tree));
for (device=0;device<0x100;device++) { for (device=0;device<0x100;device++) {
printf("testing device=0x%x\n", device); torture_comment(tctx, "testing device=0x%x\n", device);
for (function=0;function<0x100;function++) { for (function=0;function<0x100;function++) {
parms.ioctl.in.request = (device << 16) | function; parms.ioctl.in.request = (device << 16) | function;
status = smb_raw_ioctl(cli->tree, mem_ctx, &parms); status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
if (NT_STATUS_IS_OK(status)) { if (NT_STATUS_IS_OK(status)) {
printf("ioctl device=0x%x function=0x%x OK : %d bytes\n", torture_comment(tctx, "ioctl device=0x%x function=0x%x OK : %d bytes\n",
device, function, (int)parms.ioctl.out.blob.length); device, function, (int)parms.ioctl.out.blob.length);
} }
} }
} }
if (!torture_close_connection(cli)) {
return False;
}
return True; return True;
} }
@ -437,7 +414,7 @@ static BOOL torture_ioctl_test(struct torture_context *torture)
init params using lp_parm_xxx init params using lp_parm_xxx
return number of unclist entries return number of unclist entries
*/ */
int init_benchrw_params(TALLOC_CTX *mem_ctx,struct params *lpar) static int init_benchrw_params(struct torture_context *tctx, struct params *lpar)
{ {
char **unc_list = NULL; char **unc_list = NULL;
int num_unc_names = 0, conn_index=0, empty_lines=0; int num_unc_names = 0, conn_index=0, empty_lines=0;
@ -453,11 +430,11 @@ int init_benchrw_params(TALLOC_CTX *mem_ctx,struct params *lpar)
char *h, *s; char *h, *s;
unc_list = file_lines_load(p, &num_unc_names, NULL); unc_list = file_lines_load(p, &num_unc_names, NULL);
if (!unc_list || num_unc_names <= 0) { if (!unc_list || num_unc_names <= 0) {
printf("Failed to load unc names list from '%s'\n", p); torture_comment(tctx, "Failed to load unc names list from '%s'\n", p);
exit(1); exit(1);
} }
lpar->unc = talloc_array(mem_ctx, struct unclist *, (num_unc_names-empty_lines)); lpar->unc = talloc_array(tctx, struct unclist *, (num_unc_names-empty_lines));
for(conn_index = 0; conn_index < num_unc_names; conn_index++) { for(conn_index = 0; conn_index < num_unc_names; conn_index++) {
/* ignore empty lines */ /* ignore empty lines */
if(strlen(unc_list[conn_index % num_unc_names])==0){ if(strlen(unc_list[conn_index % num_unc_names])==0){
@ -466,18 +443,18 @@ int init_benchrw_params(TALLOC_CTX *mem_ctx,struct params *lpar)
} }
if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names], if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
NULL, &h, &s)) { NULL, &h, &s)) {
printf("Failed to parse UNC name %s\n", torture_comment(tctx, "Failed to parse UNC name %s\n",
unc_list[conn_index % num_unc_names]); unc_list[conn_index % num_unc_names]);
exit(1); exit(1);
} }
lpar->unc[conn_index-empty_lines] = talloc(mem_ctx,struct unclist); lpar->unc[conn_index-empty_lines] = talloc(tctx,struct unclist);
lpar->unc[conn_index-empty_lines]->host = h; lpar->unc[conn_index-empty_lines]->host = h;
lpar->unc[conn_index-empty_lines]->share = s; lpar->unc[conn_index-empty_lines]->share = s;
} }
return num_unc_names-empty_lines; return num_unc_names-empty_lines;
}else{ }else{
lpar->unc = talloc_array(mem_ctx, struct unclist *, 1); lpar->unc = talloc_array(tctx, struct unclist *, 1);
lpar->unc[0] = talloc(mem_ctx,struct unclist); lpar->unc[0] = talloc(tctx,struct unclist);
lpar->unc[0]->host = lp_parm_string(-1, "torture", "host"); lpar->unc[0]->host = lp_parm_string(-1, "torture", "host");
lpar->unc[0]->share = lp_parm_string(-1, "torture", "share"); lpar->unc[0]->share = lp_parm_string(-1, "torture", "share");
return 1; return 1;
@ -487,14 +464,14 @@ int init_benchrw_params(TALLOC_CTX *mem_ctx,struct params *lpar)
/* /*
Called when the reads & writes are finished. closes the file. Called when the reads & writes are finished. closes the file.
*/ */
NTSTATUS benchrw_close(struct smbcli_request *req, static NTSTATUS benchrw_close(struct torture_context *tctx,struct smbcli_request *req,
struct benchrw_state *state) struct benchrw_state *state)
{ {
union smb_close close_parms; union smb_close close_parms;
NT_STATUS_NOT_OK_RETURN(req->status); NT_STATUS_NOT_OK_RETURN(req->status);
printf("Close file %d (%d)\n",state->nr,state->fnum); torture_comment(tctx, "Close file %d (%d)\n",state->nr,state->fnum);
close_parms.close.level = RAW_CLOSE_CLOSE; close_parms.close.level = RAW_CLOSE_CLOSE;
close_parms.close.in.file.fnum = state->fnum ; close_parms.close.in.file.fnum = state->fnum ;
close_parms.close.in.write_time = 0; close_parms.close.in.write_time = 0;
@ -512,7 +489,7 @@ NTSTATUS benchrw_close(struct smbcli_request *req,
/* /*
Called when the initial write is completed is done. write or read a file. Called when the initial write is completed is done. write or read a file.
*/ */
NTSTATUS benchrw_readwrite(struct smbcli_request *req, static NTSTATUS benchrw_readwrite(struct torture_context *tctx,struct smbcli_request *req,
struct benchrw_state *state) struct benchrw_state *state)
{ {
union smb_read rd; union smb_read rd;
@ -523,7 +500,7 @@ NTSTATUS benchrw_readwrite(struct smbcli_request *req,
state->completed++; state->completed++;
/*rotate between writes and reads*/ /*rotate between writes and reads*/
if( state->completed % state->lp_params->writeratio == 0){ if( state->completed % state->lp_params->writeratio == 0){
printf("Callback WRITE file:%d (%d/%d)\n", torture_comment(tctx, "Callback WRITE file:%d (%d/%d)\n",
state->nr,state->completed,torture_numops); state->nr,state->completed,torture_numops);
wr.generic.level = RAW_WRITE_WRITEX ; wr.generic.level = RAW_WRITE_WRITEX ;
wr.writex.in.file.fnum = state->fnum ; wr.writex.in.file.fnum = state->fnum ;
@ -535,7 +512,7 @@ NTSTATUS benchrw_readwrite(struct smbcli_request *req,
state->readcnt=0; state->readcnt=0;
req = smb_raw_write_send(state->cli,&wr); req = smb_raw_write_send(state->cli,&wr);
}else{ }else{
printf("Callback READ file:%d (%d/%d) Offset:%d\n", torture_comment(tctx, "Callback READ file:%d (%d/%d) Offset:%d\n",
state->nr,state->completed,torture_numops, state->nr,state->completed,torture_numops,
(state->readcnt*state->lp_params->blocksize)); (state->readcnt*state->lp_params->blocksize));
rd.generic.level = RAW_READ_READ ; rd.generic.level = RAW_READ_READ ;
@ -564,7 +541,7 @@ NTSTATUS benchrw_readwrite(struct smbcli_request *req,
/* /*
Called when the open is done. writes to the file. Called when the open is done. writes to the file.
*/ */
NTSTATUS benchrw_open(struct smbcli_request *req, static NTSTATUS benchrw_open(struct torture_context *tctx,struct smbcli_request *req,
struct benchrw_state *state) struct benchrw_state *state)
{ {
union smb_write wr; union smb_write wr;
@ -576,11 +553,11 @@ NTSTATUS benchrw_open(struct smbcli_request *req,
state->fnum = ((union smb_open*)state->req_params) state->fnum = ((union smb_open*)state->req_params)
->openx.out.file.fnum; ->openx.out.file.fnum;
printf("File opened (%d)\n",state->fnum); torture_comment(tctx, "File opened (%d)\n",state->fnum);
state->mode=INITIAL_WRITE; state->mode=INITIAL_WRITE;
} }
printf("Write initial test file:%d (%d/%d)\n",state->nr, torture_comment(tctx, "Write initial test file:%d (%d/%d)\n",state->nr,
(state->writecnt+1)*state->lp_params->blocksize, (state->writecnt+1)*state->lp_params->blocksize,
(state->lp_params->writeblocks*state->lp_params->blocksize)); (state->lp_params->writeblocks*state->lp_params->blocksize));
wr.generic.level = RAW_WRITE_WRITEX ; wr.generic.level = RAW_WRITE_WRITEX ;
@ -610,7 +587,7 @@ NTSTATUS benchrw_open(struct smbcli_request *req,
/* /*
Called when the mkdir is done. Opens a file. Called when the mkdir is done. Opens a file.
*/ */
NTSTATUS benchrw_mkdir(struct smbcli_request *req, static NTSTATUS benchrw_mkdir(struct torture_context *tctx,struct smbcli_request *req,
struct benchrw_state *state) struct benchrw_state *state)
{ {
union smb_open *open_parms; union smb_open *open_parms;
@ -619,7 +596,7 @@ NTSTATUS benchrw_mkdir(struct smbcli_request *req,
NT_STATUS_NOT_OK_RETURN(req->status); NT_STATUS_NOT_OK_RETURN(req->status);
/* open/create the files */ /* open/create the files */
printf("Open File %d/%d\n",state->nr+1,torture_nprocs); torture_comment(tctx, "Open File %d/%d\n",state->nr+1,torture_nprocs);
open_parms=talloc_zero(state->mem_ctx, union smb_open); open_parms=talloc_zero(state->mem_ctx, union smb_open);
NT_STATUS_HAVE_NO_MEMORY(open_parms); NT_STATUS_HAVE_NO_MEMORY(open_parms);
open_parms->openx.level = RAW_OPEN_OPENX; open_parms->openx.level = RAW_OPEN_OPENX;
@ -656,9 +633,10 @@ NTSTATUS benchrw_mkdir(struct smbcli_request *req,
/* /*
handler for completion of a sub-request of the bench-rw test handler for completion of a sub-request of the bench-rw test
*/ */
void benchrw_callback(struct smbcli_request *req) static void benchrw_callback(struct smbcli_request *req)
{ {
struct benchrw_state *state = req->async.private; struct benchrw_state *state = req->async.private;
struct torture_context *tctx = state->tctx;
/*dont send new requests when torture_numops is reached*/ /*dont send new requests when torture_numops is reached*/
if(state->completed >= torture_numops){ if(state->completed >= torture_numops){
@ -669,8 +647,8 @@ void benchrw_callback(struct smbcli_request *req)
switch (state->mode) { switch (state->mode) {
case MK_TESTDIR: case MK_TESTDIR:
if (!NT_STATUS_IS_OK(benchrw_mkdir(req,state))) { if (!NT_STATUS_IS_OK(benchrw_mkdir(tctx, req,state))) {
printf("Failed to create the test directory - %s\n", torture_comment(tctx, "Failed to create the test directory - %s\n",
nt_errstr(req->status)); nt_errstr(req->status));
state->mode=ERROR; state->mode=ERROR;
return; return;
@ -678,33 +656,33 @@ void benchrw_callback(struct smbcli_request *req)
break; break;
case OPEN_FILE: case OPEN_FILE:
case INITIAL_WRITE: case INITIAL_WRITE:
if (!NT_STATUS_IS_OK(benchrw_open(req,state))){ if (!NT_STATUS_IS_OK(benchrw_open(tctx, req,state))){
printf("Failed to open/write the file - %s\n", torture_comment(tctx, "Failed to open/write the file - %s\n",
nt_errstr(req->status)); nt_errstr(req->status));
state->mode=ERROR; state->mode=ERROR;
return; return;
} }
break; break;
case READ_WRITE_DATA: case READ_WRITE_DATA:
if (!NT_STATUS_IS_OK(benchrw_readwrite(req,state))){ if (!NT_STATUS_IS_OK(benchrw_readwrite(tctx,req,state))){
printf("Failed to read/write the file - %s\n", torture_comment(tctx, "Failed to read/write the file - %s\n",
nt_errstr(req->status)); nt_errstr(req->status));
state->mode=ERROR; state->mode=ERROR;
return; return;
} }
break; break;
case MAX_OPS_REACHED: case MAX_OPS_REACHED:
if (!NT_STATUS_IS_OK(benchrw_close(req,state))){ if (!NT_STATUS_IS_OK(benchrw_close(tctx,req,state))){
printf("Failed to read/write/close the file - %s\n", torture_comment(tctx, "Failed to read/write/close the file - %s\n",
nt_errstr(req->status)); nt_errstr(req->status));
state->mode=ERROR; state->mode=ERROR;
return; return;
} }
break; break;
case CLOSE_FILE: case CLOSE_FILE:
printf("File %d closed\n",state->nr); torture_comment(tctx, "File %d closed\n",state->nr);
if (!NT_STATUS_IS_OK(req->status)) { if (!NT_STATUS_IS_OK(req->status)) {
printf("Failed to close the file - %s\n", torture_comment(tctx, "Failed to close the file - %s\n",
nt_errstr(req->status)); nt_errstr(req->status));
state->mode=ERROR; state->mode=ERROR;
return; return;
@ -718,9 +696,10 @@ void benchrw_callback(struct smbcli_request *req)
} }
/* open connection async callback function*/ /* open connection async callback function*/
void async_open_callback(struct composite_context *con) static void async_open_callback(struct composite_context *con)
{ {
struct benchrw_state *state = con->async.private_data; struct benchrw_state *state = con->async.private_data;
struct torture_context *tctx = state->tctx;
int retry = state->lp_params->retry; int retry = state->lp_params->retry;
if (NT_STATUS_IS_OK(con->status)) { if (NT_STATUS_IS_OK(con->status)) {
@ -729,13 +708,13 @@ void async_open_callback(struct composite_context *con)
state->mode=CLEANUP_TESTDIR; state->mode=CLEANUP_TESTDIR;
}else{ }else{
if(state->writecnt < retry){ if(state->writecnt < retry){
printf("Failed to open connection:%d, Retry (%d/%d)\n", torture_comment(tctx, "Failed to open connection:%d, Retry (%d/%d)\n",
state->nr,state->writecnt,retry); state->nr,state->writecnt,retry);
state->writecnt++; state->writecnt++;
state->mode=START; state->mode=START;
usleep(1000); usleep(1000);
}else{ }else{
printf("Failed to open connection (%d) - %s\n", torture_comment(tctx, "Failed to open connection (%d) - %s\n",
state->nr, nt_errstr(con->status)); state->nr, nt_errstr(con->status));
state->mode=ERROR; state->mode=ERROR;
} }
@ -746,7 +725,8 @@ void async_open_callback(struct composite_context *con)
/* /*
establishs a smbcli_tree from scratch (async) establishs a smbcli_tree from scratch (async)
*/ */
struct composite_context *torture_connect_async( static struct composite_context *torture_connect_async(
struct torture_context *tctx,
struct smb_composite_connect *smb, struct smb_composite_connect *smb,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
struct event_context *ev, struct event_context *ev,
@ -754,7 +734,7 @@ struct composite_context *torture_connect_async(
const char *share, const char *share,
const char *workgroup) const char *workgroup)
{ {
printf("Open Connection to %s/%s\n",host,share); torture_comment(tctx, "Open Connection to %s/%s\n",host,share);
smb->in.dest_host=talloc_strdup(mem_ctx,host); smb->in.dest_host=talloc_strdup(mem_ctx,host);
smb->in.service=talloc_strdup(mem_ctx,share); smb->in.service=talloc_strdup(mem_ctx,share);
smb->in.port=0; smb->in.port=0;
@ -767,14 +747,13 @@ struct composite_context *torture_connect_async(
return smb_composite_connect_send(smb,mem_ctx,ev); return smb_composite_connect_send(smb,mem_ctx,ev);
} }
static BOOL run_benchrw(struct torture_context *torture) BOOL run_benchrw(struct torture_context *tctx)
{ {
struct smb_composite_connect *smb_con; struct smb_composite_connect *smb_con;
const char *fname = "\\rwtest.dat"; const char *fname = "\\rwtest.dat";
struct smbcli_request *req; struct smbcli_request *req;
struct benchrw_state **state; struct benchrw_state **state;
int i , num_unc_names; int i , num_unc_names;
TALLOC_CTX *mem_ctx;
struct event_context *ev ; struct event_context *ev ;
struct composite_context *req1; struct composite_context *req1;
struct params lpparams; struct params lpparams;
@ -782,42 +761,42 @@ static BOOL run_benchrw(struct torture_context *torture)
int finished = 0; int finished = 0;
BOOL success=True; BOOL success=True;
printf("Start BENCH-READWRITE num_ops=%d num_nprocs=%d\n", torture_comment(tctx, "Start BENCH-READWRITE num_ops=%d num_nprocs=%d\n",
torture_numops,torture_nprocs); torture_numops,torture_nprocs);
/*init talloc context*/ /*init talloc context*/
mem_ctx = talloc_named_const(torture, 0, "bench-readwrite"); ev = event_context_init(tctx);
ev = event_context_init(mem_ctx); state = talloc_array(tctx, struct benchrw_state *, torture_nprocs);
state = talloc_array(mem_ctx, struct benchrw_state *, torture_nprocs);
/* init params using lp_parm_xxx */ /* init params using lp_parm_xxx */
num_unc_names = init_benchrw_params(mem_ctx,&lpparams); num_unc_names = init_benchrw_params(tctx,&lpparams);
/* init private data structs*/ /* init private data structs*/
for(i = 0; i<torture_nprocs;i++){ for(i = 0; i<torture_nprocs;i++){
state[i]=talloc(mem_ctx,struct benchrw_state); state[i]=talloc(tctx,struct benchrw_state);
state[i]->tctx = tctx;
state[i]->completed=0; state[i]->completed=0;
state[i]->lp_params=&lpparams; state[i]->lp_params=&lpparams;
state[i]->nr=i; state[i]->nr=i;
state[i]->dname=talloc_asprintf(mem_ctx,"benchrw%d",i); state[i]->dname=talloc_asprintf(tctx,"benchrw%d",i);
state[i]->fname=talloc_asprintf(mem_ctx,"%s%s", state[i]->fname=talloc_asprintf(tctx,"%s%s",
state[i]->dname,fname); state[i]->dname,fname);
state[i]->mode=START; state[i]->mode=START;
state[i]->writecnt=0; state[i]->writecnt=0;
} }
printf("Starting async requests\n"); torture_comment(tctx, "Starting async requests\n");
while(finished != torture_nprocs){ while(finished != torture_nprocs){
finished=0; finished=0;
for(i = 0; i<torture_nprocs;i++){ for(i = 0; i<torture_nprocs;i++){
switch (state[i]->mode){ switch (state[i]->mode){
/*open multiple connections with the same userid */ /*open multiple connections with the same userid */
case START: case START:
smb_con = talloc(mem_ctx,struct smb_composite_connect) ; smb_con = talloc(tctx,struct smb_composite_connect) ;
state[i]->req_params=smb_con; state[i]->req_params=smb_con;
state[i]->mode=OPEN_CONNECTION; state[i]->mode=OPEN_CONNECTION;
req1 = torture_connect_async(smb_con, req1 = torture_connect_async(tctx, smb_con,
mem_ctx,ev, tctx,ev,
lpparams.unc[i % num_unc_names]->host, lpparams.unc[i % num_unc_names]->host,
lpparams.unc[i % num_unc_names]->share, lpparams.unc[i % num_unc_names]->share,
lpparams.workgroup); lpparams.workgroup);
@ -827,11 +806,11 @@ static BOOL run_benchrw(struct torture_context *torture)
break; break;
/*setup test dirs (sync)*/ /*setup test dirs (sync)*/
case CLEANUP_TESTDIR: case CLEANUP_TESTDIR:
printf("Setup test dir %d\n",i); torture_comment(tctx, "Setup test dir %d\n",i);
smb_raw_exit(state[i]->cli->session); smb_raw_exit(state[i]->cli->session);
if (smbcli_deltree(state[i]->cli, if (smbcli_deltree(state[i]->cli,
state[i]->dname) == -1) { state[i]->dname) == -1) {
printf("Unable to delete %s - %s\n", torture_comment(tctx, "Unable to delete %s - %s\n",
state[i]->dname, state[i]->dname,
smbcli_errstr(state[i]->cli)); smbcli_errstr(state[i]->cli));
state[i]->mode=ERROR; state[i]->mode=ERROR;
@ -852,12 +831,12 @@ static BOOL run_benchrw(struct torture_context *torture)
break; break;
/* cleanup , close connection */ /* cleanup , close connection */
case CLEANUP: case CLEANUP:
printf("Deleting test dir %s %d/%d\n",state[i]->dname, torture_comment(tctx, "Deleting test dir %s %d/%d\n",state[i]->dname,
i+1,torture_nprocs); i+1,torture_nprocs);
smbcli_deltree(state[i]->cli,state[i]->dname); smbcli_deltree(state[i]->cli,state[i]->dname);
if (NT_STATUS_IS_ERR(smb_tree_disconnect( if (NT_STATUS_IS_ERR(smb_tree_disconnect(
state[i]->cli))) { state[i]->cli))) {
printf("ERROR: Tree disconnect failed"); torture_comment(tctx, "ERROR: Tree disconnect failed");
state[i]->mode=ERROR; state[i]->mode=ERROR;
break; break;
} }
@ -871,23 +850,6 @@ static BOOL run_benchrw(struct torture_context *torture)
} }
} }
printf("BENCH-READWRITE done. Closing connections.\n");
/*free all allocated memory*/
talloc_free(mem_ctx);
return success; return success;
} }
NTSTATUS torture_misc_init(void)
{
register_torture_op("BENCH-HOLDCON", torture_holdcon);
register_torture_op("SCAN-PIPE_NUMBER", run_pipe_number);
register_torture_op("SCAN-IOCTL", torture_ioctl_test);
register_torture_op("BENCH-READWRITE", run_benchrw);
register_torture_multi_op("BENCH-TORTURE", run_torture);
register_torture_multi_op("SCAN-MAXFID", run_maxfidtest);
return NT_STATUS_OK;
}

View File

@ -89,21 +89,13 @@ static void show_bits(const struct bitmapping *bm, uint32_t value)
/* /*
print out server properties print out server properties
*/ */
BOOL torture_test_properties(struct torture_context *torture) BOOL torture_test_properties(struct torture_context *torture,
struct smbcli_state *cli)
{ {
struct smbcli_state *cli;
BOOL correct = True; BOOL correct = True;
union smb_fsinfo fs; union smb_fsinfo fs;
NTSTATUS status; NTSTATUS status;
printf("starting properties test\n");
ZERO_STRUCT(cli);
if (!torture_open_connection(&cli, 0)) {
return False;
}
d_printf("Capabilities: 0x%08x\n", cli->transport->negotiate.capabilities); d_printf("Capabilities: 0x%08x\n", cli->transport->negotiate.capabilities);
show_bits(capability_bits, cli->transport->negotiate.capabilities); show_bits(capability_bits, cli->transport->negotiate.capabilities);
d_printf("\n"); d_printf("\n");
@ -122,10 +114,6 @@ BOOL torture_test_properties(struct torture_context *torture)
d_printf("fstype: %s\n", fs.attribute_info.out.fs_type.s); d_printf("fstype: %s\n", fs.attribute_info.out.fs_type.s);
} }
if (!torture_close_connection(cli)) {
correct = False;
}
return correct; return correct;
} }

View File

@ -28,20 +28,13 @@
/* /*
Test rename on files open with share delete and no share delete. Test rename on files open with share delete and no share delete.
*/ */
BOOL torture_test_rename(struct torture_context *torture) BOOL torture_test_rename(struct torture_context *tctx,
struct smbcli_state *cli1)
{ {
struct smbcli_state *cli1;
const char *fname = "\\test.txt"; const char *fname = "\\test.txt";
const char *fname1 = "\\test1.txt"; const char *fname1 = "\\test1.txt";
BOOL correct = True;
int fnum1; int fnum1;
printf("starting rename test\n");
if (!torture_open_connection(&cli1, 0)) {
return False;
}
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
smbcli_unlink(cli1->tree, fname1); smbcli_unlink(cli1->tree, fname1);
fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
@ -50,24 +43,14 @@ BOOL torture_test_rename(struct torture_context *torture)
NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_SHARE_ACCESS_READ,
NTCREATEX_DISP_OVERWRITE_IF, 0, 0); NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
if (fnum1 == -1) { torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "First open failed - %s",
printf("(%s) First open failed - %s\n", smbcli_errstr(cli1->tree)));
__location__, smbcli_errstr(cli1->tree));
return False;
}
if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) { torture_assert(tctx, NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1)),
printf("First rename failed (this is correct) - %s\n", smbcli_errstr(cli1->tree)); "First rename succeeded - this should have failed !");
} else {
printf("(%s) First rename succeeded - this should have failed !\n",
__location__);
correct = False;
}
if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
printf("(%s) close - 1 failed (%s)\n", __location__, smbcli_errstr(cli1->tree)); talloc_asprintf(tctx, "close - 1 failed (%s)", smbcli_errstr(cli1->tree)));
return False;
}
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
smbcli_unlink(cli1->tree, fname1); smbcli_unlink(cli1->tree, fname1);
@ -77,24 +60,17 @@ BOOL torture_test_rename(struct torture_context *torture)
NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ,
NTCREATEX_DISP_OVERWRITE_IF, 0, 0); NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
if (fnum1 == -1) { torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx,
printf("(%s) Second open failed - %s\n", __location__, smbcli_errstr(cli1->tree)); "Second open failed - %s", smbcli_errstr(cli1->tree)));
return False;
}
if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) { torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1),
printf("(%s) Second rename failed - this should have succeeded - %s\n", talloc_asprintf(tctx,
__location__, smbcli_errstr(cli1->tree)); "Second rename failed - this should have succeeded - %s",
correct = False; smbcli_errstr(cli1->tree)));
} else {
printf("Second rename succeeded\n");
}
if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
printf("(%s) close - 2 failed (%s)\n", talloc_asprintf(tctx,
__location__, smbcli_errstr(cli1->tree)); "close - 2 failed (%s)", smbcli_errstr(cli1->tree)));
return False;
}
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
smbcli_unlink(cli1->tree, fname1); smbcli_unlink(cli1->tree, fname1);
@ -105,33 +81,19 @@ BOOL torture_test_rename(struct torture_context *torture)
NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_SHARE_ACCESS_NONE,
NTCREATEX_DISP_OVERWRITE_IF, 0, 0); NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
if (fnum1 == -1) { torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "Third open failed - %s",
printf("(%s) Third open failed - %s\n", __location__, smbcli_errstr(cli1->tree)); smbcli_errstr(cli1->tree)));
return False;
}
torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1),
talloc_asprintf(tctx, "Third rename failed - this should have succeeded - %s",
smbcli_errstr(cli1->tree)));
if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) { torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
printf("(%s) Third rename failed - this should have succeeded - %s\n", talloc_asprintf(tctx, "close - 3 failed (%s)", smbcli_errstr(cli1->tree)));
__location__, smbcli_errstr(cli1->tree));
correct = False;
} else {
printf("Third rename succeeded\n");
}
if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
printf("(%s) close - 3 failed (%s)\n",
__location__, smbcli_errstr(cli1->tree));
return False;
}
smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname);
smbcli_unlink(cli1->tree, fname1); smbcli_unlink(cli1->tree, fname1);
if (!torture_close_connection(cli1)) { return true;
correct = False;
}
return correct;
} }

View File

@ -242,19 +242,13 @@ static BOOL scan_trans2(struct smbcli_state *cli, int op, int level,
} }
BOOL torture_trans2_scan(struct torture_context *torture) BOOL torture_trans2_scan(struct torture_context *torture,
struct smbcli_state *cli)
{ {
static struct smbcli_state *cli;
int op, level; int op, level;
const char *fname = "\\scanner.dat"; const char *fname = "\\scanner.dat";
int fnum, dnum, qfnum; int fnum, dnum, qfnum;
printf("starting trans2 scan test\n");
if (!torture_open_connection(&cli, 0)) {
return False;
}
fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
if (fnum == -1) { if (fnum == -1) {
printf("file open failed - %s\n", smbcli_errstr(cli->tree)); printf("file open failed - %s\n", smbcli_errstr(cli->tree));
@ -299,9 +293,6 @@ BOOL torture_trans2_scan(struct torture_context *torture)
} }
} }
torture_close_connection(cli);
printf("trans2 scan finished\n");
return True; return True;
} }
@ -483,19 +474,13 @@ static BOOL scan_nttrans(struct smbcli_state *cli, int op, int level,
} }
BOOL torture_nttrans_scan(struct torture_context *torture) BOOL torture_nttrans_scan(struct torture_context *torture,
struct smbcli_state *cli)
{ {
static struct smbcli_state *cli;
int op, level; int op, level;
const char *fname = "\\scanner.dat"; const char *fname = "\\scanner.dat";
int fnum, dnum; int fnum, dnum;
printf("starting nttrans scan test\n");
if (!torture_open_connection(&cli, 0)) {
return False;
}
fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC,
DENY_NONE); DENY_NONE);
dnum = smbcli_open(cli->tree, "\\", O_RDONLY, DENY_NONE); dnum = smbcli_open(cli->tree, "\\", O_RDONLY, DENY_NONE);

View File

@ -56,15 +56,10 @@ static BOOL try_failed_login(struct smbcli_state *cli)
return True; return True;
} }
BOOL torture_sec_leak(struct torture_context *torture) BOOL torture_sec_leak(struct torture_context *tctx, struct smbcli_state *cli)
{ {
struct smbcli_state *cli;
time_t t1 = time(NULL); time_t t1 = time(NULL);
int timelimit = lp_parm_int(-1, "torture", "timelimit", 20); int timelimit = torture_setting_int(tctx, "timelimit", 20);
if (!torture_open_connection(&cli, 0)) {
return False;
}
while (time(NULL) < t1+timelimit) { while (time(NULL) < t1+timelimit) {
if (!try_failed_login(cli)) { if (!try_failed_login(cli)) {

View File

@ -34,49 +34,36 @@
1) the server does not allow an unlink on a file that is open 1) the server does not allow an unlink on a file that is open
*/ */
BOOL torture_unlinktest(struct torture_context *torture) BOOL torture_unlinktest(struct torture_context *tctx, struct smbcli_state *cli)
{ {
struct smbcli_state *cli;
const char *fname = BASEDIR "\\unlink.tst"; const char *fname = BASEDIR "\\unlink.tst";
int fnum; int fnum;
BOOL correct = True; BOOL correct = True;
union smb_open io; union smb_open io;
NTSTATUS status; NTSTATUS status;
if (!torture_open_connection(&cli, 0)) { torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
return False; talloc_asprintf(tctx, "Failed setting up %s", BASEDIR));
}
printf("starting unlink test\n");
if (!torture_setup_dir(cli, BASEDIR)) {
return False;
}
cli->session->pid = 1; cli->session->pid = 1;
printf("Opening a file\n"); torture_comment(tctx, "Opening a file\n");
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum == -1) { torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, "open of %s failed (%s)", fname, smbcli_errstr(cli->tree)));
printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
return False;
}
printf("Unlinking a open file\n"); torture_comment(tctx, "Unlinking a open file\n");
if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) { torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname)),
printf("(%s) error: server allowed unlink on an open file\n", __location__); "server allowed unlink on an open file");
correct = False;
} else { correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
NT_STATUS_SHARING_VIOLATION); NT_STATUS_SHARING_VIOLATION);
}
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
printf("testing unlink after ntcreatex with DELETE access\n"); torture_comment(tctx, "testing unlink after ntcreatex with DELETE access\n");
io.ntcreatex.level = RAW_OPEN_NTCREATEX; io.ntcreatex.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.root_fid = 0; io.ntcreatex.in.root_fid = 0;
@ -92,23 +79,14 @@ BOOL torture_unlinktest(struct torture_context *torture)
io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
status = smb_raw_open(cli->tree, cli, &io); status = smb_raw_open(cli->tree, cli, &io);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "failed to open %s", fname));
printf("(%s) failed to open %s\n", __location__, fname);
} torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname)),
if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) { "server allowed unlink on an open file");
printf("(%s) error: server allowed unlink on an open file\n", __location__);
correct = False; correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
} else {
correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
NT_STATUS_SHARING_VIOLATION); NT_STATUS_SHARING_VIOLATION);
}
if (!torture_close_connection(cli)) {
correct = False;
}
printf("unlink test finished\n");
return correct; return correct;
} }

View File

@ -26,9 +26,9 @@
#include "torture/util.h" #include "torture/util.h"
#include "pstring.h" #include "pstring.h"
BOOL torture_utable(struct torture_context *torture) bool torture_utable(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
struct smbcli_state *cli;
fstring fname; fstring fname;
const char *alt_name; const char *alt_name;
int fnum; int fnum;
@ -37,19 +37,12 @@ BOOL torture_utable(struct torture_context *torture)
int chars_allowed=0, alt_allowed=0; int chars_allowed=0, alt_allowed=0;
uint8_t valid[0x10000]; uint8_t valid[0x10000];
printf("starting utable\n"); torture_comment(tctx, "Generating valid character table\n");
printf("Generating valid character table\n");
if (!torture_open_connection(&cli, 0)) {
return False;
}
memset(valid, 0, sizeof(valid)); memset(valid, 0, sizeof(valid));
if (!torture_setup_dir(cli, "\\utable")) { torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
return False; "Setting up dir \\utable failed");
}
for (c=1; c < 0x10000; c++) { for (c=1; c < 0x10000; c++) {
char *p; char *p;
@ -74,32 +67,31 @@ BOOL torture_utable(struct torture_context *torture)
if (strncmp(alt_name, "X_A_L", 5) != 0) { if (strncmp(alt_name, "X_A_L", 5) != 0) {
alt_allowed++; alt_allowed++;
valid[c] = 1; valid[c] = 1;
d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); torture_comment(tctx, "fname=[%s] alt_name=[%s]\n", fname, alt_name);
} }
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
if (c % 100 == 0) { if (c % 100 == 0) {
printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed); torture_comment(tctx, "%d (%d/%d)\r", c, chars_allowed, alt_allowed);
} }
} }
printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed); torture_comment(tctx, "%d (%d/%d)\n", c, chars_allowed, alt_allowed);
smbcli_rmdir(cli->tree, "\\utable"); smbcli_rmdir(cli->tree, "\\utable");
d_printf("%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); torture_comment(tctx, "%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed);
fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644); fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (fd == -1) { torture_assert(tctx, fd != -1,
d_printf("Failed to create valid.dat - %s", strerror(errno)); talloc_asprintf(tctx,
return False; "Failed to create valid.dat - %s", strerror(errno)));
}
write(fd, valid, 0x10000); write(fd, valid, 0x10000);
close(fd); close(fd);
d_printf("wrote valid.dat\n"); torture_comment(tctx, "wrote valid.dat\n");
return True; return true;
} }
@ -121,34 +113,28 @@ static char *form_name(int c)
return fname; return fname;
} }
BOOL torture_casetable(struct torture_context *torture) bool torture_casetable(struct torture_context *tctx,
struct smbcli_state *cli)
{ {
static struct smbcli_state *cli;
char *fname; char *fname;
int fnum; int fnum;
int c, i; int c, i;
#define MAX_EQUIVALENCE 8 #define MAX_EQUIVALENCE 8
codepoint_t equiv[0x10000][MAX_EQUIVALENCE]; codepoint_t equiv[0x10000][MAX_EQUIVALENCE];
printf("starting casetable\n");
if (!torture_open_connection(&cli, 0)) { torture_comment(tctx, "Determining upper/lower case table\n");
return False;
}
printf("Determining upper/lower case table\n");
memset(equiv, 0, sizeof(equiv)); memset(equiv, 0, sizeof(equiv));
if (!torture_setup_dir(cli, "\\utable")) { torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
return False; "Error setting up dir \\utable");
}
for (c=1; c < 0x10000; c++) { for (c=1; c < 0x10000; c++) {
size_t size; size_t size;
if (c == '.' || c == '\\') continue; if (c == '.' || c == '\\') continue;
d_printf("%04x (%c)\n", c, isprint(c)?c:'.'); torture_comment(tctx, "%04x (%c)\n", c, isprint(c)?c:'.');
fname = form_name(c); fname = form_name(c);
fnum = smbcli_nt_create_full(cli->tree, fname, 0, fnum = smbcli_nt_create_full(cli->tree, fname, 0,
@ -161,10 +147,9 @@ BOOL torture_casetable(struct torture_context *torture)
NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_SHARE_ACCESS_NONE,
NTCREATEX_DISP_OPEN_IF, 0, 0); NTCREATEX_DISP_OPEN_IF, 0, 0);
if (fnum == -1) { torture_assert(tctx, fnum != -1,
printf("Failed to create file with char %04x\n", c); talloc_asprintf(tctx,
continue; "Failed to create file with char %04x\n", c));
}
size = 0; size = 0;
@ -176,21 +161,20 @@ BOOL torture_casetable(struct torture_context *torture)
int c2[MAX_EQUIVALENCE]; int c2[MAX_EQUIVALENCE];
if (size/sizeof(int) >= MAX_EQUIVALENCE) { if (size/sizeof(int) >= MAX_EQUIVALENCE) {
printf("too many chars match?? size=%d c=0x%04x\n", torture_comment(tctx, "too many chars match?? size=%d c=0x%04x\n",
(int)size, c); (int)size, c);
smbcli_close(cli->tree, fnum); smbcli_close(cli->tree, fnum);
return False; return False;
} }
smbcli_read(cli->tree, fnum, c2, 0, size); smbcli_read(cli->tree, fnum, c2, 0, size);
printf("%04x: ", c); torture_comment(tctx, "%04x: ", c);
equiv[c][0] = c; equiv[c][0] = c;
for (i=0; i<size/sizeof(int); i++) { for (i=0; i<size/sizeof(int); i++) {
printf("%04x ", c2[i]); torture_comment(tctx, "%04x ", c2[i]);
equiv[c][i+1] = c2[i]; equiv[c][i+1] = c2[i];
} }
printf("\n"); torture_comment(tctx, "\n");
fflush(stdout);
} }
smbcli_write(cli->tree, fnum, 0, &c, size, sizeof(c)); smbcli_write(cli->tree, fnum, 0, &c, size, sizeof(c));
@ -200,5 +184,5 @@ BOOL torture_casetable(struct torture_context *torture)
smbcli_unlink(cli->tree, "\\utable\\*"); smbcli_unlink(cli->tree, "\\utable\\*");
smbcli_rmdir(cli->tree, "\\utable"); smbcli_rmdir(cli->tree, "\\utable");
return True; return true;
} }

View File

@ -30,6 +30,7 @@ PRIVATE_PROTO_HEADER = \
basic/proto.h basic/proto.h
OBJ_FILES = \ OBJ_FILES = \
basic/base.o \ basic/base.o \
basic/misc.o \
basic/scanner.o \ basic/scanner.o \
basic/utable.o \ basic/utable.o \
basic/charset.o \ basic/charset.o \
@ -94,11 +95,6 @@ PUBLIC_DEPENDENCIES = \
include smb2/config.mk include smb2/config.mk
[MODULE::torture_misc]
SUBSYSTEM = torture
INIT_FUNCTION = torture_misc_init
OBJ_FILES = misc.o
[MODULE::torture_rpc] [MODULE::torture_rpc]
# TORTURE_NET and TORTURE_NBT use functions from torture_rpc... # TORTURE_NET and TORTURE_NBT use functions from torture_rpc...
#OUTPUT_TYPE = INTEGRATED #OUTPUT_TYPE = INTEGRATED
@ -232,7 +228,6 @@ OBJ_FILES = \
nbt/winsbench.o \ nbt/winsbench.o \
nbt/winsreplication.o \ nbt/winsreplication.o \
nbt/dgram.o \ nbt/dgram.o \
nbt/browse.o \
nbt/nbt.o nbt/nbt.o
PUBLIC_DEPENDENCIES = \ PUBLIC_DEPENDENCIES = \
LIBCLI_SMB LIBCLI_NBT LIBCLI_DGRAM LIBCLI_WREPL LIBCLI_SMB LIBCLI_NBT LIBCLI_DGRAM LIBCLI_WREPL

View File

@ -101,10 +101,19 @@ NTSTATUS torture_ldap_close(struct ldap_connection *conn)
NTSTATUS torture_ldap_init(void) NTSTATUS torture_ldap_init(void)
{ {
register_torture_op("BENCH-CLDAP", torture_bench_cldap); struct torture_suite *suite = torture_suite_create(
register_torture_op("LDAP-BASIC", torture_ldap_basic); talloc_autofree_context(),
register_torture_op("LDAP-SCHEMA", torture_ldap_schema); "LDAP");
register_torture_op("LDAP-CLDAP", torture_cldap); torture_suite_add_simple_test(suite, "BENCH-CLDAP",
torture_bench_cldap);
torture_suite_add_simple_test(suite, "BASIC", torture_ldap_basic);
torture_suite_add_simple_test(suite, "CLDAP", torture_cldap);
torture_suite_add_simple_test(suite, "SCHEMA", torture_ldap_schema);
suite->description = talloc_strdup(
suite, "LDAP and CLDAP tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -24,30 +24,39 @@
NTSTATUS torture_net_init(void) NTSTATUS torture_net_init(void)
{ {
register_torture_op("NET-USERINFO", torture_userinfo); struct torture_suite *suite = torture_suite_create(
register_torture_op("NET-USERADD", torture_useradd); talloc_autofree_context(),
register_torture_op("NET-USERDEL", torture_userdel); "NET");
register_torture_op("NET-USERMOD", torture_usermod);
register_torture_op("NET-DOMOPEN", torture_domainopen); torture_suite_add_simple_test(suite, "USERINFO", torture_userinfo);
register_torture_op("NET-API-LOOKUP", torture_lookup); torture_suite_add_simple_test(suite, "USERADD", torture_useradd);
register_torture_op("NET-API-LOOKUPHOST", torture_lookup_host); torture_suite_add_simple_test(suite, "USERDEL", torture_userdel);
register_torture_op("NET-API-LOOKUPPDC", torture_lookup_pdc); torture_suite_add_simple_test(suite, "USERMOD", torture_usermod);
register_torture_op("NET-API-LOOKUPNAME", torture_lookup_sam_name); torture_suite_add_simple_test(suite, "DOMOPEN", torture_domainopen);
register_torture_op("NET-API-CREATEUSER", torture_createuser); torture_suite_add_simple_test(suite, "API-LOOKUP", torture_lookup);
register_torture_op("NET-API-DELETEUSER", torture_deleteuser); torture_suite_add_simple_test(suite, "API-LOOKUPHOST", torture_lookup_host);
register_torture_op("NET-API-MODIFYUSER", torture_modifyuser); torture_suite_add_simple_test(suite, "API-LOOKUPPDC", torture_lookup_pdc);
register_torture_op("NET-API-USERINFO", torture_userinfo_api); torture_suite_add_simple_test(suite, "API-LOOKUPNAME", torture_lookup_sam_name);
register_torture_op("NET-API-RPCCONN-BIND", torture_rpc_connect_binding); torture_suite_add_simple_test(suite, "API-CREATEUSER", torture_createuser);
register_torture_op("NET-API-RPCCONN-SRV", torture_rpc_connect_srv); torture_suite_add_simple_test(suite, "API-DELETEUSER", torture_deleteuser);
register_torture_op("NET-API-RPCCONN-PDC", torture_rpc_connect_pdc); torture_suite_add_simple_test(suite, "API-MODIFYUSER", torture_modifyuser);
register_torture_op("NET-API-RPCCONN-DC", torture_rpc_connect_dc); torture_suite_add_simple_test(suite, "API-USERINFO", torture_userinfo_api);
register_torture_op("NET-API-RPCCONN-DCINFO", torture_rpc_connect_dc_info); torture_suite_add_simple_test(suite, "API-RPCCONN-BIND", torture_rpc_connect_binding);
register_torture_op("NET-API-LISTSHARES", torture_listshares); torture_suite_add_simple_test(suite, "API-RPCCONN-SRV", torture_rpc_connect_srv);
register_torture_op("NET-API-DELSHARE", torture_delshare); torture_suite_add_simple_test(suite, "API-RPCCONN-PDC", torture_rpc_connect_pdc);
register_torture_op("NET-API-DOMOPENLSA", torture_domain_open_lsa); torture_suite_add_simple_test(suite, "API-RPCCONN-DC", torture_rpc_connect_dc);
register_torture_op("NET-API-DOMCLOSELSA", torture_domain_close_lsa); torture_suite_add_simple_test(suite, "API-RPCCONN-DCINFO", torture_rpc_connect_dc_info);
register_torture_op("NET-API-DOMOPENSAMR", torture_domain_open_samr); torture_suite_add_simple_test(suite, "API-LISTSHARES", torture_listshares);
register_torture_op("NET-API-DOMCLOSESAMR", torture_domain_close_samr); torture_suite_add_simple_test(suite, "API-DELSHARE", torture_delshare);
torture_suite_add_simple_test(suite, "API-DOMOPENLSA", torture_domain_open_lsa);
torture_suite_add_simple_test(suite, "API-DOMCLOSELSA", torture_domain_close_lsa);
torture_suite_add_simple_test(suite, "API-DOMOPENSAMR", torture_domain_open_samr);
torture_suite_add_simple_test(suite, "API-DOMCLOSESAMR", torture_domain_close_samr);
suite->description = talloc_strdup(suite,
"libnet convenience interface tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -25,37 +25,32 @@
#include "librpc/rpc/dcerpc.h" #include "librpc/rpc/dcerpc.h"
#include "torture/torture.h" #include "torture/torture.h"
static BOOL test_BindingString(struct torture_context *torture, static bool test_BindingString(struct torture_context *tctx,
const void *_binding) const void *test_data)
{ {
const char *binding = _binding; const char *binding = test_data;
struct dcerpc_binding *b, *b2; struct dcerpc_binding *b, *b2;
const char *s, *s2; const char *s, *s2;
struct epm_tower tower; struct epm_tower tower;
TALLOC_CTX *mem_ctx = tctx;
/* Parse */ /* Parse */
torture_assert_ntstatus_ok(torture, torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(mem_ctx, binding, &b),
dcerpc_parse_binding(torture, binding, &b),
"Error parsing binding string"); "Error parsing binding string");
s = dcerpc_binding_string(torture, b); s = dcerpc_binding_string(mem_ctx, b);
if (!s) { torture_assert(tctx, s != NULL, "Error converting binding back to string");
torture_fail(torture, "Error converting binding back to string");
return False;
}
torture_assert_casestr_equal(torture, binding, s, torture_assert_casestr_equal(tctx, binding, s,
"Mismatch while comparing original and regenerated binding strings"); "Mismatch while comparing original and regenerated binding strings");
/* Generate protocol towers */ /* Generate protocol towers */
torture_assert_ntstatus_ok(torture, torture_assert_ntstatus_ok(tctx, dcerpc_binding_build_tower(mem_ctx, b, &tower),
dcerpc_binding_build_tower(torture, b, &tower),
"Error generating protocol tower"); "Error generating protocol tower");
/* Convert back to binding and then back to string and compare */ /* Convert back to binding and then back to string and compare */
torture_assert_ntstatus_ok(torture, torture_assert_ntstatus_ok(tctx, dcerpc_binding_from_tower(mem_ctx, &tower, &b2),
dcerpc_binding_from_tower(torture, &tower, &b2),
"Error generating binding from tower for original binding"); "Error generating binding from tower for original binding");
/* Compare to a stripped down version of the binding string because /* Compare to a stripped down version of the binding string because
@ -64,25 +59,16 @@ static BOOL test_BindingString(struct torture_context *torture,
b->flags = 0; b->flags = 0;
s = dcerpc_binding_string(torture, b); s = dcerpc_binding_string(mem_ctx, b);
if (!s) { torture_assert(tctx, s != NULL, "Error converting binding back to string for (stripped down)");
torture_fail(torture, "Error converting binding back to string for (stripped down)");
return False;
}
s2 = dcerpc_binding_string(mem_ctx, b2);
torture_assert(tctx, s != NULL, "Error converting binding back to string");
s2 = dcerpc_binding_string(torture, b2); if (is_ipaddress(b->host))
if (!s) { torture_assert_casestr_equal(tctx, s, s2, "Mismatch while comparing original and from protocol tower generated binding strings");
torture_fail(torture, "Error converting binding back to string");
return False;
}
if (is_ipaddress(b->host) && strcasecmp(s, s2) != 0) { return true;
torture_fail(torture, "Mismatch while comparing original and from protocol tower generated binding strings: '%s' <> '%s'\n", s, s2);
return False;
}
return True;
} }
static const char *test_strings[] = { static const char *test_strings[] = {
@ -114,7 +100,7 @@ struct torture_suite *torture_local_binding_string(TALLOC_CTX *mem_ctx)
{ {
int i; int i;
struct torture_suite *suite = torture_suite_create(mem_ctx, struct torture_suite *suite = torture_suite_create(mem_ctx,
"LOCAL-BINDING"); "BINDING");
for (i = 0; i < ARRAY_SIZE(test_strings); i++) { for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
torture_suite_add_simple_tcase(suite, test_strings[i], torture_suite_add_simple_tcase(suite, test_strings[i],

View File

@ -7,9 +7,9 @@ PRIVATE_PROTO_HEADER = \
proto.h proto.h
OBJ_FILES = \ OBJ_FILES = \
iconv.o \ iconv.o \
../../lib/talloc/testsuite.o \
../../lib/replace/test/testsuite.o \ ../../lib/replace/test/testsuite.o \
../../lib/replace/test/os2_delete.o \ ../../lib/replace/test/os2_delete.o \
../../lib/talloc/testsuite.o \
../../lib/crypto/md4test.o \ ../../lib/crypto/md4test.o \
../../lib/crypto/md5test.o \ ../../lib/crypto/md5test.o \
../../lib/crypto/hmacmd5test.o \ ../../lib/crypto/hmacmd5test.o \

View File

@ -73,13 +73,13 @@ static BOOL test_tdb_speed(struct torture_context *torture, const void *_data)
if (!tdb_add_record(tdbw, if (!tdb_add_record(tdbw,
"S-1-5-21-53173311-3623041448-2049097239-%u", "S-1-5-21-53173311-3623041448-2049097239-%u",
"UID %u", i)) { "UID %u", i)) {
torture_fail(torture, "Failed to add SID %d", i); _torture_fail_ext(torture, "Failed to add SID %d", i);
goto failed; goto failed;
} }
if (!tdb_add_record(tdbw, if (!tdb_add_record(tdbw,
"UID %u", "UID %u",
"S-1-5-21-53173311-3623041448-2049097239-%u", i)) { "S-1-5-21-53173311-3623041448-2049097239-%u", i)) {
torture_fail(torture, "Failed to add UID %d", i); _torture_fail_ext(torture, "Failed to add UID %d", i);
goto failed; goto failed;
} }
} }
@ -95,7 +95,7 @@ static BOOL test_tdb_speed(struct torture_context *torture, const void *_data)
key.dsize = strlen((char *)key.dptr)+1; key.dsize = strlen((char *)key.dptr)+1;
data = tdb_fetch(tdbw->tdb, key); data = tdb_fetch(tdbw->tdb, key);
if (data.dptr == NULL) { if (data.dptr == NULL) {
torture_fail(torture, "Failed to fetch SID %d", i); _torture_fail_ext(torture, "Failed to fetch SID %d", i);
goto failed; goto failed;
} }
free(data.dptr); free(data.dptr);
@ -103,7 +103,7 @@ static BOOL test_tdb_speed(struct torture_context *torture, const void *_data)
key.dsize = strlen((char *)key.dptr)+1; key.dsize = strlen((char *)key.dptr)+1;
data = tdb_fetch(tdbw->tdb, key); data = tdb_fetch(tdbw->tdb, key);
if (data.dptr == NULL) { if (data.dptr == NULL) {
torture_fail(torture, "Failed to fetch UID %d", i); _torture_fail_ext(torture, "Failed to fetch UID %d", i);
goto failed; goto failed;
} }
free(data.dptr); free(data.dptr);
@ -186,13 +186,13 @@ static BOOL test_ldb_speed(struct torture_context *torture, const void *_data)
for (i=0;i<torture_entries;i++) { for (i=0;i<torture_entries;i++) {
if (!ldb_add_record(ldb, i)) { if (!ldb_add_record(ldb, i)) {
torture_fail(torture, "Failed to add SID %d", i); _torture_fail_ext(torture, "Failed to add SID %d", i);
goto failed; goto failed;
} }
} }
if (talloc_total_blocks(torture) > 100) { if (talloc_total_blocks(torture) > 100) {
torture_fail(torture, "memory leak in ldb add"); _torture_fail_ext(torture, "memory leak in ldb add");
goto failed; goto failed;
} }
@ -210,14 +210,16 @@ static BOOL test_ldb_speed(struct torture_context *torture, const void *_data)
i); i);
if (ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res) != LDB_SUCCESS || if (ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res) != LDB_SUCCESS ||
res->count != 1) { res->count != 1) {
torture_fail(torture, "Failed to find SID %d", i); torture_fail(torture, talloc_asprintf(torture,
"Failed to find SID %d", i));
} }
talloc_free(res); talloc_free(res);
talloc_free(dn); talloc_free(dn);
expr = talloc_asprintf(tmp_ctx, "(UID=%u)", i); expr = talloc_asprintf(tmp_ctx, "(UID=%u)", i);
if (ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res) != LDB_SUCCESS || if (ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res) != LDB_SUCCESS ||
res->count != 1) { res->count != 1) {
torture_fail(torture, "Failed to find UID %d", i); torture_fail(torture, talloc_asprintf(torture,
"Failed to find UID %d", i));
} }
talloc_free(res); talloc_free(res);
talloc_free(expr); talloc_free(expr);

View File

@ -40,13 +40,13 @@ static void fde_handler(struct event_context *ev_ctx, struct fd_event *f,
{ {
int *fd = private; int *fd = private;
torture_comment(test, "event[%d] fd[%d] events[0x%08X]%s%s", fde_count, torture_comment(test, "event[%d] fd[%d] events[0x%08X]%s%s\n",
*fd, flags, fde_count, *fd, flags,
(flags & EVENT_FD_READ)?" EVENT_FD_READ":"", (flags & EVENT_FD_READ)?" EVENT_FD_READ":"",
(flags & EVENT_FD_WRITE)?" EVENT_FD_WRITE":""); (flags & EVENT_FD_WRITE)?" EVENT_FD_WRITE":"");
if (fde_count > 5) { if (fde_count > 5) {
torture_fail(test, "got more than fde 5 events - bug!"); _torture_fail_ext(test, "got more than fde 5 events - bug!");
talloc_free(fde); talloc_free(fde);
fde = NULL; fde = NULL;
return; return;
@ -59,13 +59,13 @@ static void fde_handler(struct event_context *ev_ctx, struct fd_event *f,
static void timed_handler(struct event_context *ev_ctx, struct timed_event *te, static void timed_handler(struct event_context *ev_ctx, struct timed_event *te,
struct timeval tval, void *private) struct timeval tval, void *private)
{ {
torture_comment(test, "timed_handler called[%d]", te_count); torture_comment(test, "timed_handler called[%d]\n", te_count);
if (te_count > 2) { if (te_count > 2) {
close(write_fd); close(write_fd);
write_fd = -1; write_fd = -1;
} }
if (te_count > 5) { if (te_count > 5) {
torture_comment(test, "remove fd event!"); torture_comment(test, "remove fd event!\n");
talloc_free(fde); talloc_free(fde);
fde = NULL; fde = NULL;
return; return;
@ -74,17 +74,19 @@ static void timed_handler(struct event_context *ev_ctx, struct timed_event *te,
event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(0,500), timed_handler, private); event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(0,500), timed_handler, private);
} }
static BOOL test_event_context(struct torture_context *torture, const void *_data) static bool test_event_context(struct torture_context *torture_ctx,
const void *test_data)
{ {
struct event_context *ev_ctx; struct event_context *ev_ctx;
int fd[2] = { -1, -1 }; int fd[2] = { -1, -1 };
BOOL try_epoll = (BOOL)_data; BOOL try_epoll = (BOOL)test_data;
TALLOC_CTX *mem_ctx = torture_ctx;
ev_ctx = event_context_init_ops(torture, ev_ctx = event_context_init_ops(mem_ctx,
event_standard_get_ops(), event_standard_get_ops(),
&try_epoll); &try_epoll);
test = torture; test = torture_ctx;
/* reset globals */ /* reset globals */
write_fd = -1; write_fd = -1;
@ -108,13 +110,12 @@ static BOOL test_event_context(struct torture_context *torture, const void *_dat
close(write_fd); close(write_fd);
talloc_free(ev_ctx); talloc_free(ev_ctx);
return true;
return True;
} }
struct torture_suite *torture_local_event(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_event(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-EVENT"); struct torture_suite *suite = torture_suite_create(mem_ctx, "EVENT");
torture_suite_add_simple_tcase(suite, "standard with select", torture_suite_add_simple_tcase(suite, "standard with select",
test_event_context, test_event_context,

View File

@ -107,7 +107,7 @@ static void show_buf(const char *name, uint8_t *buf, size_t size)
"charset", then convert it back again and ensure we get the same "charset", then convert it back again and ensure we get the same
buffer back buffer back
*/ */
static int test_buffer(struct torture_context *test, static bool test_buffer(struct torture_context *test,
uint8_t *inbuf, size_t size, const char *charset) uint8_t *inbuf, size_t size, const char *charset)
{ {
uint8_t buf1[1000], buf2[1000], buf3[1000]; uint8_t buf1[1000], buf2[1000], buf3[1000];
@ -116,7 +116,6 @@ static int test_buffer(struct torture_context *test,
char *ptr_out; char *ptr_out;
size_t size_in1, size_in2, size_in3; size_t size_in1, size_in2, size_in3;
size_t ret1, ret2, ret3, len1, len2; size_t ret1, ret2, ret3, len1, len2;
int ok = 1;
int errno1, errno2; int errno1, errno2;
static iconv_t cd; static iconv_t cd;
static smb_iconv_t cd2, cd3; static smb_iconv_t cd2, cd3;
@ -133,7 +132,7 @@ static int test_buffer(struct torture_context *test,
cd = iconv_open(charset, "UTF-16LE"); cd = iconv_open(charset, "UTF-16LE");
if (cd == (iconv_t)-1) { if (cd == (iconv_t)-1) {
cd = NULL; cd = NULL;
return False; return false;
} }
cd2 = smb_iconv_open(charset, "UTF-16LE"); cd2 = smb_iconv_open(charset, "UTF-16LE");
cd3 = smb_iconv_open("UTF-16LE", charset); cd3 = smb_iconv_open("UTF-16LE", charset);
@ -169,42 +168,30 @@ static int test_buffer(struct torture_context *test,
if (len2 > len1 && if (len2 > len1 &&
memcmp(buf1, buf2, len1) == 0 && memcmp(buf1, buf2, len1) == 0 &&
get_codepoint((char *)(buf2+len1), len2-len1, charset) >= (1<<20)) { get_codepoint((char *)(buf2+len1), len2-len1, charset) >= (1<<20)) {
return ok; return true;
} }
if (len1 > len2 && if (len1 > len2 &&
memcmp(buf1, buf2, len2) == 0 && memcmp(buf1, buf2, len2) == 0 &&
get_codepoint((char *)(buf1+len2), len1-len2, charset) >= (1<<20)) { get_codepoint((char *)(buf1+len2), len1-len2, charset) >= (1<<20)) {
return ok; return true;
} }
if (ret1 != ret2) { torture_assert_int_equal(test, ret1, ret2, "ret mismatch");
torture_fail(test, "ret1=%d ret2=%d", (int)ret1, (int)ret2);
ok = 0;
}
if (errno1 != errno2) { if (errno1 != errno2) {
torture_fail(test, "e1=%s e2=%s", strerror(errno1), strerror(errno2));
show_buf(" rem1:", inbuf+(size-size_in1), size_in1); show_buf(" rem1:", inbuf+(size-size_in1), size_in1);
show_buf(" rem2:", inbuf+(size-size_in2), size_in2); show_buf(" rem2:", inbuf+(size-size_in2), size_in2);
ok = 0; torture_fail(test, talloc_asprintf(test,
"e1=%s e2=%s", strerror(errno1), strerror(errno2)));
} }
if (outsize1 != outsize2) { torture_assert_int_equal(test, outsize1, outsize2, "outsize mismatch");
torture_fail(test, "outsize mismatch outsize1=%d outsize2=%d",
(int)outsize1, (int)outsize2);
ok = 0;
}
if (size_in1 != size_in2) { torture_assert_int_equal(test, size_in1, size_in2, "size_in mismatch");
torture_fail(test, "size_in mismatch size_in1=%d size_in2=%d",
(int)size_in1, (int)size_in2);
ok = 0;
}
if (!ok || if (len1 != len2 ||
len1 != len2 ||
memcmp(buf1, buf2, len1) != 0) { memcmp(buf1, buf2, len1) != 0) {
torture_fail(test, "size=%d ret1=%d ret2=%d", (int)size, (int)ret1, (int)ret2); torture_comment(test, "size=%d ret1=%d ret2=%d", (int)size, (int)ret1, (int)ret2);
show_buf(" IN1:", inbuf, size-size_in1); show_buf(" IN1:", inbuf, size-size_in1);
show_buf(" IN2:", inbuf, size-size_in2); show_buf(" IN2:", inbuf, size-size_in2);
show_buf("OUT1:", buf1, len1); show_buf("OUT1:", buf1, len1);
@ -218,7 +205,7 @@ static int test_buffer(struct torture_context *test,
get_codepoint((char *)(buf1+len2),len1-len2, charset)); get_codepoint((char *)(buf1+len2),len1-len2, charset));
} }
ok = 0; torture_fail(test, "failed");
} }
/* convert back to UTF-16, putting result in buf3 */ /* convert back to UTF-16, putting result in buf3 */
@ -236,42 +223,33 @@ static int test_buffer(struct torture_context *test,
get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3), get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3),
size - (sizeof(buf3) - outsize3), size - (sizeof(buf3) - outsize3),
"UTF-16LE") >= (1<<20)) { "UTF-16LE") >= (1<<20)) {
return ok; return true;
} }
if (ret3 != 0) { torture_assert_int_equal(test, ret3, 0, talloc_asprintf(test,
torture_fail(test, "pull failed - %s", strerror(errno)); "pull failed - %s", strerror(errno)));
ok = 0;
}
if (strncmp(charset, "UTF", 3) != 0) { if (strncmp(charset, "UTF", 3) != 0) {
/* don't expect perfect mappings for non UTF charsets */ /* don't expect perfect mappings for non UTF charsets */
return ok; return true;
} }
if (outsize3 != sizeof(buf3) - size) { torture_assert_int_equal(test, outsize3, sizeof(buf3) - size,
torture_fail(test, "wrong outsize3 - %d should be %d", "wrong outsize3");
(int)outsize3, (int)(sizeof(buf3) - size));
ok = 0;
}
if (memcmp(buf3, inbuf, size) != 0) { if (memcmp(buf3, inbuf, size) != 0) {
torture_fail(test, "pull bytes mismatch:"); torture_comment(test, "pull bytes mismatch:");
show_buf("inbuf", inbuf, size); show_buf("inbuf", inbuf, size);
show_buf(" buf3", buf3, sizeof(buf3) - outsize3); show_buf(" buf3", buf3, sizeof(buf3) - outsize3);
ok = 0; torture_fail(test, "");
torture_comment(test, "next codepoint is %u\n", torture_comment(test, "next codepoint is %u\n",
get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3), get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3),
size - (sizeof(buf3) - outsize3), size - (sizeof(buf3) - outsize3),
"UTF-16LE")); "UTF-16LE"));
} }
if (!ok) { return true;
torture_fail(test, "test_buffer failed for charset %s", charset);
}
return ok;
} }
@ -279,18 +257,14 @@ static int test_buffer(struct torture_context *test,
test the push_codepoint() and next_codepoint() functions for a given test the push_codepoint() and next_codepoint() functions for a given
codepoint codepoint
*/ */
static int test_codepoint(struct torture_context *test, const void *data) static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint)
{ {
uint8_t buf[10]; uint8_t buf[10];
size_t size, size2; size_t size, size2;
unsigned int codepoint = *((const unsigned int *)data);
codepoint_t c; codepoint_t c;
size = push_codepoint((char *)buf, codepoint); size = push_codepoint((char *)buf, codepoint);
if (size == -1) { torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000), "Invalid Codepoint range");
torture_assert(test, codepoint >= 0xd800 && codepoint <= 0x10000, "Invalid Codepoint range");
return True;
}
buf[size] = random(); buf[size] = random();
buf[size+1] = random(); buf[size+1] = random();
buf[size+2] = random(); buf[size+2] = random();
@ -298,31 +272,27 @@ static int test_codepoint(struct torture_context *test, const void *data)
c = next_codepoint((char *)buf, &size2); c = next_codepoint((char *)buf, &size2);
if (c != codepoint) { torture_assert(tctx, c == codepoint, talloc_asprintf(tctx,
torture_fail(test, "next_codepoint(%u) failed - gave %u", codepoint, c); "next_codepoint(%u) failed - gave %u", codepoint, c));
return False;
}
if (size2 != size) { torture_assert(tctx, size2 == size,
torture_fail(test, "next_codepoint(%u) gave wrong size %d (should be %d)\n", talloc_asprintf(tctx, "next_codepoint(%u) gave wrong size %d (should be %d)\n",
codepoint, (int)size2, (int)size); codepoint, (int)size2, (int)size));
return False;
}
return True; return true;
} }
static BOOL test_next_codepoint(struct torture_context *test, const void *data) static bool test_next_codepoint(struct torture_context *tctx)
{ {
unsigned int codepoint; unsigned int codepoint;
for (codepoint=0;codepoint<(1<<20);codepoint++) { for (codepoint=0;codepoint<(1<<20);codepoint++) {
if (!test_codepoint(test, &codepoint)) if (!test_codepoint(tctx, codepoint))
return False; return false;
} }
return True; return true;
} }
static BOOL test_first_1m(struct torture_context *test, const void *data) static bool test_first_1m(struct torture_context *tctx)
{ {
unsigned int codepoint; unsigned int codepoint;
size_t size; size_t size;
@ -339,14 +309,13 @@ static BOOL test_first_1m(struct torture_context *test, const void *data)
} }
} }
if (!test_buffer(test, inbuf, size, "UTF-8")) if (!test_buffer(tctx, inbuf, size, "UTF-8"))
return False; return false;
} }
return true;
return True;
} }
static BOOL test_random_5m(struct torture_context *test, const void *data) static bool test_random_5m(struct torture_context *tctx)
{ {
unsigned char inbuf[1000]; unsigned char inbuf[1000];
unsigned int i; unsigned int i;
@ -356,7 +325,7 @@ static BOOL test_random_5m(struct torture_context *test, const void *data)
if (i % 1000 == 0) { if (i % 1000 == 0) {
if (!lp_parm_bool(-1, "torture", "progress", True)) { if (!lp_parm_bool(-1, "torture", "progress", True)) {
torture_comment(test, "i=%u \r", i); torture_comment(tctx, "i=%u \r", i);
} }
} }
@ -374,20 +343,19 @@ static BOOL test_random_5m(struct torture_context *test, const void *data)
inbuf[c] |= 0xdc; inbuf[c] |= 0xdc;
} }
} }
if (!test_buffer(test, inbuf, size, "UTF-8")) if (!test_buffer(tctx, inbuf, size, "UTF-8"))
return False; return false;
if (!test_buffer(test, inbuf, size, "CP850")) if (!test_buffer(tctx, inbuf, size, "CP850"))
return False; return false;
} }
return true;
return True;
} }
struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
{ {
static iconv_t cd; static iconv_t cd;
struct torture_suite *suite; struct torture_suite *suite = torture_suite_create(mem_ctx, "ICONV");
if (!lp_parm_bool(-1, "iconv", "native", True)) { if (!lp_parm_bool(-1, "iconv", "native", True)) {
printf("system iconv disabled - skipping test\n"); printf("system iconv disabled - skipping test\n");
@ -401,18 +369,15 @@ struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
} }
iconv_close(cd); iconv_close(cd);
suite = torture_suite_create(mem_ctx, "LOCAL-ICONV");
srandom(time(NULL)); srandom(time(NULL));
torture_suite_add_simple_test(suite, "next_codepoint()",
test_next_codepoint);
torture_suite_add_simple_tcase(suite, "next_codepoint()", torture_suite_add_simple_test(suite, "first 1M codepoints",
test_next_codepoint, NULL); test_first_1m);
torture_suite_add_simple_tcase(suite, "first 1M codepoints",
test_first_1m, NULL);
torture_suite_add_simple_tcase(suite, "5M random UTF-16LE sequences",
test_random_5m, NULL);
torture_suite_add_simple_test(suite, "5M random UTF-16LE sequences",
test_random_5m);
return suite; return suite;
} }

View File

@ -23,8 +23,7 @@
#include "includes.h" #include "includes.h"
#include "torture/torture.h" #include "torture/torture.h"
static BOOL torture_local_idtree_simple(struct torture_context *test, static bool torture_local_idtree_simple(struct torture_context *tctx)
const void *_data)
{ {
struct idr_context *idr; struct idr_context *idr;
int i; int i;
@ -32,11 +31,12 @@ static BOOL torture_local_idtree_simple(struct torture_context *test,
int *present; int *present;
extern int torture_numops; extern int torture_numops;
int n = torture_numops; int n = torture_numops;
TALLOC_CTX *mem_ctx = tctx;
idr = idr_init(test); idr = idr_init(mem_ctx);
ids = talloc_zero_array(test, int, n); ids = talloc_zero_array(mem_ctx, int, n);
present = talloc_zero_array(test, int, n); present = talloc_zero_array(mem_ctx, int, n);
for (i=0;i<n;i++) { for (i=0;i<n;i++) {
ids[i] = -1; ids[i] = -1;
@ -47,28 +47,32 @@ static BOOL torture_local_idtree_simple(struct torture_context *test,
void *p = idr_find(idr, ids[ii]); void *p = idr_find(idr, ids[ii]);
if (present[ii]) { if (present[ii]) {
if (p != &ids[ii]) { if (p != &ids[ii]) {
torture_fail(test, "wrong ptr at %d - %p should be %p", torture_fail(tctx, talloc_asprintf(tctx,
ii, p, &ids[ii]); "wrong ptr at %d - %p should be %p",
ii, p, &ids[ii]));
} }
if (random() % 7 == 0) { if (random() % 7 == 0) {
if (idr_remove(idr, ids[ii]) != 0) { if (idr_remove(idr, ids[ii]) != 0) {
torture_fail(test, "remove failed at %d (id=%d)", torture_fail(tctx, talloc_asprintf(tctx,
i, ids[ii]); "remove failed at %d (id=%d)",
i, ids[ii]));
} }
present[ii] = 0; present[ii] = 0;
ids[ii] = -1; ids[ii] = -1;
} }
} else { } else {
if (p != NULL) { if (p != NULL) {
torture_fail(test, "non-present at %d gave %p (would be %d)", torture_fail(tctx, talloc_asprintf(tctx,
"non-present at %d gave %p (would be %d)",
ii, p, ii, p,
(int)(((char *)p) - (char *)(&ids[0])) / sizeof(int)); (int)(((char *)p) - (char *)(&ids[0])) / sizeof(int)));
} }
if (random() % 5) { if (random() % 5) {
ids[ii] = idr_get_new(idr, &ids[ii], n); ids[ii] = idr_get_new(idr, &ids[ii], n);
if (ids[ii] < 0) { if (ids[ii] < 0) {
torture_fail(test, "alloc failure at %d (ret=%d)", torture_fail(tctx, talloc_asprintf(tctx,
ii, ids[ii]); "alloc failure at %d (ret=%d)",
ii, ids[ii]));
} else { } else {
present[ii] = 1; present[ii] = 1;
} }
@ -76,26 +80,25 @@ static BOOL torture_local_idtree_simple(struct torture_context *test,
} }
} }
torture_comment(test, "done %d random ops", i); torture_comment(tctx, "done %d random ops\n", i);
for (i=0;i<n;i++) { for (i=0;i<n;i++) {
if (present[i]) { if (present[i]) {
if (idr_remove(idr, ids[i]) != 0) { if (idr_remove(idr, ids[i]) != 0) {
torture_fail(test, "delete failed on cleanup at %d (id=%d)", torture_fail(tctx, talloc_asprintf(tctx,
i, ids[i]); "delete failed on cleanup at %d (id=%d)",
i, ids[i]));
} }
} }
} }
torture_comment(test, "cleaned up"); torture_comment(tctx, "cleaned up\n");
return true;
return True;
} }
struct torture_suite *torture_local_idtree(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_idtree(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-IDTREE"); struct torture_suite *suite = torture_suite_create(mem_ctx, "IDTREE");
torture_suite_add_simple_tcase(suite, "idtree", torture_local_idtree_simple, torture_suite_add_simple_test(suite, "idtree", torture_local_idtree_simple);
NULL);
return suite; return suite;
} }

View File

@ -80,7 +80,7 @@ static NTSTATUS irpc_EchoData(struct irpc_message *irpc, struct echo_EchoData *r
/* /*
test a addone call over the internal messaging system test a addone call over the internal messaging system
*/ */
static BOOL test_addone(struct torture_context *test, const void *_data, static bool test_addone(struct torture_context *test, const void *_data,
const void *_value) const void *_value)
{ {
struct echo_AddOne r; struct echo_AddOne r;
@ -97,47 +97,45 @@ static BOOL test_addone(struct torture_context *test, const void *_data,
torture_assert_ntstatus_ok(test, status, "AddOne failed"); torture_assert_ntstatus_ok(test, status, "AddOne failed");
/* check the answer */ /* check the answer */
torture_assert(test, torture_assert(test, *r.out.out_data == r.in.in_data + 1,
*r.out.out_data == r.in.in_data + 1,
"AddOne wrong answer"); "AddOne wrong answer");
torture_comment(test, "%u + 1 = %u", r.in.in_data, *r.out.out_data); torture_comment(test, "%u + 1 = %u\n", r.in.in_data, *r.out.out_data);
return true;
return True;
} }
/* /*
test a echodata call over the internal messaging system test a echodata call over the internal messaging system
*/ */
static BOOL test_echodata(struct torture_context *test, static bool test_echodata(struct torture_context *tctx,
const void *_data, const void *_data2) const void *tcase_data,
const void *test_data)
{ {
struct echo_EchoData r; struct echo_EchoData r;
NTSTATUS status; NTSTATUS status;
const struct irpc_test_data *data = _data; const struct irpc_test_data *data = tcase_data;
TALLOC_CTX *mem_ctx = tctx;
/* make the call */ /* make the call */
r.in.in_data = (unsigned char *)talloc_strdup(test, "0123456789"); r.in.in_data = (unsigned char *)talloc_strdup(mem_ctx, "0123456789");
r.in.len = strlen((char *)r.in.in_data); r.in.len = strlen((char *)r.in.in_data);
status = IRPC_CALL(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ECHODATA, &r, status = IRPC_CALL(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ECHODATA, &r,
test); mem_ctx);
torture_assert_ntstatus_ok(test, status, "EchoData failed"); torture_assert_ntstatus_ok(tctx, status, "EchoData failed");
/* check the answer */ /* check the answer */
if (memcmp(r.out.out_data, r.in.in_data, r.in.len) != 0) { if (memcmp(r.out.out_data, r.in.in_data, r.in.len) != 0) {
torture_fail(test, "EchoData wrong answer");
NDR_PRINT_OUT_DEBUG(echo_EchoData, &r); NDR_PRINT_OUT_DEBUG(echo_EchoData, &r);
return False; torture_fail(tctx, "EchoData wrong answer");
} }
torture_comment(test, "Echo '%*.*s' -> '%*.*s'", torture_comment(tctx, "Echo '%*.*s' -> '%*.*s'\n",
r.in.len, r.in.len, r.in.len, r.in.len,
r.in.in_data, r.in.in_data,
r.in.len, r.in.len, r.in.len, r.in.len,
r.out.out_data); r.out.out_data);
return true;
return True;
} }
@ -159,28 +157,29 @@ static void irpc_callback(struct irpc_request *irpc)
/* /*
test echo speed test echo speed
*/ */
static BOOL test_speed(struct torture_context *test, static bool test_speed(struct torture_context *tctx,
const void *_data, const void *tcase_data,
const void *_data2) const void *test_data)
{ {
int ping_count = 0; int ping_count = 0;
int pong_count = 0; int pong_count = 0;
const struct irpc_test_data *data = _data; const struct irpc_test_data *data = tcase_data;
struct timeval tv; struct timeval tv;
struct echo_AddOne r; struct echo_AddOne r;
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); TALLOC_CTX *mem_ctx = tctx;
int timelimit = torture_setting_int(tctx, "timelimit", 10);
tv = timeval_current(); tv = timeval_current();
r.in.in_data = 0; r.in.in_data = 0;
torture_comment(test, "Sending echo for %d seconds", timelimit); torture_comment(tctx, "Sending echo for %d seconds\n", timelimit);
while (timeval_elapsed(&tv) < timelimit) { while (timeval_elapsed(&tv) < timelimit) {
struct irpc_request *irpc; struct irpc_request *irpc;
irpc = IRPC_CALL_SEND(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ADDONE, irpc = IRPC_CALL_SEND(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ADDONE,
&r, test); &r, mem_ctx);
torture_assert(test, irpc != NULL, "AddOne send failed"); torture_assert(tctx, irpc != NULL, "AddOne send failed");
irpc->async.fn = irpc_callback; irpc->async.fn = irpc_callback;
irpc->async.private = &pong_count; irpc->async.private = &pong_count;
@ -192,39 +191,33 @@ static BOOL test_speed(struct torture_context *test,
} }
} }
torture_comment(test, "waiting for %d remaining replies (done %d)", torture_comment(tctx, "waiting for %d remaining replies (done %d)\n",
ping_count - pong_count, pong_count); ping_count - pong_count, pong_count);
while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) {
event_loop_once(data->ev); event_loop_once(data->ev);
} }
if (ping_count != pong_count) { torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
torture_fail(test, "ping test failed! received %d, sent %d",
pong_count, ping_count);
}
torture_comment(test, "echo rate of %.0f messages/sec", torture_comment(tctx, "echo rate of %.0f messages/sec\n",
(ping_count+pong_count)/timeval_elapsed(&tv)); (ping_count+pong_count)/timeval_elapsed(&tv));
return true;
return True;
} }
static BOOL irpc_setup(struct torture_context *test, void **_data) static BOOL irpc_setup(struct torture_context *tctx, void **_data)
{ {
struct irpc_test_data *data; struct irpc_test_data *data;
*_data = data = talloc(test, struct irpc_test_data); *_data = data = talloc(tctx, struct irpc_test_data);
lp_set_cmdline("lock dir", "lockdir.tmp"); lp_set_cmdline("lock dir", "lockdir.tmp");
data->ev = event_context_init(test); data->ev = event_context_init(tctx);
torture_assert(test, torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, MSG_ID1, data->ev),
data->msg_ctx1 = messaging_init(test, MSG_ID1, data->ev),
"Failed to init first messaging context"); "Failed to init first messaging context");
torture_assert(test, torture_assert(tctx, data->msg_ctx2 = messaging_init(tctx, MSG_ID2, data->ev),
data->msg_ctx2 = messaging_init(test, MSG_ID2, data->ev),
"Failed to init second messaging context"); "Failed to init second messaging context");
/* register the server side function */ /* register the server side function */
@ -239,7 +232,7 @@ static BOOL irpc_setup(struct torture_context *test, void **_data)
struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-IRPC"); struct torture_suite *suite = torture_suite_create(mem_ctx, "IRPC");
struct torture_tcase *tcase = torture_suite_add_tcase(suite, "irpc"); struct torture_tcase *tcase = torture_suite_add_tcase(suite, "irpc");
int i; int i;
uint32_t *values = talloc_array(tcase, uint32_t, 5); uint32_t *values = talloc_array(tcase, uint32_t, 5);

View File

@ -49,17 +49,34 @@
NTSTATUS torture_local_init(void) NTSTATUS torture_local_init(void)
{ {
int i; int i;
TALLOC_CTX *mem_ctx = talloc_autofree_context(); struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"LOCAL");
struct torture_suite *talloc_suite = torture_suite_create(
talloc_autofree_context(),
"TALLOC");
register_torture_op("LOCAL-REPLACE", torture_local_replace); torture_local_talloc(talloc_suite);
register_torture_op("LOCAL-TALLOC", torture_local_talloc); torture_suite_add_suite(suite, talloc_suite);
register_torture_op("LOCAL-CRYPTO-MD4", torture_local_crypto_md4); torture_suite_add_simple_test(suite, "REPLACE", torture_local_replace);
register_torture_op("LOCAL-CRYPTO-MD5", torture_local_crypto_md5); torture_suite_add_simple_test(suite, "CRYPTO-SHA1",
register_torture_op("LOCAL-CRYPTO-HMACMD5", torture_local_crypto_hmacmd5); torture_local_crypto_sha1);
register_torture_op("LOCAL-CRYPTO-SHA1", torture_local_crypto_sha1); torture_suite_add_simple_test(suite,
register_torture_op("LOCAL-CRYPTO-HMACSHA1", torture_local_crypto_hmacsha1); "CRYPTO-MD4", torture_local_crypto_md4);
torture_suite_add_simple_test(suite, "CRYPTO-MD5",
torture_local_crypto_md5);
torture_suite_add_simple_test(suite, "CRYPTO-HMACMD5",
torture_local_crypto_hmacmd5);
torture_suite_add_simple_test(suite, "CRYPTO-HMACSHA1",
torture_local_crypto_hmacsha1);
for (i = 0; suite_generators[i]; i++) for (i = 0; suite_generators[i]; i++)
torture_register_suite(suite_generators[i](mem_ctx)); torture_suite_add_suite(suite,
suite_generators[i](talloc_autofree_context()));
suite->description = talloc_strdup(suite,
"Local, Samba-specific tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -55,7 +55,7 @@ static void exit_message(struct messaging_context *msg, void *private,
/* /*
test ping speed test ping speed
*/ */
static BOOL test_ping_speed(struct torture_context *torture, const void *_data) static bool test_ping_speed(struct torture_context *tctx)
{ {
struct event_context *ev; struct event_context *ev;
struct messaging_context *msg_client_ctx; struct messaging_context *msg_client_ctx;
@ -63,35 +63,30 @@ static BOOL test_ping_speed(struct torture_context *torture, const void *_data)
int ping_count = 0; int ping_count = 0;
int pong_count = 0; int pong_count = 0;
struct timeval tv; struct timeval tv;
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); int timelimit = torture_setting_int(tctx, "timelimit", 10);
uint32_t msg_ping, msg_exit; uint32_t msg_ping, msg_exit;
TALLOC_CTX *mem_ctx = tctx;
lp_set_cmdline("lock dir", "lockdir.tmp"); lp_set_cmdline("lock dir", "lockdir.tmp");
ev = event_context_init(torture); ev = event_context_init(mem_ctx);
msg_server_ctx = messaging_init(torture, 1, ev); msg_server_ctx = messaging_init(mem_ctx, 1, ev);
if (!msg_server_ctx) { torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context");
torture_fail(torture, "Failed to init ping messaging context");
return False;
}
messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping); messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping);
messaging_register_tmp(msg_server_ctx, torture, exit_message, &msg_exit); messaging_register_tmp(msg_server_ctx, mem_ctx, exit_message, &msg_exit);
msg_client_ctx = messaging_init(torture, 2, ev); msg_client_ctx = messaging_init(mem_ctx, 2, ev);
if (!msg_client_ctx) { torture_assert(tctx, msg_client_ctx != NULL, "msg_client_ctx messaging_init() failed");
torture_fail(torture, "msg_client_ctx messaging_init() failed");
return False;
}
messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong); messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong);
tv = timeval_current(); tv = timeval_current();
torture_comment(torture, "Sending pings for %d seconds", timelimit); torture_comment(tctx, "Sending pings for %d seconds", timelimit);
while (timeval_elapsed(&tv) < timelimit) { while (timeval_elapsed(&tv) < timelimit) {
DATA_BLOB data; DATA_BLOB data;
NTSTATUS status1, status2; NTSTATUS status1, status2;
@ -102,51 +97,41 @@ static BOOL test_ping_speed(struct torture_context *torture, const void *_data)
status1 = messaging_send(msg_client_ctx, 1, msg_ping, &data); status1 = messaging_send(msg_client_ctx, 1, msg_ping, &data);
status2 = messaging_send(msg_client_ctx, 1, msg_ping, NULL); status2 = messaging_send(msg_client_ctx, 1, msg_ping, NULL);
if (!NT_STATUS_IS_OK(status1)) { torture_assert_ntstatus_ok(tctx, status1, "msg1 failed");
torture_fail(torture, "msg1 failed - %s", nt_errstr(status1)); ping_count++;
} else {
ping_count++;
}
if (!NT_STATUS_IS_OK(status2)) { torture_assert_ntstatus_ok(tctx, status2, "msg2 failed");
torture_fail(torture, "msg2 failed - %s", nt_errstr(status2)); ping_count++;
} else {
ping_count++;
}
while (ping_count > pong_count + 20) { while (ping_count > pong_count + 20) {
event_loop_once(ev); event_loop_once(ev);
} }
} }
torture_comment(torture, "waiting for %d remaining replies (done %d)", torture_comment(tctx, "waiting for %d remaining replies (done %d)",
ping_count - pong_count, pong_count); ping_count - pong_count, pong_count);
while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) {
event_loop_once(ev); event_loop_once(ev);
} }
torture_comment(torture, "sending exit"); torture_comment(tctx, "sending exit");
messaging_send(msg_client_ctx, 1, msg_exit, NULL); messaging_send(msg_client_ctx, 1, msg_exit, NULL);
if (ping_count != pong_count) { torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
torture_fail(torture, "ping test failed! received %d, sent %d",
pong_count, ping_count);
}
torture_comment(torture, "ping rate of %.0f messages/sec", torture_comment(tctx, "ping rate of %.0f messages/sec",
(ping_count+pong_count)/timeval_elapsed(&tv)); (ping_count+pong_count)/timeval_elapsed(&tv));
talloc_free(msg_client_ctx); talloc_free(msg_client_ctx);
talloc_free(msg_server_ctx); talloc_free(msg_server_ctx);
talloc_free(ev); talloc_free(ev);
return true;
return True;
} }
struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *s = torture_suite_create(mem_ctx, "LOCAL-MESSAGING"); struct torture_suite *s = torture_suite_create(mem_ctx, "MESSAGING");
torture_suite_add_simple_tcase(s, "ping_speed", test_ping_speed, NULL); torture_suite_add_simple_test(s, "ping_speed", test_ping_speed);
return s; return s;
} }

View File

@ -23,64 +23,59 @@
#include "torture/torture.h" #include "torture/torture.h"
#include "librpc/ndr/libndr.h" #include "librpc/ndr/libndr.h"
static BOOL test_check_string_terminator(struct torture_context *test, static bool test_check_string_terminator(struct torture_context *tctx)
const void *_data)
{ {
struct ndr_pull *ndr; struct ndr_pull *ndr;
DATA_BLOB blob; DATA_BLOB blob;
TALLOC_CTX *mem_ctx = tctx;
/* Simple test */ /* Simple test */
blob = strhex_to_data_blob("0000"); blob = strhex_to_data_blob("0000");
ndr = ndr_pull_init_blob(&blob, test); ndr = ndr_pull_init_blob(&blob, mem_ctx);
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx, ndr_check_string_terminator(ndr, 1, 2),
ndr_check_string_terminator(ndr, 1, 2),
"simple check_string_terminator test failed"); "simple check_string_terminator test failed");
torture_assert(test, ndr->offset == 0, torture_assert(tctx, ndr->offset == 0,
"check_string_terminator did not reset offset"); "check_string_terminator did not reset offset");
if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr, 1, 3))) { if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr, 1, 3))) {
torture_fail(test, "check_string_terminator checked beyond string boundaries"); torture_fail(tctx, "check_string_terminator checked beyond string boundaries");
return False;
} }
torture_assert(test, ndr->offset == 0, torture_assert(tctx, ndr->offset == 0,
"check_string_terminator did not reset offset"); "check_string_terminator did not reset offset");
talloc_free(ndr); talloc_free(ndr);
blob = strhex_to_data_blob("11220000"); blob = strhex_to_data_blob("11220000");
ndr = ndr_pull_init_blob(&blob, test); ndr = ndr_pull_init_blob(&blob, mem_ctx);
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
ndr_check_string_terminator(ndr, 4, 1), ndr_check_string_terminator(ndr, 4, 1),
"check_string_terminator failed to recognize terminator"); "check_string_terminator failed to recognize terminator");
torture_assert_ntstatus_ok(test, torture_assert_ntstatus_ok(tctx,
ndr_check_string_terminator(ndr, 3, 1), ndr_check_string_terminator(ndr, 3, 1),
"check_string_terminator failed to recognize terminator"); "check_string_terminator failed to recognize terminator");
if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr, 2, 1))) { if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr, 2, 1))) {
torture_fail(test, torture_fail(tctx,
"check_string_terminator erroneously reported terminator"); "check_string_terminator erroneously reported terminator");
return False;
} }
torture_assert (test, ndr->offset == 0, torture_assert(tctx, ndr->offset == 0,
"check_string_terminator did not reset offset"); "check_string_terminator did not reset offset");
return true;
return True;
} }
struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-NDR"); struct torture_suite *suite = torture_suite_create(mem_ctx, "NDR");
torture_suite_add_simple_tcase(suite, "string terminator", torture_suite_add_simple_test(suite, "string terminator",
test_check_string_terminator, test_check_string_terminator);
NULL);
return suite; return suite;
} }

View File

@ -36,50 +36,51 @@ const static struct test_backend_settings {
{ NULL, NULL } { NULL, NULL }
}; };
static BOOL test_hive(struct torture_context *ctx, const void *_backend) static bool test_hive(struct torture_context *tctx,
const void *test_data)
{ {
WERROR error; WERROR error;
struct registry_key *root, *subkey; struct registry_key *root, *subkey;
uint32_t count; uint32_t count;
const struct test_backend_settings *backend = _backend; const struct test_backend_settings *backend = test_data;
TALLOC_CTX *mem_ctx = tctx;
if (!reg_has_backend(backend->name)) { if (!reg_has_backend(backend->name)) {
torture_skip(ctx, "Backend '%s' support not compiled in", torture_skip(tctx, talloc_asprintf(tctx,
backend->name); "Backend '%s' support not compiled in", backend->name));
return True;
} }
error = reg_open_hive(ctx, backend->name, error = reg_open_hive(mem_ctx, backend->name,
backend->location, NULL, cmdline_credentials, &root); backend->location, NULL, cmdline_credentials, &root);
torture_assert_werr_ok(ctx, error, "reg_open_hive()"); torture_assert_werr_ok(tctx, error, "reg_open_hive()");
/* This is a new backend. There should be no subkeys and no /* This is a new backend. There should be no subkeys and no
* values */ * values */
error = reg_key_num_subkeys(root, &count); error = reg_key_num_subkeys(root, &count);
torture_assert_werr_ok(ctx, error, "reg_key_num_subkeys()"); torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()");
torture_assert(ctx, count != 0, "New key has non-zero subkey count"); torture_assert(tctx, count != 0, "New key has non-zero subkey count");
error = reg_key_num_values(root, &count); error = reg_key_num_values(root, &count);
torture_assert_werr_ok(ctx, error, "reg_key_num_values"); torture_assert_werr_ok(tctx, error, "reg_key_num_values");
torture_assert(ctx, count != 0, "New key has non-zero value count"); torture_assert(tctx, count != 0, "New key has non-zero value count");
error = reg_key_add_name(ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey); error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey);
torture_assert_werr_ok(ctx, error, "reg_key_add_name"); torture_assert_werr_ok(tctx, error, "reg_key_add_name");
error = reg_key_del(root, "Nested\\Key"); error = reg_key_del(root, "Nested\\Key");
torture_assert_werr_ok(ctx, error, "reg_key_del"); torture_assert_werr_ok(tctx, error, "reg_key_del");
talloc_free(root); talloc_free(root);
return true;
return True;
} }
struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, struct torture_suite *suite = torture_suite_create(mem_ctx,
"LOCAL-REGISTRY"); "REGISTRY");
int i; int i;
registry_init(); registry_init();

View File

@ -25,68 +25,67 @@
#include "libcli/resolve/resolve.h" #include "libcli/resolve/resolve.h"
#include "torture/torture.h" #include "torture/torture.h"
static BOOL test_async_resolve(struct torture_context *test, const void *_data) static bool test_async_resolve(struct torture_context *tctx)
{ {
struct nbt_name n; struct nbt_name n;
struct event_context *ev; struct event_context *ev;
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); int timelimit = torture_setting_int(tctx, "timelimit", 10);
const char *host = lp_parm_string(-1, "torture", "host"); const char *host = torture_setting_string(tctx, "host", NULL);
int count = 0; int count = 0;
struct timeval tv = timeval_current(); struct timeval tv = timeval_current();
TALLOC_CTX *mem_ctx = tctx;
ev = event_context_init(test); ev = event_context_init(mem_ctx);
ZERO_STRUCT(n); ZERO_STRUCT(n);
n.name = host; n.name = host;
torture_comment(test, "Testing async resolve of localhost for %d seconds", torture_comment(tctx, "Testing async resolve of localhost for %d seconds\n",
timelimit); timelimit);
while (timeval_elapsed(&tv) < timelimit) { while (timeval_elapsed(&tv) < timelimit) {
const char *s; const char *s;
struct composite_context *c = resolve_name_host_send(&n, ev); struct composite_context *c = resolve_name_host_send(&n, ev);
torture_assert(test, c, "resolve_name_host_send"); torture_assert(tctx, c != NULL, "resolve_name_host_send");
torture_assert_ntstatus_ok(test, resolve_name_host_recv(c, test, &s), torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s),
"async resolve failed"); "async resolve failed");
count++; count++;
} }
torture_comment(test, "async rate of %.1f resolves/sec", torture_comment(tctx, "async rate of %.1f resolves/sec\n",
count/timeval_elapsed(&tv)); count/timeval_elapsed(&tv));
return true;
return True;
} }
/* /*
test resolution using sync method test resolution using sync method
*/ */
static BOOL test_sync_resolve(struct torture_context *test, const void *_data) static bool test_sync_resolve(struct torture_context *tctx)
{ {
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); int timelimit = torture_setting_int(tctx, "timelimit", 10);
struct timeval tv = timeval_current(); struct timeval tv = timeval_current();
int count = 0; int count = 0;
const char *host = lp_parm_string(-1, "torture", "host"); const char *host = torture_setting_string(tctx, "host", NULL);
torture_comment(test, "Testing sync resolve of localhost for %d seconds", torture_comment(tctx, "Testing sync resolve of localhost for %d seconds\n",
timelimit); timelimit);
while (timeval_elapsed(&tv) < timelimit) { while (timeval_elapsed(&tv) < timelimit) {
sys_inet_ntoa(interpret_addr2(host)); sys_inet_ntoa(interpret_addr2(host));
count++; count++;
} }
torture_comment(test, "sync rate of %.1f resolves/sec", torture_comment(tctx, "sync rate of %.1f resolves/sec\n",
count/timeval_elapsed(&tv)); count/timeval_elapsed(&tv));
return true;
return True;
} }
struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, struct torture_suite *suite = torture_suite_create(mem_ctx,
"LOCAL-RESOLVE"); "RESOLVE");
torture_suite_add_simple_tcase(suite, "async", test_async_resolve, NULL); torture_suite_add_simple_test(suite, "async", test_async_resolve);
torture_suite_add_simple_tcase(suite, "sync", test_sync_resolve, NULL); torture_suite_add_simple_test(suite, "sync", test_sync_resolve);
return suite; return suite;
} }

View File

@ -29,37 +29,31 @@
/* /*
test one SDDL example test one SDDL example
*/ */
static BOOL test_sddl(struct torture_context *mem_ctx, const void *_sddl) static bool test_sddl(struct torture_context *tctx,
const void *test_data)
{ {
struct security_descriptor *sd, *sd2; struct security_descriptor *sd, *sd2;
struct dom_sid *domain; struct dom_sid *domain;
const char *sddl = _sddl; const char *sddl = test_data;
const char *sddl2; const char *sddl2;
TALLOC_CTX *mem_ctx = tctx;
domain = dom_sid_parse_talloc(mem_ctx, "S-1-2-3-4"); domain = dom_sid_parse_talloc(mem_ctx, "S-1-2-3-4");
sd = sddl_decode(mem_ctx, sddl, domain); sd = sddl_decode(mem_ctx, sddl, domain);
if (sd == NULL) { torture_assert(tctx, sd != NULL, talloc_asprintf(tctx,
printf("Failed to decode '%s'\n", sddl); "Failed to decode '%s'\n", sddl));
return False;
}
sddl2 = sddl_encode(mem_ctx, sd, domain); sddl2 = sddl_encode(mem_ctx, sd, domain);
if (sddl2 == NULL) { torture_assert(tctx, sddl2 != NULL, talloc_asprintf(tctx,
printf("Failed to re-encode '%s'\n", sddl); "Failed to re-encode '%s'\n", sddl));
return False;
}
sd2 = sddl_decode(mem_ctx, sddl2, domain); sd2 = sddl_decode(mem_ctx, sddl2, domain);
if (sd2 == NULL) { torture_assert(tctx, sd2 != NULL, talloc_asprintf(tctx,
printf("Failed to decode2 '%s'\n", sddl2); "Failed to decode2 '%s'\n", sddl2));
return False;
}
if (!security_descriptor_equal(sd, sd2)) { torture_assert(tctx, security_descriptor_equal(sd, sd2),
printf("Failed equality test for '%s'\n", sddl); talloc_asprintf(tctx, "Failed equality test for '%s'\n", sddl));
return False;
}
#if 0 #if 0
/* flags don't have a canonical order ... */ /* flags don't have a canonical order ... */
@ -73,7 +67,7 @@ static BOOL test_sddl(struct torture_context *mem_ctx, const void *_sddl)
} }
talloc_free(sd); talloc_free(sd);
talloc_free(domain); talloc_free(domain);
return True; return true;
} }
static const char *examples[] = { static const char *examples[] = {
@ -99,7 +93,7 @@ static const char *examples[] = {
/* test a set of example SDDL strings */ /* test a set of example SDDL strings */
struct torture_suite *torture_local_sddl(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_sddl(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-SDDL"); struct torture_suite *suite = torture_suite_create(mem_ctx, "SDDL");
int i; int i;
for (i = 0; i < ARRAY_SIZE(examples); i++) { for (i = 0; i < ARRAY_SIZE(examples); i++) {

View File

@ -30,7 +30,7 @@
/* /*
basic testing of udp routines basic testing of udp routines
*/ */
static BOOL test_udp(struct torture_context *test, const void *data) static bool test_udp(struct torture_context *tctx)
{ {
struct socket_context *sock1, *sock2; struct socket_context *sock1, *sock2;
NTSTATUS status; NTSTATUS status;
@ -38,95 +38,79 @@ static BOOL test_udp(struct torture_context *test, const void *data)
size_t size = 100 + (random() % 100); size_t size = 100 + (random() % 100);
DATA_BLOB blob, blob2; DATA_BLOB blob, blob2;
size_t sent, nread; size_t sent, nread;
BOOL ret = True; TALLOC_CTX *mem_ctx = tctx;
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0); status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
torture_assert_ntstatus_ok(test, status, "creating DGRAM IP socket 1"); torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
talloc_steal(test, sock1); talloc_steal(mem_ctx, sock1);
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock2, 0); status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock2, 0);
torture_assert_ntstatus_ok(test, status, "creating DGRAM IP socket 1"); torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
talloc_steal(test, sock2); talloc_steal(mem_ctx, sock2);
localhost = socket_address_from_strings(sock1, sock1->backend_name, localhost = socket_address_from_strings(sock1, sock1->backend_name,
iface_best_ip("127.0.0.1"), 0); iface_best_ip("127.0.0.1"), 0);
torture_assert(test, localhost, "Localhost not found"); torture_assert(tctx, localhost, "Localhost not found");
status = socket_listen(sock1, localhost, 0, 0); status = socket_listen(sock1, localhost, 0, 0);
torture_assert_ntstatus_ok(test, status, "listen on socket 1"); torture_assert_ntstatus_ok(tctx, status, "listen on socket 1");
srv_addr = socket_get_my_addr(sock1, test); srv_addr = socket_get_my_addr(sock1, mem_ctx);
if (srv_addr == NULL || strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) != 0) { torture_assert(tctx, srv_addr != NULL && strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) == 0,
torture_fail(test, "Expected server address of %s but got %s", talloc_asprintf(tctx,
iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL); "Expected server address of %s but got %s",
return False; iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
}
torture_comment(test, "server port is %d", srv_addr->port); torture_comment(tctx, "server port is %d\n", srv_addr->port);
blob = data_blob_talloc(test, NULL, size); blob = data_blob_talloc(mem_ctx, NULL, size);
blob2 = data_blob_talloc(test, NULL, size); blob2 = data_blob_talloc(mem_ctx, NULL, size);
generate_random_buffer(blob.data, blob.length); generate_random_buffer(blob.data, blob.length);
sent = size; sent = size;
status = socket_sendto(sock2, &blob, &sent, srv_addr); status = socket_sendto(sock2, &blob, &sent, srv_addr);
torture_assert_ntstatus_ok(test, status, "sendto() on socket 2"); torture_assert_ntstatus_ok(tctx, status, "sendto() on socket 2");
status = socket_recvfrom(sock1, blob2.data, size, &nread, status = socket_recvfrom(sock1, blob2.data, size, &nread,
sock1, &from_addr); sock1, &from_addr);
torture_assert_ntstatus_ok(test, status, "recvfrom() on socket 1"); torture_assert_ntstatus_ok(tctx, status, "recvfrom() on socket 1");
if (strcmp(from_addr->addr, srv_addr->addr) != 0) { torture_assert_str_equal(tctx, from_addr->addr, srv_addr->addr,
torture_fail(test, "Unexpected recvfrom addr %s", from_addr->addr); "different address");
return False;
}
if (nread != size) {
torture_fail(test, "Unexpected recvfrom size %d should be %d\n",
(int)nread, (int)size);
return False;
}
torture_assert(test, memcmp(blob2.data, blob.data, size) == 0, torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
"Bad data in recvfrom"); "Bad data in recvfrom");
generate_random_buffer(blob.data, blob.length); generate_random_buffer(blob.data, blob.length);
status = socket_sendto(sock1, &blob, &sent, from_addr); status = socket_sendto(sock1, &blob, &sent, from_addr);
torture_assert_ntstatus_ok(test, status, "sendto() on socket 1"); torture_assert_ntstatus_ok(tctx, status, "sendto() on socket 1");
status = socket_recvfrom(sock2, blob2.data, size, &nread, status = socket_recvfrom(sock2, blob2.data, size, &nread,
sock2, &from_addr); sock2, &from_addr);
torture_assert_ntstatus_ok(test, status, "recvfrom() on socket 2"); torture_assert_ntstatus_ok(tctx, status, "recvfrom() on socket 2");
if (strcmp(from_addr->addr, srv_addr->addr) != 0) { torture_assert_str_equal(tctx, from_addr->addr, srv_addr->addr,
torture_fail(test, "Unexpected recvfrom addr %s\n", from_addr->addr); "Unexpected recvfrom addr");
return False;
}
if (nread != size) { torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
torture_fail(test, "Unexpected recvfrom size %d should be %d\n",
(int)nread, (int)size);
return False;
}
if (from_addr->port != srv_addr->port) { torture_assert_int_equal(tctx, from_addr->port, srv_addr->port,
torture_fail(test, "Unexpected recvfrom port %d should be %d\n", "Unexpected recvfrom port");
from_addr->port, srv_addr->port);
return False;
}
torture_assert(test, memcmp(blob2.data, blob.data, size) == 0, torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
"Bad data in recvfrom"); "Bad data in recvfrom");
talloc_free(sock1); talloc_free(sock1);
talloc_free(sock2); talloc_free(sock2);
return true;
return ret;
} }
/* /*
basic testing of tcp routines basic testing of tcp routines
*/ */
static BOOL test_tcp(struct torture_context *test, const void *data) static bool test_tcp(struct torture_context *tctx)
{ {
struct socket_context *sock1, *sock2, *sock3; struct socket_context *sock1, *sock2, *sock3;
NTSTATUS status; NTSTATUS status;
@ -134,84 +118,74 @@ static BOOL test_tcp(struct torture_context *test, const void *data)
size_t size = 100 + (random() % 100); size_t size = 100 + (random() % 100);
DATA_BLOB blob, blob2; DATA_BLOB blob, blob2;
size_t sent, nread; size_t sent, nread;
struct event_context *ev = event_context_init(test); TALLOC_CTX *mem_ctx = tctx;
struct event_context *ev = event_context_init(mem_ctx);
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0);
torture_assert_ntstatus_ok(test, status, "creating IP stream socket 1"); torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(test, sock1); talloc_steal(mem_ctx, sock1);
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock2, 0); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock2, 0);
torture_assert_ntstatus_ok(test, status, "creating IP stream socket 1"); torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(test, sock2); talloc_steal(mem_ctx, sock2);
localhost = socket_address_from_strings(sock1, sock1->backend_name, localhost = socket_address_from_strings(sock1, sock1->backend_name,
iface_best_ip("127.0.0.1"), 0); iface_best_ip("127.0.0.1"), 0);
torture_assert(test, localhost, "Localhost not found"); torture_assert(tctx, localhost, "Localhost not found");
status = socket_listen(sock1, localhost, 0, 0); status = socket_listen(sock1, localhost, 0, 0);
torture_assert_ntstatus_ok(test, status, "listen on socket 1"); torture_assert_ntstatus_ok(tctx, status, "listen on socket 1");
srv_addr = socket_get_my_addr(sock1, test); srv_addr = socket_get_my_addr(sock1, mem_ctx);
torture_assert(test, srv_addr && srv_addr->addr, torture_assert(tctx, srv_addr && srv_addr->addr,
"Unexpected socket_get_my_addr NULL\n"); "Unexpected socket_get_my_addr NULL\n");
if (strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) != 0) { torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip("127.0.0.1"),
torture_fail(test, "Expected server address of %s but got %s\n", "Unexpected server address");
iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL);
return False;
}
torture_comment(test, "server port is %d", srv_addr->port); torture_comment(tctx, "server port is %d\n", srv_addr->port);
status = socket_connect_ev(sock2, NULL, srv_addr, 0, ev); status = socket_connect_ev(sock2, NULL, srv_addr, 0, ev);
torture_assert_ntstatus_ok(test, status, "connect() on socket 2"); torture_assert_ntstatus_ok(tctx, status, "connect() on socket 2");
status = socket_accept(sock1, &sock3); status = socket_accept(sock1, &sock3);
torture_assert_ntstatus_ok(test, status, "accept() on socket 1"); torture_assert_ntstatus_ok(tctx, status, "accept() on socket 1");
talloc_steal(test, sock3); talloc_steal(mem_ctx, sock3);
talloc_free(sock1); talloc_free(sock1);
blob = data_blob_talloc(test, NULL, size); blob = data_blob_talloc(mem_ctx, NULL, size);
blob2 = data_blob_talloc(test, NULL, size); blob2 = data_blob_talloc(mem_ctx, NULL, size);
generate_random_buffer(blob.data, blob.length); generate_random_buffer(blob.data, blob.length);
sent = size; sent = size;
status = socket_send(sock2, &blob, &sent); status = socket_send(sock2, &blob, &sent);
torture_assert_ntstatus_ok(test, status, "send() on socket 2"); torture_assert_ntstatus_ok(tctx, status, "send() on socket 2");
status = socket_recv(sock3, blob2.data, size, &nread); status = socket_recv(sock3, blob2.data, size, &nread);
torture_assert_ntstatus_ok(test, status, "recv() on socket 3"); torture_assert_ntstatus_ok(tctx, status, "recv() on socket 3");
from_addr = socket_get_peer_addr(sock3, test); from_addr = socket_get_peer_addr(sock3, mem_ctx);
torture_assert(test, from_addr && from_addr->addr, torture_assert(tctx, from_addr && from_addr->addr,
"Unexpected recvfrom addr NULL"); "Unexpected recvfrom addr NULL");
if (strcmp(from_addr->addr, srv_addr->addr) != 0) { torture_assert_str_equal(tctx, from_addr->addr, srv_addr->addr,
torture_fail(test, "Unexpected recvfrom addr %s\n", "Unexpected recvfrom addr");
from_addr ? from_addr->addr : NULL);
return False;
}
if (nread != size) {
torture_fail(test, "Unexpected recvfrom size %d should be %d\n",
(int)nread, (int)size);
return False;
}
torture_assert(test, torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
memcmp(blob2.data, blob.data, size) == 0,
torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
"Bad data in recv"); "Bad data in recv");
return true;
return True;
} }
struct torture_suite *torture_local_socket(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_socket(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, struct torture_suite *suite = torture_suite_create(mem_ctx,
"LOCAL-SOCKET"); "SOCKET");
torture_suite_add_simple_tcase(suite, "udp", test_udp, NULL); torture_suite_add_simple_test(suite, "udp", test_udp);
torture_suite_add_simple_tcase(suite, "tcp", test_tcp, NULL); torture_suite_add_simple_test(suite, "tcp", test_tcp);
return suite; return suite;
} }

View File

@ -27,58 +27,57 @@
#include "libcli/raw/libcliraw.h" #include "libcli/raw/libcliraw.h"
#include "torture/util.h" #include "torture/util.h"
static BOOL test_tempdir(struct torture_context *torture, static bool test_tempdir(struct torture_context *tctx)
const void *_data)
{ {
char *location = NULL; char *location = NULL;
TALLOC_CTX *mem_ctx = tctx;
torture_assert_ntstatus_ok(torture, torture_temp_dir(torture, "tempdir", &location), torture_assert_ntstatus_ok(tctx, torture_temp_dir(mem_ctx, "tempdir", &location),
"torture_temp_dir should return NT_STATUS_OK" ); "torture_temp_dir should return NT_STATUS_OK" );
torture_assert(torture, directory_exist(location), torture_assert(tctx, directory_exist(location),
"created dir doesn't exist"); "created dir doesn't exist");
return true;
return True;
} }
static BOOL test_setup_server(struct torture_context *torture, static bool test_setup_server(struct torture_context *tctx)
const void *_data)
{ {
pid_t pid; pid_t pid;
TALLOC_CTX *mem_ctx = tctx;
torture_assert_ntstatus_ok(torture, torture_setup_server(torture, torture_assert_ntstatus_ok(tctx, torture_setup_server(mem_ctx,
"setupserver-success", "setupserver-success",
"./script/tests/mktestsetup.sh", "./script/tests/mktestsetup.sh",
"./bin/smbd", &pid), "./bin/smbd", &pid),
"starting smbd failed"); "starting smbd failed");
torture_assert(torture, pid > 0, "Pid invalid"); torture_assert(tctx, pid > 0, "Pid invalid");
torture_comment(torture, "Created smbd with pid %d", pid); torture_comment(tctx, "Created smbd with pid %d\n", pid);
kill(pid, SIGINT); kill(pid, SIGINT);
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
torture_assert_ntstatus_equal(torture, torture_setup_server(torture, torture_assert_ntstatus_equal(tctx, torture_setup_server(mem_ctx,
"setupserver-fail", "setupserver-fail",
"./invalid-script", "./invalid-script",
"./bin/smbd", &pid), "./bin/smbd", &pid),
NT_STATUS_UNSUCCESSFUL, NT_STATUS_UNSUCCESSFUL,
"invalid script specified"); "invalid script specified");
torture_assert(torture, pid == -1, "Pid not -1 after failure"); torture_assert(tctx, pid == -1, "Pid not -1 after failure");
return true;
return True;
} }
struct torture_suite *torture_local_torture(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_torture(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, struct torture_suite *suite = torture_suite_create(mem_ctx,
"LOCAL-TORTURE"); "TORTURE");
torture_suite_add_simple_tcase(suite, "tempdir", test_tempdir, NULL); torture_suite_add_simple_test(suite, "tempdir", test_tempdir);
torture_suite_add_simple_tcase(suite, "setup server", test_setup_server, NULL); torture_suite_add_simple_test(suite, "setup server", test_setup_server);
return suite; return suite;
} }

View File

@ -31,66 +31,65 @@
#define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3 #define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3
static BOOL test_file_load_save(struct torture_context *test, const void *_data) static bool test_file_load_save(struct torture_context *tctx)
{ {
size_t len; size_t len;
char *data; char *data;
TALLOC_CTX *mem_ctx = tctx;
torture_assert(test, torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)),
file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)),
"saving file"); "saving file");
data = file_load(TEST_FILENAME, &len, test); data = file_load(TEST_FILENAME, &len, mem_ctx);
torture_assert(test, data, "loading file"); torture_assert(tctx, data, "loading file");
torture_assert(test, len == strlen(TEST_DATA), "Length"); torture_assert(tctx, len == strlen(TEST_DATA), "Length");
torture_assert(test, memcmp(data, TEST_DATA, len) == 0, "Contents"); torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents");
unlink(TEST_FILENAME); unlink(TEST_FILENAME);
return true;
return True;
} }
static BOOL test_afdgets(struct torture_context *test, const void *data)
static bool test_afdgets(struct torture_context *tctx)
{ {
int fd; int fd;
char *line; char *line;
TALLOC_CTX *mem_ctx = tctx;
torture_assert(test, torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA,
file_save(TEST_FILENAME, (const void *)TEST_DATA,
strlen(TEST_DATA)), strlen(TEST_DATA)),
"saving file"); "saving file");
fd = open(TEST_FILENAME, O_RDONLY); fd = open(TEST_FILENAME, O_RDONLY);
torture_assert(test, fd != -1, "opening file"); torture_assert(tctx, fd != -1, "opening file");
line = afdgets(fd, test, 8); line = afdgets(fd, mem_ctx, 8);
torture_assert(test, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch"); torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch");
line = afdgets(fd, test, 8); line = afdgets(fd, mem_ctx, 8);
torture_assert(test, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch"); torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch");
line = afdgets(fd, test, 8); line = afdgets(fd, mem_ctx, 8);
torture_assert(test, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch"); torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch");
close(fd); close(fd);
unlink(TEST_FILENAME); unlink(TEST_FILENAME);
return true;
return True;
} }
struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-FILE"); struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE");
torture_suite_add_simple_tcase(suite, "file_load_save", torture_suite_add_simple_test(suite, "file_load_save",
test_file_load_save, NULL); test_file_load_save);
torture_suite_add_simple_tcase(suite, "afdgets", torture_suite_add_simple_test(suite, "afdgets",
test_afdgets, NULL); test_afdgets);
return suite; return suite;
} }

View File

@ -33,15 +33,17 @@ static const char *test_lists_shell_strings[] = {
NULL NULL
}; };
static BOOL test_lists_shell(struct torture_context *test, const void *_data) static bool test_lists_shell(struct torture_context *tctx,
const void *test_data)
{ {
const char *data = _data; const char *data = test_data;
const char **ret1, **ret2, *tmp; const char **ret1, **ret2, *tmp;
BOOL match = True; BOOL match = True;
TALLOC_CTX *mem_ctx = tctx;
ret1 = str_list_make_shell(test, data, " "); ret1 = str_list_make_shell(mem_ctx, data, " ");
tmp = str_list_join_shell(test, ret1, ' '); tmp = str_list_join_shell(mem_ctx, ret1, ' ');
ret2 = str_list_make_shell(test, tmp, " "); ret2 = str_list_make_shell(mem_ctx, tmp, " ");
if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) { if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
match = False; match = False;
@ -58,17 +60,14 @@ static BOOL test_lists_shell(struct torture_context *test, const void *_data)
match = False; match = False;
} }
if (!match) { torture_assert(tctx, match, talloc_asprintf(tctx,
torture_fail(test, "str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", data, tmp); "str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", data, tmp));
return False; return true;
}
return True;
} }
struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx) struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
{ {
struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-STRLIST"); struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST");
int i; int i;
for (i = 0; test_lists_shell_strings[i]; i++) { for (i = 0; test_lists_shell_strings[i]; i++) {

View File

@ -20,6 +20,7 @@
#include "includes.h" #include "includes.h"
#include "libcli/libcli.h" #include "libcli/libcli.h"
#include "torture/ui.h"
#include "torture/util.h" #include "torture/util.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "system/filesys.h" #include "system/filesys.h"
@ -35,7 +36,7 @@ static const char *loadfile;
#define ival(s) strtol(s, NULL, 0) #define ival(s) strtol(s, NULL, 0)
/* run a test that simulates an approximate netbench client load */ /* run a test that simulates an approximate netbench client load */
static BOOL run_netbench(struct smbcli_state *cli, int client) static BOOL run_netbench(struct torture_context *tctx, struct smbcli_state *cli, int client)
{ {
extern int torture_nprocs; extern int torture_nprocs;
int i; int i;
@ -211,7 +212,7 @@ BOOL torture_nbench(struct torture_context *torture)
signal(SIGALRM, nb_alarm); signal(SIGALRM, nb_alarm);
alarm(1); alarm(1);
torture_create_procs(run_netbench, &correct); torture_create_procs(torture, run_netbench, &correct);
alarm(0); alarm(0);
if (torture_nprocs > 1) { if (torture_nprocs > 1) {
@ -224,6 +225,15 @@ BOOL torture_nbench(struct torture_context *torture)
NTSTATUS torture_nbench_init(void) NTSTATUS torture_nbench_init(void)
{ {
register_torture_op("BENCH-NBENCH", torture_nbench); struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"BENCH");
torture_suite_add_simple_test(suite, "NBENCH", torture_nbench);
suite->description = talloc_strdup(suite,
"Benchmarks");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -61,13 +61,12 @@ static void netlogon_handler(struct dgram_mailslot_handler *dgmslot,
/* test UDP/138 netlogon requests */ /* test UDP/138 netlogon requests */
static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx, static bool nbt_test_netlogon(struct torture_context *tctx)
struct nbt_name name, const char *address)
{ {
struct dgram_mailslot_handler *dgmslot; struct dgram_mailslot_handler *dgmslot;
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
struct socket_address *dest; struct socket_address *dest;
const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); const char *myaddress;
struct nbt_netlogon_packet logon; struct nbt_netlogon_packet logon;
struct nbt_name myname; struct nbt_name myname;
NTSTATUS status; NTSTATUS status;
@ -76,11 +75,25 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address; 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, socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port()); myaddress, lp_dgram_port());
if (!socket_address) { torture_assert(tctx, socket_address != NULL,
return False; "Error getting address");
}
/* try receiving replies on port 138 first, which will only /* try receiving replies on port 138 first, which will only
work if we are root and smbd/nmbd are not running - fall work if we are root and smbd/nmbd are not running - fall
@ -91,9 +104,7 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
talloc_free(socket_address); talloc_free(socket_address);
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, 0); myaddress, 0);
if (!socket_address) { torture_assert(tctx, socket_address != NULL, "Error getting address");
return False;
}
socket_listen(dgmsock->sock, socket_address, 0, 0); socket_listen(dgmsock->sock, socket_address, 0, 0);
} }
@ -115,38 +126,27 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
address, 0); address, 0);
if (!dest) { torture_assert(tctx, dest != NULL, "Error getting address");
return False;
}
status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, status = dgram_mailslot_netlogon_send(dgmsock, &name, dest,
&myname, &logon); &myname, &logon);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request");
printf("Failed to send netlogon request - %s\n", nt_errstr(status));
goto failed;
}
while (timeval_elapsed(&tv) < 5 && replies == 0) { while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx); event_loop_once(dgmsock->event_ctx);
} }
talloc_free(dgmsock); return true;
return True;
failed:
talloc_free(dgmsock);
return False;
} }
/* test UDP/138 netlogon requests */ /* test UDP/138 netlogon requests */
static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx, static bool nbt_test_netlogon2(struct torture_context *tctx)
struct nbt_name name, const char *address)
{ {
struct dgram_mailslot_handler *dgmslot; struct dgram_mailslot_handler *dgmslot;
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
struct socket_address *dest; struct socket_address *dest;
const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); const char *myaddress;
struct nbt_netlogon_packet logon; struct nbt_netlogon_packet logon;
struct nbt_name myname; struct nbt_name myname;
NTSTATUS status; NTSTATUS status;
@ -155,11 +155,23 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address; 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, socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port()); myaddress, lp_dgram_port());
if (!socket_address) { torture_assert(tctx, socket_address != NULL, "Error getting address");
return False;
}
/* try receiving replies on port 138 first, which will only /* try receiving replies on port 138 first, which will only
work if we are root and smbd/nmbd are not running - fall work if we are root and smbd/nmbd are not running - fall
@ -170,9 +182,8 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
talloc_free(socket_address); talloc_free(socket_address);
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, 0); myaddress, 0);
if (!socket_address) {
return False; torture_assert(tctx, socket_address != NULL, "Error getting address");
}
socket_listen(dgmsock->sock, socket_address, 0, 0); socket_listen(dgmsock->sock, socket_address, 0, 0);
} }
@ -196,27 +207,17 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
address, 0); address, 0);
if (!dest) {
goto failed; torture_assert(tctx, dest != NULL, "Error getting address");
}
status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, status = dgram_mailslot_netlogon_send(dgmsock, &name, dest,
&myname, &logon); &myname, &logon);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request");
printf("Failed to send netlogon request - %s\n", nt_errstr(status));
goto failed;
}
while (timeval_elapsed(&tv) < 5 && replies == 0) { while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx); event_loop_once(dgmsock->event_ctx);
} }
talloc_free(dgmsock); return true;
return True;
failed:
talloc_free(dgmsock);
return False;
} }
@ -247,17 +248,16 @@ static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot,
/* test UDP/138 ntlogon requests */ /* test UDP/138 ntlogon requests */
static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx, static bool nbt_test_ntlogon(struct torture_context *tctx)
struct nbt_name name, const char *address)
{ {
struct dgram_mailslot_handler *dgmslot; struct dgram_mailslot_handler *dgmslot;
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
struct socket_address *dest; struct socket_address *dest;
struct test_join *join_ctx; struct test_join *join_ctx;
struct cli_credentials *machine_credentials; struct cli_credentials *machine_credentials;
const struct dom_sid *dom_sid; const struct dom_sid *dom_sid;
const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); const char *myaddress;
struct nbt_ntlogon_packet logon; struct nbt_ntlogon_packet logon;
struct nbt_name myname; struct nbt_name myname;
NTSTATUS status; NTSTATUS status;
@ -265,12 +265,23 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
int replies = 0; int replies = 0;
struct socket_address *socket_address; 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, socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port()); myaddress, lp_dgram_port());
if (!socket_address) { torture_assert(tctx, socket_address != NULL, "Error getting address");
return False;
}
/* try receiving replies on port 138 first, which will only /* try receiving replies on port 138 first, which will only
work if we are root and smbd/nmbd are not running - fall work if we are root and smbd/nmbd are not running - fall
@ -281,20 +292,15 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
talloc_free(socket_address); talloc_free(socket_address);
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, 0); myaddress, 0);
if (!socket_address) { torture_assert(tctx, socket_address != NULL, "Error getting address");
return False;
}
socket_listen(dgmsock->sock, socket_address, 0, 0); socket_listen(dgmsock->sock, socket_address, 0, 0);
} }
join_ctx = torture_join_domain(TEST_NAME, join_ctx = torture_join_domain(TEST_NAME,
ACB_WSTRUST, &machine_credentials); ACB_WSTRUST, &machine_credentials);
if (join_ctx == NULL) { torture_assert(tctx, join_ctx != NULL,
printf("Failed to join domain %s as %s\n", lp_workgroup(), TEST_NAME); talloc_asprintf(tctx, "Failed to join domain %s as %s\n", lp_workgroup(), TEST_NAME));
talloc_free(dgmsock);
return False;
}
dom_sid = torture_join_sid(join_ctx); dom_sid = torture_join_sid(join_ctx);
@ -319,61 +325,31 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
address, 0); address, 0);
if (!dest) { torture_assert(tctx, dest != NULL, "Error getting address");
goto failed;
}
status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE, status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE,
&name, dest, &myname, &logon); &name, dest, &myname, &logon);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request");
printf("Failed to send ntlogon request - %s\n", nt_errstr(status));
goto failed;
}
while (timeval_elapsed(&tv) < 5 && replies == 0) { while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx); event_loop_once(dgmsock->event_ctx);
} }
torture_leave_domain(join_ctx); torture_leave_domain(join_ctx);
talloc_free(dgmsock); return true;
return True;
failed:
torture_leave_domain(join_ctx);
talloc_free(dgmsock);
return False;
} }
/* /*
test nbt dgram operations test nbt dgram operations
*/ */
BOOL torture_nbt_dgram(struct torture_context *torture) struct torture_suite *torture_nbt_dgram(void)
{ {
const char *address; struct torture_suite *suite = torture_suite_create(talloc_autofree_context(),
struct nbt_name name; "DGRAM");
TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
BOOL ret = True;
name.name = lp_workgroup();
name.type = NBT_NAME_LOGON;
name.scope = NULL;
/* do an initial name resolution to find its IP */ torture_suite_add_simple_test(suite, "netlogon", nbt_test_netlogon);
status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx)); torture_suite_add_simple_test(suite, "netlogon2", nbt_test_netlogon2);
if (!NT_STATUS_IS_OK(status)) { torture_suite_add_simple_test(suite, "ntlogon", nbt_test_ntlogon);
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
talloc_free(mem_ctx);
return False;
}
ret &= nbt_test_netlogon(mem_ctx, name, address); return suite;
ret &= nbt_test_netlogon2(mem_ctx, name, address);
ret &= nbt_test_ntlogon(mem_ctx, name, address);
talloc_free(mem_ctx);
return ret;
} }

View File

@ -21,19 +21,42 @@
#include "includes.h" #include "includes.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "torture/nbt/proto.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) NTSTATUS torture_nbt_init(void)
{ {
struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"NBT");
/* nbt tests */ /* nbt tests */
register_torture_op("NBT-REGISTER", torture_nbt_register); torture_suite_add_suite(suite, torture_nbt_register());
register_torture_op("NBT-WINS", torture_nbt_wins); torture_suite_add_suite(suite, torture_nbt_wins());
register_torture_op("NBT-DGRAM", torture_nbt_dgram); torture_suite_add_suite(suite, torture_nbt_dgram());
register_torture_op("NBT-BROWSE", torture_nbt_browse); torture_suite_add_suite(suite, torture_nbt_winsreplication());
register_torture_op("NBT-WINSREPLICATION-SIMPLE", torture_nbt_winsreplication_simple); torture_suite_add_suite(suite, torture_bench_nbt());
register_torture_op("NBT-WINSREPLICATION-REPLICA", torture_nbt_winsreplication_replica); torture_suite_add_suite(suite, torture_bench_wins());
register_torture_op("NBT-WINSREPLICATION-OWNED", torture_nbt_winsreplication_owned);
register_torture_op("BENCH-WINS", torture_bench_wins); suite->description = talloc_strdup(suite,
register_torture_op("BENCH-NBT", torture_bench_nbt); "NetBIOS over TCP/IP and WINS tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -24,6 +24,7 @@
#include "lib/events/events.h" #include "lib/events/events.h"
#include "libcli/resolve/resolve.h" #include "libcli/resolve/resolve.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "torture/nbt/proto.h"
struct result_struct { struct result_struct {
int num_pass; int num_pass;
@ -44,39 +45,40 @@ static void increment_handler(struct nbt_name_request *req)
/* /*
benchmark simple name queries benchmark simple name queries
*/ */
static BOOL bench_namequery(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *address) static bool bench_namequery(struct torture_context *tctx)
{ {
struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
int num_sent=0; int num_sent=0;
struct result_struct *result; struct result_struct *result;
struct nbt_name_query io; struct nbt_name_query io;
struct timeval tv = timeval_current(); struct timeval tv = timeval_current();
BOOL ret = True; int timelimit = torture_setting_int(tctx, "timelimit", 10);
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
io.in.name = *name; 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.dest_addr = address;
io.in.broadcast = False; io.in.broadcast = False;
io.in.wins_lookup = False; io.in.wins_lookup = False;
io.in.timeout = 1; io.in.timeout = 1;
result = talloc_zero(mem_ctx, struct result_struct); result = talloc_zero(tctx, struct result_struct);
printf("Running for %d seconds\n", timelimit); torture_comment(tctx, "Running for %d seconds\n", timelimit);
while (timeval_elapsed(&tv) < timelimit) { while (timeval_elapsed(&tv) < timelimit) {
while (num_sent - (result->num_pass+result->num_fail) < 10) { while (num_sent - (result->num_pass+result->num_fail) < 10) {
struct nbt_name_request *req; struct nbt_name_request *req;
req = nbt_name_query_send(nbtsock, &io); req = nbt_name_query_send(nbtsock, &io);
if (req == NULL) { torture_assert(tctx, req != NULL, "Failed to setup request!");
printf("Failed to setup request!\n");
ret = False;
goto failed;
}
req->async.fn = increment_handler; req->async.fn = increment_handler;
req->async.private = result; req->async.private = result;
num_sent++; num_sent++;
if (num_sent % 1000 == 0) { if (num_sent % 1000 == 0) {
printf("%.1f queries per second (%d failures) \r", torture_comment(tctx, "%.1f queries per second (%d failures) \r",
result->num_pass / timeval_elapsed(&tv), result->num_pass / timeval_elapsed(&tv),
result->num_fail); result->num_fail);
} }
@ -89,41 +91,22 @@ static BOOL bench_namequery(TALLOC_CTX *mem_ctx, struct nbt_name *name, const ch
event_loop_once(nbtsock->event_ctx); event_loop_once(nbtsock->event_ctx);
} }
printf("%.1f queries per second (%d failures) \n", torture_comment(tctx, "%.1f queries per second (%d failures) \n",
result->num_pass / timeval_elapsed(&tv), result->num_pass / timeval_elapsed(&tv),
result->num_fail); result->num_fail);
failed: return true;
talloc_free(nbtsock);
return ret;
} }
/* /*
benchmark how fast a server can respond to name queries benchmark how fast a server can respond to name queries
*/ */
BOOL torture_bench_nbt(struct torture_context *torture) struct torture_suite *torture_bench_nbt(void)
{ {
const char *address; struct torture_suite *suite = torture_suite_create(talloc_autofree_context(),
struct nbt_name name; "BENCH");
TALLOC_CTX *mem_ctx = talloc_new(NULL); torture_suite_add_simple_test(suite, "namequery", bench_namequery);
NTSTATUS status;
BOOL ret = True;
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */ return suite;
status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
talloc_free(mem_ctx);
return False;
}
ret &= bench_namequery(mem_ctx, &name, address);
talloc_free(mem_ctx);
return ret;
} }

View File

@ -26,49 +26,46 @@
#include "system/network.h" #include "system/network.h"
#include "lib/socket/netif.h" #include "lib/socket/netif.h"
#include "torture/torture.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_VALUE(v, correct) do { \
if ((v) != (correct)) { \
printf("(%s) Incorrect value %s=%d - should be %d\n", \
__location__, #v, (int)v, (int)correct); \
ret = False; \
}} while (0)
#define CHECK_STRING(v, correct) do { \
if (strcasecmp_m(v, correct) != 0) { \
printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
__location__, #v, v, correct); \
ret = False; \
}} while (0)
/* /*
test that a server responds correctly to attempted registrations of its name test that a server responds correctly to attempted registrations of its name
*/ */
static BOOL nbt_register_own(TALLOC_CTX *mem_ctx, struct nbt_name *name, static bool nbt_register_own(struct torture_context *tctx)
const char *address)
{ {
struct nbt_name_register io; struct nbt_name_register io;
NTSTATUS status; NTSTATUS status;
struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
BOOL ret = True;
const char *myaddress = iface_best_ip(address);
struct socket_address *socket_address; struct socket_address *socket_address;
struct nbt_name name;
const char *address;
const char *myaddress;
socket_address = socket_address_from_strings(mem_ctx, nbtsock->sock->backend_name, 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); myaddress, 0);
if (!socket_address) { torture_assert(tctx, socket_address != NULL, "Unable to get address");
return False;
}
status = socket_listen(nbtsock->sock, socket_address, 0, 0); status = socket_listen(nbtsock->sock, socket_address, 0, 0);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("socket_listen for nbt_register_own failed: %s\n", nt_errstr(status)); "socket_listen for nbt_register_own failed");
return False;
}
printf("Testing name defense to name registration\n"); torture_comment(tctx, "Testing name defense to name registration\n");
io.in.name = *name; io.in.name = name;
io.in.dest_addr = address; io.in.dest_addr = address;
io.in.address = myaddress; io.in.address = myaddress;
io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE; io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE;
@ -79,72 +76,62 @@ static BOOL nbt_register_own(TALLOC_CTX *mem_ctx, struct nbt_name *name,
io.in.timeout = 3; io.in.timeout = 3;
io.in.retries = 0; io.in.retries = 0;
status = nbt_name_register(nbtsock, mem_ctx, &io); status = nbt_name_register(nbtsock, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_ok(tctx, status,
printf("No response from %s for name register\n", address); talloc_asprintf(tctx, "Bad response from %s for name register",
return False; address));
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name register - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_STRING(io.out.name.name, name->name); CHECK_STRING(tctx, io.out.name.name, name.name);
CHECK_VALUE(io.out.name.type, name->type); CHECK_VALUE(tctx, io.out.name.type, name.type);
CHECK_VALUE(io.out.rcode, NBT_RCODE_ACT); CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
/* check a register demand */ /* check a register demand */
io.in.address = myaddress; io.in.address = myaddress;
io.in.register_demand = True; io.in.register_demand = True;
status = nbt_name_register(nbtsock, mem_ctx, &io); status = nbt_name_register(nbtsock, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
printf("No response from %s for name register demand\n", address);
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name register demand - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_STRING(io.out.name.name, name->name);
CHECK_VALUE(io.out.name.type, name->type);
CHECK_VALUE(io.out.rcode, NBT_RCODE_ACT);
return ret; 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 test that a server responds correctly to attempted name refresh requests
*/ */
static BOOL nbt_refresh_own(TALLOC_CTX *mem_ctx, struct nbt_name *name, static bool nbt_refresh_own(struct torture_context *tctx)
const char *address)
{ {
struct nbt_name_refresh io; struct nbt_name_refresh io;
NTSTATUS status; NTSTATUS status;
struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
BOOL ret = True; const char *myaddress;
const char *myaddress = iface_best_ip(address);
struct socket_address *socket_address; struct socket_address *socket_address;
struct nbt_name name;
const char *address;
socket_address = socket_address_from_strings(mem_ctx, nbtsock->sock->backend_name, 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); myaddress, 0);
if (!socket_address) { torture_assert(tctx, socket_address != NULL,
return False; "Can't parse socket address");
}
status = socket_listen(nbtsock->sock, socket_address, 0, 0); status = socket_listen(nbtsock->sock, socket_address, 0, 0);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("socket_listen for nbt_referesh_own failed: %s\n", nt_errstr(status)); "socket_listen for nbt_referesh_own failed");
return False;
}
printf("Testing name defense to name refresh\n"); torture_comment(tctx, "Testing name defense to name refresh\n");
io.in.name = *name; io.in.name = name;
io.in.dest_addr = address; io.in.dest_addr = address;
io.in.address = myaddress; io.in.address = myaddress;
io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE; io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE;
@ -153,52 +140,29 @@ static BOOL nbt_refresh_own(TALLOC_CTX *mem_ctx, struct nbt_name *name,
io.in.timeout = 3; io.in.timeout = 3;
io.in.retries = 0; io.in.retries = 0;
status = nbt_name_refresh(nbtsock, mem_ctx, &io); status = nbt_name_refresh(nbtsock, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
printf("No response from %s for name refresh\n", address); torture_assert_ntstatus_ok(tctx, status,
return False; talloc_asprintf(tctx, "Bad response from %s for name refresh", address));
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name refresh - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_STRING(io.out.name.name, name->name); CHECK_STRING(tctx, io.out.name.name, name.name);
CHECK_VALUE(io.out.name.type, name->type); CHECK_VALUE(tctx, io.out.name.type, name.type);
CHECK_VALUE(io.out.rcode, NBT_RCODE_ACT); CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
return ret; return true;
} }
/* /*
test name registration to a server test name registration to a server
*/ */
BOOL torture_nbt_register(struct torture_context *torture) struct torture_suite *torture_nbt_register(void)
{ {
const char *address; struct torture_suite *suite;
struct nbt_name name;
TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
BOOL ret = True;
make_nbt_name_server(&name, strupper_talloc(mem_ctx, lp_parm_string(-1, "torture", "host")));
/* do an initial name resolution to find its IP */ suite = torture_suite_create(talloc_autofree_context(), "REGISTER");
status = resolve_name(&name, mem_ctx, &address, NULL); torture_suite_add_simple_test(suite, "register_own", nbt_register_own);
if (!NT_STATUS_IS_OK(status)) { torture_suite_add_simple_test(suite, "refresh_own", nbt_refresh_own);
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
talloc_free(mem_ctx);
return False;
}
ret &= nbt_register_own(mem_ctx, &name, address); return suite;
ret &= nbt_refresh_own(mem_ctx, &name, address);
talloc_free(mem_ctx);
return ret;
} }

View File

@ -27,33 +27,25 @@
#include "lib/socket/netif.h" #include "lib/socket/netif.h"
#include "librpc/gen_ndr/ndr_nbt.h" #include "librpc/gen_ndr/ndr_nbt.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "torture/nbt/proto.h"
#define CHECK_VALUE(v, correct) do { \ #define CHECK_VALUE(tctx, v, correct) \
if ((v) != (correct)) { \ torture_assert_int_equal(tctx, v, correct, "Incorrect value")
printf("(%s) Incorrect value %s=%d (0x%X) - should be %d (0x%X)\n", \
__location__, #v, v, v, correct, correct); \
ret = False; \
}} while (0)
#define CHECK_STRING(v, correct) do { \ #define CHECK_STRING(tctx, v, correct) \
if ((v) != (correct) && \ torture_assert_casestr_equal(tctx, v, correct, "Incorrect value")
((v)==NULL || (correct)==NULL || strcasecmp_m(v, correct) != 0)) { \
printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
__location__, #v, v, correct); \
ret = False; \
}} while (0)
#define CHECK_NAME(_name, correct) do { \ #define CHECK_NAME(tctx, _name, correct) do { \
CHECK_STRING((_name).name, (correct).name); \ CHECK_STRING(tctx, (_name).name, (correct).name); \
CHECK_VALUE((uint8_t)(_name).type, (uint8_t)(correct).type); \ CHECK_VALUE(tctx, (uint8_t)(_name).type, (uint8_t)(correct).type); \
CHECK_STRING((_name).scope, (correct).scope); \ CHECK_STRING(tctx, (_name).scope, (correct).scope); \
} while (0) } while (0)
/* /*
test operations against a WINS server test operations against a WINS server
*/ */
static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address, static bool nbt_test_wins_name(struct torture_context *tctx, const char *address,
struct nbt_name *name, uint16_t nb_flags) struct nbt_name *name, uint16_t nb_flags)
{ {
struct nbt_name_register_wins io; struct nbt_name_register_wins io;
@ -61,31 +53,27 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
struct nbt_name_refresh_wins refresh; struct nbt_name_refresh_wins refresh;
struct nbt_name_release release; struct nbt_name_release release;
NTSTATUS status; NTSTATUS status;
struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
BOOL ret = True; const char *myaddress = talloc_strdup(tctx, iface_best_ip(address));
const char *myaddress = talloc_strdup(mem_ctx, iface_best_ip(address));
struct socket_address *socket_address; struct socket_address *socket_address;
socket_address = socket_address_from_strings(mem_ctx, socket_address = socket_address_from_strings(tctx,
nbtsock->sock->backend_name, nbtsock->sock->backend_name,
myaddress, 0); myaddress, 0);
if (!socket_address) { torture_assert(tctx, socket_address != NULL,
return False; "Error getting address");
}
/* we do the listen here to ensure the WINS server receives the packets from /* we do the listen here to ensure the WINS server receives the packets from
the right IP */ the right IP */
status = socket_listen(nbtsock->sock, socket_address, 0, 0); status = socket_listen(nbtsock->sock, socket_address, 0, 0);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("socket_listen for WINS failed: %s\n", nt_errstr(status)); "socket_listen for WINS failed");
return False;
}
talloc_free(socket_address); talloc_free(socket_address);
printf("Testing name registration to WINS with name %s at %s nb_flags=0x%x\n", torture_comment(tctx, "Testing name registration to WINS with name %s at %s nb_flags=0x%x\n",
nbt_name_string(mem_ctx, name), myaddress, nb_flags); nbt_name_string(tctx, name), myaddress, nb_flags);
printf("release the name\n"); torture_comment(tctx, "release the name\n");
release.in.name = *name; release.in.name = *name;
release.in.dest_addr = address; release.in.dest_addr = address;
release.in.address = myaddress; release.in.address = myaddress;
@ -94,55 +82,36 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
release.in.timeout = 3; release.in.timeout = 3;
release.in.retries = 0; release.in.retries = 0;
status = nbt_name_release(nbtsock, mem_ctx, &release); status = nbt_name_release(nbtsock, tctx, &release);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name query", address));
printf("No response from %s for name release\n", address); CHECK_VALUE(tctx, release.out.rcode, 0);
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name query - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_VALUE(release.out.rcode, 0);
printf("register the name\n"); torture_comment(tctx, "register the name\n");
io.in.name = *name; io.in.name = *name;
io.in.wins_servers = str_list_make(mem_ctx, address, NULL); io.in.wins_servers = str_list_make(tctx, address, NULL);
io.in.addresses = str_list_make(mem_ctx, myaddress, NULL); io.in.addresses = str_list_make(tctx, myaddress, NULL);
io.in.nb_flags = nb_flags; io.in.nb_flags = nb_flags;
io.in.ttl = 300000; io.in.ttl = 300000;
status = nbt_name_register_wins(nbtsock, mem_ctx, &io); status = nbt_name_register_wins(nbtsock, tctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name register", address));
printf("No response from %s for name register\n", address);
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name register - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_STRING(io.out.wins_server, address); CHECK_STRING(tctx, io.out.wins_server, address);
CHECK_VALUE(io.out.rcode, 0); CHECK_VALUE(tctx, io.out.rcode, 0);
if (name->type != NBT_NAME_MASTER && if (name->type != NBT_NAME_MASTER &&
name->type != NBT_NAME_LOGON && name->type != NBT_NAME_LOGON &&
name->type != NBT_NAME_BROWSER && name->type != NBT_NAME_BROWSER &&
(nb_flags & NBT_NM_GROUP)) { (nb_flags & NBT_NM_GROUP)) {
printf("Try to register as non-group\n"); torture_comment(tctx, "Try to register as non-group\n");
io.in.nb_flags &= ~NBT_NM_GROUP; io.in.nb_flags &= ~NBT_NM_GROUP;
status = nbt_name_register_wins(nbtsock, mem_ctx, &io); status = nbt_name_register_wins(nbtsock, tctx, &io);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name register\n",
printf("Bad response from %s for name register - %s\n", address));
address, nt_errstr(status)); CHECK_VALUE(tctx, io.out.rcode, NBT_RCODE_ACT);
return False;
}
CHECK_VALUE(io.out.rcode, NBT_RCODE_ACT);
} }
printf("query the name to make sure its there\n"); torture_comment(tctx, "query the name to make sure its there\n");
query.in.name = *name; query.in.name = *name;
query.in.dest_addr = address; query.in.dest_addr = address;
query.in.broadcast = False; query.in.broadcast = False;
@ -150,92 +119,58 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
query.in.timeout = 3; query.in.timeout = 3;
query.in.retries = 0; query.in.retries = 0;
status = nbt_name_query(nbtsock, mem_ctx, &query); status = nbt_name_query(nbtsock, tctx, &query);
if (name->type == NBT_NAME_MASTER) { if (name->type == NBT_NAME_MASTER) {
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { torture_assert_ntstatus_equal(
printf("Bad response from %s for name query - %s\n", tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
address, nt_errstr(status)); talloc_asprintf(tctx, "Bad response from %s for name query", address));
return False; return true;
}
return ret;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
printf("No response from %s for name query\n", address);
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name query - %s\n",
address, nt_errstr(status));
return False;
} }
torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name query", address));
CHECK_NAME(query.out.name, *name); CHECK_NAME(tctx, query.out.name, *name);
CHECK_VALUE(query.out.num_addrs, 1); CHECK_VALUE(tctx, query.out.num_addrs, 1);
if (name->type != NBT_NAME_LOGON && if (name->type != NBT_NAME_LOGON &&
(nb_flags & NBT_NM_GROUP)) { (nb_flags & NBT_NM_GROUP)) {
CHECK_STRING(query.out.reply_addrs[0], "255.255.255.255"); CHECK_STRING(tctx, query.out.reply_addrs[0], "255.255.255.255");
} else { } else {
CHECK_STRING(query.out.reply_addrs[0], myaddress); CHECK_STRING(tctx, query.out.reply_addrs[0], myaddress);
} }
query.in.name.name = strupper_talloc(mem_ctx, name->name); query.in.name.name = strupper_talloc(tctx, name->name);
if (query.in.name.name && if (query.in.name.name &&
strcmp(query.in.name.name, name->name) != 0) { strcmp(query.in.name.name, name->name) != 0) {
printf("check case sensitivity\n"); torture_comment(tctx, "check case sensitivity\n");
status = nbt_name_query(nbtsock, mem_ctx, &query); status = nbt_name_query(nbtsock, tctx, &query);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, talloc_asprintf(tctx, "Bad response from %s for name query", address));
printf("No response from %s for name query\n", address);
return False;
}
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
printf("Bad response from %s for name query - %s\n",
address, nt_errstr(status));
return False;
}
} }
query.in.name = *name; query.in.name = *name;
if (name->scope) { if (name->scope) {
query.in.name.scope = strupper_talloc(mem_ctx, name->scope); query.in.name.scope = strupper_talloc(tctx, name->scope);
} }
if (query.in.name.scope && if (query.in.name.scope &&
strcmp(query.in.name.scope, name->scope) != 0) { strcmp(query.in.name.scope, name->scope) != 0) {
printf("check case sensitivity on scope\n"); torture_comment(tctx, "check case sensitivity on scope\n");
status = nbt_name_query(nbtsock, mem_ctx, &query); status = nbt_name_query(nbtsock, tctx, &query);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, talloc_asprintf(tctx, "Bad response from %s for name query", address));
printf("No response from %s for name query\n", address);
return False;
}
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
printf("Bad response from %s for name query - %s\n",
address, nt_errstr(status));
return False;
}
} }
printf("refresh the name\n"); torture_comment(tctx, "refresh the name\n");
refresh.in.name = *name; refresh.in.name = *name;
refresh.in.wins_servers = str_list_make(mem_ctx, address, NULL); refresh.in.wins_servers = str_list_make(tctx, address, NULL);
refresh.in.addresses = str_list_make(mem_ctx, myaddress, NULL); refresh.in.addresses = str_list_make(tctx, myaddress, NULL);
refresh.in.nb_flags = nb_flags; refresh.in.nb_flags = nb_flags;
refresh.in.ttl = 12345; refresh.in.ttl = 12345;
status = nbt_name_refresh_wins(nbtsock, mem_ctx, &refresh); status = nbt_name_refresh_wins(nbtsock, tctx, &refresh);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name refresh", address));
printf("No response from %s for name refresh\n", address);
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name refresh - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_STRING(refresh.out.wins_server, address); CHECK_STRING(tctx, refresh.out.wins_server, address);
CHECK_VALUE(refresh.out.rcode, 0); CHECK_VALUE(tctx, refresh.out.rcode, 0);
printf("release the name\n"); torture_comment(tctx, "release the name\n");
release.in.name = *name; release.in.name = *name;
release.in.dest_addr = address; release.in.dest_addr = address;
release.in.address = myaddress; release.in.address = myaddress;
@ -244,59 +179,36 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
release.in.timeout = 3; release.in.timeout = 3;
release.in.retries = 0; release.in.retries = 0;
status = nbt_name_release(nbtsock, mem_ctx, &release); status = nbt_name_release(nbtsock, tctx, &release);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "Bad response from %s for name query", address));
printf("No response from %s for name release\n", address);
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name query - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_NAME(release.out.name, *name); CHECK_NAME(tctx, release.out.name, *name);
CHECK_VALUE(release.out.rcode, 0); CHECK_VALUE(tctx, release.out.rcode, 0);
torture_comment(tctx, "release again\n");
printf("release again\n"); status = nbt_name_release(nbtsock, tctx, &release);
status = nbt_name_release(nbtsock, mem_ctx, &release); torture_assert_ntstatus_ok(tctx, status,
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { talloc_asprintf(tctx, "Bad response from %s for name query",
printf("No response from %s for name release\n", address); address));
return False;
}
if (!NT_STATUS_IS_OK(status)) {
printf("Bad response from %s for name query - %s\n",
address, nt_errstr(status));
return False;
}
CHECK_NAME(release.out.name, *name); CHECK_NAME(tctx, release.out.name, *name);
CHECK_VALUE(release.out.rcode, 0); CHECK_VALUE(tctx, release.out.rcode, 0);
printf("query the name to make sure its gone\n"); torture_comment(tctx, "query the name to make sure its gone\n");
query.in.name = *name; query.in.name = *name;
status = nbt_name_query(nbtsock, mem_ctx, &query); status = nbt_name_query(nbtsock, tctx, &query);
if (name->type != NBT_NAME_LOGON && if (name->type != NBT_NAME_LOGON &&
(nb_flags & NBT_NM_GROUP)) { (nb_flags & NBT_NM_GROUP)) {
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("ERROR: Name query failed after group release - %s\n", "ERROR: Name query failed after group release");
nt_errstr(status));
return False;
}
} else { } else {
if (NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_equal(tctx, status,
printf("ERROR: Name query success after release\n"); NT_STATUS_OBJECT_NAME_NOT_FOUND,
return False; "Incorrect response to name query");
}
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
printf("Incorrect response to name query - %s\n", nt_errstr(status));
return False;
}
} }
return ret; return true;
} }
@ -304,64 +216,68 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
/* /*
test operations against a WINS server test operations against a WINS server
*/ */
static BOOL nbt_test_wins(TALLOC_CTX *mem_ctx, const char *address) static bool nbt_test_wins(struct torture_context *tctx)
{ {
struct nbt_name name; struct nbt_name name;
BOOL ret = True;
uint32_t r = (uint32_t)(random() % (100000)); uint32_t r = (uint32_t)(random() % (100000));
const char *address;
bool ret = true;
name.name = talloc_asprintf(mem_ctx, "_TORTURE-%5u", r); if (!torture_nbt_get_name(tctx, &name, &address))
return false;
name.name = talloc_asprintf(tctx, "_TORTURE-%5u", r);
name.type = NBT_NAME_CLIENT; name.type = NBT_NAME_CLIENT;
name.scope = NULL; name.scope = NULL;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.type = NBT_NAME_MASTER; name.type = NBT_NAME_MASTER;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H | NBT_NM_GROUP); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
name.type = NBT_NAME_SERVER; name.type = NBT_NAME_SERVER;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.type = NBT_NAME_LOGON; name.type = NBT_NAME_LOGON;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H | NBT_NM_GROUP); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
name.type = NBT_NAME_BROWSER; name.type = NBT_NAME_BROWSER;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H | NBT_NM_GROUP); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
name.type = NBT_NAME_PDC; name.type = NBT_NAME_PDC;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.type = 0xBF; name.type = 0xBF;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.type = 0xBE; name.type = 0xBE;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.scope = "example"; name.scope = "example";
name.type = 0x72; name.type = 0x72;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.scope = "example"; name.scope = "example";
name.type = 0x71; name.type = 0x71;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H | NBT_NM_GROUP); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
name.scope = "foo.example.com"; name.scope = "foo.example.com";
name.type = 0x72; name.type = 0x72;
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.name = talloc_asprintf(mem_ctx, "_T\01-%5u.foo", r); name.name = talloc_asprintf(tctx, "_T\01-%5u.foo", r);
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.name = ""; name.name = "";
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.name = talloc_asprintf(mem_ctx, "."); name.name = talloc_asprintf(tctx, ".");
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
name.name = talloc_asprintf(mem_ctx, "%5u-\377\200\300FOO", r); name.name = talloc_asprintf(tctx, "%5u-\377\200\300FOO", r);
ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H); ret &= nbt_test_wins_name(tctx, address, &name, NBT_NODE_H);
return ret; return ret;
} }
@ -369,28 +285,12 @@ static BOOL nbt_test_wins(TALLOC_CTX *mem_ctx, const char *address)
/* /*
test WINS operations test WINS operations
*/ */
BOOL torture_nbt_wins(struct torture_context *torture) struct torture_suite *torture_nbt_wins(void)
{ {
const char *address; struct torture_suite *suite = torture_suite_create(talloc_autofree_context(),
struct nbt_name name; "WINS");
TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
BOOL ret = True;
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */ torture_suite_add_simple_test(suite, "wins", nbt_test_wins);
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;
}
ret &= nbt_test_wins(mem_ctx, address); return suite;
talloc_free(mem_ctx);
return ret;
} }

View File

@ -27,10 +27,11 @@
#include "system/network.h" #include "system/network.h"
#include "lib/socket/netif.h" #include "lib/socket/netif.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "torture/nbt/proto.h"
struct wins_state { struct wins_state {
int num_names; int num_names;
BOOL *registered; bool *registered;
int pass_count; int pass_count;
int fail_count; int fail_count;
const char *wins_server; const char *wins_server;
@ -43,10 +44,10 @@ struct idx_state {
struct wins_state *state; struct wins_state *state;
}; };
struct nbt_name generate_name(TALLOC_CTX *mem_ctx, int idx) struct nbt_name generate_name(TALLOC_CTX *tctx, int idx)
{ {
struct nbt_name name; struct nbt_name name;
name.name = talloc_asprintf(mem_ctx, "WINSBench%6u", idx); name.name = talloc_asprintf(tctx, "WINSBench%6u", idx);
name.type = 0x4; name.type = 0x4;
name.scope = NULL; name.scope = NULL;
return name; return name;
@ -64,7 +65,7 @@ static void register_handler(struct nbt_name_request *req)
state->fail_count++; state->fail_count++;
} else { } else {
state->pass_count++; state->pass_count++;
state->registered[istate->idx] = True; state->registered[istate->idx] = true;
} }
talloc_free(istate); talloc_free(istate);
} }
@ -87,9 +88,9 @@ static void generate_register(struct nbt_name_socket *nbtsock, struct wins_state
io.in.dest_addr = state->wins_server; io.in.dest_addr = state->wins_server;
io.in.address = state->my_ip; io.in.address = state->my_ip;
io.in.nb_flags = NBT_NODE_H; io.in.nb_flags = NBT_NODE_H;
io.in.register_demand = False; io.in.register_demand = false;
io.in.broadcast = False; io.in.broadcast = false;
io.in.multi_homed = False; io.in.multi_homed = false;
io.in.ttl = state->ttl; io.in.ttl = state->ttl;
io.in.timeout = 2; io.in.timeout = 2;
io.in.retries = 1; io.in.retries = 1;
@ -116,7 +117,7 @@ static void release_handler(struct nbt_name_request *req)
state->fail_count++; state->fail_count++;
} else { } else {
state->pass_count++; state->pass_count++;
state->registered[istate->idx] = False; state->registered[istate->idx] = false;
} }
talloc_free(istate); talloc_free(istate);
} }
@ -139,7 +140,7 @@ static void generate_release(struct nbt_name_socket *nbtsock, struct wins_state
io.in.dest_addr = state->wins_server; io.in.dest_addr = state->wins_server;
io.in.address = state->my_ip; io.in.address = state->my_ip;
io.in.nb_flags = NBT_NODE_H; io.in.nb_flags = NBT_NODE_H;
io.in.broadcast = False; io.in.broadcast = false;
io.in.timeout = 2; io.in.timeout = 2;
io.in.retries = 1; io.in.retries = 1;
@ -184,8 +185,8 @@ static void generate_query(struct nbt_name_socket *nbtsock, struct wins_state *s
io.in.name = generate_name(tmp_ctx, idx); io.in.name = generate_name(tmp_ctx, idx);
io.in.dest_addr = state->wins_server; io.in.dest_addr = state->wins_server;
io.in.broadcast = False; io.in.broadcast = false;
io.in.wins_lookup = True; io.in.wins_lookup = true;
io.in.timeout = 2; io.in.timeout = 2;
io.in.retries = 1; io.in.retries = 1;
@ -218,23 +219,28 @@ static void generate_request(struct nbt_name_socket *nbtsock, struct wins_state
/* /*
benchmark simple name queries benchmark simple name queries
*/ */
static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *address) static bool bench_wins(struct torture_context *tctx)
{ {
struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL);
int num_sent=0; int num_sent=0;
struct timeval tv = timeval_current(); struct timeval tv = timeval_current();
BOOL ret = True; bool ret = true;
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); int timelimit = torture_setting_int(tctx, "timelimit", 10);
struct wins_state *state; struct wins_state *state;
extern int torture_entries; extern int torture_entries;
struct socket_address *my_ip; 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 = talloc_zero(nbtsock, struct wins_state);
state->num_names = torture_entries; state->num_names = torture_entries;
state->registered = talloc_zero_array(state, BOOL, state->num_names); state->registered = talloc_zero_array(state, bool, state->num_names);
state->wins_server = address; state->wins_server = address;
state->my_ip = talloc_strdup(mem_ctx, iface_best_ip(address)); state->my_ip = talloc_strdup(tctx, iface_best_ip(address));
state->ttl = timelimit; state->ttl = timelimit;
my_ip = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name, my_ip = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name,
@ -242,13 +248,13 @@ static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *a
socket_listen(nbtsock->sock, my_ip, 0, 0); socket_listen(nbtsock->sock, my_ip, 0, 0);
printf("Running for %d seconds\n", timelimit); torture_comment(tctx, "Running for %d seconds\n", timelimit);
while (timeval_elapsed(&tv) < timelimit) { while (timeval_elapsed(&tv) < timelimit) {
while (num_sent - (state->pass_count+state->fail_count) < 10) { while (num_sent - (state->pass_count+state->fail_count) < 10) {
generate_request(nbtsock, state, num_sent % state->num_names); generate_request(nbtsock, state, num_sent % state->num_names);
num_sent++; num_sent++;
if (num_sent % 50 == 0) { if (num_sent % 50 == 0) {
printf("%.1f queries per second (%d failures) \r", torture_comment(tctx, "%.1f queries per second (%d failures) \r",
state->pass_count / timeval_elapsed(&tv), state->pass_count / timeval_elapsed(&tv),
state->fail_count); state->fail_count);
} }
@ -261,7 +267,7 @@ static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *a
event_loop_once(nbtsock->event_ctx); event_loop_once(nbtsock->event_ctx);
} }
printf("%.1f queries per second (%d failures) \n", torture_comment(tctx, "%.1f queries per second (%d failures) \n",
state->pass_count / timeval_elapsed(&tv), state->pass_count / timeval_elapsed(&tv),
state->fail_count); state->fail_count);
@ -274,28 +280,13 @@ static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *a
benchmark how fast a WINS server can respond to a mixture of benchmark how fast a WINS server can respond to a mixture of
registration/refresh/release and name query requests registration/refresh/release and name query requests
*/ */
BOOL torture_bench_wins(struct torture_context *torture) struct torture_suite *torture_bench_wins(void)
{ {
const char *address; struct torture_suite *suite = torture_suite_create(
struct nbt_name name; talloc_autofree_context(),
TALLOC_CTX *mem_ctx = talloc_new(NULL); "BENCH-WINS");
NTSTATUS status;
BOOL ret = True;
make_nbt_name_server(&name, lp_parm_string(-1, "torture", "host"));
/* do an initial name resolution to find its IP */ torture_suite_add_simple_test(suite, "wins", bench_wins);
status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
talloc_free(mem_ctx);
return False;
}
ret &= bench_wins(mem_ctx, &name, address); return suite;
talloc_free(mem_ctx);
return ret;
} }

File diff suppressed because it is too large Load Diff

View File

@ -563,8 +563,17 @@ BOOL torture_rap_scan(struct torture_context *torture)
NTSTATUS torture_rap_init(void) NTSTATUS torture_rap_init(void)
{ {
register_torture_op("RAP-BASIC", torture_rap_basic); struct torture_suite *suite = torture_suite_create(
register_torture_op("SCAN-RAP", torture_rap_scan); talloc_autofree_context(),
"RAP");
torture_suite_add_simple_test(suite, "BASIC", torture_rap_basic);
torture_suite_add_simple_test(suite, "SCAN", torture_rap_scan);
suite->description = talloc_strdup(suite,
"Remote Administration Protocol tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -25,37 +25,44 @@
NTSTATUS torture_raw_init(void) NTSTATUS torture_raw_init(void)
{ {
struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"RAW");
/* RAW smb tests */ /* RAW smb tests */
torture_suite_add_simple_test(suite, "BENCH-OPLOCK", torture_bench_oplock);
torture_suite_add_simple_test(suite, "QFSINFO", torture_raw_qfsinfo);
torture_suite_add_simple_test(suite, "QFILEINFO", torture_raw_qfileinfo);
torture_suite_add_simple_test(suite, "SFILEINFO", torture_raw_sfileinfo);
torture_suite_add_simple_test(suite, "SFILEINFO-BUG", torture_raw_sfileinfo_bug);
torture_suite_add_simple_test(suite, "SEARCH", torture_raw_search);
torture_suite_add_simple_test(suite, "CLOSE", torture_raw_close);
torture_suite_add_simple_test(suite, "OPEN", torture_raw_open);
torture_suite_add_simple_test(suite, "MKDIR", torture_raw_mkdir);
torture_suite_add_simple_test(suite, "OPLOCK", torture_raw_oplock);
torture_suite_add_simple_test(suite, "NOTIFY", torture_raw_notify);
torture_suite_add_simple_test(suite, "MUX", torture_raw_mux);
torture_suite_add_simple_test(suite, "IOCTL", torture_raw_ioctl);
torture_suite_add_simple_test(suite, "CHKPATH", torture_raw_chkpath);
torture_suite_add_simple_test(suite, "UNLINK", torture_raw_unlink);
torture_suite_add_simple_test(suite, "READ", torture_raw_read);
torture_suite_add_simple_test(suite, "WRITE", torture_raw_write);
torture_suite_add_simple_test(suite, "LOCK", torture_raw_lock);
torture_suite_add_simple_test(suite, "CONTEXT", torture_raw_context);
torture_suite_add_simple_test(suite, "RENAME", torture_raw_rename);
torture_suite_add_simple_test(suite, "SEEK", torture_raw_seek);
torture_suite_add_simple_test(suite, "EAS", torture_raw_eas);
torture_suite_add_simple_test(suite, "STREAMS", torture_raw_streams);
torture_suite_add_simple_test(suite, "ACLS", torture_raw_acls);
torture_suite_add_simple_test(suite, "COMPOSITE", torture_raw_composite);
torture_suite_add_simple_test(suite, "SAMBA3HIDE", torture_samba3_hide);
torture_suite_add_simple_test(suite, "SAMBA3CHECKFSP", torture_samba3_checkfsp);
torture_suite_add_simple_test(suite, "SAMBA3BADPATH", torture_samba3_badpath);
torture_suite_add_simple_test(suite, "SCAN-EAMAX", torture_max_eas);
register_torture_op("BENCH-OPLOCK", torture_bench_oplock); suite->description = talloc_strdup(suite,
register_torture_op("RAW-QFSINFO", torture_raw_qfsinfo); "Tests for the raw SMB interface");
register_torture_op("RAW-QFILEINFO", torture_raw_qfileinfo);
register_torture_op("RAW-SFILEINFO", torture_raw_sfileinfo); torture_register_suite(suite);
register_torture_op("RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug);
register_torture_op("RAW-SEARCH", torture_raw_search);
register_torture_op("RAW-CLOSE", torture_raw_close);
register_torture_op("RAW-OPEN", torture_raw_open);
register_torture_op("RAW-MKDIR", torture_raw_mkdir);
register_torture_op("RAW-OPLOCK", torture_raw_oplock);
register_torture_op("RAW-NOTIFY", torture_raw_notify);
register_torture_op("RAW-MUX", torture_raw_mux);
register_torture_op("RAW-IOCTL", torture_raw_ioctl);
register_torture_op("RAW-CHKPATH", torture_raw_chkpath);
register_torture_op("RAW-UNLINK", torture_raw_unlink);
register_torture_op("RAW-READ", torture_raw_read);
register_torture_op("RAW-WRITE", torture_raw_write);
register_torture_op("RAW-LOCK", torture_raw_lock);
register_torture_op("RAW-CONTEXT", torture_raw_context);
register_torture_op("RAW-RENAME", torture_raw_rename);
register_torture_op("RAW-SEEK", torture_raw_seek);
register_torture_op("RAW-EAS", torture_raw_eas);
register_torture_op("RAW-STREAMS", torture_raw_streams);
register_torture_op("RAW-ACLS", torture_raw_acls);
register_torture_op("RAW-COMPOSITE", torture_raw_composite);
register_torture_op("RAW-SAMBA3HIDE", torture_samba3_hide);
register_torture_op("RAW-SAMBA3CHECKFSP", torture_samba3_checkfsp);
register_torture_op("RAW-SAMBA3BADPATH", torture_samba3_badpath);
register_torture_op("SCAN-EAMAX", torture_max_eas);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -24,7 +24,7 @@
#include "librpc/gen_ndr/ndr_atsvc_c.h" #include "librpc/gen_ndr/ndr_atsvc_c.h"
#include "torture/rpc/rpc.h" #include "torture/rpc/rpc.h"
static BOOL test_JobGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t job_id) static bool test_JobGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx, uint32_t job_id)
{ {
NTSTATUS status; NTSTATUS status;
struct atsvc_JobGetInfo r; struct atsvc_JobGetInfo r;
@ -32,17 +32,14 @@ static BOOL test_JobGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t
r.in.servername = dcerpc_server_name(p); r.in.servername = dcerpc_server_name(p);
r.in.job_id = job_id; r.in.job_id = job_id;
status = dcerpc_atsvc_JobGetInfo(p, mem_ctx, &r); status = dcerpc_atsvc_JobGetInfo(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "JobGetInfo failed");
printf("JobGetInfo failed - %s\n", nt_errstr(status));
return False;
}
return True; return true;
} }
static BOOL test_JobDel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t min_job_id, static bool test_JobDel(struct dcerpc_pipe *p, struct torture_context *tctx, uint32_t min_job_id,
uint32_t max_job_id) uint32_t max_job_id)
{ {
NTSTATUS status; NTSTATUS status;
@ -52,25 +49,20 @@ static BOOL test_JobDel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t min
r.in.min_job_id = min_job_id; r.in.min_job_id = min_job_id;
r.in.max_job_id = max_job_id; r.in.max_job_id = max_job_id;
status = dcerpc_atsvc_JobDel(p, mem_ctx, &r); status = dcerpc_atsvc_JobDel(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "JobDel failed");
printf("JobDel failed - %s\n", nt_errstr(status));
return False;
}
return True; return true;
} }
static BOOL test_JobEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_JobEnum(struct torture_context *tctx, struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct atsvc_JobEnum r; struct atsvc_JobEnum r;
struct atsvc_enum_ctr ctr; struct atsvc_enum_ctr ctr;
uint32_t resume_handle = 0, i; uint32_t resume_handle = 0, i;
BOOL ret = True; bool ret = true;
printf("\ntesting JobEnum\n");
r.in.servername = dcerpc_server_name(p); r.in.servername = dcerpc_server_name(p);
ctr.entries_read = 0; ctr.entries_read = 0;
@ -79,15 +71,12 @@ static BOOL test_JobEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
r.in.preferred_max_len = 0xffffffff; r.in.preferred_max_len = 0xffffffff;
r.in.resume_handle = r.out.resume_handle = &resume_handle; r.in.resume_handle = r.out.resume_handle = &resume_handle;
status = dcerpc_atsvc_JobEnum(p, mem_ctx, &r); status = dcerpc_atsvc_JobEnum(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "JobEnum failed");
printf("JobEnum failed - %s\n", nt_errstr(status));
return False;
}
for (i = 0; i < r.out.ctr->entries_read; i++) { for (i = 0; i < r.out.ctr->entries_read; i++) {
if (!test_JobGetInfo(p, mem_ctx, r.out.ctr->first_entry[i].job_id)) { if (!test_JobGetInfo(p, tctx, r.out.ctr->first_entry[i].job_id)) {
ret = False; ret = False;
} }
} }
@ -95,14 +84,12 @@ static BOOL test_JobEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
return ret; return ret;
} }
static BOOL test_JobAdd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_JobAdd(struct torture_context *tctx, struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct atsvc_JobAdd r; struct atsvc_JobAdd r;
struct atsvc_JobInfo info; struct atsvc_JobInfo info;
printf("\ntesting JobAdd\n");
r.in.servername = dcerpc_server_name(p); r.in.servername = dcerpc_server_name(p);
info.job_time = 0x050ae4c0; /* 11:30pm */ info.job_time = 0x050ae4c0; /* 11:30pm */
info.days_of_month = 0; /* n/a */ info.days_of_month = 0; /* n/a */
@ -111,56 +98,39 @@ static BOOL test_JobAdd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
info.command = "foo.exe"; info.command = "foo.exe";
r.in.job_info = &info; r.in.job_info = &info;
status = dcerpc_atsvc_JobAdd(p, mem_ctx, &r); status = dcerpc_atsvc_JobAdd(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "JobAdd failed");
printf("JobAdd failed - %s\n", nt_errstr(status));
return False;
}
/* Run EnumJobs again in case there were no jobs to begin with */ /* Run EnumJobs again in case there were no jobs to begin with */
if (!test_JobEnum(p, mem_ctx)) { if (!test_JobEnum(tctx, p)) {
return False; return false;
} }
if (!test_JobGetInfo(p, mem_ctx, r.out.job_id)) { if (!test_JobGetInfo(p, tctx, r.out.job_id)) {
return False; return false;
} }
if (!test_JobDel(p, mem_ctx, r.out.job_id, r.out.job_id)) { if (!test_JobDel(p, tctx, r.out.job_id, r.out.job_id)) {
return False; return false;
} }
return True; return true;
} }
BOOL torture_rpc_atsvc(struct torture_context *torture) struct torture_suite *torture_rpc_atsvc(void)
{ {
NTSTATUS status; struct torture_suite *suite = torture_suite_create(
struct dcerpc_pipe *p; talloc_autofree_context(),
TALLOC_CTX *mem_ctx; "ATSVC");
BOOL ret = True; struct torture_tcase *tcase;
tcase = torture_suite_add_rpc_iface_tcase(suite, "atsvc",
&dcerpc_table_atsvc);
mem_ctx = talloc_init("torture_rpc_atsvc"); torture_rpc_tcase_add_test(tcase, "JobEnum", test_JobEnum);
torture_rpc_tcase_add_test(tcase, "JobAdd", test_JobAdd);
status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_atsvc); return suite;
if (!NT_STATUS_IS_OK(status)) {
talloc_free(mem_ctx);
return False;
}
if (!test_JobEnum(p, mem_ctx)) {
talloc_free(mem_ctx);
return False;
}
if (!test_JobAdd(p, mem_ctx)) {
talloc_free(mem_ctx);
return False;
}
talloc_free(mem_ctx);
return ret;
} }

View File

@ -30,6 +30,8 @@
#include "libcli/libcli.h" #include "libcli/libcli.h"
#include "lib/cmdline/popt_common.h" #include "lib/cmdline/popt_common.h"
#if 0
#define SMBTORTURE_DFS_SHARENAME "smbtorture_dfs_share" #define SMBTORTURE_DFS_SHARENAME "smbtorture_dfs_share"
#define SMBTORTURE_DFS_DIRNAME "\\smbtorture_dfs_dir" #define SMBTORTURE_DFS_DIRNAME "\\smbtorture_dfs_dir"
#define SMBTORTURE_DFS_PATHNAME "C:"SMBTORTURE_DFS_DIRNAME #define SMBTORTURE_DFS_PATHNAME "C:"SMBTORTURE_DFS_DIRNAME
@ -139,23 +141,20 @@ static BOOL test_DeleteDir(struct smbcli_state *cli, const char *dir)
return True; return True;
} }
static BOOL test_GetManagerVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, enum dfs_ManagerVersion *version) static BOOL test_GetManagerVersion(struct torture_context *tctx, struct dcerpc_pipe *p, enum dfs_ManagerVersion *version)
{ {
NTSTATUS status; NTSTATUS status;
struct dfs_GetManagerVersion r; struct dfs_GetManagerVersion r;
r.out.version = version; r.out.version = version;
status = dcerpc_dfs_GetManagerVersion(p, mem_ctx, &r); status = dcerpc_dfs_GetManagerVersion(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "GetManagerVersion failed");
printf("GetManagerVersion failed - %s\n", nt_errstr(status));
return False;
}
return True; return true;
} }
static BOOL test_ManagerInitialize(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host) static BOOL test_ManagerInitialize(struct torture_context *tctx, struct dcerpc_pipe *p, const char *host)
{ {
NTSTATUS status; NTSTATUS status;
enum dfs_ManagerVersion version; enum dfs_ManagerVersion version;
@ -163,14 +162,14 @@ static BOOL test_ManagerInitialize(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, c
printf("Testing ManagerInitialize\n"); printf("Testing ManagerInitialize\n");
if (!test_GetManagerVersion(p, mem_ctx, &version)) { if (!test_GetManagerVersion(tctx, p, &version)) {
return False; return False;
} }
r.in.servername = host; r.in.servername = host;
r.in.flags = 0; r.in.flags = 0;
status = dcerpc_dfs_ManagerInitialize(p, mem_ctx, &r); status = dcerpc_dfs_ManagerInitialize(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("ManagerInitialize failed - %s\n", nt_errstr(status)); printf("ManagerInitialize failed - %s\n", nt_errstr(status));
return False; return False;
@ -183,33 +182,31 @@ static BOOL test_ManagerInitialize(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, c
return True; return True;
} }
static BOOL test_GetInfoLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level, static BOOL test_GetInfoLevel(struct torture_context *tctx, struct dcerpc_pipe *p, uint16_t level, const char *root)
const char *root)
{ {
NTSTATUS status; NTSTATUS status;
struct dfs_GetInfo r; struct dfs_GetInfo r;
printf("Testing GetInfo level %u on '%s'\n", level, root); torture_comment(tctx,
talloc_asprintf(tctx, "Testing GetInfo level %u on '%s'\n", level, root));
r.in.dfs_entry_path = talloc_strdup(mem_ctx, root); r.in.dfs_entry_path = talloc_strdup(tctx, root);
r.in.servername = NULL; r.in.servername = NULL;
r.in.sharename = NULL; r.in.sharename = NULL;
r.in.level = level; r.in.level = level;
status = dcerpc_dfs_GetInfo(p, mem_ctx, &r); status = dcerpc_dfs_GetInfo(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "Info failed");
printf("GetInfo failed - %s\n", nt_errstr(status)); torture_assert(tctx, W_ERROR_IS_OK(r.out.result) ||
return False; W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result),
} else if (!W_ERROR_IS_OK(r.out.result) && talloc_asprintf(tctx,
!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) { "dfs_GetInfo failed - %s", win_errstr(r.out.result)));
printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
return False;
}
return True; return True;
} }
static BOOL test_GetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *root) static bool test_Info(struct torture_context *tctx,
struct dcerpc_pipe *p, const char *root)
{ {
BOOL ret = True; BOOL ret = True;
/* 103, 104, 105, 106 is only available on Set */ /* 103, 104, 105, 106 is only available on Set */
@ -217,14 +214,15 @@ static BOOL test_GetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char
int i; int i;
for (i=0;i<ARRAY_SIZE(levels);i++) { for (i=0;i<ARRAY_SIZE(levels);i++) {
if (!test_GetInfoLevel(p, mem_ctx, levels[i], root)) { if (!test_GetInfoLevel(tctx, p, levels[i], root)) {
ret = False; ret = false;
} }
} }
return ret; return ret;
} }
static BOOL test_EnumLevelEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level, const char *dfs_name) static bool test_EnumLevel(struct torture_context *tctx,
struct dcerpc_pipe *p, uint16_t level)
{ {
NTSTATUS status; NTSTATUS status;
struct dfs_EnumEx rex; struct dfs_EnumEx rex;
@ -305,23 +303,18 @@ static BOOL test_EnumLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t
e.e.info1->s = &s; e.e.info1->s = &s;
s.path = NULL; s.path = NULL;
printf("Testing Enum level %u\n", level); status = dcerpc_dfs_Enum(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status, "Enum failed - %s\n",
status = dcerpc_dfs_Enum(p, mem_ctx, &r); nt_errstr(status));
if (!NT_STATUS_IS_OK(status)) { torture_assert(tctx, W_ERROR_IS_OK(r.out.result) ||
printf("Enum failed - %s\n", nt_errstr(status)); W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result),
return False; "dfs_Enum failed - %s", win_errstr(r.out.result));
} else if (!W_ERROR_IS_OK(r.out.result) &&
!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
printf("dfs_Enum failed - %s\n", win_errstr(r.out.result));
return False;
}
if (level == 1 && r.out.total) { if (level == 1 && r.out.total) {
int i; int i;
for (i=0;i<*r.out.total;i++) { for (i=0;i<*r.out.total;i++) {
const char *root = r.out.info->e.info1->s[i].path; const char *root = r.out.info->e.info1->s[i].path;
if (!test_GetInfo(p, mem_ctx, root)) { if (!test_GetInfo(tctx, p, root)) {
ret = False; ret = False;
} }
} }
@ -332,15 +325,16 @@ static BOOL test_EnumLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t
} }
static BOOL test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_Enum(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
BOOL ret = True; BOOL ret = True;
uint16_t levels[] = {1, 2, 3, 4, 200, 300}; uint16_t levels[] = {1, 2, 3, 4, 200, 300};
int i; int i;
for (i=0;i<ARRAY_SIZE(levels);i++) { for (i=0;i<ARRAY_SIZE(levels);i++) {
if (!test_EnumLevel(p, mem_ctx, levels[i])) { if (!test_EnumLevel(tctx, p, levels[i])) {
ret = False; ret = false;
} }
} }
@ -481,31 +475,35 @@ static BOOL test_StdRoot(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char
return ret; return ret;
} }
BOOL torture_rpc_dfs(struct torture_context *torture) #endif
struct torture_suite *torture_rpc_dfs(void)
{ {
NTSTATUS status; struct torture_suite *suite = torture_suite_create(
struct dcerpc_pipe *p; talloc_autofree_context(), "RPC-DFS");
TALLOC_CTX *mem_ctx;
BOOL ret = True;
enum dfs_ManagerVersion version;
const char *host = lp_parm_string(-1, "torture", "host");
mem_ctx = talloc_init("torture_rpc_dfs"); #if 0
struct torture_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
"dfs", &dcerpc_table_netdfs);
status = torture_rpc_connection(mem_ctx, torture_rpc_tcase_add_test(tcase, "GetManagerVersion",
&p, test_GetManagerVersion);
&dcerpc_table_netdfs);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
ret &= test_GetManagerVersion(p, mem_ctx, &version); #if 0
ret &= test_ManagerInitialize(p, mem_ctx, host); torture_rpc_tcase_add_test(tcase, "Add",
ret &= test_Enum(p, mem_ctx); test_Add);
ret &= test_EnumEx(p, mem_ctx, host); #endif
ret &= test_StdRoot(p, mem_ctx, host);
torture_rpc_tcase_add_test(tcase, "Enum", test_Enum);
torture_rpc_tcase_add_test(tcase, "EnumEx", test_EnumEx);
torture_rpc_tcase_add_test(tcase, "ManagerInitialize",
test_ManagerInitialize);
torture_rpc_tcase_add_test(tcase, "StdRoot",
test_StdRoot);
talloc_free(mem_ctx); talloc_free(mem_ctx);
return ret; #endif
return suite;
} }

View File

@ -31,49 +31,40 @@
/* /*
test the AddOne interface test the AddOne interface
*/ */
#define TEST_ADDONE(value) do { \ #define TEST_ADDONE(tctx, value) do { \
n = i = value; \ n = i = value; \
r.in.in_data = n; \ r.in.in_data = n; \
r.out.out_data = &n; \ r.out.out_data = &n; \
status = dcerpc_echo_AddOne(p, mem_ctx, &r); \ status = dcerpc_echo_AddOne(p, tctx, &r); \
if (!NT_STATUS_IS_OK(status)) { \ torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "AddOne(%d) failed", i)); \
printf("AddOne(%d) failed - %s\n", i, nt_errstr(status)); \ torture_assert (tctx, n == i+1, talloc_asprintf(tctx, "%d + 1 != %u (should be %u)\n", i, n, i+1)); \
return False; \ torture_comment (tctx, "%d + 1 = %u\n", i, n); \
} \
if (n != i+1) { \
printf("%d + 1 != %u (should be %u)\n", i, n, i+1); \
ret = False; \
} else { \
printf("%d + 1 = %u\n", i, n); \
} \
} while(0) } while(0)
static BOOL test_addone(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_addone(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
BOOL ret = True;
uint32_t i; uint32_t i;
NTSTATUS status; NTSTATUS status;
uint32_t n; uint32_t n;
struct echo_AddOne r; struct echo_AddOne r;
printf("\nTesting AddOne\n");
for (i=0;i<10;i++) { for (i=0;i<10;i++) {
TEST_ADDONE(i); TEST_ADDONE(tctx, i);
} }
TEST_ADDONE(0x7FFFFFFE); TEST_ADDONE(tctx, 0x7FFFFFFE);
TEST_ADDONE(0xFFFFFFFE); TEST_ADDONE(tctx, 0xFFFFFFFE);
TEST_ADDONE(0xFFFFFFFF); TEST_ADDONE(tctx, 0xFFFFFFFF);
TEST_ADDONE(random() & 0xFFFFFFFF); TEST_ADDONE(tctx, random() & 0xFFFFFFFF);
return true;
return ret;
} }
/* /*
test the EchoData interface test the EchoData interface
*/ */
static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_echodata(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
int i; int i;
NTSTATUS status; NTSTATUS status;
@ -81,17 +72,15 @@ static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
int len; int len;
struct echo_EchoData r; struct echo_EchoData r;
if (lp_parm_bool(-1, "torture", "quick", False) && if (torture_setting_bool(tctx, "quick", false) &&
(p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) { (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
len = 1 + (random() % 500); len = 1 + (random() % 500);
} else { } else {
len = 1 + (random() % 5000); len = 1 + (random() % 5000);
} }
printf("\nTesting EchoData\n"); data_in = talloc_size(tctx, len);
data_out = talloc_size(tctx, len);
data_in = talloc_size(mem_ctx, len);
data_out = talloc_size(mem_ctx, len);
for (i=0;i<len;i++) { for (i=0;i<len;i++) {
data_in[i] = i; data_in[i] = i;
} }
@ -99,73 +88,64 @@ static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
r.in.len = len; r.in.len = len;
r.in.in_data = data_in; r.in.in_data = data_in;
status = dcerpc_echo_EchoData(p, mem_ctx, &r); status = dcerpc_echo_EchoData(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx,
printf("EchoData(%d) failed - %s\n", len, nt_errstr(status)); "EchoData(%d) failed\n", len));
return False;
}
data_out = r.out.out_data; data_out = r.out.out_data;
for (i=0;i<len;i++) { for (i=0;i<len;i++) {
if (data_in[i] != data_out[i]) { if (data_in[i] != data_out[i]) {
printf("Bad data returned for len %d at offset %d\n", torture_comment(tctx, "Bad data returned for len %d at offset %d\n",
len, i); len, i);
printf("in:\n"); torture_comment(tctx, "in:\n");
dump_data(0, data_in+i, MIN(len-i, 16)); dump_data(0, data_in+i, MIN(len-i, 16));
printf("out:\n"); torture_comment(tctx, "out:\n");
dump_data(0, data_out+i, MIN(len-1, 16)); dump_data(0, data_out+i, MIN(len-1, 16));
return False; return false;
} }
} }
return true;
return True;
} }
/* /*
test the SourceData interface test the SourceData interface
*/ */
static BOOL test_sourcedata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_sourcedata(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
int i; int i;
NTSTATUS status; NTSTATUS status;
int len; int len;
struct echo_SourceData r; struct echo_SourceData r;
if (lp_parm_bool(-1, "torture", "quick", False) && if (torture_setting_bool(tctx, "quick", false) &&
(p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) { (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
len = 100 + (random() % 500); len = 100 + (random() % 500);
} else { } else {
len = 200000 + (random() % 5000); len = 200000 + (random() % 5000);
} }
printf("\nTesting SourceData\n");
r.in.len = len; r.in.len = len;
status = dcerpc_echo_SourceData(p, mem_ctx, &r); status = dcerpc_echo_SourceData(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx,
printf("SourceData(%d) failed - %s\n", len, nt_errstr(status)); "SourceData(%d) failed", len));
return False;
}
for (i=0;i<len;i++) { for (i=0;i<len;i++) {
uint8_t *v = (uint8_t *)r.out.data; uint8_t *v = (uint8_t *)r.out.data;
if (v[i] != (i & 0xFF)) { torture_assert(tctx, v[i] == (i & 0xFF),
printf("bad data 0x%x at %d\n", (uint8_t)r.out.data[i], i); talloc_asprintf(tctx,
return False; "bad data 0x%x at %d\n", (uint8_t)r.out.data[i], i));
}
} }
return true;
return True;
} }
/* /*
test the SinkData interface test the SinkData interface
*/ */
static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_sinkdata(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
int i; int i;
NTSTATUS status; NTSTATUS status;
@ -173,16 +153,14 @@ static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
int len; int len;
struct echo_SinkData r; struct echo_SinkData r;
if (lp_parm_bool(-1, "torture", "quick", False) && if (torture_setting_bool(tctx, "quick", false) &&
(p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) { (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
len = 100 + (random() % 5000); len = 100 + (random() % 5000);
} else { } else {
len = 200000 + (random() % 5000); len = 200000 + (random() % 5000);
} }
printf("\nTesting SinkData\n"); data_in = talloc_size(tctx, len);
data_in = talloc_size(mem_ctx, len);
for (i=0;i<len;i++) { for (i=0;i<len;i++) {
data_in[i] = i+1; data_in[i] = i+1;
} }
@ -190,74 +168,63 @@ static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
r.in.len = len; r.in.len = len;
r.in.data = data_in; r.in.data = data_in;
status = dcerpc_echo_SinkData(p, mem_ctx, &r); status = dcerpc_echo_SinkData(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx,
printf("SinkData(%d) failed - %s\n", len, nt_errstr(status)); "SinkData(%d) failed",
return False; len));
}
printf("sunk %d bytes\n", len); torture_comment(tctx, "sunk %d bytes\n", len);
return true;
return True;
} }
/* /*
test the testcall interface test the testcall interface
*/ */
static BOOL test_testcall(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_testcall(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct echo_TestCall r; struct echo_TestCall r;
char *s = NULL; const char *s = NULL;
r.in.s1 = "input string"; r.in.s1 = "input string";
r.out.s2 = &s; r.out.s2 = &s;
printf("\nTesting TestCall\n"); status = dcerpc_echo_TestCall(p, tctx, &r);
status = dcerpc_echo_TestCall(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx, status, "TestCall failed");
if (!NT_STATUS_IS_OK(status)) {
printf("TestCall failed - %s\n", nt_errstr(status));
return False;
}
if (!strcmp(s, "input string")) { torture_assert_str_equal(tctx, s, "input string", "Didn't receive back same string");
printf("Didn't receive back same string\n");
return False;
}
return True; return true;
} }
/* /*
test the testcall interface test the testcall interface
*/ */
static BOOL test_testcall2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_testcall2(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct echo_TestCall2 r; struct echo_TestCall2 r;
int i; int i;
BOOL ret = True;
for (i=1;i<=7;i++) { for (i=1;i<=7;i++) {
r.in.level = i; r.in.level = i;
r.out.info = talloc(mem_ctx, union echo_Info); r.out.info = talloc(tctx, union echo_Info);
printf("\nTesting TestCall2 level %d\n", i); torture_comment(tctx, "Testing TestCall2 level %d\n", i);
status = dcerpc_echo_TestCall2(p, mem_ctx, &r); status = dcerpc_echo_TestCall2(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "TestCall2 failed");
printf("TestCall2 failed - %s\n", nt_errstr(status));
ret = False;
}
} }
return true;
return ret;
} }
/* /*
test the TestSleep interface test the TestSleep interface
*/ */
static BOOL test_sleep(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_sleep(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
int i; int i;
NTSTATUS status; NTSTATUS status;
@ -270,31 +237,25 @@ static BOOL test_sleep(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
struct timeval diff[ASYNC_COUNT]; struct timeval diff[ASYNC_COUNT];
struct event_context *ctx; struct event_context *ctx;
int total_done = 0; int total_done = 0;
BOOL ret = True;
if (lp_parm_bool(-1, "torture", "quick", False)) { if (torture_setting_bool(tctx, "quick", false)) {
printf("TestSleep disabled - use \"torture:quick=no\" to enable\n"); torture_skip(tctx, "TestSleep disabled - use \"torture:quick=no\" to enable\n");
return True;
} }
printf("Testing TestSleep - use \"torture:quick=no\" to disable\n"); torture_comment(tctx, "Testing TestSleep - use \"torture:quick=no\" to disable\n");
for (i=0;i<ASYNC_COUNT;i++) { for (i=0;i<ASYNC_COUNT;i++) {
done[i] = False; done[i] = False;
snd[i] = timeval_current(); snd[i] = timeval_current();
rcv[i] = timeval_zero(); rcv[i] = timeval_zero();
r[i].in.seconds = ASYNC_COUNT-i; r[i].in.seconds = ASYNC_COUNT-i;
req[i] = dcerpc_echo_TestSleep_send(p, mem_ctx, &r[i]); req[i] = dcerpc_echo_TestSleep_send(p, tctx, &r[i]);
if (!req[i]) { torture_assert(tctx, req[i], "Failed to send async sleep request\n");
printf("Failed to send async sleep request\n");
return False;
}
} }
ctx = dcerpc_event_context(p); ctx = dcerpc_event_context(p);
while (total_done < ASYNC_COUNT) { while (total_done < ASYNC_COUNT) {
if (event_loop_once(ctx) != 0) { torture_assert(tctx, event_loop_once(ctx) == 0,
return False; "Event context loop failed");
}
for (i=0;i<ASYNC_COUNT;i++) { for (i=0;i<ASYNC_COUNT;i++) {
if (done[i] == False && req[i]->state == RPC_REQUEST_DONE) { if (done[i] == False && req[i]->state == RPC_REQUEST_DONE) {
total_done++; total_done++;
@ -302,46 +263,39 @@ static BOOL test_sleep(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
rcv[i] = timeval_current(); rcv[i] = timeval_current();
diff[i] = timeval_until(&snd[i], &rcv[i]); diff[i] = timeval_until(&snd[i], &rcv[i]);
status = dcerpc_ndr_request_recv(req[i]); status = dcerpc_ndr_request_recv(req[i]);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("TestSleep(%d) failed - %s\n", talloc_asprintf(tctx, "TestSleep(%d) failed", i));
i, nt_errstr(status)); torture_assert(tctx, r[i].out.result == r[i].in.seconds,
ret = False; talloc_asprintf(tctx, "Failed - Asked to sleep for %u seconds (server replied with %u seconds and the reply takes only %u seconds)",
} else if (r[i].out.result != r[i].in.seconds) { r[i].out.result, r[i].in.seconds, (uint_t)diff[i].tv_sec));
printf("Failed - Asked to sleep for %u seconds (server replied with %u seconds and the reply takes only %u seconds)\n", torture_assert(tctx, r[i].out.result <= diff[i].tv_sec,
r[i].out.result, r[i].in.seconds, (uint_t)diff[i].tv_sec); talloc_asprintf(tctx, "Failed - Slept for %u seconds (but reply takes only %u.%06u seconds)",
ret = False; r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec));
if (r[i].out.result+1 == diff[i].tv_sec) {
torture_comment(tctx, "Slept for %u seconds (but reply takes %u.%06u seconds - busy server?)\n",
r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
} else if (r[i].out.result == diff[i].tv_sec) {
torture_comment(tctx, "Slept for %u seconds (reply takes %u.%06u seconds - ok)\n",
r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
} else { } else {
if (r[i].out.result > diff[i].tv_sec) { torture_comment(tctx, "(Failed) - Not async - Slept for %u seconds (but reply takes %u.%06u seconds)",
printf("Failed - Slept for %u seconds (but reply takes only %u.%06u seconds)\n", r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec); /* TODO: let the test fail here, when we support async rpc on ncacn_np */
} else if (r[i].out.result+1 == diff[i].tv_sec) {
printf("Slept for %u seconds (but reply takes %u.%06u seconds - busy server?)\n",
r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
} else if (r[i].out.result == diff[i].tv_sec) {
printf("Slept for %u seconds (reply takes %u.%06u seconds - ok)\n",
r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
} else {
printf("(Failed) - Not async - Slept for %u seconds (but reply takes %u.%06u seconds)\n",
r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
/* TODO: let the test fail here, when we support async rpc on ncacn_np
ret = False;*/
}
} }
} }
} }
} }
return true;
return ret;
} }
/* /*
test enum handling test enum handling
*/ */
static BOOL test_enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_enum(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct echo_TestEnum r; struct echo_TestEnum r;
BOOL ret = True;
enum echo_Enum1 v = ECHO_ENUM1; enum echo_Enum1 v = ECHO_ENUM1;
struct echo_Enum2 e2; struct echo_Enum2 e2;
union echo_Enum3 e3; union echo_Enum3 e3;
@ -357,56 +311,45 @@ static BOOL test_enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
e2.e2 = ECHO_ENUM1_32; e2.e2 = ECHO_ENUM1_32;
e3.e1 = ECHO_ENUM2; e3.e1 = ECHO_ENUM2;
printf("\nTesting TestEnum\n"); status = dcerpc_echo_TestEnum(p, tctx, &r);
status = dcerpc_echo_TestEnum(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx, status, "TestEnum failed");
if (!NT_STATUS_IS_OK(status)) { return true;
printf("TestEnum failed - %s\n", nt_errstr(status));
ret = False;
}
return ret;
} }
/* /*
test surrounding conformant array handling test surrounding conformant array handling
*/ */
static BOOL test_surrounding(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_surrounding(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct echo_TestSurrounding r; struct echo_TestSurrounding r;
BOOL ret = True;
ZERO_STRUCT(r); ZERO_STRUCT(r);
r.in.data = talloc(mem_ctx, struct echo_Surrounding); r.in.data = talloc(tctx, struct echo_Surrounding);
r.in.data->x = 20; r.in.data->x = 20;
r.in.data->surrounding = talloc_zero_array(mem_ctx, uint16_t, r.in.data->x); r.in.data->surrounding = talloc_zero_array(tctx, uint16_t, r.in.data->x);
r.out.data = talloc(mem_ctx, struct echo_Surrounding); r.out.data = talloc(tctx, struct echo_Surrounding);
printf("\nTesting TestSurrounding\n"); status = dcerpc_echo_TestSurrounding(p, tctx, &r);
status = dcerpc_echo_TestSurrounding(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx, status, "TestSurrounding failed");
if (!NT_STATUS_IS_OK(status)) {
printf("TestSurrounding failed - %s\n", nt_errstr(status));
return False;
}
if (r.out.data->x != 2 * r.in.data->x) { torture_assert(tctx, r.out.data->x == 2 * r.in.data->x,
printf("TestSurrounding did not make the array twice as large\n"); "TestSurrounding did not make the array twice as large");
ret = False;
}
return ret; return true;
} }
/* /*
test multiple levels of pointers test multiple levels of pointers
*/ */
static BOOL test_doublepointer(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_doublepointer(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct echo_TestDoublePointer r; struct echo_TestDoublePointer r;
BOOL ret = True;
uint16_t value = 12; uint16_t value = 12;
uint16_t *pvalue = &value; uint16_t *pvalue = &value;
uint16_t **ppvalue = &pvalue; uint16_t **ppvalue = &pvalue;
@ -414,112 +357,88 @@ static BOOL test_doublepointer(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
ZERO_STRUCT(r); ZERO_STRUCT(r);
r.in.data = &ppvalue; r.in.data = &ppvalue;
printf("\nTesting TestDoublePointer\n"); status = dcerpc_echo_TestDoublePointer(p, tctx, &r);
status = dcerpc_echo_TestDoublePointer(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx, status, "TestDoublePointer failed");
if (!NT_STATUS_IS_OK(status)) {
printf("TestDoublePointer failed - %s\n", nt_errstr(status));
ret = False;
}
if (value != r.out.result) { torture_assert_int_equal(tctx, value, r.out.result,
printf("TestDoublePointer did not return original value (%d != %d)\n", value, r.out.result); "TestDoublePointer did not return original value");
ret = False; return true;
}
return ret;
} }
/* /*
test request timeouts test request timeouts
*/ */
static BOOL test_timeout(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_timeout(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct rpc_request *req; struct rpc_request *req;
struct echo_TestSleep r; struct echo_TestSleep r;
int timeout_saved = p->request_timeout; int timeout_saved = p->request_timeout;
if (lp_parm_bool(-1, "torture", "quick", False)) { if (torture_setting_bool(tctx, "quick", false)) {
printf("timeout testing disabled - use \"torture:quick=no\" to enable\n"); torture_skip(tctx, "timeout testing disabled - use \"torture:quick=no\" to enable\n");
return True;
} }
printf("testing request timeouts\n"); torture_comment(tctx, "testing request timeouts\n");
r.in.seconds = 2; r.in.seconds = 2;
p->request_timeout = 1; p->request_timeout = 1;
req = dcerpc_echo_TestSleep_send(p, mem_ctx, &r); torture_assert(tctx, req = dcerpc_echo_TestSleep_send(p, tctx, &r),
if (!req) { "Failed to send async sleep request");
printf("Failed to send async sleep request\n");
goto failed;
}
status = dcerpc_ndr_request_recv(req); status = dcerpc_ndr_request_recv(req);
if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT,
printf("request should have timed out - %s\n", nt_errstr(status)); "request should have timed out");
goto failed;
}
printf("testing request destruction\n"); torture_comment(tctx, "testing request destruction\n");
req = dcerpc_echo_TestSleep_send(p, mem_ctx, &r); req = dcerpc_echo_TestSleep_send(p, tctx, &r);
if (!req) { if (!req) {
printf("Failed to send async sleep request\n"); torture_comment(tctx, "Failed to send async sleep request\n");
goto failed; goto failed;
} }
talloc_free(req); talloc_free(req);
req = dcerpc_echo_TestSleep_send(p, mem_ctx, &r); req = dcerpc_echo_TestSleep_send(p, tctx, &r);
if (!req) { if (!req) {
printf("Failed to send async sleep request\n"); torture_comment(tctx, "Failed to send async sleep request\n");
goto failed; goto failed;
} }
status = dcerpc_ndr_request_recv(req); status = dcerpc_ndr_request_recv(req);
if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT,
printf("request should have timed out - %s\n", nt_errstr(status)); "request should have timed out");
goto failed;
}
p->request_timeout = timeout_saved; p->request_timeout = timeout_saved;
return test_addone(p, mem_ctx);
return test_addone(tctx, p);
failed: failed:
p->request_timeout = timeout_saved; p->request_timeout = timeout_saved;
return False; return false;
} }
BOOL torture_rpc_echo(struct torture_context *torture) struct torture_suite *torture_rpc_echo(void)
{ {
NTSTATUS status; struct torture_suite *suite = torture_suite_create(
struct dcerpc_pipe *p; talloc_autofree_context(), "ECHO");
TALLOC_CTX *mem_ctx; struct torture_tcase *tcase;
BOOL ret = True;
mem_ctx = talloc_init("torture_rpc_echo"); tcase = torture_suite_add_rpc_iface_tcase(suite, "echo",
&dcerpc_table_rpcecho);
status = torture_rpc_connection(mem_ctx, torture_rpc_tcase_add_test(tcase, "addone", test_addone);
&p, torture_rpc_tcase_add_test(tcase, "sinkdata", test_sinkdata);
&dcerpc_table_rpcecho); torture_rpc_tcase_add_test(tcase, "echodata", test_echodata);
if (!NT_STATUS_IS_OK(status)) { torture_rpc_tcase_add_test(tcase, "sourcedata", test_sourcedata);
return False; torture_rpc_tcase_add_test(tcase, "testcall", test_testcall);
} torture_rpc_tcase_add_test(tcase, "testcall2", test_testcall2);
torture_rpc_tcase_add_test(tcase, "enum", test_enum);
torture_rpc_tcase_add_test(tcase, "surrounding", test_surrounding);
torture_rpc_tcase_add_test(tcase, "doublepointer", test_doublepointer);
torture_rpc_tcase_add_test(tcase, "sleep", test_sleep);
torture_rpc_tcase_add_test(tcase, "timeout", test_timeout);
ret &= test_addone(p, mem_ctx); return suite;
ret &= test_sinkdata(p, mem_ctx);
ret &= test_echodata(p, mem_ctx);
ret &= test_sourcedata(p, mem_ctx);
ret &= test_testcall(p, mem_ctx);
ret &= test_testcall2(p, mem_ctx);
ret &= test_enum(p, mem_ctx);
ret &= test_surrounding(p, mem_ctx);
ret &= test_doublepointer(p, mem_ctx);
ret &= test_sleep(p, mem_ctx);
ret &= test_timeout(p, mem_ctx);
printf("\n");
talloc_free(mem_ctx);
return ret;
} }

View File

@ -34,38 +34,72 @@ static void init_lsa_String(struct lsa_String *name, const char *s)
name->size = name->length; name->size = name->length;
} }
static BOOL test_GetNumRecords(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, static bool get_policy_handle(struct torture_context *tctx,
struct policy_handle *handle) struct dcerpc_pipe *p,
struct policy_handle *handle)
{ {
NTSTATUS status; struct eventlog_OpenEventLogW r;
struct eventlog_GetNumRecords r; struct eventlog_OpenUnknown0 unknown0;
printf("\ntesting GetNumRecords\n"); unknown0.unknown0 = 0x005c;
unknown0.unknown1 = 0x0001;
r.in.handle = handle; r.in.unknown0 = &unknown0;
init_lsa_String(&r.in.logname, "dns server");
init_lsa_String(&r.in.servername, NULL);
r.in.unknown2 = 0x00000001;
r.in.unknown3 = 0x00000001;
r.out.handle = handle;
status = dcerpc_eventlog_GetNumRecords(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx,
dcerpc_eventlog_OpenEventLogW(p, tctx, &r),
"OpenEventLog failed");
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, r.out.result, "OpenEventLog failed");
printf("GetNumRecords failed - %s\n", nt_errstr(status));
return False;
}
printf("%d records\n", r.out.number); return true;
return True;
} }
static BOOL test_ReadEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
struct policy_handle *handle)
static bool test_GetNumRecords(struct torture_context *tctx, struct dcerpc_pipe *p)
{
struct eventlog_GetNumRecords r;
struct eventlog_CloseEventLog cr;
struct policy_handle handle;
if (!get_policy_handle(tctx, p, &handle))
return false;
r.in.handle = &handle;
torture_assert_ntstatus_ok(tctx,
dcerpc_eventlog_GetNumRecords(p, tctx, &r),
"GetNumRecords failed");
torture_comment(tctx, talloc_asprintf(tctx, "%d records\n", r.out.number));
cr.in.handle = cr.out.handle = &handle;
torture_assert_ntstatus_ok(tctx,
dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
"CloseEventLog failed");
return true;
}
static bool test_ReadEventLog(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct eventlog_ReadEventLogW r; struct eventlog_ReadEventLogW r;
struct eventlog_CloseEventLog cr;
struct policy_handle handle;
printf("\ntesting ReadEventLog\n"); if (!get_policy_handle(tctx, p, &handle))
return false;
r.in.offset = 0; r.in.offset = 0;
r.in.handle = handle; r.in.handle = &handle;
r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ; r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ;
while (1) { while (1) {
@ -78,185 +112,142 @@ static BOOL test_ReadEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
r.in.number_of_bytes = 0; r.in.number_of_bytes = 0;
r.out.data = NULL; r.out.data = NULL;
status = dcerpc_eventlog_ReadEventLogW(p, mem_ctx, &r); status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) { if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) {
break; break;
} }
if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_BUFFER_TOO_SMALL)) { torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
printf("ReadEventLog failed - %s\n", nt_errstr(r.out.result));
return False; torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_BUFFER_TOO_SMALL,
} "ReadEventLog failed");
/* Now read the actual record */ /* Now read the actual record */
r.in.number_of_bytes = r.out.real_size; r.in.number_of_bytes = r.out.real_size;
r.out.data = talloc_size(mem_ctx, r.in.number_of_bytes); r.out.data = talloc_size(tctx, r.in.number_of_bytes);
status = dcerpc_eventlog_ReadEventLogW(p, mem_ctx, &r); status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
printf("ReadEventLog failed - %s\n", nt_errstr(status));
return False;
}
/* Decode a user-marshalled record */ /* Decode a user-marshalled record */
blob.length = r.out.sent_size; blob.length = r.out.sent_size;
blob.data = talloc_steal(mem_ctx, r.out.data); blob.data = talloc_steal(tctx, r.out.data);
ndr = ndr_pull_init_blob(&blob, mem_ctx); ndr = ndr_pull_init_blob(&blob, tctx);
status = ndr_pull_eventlog_Record( status = ndr_pull_eventlog_Record(
ndr, NDR_SCALARS|NDR_BUFFERS, &rec); ndr, NDR_SCALARS|NDR_BUFFERS, &rec);
NDR_PRINT_DEBUG(eventlog_Record, &rec); NDR_PRINT_DEBUG(eventlog_Record, &rec);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("ReadEventLog failed parsing event log record " "ReadEventLog failed parsing event log record");
"- %s\n", nt_errstr(status));
return False;
}
r.in.offset++; r.in.offset++;
} }
return True; cr.in.handle = cr.out.handle = &handle;
torture_assert_ntstatus_ok(tctx,
dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
"CloseEventLog failed");
return true;
} }
static BOOL test_CloseEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, static bool test_FlushEventLog(struct torture_context *tctx,
struct policy_handle *handle) struct dcerpc_pipe *p)
{ {
NTSTATUS status;
struct eventlog_CloseEventLog r;
r.in.handle = r.out.handle = handle;
printf("Testing CloseEventLog\n");
status = dcerpc_eventlog_CloseEventLog(p, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
printf("CloseEventLog failed - %s\n", nt_errstr(status));
return False;
}
return True;
}
static BOOL test_FlushEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
struct policy_handle *handle)
{
NTSTATUS status;
struct eventlog_FlushEventLog r; struct eventlog_FlushEventLog r;
struct eventlog_CloseEventLog cr;
struct policy_handle handle;
r.in.handle = handle; if (!get_policy_handle(tctx, p, &handle))
return false;
printf("Testing FlushEventLog\n"); r.in.handle = &handle;
status = dcerpc_eventlog_FlushEventLog(p, mem_ctx, &r);
/* Huh? Does this RPC always return access denied? */ /* Huh? Does this RPC always return access denied? */
torture_assert_ntstatus_equal(tctx,
dcerpc_eventlog_FlushEventLog(p, tctx, &r),
NT_STATUS_ACCESS_DENIED,
"FlushEventLog failed");
if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { cr.in.handle = cr.out.handle = &handle;
printf("FlushEventLog failed - %s\n", nt_errstr(status));
return False;
}
return True; torture_assert_ntstatus_ok(tctx,
dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
"CloseEventLog failed");
return true;
} }
static BOOL test_ClearEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, static bool test_ClearEventLog(struct dcerpc_pipe *p, TALLOC_CTX *tctx)
struct policy_handle *handle)
{ {
NTSTATUS status;
struct eventlog_ClearEventLogW r; struct eventlog_ClearEventLogW r;
struct eventlog_CloseEventLog cr;
struct policy_handle handle;
r.in.handle = handle; if (!get_policy_handle(tctx, p, &handle))
return false;
r.in.handle = &handle;
r.in.unknown = NULL; r.in.unknown = NULL;
printf("Testing ClearEventLog\n"); torture_assert_ntstatus_ok(tctx,
dcerpc_eventlog_ClearEventLogW(p, tctx, &r),
"ClearEventLog failed");
status = dcerpc_eventlog_ClearEventLogW(p, mem_ctx, &r); cr.in.handle = cr.out.handle = &handle;
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx,
printf("ClearEventLog failed - %s\n", nt_errstr(status)); dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
return False; "CloseEventLog failed");
}
return True; return true;
} }
static BOOL test_OpenEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, static bool test_OpenEventLog(struct torture_context *tctx,
struct policy_handle *handle) struct dcerpc_pipe *p)
{ {
NTSTATUS status;
struct eventlog_OpenEventLogW r;
struct eventlog_OpenUnknown0 unknown0;
printf("\ntesting OpenEventLog\n");
unknown0.unknown0 = 0x005c;
unknown0.unknown1 = 0x0001;
r.in.unknown0 = &unknown0;
init_lsa_String(&r.in.logname, "dns server");
init_lsa_String(&r.in.servername, NULL);
r.in.unknown2 = 0x00000001;
r.in.unknown3 = 0x00000001;
r.out.handle = handle;
status = dcerpc_eventlog_OpenEventLogW(p, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
printf("OpenEventLog failed - %s\n", nt_errstr(status));
return False;
}
if (!NT_STATUS_IS_OK(r.out.result)) {
printf("OpenEventLog failed - %s\n", nt_errstr(r.out.result));
return False;
}
return True;
}
BOOL torture_rpc_eventlog(struct torture_context *torture)
{
NTSTATUS status;
struct dcerpc_pipe *p;
struct policy_handle handle; struct policy_handle handle;
TALLOC_CTX *mem_ctx; struct eventlog_CloseEventLog cr;
BOOL ret = True;
mem_ctx = talloc_init("torture_rpc_atsvc"); if (!get_policy_handle(tctx, p, &handle))
return false;
status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_eventlog); cr.in.handle = cr.out.handle = &handle;
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx,
talloc_free(mem_ctx); dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
return False; "CloseEventLog failed");
}
if (!test_OpenEventLog(p, mem_ctx, &handle)) { return true;
talloc_free(mem_ctx); }
return False;
} struct torture_suite *torture_rpc_eventlog(void)
{
struct torture_suite *suite;
struct torture_tcase *tcase;
suite = torture_suite_create(talloc_autofree_context(), "EVENTLOG");
tcase = torture_suite_add_rpc_iface_tcase(suite, "eventlog",
&dcerpc_table_eventlog);
torture_rpc_tcase_add_test(tcase, "OpenEventLog", test_OpenEventLog);
#if 0 #if 0
ret &= test_ClearEventLog(p, mem_ctx, &handle); /* Destructive test */ /* Destructive test */
torture_rpc_tcase_add_test(tcase, "ClearEventLog", test_ClearEventLog);
#endif #endif
ret &= test_GetNumRecords(p, mem_ctx, &handle); torture_rpc_tcase_add_test(tcase, "GetNumRecords", test_GetNumRecords);
torture_rpc_tcase_add_test(tcase, "ReadEventLog", test_ReadEventLog);
torture_rpc_tcase_add_test(tcase, "FlushEventLog", test_FlushEventLog);
ret &= test_ReadEventLog(p, mem_ctx, &handle); return suite;
ret &= test_FlushEventLog(p, mem_ctx, &handle);
ret &= test_CloseEventLog(p, mem_ctx, &handle);
talloc_free(mem_ctx);
return ret;
} }

View File

@ -26,6 +26,7 @@
#include "torture/rpc/rpc.h" #include "torture/rpc/rpc.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "librpc/rpc/dcerpc_table.h" #include "librpc/rpc/dcerpc_table.h"
#include "lib/util/dlinklist.h"
/* open a rpc connection to the chosen binding string */ /* open a rpc connection to the chosen binding string */
_PUBLIC_ NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, _PUBLIC_ NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx,
@ -89,64 +90,136 @@ NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx,
return status; return status;
} }
static bool torture_rpc_setup (struct torture_context *tctx, void **data)
{
NTSTATUS status;
status = torture_rpc_connection(tctx,
(struct dcerpc_pipe **)data,
(const struct dcerpc_interface_table *)tctx->active_tcase->data);
torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
return true;
}
static bool torture_rpc_teardown (struct torture_context *tcase, void *data)
{
talloc_free(data);
return true;
}
_PUBLIC_ struct torture_tcase *torture_suite_add_rpc_iface_tcase(struct torture_suite *suite,
const char *name,
const struct dcerpc_interface_table *table)
{
struct torture_tcase *tcase = torture_suite_add_tcase(suite, name);
tcase->setup = torture_rpc_setup;
tcase->teardown = torture_rpc_teardown;
tcase->data = table;
return tcase;
}
static bool torture_rpc_wrap_test(struct torture_context *tctx,
struct torture_tcase *tcase,
struct torture_test *test)
{
bool (*fn) (struct torture_context *, struct dcerpc_pipe *);
fn = test->fn;
return fn(tctx, (struct dcerpc_pipe *)tcase->data);
}
_PUBLIC_ struct torture_test *torture_rpc_tcase_add_test(
struct torture_tcase *tcase,
const char *name,
bool (*fn) (struct torture_context *, struct dcerpc_pipe *))
{
struct torture_test *test;
test = talloc(tcase, struct torture_test);
test->name = talloc_strdup(test, name);
test->description = NULL;
test->run = torture_rpc_wrap_test;
test->dangerous = false;
test->data = NULL;
test->fn = fn;
DLIST_ADD(tcase->tests, test);
return test;
}
NTSTATUS torture_rpc_init(void) NTSTATUS torture_rpc_init(void)
{ {
struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"RPC");
dcerpc_init(); dcerpc_init();
dcerpc_table_init(); dcerpc_table_init();
register_torture_op("RPC-LSA", torture_rpc_lsa); torture_suite_add_simple_test(suite, "LSA", torture_rpc_lsa);
register_torture_op("RPC-LSALOOKUP", torture_rpc_lsa_lookup); torture_suite_add_simple_test(suite, "LSALOOKUP", torture_rpc_lsa_lookup);
register_torture_op("RPC-LSA-GETUSER", torture_rpc_lsa_get_user); torture_suite_add_simple_test(suite, "LSA-GETUSER", torture_rpc_lsa_get_user);
register_torture_op("RPC-SECRETS", torture_rpc_lsa_secrets); torture_suite_add_simple_test(suite, "SECRETS", torture_rpc_lsa_secrets);
register_torture_op("RPC-ECHO", torture_rpc_echo); torture_suite_add_suite(suite, torture_rpc_echo());
register_torture_op("RPC-DFS", torture_rpc_dfs); torture_suite_add_suite(suite, torture_rpc_dfs());
register_torture_op("RPC-SPOOLSS", torture_rpc_spoolss); torture_suite_add_suite(suite, torture_rpc_unixinfo());
register_torture_op("RPC-SAMR", torture_rpc_samr); torture_suite_add_suite(suite, torture_rpc_eventlog());
register_torture_op("RPC-SAMR-USERS", torture_rpc_samr_users); torture_suite_add_suite(suite, torture_rpc_atsvc());
register_torture_op("RPC-SAMR-PASSWORDS", torture_rpc_samr_passwords); torture_suite_add_suite(suite, torture_rpc_wkssvc());
register_torture_op("RPC-UNIXINFO", torture_rpc_unixinfo); torture_suite_add_simple_test(suite, "SPOOLSS", torture_rpc_spoolss);
register_torture_op("RPC-NETLOGON", torture_rpc_netlogon); torture_suite_add_simple_test(suite, "SAMR", torture_rpc_samr);
register_torture_op("RPC-SAMLOGON", torture_rpc_samlogon); torture_suite_add_simple_test(suite, "SAMR-USERS", torture_rpc_samr_users);
register_torture_op("RPC-SAMSYNC", torture_rpc_samsync); torture_suite_add_simple_test(suite, "SAMR-PASSWORDS", torture_rpc_samr_passwords);
register_torture_op("RPC-SCHANNEL", torture_rpc_schannel); torture_suite_add_simple_test(suite, "NETLOGON", torture_rpc_netlogon);
register_torture_op("RPC-WKSSVC", torture_rpc_wkssvc); torture_suite_add_simple_test(suite, "SAMLOGON", torture_rpc_samlogon);
register_torture_op("RPC-SRVSVC", torture_rpc_srvsvc); torture_suite_add_simple_test(suite, "SAMSYNC", torture_rpc_samsync);
register_torture_op("RPC-SVCCTL", torture_rpc_svcctl); torture_suite_add_simple_test(suite, "SCHANNEL", torture_rpc_schannel);
register_torture_op("RPC-ATSVC", torture_rpc_atsvc); torture_suite_add_simple_test(suite, "SRVSVC", torture_rpc_srvsvc);
register_torture_op("RPC-EVENTLOG", torture_rpc_eventlog); torture_suite_add_simple_test(suite, "SVCCTL", torture_rpc_svcctl);
register_torture_op("RPC-EPMAPPER", torture_rpc_epmapper); torture_suite_add_simple_test(suite, "EPMAPPER", torture_rpc_epmapper);
register_torture_op("RPC-WINREG", torture_rpc_winreg); torture_suite_add_simple_test(suite, "WINREG", torture_rpc_winreg);
register_torture_op("RPC-INITSHUTDOWN", torture_rpc_initshutdown); torture_suite_add_simple_test(suite, "INITSHUTDOWN", torture_rpc_initshutdown);
register_torture_op("RPC-OXIDRESOLVE", torture_rpc_oxidresolve); torture_suite_add_simple_test(suite, "OXIDRESOLVE", torture_rpc_oxidresolve);
register_torture_op("RPC-REMACT", torture_rpc_remact); torture_suite_add_simple_test(suite, "REMACT", torture_rpc_remact);
register_torture_op("RPC-MGMT", torture_rpc_mgmt); torture_suite_add_simple_test(suite, "MGMT", torture_rpc_mgmt);
register_torture_op("RPC-SCANNER", torture_rpc_scanner); torture_suite_add_simple_test(suite, "SCANNER", torture_rpc_scanner);
register_torture_op("RPC-AUTOIDL", torture_rpc_autoidl); torture_suite_add_simple_test(suite, "AUTOIDL", torture_rpc_autoidl);
register_torture_op("RPC-COUNTCALLS", torture_rpc_countcalls); torture_suite_add_simple_test(suite, "COUNTCALLS", torture_rpc_countcalls);
register_torture_op("RPC-MULTIBIND", torture_multi_bind); torture_suite_add_simple_test(suite, "MULTIBIND", torture_multi_bind);
register_torture_op("RPC-AUTHCONTEXT", torture_bind_authcontext); torture_suite_add_simple_test(suite, "AUTHCONTEXT", torture_bind_authcontext);
register_torture_op("RPC-BINDSAMBA3", torture_bind_samba3); torture_suite_add_simple_test(suite, "BINDSAMBA3", torture_bind_samba3);
register_torture_op("RPC-NETLOGSAMBA3", torture_netlogon_samba3); torture_suite_add_simple_test(suite, "NETLOGSAMBA3", torture_netlogon_samba3);
register_torture_op("RPC-SAMBA3SESSIONKEY", torture_samba3_sessionkey); torture_suite_add_simple_test(suite, "SAMBA3SESSIONKEY", torture_samba3_sessionkey);
register_torture_op("RPC-SAMBA3-SRVSVC", torture_samba3_rpc_srvsvc); torture_suite_add_simple_test(suite, "SAMBA3-SRVSVC", torture_samba3_rpc_srvsvc);
register_torture_op("RPC-SAMBA3-SHARESEC", torture_suite_add_simple_test(suite, "SAMBA3-SHARESEC",
torture_samba3_rpc_sharesec); torture_samba3_rpc_sharesec);
register_torture_op("RPC-SAMBA3-GETUSERNAME", torture_suite_add_simple_test(suite, "SAMBA3-GETUSERNAME",
torture_samba3_rpc_getusername); torture_samba3_rpc_getusername);
register_torture_op("RPC-SAMBA3-LSA", torture_samba3_rpc_lsa); torture_suite_add_simple_test(suite, "SAMBA3-LSA", torture_samba3_rpc_lsa);
register_torture_op("RPC-SAMBA3-SPOOLSS", torture_samba3_rpc_spoolss); torture_suite_add_simple_test(suite, "SAMBA3-SPOOLSS", torture_samba3_rpc_spoolss);
register_torture_op("RPC-SAMBA3-WKSSVC", torture_samba3_rpc_wkssvc); torture_suite_add_simple_test(suite, "SAMBA3-WKSSVC", torture_samba3_rpc_wkssvc);
register_torture_op("RPC-SAMBA3-WINREG", torture_samba3_rpc_winreg); torture_suite_add_simple_test(suite, "RPC-SAMBA3-WINREG", torture_samba3_rpc_winreg);
register_torture_op("RPC-DRSUAPI", torture_rpc_drsuapi); torture_suite_add_simple_test(suite, "DRSUAPI", torture_rpc_drsuapi);
register_torture_op("RPC-CRACKNAMES", torture_rpc_drsuapi_cracknames); torture_suite_add_simple_test(suite, "CRACKNAMES", torture_rpc_drsuapi_cracknames);
register_torture_op("RPC-ROT", torture_rpc_rot); torture_suite_add_simple_test(suite, "ROT", torture_rpc_rot);
register_torture_op("RPC-DSSETUP", torture_rpc_dssetup); torture_suite_add_simple_test(suite, "DSSETUP", torture_rpc_dssetup);
register_torture_op("RPC-ALTERCONTEXT", torture_rpc_alter_context); torture_suite_add_simple_test(suite, "ALTERCONTEXT", torture_rpc_alter_context);
register_torture_op("RPC-JOIN", torture_rpc_join); torture_suite_add_simple_test(suite, "JOIN", torture_rpc_join);
register_torture_op("RPC-DSSYNC", torture_rpc_dssync); torture_suite_add_simple_test(suite, "DSSYNC", torture_rpc_dssync);
register_torture_op("BENCH-RPC", torture_bench_rpc); torture_suite_add_simple_test(suite, "BENCH-RPC", torture_bench_rpc);
register_torture_op("RPC-ASYNCBIND", torture_async_bind); torture_suite_add_simple_test(suite, "ASYNCBIND", torture_async_bind);
suite->description = talloc_strdup(suite,
"DCE/RPC protocol and interface tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -29,5 +29,6 @@
#include "librpc/rpc/dcerpc.h" #include "librpc/rpc/dcerpc.h"
#include "libcli/raw/libcliraw.h" #include "libcli/raw/libcliraw.h"
#include "torture/rpc/proto.h" #include "torture/rpc/proto.h"
#include "torture/ui.h"
#endif /* __TORTURE_RPC_H__ */ #endif /* __TORTURE_RPC_H__ */

View File

@ -51,24 +51,21 @@ static BOOL test_sidtouid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
/* /*
test the UidToSid interface test the UidToSid interface
*/ */
static BOOL test_uidtosid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_uidtosid(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
NTSTATUS status;
struct unixinfo_UidToSid r; struct unixinfo_UidToSid r;
r.in.uid = 1000; r.in.uid = 1000;
status = dcerpc_unixinfo_UidToSid(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_UidToSid(p, tctx, &r),
if (NT_STATUS_EQUAL(NT_STATUS_NO_SUCH_USER, status)) { "UidToSid failed");
} else if (!NT_STATUS_IS_OK(status)) {
printf("UidToSid failed == %s\n", nt_errstr(status));
return False;
}
return True; return true;
} }
static BOOL test_getpwuid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static bool test_getpwuid(struct torture_context *tctx,
struct dcerpc_pipe *p)
{ {
uint64_t uids[512]; uint64_t uids[512];
uint32_t num_uids = ARRAY_SIZE(uids); uint32_t num_uids = ARRAY_SIZE(uids);
@ -83,11 +80,13 @@ static BOOL test_getpwuid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
r.in.count = &num_uids; r.in.count = &num_uids;
r.in.uids = uids; r.in.uids = uids;
r.out.count = &num_uids; r.out.count = &num_uids;
r.out.infos = talloc_array(mem_ctx, struct unixinfo_GetPWUidInfo, num_uids); r.out.infos = talloc_array(tctx, struct unixinfo_GetPWUidInfo, num_uids);
result = dcerpc_unixinfo_GetPWUid(p, mem_ctx, &r); result = dcerpc_unixinfo_GetPWUid(p, tctx, &r);
return NT_STATUS_IS_OK(result); torture_assert_ntstatus_ok(tctx, result, "GetPWUid failed");
return true;
} }
/* /*
@ -115,44 +114,32 @@ static BOOL test_sidtogid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
/* /*
test the GidToSid interface test the GidToSid interface
*/ */
static BOOL test_gidtosid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) static BOOL test_gidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct unixinfo_GidToSid r; struct unixinfo_GidToSid r;
r.in.gid = 1000; r.in.gid = 1000;
status = dcerpc_unixinfo_GidToSid(p, mem_ctx, &r); status = dcerpc_unixinfo_GidToSid(p, tctx, &r);
if (NT_STATUS_EQUAL(NT_STATUS_NO_SUCH_GROUP, status)) { if (NT_STATUS_EQUAL(NT_STATUS_NO_SUCH_GROUP, status)) {
} else if (!NT_STATUS_IS_OK(status)) { } else torture_assert_ntstatus_ok(tctx, status, "GidToSid failed");
printf("GidToSid failed == %s\n", nt_errstr(status));
return False;
}
return True; return true;
} }
BOOL torture_rpc_unixinfo(struct torture_context *torture) struct torture_suite *torture_rpc_unixinfo(void)
{ {
NTSTATUS status; struct torture_suite *suite;
struct dcerpc_pipe *p; struct torture_tcase *tcase;
TALLOC_CTX *mem_ctx;
BOOL ret = True;
mem_ctx = talloc_init("torture_rpc_unixinfo"); suite = torture_suite_create(talloc_autofree_context(), "UNIXINFO");
tcase = torture_suite_add_rpc_iface_tcase(suite, "unixinfo",
&dcerpc_table_unixinfo);
status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_unixinfo); torture_rpc_tcase_add_test(tcase, "uidtosid", test_uidtosid);
if (!NT_STATUS_IS_OK(status)) { torture_rpc_tcase_add_test(tcase, "getpwuid", test_getpwuid);
return False; torture_rpc_tcase_add_test(tcase, "gidtosid", test_gidtosid);
}
ret &= test_uidtosid(p, mem_ctx); return suite;
ret &= test_getpwuid(p, mem_ctx);
ret &= test_gidtosid(p, mem_ctx);
printf("\n");
talloc_free(mem_ctx);
return ret;
} }

View File

@ -24,43 +24,37 @@
#include "librpc/gen_ndr/ndr_wkssvc_c.h" #include "librpc/gen_ndr/ndr_wkssvc_c.h"
#include "torture/rpc/rpc.h" #include "torture/rpc/rpc.h"
static bool test_NetWkstaGetInfo(struct torture_context *tctx,
static BOOL test_NetWkstaGetInfo(struct dcerpc_pipe *p, struct dcerpc_pipe *p)
TALLOC_CTX *mem_ctx)
{ {
NTSTATUS status; NTSTATUS status;
struct wkssvc_NetWkstaGetInfo r; struct wkssvc_NetWkstaGetInfo r;
union wkssvc_NetWkstaInfo info; union wkssvc_NetWkstaInfo info;
uint16_t levels[] = {100, 101, 102, 502}; uint16_t levels[] = {100, 101, 102, 502};
int i; int i;
BOOL ret = True;
r.in.server_name = dcerpc_server_name(p); r.in.server_name = dcerpc_server_name(p);
r.out.info = &info; r.out.info = &info;
for (i=0;i<ARRAY_SIZE(levels);i++) { for (i=0;i<ARRAY_SIZE(levels);i++) {
r.in.level = levels[i]; r.in.level = levels[i];
printf("testing NetWkstaGetInfo level %u\n", r.in.level); torture_comment(tctx, talloc_asprintf(tctx, "testing NetWkstaGetInfo level %u\n", r.in.level));
status = dcerpc_wkssvc_NetWkstaGetInfo(p, mem_ctx, &r); status = dcerpc_wkssvc_NetWkstaGetInfo(p, tctx, &r);
if (!NT_STATUS_IS_OK(status)) { torture_assert_ntstatus_ok(tctx, status,
printf("NetWkstaGetInfo level %u failed - %s\n", r.in.level, nt_errstr(status)); talloc_asprintf(tctx, "NetWkstaGetInfo level %u failed", r.in.level));
ret = False; torture_assert_werr_ok(tctx, r.out.result,
} talloc_asprintf(tctx, "NetWkstaGetInfo level %u failed", r.in.level));
if (!W_ERROR_IS_OK(r.out.result)) {
printf("NetWkstaGetInfo level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
}
} }
return ret; return true;
} }
static BOOL test_NetWkstaTransportEnum(struct dcerpc_pipe *p, static bool test_NetWkstaTransportEnum(struct torture_context *tctx,
TALLOC_CTX *mem_ctx) struct dcerpc_pipe *p)
{ {
NTSTATUS status; NTSTATUS status;
struct wkssvc_NetWkstaTransportEnum r; struct wkssvc_NetWkstaTransportEnum r;
BOOL ret = True;
uint32_t resume_handle = 0; uint32_t resume_handle = 0;
union wkssvc_NetWkstaTransportCtr ctr; union wkssvc_NetWkstaTransportCtr ctr;
struct wkssvc_NetWkstaTransportCtr0 ctr0; struct wkssvc_NetWkstaTransportCtr0 ctr0;
@ -76,45 +70,28 @@ static BOOL test_NetWkstaTransportEnum(struct dcerpc_pipe *p,
r.out.ctr = &ctr; r.out.ctr = &ctr;
r.out.resume_handle = &resume_handle; r.out.resume_handle = &resume_handle;
printf("testing NetWkstaTransportEnum\n"); status = dcerpc_wkssvc_NetWkstaTransportEnum(p, tctx, &r);
status = dcerpc_wkssvc_NetWkstaTransportEnum(p, mem_ctx, &r); torture_assert_ntstatus_ok(tctx, status, "NetWkstaTransportEnum failed");
if (!NT_STATUS_IS_OK(status)) { torture_assert_werr_ok(tctx, r.out.result,
printf("NetWkstaTransportEnum failed - %s\n", nt_errstr(status)); talloc_asprintf(tctx,
ret = False; "NetWkstaTransportEnum level %u failed", r.in.level));
}
if (!W_ERROR_IS_OK(r.out.result)) {
printf("NetWkstaTransportEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
}
return ret; return true;
} }
BOOL torture_rpc_wkssvc(struct torture_context *torture) struct torture_suite *torture_rpc_wkssvc(void)
{ {
NTSTATUS status; struct torture_suite *suite;
struct dcerpc_pipe *p; struct torture_tcase *tcase;
TALLOC_CTX *mem_ctx;
BOOL ret = True;
mem_ctx = talloc_init("torture_rpc_wkssvc"); suite = torture_suite_create(talloc_autofree_context(), "WKSSVC");
tcase = torture_suite_add_rpc_iface_tcase(suite, "wkssvc",
&dcerpc_table_wkssvc);
status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_wkssvc); torture_rpc_tcase_add_test(tcase, "NetWkstaGetInfo", test_NetWkstaGetInfo);
if (!NT_STATUS_IS_OK(status)) { torture_rpc_tcase_add_test(tcase, "NetWkstaTransportEnum",
talloc_free(mem_ctx); test_NetWkstaTransportEnum);
return False; return suite;
}
if (!test_NetWkstaGetInfo(p, mem_ctx)) {
ret = False;
}
if (!test_NetWkstaTransportEnum(p, mem_ctx)) {
ret = False;
}
talloc_free(mem_ctx);
return ret;
} }

View File

@ -8,8 +8,6 @@ PRIVATE_PROTO_HEADER = \
proto.h proto.h
OBJ_FILES = \ OBJ_FILES = \
connect.o \ connect.o \
dir.o \
maxwrite.o \
scan.o \ scan.o \
util.o \ util.o \
getinfo.o \ getinfo.o \

View File

@ -75,7 +75,7 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
int i; int i;
if (lp_parm_bool(-1, "torture", "dangerous", False)) { if (lp_parm_bool(-1, "torture", "dangerous", False)) {
data = data_blob_talloc(tree, NULL, 16000000); data = data_blob_talloc(tree, NULL, 160000);
} else if (lp_parm_bool(-1, "target", "samba4", False)) { } else if (lp_parm_bool(-1, "target", "samba4", False)) {
data = data_blob_talloc(tree, NULL, UINT16_MAX); data = data_blob_talloc(tree, NULL, UINT16_MAX);
} else { } else {
@ -90,8 +90,6 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
w.in.offset = 0; w.in.offset = 0;
w.in.data = data; w.in.data = data;
printf("writing %d bytes\n", data.length);
status = smb2_write(tree, &w); status = smb2_write(tree, &w);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("write failed - %s\n", nt_errstr(status)); printf("write failed - %s\n", nt_errstr(status));
@ -122,8 +120,6 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
r.in.length = data.length; r.in.length = data.length;
r.in.offset = 0; r.in.offset = 0;
printf("reading %d bytes\n", data.length);
status = smb2_read(tree, tree, &r); status = smb2_read(tree, tree, &r);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
printf("read failed - %s\n", nt_errstr(status)); printf("read failed - %s\n", nt_errstr(status));
@ -143,7 +139,8 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
/* /*
send a create send a create
*/ */
struct smb2_handle torture_smb2_create(struct smb2_tree *tree, const char *fname) static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
const char *fname)
{ {
struct smb2_create io; struct smb2_create io;
NTSTATUS status; NTSTATUS status;

View File

@ -27,18 +27,24 @@
NTSTATUS torture_smb2_init(void) NTSTATUS torture_smb2_init(void)
{ {
register_torture_op("SMB2-CONNECT", torture_smb2_connect); struct torture_suite *suite = torture_suite_create(
register_torture_op("SMB2-SCAN", torture_smb2_scan); talloc_autofree_context(),
register_torture_op("SMB2-SCANGETINFO", torture_smb2_getinfo_scan); "SMB2");
register_torture_op("SMB2-SCANSETINFO", torture_smb2_setinfo_scan); torture_suite_add_simple_test(suite, "CONNECT", torture_smb2_connect);
register_torture_op("SMB2-SCANFIND", torture_smb2_find_scan); torture_suite_add_simple_test(suite, "SCAN", torture_smb2_scan);
register_torture_op("SMB2-GETINFO", torture_smb2_getinfo); torture_suite_add_simple_test(suite, "SCANGETINFO", torture_smb2_getinfo_scan);
register_torture_op("SMB2-SETINFO", torture_smb2_setinfo); torture_suite_add_simple_test(suite, "SCANSETINFO", torture_smb2_setinfo_scan);
register_torture_op("SMB2-FIND", torture_smb2_find); torture_suite_add_simple_test(suite, "SCANFIND", torture_smb2_find_scan);
register_torture_op("SMB2-LOCK", torture_smb2_lock); torture_suite_add_simple_test(suite, "GETINFO", torture_smb2_getinfo);
register_torture_op("SMB2-NOTIFY", torture_smb2_notify); torture_suite_add_simple_test(suite, "SETINFO", torture_smb2_setinfo);
register_torture_op("SMB2-MAXWRITE", torture_smb2_maxwrite); torture_suite_add_simple_test(suite, "FIND", torture_smb2_find);
register_torture_op("SMB2-DIR", torture_smb2_dir); torture_suite_add_simple_test(suite, "LOCK", torture_smb2_lock);
torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify);
suite->description = talloc_strdup(suite,
"SMB2-specific tests");
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -33,35 +33,85 @@
#include "lib/util/dlinklist.h" #include "lib/util/dlinklist.h"
#include "librpc/rpc/dcerpc.h" #include "librpc/rpc/dcerpc.h"
static bool run_matching(struct torture_context *torture,
const char *prefix,
const char *expr,
struct torture_suite *suite,
bool *matched)
{
bool ret = true;
if (suite == NULL) {
struct torture_suite_list *o;
for (o = torture_suites; o; o = o->next) {
if (gen_fnmatch(expr, o->suite->name) == 0) {
*matched = true;
init_iconv();
ret &= torture_run_suite(torture, o->suite);
continue;
}
ret &= run_matching(torture,
o->suite->name, expr, o->suite, matched);
}
} else {
char *name;
struct torture_suite *c;
struct torture_tcase *t;
for (c = suite->children; c; c = c->next) {
asprintf(&name, "%s-%s", prefix, c->name);
if (gen_fnmatch(expr, name) == 0) {
*matched = true;
init_iconv();
ret &= torture_run_suite(torture, c);
free(name);
continue;
}
ret &= run_matching(torture, name, expr, c, matched);
free(name);
}
for (t = suite->testcases; t; t = t->next) {
asprintf(&name, "%s-%s", prefix, t->name);
if (gen_fnmatch(expr, name) == 0) {
*matched = true;
init_iconv();
ret &= torture_run_tcase(torture, t);
}
free(name);
}
}
return ret;
}
#define MAX_COLS 80 /* FIXME: Determine this at run-time */ #define MAX_COLS 80 /* FIXME: Determine this at run-time */
/**************************************************************************** /****************************************************************************
run a specified test or "ALL" run a specified test or "ALL"
****************************************************************************/ ****************************************************************************/
static BOOL run_test(struct torture_context *torture, const char *name) static bool run_test(struct torture_context *torture, const char *name)
{ {
BOOL ret = True; bool ret = true;
bool matched = false;
struct torture_suite_list *o; struct torture_suite_list *o;
BOOL matched = False;
if (strequal(name,"ALL")) { if (strequal(name, "ALL")) {
for (o = torture_suites; o; o = o->next) { for (o = torture_suites; o; o = o->next) {
ret &= torture_run_suite(torture, o->suite); ret &= torture_run_suite(torture, o->suite);
} }
return ret; return ret;
} }
for (o = torture_suites; o; o = o->next) { ret = run_matching(torture, NULL, name, NULL, &matched);
if (gen_fnmatch(name, o->suite->name) == 0) {
matched = True;
init_iconv();
ret &= torture_run_suite(torture, o->suite);
}
}
if (!matched) { if (!matched) {
printf("Unknown torture operation '%s'\n", name); printf("Unknown torture operation '%s'\n", name);
ret = False; return false;
} }
return ret; return ret;
@ -110,7 +160,8 @@ static void parse_dns(const char *dns)
static void usage(poptContext pc) static void usage(poptContext pc)
{ {
struct torture_suite_list *o; struct torture_suite_list *o;
char last_prefix[64]; struct torture_suite *s;
struct torture_tcase *t;
int i; int i;
poptPrintUsage(pc, stdout, 0); poptPrintUsage(pc, stdout, 0);
@ -165,35 +216,35 @@ static void usage(poptContext pc)
printf("Tests are:"); printf("Tests are:");
i = 0;
last_prefix[0] = '\0';
for (o = torture_suites; o; o = o->next) { for (o = torture_suites; o; o = o->next) {
const char * sep; printf("\n%s (%s):\n ", o->suite->description, o->suite->name);
if ((sep = strchr(o->suite->name, '-'))) { i = 0;
if (strncmp(o->suite->name, last_prefix, sep-o->suite->name) != 0) { for (s = o->suite->children; s; s = s->next) {
strncpy(last_prefix, o->suite->name, if (i + strlen(o->suite->name) + strlen(s->name) >= (MAX_COLS - 3)) {
MIN(sizeof(last_prefix), printf("\n ");
sep - o->suite->name));
printf("\n\n ");
i = 0; i = 0;
} }
i+=printf("%s-%s ", o->suite->name, s->name);
} }
if (i + strlen(o->suite->name) >= (MAX_COLS - 2)) { for (t = o->suite->testcases; t; t = t->next) {
printf("\n "); if (i + strlen(o->suite->name) + strlen(t->name) >= (MAX_COLS - 3)) {
i = 0; printf("\n ");
i = 0;
}
i+=printf("%s-%s ", o->suite->name, t->name);
} }
i+=printf("%s ", o->suite->name);
if (i) printf("\n");
} }
printf("\n\n");
printf("The default test is ALL.\n"); printf("\nThe default test is ALL.\n");
exit(1); exit(1);
} }
static BOOL is_binding_string(const char *binding_string) static bool is_binding_string(const char *binding_string)
{ {
TALLOC_CTX *mem_ctx = talloc_named_const(NULL, 0, "is_binding_string"); TALLOC_CTX *mem_ctx = talloc_named_const(NULL, 0, "is_binding_string");
struct dcerpc_binding *binding_struct; struct dcerpc_binding *binding_struct;
@ -249,9 +300,10 @@ static void simple_test_result (struct torture_context *context,
} }
} }
static void simple_comment (struct torture_context *test, const char *comment) static void simple_comment (struct torture_context *test,
const char *comment)
{ {
printf("# %s\n", comment); printf("%s", comment);
} }
const static struct torture_ui_ops std_ui_ops = { const static struct torture_ui_ops std_ui_ops = {
@ -288,9 +340,11 @@ static void subunit_test_result (struct torture_context *context,
} }
} }
static void subunit_comment (struct torture_context *test, const char *comment) static void subunit_comment (struct torture_context *test,
const char *comment)
{ {
printf("# %s\n", comment); /* FIXME Add # sign before each line */
printf("%s", comment);
} }
const static struct torture_ui_ops subunit_ui_ops = { const static struct torture_ui_ops subunit_ui_ops = {
@ -324,7 +378,8 @@ static void harness_test_result (struct torture_context *context,
} }
} }
static void harness_comment (struct torture_context *test, const char *comment) static void harness_comment (struct torture_context *test,
const char *comment)
{ {
printf("# %s\n", comment); printf("# %s\n", comment);
} }
@ -338,7 +393,11 @@ const static struct torture_ui_ops harness_ui_ops = {
static void quiet_suite_start(struct torture_context *ctx, static void quiet_suite_start(struct torture_context *ctx,
struct torture_suite *suite) struct torture_suite *suite)
{ {
int i;
ctx->quiet = true;
for (i = 1; i < ctx->level; i++) putchar('\t');
printf("%s: ", suite->name); printf("%s: ", suite->name);
fflush(stdout);
} }
static void quiet_suite_finish(struct torture_context *ctx, static void quiet_suite_finish(struct torture_context *ctx,
@ -348,8 +407,9 @@ static void quiet_suite_finish(struct torture_context *ctx,
} }
static void quiet_test_result (struct torture_context *context, static void quiet_test_result (struct torture_context *context,
enum torture_result res, const char *reason) enum torture_result res, const char *reason)
{ {
fflush(stdout);
switch (res) { switch (res) {
case TORTURE_OK: putchar('.'); break; case TORTURE_OK: putchar('.'); break;
case TORTURE_FAIL: putchar('E'); break; case TORTURE_FAIL: putchar('E'); break;
@ -371,7 +431,7 @@ const static struct torture_ui_ops quiet_ui_ops = {
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
int opt, i; int opt, i;
BOOL correct = True; bool correct = true;
int max_runtime=0; int max_runtime=0;
int argc_new; int argc_new;
struct torture_context *torture; struct torture_context *torture;
@ -390,7 +450,6 @@ const static struct torture_ui_ops quiet_ui_ops = {
{"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL}, {"num-progs", 0, POPT_ARG_INT, &torture_nprocs, 0, "num progs", NULL},
{"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL}, {"num-ops", 0, POPT_ARG_INT, &torture_numops, 0, "num ops", NULL},
{"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL}, {"entries", 0, POPT_ARG_INT, &torture_entries, 0, "entries", NULL},
{"use-oplocks", 'L', POPT_ARG_NONE, &use_oplocks, 0, "use oplocks", NULL},
{"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL}, {"show-all", 0, POPT_ARG_NONE, &torture_showall, 0, "show all", NULL},
{"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL}, {"loadfile", 0, POPT_ARG_STRING, NULL, OPT_LOADFILE, "loadfile", NULL},
{"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL}, {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
@ -416,7 +475,7 @@ const static struct torture_ui_ops quiet_ui_ops = {
setlinebuf(stdout); setlinebuf(stdout);
/* we are never interested in SIGPIPE */ /* we are never interested in SIGPIPE */
BlockSignals(True,SIGPIPE); BlockSignals(true,SIGPIPE);
pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
POPT_CONTEXT_KEEP_FIRST); POPT_CONTEXT_KEEP_FIRST);
@ -513,7 +572,7 @@ const static struct torture_ui_ops quiet_ui_ops = {
lp_set_cmdline("torture:binding", binding); lp_set_cmdline("torture:binding", binding);
} }
torture = talloc_zero(NULL, struct torture_context); torture = talloc_zero(talloc_autofree_context(), struct torture_context);
if (!strcmp(ui_ops_name, "simple")) { if (!strcmp(ui_ops_name, "simple")) {
torture->ui_ops = &std_ui_ops; torture->ui_ops = &std_ui_ops;
} else if (!strcmp(ui_ops_name, "subunit")) { } else if (!strcmp(ui_ops_name, "subunit")) {
@ -534,15 +593,19 @@ const static struct torture_ui_ops quiet_ui_ops = {
double rate; double rate;
for (i=2;i<argc_new;i++) { for (i=2;i<argc_new;i++) {
if (!run_test(torture, argv_new[i])) { if (!run_test(torture, argv_new[i])) {
correct = False; correct = false;
} }
} }
total = torture->skipped+torture->success+torture->failed; total = torture->skipped+torture->success+torture->failed;
rate = ((total - torture->failed) * (100.0 / total)); if (total == 0) {
printf("Tests: %d, Errors: %d, Skipped: %d. Success rate: %.2f%%\n", printf("No tests run.\n");
} else {
rate = ((total - torture->failed) * (100.0 / total));
printf("Tests: %d, Errors: %d, Skipped: %d. Success rate: %.2f%%\n",
total, torture->failed, torture->skipped, total, torture->failed, torture->skipped,
rate); rate);
}
} }
talloc_free(torture); talloc_free(torture);

View File

@ -31,13 +31,11 @@ _PUBLIC_ int torture_entries=1000;
_PUBLIC_ int torture_failures=1; _PUBLIC_ int torture_failures=1;
_PUBLIC_ int torture_seed=0; _PUBLIC_ int torture_seed=0;
_PUBLIC_ int torture_numasync=100; _PUBLIC_ int torture_numasync=100;
_PUBLIC_ BOOL use_oplocks; _PUBLIC_ bool torture_showall = false;
_PUBLIC_ BOOL use_level_II_oplocks;
_PUBLIC_ BOOL torture_showall = False;
struct torture_suite_list *torture_suites = NULL; struct torture_suite_list *torture_suites = NULL;
_PUBLIC_ NTSTATUS torture_register_suite(struct torture_suite *suite) NTSTATUS torture_register_suite(struct torture_suite *suite)
{ {
struct torture_suite_list *p, *n; struct torture_suite_list *p, *n;
@ -62,26 +60,7 @@ _PUBLIC_ NTSTATUS torture_register_suite(struct torture_suite *suite)
} }
} }
DLIST_ADD(torture_suites, n); DLIST_ADD_END(torture_suites, n, struct torture_suite_list *);
return NT_STATUS_OK;
}
static BOOL wrap_old_torture_fn(struct torture_context *torture, const void *_fn)
{
BOOL (*fn)(struct torture_context *) = _fn;
return fn(torture);
}
/* Backwards compatibility wrapper */
_PUBLIC_ NTSTATUS register_torture_op(const char *name, BOOL (*fn)(struct torture_context *))
{
struct torture_suite *suite;
suite = torture_suite_create(talloc_autofree_context(), name);
torture_suite_add_simple_tcase(suite, name, wrap_old_torture_fn, fn);
torture_register_suite(suite);
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -23,7 +23,8 @@
#include "torture/ui.h" #include "torture/ui.h"
#include "lib/util/dlinklist.h" #include "lib/util/dlinklist.h"
void torture_comment(struct torture_context *context, const char *comment, ...) void torture_comment(struct torture_context *context,
const char *comment, ...)
{ {
va_list ap; va_list ap;
char *tmp; char *tmp;
@ -39,7 +40,8 @@ void torture_comment(struct torture_context *context, const char *comment, ...)
talloc_free(tmp); talloc_free(tmp);
} }
void torture_fail(struct torture_context *context, const char *fmt, ...) void _torture_fail_ext(struct torture_context *context,
const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -51,7 +53,8 @@ void torture_fail(struct torture_context *context, const char *fmt, ...)
context->last_result = TORTURE_FAIL; context->last_result = TORTURE_FAIL;
} }
void torture_skip(struct torture_context *context, const char *fmt, ...) void _torture_skip_ext(struct torture_context *context,
const char *fmt, ...)
{ {
va_list ap; va_list ap;
context->skipped++; context->skipped++;
@ -68,6 +71,7 @@ struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name)
suite->name = talloc_strdup(suite, name); suite->name = talloc_strdup(suite, name);
suite->testcases = NULL; suite->testcases = NULL;
suite->children = NULL;
return suite; return suite;
} }
@ -80,9 +84,22 @@ void torture_tcase_set_fixture(struct torture_tcase *tcase,
tcase->teardown = teardown; tcase->teardown = teardown;
} }
static bool wrap_test_with_testcase(struct torture_context *torture_ctx,
struct torture_tcase *tcase,
struct torture_test *test)
{
bool (*fn) (struct torture_context *,
const void *tcase_data,
const void *test_data);
fn = test->fn;
return fn(torture_ctx, tcase->data, test->data);
}
struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase, struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase,
const char *name, const char *name,
BOOL (*run) (struct torture_context *, bool (*run) (struct torture_context *,
const void *tcase_data, const void *tcase_data,
const void *test_data), const void *test_data),
const void *data) const void *data)
@ -91,7 +108,8 @@ struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase,
test->name = talloc_strdup(test, name); test->name = talloc_strdup(test, name);
test->description = NULL; test->description = NULL;
test->run = run; test->run = wrap_test_with_testcase;
test->fn = run;
test->dangerous = False; test->dangerous = False;
test->data = data; test->data = data;
@ -112,7 +130,7 @@ struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
tcase->fixture_persistent = True; tcase->fixture_persistent = True;
tcase->tests = NULL; tcase->tests = NULL;
DLIST_ADD(suite->testcases, tcase); DLIST_ADD_END(suite->testcases, tcase, struct torture_tcase *);
return tcase; return tcase;
} }
@ -122,7 +140,9 @@ BOOL torture_run_suite(struct torture_context *context,
{ {
BOOL ret = True; BOOL ret = True;
struct torture_tcase *tcase; struct torture_tcase *tcase;
struct torture_suite *tsuite;
context->level++;
if (context->ui_ops->suite_start) if (context->ui_ops->suite_start)
context->ui_ops->suite_start(context, suite); context->ui_ops->suite_start(context, suite);
@ -130,8 +150,14 @@ BOOL torture_run_suite(struct torture_context *context,
ret &= torture_run_tcase(context, tcase); ret &= torture_run_tcase(context, tcase);
} }
for (tsuite = suite->children; tsuite; tsuite = tsuite->next) {
ret &= torture_run_suite(context, tsuite);
}
if (context->ui_ops->suite_finish) if (context->ui_ops->suite_finish)
context->ui_ops->suite_finish(context, suite); context->ui_ops->suite_finish(context, suite);
context->level--;
return ret; return ret;
} }
@ -139,19 +165,18 @@ BOOL torture_run_suite(struct torture_context *context,
static BOOL internal_torture_run_test(struct torture_context *context, static BOOL internal_torture_run_test(struct torture_context *context,
struct torture_tcase *tcase, struct torture_tcase *tcase,
struct torture_test *test, struct torture_test *test,
BOOL already_setup, BOOL already_setup)
const void *tcase_data)
{ {
BOOL ret; BOOL ret;
void *data = NULL;
if (test->dangerous && !lp_parm_bool(-1, "torture", "dangerous", False)) { if (test->dangerous && !torture_setting_bool(context, "dangerous", False)) {
torture_skip(context, "disabled %s - enable dangerous tests to use", _torture_skip_ext(context,
test->name); "disabled %s - enable dangerous tests to use", test->name);
return True; return True;
} }
if (!already_setup && tcase->setup && !tcase->setup(context, &data)) if (!already_setup && tcase->setup &&
!tcase->setup(context, &(tcase->data)))
return False; return False;
context->active_tcase = tcase; context->active_tcase = tcase;
@ -163,14 +188,16 @@ static BOOL internal_torture_run_test(struct torture_context *context,
context->last_reason = NULL; context->last_reason = NULL;
context->last_result = TORTURE_OK; context->last_result = TORTURE_OK;
ret = test->run(context, !already_setup?data:tcase_data, test->data); ret = test->run(context, tcase, test);
if (!ret) { if (!ret) {
context->last_reason = talloc_strdup(context, "..."); if (context->last_reason == NULL)
context->last_reason = talloc_strdup(context, "...");
context->last_result = TORTURE_FAIL; context->last_result = TORTURE_FAIL;
} }
if (context->ui_ops->test_result) if (context->ui_ops->test_result)
context->ui_ops->test_result(context, context->last_result, context->ui_ops->test_result(context,
context->last_result,
context->last_reason); context->last_reason);
@ -186,7 +213,7 @@ static BOOL internal_torture_run_test(struct torture_context *context,
context->active_test = NULL; context->active_test = NULL;
context->active_tcase = NULL; context->active_tcase = NULL;
if (!already_setup && tcase->teardown && !tcase->teardown(context, data)) if (!already_setup && tcase->teardown && !tcase->teardown(context, tcase->data))
return False; return False;
return ret; return ret;
@ -196,27 +223,27 @@ BOOL torture_run_tcase(struct torture_context *context,
struct torture_tcase *tcase) struct torture_tcase *tcase)
{ {
BOOL ret = True; BOOL ret = True;
void *data = NULL;
struct torture_test *test; struct torture_test *test;
context->level++;
context->active_tcase = tcase; context->active_tcase = tcase;
if (context->ui_ops->tcase_start) if (context->ui_ops->tcase_start)
context->ui_ops->tcase_start(context, tcase); context->ui_ops->tcase_start(context, tcase);
if (tcase->fixture_persistent && tcase->setup if (tcase->fixture_persistent && tcase->setup
&& !tcase->setup(context, &data)) { && !tcase->setup(context, &tcase->data)) {
ret = False; ret = False;
goto done; goto done;
} }
for (test = tcase->tests; test; test = test->next) { for (test = tcase->tests; test; test = test->next) {
ret &= internal_torture_run_test(context, tcase, test, ret &= internal_torture_run_test(context, tcase, test,
tcase->fixture_persistent, tcase->fixture_persistent);
(tcase->setup?data:tcase->data));
} }
if (tcase->fixture_persistent && tcase->teardown && if (tcase->fixture_persistent && tcase->teardown &&
!tcase->teardown(context, data)) !tcase->teardown(context, tcase->data))
ret = False; ret = False;
done: done:
@ -225,6 +252,8 @@ done:
if (context->ui_ops->tcase_finish) if (context->ui_ops->tcase_finish)
context->ui_ops->tcase_finish(context, tcase); context->ui_ops->tcase_finish(context, tcase);
context->level--;
return ret; return ret;
} }
@ -232,10 +261,22 @@ BOOL torture_run_test(struct torture_context *context,
struct torture_tcase *tcase, struct torture_tcase *tcase,
struct torture_test *test) struct torture_test *test)
{ {
return internal_torture_run_test(context, tcase, test, False, NULL); return internal_torture_run_test(context, tcase, test, False);
} }
const char *torture_setting(struct torture_context *test, const char *name, int torture_setting_int(struct torture_context *test, const char *name,
int default_value)
{
return lp_parm_int(-1, "torture", name, default_value);
}
bool torture_setting_bool(struct torture_context *test, const char *name,
bool default_value)
{
return lp_parm_bool(-1, "torture", name, default_value);
}
const char *torture_setting_string(struct torture_context *test, const char *name,
const char *default_value) const char *default_value)
{ {
const char *ret = lp_parm_string(-1, "torture", name); const char *ret = lp_parm_string(-1, "torture", name);
@ -246,27 +287,72 @@ const char *torture_setting(struct torture_context *test, const char *name,
return ret; return ret;
} }
static BOOL simple_tcase_helper(struct torture_context *test, static bool wrap_test_with_simple_tcase(struct torture_context *torture_ctx,
const void *tcase_data, struct torture_tcase *tcase,
const void *test_data) struct torture_test *test)
{ {
BOOL (*run) (struct torture_context *, const void *) = test_data; bool (*fn) (struct torture_context *, const void *tcase_data);
return run(test, tcase_data); fn = test->fn;
return fn(torture_ctx, test->data);
} }
struct torture_tcase *torture_suite_add_simple_tcase( struct torture_tcase *torture_suite_add_simple_tcase(
struct torture_suite *suite, struct torture_suite *suite,
const char *name, const char *name,
BOOL (*run) (struct torture_context *test, const void *), bool (*run) (struct torture_context *test, const void *),
const void *data) const void *data)
{ {
struct torture_tcase *tcase; struct torture_tcase *tcase;
struct torture_test *test;
tcase = torture_suite_add_tcase(suite, name); tcase = torture_suite_add_tcase(suite, name);
tcase->data = data;
torture_tcase_add_test(tcase, name, simple_tcase_helper, run); test = talloc(tcase, struct torture_test);
test->name = talloc_strdup(test, name);
test->description = NULL;
test->run = wrap_test_with_simple_tcase;
test->fn = run;
test->data = data;
test->dangerous = False;
DLIST_ADD_END(tcase->tests, test, struct torture_test *);
return tcase;
}
static bool wrap_simple_test(struct torture_context *torture_ctx,
struct torture_tcase *tcase,
struct torture_test *test)
{
bool (*fn) (struct torture_context *);
fn = test->fn;
return fn(torture_ctx);
}
struct torture_tcase *torture_suite_add_simple_test(
struct torture_suite *suite,
const char *name,
bool (*run) (struct torture_context *test))
{
struct torture_test *test;
struct torture_tcase *tcase;
tcase = torture_suite_add_tcase(suite, name);
test = talloc(tcase, struct torture_test);
test->name = talloc_strdup(test, name);
test->description = NULL;
test->run = wrap_simple_test;
test->fn = run;
test->dangerous = false;
DLIST_ADD_END(tcase->tests, test, struct torture_test *);
return tcase; return tcase;
} }
@ -275,3 +361,26 @@ BOOL torture_teardown_free(struct torture_context *torture, void *data)
{ {
return talloc_free(data); return talloc_free(data);
} }
bool torture_suite_add_suite(struct torture_suite *suite,
struct torture_suite *child)
{
if (child == NULL)
return false;
DLIST_ADD_END(suite->children, child, struct torture_suite *);
/* FIXME: Check for duplicates and return false if the
* added suite already exists as a child */
return true;
}
struct torture_suite *torture_find_suite(const char *name)
{
/* FIXME */
return NULL;
}

View File

@ -34,6 +34,10 @@ enum torture_result {
TORTURE_SKIP=3 TORTURE_SKIP=3
}; };
/*
* These callbacks should be implemented by any backend that wishes
* to listen to reports from the torture tests.
*/
struct torture_ui_ops struct torture_ui_ops
{ {
void (*comment) (struct torture_context *, const char *); void (*comment) (struct torture_context *, const char *);
@ -44,10 +48,20 @@ struct torture_ui_ops
void (*test_start) (struct torture_context *, void (*test_start) (struct torture_context *,
struct torture_tcase *, struct torture_tcase *,
struct torture_test *); struct torture_test *);
void (*test_result) (struct torture_context *, enum torture_result, void (*test_result) (struct torture_context *,
const char *reason); enum torture_result, const char *reason);
}; };
/*
* Holds information about a specific run of the testsuite.
* The data in this structure should be considered private to
* the torture tests and should only be used directly by the torture
* code and the ui backends.
*
* Torture tests should instead call the torture_*() macros and functions
* specified below.
*/
struct torture_context struct torture_context
{ {
const struct torture_ui_ops *ui_ops; const struct torture_ui_ops *ui_ops;
@ -61,124 +75,214 @@ struct torture_context
int success; int success;
int failed; int failed;
bool quiet; /* Whether tests should avoid writing output to stdout */
enum torture_result last_result; enum torture_result last_result;
char *last_reason; char *last_reason;
char *outputdir; char *outputdir;
int level;
};
/*
* Describes a particular torture test
*/
struct torture_test {
const char *name;
const char *description;
bool dangerous;
/* Function to call to run this test */
bool (*run) (struct torture_context *torture_ctx,
struct torture_tcase *tcase,
struct torture_test *test);
struct torture_test *prev, *next;
/* Pointer to the actual test function. This is run by the
* run() function above. */
void *fn;
const void *data;
};
/*
* Describes a particular test case.
*/
struct torture_tcase {
const char *name;
const char *description;
bool (*setup) (struct torture_context *tcase, void **data);
bool (*teardown) (struct torture_context *tcase, void *data);
bool fixture_persistent;
void *data;
struct torture_test *tests;
struct torture_tcase *prev, *next;
}; };
struct torture_suite struct torture_suite
{ {
const char *name; const char *name;
const char *description; const char *description;
struct torture_tcase { struct torture_tcase *testcases;
const char *name; struct torture_suite *children;
const char *description;
BOOL (*setup) (struct torture_context *tcase, void **data); /* Pointers to siblings of this torture suite */
BOOL (*teardown) (struct torture_context *tcase, void *data); struct torture_suite *prev, *next;
BOOL fixture_persistent;
const void *data;
struct torture_test {
const char *name;
const char *description;
const void *data;
BOOL dangerous;
BOOL (*run) (struct torture_context *test,
const void *tcase_data,
const void *test_data);
struct torture_test *prev, *next;
} *tests;
struct torture_tcase *prev, *next;
} *testcases;
}; };
struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name); /** Create a new torture suite */
struct torture_suite *torture_suite_create(TALLOC_CTX *mem_ctx,
const char *name);
/** Change the setup and teardown functions for a testcase */
void torture_tcase_set_fixture(struct torture_tcase *tcase, void torture_tcase_set_fixture(struct torture_tcase *tcase,
BOOL (*setup) (struct torture_context *, void **), bool (*setup) (struct torture_context *, void **),
BOOL (*teardown) (struct torture_context *, void *)); bool (*teardown) (struct torture_context *, void *));
/* Add another test to run for a particular testcase */
struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase, struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase,
const char *name, const char *name,
BOOL (*run) (struct torture_context *test, const void *tcase_data, bool (*run) (struct torture_context *test, const void *tcase_data,
const void *test_data), const void *test_data),
const void *test_data); const void *test_data);
/* Add a testcase to a testsuite */
struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite, struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
const char *name); const char *name);
/* Convenience wrapper that adds a testcase against only one
* test will be run */
struct torture_tcase *torture_suite_add_simple_tcase( struct torture_tcase *torture_suite_add_simple_tcase(
struct torture_suite *suite, struct torture_suite *suite,
const char *name, const char *name,
BOOL (*run) (struct torture_context *test, const void *test_data), bool (*run) (struct torture_context *test, const void *test_data),
const void *data); const void *data);
BOOL torture_run_suite(struct torture_context *context, /* Convenience wrapper that adds a test that doesn't need any
* testcase data */
struct torture_tcase *torture_suite_add_simple_test(
struct torture_suite *suite,
const char *name,
bool (*run) (struct torture_context *test));
/* Add a child testsuite to an existing testsuite */
bool torture_suite_add_suite(struct torture_suite *suite,
struct torture_suite *child);
/* Run the specified testsuite recursively */
bool torture_run_suite(struct torture_context *context,
struct torture_suite *suite); struct torture_suite *suite);
BOOL torture_run_tcase(struct torture_context *context, /* Run the specified testcase */
bool torture_run_tcase(struct torture_context *context,
struct torture_tcase *tcase); struct torture_tcase *tcase);
BOOL torture_run_test(struct torture_context *context, /* Run the specified test */
bool torture_run_test(struct torture_context *context,
struct torture_tcase *tcase, struct torture_tcase *tcase,
struct torture_test *test); struct torture_test *test);
#define torture_assert(ctx,expr,string) \ void _torture_fail_ext(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3);
void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
void _torture_skip_ext(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3);
#define torture_assert(torture_ctx,expr,cmt) \
if (!(expr)) { \ if (!(expr)) { \
torture_fail(ctx, "%s:%d (%s): %s", __FILE__, __LINE__, string, \ torture_comment(torture_ctx, __location__": Expression `%s' failed\n", __STRING(expr)); \
__STRING(expr)); \ _torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return False; \ return false; \
} }
#define torture_assert_werr_equal(ctx,got,expected,string) \ #define torture_assert_werr_equal(torture_ctx, got, expected, cmt) \
do { WERROR __got = got, __expected = expected; \ do { WERROR __got = got, __expected = expected; \
if (!W_ERROR_EQUAL(__got, __expected)) { \ if (!W_ERROR_EQUAL(__got, __expected)) { \
torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \ torture_comment(torture_ctx, __location__": "#got" was %s, expected %s\n", \
__LINE__, string, win_errstr(__got), win_errstr(__expected)); \ win_errstr(__got), win_errstr(__expected)); \
return False; \ _torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return false; \
} \ } \
} while (0) } while (0)
#define torture_assert_ntstatus_equal(ctx,got,expected,string) \ #define torture_assert_ntstatus_equal(torture_ctx,got,expected,cmt) \
do { NTSTATUS __got = got, __expected = expected; \ do { NTSTATUS __got = got, __expected = expected; \
if (!NT_STATUS_EQUAL(__got, __expected)) { \ if (!NT_STATUS_EQUAL(__got, __expected)) { \
torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \ torture_comment(torture_ctx, __location__": "#got" was %s, expected %s\n", \
__LINE__, string, nt_errstr(__got), nt_errstr(__expected)); \ nt_errstr(__got), nt_errstr(__expected)); \
return False; \ _torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return false; \
}\ }\
} while(0) } while(0)
#define torture_assert_casestr_equal(ctx,got,expected,string) \ #define torture_assert_casestr_equal(torture_ctx,got,expected,cmt) \
do { const char *__got = got, *__expected = expected; \ do { const char *__got = (got), *__expected = (expected); \
if (strcasecmp(__got, __expected) != 0) { \ if (!strequal(__got, __expected)) { \
torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \ torture_comment(torture_ctx, __location__": "#got" was %s, expected %s\n", __got, __expected); \
__LINE__, string, got, expected); \ _torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return False; \ return false; \
} \ } \
} while(0) } while(0)
#define torture_assert_str_equal(ctx,got,expected,string) \ #define torture_assert_str_equal(torture_ctx,got,expected,cmt)\
do { const char *__got = got, *__expected = expected; \ do { const char *__got = (got), *__expected = (expected); \
if (strcmp(__got, __expected) != 0) { \ if (strcmp_safe(__got, __expected) != 0) { \
torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \ torture_comment(torture_ctx, __location__": "#got" was %s, expected %s\n", __got, __expected); \
__LINE__, string, __got, __expected); \ _torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return False; \ return false; \
} \ } \
} while(0) } while(0)
#define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
do { int __got = (got), __expected = (expected); \
if (__got != __expected) { \
torture_comment(torture_ctx, __location__": "#got" was %d, expected %d\n", __got, __expected); \
_torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return false; \
} \
} while(0)
#define torture_assert_errno_equal(torture_ctx,expected,cmt)\
do { int __expected = (expected); \
if (errno != __expected) { \
torture_comment(torture_ctx, __location__": errno was %d, expected %s\n", errno, strerror(__expected)); \
_torture_fail_ext(torture_ctx, __location__": %s", cmt); \
return false; \
} \
} while(0)
#define torture_skip(torture_ctx,cmt) do {\
_torture_skip_ext(torture_ctx, __location__": %s", cmt);\
return true; \
} while(0)
#define torture_fail(torture_ctx,cmt) do {\
_torture_fail_ext(torture_ctx, __location__": %s", cmt);\
return false; \
} while (0)
#define torture_out stderr
/* Convenience macros */ /* Convenience macros */
#define torture_assert_ntstatus_ok(torture_ctx,expr,cmt) \
torture_assert_ntstatus_equal(torture_ctx,expr,NT_STATUS_OK,cmt)
#define torture_assert_ntstatus_ok(ctx,expr,string) \ #define torture_assert_werr_ok(torture_ctx,expr,cmt) \
torture_assert_ntstatus_equal(ctx,expr,NT_STATUS_OK,string) torture_assert_werr_equal(torture_ctx,expr,WERR_OK,cmt)
#define torture_assert_werr_ok(ctx,expr,string) \ /* Getting settings */
torture_assert_werr_equal(ctx,expr,WERR_OK,string) const char *torture_setting_string(struct torture_context *test, \
const char *name,
const char *default_value);
void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3); int torture_setting_int(struct torture_context *test,
void torture_fail(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3); const char *name,
void torture_skip(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3); int default_value);
const char *torture_setting(struct torture_context *test, const char *name,
const char *default_value); bool torture_setting_bool(struct torture_context *test,
const char *name,
bool default_value);
/* Helper function commonly used */ /* Helper function commonly used */
BOOL torture_teardown_free(struct torture_context *torture, void *data); bool torture_teardown_free(struct torture_context *torture, void *data);
#endif /* __TORTURE_UI_H__ */ #endif /* __TORTURE_UI_H__ */

View File

@ -2,6 +2,7 @@
Unix SMB/CIFS implementation. Unix SMB/CIFS implementation.
SMB torture tester utility functions SMB torture tester utility functions
Copyright (C) Andrew Tridgell 2003 Copyright (C) Andrew Tridgell 2003
Copyright (C) Jelmer Vernooij 2006
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -27,13 +28,15 @@
#include "system/shmem.h" #include "system/shmem.h"
#include "system/wait.h" #include "system/wait.h"
#include "system/time.h" #include "system/time.h"
#include "torture/ui.h"
#include "torture/torture.h" #include "torture/torture.h"
#include "util/dlinklist.h"
/** /**
setup a directory ready for a test setup a directory ready for a test
*/ */
_PUBLIC_ BOOL torture_setup_dir(struct smbcli_state *cli, const char *dname) _PUBLIC_ bool torture_setup_dir(struct smbcli_state *cli, const char *dname)
{ {
smb_raw_exit(cli->session); smb_raw_exit(cli->session);
if (smbcli_deltree(cli->tree, dname) == -1 || if (smbcli_deltree(cli->tree, dname) == -1 ||
@ -279,9 +282,9 @@ void *shm_setup(int size)
check that a wire string matches the flags specified check that a wire string matches the flags specified
not 100% accurate, but close enough for testing not 100% accurate, but close enough for testing
*/ */
BOOL wire_bad_flags(struct smb_wire_string *str, int flags, struct smbcli_state *cli) bool wire_bad_flags(struct smb_wire_string *str, int flags, struct smbcli_state *cli)
{ {
BOOL server_unicode; bool server_unicode;
int len; int len;
if (!str || !str->s) return True; if (!str || !str->s) return True;
len = strlen(str->s); len = strlen(str->s);
@ -350,7 +353,7 @@ void torture_all_info(struct smbcli_tree *tree, const char *fname)
/* /*
set a attribute on a file set a attribute on a file
*/ */
BOOL torture_set_file_attribute(struct smbcli_tree *tree, const char *fname, uint16_t attrib) bool torture_set_file_attribute(struct smbcli_tree *tree, const char *fname, uint16_t attrib)
{ {
union smb_setfileinfo sfinfo; union smb_setfileinfo sfinfo;
NTSTATUS status; NTSTATUS status;
@ -459,7 +462,7 @@ NTSTATUS torture_check_ea(struct smbcli_state *cli,
return NT_STATUS_EA_CORRUPT_ERROR; return NT_STATUS_EA_CORRUPT_ERROR;
} }
BOOL torture_open_connection_share(TALLOC_CTX *mem_ctx, bool torture_open_connection_share(TALLOC_CTX *mem_ctx,
struct smbcli_state **c, struct smbcli_state **c,
const char *hostname, const char *hostname,
const char *sharename, const char *sharename,
@ -475,13 +478,15 @@ BOOL torture_open_connection_share(TALLOC_CTX *mem_ctx,
return False; return False;
} }
(*c)->transport->options.use_oplocks = use_oplocks; (*c)->transport->options.use_oplocks = lp_parm_bool(-1, "torture",
(*c)->transport->options.use_level2_oplocks = use_level_II_oplocks; "use_oplocks", False);
(*c)->transport->options.use_level2_oplocks = lp_parm_bool(-1, "torture",
"use_level2_oplocks", False);
return True; return True;
} }
_PUBLIC_ BOOL torture_open_connection(struct smbcli_state **c, int conn_index) _PUBLIC_ bool torture_open_connection(struct smbcli_state **c, int conn_index)
{ {
const char *host = lp_parm_string(-1, "torture", "host"); const char *host = lp_parm_string(-1, "torture", "host");
const char *share = lp_parm_string(-1, "torture", "share"); const char *share = lp_parm_string(-1, "torture", "share");
@ -511,7 +516,7 @@ _PUBLIC_ BOOL torture_open_connection(struct smbcli_state **c, int conn_index)
return torture_open_connection_share(NULL, c, host, share, NULL); return torture_open_connection_share(NULL, c, host, share, NULL);
} }
_PUBLIC_ BOOL torture_open_connection_ev(struct smbcli_state **c, _PUBLIC_ bool torture_open_connection_ev(struct smbcli_state **c,
int conn_index, int conn_index,
struct event_context *ev) struct event_context *ev)
{ {
@ -546,9 +551,9 @@ _PUBLIC_ BOOL torture_open_connection_ev(struct smbcli_state **c,
_PUBLIC_ BOOL torture_close_connection(struct smbcli_state *c) _PUBLIC_ bool torture_close_connection(struct smbcli_state *c)
{ {
BOOL ret = True; bool ret = True;
if (!c) return True; if (!c) return True;
if (NT_STATUS_IS_ERR(smbcli_tdis(c))) { if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
printf("tdis failed (%s)\n", smbcli_errstr(c->tree)); printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
@ -560,7 +565,7 @@ _PUBLIC_ BOOL torture_close_connection(struct smbcli_state *c)
/* check if the server produced the expected error code */ /* check if the server produced the expected error code */
_PUBLIC_ BOOL check_error(const char *location, struct smbcli_state *c, _PUBLIC_ bool check_error(const char *location, struct smbcli_state *c,
uint8_t eclass, uint32_t ecode, NTSTATUS nterr) uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
{ {
NTSTATUS status; NTSTATUS status;
@ -595,11 +600,12 @@ static void sigcont(int sig)
{ {
} }
double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result) double torture_create_procs(struct torture_context *tctx,
bool (*fn)(struct torture_context *, struct smbcli_state *, int), bool *result)
{ {
int i, status; int i, status;
volatile pid_t *child_status; volatile pid_t *child_status;
volatile BOOL *child_status_out; volatile bool *child_status_out;
int synccount; int synccount;
int tries = 8; int tries = 8;
double start_time_limit = 10 + (torture_nprocs * 1.5); double start_time_limit = 10 + (torture_nprocs * 1.5);
@ -617,7 +623,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
return -1; return -1;
} }
child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs); child_status_out = (volatile bool *)shm_setup(sizeof(bool)*torture_nprocs);
if (!child_status_out) { if (!child_status_out) {
printf("Failed to setup result status shared memory\n"); printf("Failed to setup result status shared memory\n");
return -1; return -1;
@ -664,7 +670,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
_exit(1); _exit(1);
} }
child_status_out[i] = fn(current_cli, i); child_status_out[i] = fn(tctx, current_cli, i);
_exit(0); _exit(0);
} }
} }
@ -714,30 +720,139 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
return timeval_elapsed(&tv); return timeval_elapsed(&tv);
} }
static BOOL wrap_old_torture_multifn(struct torture_context *torture, static bool wrap_smb_multi_test(struct torture_context *torture,
const void *_fn) struct torture_tcase *tcase,
struct torture_test *test)
{ {
BOOL (*fn)(struct smbcli_state *, int ) = _fn; bool (*fn)(struct torture_context *, struct smbcli_state *, int ) = test->fn;
BOOL result; bool result;
torture_create_procs(fn, &result); torture_create_procs(torture, fn, &result);
return result; return result;
} }
_PUBLIC_ NTSTATUS register_torture_multi_op(const char *name, _PUBLIC_ struct torture_test *torture_suite_add_smb_multi_test(
BOOL (*multi_fn)(struct smbcli_state *, int )) struct torture_suite *suite,
const char *name,
bool (*run) (struct torture_context *,
struct smbcli_state *,
int i))
{ {
struct torture_suite *suite; struct torture_test *test;
struct torture_tcase *tcase;
tcase = torture_suite_add_tcase(suite, name);
suite = torture_suite_create(talloc_autofree_context(), name); test = talloc(tcase, struct torture_test);
torture_suite_add_simple_tcase(suite, name, test->name = talloc_strdup(test, name);
wrap_old_torture_multifn, test->description = NULL;
multi_fn); test->run = wrap_smb_multi_test;
torture_register_suite(suite); test->fn = run;
test->dangerous = false;
return NT_STATUS_OK; DLIST_ADD_END(tcase->tests, test, struct torture_test *);
return test;
}
static bool wrap_simple_2smb_test(struct torture_context *torture_ctx,
struct torture_tcase *tcase,
struct torture_test *test)
{
bool (*fn) (struct torture_context *, struct smbcli_state *,
struct smbcli_state *);
bool ret;
struct smbcli_state *cli1, *cli2;
if (!torture_open_connection(&cli1, 0) ||
!torture_open_connection(&cli2, 1))
return false;
fn = test->fn;
ret = fn(torture_ctx, cli1, cli2);
talloc_free(cli1);
talloc_free(cli2);
return ret;
}
_PUBLIC_ struct torture_test *torture_suite_add_2smb_test(
struct torture_suite *suite,
const char *name,
bool (*run) (struct torture_context *,
struct smbcli_state *,
struct smbcli_state *))
{
struct torture_test *test;
struct torture_tcase *tcase;
tcase = torture_suite_add_tcase(suite, name);
test = talloc(tcase, struct torture_test);
test->name = talloc_strdup(test, name);
test->description = NULL;
test->run = wrap_simple_2smb_test;
test->fn = run;
test->dangerous = false;
DLIST_ADD_END(tcase->tests, test, struct torture_test *);
return test;
}
static bool wrap_simple_1smb_test(struct torture_context *torture_ctx,
struct torture_tcase *tcase,
struct torture_test *test)
{
bool (*fn) (struct torture_context *, struct smbcli_state *);
bool ret;
struct smbcli_state *cli1;
if (!torture_open_connection(&cli1, 0))
return false;
fn = test->fn;
ret = fn(torture_ctx, cli1);
talloc_free(cli1);
return ret;
}
_PUBLIC_ struct torture_test *torture_suite_add_1smb_test(
struct torture_suite *suite,
const char *name,
bool (*run) (struct torture_context *,
struct smbcli_state *))
{
struct torture_test *test;
struct torture_tcase *tcase;
tcase = torture_suite_add_tcase(suite, name);
test = talloc(tcase, struct torture_test);
test->name = talloc_strdup(test, name);
test->description = NULL;
test->run = wrap_simple_1smb_test;
test->fn = run;
test->dangerous = false;
DLIST_ADD_END(tcase->tests, test, struct torture_test *);
return test;
} }