Exemplo n.º 1
0
static bool test_get_includes(struct smbconf_ctx *ctx)
{
	WERROR werr;
	bool ret = false;
	uint32_t num_includes = 0;
	char **includes = NULL;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("TEST: get_includes\n");
	werr = smbconf_get_global_includes(ctx, mem_ctx,
					   &num_includes, &includes);
	if (!W_ERROR_IS_OK(werr)) {
		printf("FAIL: get_includes - %s\n", win_errstr(werr));
		goto done;
	}

	printf("got %u includes%s\n", num_includes,
	       (num_includes > 0) ? ":" : ".");
	print_strings("", num_includes, (const char **)includes);

	printf("OK: get_includes\n");
	ret = true;

done:
	talloc_free(mem_ctx);
	return ret;
}
Exemplo n.º 2
0
static bool torture_smbconf_reg(void)
{
	WERROR werr;
	bool ret = true;
	struct smbconf_ctx *conf_ctx = NULL;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("test: registry backend\n");

	printf("TEST: init\n");
	werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
	if (!W_ERROR_IS_OK(werr)) {
		printf("FAIL: init failed: %s\n", win_errstr(werr));
		ret = false;
		goto done;
	}
	printf("OK: init\n");

	ret &= test_get_includes(conf_ctx);
	ret &= test_set_get_includes(conf_ctx);
	ret &= test_delete_includes(conf_ctx);

	smbconf_shutdown(conf_ctx);

done:
	printf("%s: registry backend\n", ret ? "success" : "failure");
	talloc_free(mem_ctx);
	return ret;
}
Exemplo n.º 3
0
static struct registry_context *open_backend(poptContext pc,
					     struct tevent_context *ev_ctx,
					     struct loadparm_context *lp_ctx,
					     enum reg_backend backend,
					     const char *remote_host)
{
	WERROR error;
	struct registry_context *ctx;

	switch (backend) {
	case REG_UNKNOWN:
		poptPrintUsage(pc, stderr, 0);
		return NULL;
	case REG_LOCAL:
		error = reg_open_samba(NULL, &ctx, ev_ctx, lp_ctx, NULL, cmdline_credentials);
		break;
	case REG_REMOTE:
		error = reg_open_remote(&ctx, NULL, cmdline_credentials, lp_ctx,
					remote_host, ev_ctx);
		break;
	case REG_NULL:
		error = reg_open_local(NULL, &ctx);
		break;
	}

	if (!W_ERROR_IS_OK(error)) {
		fprintf(stderr, "Error: %s\n", win_errstr(error));
		return NULL;
	}

	return ctx;
}
Exemplo n.º 4
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_FlushFtTable(struct dcerpc_pipe *p,
			      TALLOC_CTX *mem_ctx,
			      const char *host,
			      const char *sharename)
{
	NTSTATUS status;
	struct dfs_FlushFtTable r;
	enum dfs_ManagerVersion version;

	printf("Testing FlushFtTable\n");

	if (!test_GetManagerVersion(p, mem_ctx, &version)) {
		return false;
	}

	r.in.servername = host;
	r.in.rootshare = sharename;

	status = dcerpc_dfs_FlushFtTable(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("FlushFtTable failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_FlushFtTable failed - %s\n",
			win_errstr(r.out.result));
		IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
		return false;
	}

	return true;
}
Exemplo n.º 5
0
const char *cli_errstr(struct cli_state *cli)
{   
	fstring cli_error_message;
	char *result;

	if (!cli->initialised) {
		fstrcpy(cli_error_message, "[Programmer's error] cli_errstr called on unitialized cli_stat struct!\n");
		goto done;
	}

	/* Case #1: RAP error */
	if (cli->rap_error) {
		strlcpy(cli_error_message, win_errstr(W_ERROR(cli->rap_error)),
			sizeof(cli_error_message));
		goto done;
	}

	if (!cli_state_is_connected(cli) && NT_STATUS_IS_OK(cli->raw_status)) {
		return nt_errstr(NT_STATUS_CONNECTION_DISCONNECTED);
	}

	return nt_errstr(cli->raw_status);
 done:
	result = talloc_strdup(talloc_tos(), cli_error_message);
	SMB_ASSERT(result);
	return result;
}
Exemplo n.º 6
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_AddStdRootForced(struct dcerpc_pipe *p,
				  TALLOC_CTX *mem_ctx,
				  const char *host,
				  const char *sharename)
{
	NTSTATUS status;
	struct dfs_AddStdRootForced r;
	enum dfs_ManagerVersion version;

	printf("Testing AddStdRootForced\n");

	if (!test_GetManagerVersion(p, mem_ctx, &version)) {
		return false;
	}

	r.in.servername	= host;
	r.in.rootshare	= sharename;
	r.in.comment	= "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
	r.in.store	= SMBTORTURE_DFS_PATHNAME;

	status = dcerpc_dfs_AddStdRootForced(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("AddStdRootForced failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_AddStdRootForced failed - %s\n",
			win_errstr(r.out.result));
		IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
		return false;
	}

	return test_RemoveStdRoot(p, mem_ctx, host, sharename);
}
Exemplo n.º 7
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_RemoveStdRoot(struct dcerpc_pipe *p,
			       TALLOC_CTX *mem_ctx,
			       const char *host,
			       const char *sharename)
{
	struct dfs_RemoveStdRoot r;
	NTSTATUS status;

	printf("Testing RemoveStdRoot\n");

	r.in.servername	= host;
	r.in.rootshare	= sharename;
	r.in.flags	= 0;

	status = dcerpc_dfs_RemoveStdRoot(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("RemoveStdRoot failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_RemoveStdRoot failed - %s\n",
			win_errstr(r.out.result));
		return false;
	}

	return true;
}
Exemplo n.º 8
0
static WERROR cmd_clusapi_get_cluster_name(struct rpc_pipe_client *cli,
					   TALLOC_CTX *mem_ctx,
					   int argc,
					   const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	WERROR error;
	const char *ClusterName;
	const char *NodeName;

	status = dcerpc_clusapi_GetClusterName(b, mem_ctx,
					       &ClusterName,
					       &NodeName,
					       &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (!W_ERROR_IS_OK(error)) {
		printf("error: %s\n", win_errstr(error));
		return error;
	}

	printf("ClusterName: %s\n", ClusterName);
	printf("NodeName: %s\n", NodeName);

	return WERR_OK;
}
/**
 * create a subkey of the base key (i.e. a service...)
 */
static sbcErr smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
					     struct smbconf_ctx *ctx,
					     const char * subkeyname,
					     struct registry_key **newkey)
{
	WERROR werr;
	sbcErr err = SBC_ERR_OK;
	TALLOC_CTX *create_ctx;
	enum winreg_CreateAction action = REG_ACTION_NONE;

	/* create a new talloc ctx for creation. it will hold
	 * the intermediate parent key (SMBCONF) for creation
	 * and will be destroyed when leaving this function... */
	create_ctx = talloc_stackframe();

	werr = reg_createkey(mem_ctx, rpd(ctx)->base_key, subkeyname,
			     REG_KEY_WRITE, newkey, &action);
	if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
		DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
		err = SBC_ERR_FILE_EXISTS;
	}
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(5, ("Error creating key %s: %s\n",
			 subkeyname, win_errstr(werr)));
		err = SBC_ERR_UNKNOWN_FAILURE;
	}

	talloc_free(create_ctx);
	return err;
}
Exemplo n.º 10
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_GetDcAddress(struct dcerpc_pipe *p,
			      TALLOC_CTX *mem_ctx,
			      const char *host)
{
	NTSTATUS status;
	struct dfs_GetDcAddress r;
	uint8_t is_root = 0;
	uint32_t ttl = 0;
	const char *ptr;

	printf("Testing GetDcAddress\n");

	ptr = host;

	r.in.servername = host;
	r.in.server_fullname = r.out.server_fullname = &ptr;
	r.in.is_root = r.out.is_root = &is_root;
	r.in.ttl = r.out.ttl = &ttl;

	status = dcerpc_dfs_GetDcAddress(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("GetDcAddress failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_GetDcAddress failed - %s\n",
			win_errstr(r.out.result));
		return false;
	}

	return true;
}
Exemplo n.º 11
0
static int net_registry_enumerate_recursive(struct net_context *c, int argc,
					    const char **argv)
{
	WERROR werr;
	struct registry_key *key = NULL;
	char* name = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	int ret = -1;

	if (argc != 1 || c->display_usage) {
		d_printf("%s\n%s",
			 _("Usage:"),
			 _("net registry enumerate <path>\n"));
		d_printf("%s\n%s",
			 _("Example:"),
			 _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
		goto done;
	}

	werr = open_hive(ctx, argv[0], REG_KEY_READ, &key, &name);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
		goto done;
	}

	werr = registry_enumkey(key, name, true);
	if (W_ERROR_IS_OK(werr)) {
		ret = 0;
	}
done:
	TALLOC_FREE(ctx);
	return ret;
}
Exemplo n.º 12
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_SetDcAddress(struct dcerpc_pipe *p,
			      TALLOC_CTX *mem_ctx,
			      const char *host)
{
	NTSTATUS status;
	struct dfs_SetDcAddress r;

	printf("Testing SetDcAddress\n");

	r.in.servername = host;
	r.in.server_fullname = host;
	r.in.flags = 0;
	r.in.ttl = 1000;

	status = dcerpc_dfs_SetDcAddress(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("SetDcAddress failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_SetDcAddress failed - %s\n",
			win_errstr(r.out.result));
		return false;
	}

	return true;
}
Exemplo n.º 13
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_AddStdRoot(struct dcerpc_pipe *p,
			    TALLOC_CTX *mem_ctx,
			    const char *host,
			    const char *sharename)
{
	NTSTATUS status;
	struct dfs_AddStdRoot r;

	printf("Testing AddStdRoot\n");

	r.in.servername	= host;
	r.in.rootshare	= sharename;
	r.in.comment	= "standard dfs standalone DFS root created by smbtorture (dfs_AddStdRoot)";
	r.in.flags	= 0;

	status = dcerpc_dfs_AddStdRoot(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("AddStdRoot failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_AddStdRoot failed - %s\n",
			win_errstr(r.out.result));
		return false;
	}

	return true;
}
Exemplo n.º 14
0
/**
 * delete all values from a key
 */
static sbcErr smbconf_reg_delete_values(struct registry_key *key)
{
	WERROR werr;
	sbcErr err;
	char *valname;
	struct registry_value *valvalue;
	uint32_t count;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	for (count = 0;
	     werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue),
	     W_ERROR_IS_OK(werr);
	     count++)
	{
		werr = reg_deletevalue(key, valname);
		if (!W_ERROR_IS_OK(werr)) {
			err = SBC_ERR_ACCESS_DENIED;
			goto done;
		}
	}
	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
		DEBUG(1, ("smbconf_reg_delete_values: "
			  "Error enumerating values of %s: %s\n",
			  key->key->name,
			  win_errstr(werr)));
		err = SBC_ERR_ACCESS_DENIED;
		goto done;
	}

	err = SBC_ERR_OK;

done:
	talloc_free(mem_ctx);
	return err;
}
Exemplo n.º 15
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_GetInfoLevel(struct dcerpc_pipe *p,
			      TALLOC_CTX *mem_ctx,
			      uint16_t level,
			      const char *root)
{
	NTSTATUS status;
	struct dfs_GetInfo r;
	union dfs_Info info;

	printf("Testing GetInfo level %u on '%s'\n", level, root);

	r.in.dfs_entry_path = talloc_strdup(mem_ctx, root);
	r.in.servername = NULL;
	r.in.sharename = NULL;
	r.in.level = level;
	r.out.info = &info;

	status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("GetInfo failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result) &&
		   !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
		printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
		return false;
	}

	return true;
}
Exemplo n.º 16
0
BOOL test_DsRoleGetPrimaryDomainInformation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
{
	struct dssetup_DsRoleGetPrimaryDomainInformation r;
	NTSTATUS status;
	BOOL ret = True;
	int i;

	printf("\ntesting DsRoleGetPrimaryDomainInformation\n");

	for (i=DS_ROLE_BASIC_INFORMATION; i <= DS_ROLE_OP_STATUS; i++) {
		r.in.level = i;

		status = dcerpc_dssetup_DsRoleGetPrimaryDomainInformation(p, mem_ctx, &r);
		if (!NT_STATUS_IS_OK(status)) {
			const char *errstr = nt_errstr(status);
			if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
				errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
			}
			printf("dcerpc_dssetup_DsRoleGetPrimaryDomainInformation level %d failed - %s\n",
				i, errstr);
			ret = False;
		} else if (!W_ERROR_IS_OK(r.out.result)) {
			printf("DsRoleGetPrimaryDomainInformation level %d failed - %s\n",
				i, win_errstr(r.out.result));
			ret = False;
		}
	}

	return ret;
}
Exemplo n.º 17
0
Arquivo: dfs.c Projeto: AllardJ/Tomato
static bool test_ManagerInitialize(struct dcerpc_pipe *p,
				   TALLOC_CTX *mem_ctx,
				   const char *host)
{
	NTSTATUS status;
	enum dfs_ManagerVersion version;
	struct dfs_ManagerInitialize r;

	printf("Testing ManagerInitialize\n");

	if (!test_GetManagerVersion(p, mem_ctx, &version)) {
		return false;
	}

	r.in.servername = host;
	r.in.flags = 0;

	status = dcerpc_dfs_ManagerInitialize(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("ManagerInitialize failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		printf("dfs_ManagerInitialize failed - %s\n",
			win_errstr(r.out.result));
		IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
		return false;
	}

	return true;
}
Exemplo n.º 18
0
static WERROR cmd_ls(struct regshell_context *ctx, int argc, char **argv)
{
	unsigned int i;
	WERROR error;
	uint32_t valuetype;
	DATA_BLOB valuedata;
	const char *name = NULL;

	for (i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(ctx,
								      ctx->current,
								      i,
								      &name,
								      NULL,
								      NULL)); i++) {
		printf("K %s\n", name);
	}

	if (!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
		fprintf(stderr, "Error occurred while browsing through keys: %s\n",
			win_errstr(error));
		return error;
	}

	for (i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(ctx,
		ctx->current, i, &name, &valuetype, &valuedata)); i++)
		printf("V \"%s\" %s %s\n", name, str_regtype(valuetype),
			   reg_val_data_string(ctx, valuetype, valuedata));

	return WERR_OK;
}
Exemplo n.º 19
0
static WERROR cmd_ck(struct regshell_context *ctx, int argc, char **argv)
{
	struct registry_key *nkey = NULL;
	char *full_path;
	WERROR error;

	if(argc == 2) {
		if (!W_ERROR_IS_OK(get_full_path(ctx, argv[1], &full_path))) {
			fprintf(stderr, "Unable to parse the supplied path\n");
			return WERR_INVALID_PARAM;
		}
		error = reg_open_key(ctx->registry, ctx->root, full_path,
				     &nkey);
		if(!W_ERROR_IS_OK(error)) {
			DEBUG(0, ("Error opening specified key: %s\n",
				win_errstr(error)));
			return error;
		}

		talloc_free(ctx->path);
		ctx->path = full_path;

		ctx->current = nkey;
	}
	printf("New path is: %s\\%s\n", ctx->predef?ctx->predef:"", ctx->path);

	return WERR_OK;
}
Exemplo n.º 20
0
int main(int argc, char **argv)
{
	int opt;
	poptContext pc;
	char *outputfile = NULL;
	struct registry_context *h1 = NULL, *h2 = NULL;
	int from_null = 0;
	WERROR error;
	struct reg_diff *diff;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
		{"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL },
		{"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL },
		{"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL },
		POPT_COMMON_SAMBA
		POPT_COMMON_CREDENTIALS
		POPT_COMMON_VERSION
		{ NULL }
	};

	registry_init();

	pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);

	while((opt = poptGetNextOpt(pc)) != -1) {
		error = WERR_OK;
		switch(opt)	{
		case 'L':
			if (!h1 && !from_null) error = reg_open_local(NULL, &h1, NULL, cmdline_credentials);
			else if (!h2) error = reg_open_local(NULL, &h2, NULL, cmdline_credentials);
			break;
		case 'R':
			if (!h1 && !from_null) 
				error = reg_open_remote(&h1, NULL, cmdline_credentials, 
							poptGetOptArg(pc), NULL);
			else if (!h2) error = reg_open_remote(&h2, NULL, cmdline_credentials, 
							      poptGetOptArg(pc), NULL);
			break;
		}

		if (!W_ERROR_IS_OK(error)) {
			fprintf(stderr, "Error: %s\n", win_errstr(error));
			return 1;
		}
	}

	poptFreeContext(pc);

	diff = reg_generate_diff(NULL, h1, h2);
	if (!diff) {
		fprintf(stderr, "Unable to generate diff between keys\n");
		return -1;
	}

	reg_diff_save(diff, outputfile);

	return 0;
}
Exemplo n.º 21
0
/**
 * Multi-pass working schema creation
 * Function will:
 *  - shallow copy initial schema supplied
 *  - create a working schema in multiple passes
 *    until all objects are resolved
 * Working schema is a schema with Attributes, Classes
 * and indexes, but w/o subClassOf, possibleSupperiors etc.
 * It is to be used just us cache for converting attribute values.
 */
WERROR dsdb_repl_make_working_schema(struct ldb_context *ldb,
				     const struct dsdb_schema *initial_schema,
				     const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
				     uint32_t object_count,
				     const struct drsuapi_DsReplicaObjectListItemEx *first_object,
				     const DATA_BLOB *gensec_skey,
				     TALLOC_CTX *mem_ctx,
				     struct dsdb_schema **_schema_out)
{
	WERROR werr;
	struct dsdb_schema_prefixmap *pfm_remote;
	struct dsdb_schema *working_schema;

	/* make a copy of the iniatial_scheam so we don't mess with it */
	working_schema = dsdb_schema_copy_shallow(mem_ctx, ldb, initial_schema);
	if (!working_schema) {
		DEBUG(0,(__location__ ": schema copy failed!\n"));
		return WERR_NOMEM;
	}

	/* we are going to need remote prefixMap for decoding */
	werr = dsdb_schema_pfm_from_drsuapi_pfm(mapping_ctr, true,
						mem_ctx, &pfm_remote, NULL);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0,(__location__ ": Failed to decode remote prefixMap: %s",
			 win_errstr(werr)));
		return werr;
	}

	werr = dsdb_repl_resolve_working_schema(ldb, mem_ctx,
						pfm_remote,
						0, /* cycle_before_switching */
						working_schema,
						working_schema,
						object_count,
						first_object);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0, ("%s: dsdb_repl_resolve_working_schema() failed: %s",
			  __location__, win_errstr(werr)));
		return werr;
	}

	*_schema_out = working_schema;

	return WERR_OK;
}
Exemplo n.º 22
0
const char *svcctl_get_string_value(TALLOC_CTX *mem_ctx,
				    struct messaging_context *msg_ctx,
				    const struct auth_session_info *session_info,
				    const char *key_name,
				    const char *value_name)
{
	struct dcerpc_binding_handle *h = NULL;
	uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
	struct policy_handle hive_hnd, key_hnd;
	const char *data = NULL;
	char *path = NULL;
	TALLOC_CTX *tmp_ctx;
	NTSTATUS status;
	WERROR result = WERR_OK;

	tmp_ctx = talloc_stackframe();
	if (tmp_ctx == NULL) {
		return NULL;
	}

	path = talloc_asprintf(tmp_ctx, "%s\\%s",
					TOP_LEVEL_SERVICES_KEY, key_name);
	if (path == NULL) {
		goto done;
	}

	status = dcerpc_winreg_int_hklm_openkey(tmp_ctx,
						session_info,
						msg_ctx,
						&h,
						path,
						false,
						access_mask,
						&hive_hnd,
						&key_hnd,
						&result);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(2, ("svcctl_get_string_value: Could not open %s - %s\n",
			  path, nt_errstr(status)));
		goto done;
	}
	if (!W_ERROR_IS_OK(result)) {
		DEBUG(2, ("svcctl_get_string_value: Could not open %s - %s\n",
			  path, win_errstr(result)));
		goto done;
	}

	status = dcerpc_winreg_query_sz(mem_ctx,
					h,
					&key_hnd,
					value_name,
					&data,
					&result);

done:
	talloc_free(tmp_ctx);
	return data;
}
Exemplo n.º 23
0
static sbcErr smbconf_reg_set_multi_sz_value(struct registry_key *key,
					     const char *valname,
					     const uint32_t num_strings,
					     const char **strings)
{
	WERROR werr;
	sbcErr err = SBC_ERR_OK;
	struct registry_value *value;
	uint32_t count;
	TALLOC_CTX *tmp_ctx = talloc_stackframe();
	const char **array;

	if (strings == NULL) {
		err = SBC_ERR_INVALID_PARAM;
		goto done;
	}

	array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1);
	if (array == NULL) {
		err = SBC_ERR_NOMEM;
		goto done;
	}

	value = talloc_zero(tmp_ctx, struct registry_value);
	if (value == NULL) {
		err = SBC_ERR_NOMEM;
		goto done;
	}

	value->type = REG_MULTI_SZ;

	for (count = 0; count < num_strings; count++) {
		array[count] = talloc_strdup(value, strings[count]);
		if (array[count] == NULL) {
			err = SBC_ERR_NOMEM;
			goto done;
		}
	}

	if (!push_reg_multi_sz(value, &value->data, array)) {
		err = SBC_ERR_NOMEM;
		goto done;
	}

	werr = reg_setvalue(key, valname, value);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
			  valname, key->key->name, win_errstr(werr)));
		err = SBC_ERR_ACCESS_DENIED;
	}

done:
	talloc_free(tmp_ctx);
	return err;
}
Exemplo n.º 24
0
int main(int argc, const char **argv)
{
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		/* ... */
		POPT_COMMON_SAMBA
		POPT_COMMON_CONNECTION
		POPT_COMMON_CREDENTIALS
		POPT_TABLEEND
	};
	int opt;
	poptContext pc;
	struct user_auth_info *auth_info;
	TALLOC_CTX *frame;
	struct registry_context *ctx;
	WERROR rv;

	frame = talloc_stackframe();

	setup_logging("regedit", DEBUG_DEFAULT_STDERR);
	lp_set_cmdline("log level", "0");

	/* process options */
	auth_info = user_auth_info_init(frame);
	if (auth_info == NULL) {
		exit(1);
	}
	popt_common_set_auth_info(auth_info);
	pc = poptGetContext("regedit", argc, argv, long_options, 0);

	while ((opt = poptGetNextOpt(pc)) != -1) {
		/* TODO */
	}

	if (!lp_load_global(get_dyn_CONFIGFILE())) {
		DEBUG(0, ("ERROR loading config file...\n"));
		exit(1);
	}

	rv = reg_open_samba3(frame, &ctx);
	if (!W_ERROR_IS_OK(rv)) {
		fprintf(stderr, "Unable to open registry: %s\n",
			win_errstr(rv));
		TALLOC_FREE(frame);

		return 1;
	}

	display_window(frame, ctx);

	TALLOC_FREE(frame);

	return 0;
}
Exemplo n.º 25
0
static int net_registry_enumerate(struct net_context *c, int argc,
				  const char **argv)
{
	WERROR werr;
	struct registry_key *key = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	char *subkey_name;
	NTTIME modtime;
	uint32_t count;
	char *valname = NULL;
	struct registry_value *valvalue = NULL;
	int ret = -1;

	if (argc != 1 || c->display_usage) {
		d_printf("Usage:    net registry enumerate <path>\n");
		d_printf("Example:  net registry enumerate "
			 "'HKLM\\Software\\Samba'\n");
		goto done;
	}

	werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
		goto done;
	}

	for (count = 0;
	     werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
	     W_ERROR_IS_OK(werr);
	     count++)
	{
		print_registry_key(subkey_name, &modtime);
	}
	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
		goto done;
	}

	for (count = 0;
	     werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
	     W_ERROR_IS_OK(werr);
	     count++)
	{
		print_registry_value_with_name(valname, valvalue);
	}
	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
		goto done;
	}

	ret = 0;
done:
	TALLOC_FREE(ctx);
	return ret;
}
Exemplo n.º 26
0
static WERROR cmd_clusapi_open_cluster(struct rpc_pipe_client *cli,
				       TALLOC_CTX *mem_ctx,
				       int argc,
				       const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	WERROR error;
	struct policy_handle Cluster;

	status = dcerpc_clusapi_OpenCluster(b, mem_ctx,
					    &error,
					    &Cluster);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (!W_ERROR_IS_OK(error)) {
		printf("error: %s\n", win_errstr(error));
		return error;
	}

	printf("successfully opened cluster\n");

	status = dcerpc_clusapi_CloseCluster(b, mem_ctx,
					     &Cluster,
					     &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (!W_ERROR_IS_OK(error)) {
		printf("error: %s\n", win_errstr(error));
		return error;
	}

	printf("successfully closed cluster\n");

	return WERR_OK;
}
Exemplo n.º 27
0
const char *get_friendly_werror_msg(WERROR werror)
{
    int i = 0;

    for (i = 0; i < ARRAY_SIZE(dos_err_strs); i++) {
        if (W_ERROR_V(dos_err_strs[i].werror) ==
                W_ERROR_V(werror)) {
            return dos_err_strs[i].friendly_errstr;
        }
    }

    return win_errstr(werror);
}
Exemplo n.º 28
0
/*
  turn a WERROR into a MprVar object with lots of funky properties
*/
struct MprVar mprWERROR(WERROR status)
{
	struct MprVar res;

	res = mprObject("werror");

	mprSetVar(&res, "errstr", mprString(win_errstr(status)));
	mprSetVar(&res, "v", mprCreateIntegerVar(W_ERROR_V(status)));
	mprSetVar(&res, "is_ok", mprCreateBoolVar(W_ERROR_IS_OK(status)));
	mprSetVar(&res, "is_err", mprCreateBoolVar(!W_ERROR_IS_OK(status)));

	return res;
}
Exemplo n.º 29
0
static int net_registry_deletekey(struct net_context *c, int argc,
				  const char **argv)
{
	WERROR werr;
	char *subkeyname;
	struct registry_key *hivekey = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	int ret = -1;

	if (argc != 1 || c->display_usage) {
		d_printf("Usage:    net registry deletekey <path>\n");
		d_printf("Example:  net registry deletekey "
			 "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n");
		goto done;
	}
	if (strlen(argv[0]) == 0) {
		d_fprintf(stderr, "error: zero length key name given\n");
		goto done;
	}

	werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, "open_hive failed: %s\n", win_errstr(werr));
		goto done;
	}

	werr = reg_deletekey(hivekey, subkeyname);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, "reg_deletekey failed: %s\n",
			  win_errstr(werr));
		goto done;
	}

	ret = 0;

done:
	TALLOC_FREE(ctx);
	return ret;
}
Exemplo n.º 30
0
static WERROR cmd_clusapi_open_resource(struct rpc_pipe_client *cli,
					TALLOC_CTX *mem_ctx,
					int argc,
					const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	const char *lpszResourceName = "Cluster Name";
	WERROR Status;
	struct policy_handle hResource;
	WERROR rpc_status, ignore;

	if (argc >= 2) {
		lpszResourceName = argv[1];
	}

	status = dcerpc_clusapi_OpenResource(b, mem_ctx,
					     lpszResourceName,
					     &Status,
					     &rpc_status,
					     &hResource);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (!W_ERROR_IS_OK(Status)) {
		printf("Status: %s\n", win_errstr(Status));
		return Status;
	}

	printf("rpc_status: %s\n", win_errstr(rpc_status));

	dcerpc_clusapi_CloseResource(b, mem_ctx,
				     &hResource,
				     &ignore);

	return WERR_OK;
}