Exemplo n.º 1
0
static void add_reg_key(struct regedit *regedit, struct tree_node *node,
			bool subkey)
{
	char *name;
	const char *msg;

	if (!subkey && !node->parent) {
		return;
	}

	msg = "Enter name of new key";
	if (subkey) {
		msg = "Enter name of new subkey";
	}
	dialog_input(regedit, &name, "New Key", msg);
	if (name) {
		WERROR rv;
		struct registry_key *new_key;
		struct tree_node *new_node;
		struct tree_node *list;
		struct tree_node *parent;

		if (subkey) {
			parent = node;
			list = node->child_head;
		} else {
			parent = node->parent;
			list = tree_node_first(node);
			SMB_ASSERT(list != NULL);
		}
		rv = reg_key_add_name(regedit, parent->key, name,
				      NULL, NULL, &new_key);
		if (W_ERROR_IS_OK(rv)) {
			/* The list of subkeys may not be present in
			   cache yet, so if not, don't bother allocating
			   a new node for the key. */
			if (list) {
				new_node = tree_node_new(parent, parent,
							 name, new_key);
				SMB_ASSERT(new_node);
				tree_node_append_last(list, new_node);
			}

			list = tree_node_first(node);
			tree_view_clear(regedit->keys);
			tree_view_update(regedit->keys, list);
		} else {
			dialog_notice(regedit, DIA_ALERT, "New Key",
				      "Failed to create key.");
		}
		talloc_free(name);
	}
}
Exemplo n.º 2
0
static void handle_value_input(struct regedit *regedit, int c)
{
	struct value_item *vitem;
	bool binmode = false;

	switch (c) {
	case KEY_DOWN:
		menu_driver(regedit->vl->menu, REQ_DOWN_ITEM);
		break;
	case KEY_UP:
		menu_driver(regedit->vl->menu, REQ_UP_ITEM);
		break;
	case 'b':
	case 'B':
		binmode = true;
		/* Falthrough... */
	case '\n':
	case KEY_ENTER:
		vitem = item_userptr(current_item(regedit->vl->menu));
		if (vitem) {
			struct tree_node *node;
			node = item_userptr(current_item(regedit->keys->menu));
			dialog_edit_value(regedit, node->key, vitem->type,
					  vitem, binmode);
			value_list_load(regedit->vl, node->key);
		}
		break;
	case 'n':
	case 'N': {
		int new_type;
		int sel;

		sel = dialog_select_type(regedit, &new_type);
		if (sel == DIALOG_OK) {
			struct tree_node *node;
			node = item_userptr(current_item(regedit->keys->menu));
			dialog_edit_value(regedit, node->key, new_type, NULL,
					  false);
			value_list_load(regedit->vl, node->key);
		}
		break;
	}
	case 'd':
	case 'D':
		vitem = item_userptr(current_item(regedit->vl->menu));
		if (vitem) {
			int sel;

			sel = dialog_notice(regedit, DIA_CONFIRM,
					    "Delete Value",
					     "Really delete value \"%s\"?",
					     vitem->value_name);
			if (sel == DIALOG_OK) {
				ITEM *it = current_item(regedit->keys->menu);
				struct tree_node *node = item_userptr(it);
				reg_del_value(regedit, node->key,
					      vitem->value_name);
				value_list_load(regedit->vl, node->key);
			}
		}
		break;
	}

	value_list_show(regedit->vl);
}
Exemplo n.º 3
0
static void handle_tree_input(struct regedit *regedit, int c)
{
	struct tree_node *node;

	switch (c) {
	case KEY_DOWN:
		menu_driver(regedit->keys->menu, REQ_DOWN_ITEM);
		load_values(regedit);
		break;
	case KEY_UP:
		menu_driver(regedit->keys->menu, REQ_UP_ITEM);
		load_values(regedit);
		break;
	case '\n':
	case KEY_ENTER:
	case KEY_RIGHT:
		node = item_userptr(current_item(regedit->keys->menu));
		if (node && tree_node_has_children(node)) {
			tree_node_load_children(node);
			print_path(regedit, node->child_head);
			tree_view_update(regedit->keys, node->child_head);
			value_list_load(regedit->vl, node->child_head->key);
		}
		break;
	case KEY_LEFT:
		node = item_userptr(current_item(regedit->keys->menu));
		if (node && node->parent) {
			print_path(regedit, node->parent);
			node = tree_node_first(node->parent);
			tree_view_update(regedit->keys, node);
			value_list_load(regedit->vl, node->key);
		}
		break;
	case 'n':
	case 'N':
		node = item_userptr(current_item(regedit->keys->menu));
		add_reg_key(regedit, node, false);
		break;
	case 's':
	case 'S':
		node = item_userptr(current_item(regedit->keys->menu));
		add_reg_key(regedit, node, true);
		break;
	case 'd':
	case 'D': {
		int sel;

		node = item_userptr(current_item(regedit->keys->menu));
		if (!node->parent) {
			break;
		}
		sel = dialog_notice(regedit, DIA_CONFIRM,
				    "Delete Key",
				     "Really delete key \"%s\"?",
				     node->name);
		if (sel == DIALOG_OK) {
			WERROR rv;
			struct tree_node *pop;
			struct tree_node *parent = node->parent;

			rv = reg_key_del(node, parent->key, node->name);
			if (W_ERROR_IS_OK(rv)) {
				tree_view_clear(regedit->keys);
				pop = tree_node_pop(&node);
				tree_node_free_recursive(pop);
				node = parent->child_head;
				if (node == NULL) {
					node = tree_node_first(parent);
					print_path(regedit, node);
				}
				tree_view_update(regedit->keys, node);
				value_list_load(regedit->vl, node->key);
			} else {
				dialog_notice(regedit, DIA_ALERT, "Delete Key",
					      "Failed to delete key.");
			}
		}
		break;
	}
	}

	tree_view_show(regedit->keys);
	value_list_show(regedit->vl);
}
static void handle_value_input(struct regedit *regedit, int c)
{
	struct value_item *vitem;
	bool binmode = false;
	WERROR err;
	int sel;

	switch (c) {
	case KEY_DOWN:
		value_list_driver(regedit->vl, ML_CURSOR_DOWN);
		break;
	case KEY_UP:
		value_list_driver(regedit->vl, ML_CURSOR_UP);
		break;
	case KEY_NPAGE:
		value_list_driver(regedit->vl, ML_CURSOR_PGDN);
		break;
	case KEY_PPAGE:
		value_list_driver(regedit->vl, ML_CURSOR_PGUP);
		break;
	case KEY_HOME:
		value_list_driver(regedit->vl, ML_CURSOR_HOME);
		break;
	case KEY_END:
		value_list_driver(regedit->vl, ML_CURSOR_END);
		break;
	case 'b':
	case 'B':
		binmode = true;
		/* Falthrough... */
	case '\n':
	case KEY_ENTER:
		vitem = value_list_get_current_item(regedit->vl);
		if (vitem) {
			struct tree_node *node;
			const char *name = NULL;
			node = tree_view_get_current_node(regedit->keys);
			sel = dialog_edit_value(regedit, node->key, vitem->type,
					        vitem, binmode, &err, &name);
			if (!W_ERROR_IS_OK(err)) {
				const char *msg = get_friendly_werror_msg(err);
				dialog_notice(regedit, DIA_ALERT, "Error",
					      "Error editing value:\n%s", msg);
			} else if (sel == DIALOG_OK) {
				tree_node_reopen_key(regedit->registry_context,
						     node);
				value_list_load(regedit->vl, node->key);
				value_list_set_current_item_by_name(regedit->vl,
								    name);
				talloc_free(discard_const(name));
			}
		}
		break;
	case 'n':
	case 'N': {
		int new_type;

		sel = dialog_select_type(regedit, &new_type);
		if (sel == DIALOG_OK) {
			struct tree_node *node;
			const char *name = NULL;
			node = tree_view_get_current_node(regedit->keys);
			sel = dialog_edit_value(regedit, node->key, new_type,
						NULL, false, &err, &name);
			if (!W_ERROR_IS_OK(err)) {
				const char *msg = get_friendly_werror_msg(err);
				dialog_notice(regedit, DIA_ALERT, "Error",
					      "Error creating value:\n%s", msg);
			} else if (sel == DIALOG_OK) {
				tree_node_reopen_key(regedit->registry_context,
						     node);
				value_list_load(regedit->vl, node->key);
				value_list_set_current_item_by_name(regedit->vl,
								    name);
				talloc_free(discard_const(name));
			}
		}
		break;
	}
	case 'd':
	case 'D':
		vitem = value_list_get_current_item(regedit->vl);
		if (vitem) {
			sel = dialog_notice(regedit, DIA_CONFIRM,
					    "Delete Value",
					     "Really delete value \"%s\"?",
					     vitem->value_name);
			if (sel == DIALOG_OK) {
				struct tree_node *node;
				node = tree_view_get_current_node(regedit->keys);
				reg_del_value(regedit, node->key,
					      vitem->value_name);
				tree_node_reopen_key(regedit->registry_context,
						     node);
				value_list_load(regedit->vl, node->key);
			}
		}
		break;
	}

	value_list_show(regedit->vl);
}
static void handle_tree_input(struct regedit *regedit, int c)
{
	struct tree_node *node;

	switch (c) {
	case KEY_DOWN:
		tree_view_driver(regedit->keys, ML_CURSOR_DOWN);
		load_values(regedit);
		break;
	case KEY_UP:
		tree_view_driver(regedit->keys, ML_CURSOR_UP);
		load_values(regedit);
		break;
	case KEY_NPAGE:
		tree_view_driver(regedit->keys, ML_CURSOR_PGDN);
		load_values(regedit);
		break;
	case KEY_PPAGE:
		tree_view_driver(regedit->keys, ML_CURSOR_PGUP);
		load_values(regedit);
		break;
	case KEY_HOME:
		tree_view_driver(regedit->keys, ML_CURSOR_HOME);
		load_values(regedit);
		break;
	case KEY_END:
		tree_view_driver(regedit->keys, ML_CURSOR_END);
		load_values(regedit);
		break;
	case '\n':
	case KEY_ENTER:
	case KEY_RIGHT:
		node = tree_view_get_current_node(regedit->keys);
		if (node && tree_node_has_children(node)) {
			WERROR rv;

			rv = tree_node_load_children(node);
			if (W_ERROR_IS_OK(rv)) {
				print_path(regedit, node->child_head);
				tree_view_update(regedit->keys, node->child_head);
				value_list_load(regedit->vl, node->child_head->key);
			} else {
				const char *msg = get_friendly_werror_msg(rv);
				dialog_notice(regedit, DIA_ALERT, "Loading Subkeys",
					      "Failed to load subkeys: %s", msg);
			}
		}
		break;
	case KEY_LEFT:
		node = tree_view_get_current_node(regedit->keys);
		if (node && !tree_node_is_top_level(node)) {
			print_path(regedit, node->parent);
			node = node->parent;
			tree_view_update(regedit->keys, tree_node_first(node));
			tree_view_set_current_node(regedit->keys, node);
			value_list_load(regedit->vl, node->key);
		}
		break;
	case 'n':
	case 'N':
		node = tree_view_get_current_node(regedit->keys);
		add_reg_key(regedit, node, false);
		break;
	case 's':
	case 'S':
		node = tree_view_get_current_node(regedit->keys);
		add_reg_key(regedit, node, true);
		break;
	case 'd':
	case 'D': {
		int sel;

		node = tree_view_get_current_node(regedit->keys);
		if (tree_node_is_top_level(node)) {
			break;
		}
		sel = dialog_notice(regedit, DIA_CONFIRM,
				    "Delete Key",
				     "Really delete key \"%s\"?",
				     node->name);
		if (sel == DIALOG_OK) {
			WERROR rv;
			struct tree_node *pop;
			struct tree_node *parent = node->parent;

			rv = reg_key_del(node, parent->key, node->name);
			if (W_ERROR_IS_OK(rv)) {
				tree_node_reopen_key(regedit->registry_context,
						     parent);
				tree_view_clear(regedit->keys);
				pop = tree_node_pop(&node);
				talloc_free(pop);
				node = parent->child_head;
				if (node == NULL) {
					node = tree_node_first(parent);
					print_path(regedit, node);
				}
				tree_view_update(regedit->keys, node);
				value_list_load(regedit->vl, node->key);
			} else {
				const char *msg = get_friendly_werror_msg(rv);
				dialog_notice(regedit, DIA_ALERT, "Delete Key",
					      "Failed to delete key: %s", msg);
			}
		}
		break;
	}
	}

	tree_view_show(regedit->keys);
	value_list_show(regedit->vl);
}
static void add_reg_key(struct regedit *regedit, struct tree_node *node,
			bool subkey)
{
	const char *name;
	const char *msg;

	if (!subkey && tree_node_is_top_level(node)) {
		return;
	}

	msg = "Enter name of new key";
	if (subkey) {
		msg = "Enter name of new subkey";
	}
	dialog_input(regedit, &name, "New Key", msg);
	if (name) {
		WERROR rv;
		struct registry_key *new_key;
		struct tree_node *new_node;
		struct tree_node *list;
		struct tree_node *parent;

		if (subkey) {
			parent = node;
			list = node->child_head;
		} else {
			parent = node->parent;
			list = tree_node_first(node);
			SMB_ASSERT(list != NULL);
		}
		rv = reg_key_add_name(regedit, parent->key, name,
				      NULL, NULL, &new_key);
		if (W_ERROR_IS_OK(rv)) {
			/* The list of subkeys may not be present in
			   cache yet, so if not, don't bother allocating
			   a new node for the key. */
			if (list) {
				new_node = tree_node_new(parent, parent,
							 name, new_key);
				SMB_ASSERT(new_node);
				tree_node_insert_sorted(list, new_node);
			} else {
				/* Reopen the parent key to make sure the
				   new subkey will be noticed. */
				tree_node_reopen_key(regedit->registry_context,
						     parent);
			}

			list = tree_node_first(node);
			tree_view_clear(regedit->keys);
			tree_view_update(regedit->keys, list);
			if (!subkey) {
				node = new_node;
			}
			tree_view_set_current_node(regedit->keys, node);
			load_values(regedit);
		} else {
			msg = get_friendly_werror_msg(rv);
			dialog_notice(regedit, DIA_ALERT, "New Key",
				      "Failed to create key: %s", msg);
		}
		talloc_free(discard_const(name));
	}
}