summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/regedit.c32
-rw-r--r--source3/utils/regedit_valuelist.c182
-rw-r--r--source3/utils/regedit_valuelist.h49
3 files changed, 254 insertions, 9 deletions
diff --git a/source3/utils/regedit.c b/source3/utils/regedit.c
index 59afeefe53..182fe3438a 100644
--- a/source3/utils/regedit.c
+++ b/source3/utils/regedit.c
@@ -23,6 +23,7 @@
#include "lib/registry/registry.h"
#include "regedit.h"
#include "regedit_treeview.h"
+#include "regedit_valuelist.h"
#include <ncurses.h>
#include <menu.h>
@@ -53,7 +54,7 @@ static struct tree_node *load_hives(TALLOC_CTX *mem_ctx,
for (i = 0; hives[i] != NULL; ++i) {
rv = reg_get_predefined_key_by_name(ctx, hives[i], &key);
if (!W_ERROR_IS_OK(rv)) {
- return root;
+ continue;
}
node = tree_node_new(mem_ctx, NULL, hives[i], key);
@@ -77,7 +78,8 @@ static struct tree_node *load_hives(TALLOC_CTX *mem_ctx,
static void display_test_window(TALLOC_CTX *mem_ctx,
struct registry_context *ctx)
{
- WINDOW *tree_window, *path_label;
+ WINDOW *main_window, *path_label;
+ struct value_list *vl;
struct tree_view *view;
struct tree_node *root, *node;
int c;
@@ -88,31 +90,41 @@ static void display_test_window(TALLOC_CTX *mem_ctx,
noecho();
keypad(stdscr, TRUE);
- tree_window = newwin(25, 80, 0, 0);
- SMB_ASSERT(tree_window != NULL);
+ main_window = newwin(25, 80, 0, 0);
+ SMB_ASSERT(main_window != NULL);
- keypad(tree_window, TRUE);
+ keypad(main_window, TRUE);
- mvwprintw(tree_window, 0, 0, "Path: ");
- path_label = derwin(tree_window, 1, 45, 0, 6);
+ mvwprintw(main_window, 0, 0, "Path: ");
+ path_label = derwin(main_window, 1, 65, 0, 6);
wprintw(path_label, "/");
root = load_hives(mem_ctx, ctx);
SMB_ASSERT(root != NULL);
- view = tree_view_new(mem_ctx, root, tree_window, 15, 40, 3, 0);
+ mvwprintw(main_window, 2, 0, "Keys");
+ view = tree_view_new(mem_ctx, root, main_window, 15, 24, 3, 0);
SMB_ASSERT(view != NULL);
+ mvwprintw(main_window, 2, 25, "Values");
+ vl = value_list_new(mem_ctx, main_window, 15, 40, 3, 25);
+ SMB_ASSERT(vl != NULL);
+
refresh();
tree_view_show(view);
+ value_list_show(vl);
- while ((c = wgetch(tree_window)) != 'q') {
+ while ((c = wgetch(main_window)) != 'q') {
switch (c) {
case KEY_DOWN:
menu_driver(view->menu, REQ_DOWN_ITEM);
+ node = item_userptr(current_item(view->menu));
+ value_list_load(vl, node->key);
break;
case KEY_UP:
menu_driver(view->menu, REQ_UP_ITEM);
+ node = item_userptr(current_item(view->menu));
+ value_list_load(vl, node->key);
break;
case KEY_RIGHT:
node = item_userptr(current_item(view->menu));
@@ -131,7 +143,9 @@ static void display_test_window(TALLOC_CTX *mem_ctx,
}
break;
}
+
tree_view_show(view);
+ value_list_show(vl);
}
endwin();
diff --git a/source3/utils/regedit_valuelist.c b/source3/utils/regedit_valuelist.c
new file mode 100644
index 0000000000..44cafca8c5
--- /dev/null
+++ b/source3/utils/regedit_valuelist.c
@@ -0,0 +1,182 @@
+/*
+ * Samba Unix/Linux SMB client library
+ * Registry Editor
+ * Copyright (C) Christopher Davis 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "regedit_valuelist.h"
+#include "lib/registry/registry.h"
+
+static void value_list_free_items(struct value_list *vl)
+{
+ size_t i;
+ ITEM *item;
+ struct value_item *vitem;
+
+ if (vl->items == NULL) {
+ return;
+ }
+
+ for (i = 0; vl->items[i] != NULL; ++i) {
+ item = vl->items[i];
+ vitem = item_userptr(item);
+ SMB_ASSERT(vitem != NULL);
+ free_item(item);
+ talloc_free(vitem);
+ }
+
+ talloc_free(vl->items);
+ vl->items = NULL;
+}
+
+static int value_list_free(struct value_list *vl)
+{
+ if (vl->menu) {
+ unpost_menu(vl->menu);
+ free_menu(vl->menu);
+ }
+ if (vl->empty && vl->empty[0]) {
+ free_item(vl->empty[0]);
+ }
+ value_list_free_items(vl);
+
+ return 0;
+}
+
+struct value_list *value_list_new(TALLOC_CTX *ctx, WINDOW *orig, int nlines,
+ int ncols, int begin_y, int begin_x)
+{
+ static const char *empty = "(no values)";
+ static const char *empty_desc = "";
+ struct value_list *vl;
+
+ vl = talloc_zero(ctx, struct value_list);
+ if (vl == NULL) {
+ return NULL;
+ }
+
+ talloc_set_destructor(vl, value_list_free);
+
+ vl->empty = talloc_zero_array(ctx, ITEM *, 2);
+ if (vl->empty == NULL) {
+ goto fail;
+ }
+ vl->empty[0] = new_item(empty, empty_desc);
+ if (vl->empty[0] == NULL) {
+ goto fail;
+ }
+
+ vl->window = orig;
+ vl->sub_window = derwin(orig, nlines, ncols, begin_y, begin_x);
+
+ vl->menu = new_menu(vl->empty);
+ if (vl->menu == NULL) {
+ goto fail;
+ }
+
+ set_menu_format(vl->menu, nlines, 1);
+ set_menu_win(vl->menu, vl->window);
+ set_menu_sub(vl->menu, vl->sub_window);
+ menu_opts_on(vl->menu, O_SHOWDESC);
+ set_menu_mark(vl->menu, "* ");
+
+ return vl;
+
+fail:
+ talloc_free(vl);
+
+ return NULL;
+}
+
+static uint32_t get_num_values(TALLOC_CTX *ctx, const struct registry_key *key)
+{
+ const char *classname;
+ uint32_t num_subkeys;
+ uint32_t num_values;
+ NTTIME last_change_time;
+ uint32_t max_subkeynamelen;
+ uint32_t max_valnamelen;
+ uint32_t max_valbufsize;
+ WERROR rv;
+
+ rv = reg_key_get_info(ctx, key, &classname, &num_subkeys,
+ &num_values, &last_change_time,
+ &max_subkeynamelen, &max_valnamelen,
+ &max_valbufsize);
+
+ if (W_ERROR_IS_OK(rv)) {
+ return num_values;
+ }
+
+ return 0;
+}
+
+void value_list_show(struct value_list *vl)
+{
+ post_menu(vl->menu);
+ wrefresh(vl->window);
+}
+
+WERROR value_list_load(struct value_list *vl, struct registry_key *key)
+{
+ uint32_t n_values;
+ uint32_t idx;
+ struct value_item *vitem;
+ WERROR rv;
+
+ value_list_free_items(vl);
+
+ unpost_menu(vl->menu);
+ set_menu_items(vl->menu, vl->empty);
+
+ n_values = get_num_values(vl, key);
+ if (n_values == 0) {
+ return WERR_OK;
+ }
+
+ vl->items = talloc_zero_array(vl, ITEM *, n_values + 1);
+ if (vl->items == NULL) {
+ return WERR_NOMEM;
+ }
+
+ for (idx = 0; idx < n_values; ++idx) {
+ vitem = talloc_zero(vl, struct value_item);
+ if (vitem == NULL) {
+ return WERR_NOMEM;
+ }
+
+ rv = reg_key_get_value_by_index(vitem, key, idx,
+ &vitem->value_name,
+ &vitem->type,
+ &vitem->data);
+
+ if (!W_ERROR_IS_OK(rv)) {
+ talloc_free(vitem);
+ return rv;
+ }
+
+ /* TODO: format a preview of the data blob and stick it
+ in the description */
+
+ vl->items[idx] = new_item(vitem->value_name,
+ str_regtype(vitem->type));
+ set_item_userptr(vl->items[idx], vitem);
+ }
+
+ set_menu_items(vl->menu, vl->items);
+
+ return WERR_OK;
+}
diff --git a/source3/utils/regedit_valuelist.h b/source3/utils/regedit_valuelist.h
new file mode 100644
index 0000000000..5d5399905c
--- /dev/null
+++ b/source3/utils/regedit_valuelist.h
@@ -0,0 +1,49 @@
+/*
+ * Samba Unix/Linux SMB client library
+ * Registry Editor
+ * Copyright (C) Christopher Davis 2012
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _REGEDIT_VALUELIST_H_
+#define _REGEDIT_VALUELIST_H_
+
+#include "includes.h"
+#include <ncurses.h>
+#include <menu.h>
+
+struct registry_key;
+
+struct value_item {
+ uint32_t type;
+ DATA_BLOB data;
+ const char *value_name;
+ char *value_desc;
+};
+
+struct value_list {
+ WINDOW *window;
+ WINDOW *sub_window;
+ MENU *menu;
+ ITEM **items;
+ ITEM **empty;
+}
+;
+struct value_list *value_list_new(TALLOC_CTX *ctx, WINDOW *orig, int nlines,
+ int ncols, int begin_y, int begin_x);
+void value_list_show(struct value_list *vl);
+WERROR value_list_load(struct value_list *vl, struct registry_key *key);
+
+#endif