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 void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out)
26 int i, numvals1, numvals2, numkeys2;
28 numkeys2 = reg_key_num_subkeys(newkey);
29 for(i = 0; i < numkeys2; i++) {
30 REG_KEY *t1 = reg_key_get_subkey_by_index(newkey, i);
31 REG_KEY *t2 = reg_key_get_subkey_by_name(oldkey, reg_key_name(t1));
33 fprintf(out, "[%s]\n", reg_key_get_path(t1));
35 writediff(t2, t1, out);
38 numvals2 = reg_key_num_values(newkey);
39 for(i = 0; i < numvals2; i++) {
40 REG_VAL *t1 = reg_key_get_value_by_index(newkey, i);
41 REG_VAL *t2 = reg_key_get_value_by_name(oldkey, reg_val_name(t1));
42 if(!t2 || reg_val_size(t2) != reg_val_size(t1) || memcmp(reg_val_data_blk(t1), reg_val_data_blk(t2), reg_val_size(t1))) {
43 fprintf(out, "\"%s\"=%s:%s\n", reg_val_name(t1), str_regtype(reg_val_type(t1)), reg_val_data_string(t1));
47 numvals1 = reg_key_num_values(oldkey);
48 for(i = 0; i < numvals1; i++) {
49 REG_VAL *t1 = reg_key_get_value_by_index(oldkey, i);
50 if(!reg_key_get_value_by_name(newkey, reg_val_name(t1))) {
51 fprintf(out, "\"%s\"=-\n", reg_val_name(t1));
56 int main (int argc, char **argv)
58 uint32 setparms, checkparms;
62 const char *backend1 = NULL, *backend2 = NULL;
63 const char *location2;
64 char *outputfile = NULL;
67 REG_KEY *root1 = NULL, *root2;
69 int fullpath = 0, no_values = 0;
70 struct poptOption long_options[] = {
72 {"backend", 'b', POPT_ARG_STRING, NULL, 'b', "backend to use", NULL},
73 {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
74 {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL" },
78 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
80 while((opt = poptGetNextOpt(pc)) != -1) {
83 if(!backend1 && !from_null) backend1 = poptGetOptArg(pc);
84 else if(!backend2) backend2 = poptGetOptArg(pc);
88 setup_logging(argv[0], True);
92 const char *location1;
93 location1 = poptGetArg(pc);
95 poptPrintUsage(pc, stderr, 0);
99 if(!backend1) backend1 = "dir";
101 h1 = reg_open(backend1, location1, True);
103 fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location1, backend1);
107 root1 = reg_get_root(h1);
110 location2 = poptGetArg(pc);
112 poptPrintUsage(pc, stderr, 0);
116 if(!backend2) backend2 = "dir";
118 h2 = reg_open(backend2, location2, True);
120 fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location2, backend2);
124 root2 = reg_get_root(h2);
126 fprintf(stderr, "Can't open root key for '%s:%s'\n", backend2, location2);
133 fd = fopen(outputfile, "w+");
135 fprintf(stderr, "Unable to open '%s'\n", outputfile);
140 fprintf(fd, "REGEDIT4\n\n");
141 fprintf(fd, "; Generated using regdiff\n");
143 writediff(root1, root2, fd);