summaryrefslogtreecommitdiff
path: root/source4/lib/registry/tools/regdiff.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/registry/tools/regdiff.c')
-rw-r--r--source4/lib/registry/tools/regdiff.c93
1 files changed, 65 insertions, 28 deletions
diff --git a/source4/lib/registry/tools/regdiff.c b/source4/lib/registry/tools/regdiff.c
index 5e2b97cb98..94cdf8c8af 100644
--- a/source4/lib/registry/tools/regdiff.c
+++ b/source4/lib/registry/tools/regdiff.c
@@ -24,41 +24,71 @@
void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out)
{
int i, numkeys1, numvals1, numvals2, numkeys2;
+ REG_KEY *t1,*t2;
+ REG_VAL *v1, *v2;
+ WERROR error1, error2;
- numkeys1 = reg_key_num_subkeys(oldkey);
- for(i = 0; i < numkeys1; i++) {
- REG_KEY *t1 = reg_key_get_subkey_by_index(oldkey, i);
- if(!reg_key_get_subkey_by_name(newkey, reg_key_name(t1))) {
+ for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(oldkey, i, &t1)); i++) {
+ error2 = reg_key_get_subkey_by_name(newkey, reg_key_name(t1), &t2);
+ if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
fprintf(out, "-%s\n", reg_key_get_path(t1)+1);
+ } else if(!W_ERROR_IS_OK(error2)) {
+ DEBUG(0, ("Error occured while getting subkey by name: %d\n", error2));
}
}
- numkeys2 = reg_key_num_subkeys(newkey);
- for(i = 0; i < numkeys2; i++) {
- REG_KEY *t1 = reg_key_get_subkey_by_index(newkey, i);
- REG_KEY *t2 = reg_key_get_subkey_by_name(oldkey, reg_key_name(t1));
- if(!t2) {
+ if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while getting subkey by index: %d\n", error1));
+ return;
+ }
+
+ for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(newkey, i, &t1)); i++) {
+ error2 = reg_key_get_subkey_by_name(oldkey, reg_key_name(t1), &t2);
+ if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
fprintf(out, "\n[%s]\n", reg_key_get_path(t1)+1);
+ } else if(!W_ERROR_IS_OK(error2)) {
+ DEBUG(0, ("Error occured while getting subkey by name: %d\n", error2));
}
writediff(t2, t1, out);
}
- numvals2 = reg_key_num_values(newkey);
- for(i = 0; i < numvals2; i++) {
- REG_VAL *t1 = reg_key_get_value_by_index(newkey, i);
- REG_VAL *t2 = reg_key_get_value_by_name(oldkey, reg_val_name(t1));
- 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))) {
- fprintf(out, "\"%s\"=%s:%s\n", reg_val_name(t1), str_regtype(reg_val_type(t1)), reg_val_data_string(t1));
+ if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while getting subkey by index: %d\n", error1));
+ return;
+ }
+
+ for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(newkey, i, &v1)); i++) {
+ error2 = reg_key_get_value_by_name(oldkey, reg_val_name(v1), &v2);
+ if ((W_ERROR_IS_OK(error2) && reg_val_size(v2) != reg_val_size(v1) || memcmp(reg_val_data_blk(v1), reg_val_data_blk(v2), reg_val_size(v1)))
+ || W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+ fprintf(out, "\"%s\"=%s:%s\n", reg_val_name(v1), str_regtype(reg_val_type(v1)), reg_val_data_string(v1));
+ }
+
+ if(!W_ERROR_IS_OK(error2) && !W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+ DEBUG(0, ("Error occured while getting value by name: %d\n", error2));
}
}
- numvals1 = reg_key_num_values(oldkey);
- for(i = 0; i < numvals1; i++) {
- REG_VAL *t1 = reg_key_get_value_by_index(oldkey, i);
- if(!reg_key_get_value_by_name(newkey, reg_val_name(t1))) {
- fprintf(out, "\"%s\"=-\n", reg_val_name(t1));
+ if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while getting value by index: %d\n", error1));
+ return;
+ }
+
+
+ for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(oldkey, i, &v1)); i++) {
+ error2 = reg_key_get_value_by_name(newkey, reg_val_name(v1), &v2);
+ if(W_ERROR_IS_OK(error2)) {
+ } else if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
+ fprintf(out, "\"%s\"=-\n", reg_val_name(v1));
+ } else {
+ DEBUG(0, ("Error occured while getting value by name: %d\n", error2));
}
}
+
+ if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while getting value by index: %d\n", error1));
+ return;
+ }
}
int main (int argc, char **argv)
@@ -69,15 +99,18 @@ int main (int argc, char **argv)
REG_KEY *root;
const char *backend1 = NULL, *backend2 = NULL;
const char *location2;
+ const char *credentials1= NULL, *credentials2 = NULL;
char *outputfile = NULL;
FILE *fd = stdout;
REG_HANDLE *h2;
REG_KEY *root1 = NULL, *root2;
int from_null = 0;
int fullpath = 0, no_values = 0;
+ WERROR error;
struct poptOption long_options[] = {
POPT_AUTOHELP
{"backend", 'b', POPT_ARG_STRING, NULL, 'b', "backend to use", NULL},
+ {"credentials", 'c', POPT_ARG_STRING, NULL, 'c', "credentials", NULL},
{"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
{"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL" },
POPT_TABLEEND
@@ -87,7 +120,11 @@ int main (int argc, char **argv)
while((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
- case 'b':
+ case 'c':
+ if(!credentials1 && !from_null) credentials1 = poptGetOptArg(pc);
+ else if(!credentials2) credentials2 = poptGetOptArg(pc);
+ break;
+ case 'b':
if(!backend1 && !from_null) backend1 = poptGetOptArg(pc);
else if(!backend2) backend2 = poptGetOptArg(pc);
break;
@@ -106,13 +143,13 @@ int main (int argc, char **argv)
if(!backend1) backend1 = "dir";
- h1 = reg_open(backend1, location1, True);
- if(!h1) {
+ error = reg_open(backend1, location1, credentials1, &h1);
+ if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location1, backend1);
return 1;
}
- root1 = reg_get_root(h1);
+ if(!W_ERROR_IS_OK(reg_get_root(h1, &root1))) return 1;
}
location2 = poptGetArg(pc);
@@ -123,14 +160,14 @@ int main (int argc, char **argv)
if(!backend2) backend2 = "dir";
- h2 = reg_open(backend2, location2, True);
- if(!h2) {
+ error = reg_open(backend2, location2, credentials2, &h2);
+ if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location2, backend2);
return 1;
}
- root2 = reg_get_root(h2);
- if(!root2) {
+ error = reg_get_root(h2, &root2);
+ if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Can't open root key for '%s:%s'\n", backend2, location2);
return 1;
}