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"
24 #include "lib/registry/registry.h"
25 #include "lib/cmdline/popt_common.h"
27 static void writediff(struct registry_key *oldkey, struct registry_key *newkey, FILE *out)
30 struct registry_key *t1, *t2;
31 struct registry_value *v1, *v2;
32 WERROR error1, error2;
33 TALLOC_CTX *mem_ctx = talloc_init("writediff");
35 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(mem_ctx, oldkey, i, &t1)); i++) {
36 error2 = reg_key_get_subkey_by_name(mem_ctx, newkey, t1->name, &t2);
37 if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
38 fprintf(out, "-%s\n", t1->path+1);
39 } else if(!W_ERROR_IS_OK(error2)) {
40 DEBUG(0, ("Error occured while getting subkey by name: %d\n", W_ERROR_V(error2)));
46 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
47 DEBUG(0, ("Error occured while getting subkey by index: %d\n", W_ERROR_V(error1)));
51 mem_ctx = talloc_init("writediff");
53 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(mem_ctx, newkey, i, &t1)); i++) {
54 error2 = reg_key_get_subkey_by_name(mem_ctx, oldkey, t1->name, &t2);
55 if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
56 fprintf(out, "\n[%s]\n", t1->path+1);
57 } else if(!W_ERROR_IS_OK(error2)) {
58 DEBUG(0, ("Error occured while getting subkey by name: %d\n", W_ERROR_V(error2)));
60 writediff(t2, t1, out);
65 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
66 DEBUG(0, ("Error occured while getting subkey by index: %d\n", W_ERROR_V(error1)));
71 mem_ctx = talloc_init("writediff");
73 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, newkey, i, &v1)); i++) {
74 error2 = reg_key_get_value_by_name(mem_ctx, oldkey, v1->name, &v2);
75 if ((W_ERROR_IS_OK(error2) && data_blob_equal(&v1->data, &v2->data))
76 || W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
77 fprintf(out, "\"%s\"=%s:%s\n", v1->name, str_regtype(v1->data_type), reg_val_data_string(mem_ctx, v1));
80 if(!W_ERROR_IS_OK(error2) && !W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
81 DEBUG(0, ("Error occured while getting value by name: %d\n", W_ERROR_V(error2)));
87 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
88 DEBUG(0, ("Error occured while getting value by index: %d\n", W_ERROR_V(error1)));
92 mem_ctx = talloc_init("writediff");
94 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, oldkey, i, &v1)); i++) {
95 error2 = reg_key_get_value_by_name(mem_ctx, newkey, v1->name, &v2);
96 if(W_ERROR_IS_OK(error2)) {
97 } else if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
98 fprintf(out, "\"%s\"=-\n", v1->name);
100 DEBUG(0, ("Error occured while getting value by name: %d\n", W_ERROR_V(error2)));
104 talloc_free(mem_ctx);
106 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
107 DEBUG(0, ("Error occured while getting value by index: %d\n", W_ERROR_V(error1)));
112 int main(int argc, char **argv)
116 char *outputfile = NULL;
118 struct registry_context *h1 = NULL, *h2 = NULL;
121 WERROR error, error2;
122 struct poptOption long_options[] = {
124 {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
125 {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL },
126 {"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL },
127 {"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL },
129 POPT_COMMON_CREDENTIALS
134 regdiff_init_subsystems;
136 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
138 while((opt = poptGetNextOpt(pc)) != -1) {
142 if (!h1 && !from_null) error = reg_open_local(&h1);
143 else if (!h2) error = reg_open_local(&h2);
146 if (!h1 && !from_null)
147 error = reg_open_remote(&h1, cmdline_credentials,
148 poptGetOptArg(pc), NULL);
149 else if (!h2) error = reg_open_remote(&h2, cmdline_credentials,
150 poptGetOptArg(pc), NULL);
154 if (!W_ERROR_IS_OK(error)) {
155 fprintf(stderr, "Error: %s\n", win_errstr(error));
163 fd = fopen(outputfile, "w+");
165 fprintf(stderr, "Unable to open '%s'\n", outputfile);
170 fprintf(fd, "REGEDIT4\n\n");
171 fprintf(fd, "; Generated using regdiff, part of Samba\n");
173 error2 = error = WERR_OK;
175 for(i = HKEY_CLASSES_ROOT; i <= HKEY_PERFORMANCE_NLSTEXT; i++) {
176 struct registry_key *r1, *r2;
177 error = reg_get_predefined_key(h1, i, &r1);
178 if (!W_ERROR_IS_OK(error)) {
179 DEBUG(0, ("Unable to open hive %s for backend 1\n", reg_get_predef_name(i)));
183 error = reg_get_predefined_key(h2, i, &r2);
184 if (!W_ERROR_IS_OK(error)) {
185 DEBUG(0, ("Unable to open hive %s for backend 2\n", reg_get_predef_name(i)));
189 writediff(r1, r2, fd);