コード例 #1
0
ファイル: create.c プロジェクト: ElijahLuk/samba
static bool test_smb2_open_brlocked(struct torture_context *tctx,
                                    struct smb2_tree *tree)
{
    union smb_open io, io1;
    union smb_lock io2;
    struct smb2_lock_element lock[1];
    const char *fname = DNAME "\\torture_ntcreatex.txt";
    NTSTATUS status;
    bool ret = true;
    struct smb2_handle h;
    char b = 42;

    torture_comment(tctx,
                    "Testing SMB2 open with a byte range locked file\n");

    smb2_util_unlink(tree, fname);

    status = torture_smb2_testdir(tree, DNAME, &h);
    CHECK_STATUS(status, NT_STATUS_OK);

    ZERO_STRUCT(io.smb2);
    io.generic.level = RAW_OPEN_SMB2;
    io.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED;
    io.smb2.in.desired_access = 0x2019f;
    io.smb2.in.alloc_size = 0;
    io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
    io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
                              NTCREATEX_SHARE_ACCESS_WRITE;
    io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
    io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
    io.smb2.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
    io.smb2.in.security_flags = SMB2_SECURITY_DYNAMIC_TRACKING;
    io.smb2.in.fname = fname;

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

    status = smb2_util_write(tree, io.smb2.out.file.handle, &b, 0, 1);
    CHECK_STATUS(status, NT_STATUS_OK);

    ZERO_STRUCT(io2.smb2);
    io2.smb2.level = RAW_LOCK_SMB2;
    io2.smb2.in.file.handle = io.smb2.out.file.handle;
    io2.smb2.in.lock_count = 1;

    ZERO_STRUCT(lock);
    lock[0].offset = 0;
    lock[0].length = 1;
    lock[0].flags = SMB2_LOCK_FLAG_EXCLUSIVE |
                    SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
    io2.smb2.in.locks = &lock[0];
    status = smb2_lock(tree, &(io2.smb2));
    CHECK_STATUS(status, NT_STATUS_OK);

    ZERO_STRUCT(io1.smb2);
    io1.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED;
    io1.smb2.in.desired_access = 0x20196;
    io1.smb2.in.alloc_size = 0;
    io1.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
    io1.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
                               NTCREATEX_SHARE_ACCESS_WRITE;
    io1.smb2.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    io1.smb2.in.create_options = 0;
    io1.smb2.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
    io1.smb2.in.security_flags = SMB2_SECURITY_DYNAMIC_TRACKING;
    io1.smb2.in.fname = fname;

    status = smb2_create(tree, tctx, &(io1.smb2));
    CHECK_STATUS(status, NT_STATUS_OK);

    smb2_util_close(tree, io.smb2.out.file.handle);
    smb2_util_close(tree, io1.smb2.out.file.handle);
    smb2_util_unlink(tree, fname);
    smb2_deltree(tree, DNAME);

    return ret;
}
コード例 #2
0
ファイル: durable_open.c プロジェクト: AllardJ/Tomato
/*
  Open, take BRL, disconnect, reconnect.
*/
bool test_durable_open_lock(struct torture_context *tctx,
			    struct smb2_tree *tree)
{
	TALLOC_CTX *mem_ctx = talloc_new(tctx);
	struct smb2_create io;
	struct smb2_lease ls;
	struct smb2_handle h;
	struct smb2_lock lck;
	struct smb2_lock_element el[2];
	NTSTATUS status;
	char fname[256];
	bool ret = true;
	uint64_t lease;

	/*
	 * Choose a random name and random lease in case the state is left a
	 * little funky.
	 */
	lease = random();
	snprintf(fname, 256, "durable_open_lock_%s.dat", generate_random_str(tctx, 8));

	/* Clean slate */
	smb2_util_unlink(tree, fname);

	/* Create with lease */
	ZERO_STRUCT(io);
	io.in.security_flags		= 0x00;
	io.in.oplock_level		= SMB2_OPLOCK_LEVEL_LEASE;
	io.in.impersonation_level	= NTCREATEX_IMPERSONATION_IMPERSONATION;
	io.in.create_flags		= 0x00000000;
	io.in.reserved			= 0x00000000;
	io.in.desired_access		= SEC_RIGHTS_FILE_ALL;
	io.in.file_attributes		= FILE_ATTRIBUTE_NORMAL;
	io.in.share_access		= NTCREATEX_SHARE_ACCESS_READ |
					  NTCREATEX_SHARE_ACCESS_WRITE |
					  NTCREATEX_SHARE_ACCESS_DELETE;
	io.in.create_disposition	= NTCREATEX_DISP_OPEN_IF;
	io.in.create_options		= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
					  NTCREATEX_OPTIONS_ASYNC_ALERT	|
					  NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
					  0x00200000;
	io.in.fname			= fname;
	io.in.durable_open 		= true;

	ZERO_STRUCT(ls);
	ls.lease_key.data[0] = lease;
	ls.lease_key.data[1] = ~lease;
	ls.lease_state = SMB2_LEASE_READ|SMB2_LEASE_HANDLE|SMB2_LEASE_WRITE;
	io.in.lease_request = &ls;

	status = smb2_create(tree, mem_ctx, &io);
	CHECK_STATUS(status, NT_STATUS_OK);
	h = io.out.file.handle;
	CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);

	CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
	CHECK_VAL(io.out.lease_response.lease_key.data[0], lease);
	CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease);
	CHECK_VAL(io.out.lease_response.lease_state,
	    SMB2_LEASE_READ|SMB2_LEASE_HANDLE|SMB2_LEASE_WRITE);

	ZERO_STRUCT(lck);
	ZERO_STRUCT(el);
	lck.in.locks		= el;
	lck.in.lock_count	= 0x0001;
	lck.in.reserved		= 0x00000000;
	lck.in.file.handle	= h;
	el[0].offset		= 0;
	el[0].length		= 1;
	el[0].reserved		= 0x00000000;
	el[0].flags		= SMB2_LOCK_FLAG_EXCLUSIVE;
	status = smb2_lock(tree, &lck);
	CHECK_STATUS(status, NT_STATUS_OK);

	/* Disconnect/Reconnect. */
	talloc_free(tree);
	tree = NULL;

	if (!torture_smb2_connection(tctx, &tree)) {
		torture_warning(tctx, "couldn't reconnect, bailing\n");
		ret = false;
		goto done;
	}

	ZERO_STRUCT(io);
	io.in.fname = fname;
	io.in.durable_handle = &h;
	io.in.lease_request = &ls;

	status = smb2_create(tree, mem_ctx, &io);
	CHECK_STATUS(status, NT_STATUS_OK);
	h = io.out.file.handle;

	lck.in.file.handle	= h;
	el[0].flags		= SMB2_LOCK_FLAG_UNLOCK;
	status = smb2_lock(tree, &lck);
	CHECK_STATUS(status, NT_STATUS_OK);

 done:
	smb2_util_close(tree, h);
	smb2_util_unlink(tree, fname);

	return ret;
}