diff options
Diffstat (limited to 'source4/lib/registry/tools')
-rw-r--r-- | source4/lib/registry/tools/regdiff.c | 76 | ||||
-rw-r--r-- | source4/lib/registry/tools/regpatch.c | 31 | ||||
-rw-r--r-- | source4/lib/registry/tools/regshell.c | 128 | ||||
-rw-r--r-- | source4/lib/registry/tools/regtree.c | 50 |
4 files changed, 158 insertions, 127 deletions
diff --git a/source4/lib/registry/tools/regdiff.c b/source4/lib/registry/tools/regdiff.c index c46411ae31..524e538591 100644 --- a/source4/lib/registry/tools/regdiff.c +++ b/source4/lib/registry/tools/regdiff.c @@ -21,47 +21,57 @@ #include "includes.h" -static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) +static void writediff(struct registry_key *oldkey, struct registry_key *newkey, FILE *out) { int i; - REG_KEY *t1, *t2; - REG_VAL *v1, *v2; + struct registry_key *t1, *t2; + struct registry_value *v1, *v2; WERROR error1, error2; + TALLOC_CTX *mem_ctx = talloc_init("writediff"); - 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); + for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(mem_ctx, oldkey, i, &t1)); i++) { + error2 = reg_key_get_subkey_by_name(mem_ctx, newkey, t1->name, &t2); if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) { - fprintf(out, "-%s\n", reg_key_get_path(t1)+1); + fprintf(out, "-%s\n", t1->path+1); } else if(!W_ERROR_IS_OK(error2)) { DEBUG(0, ("Error occured while getting subkey by name: %d\n", W_ERROR_V(error2))); } } + talloc_destroy(mem_ctx); + if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) { DEBUG(0, ("Error occured while getting subkey by index: %d\n", W_ERROR_V(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); + mem_ctx = talloc_init("writediff"); + + for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_subkey_by_index(mem_ctx, newkey, i, &t1)); i++) { + error2 = reg_key_get_subkey_by_name(mem_ctx, oldkey, t1->name, &t2); if(W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) { - fprintf(out, "\n[%s]\n", reg_key_get_path(t1)+1); + fprintf(out, "\n[%s]\n", t1->path+1); } else if(!W_ERROR_IS_OK(error2)) { DEBUG(0, ("Error occured while getting subkey by name: %d\n", W_ERROR_V(error2))); } writediff(t2, t1, out); } + talloc_destroy(mem_ctx); + if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) { DEBUG(0, ("Error occured while getting subkey by index: %d\n", W_ERROR_V(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)))) + + mem_ctx = talloc_init("writediff"); + + for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, newkey, i, &v1)); i++) { + error2 = reg_key_get_value_by_name(mem_ctx, oldkey, v1->name, &v2); + if ((W_ERROR_IS_OK(error2) && (v2->data_len != v1->data_len || memcmp(v1->data_blk, v2->data_blk, v1->data_len))) || 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)); + fprintf(out, "\"%s\"=%s:%s\n", v1->name, str_regtype(v1->data_type), reg_val_data_string(mem_ctx, v1)); } if(!W_ERROR_IS_OK(error2) && !W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) { @@ -69,22 +79,27 @@ static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) } } + talloc_destroy(mem_ctx); + if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) { DEBUG(0, ("Error occured while getting value by index: %d\n", W_ERROR_V(error1))); return; } + mem_ctx = talloc_init("writediff"); - 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); + for(i = 0; W_ERROR_IS_OK(error1 = reg_key_get_value_by_index(mem_ctx, oldkey, i, &v1)); i++) { + error2 = reg_key_get_value_by_name(mem_ctx, newkey, v1->name, &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)); + fprintf(out, "\"%s\"=-\n", v1->name); } else { DEBUG(0, ("Error occured while getting value by name: %d\n", W_ERROR_V(error2))); } } + talloc_destroy(mem_ctx); + if(!W_ERROR_EQUAL(error1, WERR_NO_MORE_ITEMS)) { DEBUG(0, ("Error occured while getting value by index: %d\n", W_ERROR_V(error1))); return; @@ -100,8 +115,7 @@ static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) const char *credentials1= NULL, *credentials2 = NULL; char *outputfile = NULL; FILE *fd = stdout; - REG_HANDLE *h1, *h2; - REG_KEY *root1 = NULL, *root2; + struct registry_context *h1, *h2; int from_null = 0; int i; WERROR error, error2; @@ -114,6 +128,12 @@ static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) POPT_TABLEEND }; + + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + } + + pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { @@ -140,7 +160,7 @@ static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) if(!backend1) backend1 = "dir"; - error = reg_open(backend1, location1, credentials1, &h1); + error = reg_open(&h1, backend1, location1, credentials1); if(!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location1, backend1); return 1; @@ -155,7 +175,7 @@ static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) if(!backend2) backend2 = "dir"; - error = reg_open(backend2, location2, credentials2, &h2); + error = reg_open(&h2, backend2, location2, credentials2); if(!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location2, backend2); return 1; @@ -176,20 +196,8 @@ static void writediff(REG_KEY *oldkey, REG_KEY *newkey, FILE *out) error2 = error = WERR_OK; - for(i = 0; ; i++) { - if(backend1) error = reg_get_hive(h1, i, &root1); - else root1 = NULL; - - if(!W_ERROR_IS_OK(error)) break; - - if(backend2) error2 = reg_get_hive(h2, i, &root2); - else root2 = NULL; - - if(!W_ERROR_IS_OK(error2)) break; - - writediff(root1, root2, fd); - - if(!root1 && !root2) break; + for(i = 0; i < h1->num_hives && i < h2->num_hives; i++) { + writediff(h1->hives[i]->root, h2->hives[i]->root, fd); } fclose(fd); diff --git a/source4/lib/registry/tools/regpatch.c b/source4/lib/registry/tools/regpatch.c index 7eddea2b93..1b33628a71 100644 --- a/source4/lib/registry/tools/regpatch.c +++ b/source4/lib/registry/tools/regpatch.c @@ -664,12 +664,13 @@ static CMD_FILE *cmd_file_create(const char *file) char *str_type(uint8_t type); -static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) +static int nt_apply_reg_command_file(struct registry_context *r, const char *cmd_file_name) { CMD *cmd; BOOL modified = False; CMD_FILE *cmd_file = NULL; - REG_KEY *tmp = NULL; + TALLOC_CTX *mem_ctx = talloc_init("apply_cmd_file"); + struct registry_key *tmp = NULL; WERROR error; cmd_file = cmd_file_create(cmd_file_name); @@ -680,12 +681,12 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) */ switch (cmd->cmd) { case CMD_ADD_KEY: - error = reg_open_key_abs(r, cmd->key, &tmp); + error = reg_open_key_abs(mem_ctx, r, cmd->key, &tmp); /* If we found it, apply the other bits, else create such a key */ if (W_ERROR_EQUAL(error, WERR_DEST_NOT_FOUND)) { if(W_ERROR_IS_OK(reg_key_add_name_recursive_abs(r, cmd->key))) { - error = reg_open_key_abs(r, cmd->key, &tmp); + error = reg_open_key_abs(mem_ctx, r, cmd->key, &tmp); if(!W_ERROR_IS_OK(error)) { DEBUG(0, ("Error finding new key '%s' after it has been added\n", cmd->key)); continue; @@ -699,12 +700,12 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) while (cmd->val_count) { VAL_SPEC_LIST *val = cmd->val_spec_list; - REG_VAL *reg_val = NULL; + struct registry_value *reg_val = NULL; if (val->type == REG_DELETE) { - error = reg_key_get_value_by_name( tmp, val->name, ®_val); + error = reg_key_get_value_by_name( mem_ctx, tmp, val->name, ®_val); if(W_ERROR_IS_OK(error)) { - error = reg_val_del(reg_val); + error = reg_del_value(reg_val); } if(!W_ERROR_IS_OK(error)) { DEBUG(0, ("Error removing value '%s'\n", val->name)); @@ -712,7 +713,7 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) modified = True; } else { - if(!W_ERROR_IS_OK(reg_key_add_value(tmp, val->name, val->type, val->val, strlen(val->val)))) { + if(!W_ERROR_IS_OK(reg_val_set(tmp, val->name, val->type, val->val, strlen(val->val)))) { DEBUG(0, ("Error adding new value '%s'\n", val->name)); continue; } @@ -732,7 +733,7 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) * Find the key if it exists, and delete it ... */ - error = reg_open_key_abs(r, cmd->key, &tmp); + error = reg_open_key_abs(mem_ctx, r, cmd->key, &tmp); if(!W_ERROR_IS_OK(error)) { DEBUG(0, ("Unable to open key '%s'\n", cmd->key)); continue; @@ -760,7 +761,7 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) const char *credentials = NULL; const char *patch; const char *backend = "dir"; - REG_HANDLE *h; + struct registry_context *h; WERROR error; struct poptOption long_options[] = { POPT_AUTOHELP @@ -769,6 +770,12 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) POPT_TABLEEND }; + + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + } + + pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { @@ -782,7 +789,7 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) return 1; } - error = reg_open(backend, location, credentials, &h); + error = reg_open(&h, backend, location, credentials); if(!h) { fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location, backend); return 1; @@ -794,7 +801,7 @@ static int nt_apply_reg_command_file(REG_HANDLE *r, const char *cmd_file_name) nt_apply_reg_command_file(h, patch); - reg_free(h); + talloc_destroy(h->mem_ctx); return 0; } diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c index 638ed70d5e..78fe36f1a0 100644 --- a/source4/lib/registry/tools/regshell.c +++ b/source4/lib/registry/tools/regshell.c @@ -33,96 +33,96 @@ * exit */ -static REG_KEY *cmd_info(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_info(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { time_t last_mod; - printf("Name: %s\n", reg_key_name(cur)); - printf("Full path: %s\n", reg_key_get_path(cur)); - printf("Key Class: %s\n", reg_key_class(cur)); - last_mod = nt_time_to_unix(reg_key_last_modified(cur)); + printf("Name: %s\n", cur->name); + printf("Full path: %s\n", cur->path); + printf("Key Class: %s\n", cur->class_name); + last_mod = nt_time_to_unix(cur->last_mod); printf("Time Last Modified: %s\n", ctime(&last_mod)); /* FIXME: Security info */ return cur; } -static REG_KEY *cmd_pwd(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_pwd(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { - printf("%s\n", reg_key_get_path_abs(cur)); + printf("%s\n", cur->path); return cur; } -static REG_KEY *cmd_set(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_set(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { /* FIXME */ return NULL; } -static REG_KEY *cmd_ck(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_ck(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { - REG_KEY *new = NULL; + struct registry_key *new = NULL; WERROR error; if(argc < 2) { new = cur; } else { - error = reg_open_key(cur, argv[1], &new); + error = reg_open_key(mem_ctx, cur, argv[1], &new); if(!W_ERROR_IS_OK(error)) { DEBUG(0, ("Error opening specified key: %s\n", win_errstr(error))); return NULL; } } - printf("Current path is: %s\n", reg_key_get_path_abs(new)); + printf("Current path is: %s\n", new->path); return new; } -static REG_KEY *cmd_ls(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_ls(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { int i; WERROR error; - REG_VAL *value; - REG_KEY *sub; - for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(cur, i, &sub)); i++) { - printf("K %s\n", reg_key_name(sub)); + struct registry_value *value; + struct registry_key *sub; + for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, cur, i, &sub)); i++) { + printf("K %s\n", sub->name); } if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { DEBUG(0, ("Error occured while browsing thru keys: %s\n", win_errstr(error))); } - for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(cur, i, &value)); i++) { - printf("V \"%s\" %s %s\n", reg_val_name(value), str_regtype(reg_val_type(value)), reg_val_data_string(value)); + for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(mem_ctx, cur, i, &value)); i++) { + printf("V \"%s\" %s %s\n", value->name, str_regtype(value->data_type), reg_val_data_string(mem_ctx, value)); } return NULL; } -static REG_KEY *cmd_mkkey(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_mkkey(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { - REG_KEY *tmp; + struct registry_key *tmp; if(argc < 2) { fprintf(stderr, "Usage: mkkey <keyname>\n"); return NULL; } - if(!W_ERROR_IS_OK(reg_key_add_name(cur, argv[1], 0, NULL, &tmp))) { + if(!W_ERROR_IS_OK(reg_key_add_name(mem_ctx, cur, argv[1], 0, NULL, &tmp))) { fprintf(stderr, "Error adding new subkey '%s'\n", argv[1]); return NULL; } - fprintf(stderr, "Successfully added new subkey '%s' to '%s'\n", argv[1], reg_key_get_path_abs(cur)); + fprintf(stderr, "Successfully added new subkey '%s' to '%s'\n", argv[1], cur->path); return NULL; } -static REG_KEY *cmd_rmkey(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_rmkey(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { - REG_KEY *key; + struct registry_key *key; if(argc < 2) { fprintf(stderr, "Usage: rmkey <name>\n"); return NULL; } - if(!W_ERROR_IS_OK(reg_open_key(cur, argv[1], &key))) { + if(!W_ERROR_IS_OK(reg_open_key(mem_ctx, cur, argv[1], &key))) { fprintf(stderr, "No such subkey '%s'\n", argv[1]); return NULL; } @@ -136,20 +136,20 @@ static REG_KEY *cmd_rmkey(REG_KEY *cur, int argc, char **argv) return NULL; } -static REG_KEY *cmd_rmval(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_rmval(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { - REG_VAL *val; + struct registry_value *val; if(argc < 2) { fprintf(stderr, "Usage: rmval <valuename>\n"); return NULL; } - if(!W_ERROR_IS_OK(reg_key_get_value_by_name(cur, argv[1], &val))) { + if(!W_ERROR_IS_OK(reg_key_get_value_by_name(mem_ctx, cur, argv[1], &val))) { fprintf(stderr, "No such value '%s'\n", argv[1]); return NULL; } - if(!W_ERROR_IS_OK(reg_val_del(val))) { + if(!W_ERROR_IS_OK(reg_del_value(val))) { fprintf(stderr, "Error deleting value '%s'\n", argv[1]); } else { fprintf(stderr, "Successfully deleted value '%s'\n", argv[1]); @@ -158,38 +158,33 @@ static REG_KEY *cmd_rmval(REG_KEY *cur, int argc, char **argv) return NULL; } -static REG_KEY *cmd_hive(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_hive(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { int i; - WERROR error = WERR_OK; - for(i = 0; W_ERROR_IS_OK(error); i++) { - REG_KEY *hive; - error = reg_get_hive(reg_key_handle(cur), i, &hive); - if(!W_ERROR_IS_OK(error)) break; + for(i = 0; i < cur->hive->reg_ctx->num_hives; i++) { if(argc == 1) { - printf("%s\n", reg_key_name(hive)); - } else if(!strcmp(reg_key_name(hive), argv[1])) { - return hive; + printf("%s\n", cur->hive->reg_ctx->hives[i]->name); + } else if(!strcmp(cur->hive->reg_ctx->hives[i]->name, argv[1])) { + return cur->hive->reg_ctx->hives[i]->root; } - reg_key_free(hive); } return NULL; } -static REG_KEY *cmd_exit(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_exit(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { exit(0); return NULL; } -static REG_KEY *cmd_help(REG_KEY *, int, char **); +static struct registry_key *cmd_help(TALLOC_CTX *mem_ctx, struct registry_key *, int, char **); struct { const char *name; const char *alias; const char *help; - REG_KEY *(*handle)(REG_KEY *, int argc, char **argv); + struct registry_key *(*handle)(TALLOC_CTX *mem_ctx, struct registry_key *, int argc, char **argv); } regshell_cmds[] = { {"ck", "cd", "Change current key", cmd_ck }, {"ch", "hive", "Change current hive", cmd_hive }, @@ -205,7 +200,7 @@ struct { {NULL } }; -static REG_KEY *cmd_help(REG_KEY *cur, int argc, char **argv) +static struct registry_key *cmd_help(TALLOC_CTX *mem_ctx, struct registry_key *cur, int argc, char **argv) { int i; printf("Available commands:\n"); @@ -215,7 +210,7 @@ static REG_KEY *cmd_help(REG_KEY *cur, int argc, char **argv) return NULL; } -static REG_KEY *process_cmd(REG_KEY *k, char *line) +static struct registry_key *process_cmd(TALLOC_CTX *mem_ctx, struct registry_key *k, char *line) { int argc; char **argv = NULL; @@ -229,7 +224,7 @@ static REG_KEY *process_cmd(REG_KEY *k, char *line) for(i = 0; regshell_cmds[i].name; i++) { if(!strcmp(regshell_cmds[i].name, argv[0]) || (regshell_cmds[i].alias && !strcmp(regshell_cmds[i].alias, argv[0]))) { - return regshell_cmds[i].handle(k, argc, argv); + return regshell_cmds[i].handle(mem_ctx, k, argc, argv); } } @@ -240,7 +235,7 @@ static REG_KEY *process_cmd(REG_KEY *k, char *line) #define MAX_COMPLETIONS 100 -static REG_KEY *current_key = NULL; +static struct registry_key *current_key = NULL; static char **reg_complete_command(const char *text, int end) { @@ -295,10 +290,11 @@ cleanup: static char **reg_complete_key(const char *text, int end) { - REG_KEY *subkey; + struct registry_key *subkey; int i, j = 0; int len; char **matches; + TALLOC_CTX *mem_ctx; /* Complete argument */ matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS); @@ -306,22 +302,24 @@ static char **reg_complete_key(const char *text, int end) matches[0] = NULL; len = strlen(text); + mem_ctx = talloc_init("completion"); for(i = 0; j < MAX_COMPLETIONS-1; i++) { - WERROR status = reg_key_get_subkey_by_index(current_key, i, &subkey); + WERROR status = reg_key_get_subkey_by_index(mem_ctx, current_key, i, &subkey); if(W_ERROR_IS_OK(status)) { - if(!strncmp(text, reg_key_name(subkey), len)) { - matches[j] = strdup(reg_key_name(subkey)); + if(!strncmp(text, subkey->name, len)) { + matches[j] = strdup(subkey->name); j++; } - reg_key_free(subkey); } else if(W_ERROR_EQUAL(status, WERR_NO_MORE_ITEMS)) { break; } else { printf("Error creating completion list: %s\n", win_errstr(status)); + talloc_destroy(mem_ctx); return NULL; } } matches[j] = NULL; + talloc_destroy(mem_ctx); return matches; } @@ -341,10 +339,11 @@ static char **reg_completion(const char *text, int start, int end) int opt; const char *backend = "dir"; const char *credentials = NULL; - REG_KEY *curkey = NULL; + struct registry_key *curkey = NULL; poptContext pc; WERROR error; - REG_HANDLE *h; + TALLOC_CTX *mem_ctx = talloc_init("cmd"); + struct registry_context *h; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_SAMBA @@ -352,13 +351,19 @@ static char **reg_completion(const char *text, int start, int end) {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials", NULL}, POPT_TABLEEND }; + + + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + } + pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } - error = reg_open(backend, poptPeekArg(pc), credentials, &h); + error = reg_open(&h, backend, poptPeekArg(pc), credentials); if(!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to open '%s' with backend '%s'\n", poptGetArg(pc), backend); return 1; @@ -367,14 +372,16 @@ static char **reg_completion(const char *text, int start, int end) setup_logging("regtree", True); - error = reg_get_hive(h, 0, &curkey); - - if(!W_ERROR_IS_OK(error)) return 1; + curkey = h->hives[0]->root; while(True) { char *line, *prompt; - asprintf(&prompt, "%s> ", reg_key_get_path_abs(curkey)); + if(curkey->hive->name) { + asprintf(&prompt, "%s:%s> ", curkey->hive->name, curkey->path); + } else { + asprintf(&prompt, "%s> ", curkey->path); + } current_key = curkey; /* No way to pass a void * pointer via readline :-( */ @@ -384,10 +391,11 @@ static char **reg_completion(const char *text, int start, int end) break; if(line[0] != '\n') { - REG_KEY *new = process_cmd(curkey, line); + struct registry_key *new = process_cmd(mem_ctx, curkey, line); if(new)curkey = new; } } + talloc_destroy(mem_ctx); return 0; } diff --git a/source4/lib/registry/tools/regtree.c b/source4/lib/registry/tools/regtree.c index b1ca9b3fb2..9748ca3438 100644 --- a/source4/lib/registry/tools/regtree.c +++ b/source4/lib/registry/tools/regtree.c @@ -21,39 +21,45 @@ #include "includes.h" -static void print_tree(int l, REG_KEY *p, int fullpath, int novals) +static void print_tree(int l, struct registry_key *p, int fullpath, int novals) { - REG_KEY *subkey; - REG_VAL *value; + struct registry_key *subkey; + struct registry_value *value; WERROR error; int i; + TALLOC_CTX *mem_ctx; for(i = 0; i < l; i++) putchar(' '); - if(fullpath) printf("%s\n", reg_key_get_path_abs(p)); - else printf("%s\n", reg_key_name(p)); + + /* Hive name */ + if(p->hive->root == p) printf("%s\n", p->hive->name); + else if(!p->name) printf("<No Name>\n"); + else if(fullpath) printf("%s\n", p->path); + else printf("%s\n", p->name); - for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(p, i, &subkey)); i++) { + mem_ctx = talloc_init("print_tree"); + for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, p, i, &subkey)); i++) { print_tree(l+1, subkey, fullpath, novals); - reg_key_free(subkey); } + talloc_destroy(mem_ctx); if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { - DEBUG(0, ("Error occured while fetching subkeys for '%s': %s\n", reg_key_get_path_abs(p), win_errstr(error))); + DEBUG(0, ("Error occured while fetching subkeys for '%s': %s\n", p->path, win_errstr(error))); } if(!novals) { - for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(p, i, &value)); i++) { + mem_ctx = talloc_init("print_tree"); + for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(mem_ctx, p, i, &value)); i++) { int j; char *desc; for(j = 0; j < l+1; j++) putchar(' '); - desc = reg_val_description(value); + desc = reg_val_description(mem_ctx, value); printf("%s\n", desc); - free(desc); - reg_val_free(value); } + talloc_destroy(mem_ctx); if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { - DEBUG(0, ("Error occured while fetching values for '%s': %s\n", reg_key_get_path_abs(p), win_errstr(error))); + DEBUG(0, ("Error occured while fetching values for '%s': %s\n", p->path, win_errstr(error))); } } } @@ -64,8 +70,7 @@ static void print_tree(int l, REG_KEY *p, int fullpath, int novals) const char *backend = "dir"; const char *credentials = NULL; poptContext pc; - REG_KEY *root; - REG_HANDLE *h; + struct registry_context *h; WERROR error; int fullpath = 0, no_values = 0; struct poptOption long_options[] = { @@ -77,6 +82,12 @@ static void print_tree(int l, REG_KEY *p, int fullpath, int novals) POPT_TABLEEND }; + + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + } + + pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { @@ -84,7 +95,7 @@ static void print_tree(int l, REG_KEY *p, int fullpath, int novals) setup_logging("regtree", True); - error = reg_open(backend, poptPeekArg(pc), credentials, &h); + error = reg_open(&h, backend, poptPeekArg(pc), credentials); if(!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to open '%s' with backend '%s':%s \n", poptGetArg(pc), backend, win_errstr(error)); return 1; @@ -93,11 +104,8 @@ static void print_tree(int l, REG_KEY *p, int fullpath, int novals) error = WERR_OK; - for(i = 0; W_ERROR_IS_OK(error); i++) { - error = reg_get_hive(h, i, &root); - if(!W_ERROR_IS_OK(error)) return 1; - - print_tree(0, root, fullpath, no_values); + for(i = 0; i < h->num_hives; i++) { + print_tree(0, h->hives[i]->root, fullpath, no_values); } return 0; |