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
);
135 value_list_load(vl
, node
->child_head
->key
);
139 node
= item_userptr(current_item(view
->menu
));
140 if (node
&& node
->parent
) {
141 tree_node_print_path(path_label
, node
->parent
);
142 node
= tree_node_first(node
->parent
);
143 tree_view_update(view
, node
);
144 value_list_load(vl
, node
->key
);
149 tree_view_show(view
);
156 int main(int argc
, char **argv
)
158 struct poptOption long_options
[] = {
162 POPT_COMMON_CONNECTION
163 POPT_COMMON_CREDENTIALS
168 struct user_auth_info
*auth_info
;
170 struct registry_context
*ctx
;
173 talloc_enable_leak_report_full();
175 frame
= talloc_stackframe();
177 setup_logging("regedit", DEBUG_DEFAULT_STDERR
);
178 lp_set_cmdline("log level", "0");
180 /* process options */
181 auth_info
= user_auth_info_init(frame
);
182 if (auth_info
== NULL
) {
185 popt_common_set_auth_info(auth_info
);
186 pc
= poptGetContext("regedit", argc
, (const char **)argv
, long_options
, 0);
188 while ((opt
= poptGetNextOpt(pc
)) != -1) {
192 if (!lp_load_global(get_dyn_CONFIGFILE())) {
193 DEBUG(0, ("ERROR loading config file...\n"));
197 /* some simple tests */
199 rv
= reg_open_samba3(frame
, &ctx
);
200 SMB_ASSERT(W_ERROR_IS_OK(rv
));
202 display_test_window(frame
, ctx
);
204 //talloc_report_full(frame, stdout);