/**
 * 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;
}
Пример #2
0
static int net_registry_createkey(struct net_context *c, int argc,
				  const char **argv)
{
	WERROR werr;
	enum winreg_CreateAction action;
	char *subkeyname;
	struct registry_key *hivekey = NULL;
	struct registry_key *subkey = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	int ret = -1;

	if (argc != 1 || c->display_usage) {
		d_printf("%s\n%s",
			 _("Usage:"),
			 _("net registry createkey <path>\n"));
		d_printf("%s\n%s",
			 _("Example:"),
			 _("net registry createkey "
			   "'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_createkey(ctx, hivekey, subkeyname, REG_KEY_WRITE,
			     &subkey, &action);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, _("reg_createkey failed: %s\n"),
			  win_errstr(werr));
		goto done;
	}
	switch (action) {
		case REG_ACTION_NONE:
			d_printf(_("createkey did nothing -- huh?\n"));
			break;
		case REG_CREATED_NEW_KEY:
			d_printf(_("createkey created %s\n"), argv[0]);
			break;
		case REG_OPENED_EXISTING_KEY:
			d_printf(_("createkey opened existing %s\n"), argv[0]);
			break;
	}

	ret = 0;

done:
	TALLOC_FREE(ctx);
	return ret;
}
/**
 * Drop the whole configuration (restarting empty) - registry version
 */
static sbcErr smbconf_reg_drop(struct smbconf_ctx *ctx)
{
	char *path, *p;
	WERROR werr = WERR_OK;
	sbcErr err = SBC_ERR_OK;
	struct registry_key *parent_key = NULL;
	struct registry_key *new_key = NULL;
	TALLOC_CTX* mem_ctx = talloc_stackframe();
	enum winreg_CreateAction action;
	struct security_token *token;

	werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(1, ("Error creating admin token\n"));
		err = SBC_ERR_UNKNOWN_FAILURE;
		goto done;
	}

	path = talloc_strdup(mem_ctx, ctx->path);
	if (path == NULL) {
		err = SBC_ERR_NOMEM;
		goto done;
	}
	p = strrchr(path, '\\');
	if (p == NULL) {
		err = SBC_ERR_INVALID_PARAM;
		goto done;
	}
	*p = '\0';
	werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token,
			     &parent_key);
	if (!W_ERROR_IS_OK(werr)) {
		err = SBC_ERR_IO_FAILURE;
		goto done;
	}

	werr = reg_deletesubkeys_recursive(parent_key, p+1);
	if (!W_ERROR_IS_OK(werr)) {
		err = SBC_ERR_IO_FAILURE;
		goto done;
	}

	werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
			     &new_key, &action);
	if (!W_ERROR_IS_OK(werr)) {
		err = SBC_ERR_IO_FAILURE;
		goto done;
	}

done:
	talloc_free(mem_ctx);
	return err;
}
Пример #4
0
WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
                       uint32 desired_access,
                       const struct security_token *token,
                       enum winreg_CreateAction *paction,
                       struct registry_key **pkey)
{
    struct registry_key *hive;
    char *path, *p;
    WERROR err;

    if (!(path = SMB_STRDUP(orig_path))) {
        return WERR_NOMEM;
    }

    p = strchr(path, '\\');

    if ((p == NULL) || (p[1] == '\0')) {
        /*
         * No key behind the hive, just return the hive
         */

        err = reg_openhive(mem_ctx, path, desired_access, token,
                           &hive);
        if (!W_ERROR_IS_OK(err)) {
            SAFE_FREE(path);
            return err;
        }
        SAFE_FREE(path);
        *pkey = hive;
        *paction = REG_OPENED_EXISTING_KEY;
        return WERR_OK;
    }

    *p = '\0';

    err = reg_openhive(mem_ctx, path,
                       (strchr(p+1, '\\') != NULL) ?
                       KEY_ENUMERATE_SUB_KEYS : KEY_CREATE_SUB_KEY,
                       token, &hive);
    if (!W_ERROR_IS_OK(err)) {
        SAFE_FREE(path);
        return err;
    }

    err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
    SAFE_FREE(path);
    TALLOC_FREE(hive);
    return err;
}
Пример #5
0
WERROR gp_store_reg_subkey(TALLOC_CTX *mem_ctx,
			   const char *subkeyname,
			   struct registry_key *curr_key,
			   struct registry_key **new_key)
{
	enum winreg_CreateAction action = REG_ACTION_NONE;
	WERROR werr;

	werr = reg_createkey(mem_ctx, curr_key, subkeyname,
			     REG_KEY_WRITE, new_key, &action);
	if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
		return WERR_OK;
	}

	return werr;
}