예제 #1
0
파일: userman.c 프로젝트: rchicoli/samba
bool torture_useradd(struct torture_context *torture)
{
	NTSTATUS status;
	struct dcerpc_pipe *p;
	struct policy_handle h;
	struct lsa_String domain_name;
	struct dom_sid2 sid;
	const char *name = TEST_USERNAME;
	TALLOC_CTX *mem_ctx;
	bool ret = true;
	struct dcerpc_binding_handle *b;

	mem_ctx = talloc_init("test_useradd");

	status = torture_rpc_connection(torture,
					&p,
					&ndr_table_samr);

	torture_assert_ntstatus_ok(torture, status, "RPC connect failed");
	b = p->binding_handle;

	domain_name.string = lpcfg_workgroup(torture->lp_ctx);
	if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) {
		ret = false;
		goto done;
	}

	if (!test_useradd(torture, p, mem_ctx, &h, name)) {
		ret = false;
		goto done;
	}

	if (!test_user_cleanup(torture, b, mem_ctx, &h, name)) {
		ret = false;
		goto done;
	}

	if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) {
		ret = false;
		goto done;
	}

	if (!test_useradd_async(torture, p, mem_ctx, &h, name)) {
		ret = false;
		goto done;
	}

	if (!test_user_cleanup(torture, b, mem_ctx, &h, name)) {
		ret = false;
		goto done;
	}

done:
	talloc_free(mem_ctx);
	return ret;
}
예제 #2
0
파일: userman.c 프로젝트: rchicoli/samba
bool torture_usermod(struct torture_context *torture)
{
	NTSTATUS status;
	struct dcerpc_pipe *p;
	struct policy_handle h;
	struct lsa_String domain_name;
	struct dom_sid2 sid;
	uint32_t rid;
	int i;
	char *name;
	TALLOC_CTX *mem_ctx;
	bool ret = true;
	struct dcerpc_binding_handle *b;

	mem_ctx = talloc_init("test_userdel");

	status = torture_rpc_connection(torture,
					&p,
					&ndr_table_samr);

	torture_assert_ntstatus_ok(torture, status, "RPC connect");
	b = p->binding_handle;

	domain_name.string = lpcfg_workgroup(torture->lp_ctx);
	name = talloc_strdup(mem_ctx, TEST_USERNAME);

	if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) {
		ret = false;
		goto done;
	}

	if (!test_user_create(torture, b, mem_ctx, &h, name, &rid)) {
		ret = false;
		goto done;
	}

	for (i = USER_FIELD_FIRST; i <= USER_FIELD_LAST; i++) {
		struct libnet_rpc_usermod m;

		if (!test_usermod(torture, p, mem_ctx, &h, i, &m, &name)) {
			ret = false;
			goto cleanup;
		}

		if (!test_compare(torture, p, mem_ctx, &h, &m, name)) {
			ret = false;
			goto cleanup;
		}
	}

cleanup:
	if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
		ret = false;
		goto done;
	}

done:
	talloc_free(mem_ctx);
	return ret;
}
예제 #3
0
파일: utils.c 프로젝트: AIdrifter/samba
/**
 * Creates new user using SAMR
 *
 * @param name [in] Username for user to create
 * @param rid [out] If NULL, User's RID is not returned
 */
bool test_user_create(struct torture_context *tctx,
		      struct dcerpc_binding_handle *b,
		      TALLOC_CTX *mem_ctx,
		      struct policy_handle *domain_handle,
		      const char *name,
		      uint32_t *rid)
{
	struct policy_handle user_handle;
	struct lsa_String username;
	struct samr_CreateUser r;
	uint32_t user_rid;

	username.string = name;

	r.in.domain_handle = domain_handle;
	r.in.account_name  = &username;
	r.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
	r.out.user_handle  = &user_handle;
	/* return user's RID only if requested */
	r.out.rid 	   = rid ? rid : &user_rid;

	torture_comment(tctx, "creating user '%s'\n", username.string);

	torture_assert_ntstatus_ok(tctx,
				   dcerpc_samr_CreateUser_r(b, mem_ctx, &r),
				   "CreateUser RPC call failed");
	if (!NT_STATUS_IS_OK(r.out.result)) {
		torture_comment(tctx, "CreateUser failed - %s\n", nt_errstr(r.out.result));

		if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_USER_EXISTS)) {
			torture_comment(tctx,
			                "User (%s) already exists - "
			                "attempting to delete and recreate account again\n",
			                username.string);
			if (!test_user_cleanup(tctx, b, mem_ctx, domain_handle, username.string)) {
				return false;
			}

			torture_comment(tctx, "creating user account\n");

			torture_assert_ntstatus_ok(tctx,
						   dcerpc_samr_CreateUser_r(b, mem_ctx, &r),
						   "CreateUser RPC call failed");
			torture_assert_ntstatus_ok(tctx, r.out.result,
						   "CreateUser failed");

			/* be nice and close opened handles */
			test_samr_close_handle(tctx, b, mem_ctx, &user_handle);

			return true;
		}
		return false;
	}

	/* be nice and close opened handles */
	test_samr_close_handle(tctx, b, mem_ctx, &user_handle);

	return true;
}
예제 #4
0
파일: utils.c 프로젝트: endisd/samba
bool test_user_create(struct torture_context *tctx,
                      struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                      struct policy_handle *handle, const char *name,
                      uint32_t *rid)
{
    NTSTATUS status;
    struct lsa_String username;
    struct samr_CreateUser r;
    struct policy_handle user_handle;

    username.string = name;

    r.in.domain_handle = handle;
    r.in.account_name  = &username;
    r.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
    r.out.user_handle  = &user_handle;
    r.out.rid          = rid;

    torture_comment(tctx, "creating user account %s\n", name);

    status = dcerpc_samr_CreateUser(p, mem_ctx, &r);
    if (!NT_STATUS_IS_OK(status)) {
        printf("CreateUser failed - %s\n", nt_errstr(status));

        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
            torture_comment(tctx, "User (%s) already exists - attempting to delete and recreate account again\n", name);
            if (!test_user_cleanup(tctx, p, mem_ctx, handle, name)) {
                return false;
            }

            torture_comment(tctx, "creating user account\n");

            status = dcerpc_samr_CreateUser(p, mem_ctx, &r);
            torture_assert_ntstatus_ok(tctx, status, "CreateUser failed");
            return true;
        }
        return false;
    }

    return true;
}
예제 #5
0
파일: userinfo.c 프로젝트: AIdrifter/samba
bool torture_userinfo(struct torture_context *torture)
{
	NTSTATUS status;
	struct dcerpc_pipe *p;
	TALLOC_CTX *mem_ctx;
	bool ret = true;
	struct policy_handle h;
	struct lsa_String name;
	struct dom_sid2 sid;
	uint32_t rid;
	struct dcerpc_binding_handle *b;

	mem_ctx = talloc_init("test_userinfo");

	status = torture_rpc_connection(torture,
					&p,
					&ndr_table_samr);

	if (!NT_STATUS_IS_OK(status)) {
		return false;
	}
	b = p->binding_handle;

	name.string = lpcfg_workgroup(torture->lp_ctx);

	/*
	 * Testing synchronous version
	 */
	if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
		ret = false;
		goto done;
	}

	if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
		ret = false;
		goto done;
	}

	if (!test_userinfo(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
		ret = false;
		goto done;
	}

	if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
		ret = false;
		goto done;
	}

	/*
	 * Testing asynchronous version and monitor messages
	 */
	if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
		ret = false;
		goto done;
	}

	if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
		ret = false;
		goto done;
	}

	if (!test_userinfo_async(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
		ret = false;
		goto done;
	}

	if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
		ret = false;
		goto done;
	}

done:
	talloc_free(mem_ctx);

	return ret;
}