2 Unix SMB/CIFS implementation.
3 simple registry frontend
5 Copyright (C) Jelmer Vernooij 2004
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "dynconfig.h"
25 #include "lib/cmdline/popt_common.h"
27 static void print_tree(int l, struct registry_key *p, int fullpath, int novals)
29 struct registry_key *subkey;
30 struct registry_value *value;
35 for(i = 0; i < l; i++) putchar(' ');
38 if(p->hive->root == p) {
39 if(p->hive->root->name) printf("%s\n", p->hive->root->name); else printf("<No Name>\n");
41 if(!p->name) printf("<No Name>\n");
42 if(fullpath) printf("%s\n", p->path);
43 else printf("%s\n", p->name);
46 mem_ctx = talloc_init("print_tree");
47 for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, p, i, &subkey)); i++) {
48 print_tree(l+1, subkey, fullpath, novals);
50 talloc_destroy(mem_ctx);
52 if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
53 DEBUG(0, ("Error occured while fetching subkeys for '%s': %s\n", p->path, win_errstr(error)));
57 mem_ctx = talloc_init("print_tree");
58 for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(mem_ctx, p, i, &value)); i++) {
61 for(j = 0; j < l+1; j++) putchar(' ');
62 desc = reg_val_description(mem_ctx, value);
65 talloc_destroy(mem_ctx);
67 if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
68 DEBUG(0, ("Error occured while fetching values for '%s': %s\n", p->path, win_errstr(error)));
73 int main(int argc, char **argv)
76 const char *backend = NULL;
77 const char *remote = NULL;
79 struct registry_context *h = NULL;
80 struct registry_key *root = NULL;
82 int fullpath = 0, no_values = 0;
83 struct poptOption long_options[] = {
85 POPT_COMMON_CREDENTIALS
86 {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
87 {"fullpath", 'f', POPT_ARG_NONE, &fullpath, 0, "show full paths", NULL},
88 {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL },
89 {"no-values", 'V', POPT_ARG_NONE, &no_values, 0, "don't show values", NULL},
93 regtree_init_subsystems;
95 if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
96 fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
100 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
102 while((opt = poptGetNextOpt(pc)) != -1) {
105 setup_logging("regtree", True);
108 error = reg_open_remote(&h, cmdline_get_username(), cmdline_get_userpassword(), remote);
109 } else if (backend) {
110 error = reg_open_hive(NULL, backend, poptGetArg(pc), NULL, &root);
112 error = reg_open_local (&h);
115 if(!W_ERROR_IS_OK(error)) {
116 fprintf(stderr, "Unable to open '%s' with backend '%s':%s \n", poptGetArg(pc), backend, win_errstr(error));
124 print_tree(0, root, fullpath, no_values);
126 for(i = HKEY_CLASSES_ROOT; i < HKEY_PERFORMANCE_NLSTEXT; i++) {
127 error = reg_get_hive(h, i, &root);
128 if (!W_ERROR_IS_OK(error)) {
129 fprintf(stderr, "Skipping %s\n", reg_get_hkey_name(i));
132 print_tree(0, root, fullpath, no_values);