summaryrefslogtreecommitdiff
path: root/source3/utils/regedit_treeview.c
diff options
context:
space:
mode:
authorC. Davis <cd.rattan@gmail.com>2012-07-12 21:11:55 -0700
committerMichael Adam <obnox@samba.org>2013-04-29 13:05:46 +0200
commitd3633c08cd5e997d329ff42930d320a8eb4ac7f2 (patch)
treee268a51b4d3f8783727e97df2e684cf8cfdde00f /source3/utils/regedit_treeview.c
parentc99675b813c9e7020f670542750320b9145b3096 (diff)
downloadsamba-d3633c08cd5e997d329ff42930d320a8eb4ac7f2.tar.gz
samba-d3633c08cd5e997d329ff42930d320a8eb4ac7f2.tar.bz2
samba-d3633c08cd5e997d329ff42930d320a8eb4ac7f2.zip
regedit: Setup a test tree view of HKLM.
Expand on the former test by allowing the user to walk HKLM with the tree view. Subkeys are loaded dynamically in memory as the user walks the hierarchy with tree_node_load_children(). One issue with this at the moment is detecting if the in-memory copy of the hierarchy is out of date. TODO: figure out when to reload out of date portions of the hierarchy (probably by checking last_modified_time). Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/utils/regedit_treeview.c')
-rw-r--r--source3/utils/regedit_treeview.c79
1 files changed, 77 insertions, 2 deletions
diff --git a/source3/utils/regedit_treeview.c b/source3/utils/regedit_treeview.c
index f902f60678..ad6d45c7ec 100644
--- a/source3/utils/regedit_treeview.c
+++ b/source3/utils/regedit_treeview.c
@@ -18,8 +18,10 @@
*/
#include "regedit_treeview.h"
+#include "lib/registry/registry.h"
-struct tree_node *tree_node_new(TALLOC_CTX *ctx, struct tree_node *parent, const char *name)
+struct tree_node *tree_node_new(TALLOC_CTX *ctx, struct tree_node *parent,
+ const char *name, struct registry_key *key)
{
struct tree_node *node;
@@ -34,6 +36,8 @@ struct tree_node *tree_node_new(TALLOC_CTX *ctx, struct tree_node *parent, const
return NULL;
}
+ node->key = talloc_steal(node, key);
+
if (parent) {
/* Check if this node is the first descendant of parent. */
if (!parent->child_head) {
@@ -95,6 +99,77 @@ struct tree_node *tree_node_first(struct tree_node *list)
return list;
}
+bool tree_node_has_children(struct tree_node *node)
+{
+ 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;
+
+ if (node->child_head) {
+ return true;
+ }
+
+ rv = reg_key_get_info(node, node->key, &classname, &num_subkeys,
+ &num_values, &last_change_time,
+ &max_subkeynamelen, &max_valnamelen,
+ &max_valbufsize);
+
+ if (W_ERROR_IS_OK(rv)) {
+ return num_subkeys != 0;
+ }
+
+ return false;
+}
+
+WERROR tree_node_load_children(struct tree_node *node)
+{
+ struct registry_key *key;
+ const char *key_name, *klass;
+ NTTIME modified;
+ uint32_t i;
+ WERROR rv;
+ struct tree_node *new_node, *prev;
+
+ /* does this node already have it's children loaded? */
+ if (node->child_head)
+ return WERR_OK;
+
+ for (prev = NULL, i = 0; ; ++i) {
+ rv = reg_key_get_subkey_by_index(node, node->key, i,
+ &key_name, &klass,
+ &modified);
+ if (!W_ERROR_IS_OK(rv)) {
+ if (W_ERROR_EQUAL(rv, WERR_NO_MORE_ITEMS)) {
+ break;
+ }
+
+ return rv;
+ }
+
+ rv = reg_open_key(node, node->key, key_name, &key);
+ if (!W_ERROR_IS_OK(rv)) {
+ return rv;
+ }
+
+ new_node = tree_node_new(node, node, key_name, key);
+ if (new_node == NULL) {
+ return WERR_NOMEM;
+ }
+
+ if (prev) {
+ tree_node_append(prev, new_node);
+ }
+ prev = new_node;
+ }
+
+ return WERR_OK;
+}
+
void tree_node_free_recursive(struct tree_node *list)
{
struct tree_node *node;
@@ -158,7 +233,7 @@ WERROR tree_view_update(struct tree_view *view, struct tree_node *list)
/* Add a '+' marker to indicate that the item has
descendants. */
- if (node->child_head) {
+ if (tree_node_has_children(node)) {
SMB_ASSERT(node->label == NULL);
node->label = talloc_asprintf(node, "+%s", node->name);
if (node->label == NULL) {