int main(int argc, char **argv) { int opt; poptContext pc; char *outputfile = NULL; struct registry_context *h1 = NULL, *h2 = NULL; int from_null = 0; WERROR error; struct reg_diff *diff; struct poptOption long_options[] = { POPT_AUTOHELP {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL }, {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL }, {"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL }, {"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL }, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS POPT_COMMON_VERSION { NULL } }; registry_init(); pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { error = WERR_OK; switch(opt) { case 'L': if (!h1 && !from_null) error = reg_open_local(NULL, &h1, NULL, cmdline_credentials); else if (!h2) error = reg_open_local(NULL, &h2, NULL, cmdline_credentials); break; case 'R': if (!h1 && !from_null) error = reg_open_remote(&h1, NULL, cmdline_credentials, poptGetOptArg(pc), NULL); else if (!h2) error = reg_open_remote(&h2, NULL, cmdline_credentials, poptGetOptArg(pc), NULL); break; } if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Error: %s\n", win_errstr(error)); return 1; } } poptFreeContext(pc); diff = reg_generate_diff(NULL, h1, h2); if (!diff) { fprintf(stderr, "Unable to generate diff between keys\n"); return -1; } reg_diff_save(diff, outputfile); return 0; }
int main(int argc, const char **argv) { int opt; poptContext pc; char *outputfile = NULL; enum reg_backend backend1 = REG_UNKNOWN, backend2 = REG_UNKNOWN; const char *remote1 = NULL, *remote2 = NULL; struct registry_context *h1 = NULL, *h2 = NULL; WERROR error; struct poptOption long_options[] = { POPT_AUTOHELP {"output", 'o', POPT_ARG_STRING, &outputfile, 0, "output file to use", NULL }, {"null", 'n', POPT_ARG_NONE, NULL, 'n', "Diff from NULL", NULL }, {"remote", 'R', POPT_ARG_STRING, NULL, 'R', "Connect to remote server" , NULL }, {"local", 'L', POPT_ARG_NONE, NULL, 'L', "Open local registry", NULL }, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS POPT_COMMON_VERSION { NULL } }; TALLOC_CTX *ctx; void *callback_data; struct tevent_context *ev_ctx; struct reg_diff_callbacks *callbacks; ctx = talloc_init("regdiff"); pc = poptGetContext(argv[0], argc, argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { error = WERR_OK; switch(opt) { case 'L': if (backend1 == REG_UNKNOWN) backend1 = REG_LOCAL; else if (backend2 == REG_UNKNOWN) backend2 = REG_LOCAL; break; case 'n': if (backend1 == REG_UNKNOWN) backend1 = REG_NULL; else if (backend2 == REG_UNKNOWN) backend2 = REG_NULL; break; case 'R': if (backend1 == REG_UNKNOWN) { backend1 = REG_REMOTE; remote1 = poptGetOptArg(pc); } else if (backend2 == REG_UNKNOWN) { backend2 = REG_REMOTE; remote2 = poptGetOptArg(pc); } break; } } ev_ctx = s4_event_context_init(NULL); h1 = open_backend(pc, ev_ctx, cmdline_lp_ctx, backend1, remote1); if (h1 == NULL) return 1; h2 = open_backend(pc, ev_ctx, cmdline_lp_ctx, backend2, remote2); if (h2 == NULL) return 1; poptFreeContext(pc); error = reg_dotreg_diff_save(ctx, outputfile, lp_iconv_convenience(cmdline_lp_ctx), &callbacks, &callback_data); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Problem saving registry diff to '%s': %s\n", outputfile, win_errstr(error)); return -1; } error = reg_generate_diff(h1, h2, callbacks, callback_data); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to generate diff between keys: %s\n", win_errstr(error)); return -1; } return 0; }