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.
24 static void writediff(struct registry_key *oldkey, struct registry_key *newkey, FILE *out)
27 struct registry_key *t1, *t2;
28 struct registry_value *v1, *v2;
29 WERROR error1, error2;
30 TALLOC_CTX *mem_ctx = talloc_init("writediff");
32 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(mem_ctx, oldkey, i, &t1)); i++) {
33 error2 = reg_key_get_subkey_by_name(mem_ctx, newkey, t1->name, &t2);
34 if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
35 fprintf(out, "-%s\n", t1->path+1);
36 } else if(!W_ERROR_IS_OK(error2)) {
37 DEBUG(0, ("Error occured while getting subkey by name: %d\n", W_ERROR_V(error2)));
41 talloc_destroy(mem_ctx);
43 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
44 DEBUG(0, ("Error occured while getting subkey by index: %d\n", W_ERROR_V(error1)));
48 mem_ctx = talloc_init("writediff");
50 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(mem_ctx, newkey, i, &t1)); i++) {
51 error2 = reg_key_get_subkey_by_name(mem_ctx, oldkey, t1->name, &t2);
52 if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
53 fprintf(out, "\n[%s]\n", t1->path+1);
54 } else if(!W_ERROR_IS_OK(error2)) {
55 DEBUG(0, ("Error occured while getting subkey by name: %d\n", W_ERROR_V(error2)));
57 writediff(t2, t1, out);
60 talloc_destroy(mem_ctx);
62 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
63 DEBUG(0, ("Error occured while getting subkey by index: %d\n", W_ERROR_V(error1)));
68 mem_ctx = talloc_init("writediff");
70 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, newkey, i, &v1)); i++) {
71 error2 = reg_key_get_value_by_name(mem_ctx, oldkey, v1->name, &v2);
72 if ((W_ERROR_IS_OK(error2) && (v2->data_len != v1->data_len || memcmp(v1->data_blk, v2->data_blk, v1->data_len)))
73 || W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
74 fprintf(out, "\"%s\"=%s:%s\n", v1->name, str_regtype(v1->data_type), reg_val_data_string(mem_ctx, v1));
77 if(!W_ERROR_IS_OK(error2) && !W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
78 DEBUG(0, ("Error occured while getting value by name: %d\n", W_ERROR_V(error2)));
82 talloc_destroy(mem_ctx);
84 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
85 DEBUG(0, ("Error occured while getting value by index: %d\n", W_ERROR_V(error1)));
89 mem_ctx = talloc_init("writediff");
91 for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, oldkey, i, &v1)); i++) {
92 error2 = reg_key_get_value_by_name(mem_ctx, newkey, v1->name, &v2);
93 if(W_ERROR_IS_OK(error2)) {
94 } else if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
95 fprintf(out, "\"%s\"=-\n", v1->name);
97 DEBUG(0, ("Error occured while getting value by name: %d\n", W_ERROR_V(error2)));
101 talloc_destroy(mem_ctx);
103 if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
104 DEBUG(0, ("Error occured while getting value by index: %d\n", W_ERROR_V(error1)));
109 int main(int argc, char **argv)
113 const char *backend1 = NULL, *backend2 = NULL;
114 const char *location2;
115 const char *credentials1= NULL, *credentials2 = NULL;
116 char *outputfile = NULL;
118 struct registry_context *h1 = NULL, *h2;
121 WERROR error, error2;
122 struct poptOption long_options[] = {
124 {"backend", 'b', POPT_ARG_STRING, NULL, 'b', "backend to use", NULL},
125 {"credentials", 'c', POPT_ARG_STRING, NULL, 'c', "credentials", NULL},
126 {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
127 {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL" },
132 if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
133 fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
137 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
139 while((opt = poptGetNextOpt(pc)) != -1) {
142 if(!credentials1 && !from_null) credentials1 = poptGetOptArg(pc);
143 else if(!credentials2) credentials2 = poptGetOptArg(pc);
146 if(!backend1 && !from_null) backend1 = poptGetOptArg(pc);
147 else if(!backend2) backend2 = poptGetOptArg(pc);
151 setup_logging(argv[0], True);
154 const char *location1;
155 location1 = poptGetArg(pc);
157 poptPrintUsage(pc, stderr, 0);
161 if(!backend1) backend1 = "rpc";
163 error = reg_open(&h1, backend1, location1, credentials1);
164 if(!W_ERROR_IS_OK(error)) {
165 fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location1, backend1);
170 location2 = poptGetArg(pc);
172 poptPrintUsage(pc, stderr, 0);
176 if(!backend2) backend2 = "rpc";
178 error = reg_open(&h2, backend2, location2, credentials2);
179 if(!W_ERROR_IS_OK(error)) {
180 fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location2, backend2);
187 fd = fopen(outputfile, "w+");
189 fprintf(stderr, "Unable to open '%s'\n", outputfile);
194 fprintf(fd, "REGEDIT4\n\n");
195 fprintf(fd, "; Generated using regdiff\n");
197 error2 = error = WERR_OK;
199 for(i = 0; (!h1 || i < h1->num_hives) && i < h2->num_hives; i++) {
200 writediff(h1?h1->hives[i]->root:NULL, h2->hives[i]->root, fd);