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; }
static struct registry_context *open_backend(poptContext pc, struct tevent_context *ev_ctx, struct loadparm_context *lp_ctx, enum reg_backend backend, const char *remote_host) { WERROR error; struct registry_context *ctx; switch (backend) { case REG_UNKNOWN: poptPrintUsage(pc, stderr, 0); return NULL; case REG_LOCAL: error = reg_open_samba(NULL, &ctx, ev_ctx, lp_ctx, NULL, cmdline_credentials); break; case REG_REMOTE: error = reg_open_remote(&ctx, NULL, cmdline_credentials, lp_ctx, remote_host, ev_ctx); break; case REG_NULL: error = reg_open_local(NULL, &ctx); break; } if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Error: %s\n", win_errstr(error)); return NULL; } return ctx; }
_PUBLIC_ WERROR reg_open_samba(TALLOC_CTX *mem_ctx, struct registry_context **ctx, struct tevent_context *ev_ctx, struct loadparm_context *lp_ctx, struct auth_session_info *session_info, struct cli_credentials *credentials) { WERROR result; result = reg_open_local(mem_ctx, ctx); if (!W_ERROR_IS_OK(result)) { return result; } mount_samba_hive(*ctx, ev_ctx, lp_ctx, session_info, credentials, "hklm", HKEY_LOCAL_MACHINE); mount_samba_hive(*ctx, ev_ctx, lp_ctx, session_info, credentials, "hkcr", HKEY_CLASSES_ROOT); /* FIXME: Should be mounted from NTUSER.DAT in the home directory of the * current user */ mount_samba_hive(*ctx, ev_ctx, lp_ctx, session_info, credentials, "hkcu", HKEY_CURRENT_USER); mount_samba_hive(*ctx, ev_ctx, lp_ctx, session_info, credentials, "hku", HKEY_USERS); /* FIXME: Different hive backend for HKEY_CLASSES_ROOT: merged view of HKEY_LOCAL_MACHINE\Software\Classes * and HKEY_CURRENT_USER\Software\Classes */ /* FIXME: HKEY_CURRENT_CONFIG is an alias for HKEY_LOCAL_MACHINE\System\CurrentControlSet\Hardware Profiles\Current */ /* FIXME: HKEY_PERFORMANCE_DATA is dynamically generated */ /* FIXME: HKEY_LOCAL_MACHINE\Hardware is autogenerated */ /* FIXME: HKEY_LOCAL_MACHINE\Security\SAM is an alias for HKEY_LOCAL_MACHINE\SAM */ return WERR_OK; }