wmi-1.3.16 from opsview.com

This commit is contained in:
Are Casilla
2019-02-16 00:16:52 +01:00
parent 163fdd3d1b
commit 17b3af2911
2146 changed files with 678824 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
/*
Unix SMB/CIFS implementation.
local testing of RPC binding string parsing
Copyright (C) Jelmer Vernooij 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "librpc/gen_ndr/epmapper.h"
#include "librpc/rpc/dcerpc.h"
#include "torture/torture.h"
static bool test_BindingString(struct torture_context *tctx,
const void *test_data)
{
const char *binding = test_data;
struct dcerpc_binding *b, *b2;
const char *s, *s2;
struct epm_tower tower;
TALLOC_CTX *mem_ctx = tctx;
/* Parse */
torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(mem_ctx, binding, &b),
"Error parsing binding string");
s = dcerpc_binding_string(mem_ctx, b);
torture_assert(tctx, s != NULL, "Error converting binding back to string");
torture_assert_casestr_equal(tctx, binding, s,
"Mismatch while comparing original and regenerated binding strings");
/* Generate protocol towers */
torture_assert_ntstatus_ok(tctx, dcerpc_binding_build_tower(mem_ctx, b, &tower),
"Error generating protocol tower");
/* Convert back to binding and then back to string and compare */
torture_assert_ntstatus_ok(tctx, dcerpc_binding_from_tower(mem_ctx, &tower, &b2),
"Error generating binding from tower for original binding");
/* Compare to a stripped down version of the binding string because
* the protocol tower doesn't contain the extra option data */
b->options = NULL;
b->flags = 0;
s = dcerpc_binding_string(mem_ctx, b);
torture_assert(tctx, s != NULL, "Error converting binding back to string for (stripped down)");
s2 = dcerpc_binding_string(mem_ctx, b2);
torture_assert(tctx, s != NULL, "Error converting binding back to string");
if (is_ipaddress(b->host))
torture_assert_casestr_equal(tctx, s, s2, "Mismatch while comparing original and from protocol tower generated binding strings");
return true;
}
static const char *test_strings[] = {
"ncacn_np:",
"ncalrpc:",
"ncalrpc:[,Security=Sane]",
"ncacn_np:[rpcecho]",
"ncacn_np:127.0.0.1[rpcecho]",
"ncacn_ip_tcp:127.0.0.1",
"ncacn_ip_tcp:127.0.0.1[20]",
"ncacn_ip_tcp:127.0.0.1[20,sign]",
"ncacn_ip_tcp:127.0.0.1[20,Security=Foobar,sign]",
"ncacn_http:127.0.0.1",
"ncacn_http:127.0.0.1[78]",
"ncacn_http:127.0.0.1[78,ProxyServer=myproxy:3128]",
"ncacn_np:localhost[rpcecho]",
"ncacn_np:[/pipe/rpcecho]",
"ncacn_np:localhost[/pipe/rpcecho,sign,seal]",
"ncacn_np:[,sign]",
"ncadg_ip_udp:",
"308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:localhost",
"308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:127.0.0.1",
"ncacn_unix_stream:[/tmp/epmapper]",
"ncalrpc:[IDENTIFIER]",
"ncacn_unix_stream:[/tmp/epmapper,sign]",
};
struct torture_suite *torture_local_binding_string(TALLOC_CTX *mem_ctx)
{
int i;
struct torture_suite *suite = torture_suite_create(mem_ctx,
"BINDING");
for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
torture_suite_add_simple_tcase(suite, test_strings[i],
test_BindingString, test_strings[i]);
}
return suite;
}
+45
View File
@@ -0,0 +1,45 @@
#################################
# Start SUBSYSTEM TORTURE_LOCAL
[MODULE::TORTURE_LOCAL]
SUBSYSTEM = torture
INIT_FUNCTION = torture_local_init
PRIVATE_PROTO_HEADER = \
proto.h
OBJ_FILES = \
iconv.o \
../../lib/crypto/md4test.o \
../../lib/crypto/md5test.o \
../../lib/crypto/hmacmd5test.o \
../../lib/crypto/sha1test.o \
../../lib/crypto/hmacsha1test.o \
../../lib/talloc/testsuite.o \
../../lib/replace/test/os2_delete.o \
../../lib/replace/test/testsuite.o \
messaging.o \
binding_string.o \
idtree.o \
socket.o \
irpc.o \
registry.o \
resolve.o \
util_strlist.o \
util_file.o \
sddl.o \
ndr.o \
event.o \
local.o \
dbspeed.o \
torture.o
PUBLIC_DEPENDENCIES = \
RPC_NDR_ECHO \
LIBCLI_SMB \
MESSAGING \
ICONV \
registry \
LIBCRYPTO \
POPT_CREDENTIALS \
TORTURE_AUTH \
TORTURE_UTIL
# End SUBSYSTEM TORTURE_LOCAL
#################################
+246
View File
@@ -0,0 +1,246 @@
/*
Unix SMB/CIFS implementation.
local test for tdb/ldb speed
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "system/filesys.h"
#include "lib/tdb/include/tdb.h"
#include "lib/ldb/include/ldb.h"
#include "lib/ldb/include/ldb_errors.h"
#include "lib/db_wrap.h"
#include "torture/torture.h"
static BOOL tdb_add_record(struct tdb_wrap *tdbw, const char *fmt1, const char *fmt2, int i)
{
TDB_DATA key, data;
int ret;
key.dptr = (uint8_t *)talloc_asprintf(tdbw, fmt1, i);
key.dsize = strlen((char *)key.dptr)+1;
data.dptr = (uint8_t *)talloc_asprintf(tdbw, fmt2, i+10000);
data.dsize = strlen((char *)data.dptr)+1;
ret = tdb_store(tdbw->tdb, key, data, TDB_INSERT);
talloc_free(key.dptr);
talloc_free(data.dptr);
return ret == 0;
}
/*
test tdb speed
*/
static BOOL test_tdb_speed(struct torture_context *torture, const void *_data)
{
struct timeval tv;
struct tdb_wrap *tdbw;
int timelimit = torture_setting_int(torture, "timelimit", 10);
int i, count;
TALLOC_CTX *tmp_ctx = talloc_new(torture);
unlink("test.tdb");
torture_comment(torture, "Testing tdb speed for sidmap\n");
tdbw = tdb_wrap_open(tmp_ctx, "test.tdb",
10000, 0, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (!tdbw) {
torture_fail(torture, "Failed to open test.tdb\n");
goto failed;
}
torture_comment(torture, "Adding %d SID records\n", torture_entries);
for (i=0;i<torture_entries;i++) {
if (!tdb_add_record(tdbw,
"S-1-5-21-53173311-3623041448-2049097239-%u",
"UID %u", i)) {
torture_result(torture, TORTURE_FAIL, "Failed to add SID %d\n", i);
goto failed;
}
if (!tdb_add_record(tdbw,
"UID %u",
"S-1-5-21-53173311-3623041448-2049097239-%u", i)) {
torture_result(torture, TORTURE_FAIL, "Failed to add UID %d\n", i);
goto failed;
}
}
torture_comment(torture, "Testing for %d seconds\n", timelimit);
tv = timeval_current();
for (count=0;timeval_elapsed(&tv) < timelimit;count++) {
TDB_DATA key, data;
i = random() % torture_entries;
key.dptr = (uint8_t *)talloc_asprintf(tmp_ctx, "S-1-5-21-53173311-3623041448-2049097239-%u", i);
key.dsize = strlen((char *)key.dptr)+1;
data = tdb_fetch(tdbw->tdb, key);
if (data.dptr == NULL) {
torture_result(torture, TORTURE_FAIL, "Failed to fetch SID %d\n", i);
goto failed;
}
free(data.dptr);
key.dptr = (uint8_t *)talloc_asprintf(tmp_ctx, "UID %u", i);
key.dsize = strlen((char *)key.dptr)+1;
data = tdb_fetch(tdbw->tdb, key);
if (data.dptr == NULL) {
torture_result(torture, TORTURE_FAIL, "Failed to fetch UID %d\n", i);
goto failed;
}
free(data.dptr);
}
torture_comment(torture, "tdb speed %.2f ops/sec\n", count/timeval_elapsed(&tv));
unlink("test.tdb");
talloc_free(tmp_ctx);
return True;
failed:
unlink("test.tdb");
talloc_free(tmp_ctx);
return False;
}
static BOOL ldb_add_record(struct ldb_context *ldb, unsigned rid)
{
struct ldb_message *msg;
int ret;
msg = ldb_msg_new(ldb);
if (msg == NULL) {
return False;
}
msg->dn = ldb_dn_new_fmt(msg, ldb, "SID=S-1-5-21-53173311-3623041448-2049097239-%u", rid);
if (msg->dn == NULL) {
return False;
}
if (ldb_msg_add_fmt(msg, "UID", "%u", rid) != 0) {
return False;
}
ret = ldb_add(ldb, msg);
talloc_free(msg);
return ret == LDB_SUCCESS;
}
/*
test ldb speed
*/
static BOOL test_ldb_speed(struct torture_context *torture, const void *_data)
{
struct timeval tv;
struct ldb_context *ldb;
int timelimit = torture_setting_int(torture, "timelimit", 10);
int i, count;
TALLOC_CTX *tmp_ctx = talloc_new(torture);
struct ldb_ldif *ldif;
const char *init_ldif = "dn: @INDEXLIST\n" \
"@IDXATTR: UID\n";
unlink("./test.ldb");
torture_comment(torture, "Testing ldb speed for sidmap\n");
ldb = ldb_wrap_connect(tmp_ctx, "tdb://test.ldb",
NULL, NULL, LDB_FLG_NOSYNC, NULL);
if (!ldb) {
torture_fail(torture, "Failed to open test.ldb\n");
goto failed;
}
/* add an index */
ldif = ldb_ldif_read_string(ldb, &init_ldif);
if (ldif == NULL) goto failed;
if (ldb_add(ldb, ldif->msg) != LDB_SUCCESS) goto failed;
talloc_free(ldif);
torture_comment(torture, "Adding %d SID records\n", torture_entries);
for (i=0;i<torture_entries;i++) {
if (!ldb_add_record(ldb, i)) {
torture_result(torture, TORTURE_FAIL, "Failed to add SID %d\n", i);
goto failed;
}
}
if (talloc_total_blocks(torture) > 100) {
torture_result(torture, TORTURE_FAIL, "memory leak in ldb add\n");
goto failed;
}
torture_comment(torture, "Testing for %d seconds\n", timelimit);
tv = timeval_current();
for (count=0;timeval_elapsed(&tv) < timelimit;count++) {
struct ldb_dn *dn;
struct ldb_result *res;
char *expr;
i = random() % torture_entries;
dn = ldb_dn_new_fmt(tmp_ctx, ldb, "SID=S-1-5-21-53173311-3623041448-2049097239-%u", i);
if (ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res) != LDB_SUCCESS || res->count != 1) {
torture_fail(torture, talloc_asprintf(torture, "Failed to find SID %d\n", i));
}
talloc_free(res);
talloc_free(dn);
expr = talloc_asprintf(tmp_ctx, "(UID=%u)", i);
if (ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res) != LDB_SUCCESS || res->count != 1) {
torture_fail(torture, talloc_asprintf(torture, "Failed to find UID %d\n", i));
}
talloc_free(res);
talloc_free(expr);
}
if (talloc_total_blocks(torture) > 100) {
torture_fail(torture, "memory leak in ldb search\n");
goto failed;
}
torture_comment(torture, "ldb speed %.2f ops/sec\n", count/timeval_elapsed(&tv));
unlink("./test.ldb");
talloc_free(tmp_ctx);
return True;
failed:
unlink("./test.ldb");
talloc_free(tmp_ctx);
return False;
}
struct torture_suite *torture_local_dbspeed(TALLOC_CTX *mem_ctx)
{
struct torture_suite *s = torture_suite_create(mem_ctx, "DBSPEED");
torture_suite_add_simple_tcase(s, "tdb_speed", test_tdb_speed, NULL);
torture_suite_add_simple_tcase(s, "ldb_speed", test_ldb_speed, NULL);
return s;
}
+130
View File
@@ -0,0 +1,130 @@
/*
Unix SMB/CIFS implementation.
testing of the events subsystem
Copyright (C) Stefan Metzmacher
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "lib/events/events.h"
#include "system/filesys.h"
#include "torture/torture.h"
const struct event_ops *event_standard_get_ops(void);
const struct event_ops *event_liboop_get_ops(void);
const struct event_ops *gtk_event_get_ops(void);
static int write_fd, read_fd;
static struct fd_event *fde;
static int te_count;
static int fde_count;
static struct torture_context *test;
static void fde_handler(struct event_context *ev_ctx, struct fd_event *f,
uint16_t flags, void *private)
{
int *fd = private;
torture_comment(test, "event[%d] fd[%d] events[0x%08X]%s%s\n",
fde_count, *fd, flags,
(flags & EVENT_FD_READ)?" EVENT_FD_READ":"",
(flags & EVENT_FD_WRITE)?" EVENT_FD_WRITE":"");
if (fde_count > 5) {
torture_result(test, TORTURE_FAIL,
__location__": got more than fde 5 events - bug!");
talloc_free(fde);
fde = NULL;
return;
}
event_set_fd_flags(fde, 0);
fde_count++;
}
static void timed_handler(struct event_context *ev_ctx, struct timed_event *te,
struct timeval tval, void *private)
{
torture_comment(test, "timed_handler called[%d]\n", te_count);
if (te_count > 2) {
close(write_fd);
write_fd = -1;
}
if (te_count > 5) {
torture_comment(test, "remove fd event!\n");
talloc_free(fde);
fde = NULL;
return;
}
te_count++;
event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(0,500), timed_handler, private);
}
static bool test_event_context(struct torture_context *torture_ctx,
const void *test_data)
{
struct event_context *ev_ctx;
int fd[2] = { -1, -1 };
BOOL try_epoll = (BOOL)test_data;
TALLOC_CTX *mem_ctx = torture_ctx;
ev_ctx = event_context_init_ops(mem_ctx,
event_standard_get_ops(),
&try_epoll);
test = torture_ctx;
/* reset globals */
write_fd = -1;
read_fd = -1;
fde = NULL;
te_count = 0;
fde_count = 0;
/* create a pipe */
pipe(fd);
read_fd = fd[0];
write_fd = fd[1];
fde = event_add_fd(ev_ctx, ev_ctx, read_fd, EVENT_FD_READ, fde_handler, &read_fd);
event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(0,500), timed_handler, fde);
event_loop_wait(ev_ctx);
close(read_fd);
close(write_fd);
talloc_free(ev_ctx);
return true;
}
struct torture_suite *torture_local_event(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "EVENT");
torture_suite_add_simple_tcase(suite, "standard with select",
test_event_context,
(void *)False);
torture_suite_add_simple_tcase(suite, "standard try epoll (or select)",
test_event_context,
(void *)True);
return suite;
}
+413
View File
@@ -0,0 +1,413 @@
/*
Unix SMB/CIFS implementation.
local testing of iconv routines. This tests the system iconv code against
the built-in iconv code
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "torture/torture.h"
#include "system/iconv.h"
#include "system/time.h"
#include "libcli/raw/libcliraw.h"
#include "torture/util.h"
#if HAVE_NATIVE_ICONV
/*
generate a UTF-16LE buffer for a given unicode codepoint
*/
static int gen_codepoint_utf16(unsigned int codepoint,
char *buf, size_t *size)
{
static iconv_t cd;
uint8_t in[4];
char *ptr_in;
size_t size_in, size_out, ret;
if (!cd) {
cd = iconv_open("UTF-16LE", "UCS-4LE");
if (cd == (iconv_t)-1) {
cd = NULL;
return -1;
}
}
in[0] = codepoint & 0xFF;
in[1] = (codepoint>>8) & 0xFF;
in[2] = (codepoint>>16) & 0xFF;
in[3] = (codepoint>>24) & 0xFF;
ptr_in = (char *)in;
size_in = 4;
size_out = 8;
ret = iconv(cd, &ptr_in, &size_in, &buf, &size_out);
*size = 8 - size_out;
return ret;
}
/*
work out the unicode codepoint of the first UTF-8 character in the buffer
*/
static unsigned int get_codepoint(char *buf, size_t size, const char *charset)
{
iconv_t cd;
uint8_t out[4];
char *ptr_out;
size_t size_out, size_in, ret;
cd = iconv_open("UCS-4LE", charset);
size_in = size;
ptr_out = (char *)out;
size_out = sizeof(out);
memset(out, 0, sizeof(out));
ret = iconv(cd, &buf, &size_in, &ptr_out, &size_out);
iconv_close(cd);
return out[0] | (out[1]<<8) | (out[2]<<16) | (out[3]<<24);
}
/*
display a buffer with name prefix
*/
static void show_buf(const char *name, uint8_t *buf, size_t size)
{
int i;
printf("%s ", name);
for (i=0;i<size;i++) {
printf("%02x ", buf[i]);
}
printf("\n");
}
/*
given a UTF-16LE buffer, test the system and built-in iconv code to
make sure they do exactly the same thing in converting the buffer to
"charset", then convert it back again and ensure we get the same
buffer back
*/
static bool test_buffer(struct torture_context *test,
uint8_t *inbuf, size_t size, const char *charset)
{
uint8_t buf1[1000], buf2[1000], buf3[1000];
size_t outsize1, outsize2, outsize3;
const char *ptr_in;
char *ptr_out;
size_t size_in1, size_in2, size_in3;
size_t ret1, ret2, ret3, len1, len2;
int errno1, errno2;
static iconv_t cd;
static smb_iconv_t cd2, cd3;
static const char *last_charset;
if (cd && last_charset) {
iconv_close(cd);
smb_iconv_close(cd2);
smb_iconv_close(cd3);
cd = NULL;
}
if (!cd) {
cd = iconv_open(charset, "UTF-16LE");
if (cd == (iconv_t)-1) {
torture_fail(test,
talloc_asprintf(test,
"failed to open %s to UTF-16LE\n",
charset));
cd = NULL;
return false;
}
cd2 = smb_iconv_open(charset, "UTF-16LE");
cd3 = smb_iconv_open("UTF-16LE", charset);
last_charset = charset;
}
/* internal convert to charset - placing result in buf1 */
ptr_in = (const char *)inbuf;
ptr_out = (char *)buf1;
size_in1 = size;
outsize1 = sizeof(buf1);
memset(ptr_out, 0, outsize1);
errno = 0;
ret1 = smb_iconv(cd2, &ptr_in, &size_in1, &ptr_out, &outsize1);
errno1 = errno;
/* system convert to charset - placing result in buf2 */
ptr_in = (const char *)inbuf;
ptr_out = (char *)buf2;
size_in2 = size;
outsize2 = sizeof(buf2);
memset(ptr_out, 0, outsize2);
errno = 0;
ret2 = iconv(cd, discard_const_p(char *, &ptr_in), &size_in2, &ptr_out, &outsize2);
errno2 = errno;
len1 = sizeof(buf1) - outsize1;
len2 = sizeof(buf2) - outsize2;
/* codepoints above 1M are not interesting for now */
if (len2 > len1 &&
memcmp(buf1, buf2, len1) == 0 &&
get_codepoint((char *)(buf2+len1), len2-len1, charset) >= (1<<20)) {
return true;
}
if (len1 > len2 &&
memcmp(buf1, buf2, len2) == 0 &&
get_codepoint((char *)(buf1+len2), len1-len2, charset) >= (1<<20)) {
return true;
}
torture_assert_int_equal(test, ret1, ret2, "ret mismatch");
if (errno1 != errno2) {
show_buf(" rem1:", inbuf+(size-size_in1), size_in1);
show_buf(" rem2:", inbuf+(size-size_in2), size_in2);
torture_fail(test, talloc_asprintf(test,
"e1=%s e2=%s", strerror(errno1), strerror(errno2)));
}
torture_assert_int_equal(test, outsize1, outsize2, "outsize mismatch");
torture_assert_int_equal(test, size_in1, size_in2, "size_in mismatch");
if (len1 != len2 ||
memcmp(buf1, buf2, len1) != 0) {
torture_comment(test, "size=%d ret1=%d ret2=%d", (int)size, (int)ret1, (int)ret2);
show_buf(" IN1:", inbuf, size-size_in1);
show_buf(" IN2:", inbuf, size-size_in2);
show_buf("OUT1:", buf1, len1);
show_buf("OUT2:", buf2, len2);
if (len2 > len1 && memcmp(buf1, buf2, len1) == 0) {
torture_comment(test, "next codepoint is %u",
get_codepoint((char *)(buf2+len1), len2-len1, charset));
}
if (len1 > len2 && memcmp(buf1, buf2, len2) == 0) {
torture_comment(test, "next codepoint is %u",
get_codepoint((char *)(buf1+len2),len1-len2, charset));
}
torture_fail(test, "failed");
}
/* convert back to UTF-16, putting result in buf3 */
size = size - size_in1;
ptr_in = (const char *)buf1;
ptr_out = (char *)buf3;
size_in3 = len1;
outsize3 = sizeof(buf3);
memset(ptr_out, 0, outsize3);
ret3 = smb_iconv(cd3, &ptr_in, &size_in3, &ptr_out, &outsize3);
/* we only internally support the first 1M codepoints */
if (outsize3 != sizeof(buf3) - size &&
get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3),
size - (sizeof(buf3) - outsize3),
"UTF-16LE") >= (1<<20)) {
return true;
}
torture_assert_int_equal(test, ret3, 0, talloc_asprintf(test,
"pull failed - %s", strerror(errno)));
if (strncmp(charset, "UTF", 3) != 0) {
/* don't expect perfect mappings for non UTF charsets */
return true;
}
torture_assert_int_equal(test, outsize3, sizeof(buf3) - size,
"wrong outsize3");
if (memcmp(buf3, inbuf, size) != 0) {
torture_comment(test, "pull bytes mismatch:");
show_buf("inbuf", inbuf, size);
show_buf(" buf3", buf3, sizeof(buf3) - outsize3);
torture_fail(test, "");
torture_comment(test, "next codepoint is %u\n",
get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3),
size - (sizeof(buf3) - outsize3),
"UTF-16LE"));
}
return true;
}
/*
test the push_codepoint() and next_codepoint() functions for a given
codepoint
*/
static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint)
{
uint8_t buf[10];
size_t size, size2;
codepoint_t c;
size = push_codepoint((char *)buf, codepoint);
torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000),
"Invalid Codepoint range");
if (size == -1) return true;
buf[size] = random();
buf[size+1] = random();
buf[size+2] = random();
buf[size+3] = random();
c = next_codepoint((char *)buf, &size2);
torture_assert(tctx, c == codepoint,
talloc_asprintf(tctx,
"next_codepoint(%u) failed - gave %u", codepoint, c));
torture_assert(tctx, size2 == size,
talloc_asprintf(tctx, "next_codepoint(%u) gave wrong size %d (should be %d)\n",
codepoint, (int)size2, (int)size));
return true;
}
static bool test_next_codepoint(struct torture_context *tctx)
{
unsigned int codepoint;
for (codepoint=0;codepoint<(1<<20);codepoint++) {
if (!test_codepoint(tctx, codepoint))
return false;
}
return true;
}
static bool test_first_1m(struct torture_context *tctx)
{
unsigned int codepoint;
size_t size;
unsigned char inbuf[1000];
for (codepoint=0;codepoint<(1<<20);codepoint++) {
if (gen_codepoint_utf16(codepoint, (char *)inbuf, &size) != 0) {
continue;
}
if (codepoint % 1000 == 0) {
if (torture_setting_bool(tctx, "progress", True)) {
torture_comment(tctx, "codepoint=%u \r", codepoint);
}
}
if (!test_buffer(tctx, inbuf, size, "UTF-8"))
return false;
}
return true;
}
static bool test_random_5m(struct torture_context *tctx)
{
unsigned char inbuf[1000];
unsigned int i;
for (i=0;i<500000;i++) {
size_t size;
unsigned int c;
if (i % 1000 == 0) {
if (torture_setting_bool(tctx, "progress", true)) {
torture_comment(tctx, "i=%u \r", i);
}
}
size = random() % 100;
for (c=0;c<size;c++) {
if (random() % 100 < 80) {
inbuf[c] = random() % 128;
} else {
inbuf[c] = random();
}
if (random() % 10 == 0) {
inbuf[c] |= 0xd8;
}
if (random() % 10 == 0) {
inbuf[c] |= 0xdc;
}
}
if (!test_buffer(tctx, inbuf, size, "UTF-8")) {
printf("i=%d failed UTF-8\n", i);
return false;
}
if (!test_buffer(tctx, inbuf, size, "CP850")) {
printf("i=%d failed CP850\n", i);
return false;
}
}
return true;
}
struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
{
static iconv_t cd;
struct torture_suite *suite = torture_suite_create(mem_ctx, "ICONV");
if (!lp_parm_bool(-1, "iconv", "native", True)) {
printf("system iconv disabled - skipping test\n");
return NULL;
}
cd = iconv_open("UTF-16LE", "UCS-4LE");
if (cd == (iconv_t)-1) {
printf("unable to test - system iconv library does not support UTF-16LE -> UCS-4LE\n");
return NULL;
}
iconv_close(cd);
cd = iconv_open("UTF-16LE", "CP850");
if (cd == (iconv_t)-1) {
printf("unable to test - system iconv library does not support UTF-16LE -> CP850\n");
return NULL;
}
iconv_close(cd);
srandom(time(NULL));
torture_suite_add_simple_test(suite, "next_codepoint()",
test_next_codepoint);
torture_suite_add_simple_test(suite, "first 1M codepoints",
test_first_1m);
torture_suite_add_simple_test(suite, "5M random UTF-16LE sequences",
test_random_5m);
return suite;
}
#else
struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
{
printf("No native iconv library - can't run iconv test\n");
return NULL;
}
#endif
+104
View File
@@ -0,0 +1,104 @@
/*
Unix SMB/CIFS implementation.
local testing of idtree routines.
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "torture/torture.h"
static bool torture_local_idtree_simple(struct torture_context *tctx)
{
struct idr_context *idr;
int i;
int *ids;
int *present;
extern int torture_numops;
int n = torture_numops;
TALLOC_CTX *mem_ctx = tctx;
idr = idr_init(mem_ctx);
ids = talloc_zero_array(mem_ctx, int, n);
present = talloc_zero_array(mem_ctx, int, n);
for (i=0;i<n;i++) {
ids[i] = -1;
}
for (i=0;i<n;i++) {
int ii = random() % n;
void *p = idr_find(idr, ids[ii]);
if (present[ii]) {
if (p != &ids[ii]) {
torture_fail(tctx, talloc_asprintf(tctx,
"wrong ptr at %d - %p should be %p",
ii, p, &ids[ii]));
}
if (random() % 7 == 0) {
if (idr_remove(idr, ids[ii]) != 0) {
torture_fail(tctx, talloc_asprintf(tctx,
"remove failed at %d (id=%d)",
i, ids[ii]));
}
present[ii] = 0;
ids[ii] = -1;
}
} else {
if (p != NULL) {
torture_fail(tctx, talloc_asprintf(tctx,
"non-present at %d gave %p (would be %d)",
ii, p,
(int)(((char *)p) - (char *)(&ids[0])) / sizeof(int)));
}
if (random() % 5) {
ids[ii] = idr_get_new(idr, &ids[ii], n);
if (ids[ii] < 0) {
torture_fail(tctx, talloc_asprintf(tctx,
"alloc failure at %d (ret=%d)",
ii, ids[ii]));
} else {
present[ii] = 1;
}
}
}
}
torture_comment(tctx, "done %d random ops\n", i);
for (i=0;i<n;i++) {
if (present[i]) {
if (idr_remove(idr, ids[i]) != 0) {
torture_fail(tctx, talloc_asprintf(tctx,
"delete failed on cleanup at %d (id=%d)",
i, ids[i]));
}
}
}
torture_comment(tctx, "cleaned up\n");
return true;
}
struct torture_suite *torture_local_idtree(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "IDTREE");
torture_suite_add_simple_test(suite, "idtree", torture_local_idtree_simple);
return suite;
}
+256
View File
@@ -0,0 +1,256 @@
/*
Unix SMB/CIFS implementation.
local test for irpc code
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "lib/events/events.h"
#include "lib/messaging/irpc.h"
#include "librpc/gen_ndr/ndr_echo.h"
#include "torture/torture.h"
const uint32_t MSG_ID1 = 1, MSG_ID2 = 2;
static BOOL test_debug;
struct irpc_test_data
{
struct messaging_context *msg_ctx1, *msg_ctx2;
struct event_context *ev;
};
/*
serve up AddOne over the irpc system
*/
static NTSTATUS irpc_AddOne(struct irpc_message *irpc, struct echo_AddOne *r)
{
*r->out.out_data = r->in.in_data + 1;
if (test_debug) {
printf("irpc_AddOne: in=%u in+1=%u out=%u\n",
r->in.in_data, r->in.in_data+1, *r->out.out_data);
}
return NT_STATUS_OK;
}
/*
a deferred reply to echodata
*/
static void deferred_echodata(struct event_context *ev, struct timed_event *te,
struct timeval t, void *private)
{
struct irpc_message *irpc = talloc_get_type(private, struct irpc_message);
struct echo_EchoData *r = irpc->data;
r->out.out_data = talloc_memdup(r, r->in.in_data, r->in.len);
if (r->out.out_data == NULL) {
irpc_send_reply(irpc, NT_STATUS_NO_MEMORY);
}
printf("sending deferred reply\n");
irpc_send_reply(irpc, NT_STATUS_OK);
}
/*
serve up EchoData over the irpc system
*/
static NTSTATUS irpc_EchoData(struct irpc_message *irpc, struct echo_EchoData *r)
{
irpc->defer_reply = True;
event_add_timed(irpc->ev, irpc, timeval_zero(), deferred_echodata, irpc);
return NT_STATUS_OK;
}
/*
test a addone call over the internal messaging system
*/
static bool test_addone(struct torture_context *test, const void *_data,
const void *_value)
{
struct echo_AddOne r;
NTSTATUS status;
const struct irpc_test_data *data = _data;
uint32_t value = (uint32_t)_value;
/* make the call */
r.in.in_data = value;
test_debug = True;
status = IRPC_CALL(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ADDONE, &r, test);
test_debug = False;
torture_assert_ntstatus_ok(test, status, "AddOne failed");
/* check the answer */
torture_assert(test, *r.out.out_data == r.in.in_data + 1,
"AddOne wrong answer");
torture_comment(test, "%u + 1 = %u\n", r.in.in_data, *r.out.out_data);
return true;
}
/*
test a echodata call over the internal messaging system
*/
static bool test_echodata(struct torture_context *tctx,
const void *tcase_data,
const void *test_data)
{
struct echo_EchoData r;
NTSTATUS status;
const struct irpc_test_data *data = tcase_data;
TALLOC_CTX *mem_ctx = tctx;
/* make the call */
r.in.in_data = (unsigned char *)talloc_strdup(mem_ctx, "0123456789");
r.in.len = strlen((char *)r.in.in_data);
status = IRPC_CALL(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ECHODATA, &r,
mem_ctx);
torture_assert_ntstatus_ok(tctx, status, "EchoData failed");
/* check the answer */
if (memcmp(r.out.out_data, r.in.in_data, r.in.len) != 0) {
NDR_PRINT_OUT_DEBUG(echo_EchoData, &r);
torture_fail(tctx, "EchoData wrong answer");
}
torture_comment(tctx, "Echo '%*.*s' -> '%*.*s'\n",
r.in.len, r.in.len,
r.in.in_data,
r.in.len, r.in.len,
r.out.out_data);
return true;
}
static void irpc_callback(struct irpc_request *irpc)
{
struct echo_AddOne *r = irpc->r;
int *pong_count = (int *)irpc->async.private;
NTSTATUS status = irpc_call_recv(irpc);
if (!NT_STATUS_IS_OK(status)) {
printf("irpc call failed - %s\n", nt_errstr(status));
}
if (*r->out.out_data != r->in.in_data + 1) {
printf("AddOne wrong answer - %u + 1 = %u should be %u\n",
r->in.in_data, *r->out.out_data, r->in.in_data+1);
}
(*pong_count)++;
}
/*
test echo speed
*/
static bool test_speed(struct torture_context *tctx,
const void *tcase_data,
const void *test_data)
{
int ping_count = 0;
int pong_count = 0;
const struct irpc_test_data *data = tcase_data;
struct timeval tv;
struct echo_AddOne r;
TALLOC_CTX *mem_ctx = tctx;
int timelimit = torture_setting_int(tctx, "timelimit", 10);
tv = timeval_current();
r.in.in_data = 0;
torture_comment(tctx, "Sending echo for %d seconds\n", timelimit);
while (timeval_elapsed(&tv) < timelimit) {
struct irpc_request *irpc;
irpc = IRPC_CALL_SEND(data->msg_ctx1, MSG_ID2, rpcecho, ECHO_ADDONE,
&r, mem_ctx);
torture_assert(tctx, irpc != NULL, "AddOne send failed");
irpc->async.fn = irpc_callback;
irpc->async.private = &pong_count;
ping_count++;
while (ping_count > pong_count + 20) {
event_loop_once(data->ev);
}
}
torture_comment(tctx, "waiting for %d remaining replies (done %d)\n",
ping_count - pong_count, pong_count);
while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) {
event_loop_once(data->ev);
}
torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
torture_comment(tctx, "echo rate of %.0f messages/sec\n",
(ping_count+pong_count)/timeval_elapsed(&tv));
return true;
}
static BOOL irpc_setup(struct torture_context *tctx, void **_data)
{
struct irpc_test_data *data;
*_data = data = talloc(tctx, struct irpc_test_data);
lp_set_cmdline("lock dir", "lockdir.tmp");
data->ev = event_context_init(tctx);
torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, MSG_ID1, data->ev),
"Failed to init first messaging context");
torture_assert(tctx, data->msg_ctx2 = messaging_init(tctx, MSG_ID2, data->ev),
"Failed to init second messaging context");
/* register the server side function */
IRPC_REGISTER(data->msg_ctx1, rpcecho, ECHO_ADDONE, irpc_AddOne, NULL);
IRPC_REGISTER(data->msg_ctx2, rpcecho, ECHO_ADDONE, irpc_AddOne, NULL);
IRPC_REGISTER(data->msg_ctx1, rpcecho, ECHO_ECHODATA, irpc_EchoData, NULL);
IRPC_REGISTER(data->msg_ctx2, rpcecho, ECHO_ECHODATA, irpc_EchoData, NULL);
return True;
}
struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "IRPC");
struct torture_tcase *tcase = torture_suite_add_tcase(suite, "irpc");
int i;
uint32_t *values = talloc_array(tcase, uint32_t, 5);
values[0] = 0;
values[1] = 0x7FFFFFFE;
values[2] = 0xFFFFFFFE;
values[3] = 0xFFFFFFFF;
values[4] = random() & 0xFFFFFFFF;
tcase->setup = irpc_setup;
for (i = 0; i < 5; i++) {
torture_tcase_add_test(tcase, "addone", test_addone, (void *)values[i]);
}
torture_tcase_add_test(tcase, "echodata", test_echodata, NULL);
torture_tcase_add_test(tcase, "speed", test_speed, NULL);
return suite;
}
+79
View File
@@ -0,0 +1,79 @@
/*
Unix SMB/CIFS implementation.
SMB torture tester
Copyright (C) Jelmer Vernooij 2006
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "torture/torture.h"
#include "torture/local/proto.h"
#include "torture/auth/proto.h"
/* ignore me */ static struct torture_suite *
(*suite_generators[]) (TALLOC_CTX *mem_ctx) =
{
torture_local_binding_string,
torture_ntlmssp,
torture_local_messaging,
torture_local_irpc,
torture_local_util_strlist,
torture_local_util_file,
torture_local_idtree,
torture_local_iconv,
torture_local_socket,
torture_pac,
torture_registry,
torture_local_resolve,
torture_local_sddl,
torture_local_ndr,
torture_local_event,
torture_local_torture,
torture_local_dbspeed,
NULL
};
NTSTATUS torture_local_init(void)
{
int i;
struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"LOCAL");
torture_suite_add_simple_test(suite, "TALLOC", torture_local_talloc);
torture_suite_add_simple_test(suite, "REPLACE", torture_local_replace);
torture_suite_add_simple_test(suite, "CRYPTO-SHA1",
torture_local_crypto_sha1);
torture_suite_add_simple_test(suite,
"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++)
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;
}
+137
View File
@@ -0,0 +1,137 @@
/*
Unix SMB/CIFS implementation.
local test for messaging code
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "lib/events/events.h"
#include "lib/messaging/irpc.h"
#include "torture/torture.h"
static uint32_t msg_pong;
static void ping_message(struct messaging_context *msg, void *private,
uint32_t msg_type, uint32_t src, DATA_BLOB *data)
{
NTSTATUS status;
status = messaging_send(msg, src, msg_pong, data);
if (!NT_STATUS_IS_OK(status)) {
printf("pong failed - %s\n", nt_errstr(status));
}
}
static void pong_message(struct messaging_context *msg, void *private,
uint32_t msg_type, uint32_t src, DATA_BLOB *data)
{
int *count = private;
(*count)++;
}
static void exit_message(struct messaging_context *msg, void *private,
uint32_t msg_type, uint32_t src, DATA_BLOB *data)
{
talloc_free(private);
exit(0);
}
/*
test ping speed
*/
static bool test_ping_speed(struct torture_context *tctx)
{
struct event_context *ev;
struct messaging_context *msg_client_ctx;
struct messaging_context *msg_server_ctx;
int ping_count = 0;
int pong_count = 0;
struct timeval tv;
int timelimit = torture_setting_int(tctx, "timelimit", 10);
uint32_t msg_ping, msg_exit;
TALLOC_CTX *mem_ctx = tctx;
lp_set_cmdline("lock dir", "lockdir.tmp");
ev = event_context_init(mem_ctx);
msg_server_ctx = messaging_init(mem_ctx, 1, ev);
torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context");
messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping);
messaging_register_tmp(msg_server_ctx, mem_ctx, exit_message, &msg_exit);
msg_client_ctx = messaging_init(mem_ctx, 2, ev);
torture_assert(tctx, msg_client_ctx != NULL, "msg_client_ctx messaging_init() failed");
messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong);
tv = timeval_current();
torture_comment(tctx, "Sending pings for %d seconds", timelimit);
while (timeval_elapsed(&tv) < timelimit) {
DATA_BLOB data;
NTSTATUS status1, status2;
data.data = discard_const_p(uint8_t, "testing");
data.length = strlen((const char *)data.data);
status1 = messaging_send(msg_client_ctx, 1, msg_ping, &data);
status2 = messaging_send(msg_client_ctx, 1, msg_ping, NULL);
torture_assert_ntstatus_ok(tctx, status1, "msg1 failed");
ping_count++;
torture_assert_ntstatus_ok(tctx, status2, "msg2 failed");
ping_count++;
while (ping_count > pong_count + 20) {
event_loop_once(ev);
}
}
torture_comment(tctx, "waiting for %d remaining replies (done %d)",
ping_count - pong_count, pong_count);
while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) {
event_loop_once(ev);
}
torture_comment(tctx, "sending exit");
messaging_send(msg_client_ctx, 1, msg_exit, NULL);
torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
torture_comment(tctx, "ping rate of %.0f messages/sec",
(ping_count+pong_count)/timeval_elapsed(&tv));
talloc_free(msg_client_ctx);
talloc_free(msg_server_ctx);
talloc_free(ev);
return true;
}
struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx)
{
struct torture_suite *s = torture_suite_create(mem_ctx, "MESSAGING");
torture_suite_add_simple_test(s, "ping_speed", test_ping_speed);
return s;
}
+81
View File
@@ -0,0 +1,81 @@
/*
Unix SMB/CIFS implementation.
test suite for basic ndr functions
Copyright (C) Jelmer Vernooij 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "torture/torture.h"
#include "librpc/ndr/libndr.h"
static bool test_check_string_terminator(struct torture_context *tctx)
{
struct ndr_pull *ndr;
DATA_BLOB blob;
TALLOC_CTX *mem_ctx = tctx;
/* Simple test */
blob = strhex_to_data_blob("0000");
ndr = ndr_pull_init_blob(&blob, mem_ctx);
torture_assert_ntstatus_ok(tctx, ndr_check_string_terminator(ndr, 1, 2),
"simple check_string_terminator test failed");
torture_assert(tctx, ndr->offset == 0,
"check_string_terminator did not reset offset");
if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr, 1, 3))) {
torture_fail(tctx, "check_string_terminator checked beyond string boundaries");
}
torture_assert(tctx, ndr->offset == 0,
"check_string_terminator did not reset offset");
talloc_free(ndr);
blob = strhex_to_data_blob("11220000");
ndr = ndr_pull_init_blob(&blob, mem_ctx);
torture_assert_ntstatus_ok(tctx,
ndr_check_string_terminator(ndr, 4, 1),
"check_string_terminator failed to recognize terminator");
torture_assert_ntstatus_ok(tctx,
ndr_check_string_terminator(ndr, 3, 1),
"check_string_terminator failed to recognize terminator");
if (NT_STATUS_IS_OK(ndr_check_string_terminator(ndr, 2, 1))) {
torture_fail(tctx,
"check_string_terminator erroneously reported terminator");
}
torture_assert(tctx, ndr->offset == 0,
"check_string_terminator did not reset offset");
return true;
}
struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "NDR");
torture_suite_add_simple_test(suite, "string terminator",
test_check_string_terminator);
return suite;
}
+93
View File
@@ -0,0 +1,93 @@
/*
Unix SMB/CIFS implementation.
local testing of registry library
Copyright (C) Jelmer Vernooij 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "lib/registry/registry.h"
#include "lib/cmdline/popt_common.h"
#include "torture/torture.h"
const static struct test_backend_settings {
const char *name;
const char *location;
} backends[] = {
{ "nt4", "TEST.DAT" },
{ "ldb", "test.ldb" },
{ "gconf", "." },
{ "dir", "." },
{ NULL, NULL }
};
static bool test_hive(struct torture_context *tctx,
const void *test_data)
{
WERROR error;
struct registry_key *root, *subkey;
uint32_t count;
const struct test_backend_settings *backend = test_data;
TALLOC_CTX *mem_ctx = tctx;
if (!reg_has_backend(backend->name)) {
torture_skip(tctx, talloc_asprintf(tctx,
"Backend '%s' support not compiled in", backend->name));
}
error = reg_open_hive(mem_ctx, backend->name,
backend->location, NULL, cmdline_credentials, &root);
torture_assert_werr_ok(tctx, error, "reg_open_hive()");
/* This is a new backend. There should be no subkeys and no
* values */
error = reg_key_num_subkeys(root, &count);
torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()");
torture_assert(tctx, count != 0, "New key has non-zero subkey count");
error = reg_key_num_values(root, &count);
torture_assert_werr_ok(tctx, error, "reg_key_num_values");
torture_assert(tctx, count != 0, "New key has non-zero value count");
error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey);
torture_assert_werr_ok(tctx, error, "reg_key_add_name");
error = reg_key_del(root, "Nested\\Key");
torture_assert_werr_ok(tctx, error, "reg_key_del");
talloc_free(root);
return true;
}
struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx,
"REGISTRY");
int i;
registry_init();
for (i = 0; backends[i].name; i++) {
torture_suite_add_simple_tcase(suite, backends[i].name, test_hive, &backends[i]);
}
return suite;
}
+90
View File
@@ -0,0 +1,90 @@
/*
Unix SMB/CIFS implementation.
local test for async resolve code
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "lib/events/events.h"
#include "libcli/resolve/resolve.h"
#include "torture/torture.h"
static bool test_async_resolve(struct torture_context *tctx)
{
struct nbt_name n;
struct event_context *ev;
int timelimit = torture_setting_int(tctx, "timelimit", 10);
const char *host = torture_setting_string(tctx, "host", NULL);
int count = 0;
struct timeval tv = timeval_current();
TALLOC_CTX *mem_ctx = tctx;
ev = event_context_init(mem_ctx);
ZERO_STRUCT(n);
n.name = host;
torture_comment(tctx, "Testing async resolve of '%s' for %d seconds\n",
host, timelimit);
while (timeval_elapsed(&tv) < timelimit) {
const char *s;
struct composite_context *c = resolve_name_host_send(mem_ctx, ev, &n);
torture_assert(tctx, c != NULL, "resolve_name_host_send");
torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s),
"async resolve failed");
count++;
}
torture_comment(tctx, "async rate of %.1f resolves/sec\n",
count/timeval_elapsed(&tv));
return true;
}
/*
test resolution using sync method
*/
static bool test_sync_resolve(struct torture_context *tctx)
{
int timelimit = torture_setting_int(tctx, "timelimit", 10);
struct timeval tv = timeval_current();
int count = 0;
const char *host = torture_setting_string(tctx, "host", NULL);
torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n",
host, timelimit);
while (timeval_elapsed(&tv) < timelimit) {
sys_inet_ntoa(interpret_addr2(host));
count++;
}
torture_comment(tctx, "sync rate of %.1f resolves/sec\n",
count/timeval_elapsed(&tv));
return true;
}
struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "RESOLVE");
torture_suite_add_simple_test(suite, "async", test_async_resolve);
torture_suite_add_simple_test(suite, "sync", test_sync_resolve);
return suite;
}
+106
View File
@@ -0,0 +1,106 @@
/*
Unix SMB/CIFS implementation.
local testing of SDDL parsing
Copyright (C) Andrew Tridgell 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/security/security.h"
#include "torture/torture.h"
#include "librpc/gen_ndr/ndr_security.h"
/*
test one SDDL example
*/
static bool test_sddl(struct torture_context *tctx,
const void *test_data)
{
struct security_descriptor *sd, *sd2;
struct dom_sid *domain;
const char *sddl = test_data;
const char *sddl2;
TALLOC_CTX *mem_ctx = tctx;
domain = dom_sid_parse_talloc(mem_ctx, "S-1-2-3-4");
sd = sddl_decode(mem_ctx, sddl, domain);
torture_assert(tctx, sd != NULL, talloc_asprintf(tctx,
"Failed to decode '%s'\n", sddl));
sddl2 = sddl_encode(mem_ctx, sd, domain);
torture_assert(tctx, sddl2 != NULL, talloc_asprintf(tctx,
"Failed to re-encode '%s'\n", sddl));
sd2 = sddl_decode(mem_ctx, sddl2, domain);
torture_assert(tctx, sd2 != NULL, talloc_asprintf(tctx,
"Failed to decode2 '%s'\n", sddl2));
torture_assert(tctx, security_descriptor_equal(sd, sd2),
talloc_asprintf(tctx, "Failed equality test for '%s'\n", sddl));
#if 0
/* flags don't have a canonical order ... */
if (strcmp(sddl, sddl2) != 0) {
printf("Failed sddl equality test\norig: %s\n new: %s\n", sddl, sddl2);
}
#endif
if (DEBUGLVL(2)) {
NDR_PRINT_DEBUG(security_descriptor, sd);
}
talloc_free(sd);
talloc_free(domain);
return true;
}
static const char *examples[] = {
"D:(A;;CC;;;BA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
"D:(A;;GA;;;SY)",
"D:(A;;RP;;;WD)(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;BA)(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;BA)(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;BA)(A;;RPLCLORC;;;AU)(A;;RPWPCRLCLOCCRCWDWOSW;;;DA)(A;CI;RPWPCRLCLOCCRCWDWOSDSW;;;BA)(A;;RPWPCRLCLOCCDCRCWDWOSDDTSW;;;SY)(A;CI;RPWPCRLCLOCCDCRCWDWOSDDTSW;;;EA)(A;CI;LC;;;RU)(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;;RP;c7407360-20bf-11d0-a768-00aa006e0529;;RU)(OA;CIIO;RPLCLORC;;bf967a9c-0de6-11d0-a285-00aa003049e2;RU)(A;;RPRC;;;RU)(OA;CIIO;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(A;;LCRPLORC;;;ED)(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RPLCLORC;;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;RU)(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;AU)(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a9c-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-a285-00aa003049e2;ED)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;DD)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;BA)(OA;;CR;e2a36dc9-ae17-47c3-b58b-be34c55ba633;;S-1-5-32-557)(OA;;CR;280f369c-67c7-438e-ae98-1d46f3c6f541;;AU)(OA;;CR;ccc2dc7d-a6ad-4a7a-8846-c04e3cc53501;;AU)(OA;;CR;05c74c5e-4deb-43b4-bd9f-86664c2a7fd5;;AU)S:(AU;SA;WDWOWP;;;WD)(AU;SA;CR;;;BA)(AU;SA;CR;;;DU)(OU;CISA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CISA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)",
"D:(A;;RPLCLORC;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;AO)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPCRLCLORCSDDT;;;CO)(OA;;WP;4c164200-20c0-11d0-a768-00aa006e0529;;CO)(A;;RPLCLORC;;;AU)(OA;;CR;ab721a53-1e2f-11d0-9819-00aa0040529b;;WD)(A;;CCDC;;;PS)(OA;;CCDC;bf967aa8-0de6-11d0-a285-00aa003049e2;;PO)(OA;;RPWP;bf967a7f-0de6-11d0-a285-00aa003049e2;;CA)(OA;;SW;f3a64788-5306-11d1-a9c5-0000f80367c1;;PS)(OA;;RPWP;77B5B886-944A-11d1-AEBD-0000F80367C1;;PS)(OA;;SW;72e39547-7b18-11d1-adef-00c04fd8d5cd;;PS)(OA;;SW;72e39547-7b18-11d1-adef-00c04fd8d5cd;;CO)(OA;;SW;f3a64788-5306-11d1-a9c5-0000f80367c1;;CO)(OA;;WP;3e0abfd0-126a-11d0-a060-00aa006c33ed;bf967a86-0de6-11d0-a285-00aa003049e2;CO)(OA;;WP;5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967a86-0de6-11d0-a285-00aa003049e2;CO)(OA;;WP;bf967950-0de6-11d0-a285-00aa003049e2;bf967a86-0de6-11d0-a285-00aa003049e2;CO)(OA;;WP;bf967953-0de6-11d0-a285-00aa003049e2;bf967a86-0de6-11d0-a285-00aa003049e2;CO)(OA;;RP;46a9b11d-60ae-405a-b7e8-ff8a58d456d2;;S-1-5-32-560)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;AO)(A;;RPLCLORC;;;PS)(OA;;CR;ab721a55-1e2f-11d0-9819-00aa0040529b;;AU)(OA;;RP;46a9b11d-60ae-405a-b7e8-ff8a58d456d2;;S-1-5-32-560)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;CO)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)S:(AU;SA;CRWP;;;WD)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;AO)(A;;RPLCLORC;;;PS)(OA;;CR;ab721a53-1e2f-11d0-9819-00aa0040529b;;PS)(OA;;CR;ab721a54-1e2f-11d0-9819-00aa0040529b;;PS)(OA;;CR;ab721a56-1e2f-11d0-9819-00aa0040529b;;PS)(OA;;RPWP;77B5B886-944A-11d1-AEBD-0000F80367C1;;PS)(OA;;RPWP;E45795B2-9455-11d1-AEBD-0000F80367C1;;PS)(OA;;RPWP;E45795B3-9455-11d1-AEBD-0000F80367C1;;PS)(OA;;RP;037088f8-0ae1-11d2-b422-00a0c968f939;;RS)(OA;;RP;4c164200-20c0-11d0-a768-00aa006e0529;;RS)(OA;;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;;RS)(A;;RC;;;AU)(OA;;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;;AU)(OA;;RP;77B5B886-944A-11d1-AEBD-0000F80367C1;;AU)(OA;;RP;E45795B3-9455-11d1-AEBD-0000F80367C1;;AU)(OA;;RP;e48d0154-bcf8-11d1-8702-00c04fb96050;;AU)(OA;;CR;ab721a53-1e2f-11d0-9819-00aa0040529b;;WD)(OA;;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;;RS)(OA;;RPWP;bf967a7f-0de6-11d0-a285-00aa003049e2;;CA)(OA;;RP;46a9b11d-60ae-405a-b7e8-ff8a58d456d2;;S-1-5-32-560)(OA;;WPRP;6db69a1c-9422-11d1-aebd-0000f80367c1;;S-1-5-32-561)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)(A;;LCRPLORC;;;ED)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(OA;;CCDC;bf967a86-0de6-11d0-a285-00aa003049e2;;AO)(OA;;CCDC;bf967aba-0de6-11d0-a285-00aa003049e2;;AO)(OA;;CCDC;bf967a9c-0de6-11d0-a285-00aa003049e2;;AO)(OA;;CCDC;bf967aa8-0de6-11d0-a285-00aa003049e2;;PO)(A;;RPLCLORC;;;AU)(A;;LCRPLORC;;;ED)(OA;;CCDC;4828CC14-1437-45bc-9B07-AD6F015E5F28;;AO)",
"D:(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
"D:(A;CI;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
"D:S:",
"D:(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)"
};
/* test a set of example SDDL strings */
struct torture_suite *torture_local_sddl(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "SDDL");
int i;
for (i = 0; i < ARRAY_SIZE(examples); i++) {
torture_suite_add_simple_tcase(suite,
talloc_asprintf(suite, "%d", i),
test_sddl, examples[i]);
}
return suite;
}
+191
View File
@@ -0,0 +1,191 @@
/*
Unix SMB/CIFS implementation.
local testing of socket routines.
Copyright (C) Andrew Tridgell 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "lib/socket/socket.h"
#include "lib/events/events.h"
#include "system/network.h"
#include "lib/socket/netif.h"
#include "torture/torture.h"
/*
basic testing of udp routines
*/
static bool test_udp(struct torture_context *tctx)
{
struct socket_context *sock1, *sock2;
NTSTATUS status;
struct socket_address *srv_addr, *from_addr, *localhost;
size_t size = 100 + (random() % 100);
DATA_BLOB blob, blob2;
size_t sent, nread;
TALLOC_CTX *mem_ctx = tctx;
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
talloc_steal(mem_ctx, sock1);
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock2, 0);
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
talloc_steal(mem_ctx, sock2);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
iface_best_ip("127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
status = socket_listen(sock1, localhost, 0, 0);
torture_assert_ntstatus_ok(tctx, status, "listen on socket 1");
srv_addr = socket_get_my_addr(sock1, mem_ctx);
torture_assert(tctx, srv_addr != NULL && strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) == 0,
talloc_asprintf(tctx,
"Expected server address of %s but got %s",
iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
torture_comment(tctx, "server port is %d\n", srv_addr->port);
blob = data_blob_talloc(mem_ctx, NULL, size);
blob2 = data_blob_talloc(mem_ctx, NULL, size);
generate_random_buffer(blob.data, blob.length);
sent = size;
status = socket_sendto(sock2, &blob, &sent, srv_addr);
torture_assert_ntstatus_ok(tctx, status, "sendto() on socket 2");
status = socket_recvfrom(sock1, blob2.data, size, &nread,
sock1, &from_addr);
torture_assert_ntstatus_ok(tctx, status, "recvfrom() on socket 1");
torture_assert_str_equal(tctx, from_addr->addr, srv_addr->addr,
"different address");
torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
"Bad data in recvfrom");
generate_random_buffer(blob.data, blob.length);
status = socket_sendto(sock1, &blob, &sent, from_addr);
torture_assert_ntstatus_ok(tctx, status, "sendto() on socket 1");
status = socket_recvfrom(sock2, blob2.data, size, &nread,
sock2, &from_addr);
torture_assert_ntstatus_ok(tctx, status, "recvfrom() on socket 2");
torture_assert_str_equal(tctx, from_addr->addr, srv_addr->addr,
"Unexpected recvfrom addr");
torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
torture_assert_int_equal(tctx, from_addr->port, srv_addr->port,
"Unexpected recvfrom port");
torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
"Bad data in recvfrom");
talloc_free(sock1);
talloc_free(sock2);
return true;
}
/*
basic testing of tcp routines
*/
static bool test_tcp(struct torture_context *tctx)
{
struct socket_context *sock1, *sock2, *sock3;
NTSTATUS status;
struct socket_address *srv_addr, *from_addr, *localhost;
size_t size = 100 + (random() % 100);
DATA_BLOB blob, blob2;
size_t sent, nread;
TALLOC_CTX *mem_ctx = tctx;
struct event_context *ev = event_context_init(mem_ctx);
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0);
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(mem_ctx, sock1);
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock2, 0);
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(mem_ctx, sock2);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
iface_best_ip("127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
status = socket_listen(sock1, localhost, 0, 0);
torture_assert_ntstatus_ok(tctx, status, "listen on socket 1");
srv_addr = socket_get_my_addr(sock1, mem_ctx);
torture_assert(tctx, srv_addr && srv_addr->addr,
"Unexpected socket_get_my_addr NULL\n");
torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip("127.0.0.1"),
"Unexpected server address");
torture_comment(tctx, "server port is %d\n", srv_addr->port);
status = socket_connect_ev(sock2, NULL, srv_addr, 0, ev);
torture_assert_ntstatus_ok(tctx, status, "connect() on socket 2");
status = socket_accept(sock1, &sock3);
torture_assert_ntstatus_ok(tctx, status, "accept() on socket 1");
talloc_steal(mem_ctx, sock3);
talloc_free(sock1);
blob = data_blob_talloc(mem_ctx, NULL, size);
blob2 = data_blob_talloc(mem_ctx, NULL, size);
generate_random_buffer(blob.data, blob.length);
sent = size;
status = socket_send(sock2, &blob, &sent);
torture_assert_ntstatus_ok(tctx, status, "send() on socket 2");
status = socket_recv(sock3, blob2.data, size, &nread);
torture_assert_ntstatus_ok(tctx, status, "recv() on socket 3");
from_addr = socket_get_peer_addr(sock3, mem_ctx);
torture_assert(tctx, from_addr && from_addr->addr,
"Unexpected recvfrom addr NULL");
torture_assert_str_equal(tctx, from_addr->addr, srv_addr->addr,
"Unexpected recvfrom addr");
torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
"Bad data in recv");
return true;
}
struct torture_suite *torture_local_socket(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx,
"SOCKET");
torture_suite_add_simple_test(suite, "udp", test_udp);
torture_suite_add_simple_test(suite, "tcp", test_tcp);
return suite;
}
+83
View File
@@ -0,0 +1,83 @@
/*
Unix SMB/CIFS implementation.
local testing of torture
Copyright (C) Jelmer Vernooij 2006
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "torture/torture.h"
#include "system/wait.h"
#include "lib/events/events.h"
#include "libcli/raw/libcliraw.h"
#include "torture/util.h"
static bool test_tempdir(struct torture_context *tctx)
{
char *location = NULL;
TALLOC_CTX *mem_ctx = tctx;
torture_assert_ntstatus_ok(tctx, torture_temp_dir(mem_ctx, "tempdir", &location),
"torture_temp_dir should return NT_STATUS_OK" );
torture_assert(tctx, directory_exist(location),
"created dir doesn't exist");
return true;
}
static bool test_setup_server(struct torture_context *tctx)
{
pid_t pid;
TALLOC_CTX *mem_ctx = tctx;
torture_assert_ntstatus_ok(tctx, torture_setup_server(mem_ctx,
"setupserver-success",
"./script/tests/mktestsetup.sh",
"./bin/smbd", &pid),
"starting smbd failed");
torture_assert(tctx, pid > 0, "Pid invalid");
torture_comment(tctx, "Created smbd with pid %d\n", pid);
kill(pid, SIGINT);
waitpid(pid, NULL, 0);
torture_assert_ntstatus_equal(tctx, torture_setup_server(mem_ctx,
"setupserver-fail",
"./invalid-script",
"./bin/smbd", &pid),
NT_STATUS_UNSUCCESSFUL,
"invalid script specified");
torture_assert(tctx, pid == -1, "Pid not -1 after failure");
return true;
}
struct torture_suite *torture_local_torture(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx,
"TORTURE");
torture_suite_add_simple_test(suite, "tempdir", test_tempdir);
torture_suite_add_simple_test(suite, "setup server", test_setup_server);
return suite;
}
+95
View File
@@ -0,0 +1,95 @@
/*
Unix SMB/CIFS implementation.
util_file testing
Copyright (C) Jelmer Vernooij 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "system/filesys.h"
#include "torture/torture.h"
#define TEST_FILENAME "utilfile.test"
#define TEST_LINE1 "This is list line 1..."
#define TEST_LINE2 ".. and this is line 2"
#define TEST_LINE3 "and end of the file"
#define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3
static bool test_file_load_save(struct torture_context *tctx)
{
size_t len;
char *data;
TALLOC_CTX *mem_ctx = tctx;
torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)),
"saving file");
data = file_load(TEST_FILENAME, &len, mem_ctx);
torture_assert(tctx, data, "loading file");
torture_assert(tctx, len == strlen(TEST_DATA), "Length");
torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents");
unlink(TEST_FILENAME);
return true;
}
static bool test_afdgets(struct torture_context *tctx)
{
int fd;
char *line;
TALLOC_CTX *mem_ctx = tctx;
torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA,
strlen(TEST_DATA)),
"saving file");
fd = open(TEST_FILENAME, O_RDONLY);
torture_assert(tctx, fd != -1, "opening file");
line = afdgets(fd, mem_ctx, 8);
torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch");
line = afdgets(fd, mem_ctx, 8);
torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch");
line = afdgets(fd, mem_ctx, 8);
torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch");
close(fd);
unlink(TEST_FILENAME);
return true;
}
struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE");
torture_suite_add_simple_test(suite, "file_load_save",
test_file_load_save);
torture_suite_add_simple_test(suite, "afdgets",
test_afdgets);
return suite;
}
+80
View File
@@ -0,0 +1,80 @@
/*
Unix SMB/CIFS implementation.
util_strlist testing
Copyright (C) Jelmer Vernooij 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "torture/torture.h"
static const char *test_lists_shell_strings[] = {
"",
"foo",
"foo bar",
"foo bar \"bla \"",
"foo \"\" bla",
"bla \"\"\"\" blie",
NULL
};
static bool test_lists_shell(struct torture_context *tctx,
const void *test_data)
{
const char *data = test_data;
const char **ret1, **ret2, *tmp;
BOOL match = True;
TALLOC_CTX *mem_ctx = tctx;
ret1 = str_list_make_shell(mem_ctx, data, " ");
tmp = str_list_join_shell(mem_ctx, ret1, ' ');
ret2 = str_list_make_shell(mem_ctx, tmp, " ");
if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
match = False;
} else {
int j;
for (j = 0; ret1[j] && ret2[j]; j++) {
if (strcmp(ret1[j], ret2[j]) != 0) {
match = False;
break;
}
}
if (ret1[j] || ret2[j])
match = False;
}
torture_assert(tctx, match, talloc_asprintf(tctx,
"str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", data, tmp));
return true;
}
struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST");
int i;
for (i = 0; test_lists_shell_strings[i]; i++) {
torture_suite_add_simple_tcase(suite,
"lists_shell", test_lists_shell,
&test_lists_shell_strings[i]);
}
return suite;
}