2 * Samba Unix/Linux SMB client library
4 * Copyright (C) Christopher Davis 2012
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "popt_common.h"
22 #include "lib/util/data_blob.h"
23 #include "lib/registry/registry.h"
25 #include "regedit_treeview.h"
26 #include "regedit_valuelist.h"
30 /* load all available hives */
31 static struct tree_node *load_hives(TALLOC_CTX *mem_ctx,
32 struct registry_context *ctx)
34 const char *hives[] = {
38 "HKEY_PERFORMANCE_DATA",
40 "HKEY_CURRENT_CONFIG",
42 "HKEY_PERFORMANCE_TEXT",
43 "HKEY_PERFORMANCE_NLSTEXT",
46 struct tree_node *root, *prev, *node;
47 struct registry_key *key;
54 for (i = 0; hives[i] != NULL; ++i) {
55 rv = reg_get_predefined_key_by_name(ctx, hives[i], &key);
56 if (!W_ERROR_IS_OK(rv)) {
60 node = tree_node_new(mem_ctx, NULL, hives[i], key);
69 tree_node_append(prev, node);
77 /* test navigating available hives */
78 static void display_test_window(TALLOC_CTX *mem_ctx,
79 struct registry_context *ctx)
81 WINDOW *main_window, *path_label;
82 struct value_list *vl;
83 struct tree_view *view;
84 struct tree_node *root, *node;
93 main_window = newwin(25, 80, 0, 0);
94 SMB_ASSERT(main_window != NULL);
96 keypad(main_window, TRUE);
98 mvwprintw(main_window, 0, 0, "Path: ");
99 path_label = derwin(main_window, 1, 65, 0, 6);
100 wprintw(path_label, "/");
102 root = load_hives(mem_ctx, ctx);
103 SMB_ASSERT(root != NULL);
105 mvwprintw(main_window, 2, 0, "Keys");
106 view = tree_view_new(mem_ctx, root, main_window, 15, 24, 3, 0);
107 SMB_ASSERT(view != NULL);
109 mvwprintw(main_window, 2, 25, "Values");
110 vl = value_list_new(mem_ctx, main_window, 15, 40, 3, 25);
111 SMB_ASSERT(vl != NULL);
114 tree_view_show(view);
117 while ((c = wgetch(main_window)) != 'q') {
120 menu_driver(view->menu, REQ_DOWN_ITEM);
121 node = item_userptr(current_item(view->menu));
122 value_list_load(vl, node->key);
125 menu_driver(view->menu, REQ_UP_ITEM);
126 node = item_userptr(current_item(view->menu));
127 value_list_load(vl, node->key);
130 node = item_userptr(current_item(view->menu));
131 if (node && tree_node_has_children(node)) {
132 tree_node_load_children(node);
133 tree_node_print_path(path_label, node->child_head);
134 tree_view_update(view, node->child_head);
138 node = item_userptr(current_item(view->menu));
139 if (node && node->parent) {
140 tree_node_print_path(path_label, node->child_head);
141 tree_view_update(view,
142 tree_node_first(node->parent));
147 tree_view_show(view);
154 int main(int argc, char **argv)
156 struct poptOption long_options[] = {
160 POPT_COMMON_CONNECTION
161 POPT_COMMON_CREDENTIALS
166 struct user_auth_info *auth_info;
168 struct registry_context *ctx;
171 talloc_enable_leak_report_full();
173 frame = talloc_stackframe();
175 setup_logging("regedit", DEBUG_DEFAULT_STDERR);
176 lp_set_cmdline("log level", "0");
178 /* process options */
179 auth_info = user_auth_info_init(frame);
180 if (auth_info == NULL) {
183 popt_common_set_auth_info(auth_info);
184 pc = poptGetContext("regedit", argc, (const char **)argv, long_options, 0);
186 while ((opt = poptGetNextOpt(pc)) != -1) {
190 if (!lp_load_global(get_dyn_CONFIGFILE())) {
191 DEBUG(0, ("ERROR loading config file...\n"));
195 /* some simple tests */
197 rv = reg_open_samba3(frame, &ctx);
198 SMB_ASSERT(W_ERROR_IS_OK(rv));
200 display_test_window(frame, ctx);
202 //talloc_report_full(frame, stdout);