Exemple #1
0
bool torture_delshare(struct torture_context *torture)
{
	struct dcerpc_pipe *p;
	struct dcerpc_binding *binding;
	struct libnet_context* libnetctx;
	const char *host;
	NTSTATUS  status;
	bool ret = true;
	struct libnet_DelShare share;

	host = torture_setting_string(torture, "host", NULL);
	status = torture_rpc_binding(torture, &binding);
	torture_assert_ntstatus_ok(torture, status, "Failed to get binding");

	libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
	libnetctx->cred = popt_get_cmdline_credentials();

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

	torture_assert_ntstatus_ok(torture, status, "Failed to get rpc connection");

	if (!test_addshare(torture, p->binding_handle, torture, host, TEST_SHARENAME)) {
		return false;
	}

	share.in.server_name	= dcerpc_binding_get_string_option(binding, "host");
	share.in.share_name	= TEST_SHARENAME;

	status = libnet_DelShare(libnetctx, torture, &share);
	torture_assert_ntstatus_ok(torture, status, "Failed to delete share");

	return ret;
}
Exemple #2
0
bool torture_listshares(struct torture_context *torture)
{
	struct libnet_ListShares share;
	NTSTATUS  status;
	uint32_t levels[] = { 0, 1, 2, 501, 502 };
	int i;
	bool ret = true;
	struct libnet_context* libnetctx;
	struct dcerpc_binding *binding;
	TALLOC_CTX *mem_ctx;

	mem_ctx = talloc_init("test_listshares");
	status = torture_rpc_binding(torture, &binding);
	if (!NT_STATUS_IS_OK(status)) {
		ret = false;
		goto done;
	}

	libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
	if (!libnetctx) {
		torture_comment(torture, "Couldn't allocate libnet context\n");
		ret = false;
		goto done;
	}

	libnetctx->cred = popt_get_cmdline_credentials();

	torture_comment(torture, "Testing libnet_ListShare\n");

	share.in.server_name = dcerpc_binding_get_string_option(binding, "host");

	for (i = 0; i < ARRAY_SIZE(levels); i++) {
		share.in.level = levels[i];
		torture_comment(torture, "Testing libnet_ListShare level %u\n", share.in.level);

		status = libnet_ListShares(libnetctx, mem_ctx, &share);
		if (!NT_STATUS_IS_OK(status)) {
			torture_comment(torture, "libnet_ListShare level %u failed - %s\n", share.in.level, share.out.error_string);
			ret = false;
			goto done;
		}

		torture_comment(torture, "listing shares:\n");
		test_displayshares(torture, share);
	}

done:
	talloc_free(mem_ctx);
	return ret;
}
Exemple #3
0
bool torture_rpc_connect_srv(struct torture_context *torture)
{
	const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_SERVER;
	NTSTATUS status;
	struct dcerpc_binding *binding;
	const char *host;

	status = torture_rpc_binding(torture, &binding);
	if (!NT_STATUS_IS_OK(status)) {
		return false;
	}

	host = dcerpc_binding_get_string_option(binding, "host");

	return torture_rpc_connect(torture, level, NULL, host);
}
Exemple #4
0
_PUBLIC_ struct ndr_syntax_id dcerpc_binding_get_abstract_syntax(const struct dcerpc_binding *b)
{
	const char *s = dcerpc_binding_get_string_option(b, "abstract_syntax");
	bool ok;
	struct ndr_syntax_id id;

	if (s == NULL) {
		return ndr_syntax_id_null;
	}

	ok = ndr_syntax_id_from_string(s, &id);
	if (!ok) {
		return ndr_syntax_id_null;
	}

	return id;
}
Exemple #5
0
bool torture_domain_list(struct torture_context *torture)
{
	bool ret = true;
	NTSTATUS status;
	TALLOC_CTX *mem_ctx = NULL;
	struct dcerpc_binding *binding;
	struct libnet_context *ctx;
	struct libnet_DomainList r;
	int i;

	status = torture_rpc_binding(torture, &binding);
	if (!NT_STATUS_IS_OK(status)) {
		return false;
	}

	ctx = libnet_context_init(torture->ev, torture->lp_ctx);
	if (ctx == NULL) {
		torture_comment(torture, "failed to create libnet context\n");
		ret = false;
		goto done;
	}

	ctx->cred = cmdline_credentials;

	mem_ctx = talloc_init("torture_domain_close_samr");

	/*
	 * querying the domain list using default buffer size
	 */

	ZERO_STRUCT(r);
	r.in.hostname = dcerpc_binding_get_string_option(binding, "host");

	status = libnet_DomainList(ctx, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		ret = false;
		goto done;
	}

	torture_comment(torture, "Received list or domains (everything in one piece):\n");

	for (i = 0; i < r.out.count; i++) {
		torture_comment(torture, "Name[%d]: %s\n", i, r.out.domains[i].name);
	}

	/*
	 * querying the domain list using specified (much smaller) buffer size
	 */

	ctx->samr.buf_size = 32;

	ZERO_STRUCT(r);
	r.in.hostname = dcerpc_binding_get_string_option(binding, "host");

	status = libnet_DomainList(ctx, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		ret = false;
		goto done;
	}

	torture_comment(torture, "Received list or domains (collected in more than one round):\n");

	for (i = 0; i < r.out.count; i++) {
		torture_comment(torture, "Name[%d]: %s\n", i, r.out.domains[i].name);
	}

done:
	torture_comment(torture, "\nStatus: %s\n", nt_errstr(status));

	talloc_free(mem_ctx);
	talloc_free(ctx);
	return ret;
}
Exemple #6
0
static NTSTATUS torture_leave_ads_domain(struct torture_context *torture,
					 TALLOC_CTX *mem_ctx,
					 struct libnet_JoinDomain *libnet_r)
{
	int rtn;
	TALLOC_CTX *tmp_ctx;

	struct ldb_dn *server_dn;
	struct ldb_context *ldb_ctx;

	char *remote_ldb_url; 
	 
	/* Check if we are a domain controller. If not, exit. */
	if (!libnet_r->out.server_dn_str) {
		return NT_STATUS_OK;
	}

	tmp_ctx = talloc_named(mem_ctx, 0, "torture_leave temporary context");
	if (!tmp_ctx) {
		libnet_r->out.error_string = NULL;
		return NT_STATUS_NO_MEMORY;
	}

	ldb_ctx = ldb_init(tmp_ctx, torture->ev);
	if (!ldb_ctx) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	/* Remove CN=Servers,... entry from the AD. */ 
	server_dn = ldb_dn_new(tmp_ctx, ldb_ctx, libnet_r->out.server_dn_str);
	if (! ldb_dn_validate(server_dn)) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	remote_ldb_url = talloc_asprintf(tmp_ctx, "ldap://%s",
		dcerpc_binding_get_string_option(libnet_r->out.samr_binding, "host"));
	if (!remote_ldb_url) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	ldb_set_opaque(ldb_ctx, "credentials", cmdline_credentials);
	ldb_set_opaque(ldb_ctx, "loadparm", cmdline_lp_ctx);

	rtn = ldb_connect(ldb_ctx, remote_ldb_url, 0, NULL);
	if (rtn != LDB_SUCCESS) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_UNSUCCESSFUL;
	}

	rtn = ldb_delete(ldb_ctx, server_dn);
	if (rtn != LDB_SUCCESS) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_UNSUCCESSFUL;
	}

	DEBUG(0, ("%s removed successfully.\n", libnet_r->out.server_dn_str));

	talloc_free(tmp_ctx); 
	return NT_STATUS_OK;
}