Exemplo n.º 1
0
/*
  do some lsa ops using the schannel connection
 */
static bool test_lsa_ops(struct torture_context *tctx, struct dcerpc_pipe *p)
{
	struct lsa_GetUserName r;
	bool ret = true;
	struct lsa_String *account_name_p = NULL;
	struct lsa_String *authority_name_p = NULL;
	struct dcerpc_binding_handle *b = p->binding_handle;

	printf("\nTesting GetUserName\n");

	r.in.system_name = "\\";	
	r.in.account_name = &account_name_p;
	r.in.authority_name = &authority_name_p;
	r.out.account_name = &account_name_p;

	/* do several ops to test credential chaining and various operations */
	torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
		"lsa_GetUserName failed");

	authority_name_p = *r.out.authority_name;

	if (!NT_STATUS_IS_OK(r.out.result)) {
		printf("GetUserName failed - %s\n", nt_errstr(r.out.result));
		return false;
	} else {
		if (!r.out.account_name) {
			return false;
		}
		
		if (strcmp(account_name_p->string, "ANONYMOUS LOGON") != 0) {
			printf("GetUserName returned wrong user: %s, expected %s\n",
			       account_name_p->string, "ANONYMOUS LOGON");
			/* FIXME: gd */
			if (!torture_setting_bool(tctx, "samba3", false)) {
				return false;
			}
		}
		if (!authority_name_p || !authority_name_p->string) {
			return false;
		}
		
		if (strcmp(authority_name_p->string, "NT AUTHORITY") != 0) {
			printf("GetUserName returned wrong user: %s, expected %s\n",
			       authority_name_p->string, "NT AUTHORITY");
			/* FIXME: gd */
			if (!torture_setting_bool(tctx, "samba3", false)) {
				return false;
			}
		}
	}
	if (!test_many_LookupSids(p, tctx, NULL)) {
		printf("LsaLookupSids3 failed!\n");
		return false;
	}

	return ret;
}
Exemplo n.º 2
0
static bool test_read_dir(struct torture_context *torture, struct smb2_tree *tree)
{
	bool ret = true;
	NTSTATUS status;
	struct smb2_handle h;
	struct smb2_read rd;
	TALLOC_CTX *tmp_ctx = talloc_new(tree);

	status = torture_smb2_testdir(tree, DNAME, &h);
	if (!NT_STATUS_IS_OK(status)) {
		printf(__location__ " Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
		return false;
	}

	ZERO_STRUCT(rd);
	rd.in.file.handle = h;
	rd.in.length = 10;
	rd.in.offset = 0;
	rd.in.min_count = 1;

	status = smb2_read(tree, tmp_ctx, &rd);
	CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
	
	rd.in.min_count = 11;
	status = smb2_read(tree, tmp_ctx, &rd);
	CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);

	rd.in.length = 0;
	rd.in.min_count = 2592;
	status = smb2_read(tree, tmp_ctx, &rd);
	if (torture_setting_bool(torture, "windows", false)) {
		CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
	} else {
		CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
	}

	rd.in.length = 0;
	rd.in.min_count = 0;
	rd.in.channel = 0;
	status = smb2_read(tree, tmp_ctx, &rd);
	if (torture_setting_bool(torture, "windows", false)) {
		CHECK_STATUS(status, NT_STATUS_OK);
	} else {
		CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
	}
	
done:
	talloc_free(tmp_ctx);
	return ret;
}
Exemplo n.º 3
0
static bool torture_krb5_as_req_pac_request(struct torture_context *tctx)
{
	if (torture_setting_bool(tctx, "expect_rodc", false)) {
		torture_skip(tctx, "This test needs further investigation in the RODC case against a Windows DC, in particular with non-cached users");
	}
	return torture_krb5_as_req_creds(tctx, cmdline_credentials, TORTURE_KRB5_TEST_PAC_REQUEST);
}
Exemplo n.º 4
0
/*
  test the SinkData interface
*/
static bool test_sinkdata(struct torture_context *tctx, 
						  struct dcerpc_pipe *p)
{
	int i;
	NTSTATUS status;
	uint8_t *data_in;
	int len;
	struct echo_SinkData r;

	if (torture_setting_bool(tctx, "quick", false) &&
	    (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
		len = 100 + (random() % 5000);
	} else {
		len = 200000 + (random() % 5000);
	}

	data_in = talloc_array(tctx, uint8_t, len);
	for (i=0;i<len;i++) {
		data_in[i] = i+1;
	}

	r.in.len = len;
	r.in.data = data_in;

	status = dcerpc_echo_SinkData(p, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, 
										"SinkData(%d) failed", 
							   len));

	torture_comment(tctx, "sunk %d bytes\n", len);
	return true;
}
Exemplo n.º 5
0
/*
   look for the w2k3 setpathinfo STANDARD bug
*/
static bool torture_raw_sfileinfo_bug(struct torture_context *torture,
                                      struct smbcli_state *cli)
{
    const char *fname = "\\bug3.txt";
    union smb_setfileinfo sfinfo;
    NTSTATUS status;
    int fnum;

    if (!torture_setting_bool(torture, "dangerous", false))
        torture_skip(torture,
                     "torture_raw_sfileinfo_bug disabled - enable dangerous tests to use\n");

    fnum = create_complex_file(cli, torture, fname);
    smbcli_close(cli->tree, fnum);

    sfinfo.generic.level = RAW_SFILEINFO_STANDARD;
    sfinfo.generic.in.file.path = fname;

    sfinfo.standard.in.create_time = 0;
    sfinfo.standard.in.access_time = 0;
    sfinfo.standard.in.write_time  = 0;

    status = smb_raw_setpathinfo(cli->tree, &sfinfo);
    printf("%s - %s\n", fname, nt_errstr(status));

    printf("now try and delete %s\n", fname);

    return true;
}
Exemplo n.º 6
0
Arquivo: misc.c Projeto: endisd/samba
/*
  see how many RPC pipes we can open at once
*/
bool run_pipe_number(struct torture_context *tctx, 
					 struct smbcli_state *cli1)
{
	const char *pipe_name = "\\WKSSVC";
	int fnum;
	int num_pipes = 0;

	while(1) {
		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);

		if (fnum == -1) {
			torture_comment(tctx, "Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
			break;
		}
		num_pipes++;
		if (torture_setting_bool(tctx, "progress", true)) {
			torture_comment(tctx, "%d\r", num_pipes);
			fflush(stdout);
		}
	}

	torture_comment(tctx, "pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
	return true;
}
Exemplo n.º 7
0
/*
  test the SourceData interface
*/
static bool test_sourcedata(struct torture_context *tctx,
						  struct dcerpc_pipe *p)
{
	int i;
	NTSTATUS status;
	int len;
	struct echo_SourceData r;

	if (torture_setting_bool(tctx, "quick", false) &&
	    (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
		len = 100 + (random() % 500);
	} else {
		len = 200000 + (random() % 5000);
	}

	r.in.len = len;

	status = dcerpc_echo_SourceData(p, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, 
										"SourceData(%d) failed", len));

	for (i=0;i<len;i++) {
		uint8_t *v = (uint8_t *)r.out.data;
		torture_assert(tctx, v[i] == (i & 0xFF),
			talloc_asprintf(tctx, 
						"bad data 0x%x at %d\n", (uint8_t)r.out.data[i], i));
	}
	return true;
}
Exemplo n.º 8
0
/* run a test that simulates an approximate netbench client load */
bool torture_nbench(struct torture_context *torture)
{
	bool correct = true;
	int torture_nprocs = torture_setting_int(torture, "nprocs", 4);
	struct smbcli_state *cli;
	const char *p;

	read_only = torture_setting_bool(torture, "readonly", false);

	nb_max_retries = torture_setting_int(torture, "nretries", 1);

	p = torture_setting_string(torture, "timelimit", NULL);
	if (p && *p) {
		timelimit = atoi(p);
	}

	warmup = timelimit / 20;

	loadfile = torture_setting_string(torture, "loadfile", NULL);
	if (!loadfile || !*loadfile) {
		loadfile = "client.txt";
	}

	if (torture_nprocs > 1) {
		if (!torture_open_connection(&cli, torture, 0)) {
			return false;
		}

		if (!read_only && !torture_setup_dir(cli, "\\clients")) {
			return false;
		}
	}

	nbio_shmem(torture_nprocs, timelimit, warmup);

	printf("Running for %d seconds with load '%s' and warmup %d secs\n", 
	       timelimit, loadfile, warmup);

	/* we need to reset SIGCHLD here as the name resolution
	   library may have changed it. We rely on correct signals
	   from childs in the main torture code which reaps
	   children. This is why smbtorture BENCH-NBENCH was sometimes
	   failing */
	signal(SIGCHLD, SIG_DFL);


	signal(SIGALRM, nb_alarm);
	alarm(1);
	torture_create_procs(torture, run_netbench, &correct);
	alarm(0);

	if (!read_only && torture_nprocs > 1) {
		smbcli_deltree(cli->tree, "\\clients");
	}

	printf("\nThroughput %g MB/sec\n", nbio_result());
	return correct;
}
Exemplo n.º 9
0
BOOL torture_async_bind(struct torture_context *torture)
{
	NTSTATUS status;
	TALLOC_CTX *mem_ctx;
	struct event_context *evt_ctx;
	int i;
	const char *binding_string;
	struct cli_credentials *creds;
	extern int torture_numasync;

	struct composite_context **bind_req;
	struct dcerpc_pipe **pipe;
	const struct dcerpc_interface_table **table;

	if (!torture_setting_bool(torture, "async", False)) {
		printf("async bind test disabled - enable async tests to use\n");
		return True;
	}
	
	binding_string = torture_setting_string(torture, "binding", NULL);

	/* talloc context */
	mem_ctx = talloc_init("torture_async_bind");
	if (mem_ctx == NULL) return False;

	bind_req = talloc_array(torture, struct composite_context*, torture_numasync);
	if (bind_req == NULL) return False;
	pipe     = talloc_array(torture, struct dcerpc_pipe*, torture_numasync);
	if (pipe == NULL) return False;
	table    = talloc_array(torture, const struct dcerpc_interface_table*, torture_numasync);
	if (table == NULL) return False;
	
	/* event context */
	evt_ctx = event_context_init(mem_ctx);
	if (evt_ctx == NULL) return False;

	/* credentials */
	creds = cmdline_credentials;

	/* send bind requests */
	for (i = 0; i < torture_numasync; i++) {
		table[i] = &dcerpc_table_lsarpc;
		bind_req[i] = dcerpc_pipe_connect_send(mem_ctx, binding_string,
						       table[i], creds, evt_ctx);
	}

	/* recv bind requests */
	for (i = 0; i < torture_numasync; i++) {
		status = dcerpc_pipe_connect_recv(bind_req[i], mem_ctx, &pipe[i]);
		if (!NT_STATUS_IS_OK(status)) {
			printf("async rpc connection failed: %s\n", nt_errstr(status));
			return False;
		}
	}

	talloc_free(mem_ctx);
	return True;
}
Exemplo n.º 10
0
Arquivo: misc.c Projeto: endisd/samba
/*
  open a file N times on the server and just hold them open
  used for testing performance when there are N file handles
  alopenn
 */
bool torture_holdopen(struct torture_context *tctx,
		      struct smbcli_state *cli)
{
	int i, fnum;
	const char *fname = "\\holdopen.dat";
	NTSTATUS status;

	smbcli_unlink(cli->tree, fname);

	fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
	if (fnum == -1) {
		torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
		return false;
	}

	smbcli_close(cli->tree, fnum);

	for (i=0;i<torture_numops;i++) {
		union smb_open op;

		op.generic.level = RAW_OPEN_NTCREATEX;
		op.ntcreatex.in.root_fid.fnum = 0;
		op.ntcreatex.in.flags = 0;
		op.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
		op.ntcreatex.in.create_options = 0;
		op.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
		op.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
		op.ntcreatex.in.alloc_size = 0;
		op.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
		op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
		op.ntcreatex.in.security_flags = 0;
		op.ntcreatex.in.fname = fname;
		status = smb_raw_open(cli->tree, tctx, &op);
		if (!NT_STATUS_IS_OK(status)) {
			torture_warning(tctx, "open %d failed\n", i);
			continue;
		}

		if (torture_setting_bool(tctx, "progress", true)) {
			torture_comment(tctx, "opened %d file\r", i);
			fflush(stdout);
		}
	}

	torture_comment(tctx, "\nStarting pings\n");

	while (1) {
		struct smb_echo ec;

		status = smb_raw_echo(cli->transport, &ec);
		torture_comment(tctx, ".");
		fflush(stdout);
		sleep(15);
	}

	return true;
}
Exemplo n.º 11
0
/*
  test request timeouts
*/
#if 0 /* this test needs fixing to work over ncacn_np */
static bool test_timeout(struct torture_context *tctx,
						 struct dcerpc_pipe *p)
{
	NTSTATUS status;
	struct rpc_request *req;
	struct echo_TestSleep r;
	int timeout_saved = p->request_timeout;

	if (torture_setting_bool(tctx, "quick", false)) {
		torture_skip(tctx, "timeout testing disabled - use \"torture:quick=no\" to enable\n");
	}

	torture_comment(tctx, "testing request timeouts\n");
	r.in.seconds = 2;
	p->request_timeout = 1;

	req = dcerpc_echo_TestSleep_send(p, tctx, &r);
	if (!req) {
		torture_comment(tctx, "Failed to send async sleep request\n");
		goto failed;
	}
	req->ignore_timeout = true;

	status	= dcerpc_ndr_request_recv(req);
	torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT, 
								  "request should have timed out");

	torture_comment(tctx, "testing request destruction\n");
	req = dcerpc_echo_TestSleep_send(p, tctx, &r);
	if (!req) {
		torture_comment(tctx, "Failed to send async sleep request\n");
		goto failed;
	}
	talloc_free(req);

	req = dcerpc_echo_TestSleep_send(p, tctx, &r);
	if (!req) {
		torture_comment(tctx, "Failed to send async sleep request\n");
		goto failed;
	}
	req->ignore_timeout = true;
	status	= dcerpc_ndr_request_recv(req);
	torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT, 
		"request should have timed out");

	p->request_timeout = timeout_saved;
	
	return test_addone(tctx, p);

failed:
	p->request_timeout = timeout_saved;
	return false;
}
Exemplo n.º 12
0
static bool test_Insert(struct torture_context *tctx,
			struct dcerpc_binding_handle *h,
			struct ndr_syntax_id object,
			const char *annotation,
			struct dcerpc_binding *b)
{
	struct epm_Insert r;
	NTSTATUS status;

	r.in.num_ents = 1;
	r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);

	if (torture_setting_bool(tctx, "samba4", false)) {
		torture_skip(tctx, "Skip Insert test against Samba4");
	}

	/* FIXME zero */
	ZERO_STRUCT(r.in.entries[0].object);
	r.in.entries[0].annotation = annotation;

	r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);

	status = dcerpc_binding_build_tower(tctx,
					    b,
					    &r.in.entries[0].tower->tower);

	torture_assert_ntstatus_ok(tctx,
				   status,
				   "Unable to build tower from binding struct");
	r.in.replace = 0;

	/* shoot! */
	status = dcerpc_epm_Insert_r(h, tctx, &r);

	if (NT_STATUS_IS_ERR(status)) {
		torture_comment(tctx,
				"epm_Insert failed - %s\n",
				nt_errstr(status));
		return false;
	}

	if (r.out.result != EPMAPPER_STATUS_OK) {
		torture_comment(tctx,
				"epm_Insert failed - internal error: 0x%.4x\n",
				r.out.result);
		return false;
	}

	return true;
}
Exemplo n.º 13
0
static bool torture_winbind_struct_check_machacc(struct torture_context *torture)
{
	bool ok;
	bool strict = torture_setting_bool(torture, "strict mode", false);
	struct winbindd_response rep;

	ZERO_STRUCT(rep);

	torture_comment(torture, "Running WINBINDD_CHECK_MACHACC (struct based)\n");

	ok = true;
	DO_STRUCT_REQ_REP_EXT(WINBINDD_CHECK_MACHACC, NULL, &rep,
			      NSS_STATUS_SUCCESS, strict, ok = false,
			      "WINBINDD_CHECK_MACHACC");

	if (!ok) {
		torture_assert(torture,
			       strlen(rep.data.auth.nt_status_string)>0,
			       "Failed with empty nt_status_string");

		torture_warning(torture,"%s:%s:%s:%d\n",
				nt_errstr(NT_STATUS(rep.data.auth.nt_status)),
				rep.data.auth.nt_status_string,
				rep.data.auth.error_string,
				rep.data.auth.pam_error);
		return true;
	}

	torture_assert_ntstatus_ok(torture,
				   NT_STATUS(rep.data.auth.nt_status),
				   "WINBINDD_CHECK_MACHACC ok: nt_status");

	torture_assert_str_equal(torture,
				 rep.data.auth.nt_status_string,
				 nt_errstr(NT_STATUS_OK),
				 "WINBINDD_CHECK_MACHACC ok:nt_status_string");

	torture_assert_str_equal(torture,
				 rep.data.auth.error_string,
				 get_friendly_nt_error_msg(NT_STATUS_OK),
				 "WINBINDD_CHECK_MACHACC ok: error_string");

	torture_assert_int_equal(torture,
				 rep.data.auth.pam_error,
				 nt_status_to_pam(NT_STATUS_OK),
				 "WINBINDD_CHECK_MACHACC ok: pam_error");

	return true;
}
Exemplo n.º 14
0
static bool test_Insert_noreplace(struct torture_context *tctx,
				  struct dcerpc_pipe *p)
{
	bool ok;
	NTSTATUS status;
	struct epm_Insert r;
	struct dcerpc_binding *b;
	struct dcerpc_binding_handle *h = p->binding_handle;

	torture_comment(tctx, "Testing epm_Insert(noreplace) and epm_Delete\n");

	if (torture_setting_bool(tctx, "samba4", false)) {
		torture_skip(tctx, "Skip Insert test against Samba4");
	}

	r.in.num_ents = 1;
	r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);

	ZERO_STRUCT(r.in.entries[0].object);
	r.in.entries[0].annotation = "smbtorture endpoint";

	status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &b);
	torture_assert_ntstatus_ok(tctx,
				   status,
				   "Unable to generate dcerpc_binding struct");

	r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);

	status = dcerpc_binding_build_tower(tctx,
					    b,
					    &r.in.entries[0].tower->tower);
	torture_assert_ntstatus_ok(tctx,
				   status,
				   "Unable to build tower from binding struct");
	r.in.replace = 0;

	status = dcerpc_epm_Insert_r(h, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, "epm_Insert failed");

	torture_assert(tctx, r.out.result == 0, "epm_Insert failed");

	ok = test_Delete(tctx, h, "smbtorture", b);
	if (!ok) {
		return false;
	}

	return true;
}
Exemplo n.º 15
0
Arquivo: misc.c Projeto: endisd/samba
/*
  open N connections to the server and just hold them open
  used for testing performance when there are N idle users
  already connected
 */
bool torture_holdcon(struct torture_context *tctx)
{
	int i;
	struct smbcli_state **cli;
	int num_dead = 0;

	torture_comment(tctx, "Opening %d connections\n", torture_numops);
	
	cli = malloc_array_p(struct smbcli_state *, torture_numops);

	for (i=0;i<torture_numops;i++) {
		if (!torture_open_connection(&cli[i], tctx, i)) {
			return false;
		}
		if (torture_setting_bool(tctx, "progress", true)) {
			torture_comment(tctx, "opened %d connections\r", i);
			fflush(stdout);
		}
	}

	torture_comment(tctx, "\nStarting pings\n");

	while (1) {
		for (i=0;i<torture_numops;i++) {
			NTSTATUS status;
			if (cli[i]) {
				status = smbcli_chkpath(cli[i]->tree, "\\");
				if (!NT_STATUS_IS_OK(status)) {
					torture_comment(tctx, "Connection %d is dead\n", i);
					cli[i] = NULL;
					num_dead++;
				}
				usleep(100);
			}
		}

		if (num_dead == torture_numops) {
			torture_comment(tctx, "All connections dead - finishing\n");
			break;
		}

		torture_comment(tctx, ".");
		fflush(stdout);
	}

	return true;
}
Exemplo n.º 16
0
/* 
   basic testing of disconnects
*/
bool torture_disconnect(struct torture_context *torture)
{
	bool ret = true;
	TALLOC_CTX *mem_ctx;
	int i;
	extern int torture_numops;
	struct smbcli_state *cli;

	mem_ctx = talloc_init("torture_raw_mux");

	if (!torture_open_connection(&cli, torture, 0)) {
		return false;
	}

	if (!torture_setup_dir(cli, BASEDIR)) {
		return false;
	}

	for (i=0;i<torture_numops;i++) {
		ret &= test_disconnect_lock(cli, mem_ctx);
		if (!torture_open_connection(&cli, torture, 0)) {
			return false;
		}

		ret &= test_disconnect_open(cli, mem_ctx);
		if (!torture_open_connection(&cli, torture, 0)) {
			return false;
		}

		if (torture_setting_bool(torture, "samba3", false)) {
			/*
			 * In Samba3 it might happen that the old smbd from
			 * test_disconnect_lock is not scheduled before the
			 * new process comes in. Try to get rid of the random
			 * failures in the build farm.
			 */
			smb_msleep(200);
		}
	}

	smb_raw_exit(cli->session);
	smbcli_deltree(cli->tree, BASEDIR);
	talloc_free(mem_ctx);
	return ret;
}
Exemplo n.º 17
0
/*
  test the EchoData interface
*/
static bool test_echodata(struct torture_context *tctx,
						  struct dcerpc_pipe *p)
{
	int i;
	NTSTATUS status;
	uint8_t *data_in, *data_out;
	int len;
	struct echo_EchoData r;

	if (torture_setting_bool(tctx, "quick", false) &&
	    (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
		len = 1 + (random() % 500);
	} else {
		len = 1 + (random() % 5000);
	}

	data_in = talloc_array(tctx, uint8_t, len);
	data_out = talloc_array(tctx, uint8_t, len);
	for (i=0;i<len;i++) {
		data_in[i] = i;
	}
	
	r.in.len = len;
	r.in.in_data = data_in;

	status = dcerpc_echo_EchoData(p, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, 
											"EchoData(%d) failed\n", len));

	data_out = r.out.out_data;

	for (i=0;i<len;i++) {
		if (data_in[i] != data_out[i]) {
			torture_comment(tctx, "Bad data returned for len %d at offset %d\n", 
			       len, i);
			torture_comment(tctx, "in:\n");
			dump_data(0, data_in+i, MIN(len-i, 16));
			torture_comment(tctx, "out:\n");
			dump_data(0, data_out+i, MIN(len-1, 16));
			return false;
		}
	}
	return true;
}
Exemplo n.º 18
0
static bool test_read_position(struct torture_context *torture, struct smb2_tree *tree)
{
	bool ret = true;
	NTSTATUS status;
	struct smb2_handle h;
	uint8_t buf[70000];
	struct smb2_read rd;
	TALLOC_CTX *tmp_ctx = talloc_new(tree);
	union smb_fileinfo info;

	ZERO_STRUCT(buf);

	status = torture_smb2_testfile(tree, FNAME, &h);
	CHECK_STATUS(status, NT_STATUS_OK);

	status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
	CHECK_STATUS(status, NT_STATUS_OK);

	ZERO_STRUCT(rd);
	rd.in.file.handle = h;
	rd.in.length = 10;
	rd.in.offset = 0;
	rd.in.min_count = 1;

	status = smb2_read(tree, tmp_ctx, &rd);
	CHECK_STATUS(status, NT_STATUS_OK);
	CHECK_VALUE(rd.out.data.length, 10);

	info.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
	info.generic.in.file.handle = h;

	status = smb2_getinfo_file(tree, tmp_ctx, &info);
	CHECK_STATUS(status, NT_STATUS_OK);
	if (torture_setting_bool(torture, "windows", false)) {
		CHECK_VALUE(info.all_info2.out.position, 0);
	} else {
		CHECK_VALUE(info.all_info2.out.position, 10);
	}

	
done:
	talloc_free(tmp_ctx);
	return ret;
}
Exemplo n.º 19
0
static bool test_LookupHandleFree(struct torture_context *tctx,
				  struct dcerpc_binding_handle *h,
				  struct policy_handle *entry_handle) {
	NTSTATUS status;
	struct epm_LookupHandleFree r;

	if (torture_setting_bool(tctx, "samba4", false)) {
		torture_skip(tctx, "Skip Insert test against Samba4");
	}

	if (ndr_policy_handle_empty(entry_handle)) {
		torture_comment(tctx,
				"epm_LookupHandleFree failed - empty policy_handle\n");
		return false;
	}

	r.in.entry_handle = entry_handle;
	r.out.entry_handle = entry_handle;

	status = dcerpc_epm_LookupHandleFree_r(h, tctx, &r);
	if (NT_STATUS_IS_ERR(status)) {
		torture_comment(tctx,
				"epm_LookupHandleFree failed - %s\n",
				nt_errstr(status));
		return false;
	}

	if (r.out.result != EPMAPPER_STATUS_OK) {
		torture_comment(tctx,
				"epm_LookupHandleFree failed - internal error: "
				"0x%.4x\n",
				r.out.result);
		return false;
	}

	return true;
}
Exemplo n.º 20
0
bool torture_samba3_badpath(struct torture_context *torture)
{
	struct smbcli_state *cli_nt = NULL;
	struct smbcli_state *cli_dos = NULL;
	const char *fname = "test.txt";
	const char *fname1 = "test1.txt";
	const char *dirname = "testdir";
	char *fpath;
	char *fpath1;
	int fnum;
	NTSTATUS status;
	bool ret = true;
	TALLOC_CTX *mem_ctx;
	bool nt_status_support;

	torture_assert(torture, mem_ctx = talloc_init("torture_samba3_badpath"), "talloc_init failed");

	nt_status_support = lpcfg_nt_status_support(torture->lp_ctx);

	torture_assert_goto(torture, lpcfg_set_cmdline(torture->lp_ctx, "nt status support", "yes"), ret, fail, "Could not set 'nt status support = yes'\n");

	torture_assert_goto(torture, torture_open_connection(&cli_nt, torture, 0), ret, fail, "Could not open NTSTATUS connection\n");

	torture_assert_goto(torture, lpcfg_set_cmdline(torture->lp_ctx, "nt status support", "no"), ret, fail, "Could not set 'nt status support = no'\n");

	torture_assert_goto(torture, torture_open_connection(&cli_dos, torture, 1), ret, fail, "Could not open DOS connection\n");

	torture_assert_goto(torture, lpcfg_set_cmdline(torture->lp_ctx, "nt status support",
						       nt_status_support ? "yes":"no"), 
			    ret, fail, "Could not set 'nt status support' back to where it was\n");

	torture_assert(torture, torture_setup_dir(cli_nt, dirname), "creating test directory");

	status = smbcli_chkpath(cli_nt->tree, dirname);
	CHECK_STATUS(torture, status, NT_STATUS_OK);

	status = smbcli_chkpath(cli_nt->tree,
				talloc_asprintf(mem_ctx, "%s\\bla", dirname));
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND);

	status = smbcli_chkpath(cli_dos->tree,
				talloc_asprintf(mem_ctx, "%s\\bla", dirname));
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	status = smbcli_chkpath(cli_nt->tree,
				talloc_asprintf(mem_ctx, "%s\\bla\\blub",
						dirname));
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
	status = smbcli_chkpath(cli_dos->tree,
				talloc_asprintf(mem_ctx, "%s\\bla\\blub",
						dirname));
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	torture_assert_goto(torture, fpath = talloc_asprintf(mem_ctx, "%s\\%s", dirname, fname), 
			    ret, fail, "Could not allocate fpath\n");

	fnum = smbcli_open(cli_nt->tree, fpath, O_RDWR | O_CREAT, DENY_NONE);
	if (fnum == -1) {
		torture_result(torture, TORTURE_FAIL, "Could not create file %s: %s\n", fpath,
			 smbcli_errstr(cli_nt->tree));
		goto fail;
	}
	smbcli_close(cli_nt->tree, fnum);

	if (!(fpath1 = talloc_asprintf(mem_ctx, "%s\\%s", dirname, fname1))) {
		goto fail;
	}
	fnum = smbcli_open(cli_nt->tree, fpath1, O_RDWR | O_CREAT, DENY_NONE);
	if (fnum == -1) {
		torture_result(torture, TORTURE_FAIL, "Could not create file %s: %s\n", fpath1,
			 smbcli_errstr(cli_nt->tree));
		goto fail;
	}
	smbcli_close(cli_nt->tree, fnum);

	/*
	 * Do a whole bunch of error code checks on chkpath
	 */

	status = smbcli_chkpath(cli_nt->tree, fpath);
	CHECK_STATUS(torture, status, NT_STATUS_NOT_A_DIRECTORY);
	status = smbcli_chkpath(cli_dos->tree, fpath);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	status = smbcli_chkpath(cli_nt->tree, "..");
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
	status = smbcli_chkpath(cli_dos->tree, "..");
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidpath));

	status = smbcli_chkpath(cli_nt->tree, ".");
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_chkpath(cli_dos->tree, ".");
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	status = smbcli_chkpath(cli_nt->tree, "\t");
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_chkpath(cli_dos->tree, "\t");
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	status = smbcli_chkpath(cli_nt->tree, "\t\\bla");
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_chkpath(cli_dos->tree, "\t\\bla");
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	status = smbcli_chkpath(cli_nt->tree, "<");
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_chkpath(cli_dos->tree, "<");
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	status = smbcli_chkpath(cli_nt->tree, "<\\bla");
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_chkpath(cli_dos->tree, "<\\bla");
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRbadpath));

	/*
	 * .... And the same gang against getatr. Note that the DOS error codes
	 * differ....
	 */

	status = smbcli_getatr(cli_nt->tree, fpath, NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OK);
	status = smbcli_getatr(cli_dos->tree, fpath, NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OK);

	status = smbcli_getatr(cli_nt->tree, "..", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
	status = smbcli_getatr(cli_dos->tree, "..", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidpath));

	status = smbcli_getatr(cli_nt->tree, ".", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_getatr(cli_dos->tree, ".", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = smbcli_getatr(cli_nt->tree, "\t", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_getatr(cli_dos->tree, "\t", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = smbcli_getatr(cli_nt->tree, "\t\\bla", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_getatr(cli_dos->tree, "\t\\bla", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = smbcli_getatr(cli_nt->tree, "<", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_getatr(cli_dos->tree, "<", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = smbcli_getatr(cli_nt->tree, "<\\bla", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = smbcli_getatr(cli_dos->tree, "<\\bla", NULL, NULL, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	/* Try the same set with openX. */

	status = raw_smbcli_open(cli_nt->tree, "..", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
	status = raw_smbcli_open(cli_dos->tree, "..", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidpath));

	status = raw_smbcli_open(cli_nt->tree, ".", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = raw_smbcli_open(cli_dos->tree, ".", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = raw_smbcli_open(cli_nt->tree, "\t", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = raw_smbcli_open(cli_dos->tree, "\t", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = raw_smbcli_open(cli_nt->tree, "\t\\bla", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = raw_smbcli_open(cli_dos->tree, "\t\\bla", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = raw_smbcli_open(cli_nt->tree, "<", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = raw_smbcli_open(cli_dos->tree, "<", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	status = raw_smbcli_open(cli_nt->tree, "<\\bla", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_INVALID);
	status = raw_smbcli_open(cli_dos->tree, "<\\bla", O_RDONLY, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS, ERRinvalidname));

	/* Let's test EEXIST error code mapping. */
	status = raw_smbcli_open(cli_nt->tree, fpath, O_RDONLY | O_CREAT| O_EXCL, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_COLLISION);
	status = raw_smbcli_open(cli_dos->tree, fpath, O_RDONLY | O_CREAT| O_EXCL, DENY_NONE, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS,ERRfilexists));

	status = raw_smbcli_t2open(cli_nt->tree, fpath, O_RDONLY | O_CREAT| O_EXCL, DENY_NONE, NULL);
	if (!NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
	    || !torture_setting_bool(torture, "samba3", false)) {
		/* Against samba3, treat EAS_NOT_SUPPORTED as acceptable */
		CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_COLLISION);
	}
	status = raw_smbcli_t2open(cli_dos->tree, fpath, O_RDONLY | O_CREAT| O_EXCL, DENY_NONE, NULL);
	if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS,ERReasnotsupported))
	    || !torture_setting_bool(torture, "samba3", false)) {
		/* Against samba3, treat EAS_NOT_SUPPORTED as acceptable */
		CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS,ERRfilexists));
	}

	status = raw_smbcli_ntcreate(cli_nt->tree, fpath, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_COLLISION);
	status = raw_smbcli_ntcreate(cli_dos->tree, fpath, NULL);
	CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS,ERRfilexists));

	/* Try the rename test. */
	{
		union smb_rename io;
		memset(&io, '\0', sizeof(io));
		io.rename.in.pattern1 = fpath1;
		io.rename.in.pattern2 = fpath;

		/* Try with SMBmv rename. */
		status = smb_raw_rename(cli_nt->tree, &io);
		CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_COLLISION);
		status = smb_raw_rename(cli_dos->tree, &io);
		CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS,ERRrename));

		/* Try with NT rename. */
		io.generic.level = RAW_RENAME_NTRENAME;
		io.ntrename.in.old_name = fpath1;
		io.ntrename.in.new_name = fpath;
		io.ntrename.in.attrib = 0;
		io.ntrename.in.cluster_size = 0;
		io.ntrename.in.flags = RENAME_FLAG_RENAME;

		status = smb_raw_rename(cli_nt->tree, &io);
		CHECK_STATUS(torture, status, NT_STATUS_OBJECT_NAME_COLLISION);
		status = smb_raw_rename(cli_dos->tree, &io);
		CHECK_STATUS(torture, status, NT_STATUS_DOS(ERRDOS,ERRrename));
	}

	goto done;

 fail:
	ret = false;

 done:
	if (cli_nt != NULL) {
		smbcli_deltree(cli_nt->tree, dirname);
		torture_close_connection(cli_nt);
	}
	if (cli_dos != NULL) {
		torture_close_connection(cli_dos);
	}
	talloc_free(mem_ctx);

	return ret;
}
Exemplo n.º 21
0
/*
  test the TestSleep interface
*/
static bool test_sleep(struct torture_context *tctx,
						  struct dcerpc_pipe *p)
{
	int i;
	NTSTATUS status;
#define ASYNC_COUNT 3
	struct rpc_request *req[ASYNC_COUNT];
	struct echo_TestSleep r[ASYNC_COUNT];
	bool done[ASYNC_COUNT];
	struct timeval snd[ASYNC_COUNT];
	struct timeval rcv[ASYNC_COUNT];
	struct timeval diff[ASYNC_COUNT];
	struct tevent_context *ctx;
	int total_done = 0;

	if (torture_setting_bool(tctx, "quick", false)) {
		torture_skip(tctx, "TestSleep disabled - use \"torture:quick=no\" to enable\n");
	}
	torture_comment(tctx, "Testing TestSleep - use \"torture:quick=yes\" to disable\n");

	for (i=0;i<ASYNC_COUNT;i++) {
		done[i]		= false;
		snd[i]		= timeval_current();
		rcv[i]		= timeval_zero();
		r[i].in.seconds = ASYNC_COUNT-i;
		req[i] = dcerpc_echo_TestSleep_send(p, tctx, &r[i]);
		torture_assert(tctx, req[i], "Failed to send async sleep request\n");
	}

	ctx = dcerpc_event_context(p);
	while (total_done < ASYNC_COUNT) {
		torture_assert(tctx, event_loop_once(ctx) == 0, 
					   "Event context loop failed");
		for (i=0;i<ASYNC_COUNT;i++) {
			if (done[i] == false && req[i]->state == RPC_REQUEST_DONE) {
				int rounded_tdiff;
				total_done++;
				done[i] = true;
				rcv[i]	= timeval_current();
				diff[i]	= timeval_until(&snd[i], &rcv[i]);
				rounded_tdiff = (int)(0.5 + diff[i].tv_sec + (1.0e-6*diff[i].tv_usec));
				status	= dcerpc_ndr_request_recv(req[i]);
				torture_comment(tctx, "rounded_tdiff=%d\n", rounded_tdiff);
				torture_assert_ntstatus_ok(tctx, status, 
							talloc_asprintf(tctx, "TestSleep(%d) failed", i));
				torture_assert(tctx, r[i].out.result == r[i].in.seconds,
					talloc_asprintf(tctx, "Failed - Asked to sleep for %u seconds (server replied with %u seconds and the reply takes only %u seconds)", 
						r[i].out.result, r[i].in.seconds, (unsigned int)diff[i].tv_sec));
				torture_assert(tctx, r[i].out.result <= rounded_tdiff, 
					talloc_asprintf(tctx, "Failed - Slept for %u seconds (but reply takes only %u.%06u seconds)", 
						r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec));
				if (r[i].out.result+1 == rounded_tdiff) {
					torture_comment(tctx, "Slept for %u seconds (but reply takes %u.%06u seconds - busy server?)\n", 
							r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
				} else if (r[i].out.result == rounded_tdiff) {
					torture_comment(tctx, "Slept for %u seconds (reply takes %u.%06u seconds - ok)\n", 
							r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
				} else {
						torture_comment(tctx, "(Failed) - Not async - Slept for %u seconds (but reply takes %u.%06u seconds)", 
							r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
					/* TODO: let the test fail here, when we support async rpc on ncacn_np */
				}
			}
		}
	}
	torture_comment(tctx, "\n");
	return true;
}
Exemplo n.º 22
0
/*
  test some interesting combinations found by gentest
 */
static bool test_create_gentest(struct torture_context *tctx, struct smb2_tree *tree)
{
    struct smb2_create io;
    NTSTATUS status;
    uint32_t access_mask, file_attributes_set;
    uint32_t ok_mask, not_supported_mask, invalid_parameter_mask;
    uint32_t not_a_directory_mask, unexpected_mask;
    union smb_fileinfo q;

    ZERO_STRUCT(io);
    io.in.desired_access     = SEC_FLAG_MAXIMUM_ALLOWED;
    io.in.file_attributes    = FILE_ATTRIBUTE_NORMAL;
    io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    io.in.share_access =
        NTCREATEX_SHARE_ACCESS_DELETE|
        NTCREATEX_SHARE_ACCESS_READ|
        NTCREATEX_SHARE_ACCESS_WRITE;
    io.in.create_options = 0;
    io.in.fname = FNAME;

    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);

    status = smb2_util_close(tree, io.out.file.handle);
    CHECK_STATUS(status, NT_STATUS_OK);

    io.in.create_options = 0xF0000000;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);

    io.in.create_options = 0;

    io.in.file_attributes = FILE_ATTRIBUTE_DEVICE;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);

    io.in.file_attributes = FILE_ATTRIBUTE_VOLUME;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);

    io.in.create_disposition = NTCREATEX_DISP_OPEN;
    io.in.file_attributes = FILE_ATTRIBUTE_VOLUME;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);

    io.in.create_disposition = NTCREATEX_DISP_CREATE;
    io.in.desired_access = 0x08000000;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);

    io.in.desired_access = 0x04000000;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);

    io.in.file_attributes = 0;
    io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
    io.in.desired_access     = SEC_FLAG_MAXIMUM_ALLOWED;
    ok_mask = 0;
    not_supported_mask = 0;
    invalid_parameter_mask = 0;
    not_a_directory_mask = 0;
    unexpected_mask = 0;
    {
        int i;
        for (i=0; i<32; i++) {
            io.in.create_options = 1<<i;
            if (io.in.create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
                continue;
            }
            status = smb2_create(tree, tctx, &io);
            if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
                not_supported_mask |= 1<<i;
            } else if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
                invalid_parameter_mask |= 1<<i;
            } else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_DIRECTORY)) {
                not_a_directory_mask |= 1<<i;
            } else if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
                ok_mask |= 1<<i;
                status = smb2_util_close(tree, io.out.file.handle);
                CHECK_STATUS(status, NT_STATUS_OK);
            } else {
                unexpected_mask |= 1<<i;
                torture_comment(tctx,
                                "create option 0x%08x returned %s\n",
                                1<<i, nt_errstr(status));
            }
        }
    }
    io.in.create_options = 0;

    CHECK_EQUAL(ok_mask,                0x00efcf7e);
    CHECK_EQUAL(not_a_directory_mask,   0x00000001);
    CHECK_EQUAL(not_supported_mask,     0x00102080);
    CHECK_EQUAL(invalid_parameter_mask, 0xff000000);
    CHECK_EQUAL(unexpected_mask,        0x00000000);

    io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
    io.in.file_attributes = 0;
    access_mask = 0;
    {
        int i;
        for (i=0; i<32; i++) {
            io.in.desired_access = 1<<i;
            status = smb2_create(tree, tctx, &io);
            if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
                    NT_STATUS_EQUAL(status, NT_STATUS_PRIVILEGE_NOT_HELD)) {
                access_mask |= io.in.desired_access;
            } else {
                CHECK_STATUS(status, NT_STATUS_OK);
                status = smb2_util_close(tree, io.out.file.handle);
                CHECK_STATUS(status, NT_STATUS_OK);
            }
        }
    }

    if (TARGET_IS_WIN7(tctx)) {
        CHECK_EQUAL(access_mask, 0x0de0fe00);
    } else if (torture_setting_bool(tctx, "samba4", false)) {
        CHECK_EQUAL(access_mask, 0x0cf0fe00);
    } else {
        CHECK_EQUAL(access_mask, 0x0df0fe00);
    }

    io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
    io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
    io.in.file_attributes = 0;
    ok_mask = 0;
    invalid_parameter_mask = 0;
    unexpected_mask = 0;
    file_attributes_set = 0;
    {
        int i;
        for (i=0; i<32; i++) {
            io.in.file_attributes = 1<<i;
            if (io.in.file_attributes & FILE_ATTRIBUTE_ENCRYPTED) {
                continue;
            }
            smb2_deltree(tree, FNAME);
            status = smb2_create(tree, tctx, &io);
            if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
                invalid_parameter_mask |= 1<<i;
            } else if (NT_STATUS_IS_OK(status)) {
                uint32_t expected;
                ok_mask |= 1<<i;

                expected = (io.in.file_attributes | FILE_ATTRIBUTE_ARCHIVE) & 0x00005127;
                CHECK_EQUAL(io.out.file_attr, expected);
                file_attributes_set |= io.out.file_attr;

                status = smb2_util_close(tree, io.out.file.handle);
                CHECK_STATUS(status, NT_STATUS_OK);
            } else {
                unexpected_mask |= 1<<i;
                torture_comment(tctx,
                                "file attribute 0x%08x returned %s\n",
                                1<<i, nt_errstr(status));
            }
        }
    }

    CHECK_EQUAL(ok_mask,                0x00003fb7);
    CHECK_EQUAL(invalid_parameter_mask, 0xffff8048);
    CHECK_EQUAL(unexpected_mask,        0x00000000);
    CHECK_EQUAL(file_attributes_set,    0x00001127);

    smb2_deltree(tree, FNAME);

    /*
     * Standalone servers doesn't support encryption
     */
    io.in.file_attributes = FILE_ATTRIBUTE_ENCRYPTED;
    status = smb2_create(tree, tctx, &io);
    if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
        torture_comment(tctx,
                        "FILE_ATTRIBUTE_ENCRYPTED returned %s\n",
                        nt_errstr(status));
    } else {
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_EQUAL(io.out.file_attr, (FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_ARCHIVE));
        status = smb2_util_close(tree, io.out.file.handle);
        CHECK_STATUS(status, NT_STATUS_OK);
    }

    smb2_deltree(tree, FNAME);

    ZERO_STRUCT(io);
    io.in.desired_access     = SEC_FLAG_MAXIMUM_ALLOWED;
    io.in.file_attributes    = 0;
    io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    io.in.share_access =
        NTCREATEX_SHARE_ACCESS_READ|
        NTCREATEX_SHARE_ACCESS_WRITE;
    io.in.create_options = 0;
    io.in.fname = FNAME ":stream1";
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);

    status = smb2_util_close(tree, io.out.file.handle);
    CHECK_STATUS(status, NT_STATUS_OK);

    io.in.fname = FNAME;
    io.in.file_attributes = 0x8040;
    io.in.share_access =
        NTCREATEX_SHARE_ACCESS_READ;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);

    io.in.fname = FNAME;
    io.in.file_attributes = 0;
    io.in.desired_access  = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA;
    io.in.query_maximal_access = true;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_EQUAL(io.out.maximal_access, 0x001f01ff);

    q.access_information.level = RAW_FILEINFO_ACCESS_INFORMATION;
    q.access_information.in.file.handle = io.out.file.handle;
    status = smb2_getinfo_file(tree, tctx, &q);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_EQUAL(q.access_information.out.access_flags, io.in.desired_access);

    io.in.file_attributes = 0;
    io.in.desired_access  = 0;
    io.in.query_maximal_access = false;
    io.in.share_access = 0;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);

    smb2_deltree(tree, FNAME);

    return true;
}
Exemplo n.º 23
0
/*
 * basic testing of all RAW_SFILEINFO_RENAME call
 */
static bool
torture_raw_sfileinfo_rename(struct torture_context *torture,
                             struct smbcli_state *cli)
{
    bool ret = true;
    int fnum_saved, d_fnum, fnum2, fnum = -1;
    char *fnum_fname;
    char *fnum_fname_new;
    char *path_fname;
    char *path_fname_new;
    char *path_dname;
    char *path_dname_new;
    char *saved_name;
    char *saved_name_new;
    union smb_fileinfo finfo1, finfo2;
    union smb_setfileinfo sfinfo;
    NTSTATUS status, status2;
    const char *call_name;
    bool check_fnum;
    int n = time(NULL) % 100;

    asprintf(&path_fname, BASEDIR "\\fname_test_%d.txt", n);
    asprintf(&path_fname_new, BASEDIR "\\fname_test_new_%d.txt", n);
    asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n);
    asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n);
    asprintf(&path_dname, BASEDIR "\\dname_test_%d", n);
    asprintf(&path_dname_new, BASEDIR "\\dname_test_new_%d", n);

    if (!torture_setup_dir(cli, BASEDIR)) {
        return false;
    }

    RECREATE_BOTH;

    ZERO_STRUCT(sfinfo);

    smbcli_close(cli->tree, create_complex_file(cli, torture, fnum_fname_new));
    smbcli_close(cli->tree, create_complex_file(cli, torture, path_fname_new));

    sfinfo.rename_information.in.overwrite = 0;
    sfinfo.rename_information.in.root_fid  = 0;
    sfinfo.rename_information.in.new_name  = fnum_fname_new+strlen(BASEDIR)+1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION);

    sfinfo.rename_information.in.new_name  = path_fname_new+strlen(BASEDIR)+1;
    CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION);

    sfinfo.rename_information.in.new_name  = fnum_fname_new;
    sfinfo.rename_information.in.overwrite = 1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_NOT_SUPPORTED);

    sfinfo.rename_information.in.new_name  = fnum_fname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);

    printf("Trying rename with dest file open\n");
    fnum2 = create_complex_file(cli, torture, fnum_fname);
    sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_ACCESS_DENIED);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);

    fnum_saved = fnum;
    fnum = fnum2;
    sfinfo.disposition_info.in.delete_on_close = 1;
    CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK);
    fnum = fnum_saved;

    printf("Trying rename with dest file open and delete_on_close\n");
    sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_ACCESS_DENIED);

    smbcli_close(cli->tree, fnum2);
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);

    printf("Trying rename with source file open twice\n");
    sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);

    fnum2 = create_complex_file(cli, torture, fnum_fname);
    sfinfo.rename_information.in.new_name  = fnum_fname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 0;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);
    smbcli_close(cli->tree, fnum2);

    sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 0;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);

    sfinfo.rename_information.in.new_name  = path_fname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 1;
    CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new);

    sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);

    sfinfo.rename_information.in.new_name  = path_fname+strlen(BASEDIR)+1;
    CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_fname);

    printf("Trying rename with a root fid\n");
    status = create_directory_handle(cli->tree, BASEDIR, &d_fnum);
    CHECK_STATUS(status, NT_STATUS_OK);
    sfinfo.rename_information.in.new_name  = fnum_fname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.root_fid = d_fnum;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_INVALID_PARAMETER);
    CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
    smbcli_close(cli->tree, d_fnum);

    printf("Trying rename directory\n");
    if (!torture_setup_dir(cli, path_dname)) {
        ret = false;
        goto done;
    }
    saved_name = path_fname;
    saved_name_new = path_fname_new;
    path_fname = path_dname;
    path_fname_new = path_dname_new;
    sfinfo.rename_information.in.new_name  = path_dname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 0;
    sfinfo.rename_information.in.root_fid  = 0;
    CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_dname_new);
    path_fname = saved_name;
    path_fname_new = saved_name_new;

    if (torture_setting_bool(torture, "samba3", false)) {
        printf("SKIP: Trying rename directory with a handle\n");
        printf("SKIP: Trying rename by path while a handle is open\n");
        printf("SKIP: Trying rename directory by path while a handle is open\n");
        goto done;
    }

    printf("Trying rename directory with a handle\n");
    status = create_directory_handle(cli->tree, path_dname_new, &d_fnum);
    fnum_saved = fnum;
    fnum = d_fnum;
    saved_name = fnum_fname;
    saved_name_new = fnum_fname_new;
    fnum_fname = path_dname;
    fnum_fname_new = path_dname_new;
    sfinfo.rename_information.in.new_name  = path_dname+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 0;
    sfinfo.rename_information.in.root_fid  = 0;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_dname);
    smbcli_close(cli->tree, d_fnum);
    fnum = fnum_saved;
    fnum_fname = saved_name;
    fnum_fname_new = saved_name_new;

    printf("Trying rename by path while a handle is open\n");
    fnum_saved = fnum;
    fnum = create_complex_file(cli, torture, path_fname);
    sfinfo.rename_information.in.new_name  = path_fname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 0;
    sfinfo.rename_information.in.root_fid  = 0;
    CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new);
    /* check that the handle returns the same name */
    check_fnum = true;
    CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new);
    /* rename it back on the handle */
    sfinfo.rename_information.in.new_name  = path_fname+strlen(BASEDIR)+1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_fname);
    check_fnum = false;
    CHECK_STR(NAME_INFO, name_info, fname.s, path_fname);
    smbcli_close(cli->tree, fnum);
    fnum = fnum_saved;

    printf("Trying rename directory by path while a handle is open\n");
    status = create_directory_handle(cli->tree, path_dname, &d_fnum);
    fnum_saved = fnum;
    fnum = d_fnum;
    saved_name = path_fname;
    saved_name_new = path_fname_new;
    path_fname = path_dname;
    path_fname_new = path_dname_new;
    sfinfo.rename_information.in.new_name  = path_dname_new+strlen(BASEDIR)+1;
    sfinfo.rename_information.in.overwrite = 0;
    sfinfo.rename_information.in.root_fid  = 0;
    CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_dname_new);
    path_fname = saved_name;
    path_fname_new = saved_name_new;
    saved_name = fnum_fname;
    saved_name_new = fnum_fname_new;
    fnum_fname = path_dname;
    fnum_fname_new = path_dname_new;
    /* check that the handle returns the same name */
    check_fnum = true;
    CHECK_STR(NAME_INFO, name_info, fname.s, path_dname_new);
    /* rename it back on the handle */
    sfinfo.rename_information.in.new_name  = path_dname+strlen(BASEDIR)+1;
    CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
    CHECK_STR(NAME_INFO, name_info, fname.s, path_dname);
    fnum_fname = saved_name;
    fnum_fname_new = saved_name_new;
    saved_name = path_fname;
    saved_name_new = path_fname_new;
    path_fname = path_dname;
    path_fname_new = path_dname_new;
    check_fnum = false;
    CHECK_STR(NAME_INFO, name_info, fname.s, path_dname);
    smbcli_close(cli->tree, d_fnum);
    fnum = fnum_saved;
    path_fname = saved_name;
    path_fname_new = saved_name_new;

done:
    smb_raw_exit(cli->session);
    smbcli_deltree(cli->tree, BASEDIR);
    return ret;
}
Exemplo n.º 24
0
/* 
   test offline file handling
*/
bool torture_test_offline(struct torture_context *torture)
{
	bool ret = true;
	TALLOC_CTX *mem_ctx = talloc_new(torture);
	int i;
	int timelimit = torture_setting_int(torture, "timelimit", 10);
	struct timeval tv;
	struct offline_state *state;
	struct smbcli_state *cli;
	bool progress;
	progress = torture_setting_bool(torture, "progress", true);

	nconnections = torture_setting_int(torture, "nprocs", 4);
	numstates = nconnections * torture_entries;

	state = talloc_zero_array(mem_ctx, struct offline_state, numstates);

	printf("Opening %d connections with %d simultaneous operations and %u files\n", nconnections, numstates, torture_numops);
	for (i=0;i<nconnections;i++) {
		state[i].tctx = torture;
		state[i].mem_ctx = talloc_new(state);
		state[i].ev = torture->ev;
		if (!torture_open_connection_ev(&cli, i, torture, torture->ev)) {
			return false;
		}
		state[i].tree = cli->tree;
		state[i].client = i;
		/* allow more time for offline files */
		state[i].tree->session->transport->options.request_timeout = 200;
	}

	/* the others are repeats on the earlier connections */
	for (i=nconnections;i<numstates;i++) {
		state[i].tctx = torture;
		state[i].mem_ctx = talloc_new(state);
		state[i].ev = torture->ev;
		state[i].tree = state[i % nconnections].tree;
		state[i].client = i;
	}

	num_connected = i;

	if (!torture_setup_dir(cli, BASEDIR)) {
		goto failed;
	}

	/* pre-create files */
	printf("Pre-creating %u files ....\n", torture_numops);
	for (i=0;i<torture_numops;i++) {
		int fnum;
		char *fname = filename(mem_ctx, i);
		char buf[FILE_SIZE];
		NTSTATUS status;

		memset(buf, 1+(i % 255), sizeof(buf));

		fnum = smbcli_open(state[0].tree, fname, O_RDWR|O_CREAT, DENY_NONE);
		if (fnum == -1) {
			printf("Failed to open %s on connection %d\n", fname, i);
			goto failed;
		}

		if (smbcli_write(state[0].tree, fnum, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
			printf("Failed to write file of size %u\n", FILE_SIZE);
			goto failed;
		}

		status = smbcli_close(state[0].tree, fnum);
		if (!NT_STATUS_IS_OK(status)) {
			printf("Close failed - %s\n", nt_errstr(status));
			goto failed;
		}

		talloc_free(fname);
	}

	/* start the async ops */
	for (i=0;i<numstates;i++) {
		state[i].tv_start = timeval_current();
		test_offline(&state[i]);
	}

	tv = timeval_current();	

	if (progress) {
		event_add_timed(torture->ev, state, timeval_current_ofs(1, 0), report_rate, state);
	}

	printf("Running for %d seconds\n", timelimit);
	while (timeval_elapsed(&tv) < timelimit) {
		event_loop_once(torture->ev);

		if (test_failed) {
			DEBUG(0,("test failed\n"));
			goto failed;
		}
	}

	printf("\nWaiting for completion\n");
	test_finished = true;
	for (i=0;i<numstates;i++) {
		while (state[i].loadfile || 
		       state[i].savefile ||
		       state[i].req) {
			event_loop_once(torture->ev);
		}
	}	

	printf("worst latencies: set_lat=%.1f get_lat=%.1f save_lat=%.1f load_lat=%.1f\n",
	       worst_latencies[OP_SETOFFLINE],
	       worst_latencies[OP_GETOFFLINE],
	       worst_latencies[OP_SAVEFILE],
	       worst_latencies[OP_LOADFILE]);

	smbcli_deltree(state[0].tree, BASEDIR);
	talloc_free(mem_ctx);
	printf("\n");
	return ret;

failed:
	talloc_free(mem_ctx);
	return false;
}
Exemplo n.º 25
0
/*
 * Test creating a file with a NULL DACL.
 */
static bool test_create_null_dacl(struct torture_context *tctx,
                                  struct smb2_tree *tree)
{
    NTSTATUS status;
    struct smb2_create io;
    const char *fname = "nulldacl.txt";
    bool ret = true;
    struct smb2_handle handle;
    union smb_fileinfo q;
    union smb_setfileinfo s;
    struct security_descriptor *sd = security_descriptor_initialise(tctx);
    struct security_acl dacl;

    torture_comment(tctx, "TESTING SEC_DESC WITH A NULL DACL\n");

    smb2_util_unlink(tree, fname);

    ZERO_STRUCT(io);
    io.level = RAW_OPEN_SMB2;
    io.in.create_flags = 0;
    io.in.desired_access = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC
                           | SEC_STD_WRITE_OWNER;
    io.in.create_options = 0;
    io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
    io.in.share_access =
        NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
    io.in.alloc_size = 0;
    io.in.create_disposition = NTCREATEX_DISP_CREATE;
    io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
    io.in.security_flags = 0;
    io.in.fname = fname;
    io.in.sec_desc = sd;
    /* XXX create_options ? */
    io.in.create_options		= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
                                  NTCREATEX_OPTIONS_ASYNC_ALERT	|
                                  NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
                                  0x00200000;

    torture_comment(tctx, "creating a file with a empty sd\n");
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    handle = io.out.file.handle;

    torture_comment(tctx, "get the original sd\n");
    q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    q.query_secdesc.in.file.handle = handle;
    q.query_secdesc.in.secinfo_flags =
        SECINFO_OWNER |
        SECINFO_GROUP |
        SECINFO_DACL;
    status = smb2_getinfo_file(tree, tctx, &q);
    CHECK_STATUS(status, NT_STATUS_OK);

    /*
     * Testing the created DACL,
     * the server should add the inherited DACL
     * when SEC_DESC_DACL_PRESENT isn't specified
     */
    if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
        ret = false;
        torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
    }
    if (q.query_secdesc.out.sd->dacl == NULL) {
        ret = false;
        torture_fail_goto(tctx, done, "no DACL has been created on the server!\n");
    }

    torture_comment(tctx, "set NULL DACL\n");
    sd->type |= SEC_DESC_DACL_PRESENT;

    s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
    s.set_secdesc.in.file.handle = handle;
    s.set_secdesc.in.secinfo_flags = SECINFO_DACL;
    s.set_secdesc.in.sd = sd;
    status = smb2_setinfo_file(tree, &s);
    CHECK_STATUS(status, NT_STATUS_OK);

    torture_comment(tctx, "get the sd\n");
    q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    q.query_secdesc.in.file.handle = handle;
    q.query_secdesc.in.secinfo_flags =
        SECINFO_OWNER |
        SECINFO_GROUP |
        SECINFO_DACL;
    status = smb2_getinfo_file(tree, tctx, &q);
    CHECK_STATUS(status, NT_STATUS_OK);

    /* Testing the modified DACL */
    if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
        ret = false;
        torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
    }
    if (q.query_secdesc.out.sd->dacl != NULL) {
        ret = false;
        torture_fail_goto(tctx, done, "DACL has been created on the server!\n");
    }

    io.in.create_disposition = NTCREATEX_DISP_OPEN;

    torture_comment(tctx, "try open for read control\n");
    io.in.desired_access = SEC_STD_READ_CONTROL;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_ACCESS_FLAGS(io.out.file.handle,
                       SEC_STD_READ_CONTROL);
    smb2_util_close(tree, io.out.file.handle);

    torture_comment(tctx, "try open for write\n");
    io.in.desired_access = SEC_FILE_WRITE_DATA;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_ACCESS_FLAGS(io.out.file.handle,
                       SEC_FILE_WRITE_DATA);
    smb2_util_close(tree, io.out.file.handle);

    torture_comment(tctx, "try open for read\n");
    io.in.desired_access = SEC_FILE_READ_DATA;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_ACCESS_FLAGS(io.out.file.handle,
                       SEC_FILE_READ_DATA);
    smb2_util_close(tree, io.out.file.handle);

    torture_comment(tctx, "try open for generic write\n");
    io.in.desired_access = SEC_GENERIC_WRITE;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_ACCESS_FLAGS(io.out.file.handle,
                       SEC_RIGHTS_FILE_WRITE);
    smb2_util_close(tree, io.out.file.handle);

    torture_comment(tctx, "try open for generic read\n");
    io.in.desired_access = SEC_GENERIC_READ;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_ACCESS_FLAGS(io.out.file.handle,
                       SEC_RIGHTS_FILE_READ);
    smb2_util_close(tree, io.out.file.handle);

    torture_comment(tctx, "set DACL with 0 aces\n");
    ZERO_STRUCT(dacl);
    dacl.revision = SECURITY_ACL_REVISION_NT4;
    dacl.num_aces = 0;
    sd->dacl = &dacl;

    s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
    s.set_secdesc.in.file.handle = handle;
    s.set_secdesc.in.secinfo_flags = SECINFO_DACL;
    s.set_secdesc.in.sd = sd;
    status = smb2_setinfo_file(tree, &s);
    CHECK_STATUS(status, NT_STATUS_OK);

    torture_comment(tctx, "get the sd\n");
    q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    q.query_secdesc.in.file.handle = handle;
    q.query_secdesc.in.secinfo_flags =
        SECINFO_OWNER |
        SECINFO_GROUP |
        SECINFO_DACL;
    status = smb2_getinfo_file(tree, tctx, &q);
    CHECK_STATUS(status, NT_STATUS_OK);

    /* Testing the modified DACL */
    if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
        ret = false;
        torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
    }
    if (q.query_secdesc.out.sd->dacl == NULL) {
        ret = false;
        torture_fail_goto(tctx, done, "no DACL has been created on the server!\n");
    }
    if (q.query_secdesc.out.sd->dacl->num_aces != 0) {
        torture_result(tctx, TORTURE_FAIL, "DACL has %u aces!\n",
                       q.query_secdesc.out.sd->dacl->num_aces);
        ret = false;
        goto done;
    }

    torture_comment(tctx, "try open for read control\n");
    io.in.desired_access = SEC_STD_READ_CONTROL;
    status = smb2_create(tree, tctx, &io);
    CHECK_STATUS(status, NT_STATUS_OK);
    CHECK_ACCESS_FLAGS(io.out.file.handle,
                       SEC_STD_READ_CONTROL);
    smb2_util_close(tree, io.out.file.handle);

    torture_comment(tctx, "try open for write => access_denied\n");
    io.in.desired_access = SEC_FILE_WRITE_DATA;
    status = smb2_create(tree, tctx, &io);
    if (torture_setting_bool(tctx, "hide_on_access_denied", false)) {
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    } else {
        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    }

    torture_comment(tctx, "try open for read => access_denied\n");
    io.in.desired_access = SEC_FILE_READ_DATA;
    status = smb2_create(tree, tctx, &io);
    if (torture_setting_bool(tctx, "hide_on_access_denied", false)) {
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    } else {
        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    }

    torture_comment(tctx, "try open for generic write => access_denied\n");
    io.in.desired_access = SEC_GENERIC_WRITE;
    status = smb2_create(tree, tctx, &io);
    if (torture_setting_bool(tctx, "hide_on_access_denied", false)) {
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    } else {
        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    }

    torture_comment(tctx, "try open for generic read => access_denied\n");
    io.in.desired_access = SEC_GENERIC_READ;
    status = smb2_create(tree, tctx, &io);
    if (torture_setting_bool(tctx, "hide_on_access_denied", false)) {
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    } else {
        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    }

    torture_comment(tctx, "set empty sd\n");
    sd->type &= ~SEC_DESC_DACL_PRESENT;
    sd->dacl = NULL;

    s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
    s.set_secdesc.in.file.handle = handle;
    s.set_secdesc.in.secinfo_flags = SECINFO_DACL;
    s.set_secdesc.in.sd = sd;
    status = smb2_setinfo_file(tree, &s);
    CHECK_STATUS(status, NT_STATUS_OK);

    torture_comment(tctx, "get the sd\n");
    q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    q.query_secdesc.in.file.handle = handle;
    q.query_secdesc.in.secinfo_flags =
        SECINFO_OWNER |
        SECINFO_GROUP |
        SECINFO_DACL;
    status = smb2_getinfo_file(tree, tctx, &q);
    CHECK_STATUS(status, NT_STATUS_OK);

    /* Testing the modified DACL */
    if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
        ret = false;
        torture_fail_goto(tctx, done, "DACL_PRESENT flag not set by the server!\n");
    }
    if (q.query_secdesc.out.sd->dacl != NULL) {
        ret = false;
        torture_fail_goto(tctx, done, "DACL has been created on the server!\n");
    }
done:
    smb2_util_close(tree, handle);
    smb2_util_unlink(tree, fname);
    smb2_tdis(tree);
    smb2_logoff(tree->session);
    return ret;
}
Exemplo n.º 26
0
static bool internal_torture_run_test(struct torture_context *context, 
					  struct torture_tcase *tcase,
					  struct torture_test *test,
					  bool already_setup)
{
	bool success;
	char *old_testname = NULL;

	if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 
		old_testname = context->active_testname;
		context->active_testname = talloc_asprintf(context, "%s-%s", old_testname, test->name);
	}

	context->active_tcase = tcase;
	context->active_test = test;

	torture_ui_test_start(context, tcase, test);

	context->last_reason = NULL;
	context->last_result = TORTURE_OK;

	if (!already_setup && tcase->setup && 
		!tcase->setup(context, &(tcase->data))) {
	    	if (context->last_reason == NULL)
			context->last_reason = talloc_strdup(context, "Setup failure");
		context->last_result = TORTURE_ERROR;
		success = false;
	} else if (test->dangerous && 
	    !torture_setting_bool(context, "dangerous", false)) {
	    context->last_result = TORTURE_SKIP;
	    context->last_reason = talloc_asprintf(context, 
	    	"disabled %s - enable dangerous tests to use", test->name);
	    success = true;
	} else {
	    success = test->run(context, tcase, test);

	    if (!success && context->last_result == TORTURE_OK) {
		    if (context->last_reason == NULL)
			    context->last_reason = talloc_strdup(context, "Unknown error/failure");
		    context->last_result = TORTURE_ERROR;
	    }
	}

	if (!already_setup && tcase->teardown && !tcase->teardown(context, tcase->data)) {
    		if (context->last_reason == NULL)
		    context->last_reason = talloc_strdup(context, "Setup failure");
	    	context->last_result = TORTURE_ERROR;
		success = false;
	}

	torture_ui_test_result(context, context->last_result, 
			       context->last_reason);
	
	talloc_free(context->last_reason);

	if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 
		talloc_free(context->active_testname);
		context->active_testname = old_testname;
	}
	context->active_test = NULL;
	context->active_tcase = NULL;

	return success;
}
Exemplo n.º 27
0
bool torture_utable(struct torture_context *tctx, 
					struct smbcli_state *cli)
{
	char fname[256];
	const char *alt_name;
	int fnum;
	uint8_t c2[4];
	int c, fd;
	size_t len;
	int chars_allowed=0, alt_allowed=0;
	uint8_t valid[0x10000];

	torture_comment(tctx, "Generating valid character table\n");

	memset(valid, 0, sizeof(valid));

	torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
				   "Setting up dir \\utable failed");

	for (c=1; c < 0x10000; c++) {
		char *p;

		SSVAL(c2, 0, c);
		strncpy(fname, "\\utable\\x", sizeof(fname)-1);
		p = fname+strlen(fname);
		convert_string_convenience(lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, 
				     c2, 2, 
				     p, sizeof(fname)-strlen(fname), &len, false);
		p[len] = 0;
		strncat(fname,"_a_long_extension",sizeof(fname)-1);

		fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, 
				DENY_NONE);
		if (fnum == -1) continue;

		chars_allowed++;

		smbcli_qpathinfo_alt_name(cli->tree, fname, &alt_name);

		if (strncmp(alt_name, "X_A_L", 5) != 0) {
			alt_allowed++;
			valid[c] = 1;
			torture_comment(tctx, "fname=[%s] alt_name=[%s]\n", fname, alt_name);
		}

		smbcli_close(cli->tree, fnum);
		smbcli_unlink(cli->tree, fname);

		if (c % 100 == 0) {
			if (torture_setting_bool(tctx, "progress", true)) {
				torture_comment(tctx, "%d (%d/%d)\r", c, chars_allowed, alt_allowed);
				fflush(stdout);
			}
		}
	}
	torture_comment(tctx, "%d (%d/%d)\n", c, chars_allowed, alt_allowed);

	smbcli_rmdir(cli->tree, "\\utable");

	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);
	torture_assert(tctx, fd != -1, 
		talloc_asprintf(tctx, 
		"Failed to create valid.dat - %s", strerror(errno)));
	write(fd, valid, 0x10000);
	close(fd);
	torture_comment(tctx, "wrote valid.dat\n");

	return true;
}
Exemplo n.º 28
0
static bool torture_krb5_post_recv_test(struct torture_krb5_context *test_context, const krb5_data *recv_buf)
{
	KRB_ERROR error;
	size_t used;
	switch (test_context->test)
	{
	case TORTURE_KRB5_TEST_PLAIN:
		if (test_context->packet_count == 0) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KDC_ERR_PREAUTH_REQUIRED - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else if ((decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used) == 0)
			   && (test_context->packet_count == 1)) {
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KRB_ERR_RESPONSE_TOO_BIG - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else {
			torture_assert_int_equal(test_context->tctx,
						 decode_AS_REP(recv_buf->data, recv_buf->length, &test_context->as_rep, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx,
						 test_context->as_rep.pvno, 5,
						 "Got wrong as_rep->pvno");
			torture_assert_int_equal(test_context->tctx,
						 test_context->as_rep.ticket.tkt_vno, 5,
						 "Got wrong as_rep->ticket.tkt_vno");
			torture_assert(test_context->tctx,
				       test_context->as_rep.ticket.enc_part.kvno,
				       "Did not get a KVNO in test_context->as_rep.ticket.enc_part.kvno");
			if (torture_setting_bool(test_context->tctx, "expect_cached_at_rodc", false)) {
				torture_assert_int_not_equal(test_context->tctx,
							     *test_context->as_rep.ticket.enc_part.kvno & 0xFFFF0000,
							     0, "Did not get a RODC number in the KVNO");
			} else {
				torture_assert_int_equal(test_context->tctx,
							 *test_context->as_rep.ticket.enc_part.kvno & 0xFFFF0000,
							 0, "Unexpecedly got a RODC number in the KVNO");
			}
			free_AS_REP(&test_context->as_rep);
		}
		torture_assert(test_context->tctx, test_context->packet_count < 3, "too many packets");
		free_AS_REQ(&test_context->as_req);
		break;

		/* 
		 * Confirm correct error codes when we ask for the PAC.  This behaviour is rather odd...
		 */
	case TORTURE_KRB5_TEST_PAC_REQUEST:
		if (test_context->packet_count == 0) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KRB_ERR_RESPONSE_TOO_BIG - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else if (test_context->packet_count == 1) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KDC_ERR_PREAUTH_REQUIRED - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else if ((decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used) == 0)
			   && (test_context->packet_count == 2)) {
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KRB_ERR_RESPONSE_TOO_BIG - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else {
			torture_assert_int_equal(test_context->tctx,
						 decode_AS_REP(recv_buf->data, recv_buf->length, &test_context->as_rep, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, test_context->as_rep.pvno, 5, "Got wrong as_rep->pvno");
			free_AS_REP(&test_context->as_rep);
		}
		torture_assert(test_context->tctx, test_context->packet_count < 3, "too many packets");
		free_AS_REQ(&test_context->as_req);
		break;

		/* 
		 * Confirm correct error codes when we deliberatly send the wrong password
		 */
	case TORTURE_KRB5_TEST_BREAK_PW:
		if (test_context->packet_count == 0) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KDC_ERR_PREAUTH_REQUIRED - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else if (test_context->packet_count == 1) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KDC_ERR_PREAUTH_FAILED - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		}
		torture_assert(test_context->tctx, test_context->packet_count < 2, "too many packets");
		free_AS_REQ(&test_context->as_req);
		break;

		/* 
		 * Confirm correct error codes when we deliberatly skew the client clock
		 */
	case TORTURE_KRB5_TEST_CLOCK_SKEW:
		if (test_context->packet_count == 0) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KDC_ERR_PREAUTH_REQUIRED - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		} else if (test_context->packet_count == 1) {
			torture_assert_int_equal(test_context->tctx,
						 decode_KRB_ERROR(recv_buf->data, recv_buf->length, &error, &used), 0,
						 "decode_AS_REP failed");
			torture_assert_int_equal(test_context->tctx, used, recv_buf->length, "length mismatch");
			torture_assert_int_equal(test_context->tctx, error.pvno, 5, "Got wrong error.pvno");
			torture_assert_int_equal(test_context->tctx, error.error_code, KRB5KRB_AP_ERR_SKEW - KRB5KDC_ERR_NONE,
						 "Got wrong error.error_code");
			free_KRB_ERROR(&error);
		}
		torture_assert(test_context->tctx, test_context->packet_count < 2, "too many packets");
		free_AS_REQ(&test_context->as_req);
		break;
	}
	return true;
}
Exemplo n.º 29
0
Arquivo: misc.c Projeto: endisd/samba
/*
test how many open files this server supports on the one socket
*/
bool run_maxfidtest(struct torture_context *tctx, struct smbcli_state *cli, int dummy)
{
#define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
	char *fname;
	int fnums[0x11000], i;
	int retries=4, maxfid;
	bool correct = true;

	if (retries <= 0) {
		torture_comment(tctx, "failed to connect\n");
		return false;
	}

	if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
		torture_comment(tctx, "Failed to deltree \\maxfid - %s\n",
		       smbcli_errstr(cli->tree));
		return false;
	}
	if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
		torture_comment(tctx, "Failed to mkdir \\maxfid, error=%s\n", 
		       smbcli_errstr(cli->tree));
		return false;
	}

	torture_comment(tctx, "Testing maximum number of open files\n");

	for (i=0; i<0x11000; i++) {
		if (i % 1000 == 0) {
			asprintf(&fname, "\\maxfid\\fid%d", i/1000);
			if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
				torture_comment(tctx, "Failed to mkdir %s, error=%s\n", 
				       fname, smbcli_errstr(cli->tree));
				return false;
			}
			free(fname);
		}
		asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
		if ((fnums[i] = smbcli_open(cli->tree, fname, 
					O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
		    -1) {
			torture_comment(tctx, "open of %s failed (%s)\n", 
			       fname, smbcli_errstr(cli->tree));
			torture_comment(tctx, "maximum fnum is %d\n", i);
			break;
		}
		free(fname);
		if (torture_setting_bool(tctx, "progress", true)) {
			torture_comment(tctx, "%6d\r", i);
			fflush(stdout);
		}
	}
	torture_comment(tctx, "%6d\n", i);
	i--;

	maxfid = i;

	torture_comment(tctx, "cleaning up\n");
	for (i=0;i<maxfid/2;i++) {
		asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
		if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
			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))) {
			torture_comment(tctx, "unlink of %s failed (%s)\n", 
			       fname, smbcli_errstr(cli->tree));
			correct = false;
		}
		free(fname);

		asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
		if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
			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))) {
			torture_comment(tctx, "unlink of %s failed (%s)\n", 
			       fname, smbcli_errstr(cli->tree));
			correct = false;
		}
		free(fname);

		if (torture_setting_bool(tctx, "progress", true)) {
			torture_comment(tctx, "%6d %6d\r", i, maxfid-i);
			fflush(stdout);
		}
	}
	torture_comment(tctx, "%6d\n", 0);

	if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
		torture_comment(tctx, "Failed to deltree \\maxfid - %s\n",
		       smbcli_errstr(cli->tree));
		return false;
	}

	torture_comment(tctx, "maxfid test finished\n");
	if (!torture_close_connection(cli)) {
		correct = false;
	}
	return correct;
#undef MAXFID_TEMPLATE
}
Exemplo n.º 30
0
Arquivo: misc.c Projeto: endisd/samba
static bool rw_torture(struct torture_context *tctx, struct smbcli_state *c)
{
	const char *lockfname = "\\torture.lck";
	char *fname;
	int fnum;
	int fnum2;
	pid_t pid2, pid = getpid();
	int i, j;
	uint8_t buf[1024];
	bool correct = true;

	fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, 
			 DENY_NONE);
	if (fnum2 == -1)
		fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
	if (fnum2 == -1) {
		torture_comment(tctx, "open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
		return false;
	}

	generate_random_buffer(buf, sizeof(buf));

	for (i=0;i<torture_numops;i++) {
		uint_t n = (uint_t)random()%10;
		if (i % 10 == 0) {
			if (torture_setting_bool(tctx, "progress", true)) {
				torture_comment(tctx, "%d\r", i);
				fflush(stdout);
			}
		}
		asprintf(&fname, "\\torture.%u", n);

		if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
			return false;
		}

		fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
		if (fnum == -1) {
			torture_comment(tctx, "open failed (%s)\n", smbcli_errstr(c->tree));
			correct = false;
			break;
		}

		if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) {
			torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree));
			correct = false;
		}

		for (j=0;j<50;j++) {
			if (smbcli_write(c->tree, fnum, 0, buf, 
				      sizeof(pid)+(j*sizeof(buf)), 
				      sizeof(buf)) != sizeof(buf)) {
				torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree));
				correct = false;
			}
		}

		pid2 = 0;

		if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) {
			torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c->tree));
			correct = false;
		}

		if (pid2 != pid) {
			torture_comment(tctx, "data corruption!\n");
			correct = false;
		}

		if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
			torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(c->tree));
			correct = false;
		}

		if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
			torture_comment(tctx, "unlink failed (%s)\n", smbcli_errstr(c->tree));
			correct = false;
		}

		if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
			torture_comment(tctx, "unlock failed (%s)\n", smbcli_errstr(c->tree));
			correct = false;
		}
		free(fname);
	}

	smbcli_close(c->tree, fnum2);
	smbcli_unlink(c->tree, lockfname);

	torture_comment(tctx, "%d\n", i);

	return correct;
}