diff options
-rw-r--r-- | source3/utils/net_registry.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c index 19405e2c08..bb7c67f1f1 100644 --- a/source3/utils/net_registry.c +++ b/source3/utils/net_registry.c @@ -185,6 +185,105 @@ done: return ret; } +static WERROR registry_enumkey(struct registry_key* parent, const char* keyname, bool recursive) +{ + WERROR werr; + TALLOC_CTX *ctx = talloc_stackframe(); + char* subkey_name; + NTTIME modtime; + uint32_t count; + char* valname = NULL; + struct registry_value *valvalue = NULL; + struct registry_key* key = NULL; + + werr = reg_openkey(ctx, parent, keyname, REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + printf("[%s]\n", key->key->name); + + for (count = 0; + werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime), + W_ERROR_IS_OK(werr); + count++) + { + print_registry_key(subkey_name, &modtime); + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + goto done; + } + + for (count = 0; + werr = reg_enumvalue(ctx, key, count, &valname, &valvalue), + W_ERROR_IS_OK(werr); + count++) + { + print_registry_value_with_name(valname, valvalue); + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + goto done; + } + + if (!recursive) { + werr = WERR_OK; + goto done; + } + + for (count = 0; + werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime), + W_ERROR_IS_OK(werr); + count++) + { + werr = registry_enumkey(key, subkey_name, recursive); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + goto done; + } + werr = WERR_OK; +done: + TALLOC_FREE(ctx); + return werr; +} + +static int net_registry_enumerate_recursive(struct net_context *c, int argc, + const char **argv) +{ + WERROR werr; + struct registry_key *key = NULL; + char* name = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); + int ret = -1; + + if (argc != 1 || c->display_usage) { + d_printf("%s\n%s", + _("Usage:"), + _("net registry enumerate <path>\n")); + d_printf("%s\n%s", + _("Example:"), + _("net registry enumerate 'HKLM\\Software\\Samba'\n")); + goto done; + } + + werr = open_hive(ctx, argv[0], REG_KEY_READ, &key, &name); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr)); + goto done; + } + + werr = registry_enumkey(key, name, true); + if (W_ERROR_IS_OK(werr)) { + ret = 0; + } +done: + TALLOC_FREE(ctx); + return ret; +} + + static int net_registry_createkey(struct net_context *c, int argc, const char **argv) { @@ -1174,6 +1273,14 @@ int net_registry(struct net_context *c, int argc, const char **argv) " Enumerate registry keys and values") }, { + "enumerate_recursive", + net_registry_enumerate_recursive, + NET_TRANSPORT_LOCAL, + N_("Enumerate registry keys and values"), + N_("net registry enumerate_recursive\n" + " Enumerate registry keys and values") + }, + { "createkey", net_registry_createkey, NET_TRANSPORT_LOCAL, |