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/>.
20 #include "regedit_valuelist.h"
21 #include "lib/registry/registry.h"
23 static void value_list_free_items(ITEM
**items
)
27 struct value_item
*vitem
;
33 for (i
= 0; items
[i
] != NULL
; ++i
) {
35 vitem
= item_userptr(item
);
36 SMB_ASSERT(vitem
!= NULL
);
43 static int value_list_free(struct value_list
*vl
)
46 unpost_menu(vl
->menu
);
49 if (vl
->empty
&& vl
->empty
[0]) {
50 free_item(vl
->empty
[0]);
52 value_list_free_items(vl
->items
);
57 struct value_list
*value_list_new(TALLOC_CTX
*ctx
, WINDOW
*orig
, int nlines
,
58 int ncols
, int begin_y
, int begin_x
)
60 static const char *empty
= "(no values)";
61 static const char *empty_desc
= "";
62 struct value_list
*vl
;
64 vl
= talloc_zero(ctx
, struct value_list
);
69 talloc_set_destructor(vl
, value_list_free
);
71 vl
->empty
= talloc_zero_array(vl
, ITEM
*, 2);
72 if (vl
->empty
== NULL
) {
75 vl
->empty
[0] = new_item(empty
, empty_desc
);
76 if (vl
->empty
[0] == NULL
) {
81 vl
->sub_window
= derwin(orig
, nlines
, ncols
, begin_y
, begin_x
);
83 vl
->menu
= new_menu(vl
->empty
);
84 if (vl
->menu
== NULL
) {
88 set_menu_format(vl
->menu
, nlines
, 1);
89 set_menu_win(vl
->menu
, vl
->window
);
90 set_menu_sub(vl
->menu
, vl
->sub_window
);
91 menu_opts_on(vl
->menu
, O_SHOWDESC
);
92 set_menu_mark(vl
->menu
, "* ");
102 static uint32_t get_num_values(TALLOC_CTX
*ctx
, const struct registry_key
*key
)
104 const char *classname
;
105 uint32_t num_subkeys
;
107 NTTIME last_change_time
;
108 uint32_t max_subkeynamelen
;
109 uint32_t max_valnamelen
;
110 uint32_t max_valbufsize
;
113 rv
= reg_key_get_info(ctx
, key
, &classname
, &num_subkeys
,
114 &num_values
, &last_change_time
,
115 &max_subkeynamelen
, &max_valnamelen
,
118 if (W_ERROR_IS_OK(rv
)) {
125 void value_list_show(struct value_list
*vl
)
130 static WERROR
append_data_summary(struct value_item
*vitem
)
134 /* This is adapted from print_registry_value() in net_registry_util.c */
136 switch(vitem
->type
) {
139 if (vitem
->data
.length
>= 4) {
140 v
= IVAL(vitem
->data
.data
, 0);
142 tmp
= talloc_asprintf_append(vitem
->value_desc
, "(0x%x)", v
);
146 case REG_EXPAND_SZ
: {
149 if (!pull_reg_sz(vitem
, &vitem
->data
, &s
)) {
152 tmp
= talloc_asprintf_append(vitem
->value_desc
, "(\"%s\")", s
);
159 if (!pull_reg_multi_sz(vitem
, &vitem
->data
, &a
)) {
162 tmp
= vitem
->value_desc
;
163 for (i
= 0; a
[i
] != NULL
; ++i
) {
164 tmp
= talloc_asprintf_append(tmp
, "\"%s\" ", a
[i
]);
172 tmp
= talloc_asprintf_append(vitem
->value_desc
, "(%d bytes)",
173 (int)vitem
->data
.length
);
176 tmp
= talloc_asprintf_append(vitem
->value_desc
,
185 vitem
->value_desc
= tmp
;
190 WERROR
value_list_load(struct value_list
*vl
, struct registry_key
*key
)
194 struct value_item
*vitem
;
197 static const char *empty_name
= "(empty)";
200 unpost_menu(vl
->menu
);
202 n_values
= get_num_values(vl
, key
);
204 set_menu_items(vl
->menu
, vl
->empty
);
208 new_items
= talloc_zero_array(vl
, ITEM
*, n_values
+ 1);
209 if (new_items
== NULL
) {
213 for (idx
= 0; idx
< n_values
; ++idx
) {
214 vitem
= talloc_zero(new_items
, struct value_item
);
219 rv
= reg_key_get_value_by_index(vitem
, key
, idx
,
224 if (!W_ERROR_IS_OK(rv
)) {
229 vitem
->value_desc
= talloc_asprintf(vitem
, "%-8s",
230 str_regtype(vitem
->type
));
231 if (vitem
->value_desc
== NULL
) {
236 rv
= append_data_summary(vitem
);
237 if (!W_ERROR_IS_OK(rv
)) {
242 /* ncurses won't accept empty strings in menu items */
243 name
= vitem
->value_name
;
244 if (name
[0] == '\0') {
247 new_items
[idx
] = new_item(name
, vitem
->value_desc
);
248 if (new_items
[idx
] == NULL
) {
253 set_item_userptr(new_items
[idx
], vitem
);
256 set_menu_items(vl
->menu
, new_items
);
257 value_list_free_items(vl
->items
);
258 vl
->items
= new_items
;