/** * Generate diff between two registry contexts */ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1, struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks, void *callback_data) { int i; WERROR error; for (i = 0; reg_predefined_keys[i].name; i++) { struct registry_key *r1 = NULL, *r2 = NULL; error = reg_get_predefined_key(ctx1, reg_predefined_keys[i].handle, &r1); if (!W_ERROR_IS_OK(error) && !W_ERROR_EQUAL(error, WERR_BADFILE)) { DEBUG(0, ("Unable to open hive %s for backend 1\n", reg_predefined_keys[i].name)); continue; } error = reg_get_predefined_key(ctx2, reg_predefined_keys[i].handle, &r2); if (!W_ERROR_IS_OK(error) && !W_ERROR_EQUAL(error, WERR_BADFILE)) { DEBUG(0, ("Unable to open hive %s for backend 2\n", reg_predefined_keys[i].name)); continue; } error = reg_generate_diff_key(r1, r2, reg_predefined_keys[i].name, callbacks, callback_data); if (!W_ERROR_IS_OK(error)) { DEBUG(0, ("Unable to determine diff: %s\n", win_errstr(error))); return error; } } if (callbacks->done != NULL) { callbacks->done(callback_data); } return WERR_OK; }
static WERROR dcesrv_winreg_openhive(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, uint32_t hkey, struct policy_handle **outh) { struct registry_context *ctx = dce_call->context->private_data; struct dcesrv_handle *h; WERROR result; h = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY); result = reg_get_predefined_key(ctx, hkey, (struct registry_key **)&h->data); if (!W_ERROR_IS_OK(result)) { return result; } *outh = &h->wire_handle; return result; }
int main(int argc, const char **argv) { int opt; unsigned int i; const char *file = NULL; const char *remote = NULL; poptContext pc; struct registry_context *h = NULL; struct registry_key *start_key = NULL; struct tevent_context *ev_ctx; WERROR error; bool fullpath = false, no_values = false; struct poptOption long_options[] = { POPT_AUTOHELP {"file", 'F', POPT_ARG_STRING, &file, 0, "file path", NULL }, {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL }, {"fullpath", 'f', POPT_ARG_NONE, &fullpath, 0, "show full paths", NULL}, {"no-values", 'V', POPT_ARG_NONE, &no_values, 0, "don't show values", NULL}, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS POPT_COMMON_VERSION { NULL } }; pc = poptGetContext(argv[0], argc, argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } ev_ctx = s4_event_context_init(NULL); if (remote != NULL) { h = reg_common_open_remote(remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials); } else if (file != NULL) { start_key = reg_common_open_file(file, ev_ctx, cmdline_lp_ctx, cmdline_credentials); } else { h = reg_common_open_local(cmdline_credentials, ev_ctx, cmdline_lp_ctx); } if (h == NULL && start_key == NULL) return 1; poptFreeContext(pc); error = WERR_OK; if (start_key != NULL) { print_tree(0, start_key, "", fullpath, no_values); } else { for(i = 0; reg_predefined_keys[i].handle; i++) { error = reg_get_predefined_key(h, reg_predefined_keys[i].handle, &start_key); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Skipping %s: %s\n", reg_predefined_keys[i].name, win_errstr(error)); continue; } SMB_ASSERT(start_key != NULL); print_tree(0, start_key, reg_predefined_keys[i].name, fullpath, no_values); } } return 0; }
int main(int argc, char **argv) { int opt; const char *file = NULL; poptContext pc; const char *remote = NULL; struct regshell_context *ctx; struct tevent_context *ev_ctx; bool ret = true; struct poptOption long_options[] = { POPT_AUTOHELP {"file", 'F', POPT_ARG_STRING, &file, 0, "open hive file", NULL }, {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL}, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS POPT_COMMON_VERSION { NULL } }; pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } ctx = talloc_zero(NULL, struct regshell_context); ev_ctx = s4_event_context_init(ctx); if (remote != NULL) { ctx->registry = reg_common_open_remote(remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials); } else if (file != NULL) { ctx->current = reg_common_open_file(file, ev_ctx, cmdline_lp_ctx, cmdline_credentials); if (ctx->current == NULL) return 1; ctx->registry = ctx->current->context; ctx->path = talloc_strdup(ctx, ""); ctx->predef = NULL; ctx->root = ctx->current; } else { ctx->registry = reg_common_open_local(cmdline_credentials, ev_ctx, cmdline_lp_ctx); } if (ctx->registry == NULL) return 1; if (ctx->current == NULL) { unsigned int i; for (i = 0; (reg_predefined_keys[i].handle != 0) && (ctx->current == NULL); i++) { WERROR err; err = reg_get_predefined_key(ctx->registry, reg_predefined_keys[i].handle, &ctx->current); if (W_ERROR_IS_OK(err)) { ctx->predef = talloc_strdup(ctx, reg_predefined_keys[i].name); ctx->path = talloc_strdup(ctx, ""); ctx->root = ctx->current; break; } else { ctx->current = NULL; ctx->root = NULL; } } } if (ctx->current == NULL) { fprintf(stderr, "Unable to access any of the predefined keys\n"); return 1; } poptFreeContext(pc); while (true) { char *line, *prompt; if (asprintf(&prompt, "%s\\%s> ", ctx->predef?ctx->predef:"", ctx->path) < 0) { ret = false; break; } current_key = ctx->current; /* No way to pass a void * pointer via readline :-( */ line = smb_readline(prompt, NULL, reg_completion); if (line == NULL) { free(prompt); break; } if (line[0] != '\n') { ret = W_ERROR_IS_OK(process_cmd(ctx, line)); } free(line); free(prompt); } talloc_free(ctx); return (ret?0:1); }