summaryrefslogtreecommitdiff
path: root/source4/lib/registry
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2004-04-09 00:02:20 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:09 -0500
commit9cbbf2d55253783adaeceac9bc2f8c9ffe40aa94 (patch)
treea3973398a951f2debaff0e887512d577b60d5365 /source4/lib/registry
parentaebfb3b9f415d3c1f6b2a39aee27b072d48893cb (diff)
downloadsamba-9cbbf2d55253783adaeceac9bc2f8c9ffe40aa94.tar.gz
samba-9cbbf2d55253783adaeceac9bc2f8c9ffe40aa94.tar.bz2
samba-9cbbf2d55253783adaeceac9bc2f8c9ffe40aa94.zip
r129: Convert other utilities to new API
(This used to be commit 95c9852b1607335eb24025081a251139449fb695)
Diffstat (limited to 'source4/lib/registry')
-rw-r--r--source4/lib/registry/tools/regdiff.c93
-rw-r--r--source4/lib/registry/tools/regpatch.c77
-rw-r--r--source4/lib/registry/tools/regshell.c47
-rw-r--r--source4/lib/registry/tools/regtree.c33
4 files changed, 169 insertions, 81 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;
}
diff --git a/source4/lib/registry/tools/regpatch.c b/source4/lib/registry/tools/regpatch.c
index 27f578e37f..9a51b0f7ff 100644
--- a/source4/lib/registry/tools/regpatch.c
+++ b/source4/lib/registry/tools/regpatch.c
@@ -664,11 +664,13 @@ static CMD_FILE *cmd_file_create(const char *file)
char *str_type(unsigned char type);
-int nt_apply_reg_command_file(REG_HANDLE *regf, const char *cmd_file_name)
+int nt_apply_reg_command_file(REG_KEY *root, const char *cmd_file_name)
{
CMD *cmd;
- int modified = 0;
+ BOOL modified = False;
CMD_FILE *cmd_file = NULL;
+ REG_KEY *tmp = NULL;
+ WERROR error;
cmd_file = cmd_file_create(cmd_file_name);
while ((cmd = cmd_file->cmd_ops.get_cmd(cmd_file->fd)) != NULL) {
@@ -677,17 +679,22 @@ int nt_apply_reg_command_file(REG_HANDLE *regf, const char *cmd_file_name)
* Now, apply the requests to the tree ...
*/
switch (cmd->cmd) {
- case CMD_ADD_KEY: {
- REG_KEY *tmp = NULL;
- tmp = reg_open_key(reg_get_root(regf), cmd->key);
+ case CMD_ADD_KEY:
+ error = reg_open_key(root, cmd->key, &tmp);
+
/* If we found it, apply the other bits, else create such a key */
- if (!tmp) {
- if(reg_key_add_name_recursive(reg_get_root(regf), cmd->key)) {
- tmp = reg_open_key(reg_get_root(regf), cmd->key);
+ if (W_ERROR_EQUAL(error, WERR_DEST_NOT_FOUND)) {
+ if(W_ERROR_IS_OK(reg_key_add_name_recursive(root, cmd->key))) {
+ error = reg_open_key(root, 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;
+ }
} else {
DEBUG(0, ("Error adding new key '%s'\n", cmd->key));
+ continue;
}
- modified = 1;
+ modified = True;
}
while (cmd->val_count) {
@@ -695,15 +702,21 @@ int nt_apply_reg_command_file(REG_HANDLE *regf, const char *cmd_file_name)
REG_VAL *reg_val = NULL;
if (val->type == REG_DELETE) {
- reg_val = reg_key_get_value_by_name( tmp, val->name);
- reg_val_del(reg_val);
- modified = 1;
+ error = reg_key_get_value_by_name( tmp, val->name, &reg_val);
+ if(W_ERROR_IS_OK(error)) {
+ error = reg_val_del(reg_val);
+ }
+ if(!W_ERROR_IS_OK(error)) {
+ DEBUG(0, ("Error removing value '%s'\n", val->name));
+ }
+ modified = True;
}
else {
- /* FIXME
- reg_val = nt_add_reg_value(tmp, val->name, val->type,
- val->val); */
- modified = 1;
+ if(!W_ERROR_IS_OK(reg_key_add_value(tmp, val->name, val->type, val->val, strlen(val->val)))) {
+ DEBUG(0, ("Error adding new value '%s'\n", val->name));
+ continue;
+ }
+ modified = True;
}
cmd->val_spec_list = val->next;
@@ -712,7 +725,6 @@ int nt_apply_reg_command_file(REG_HANDLE *regf, const char *cmd_file_name)
}
break;
- }
case CMD_DEL_KEY:
/*
@@ -720,8 +732,18 @@ int nt_apply_reg_command_file(REG_HANDLE *regf, const char *cmd_file_name)
* Find the key if it exists, and delete it ...
*/
- reg_key_del_recursive(reg_open_key(reg_get_root(regf), cmd->key));
- modified = 1;
+ error = reg_open_key(root, cmd->key, &tmp);
+ if(!W_ERROR_IS_OK(error)) {
+ DEBUG(0, ("Unable to open key '%s'\n", cmd->key));
+ continue;
+ }
+
+ error = reg_key_del_recursive(tmp);
+ if(!W_ERROR_IS_OK(error)) {
+ DEBUG(0, ("Unable to delete key '%s'\n", cmd->key));
+ continue;
+ }
+ modified = True;
break;
}
}
@@ -737,13 +759,16 @@ int main (int argc, char **argv)
poptContext pc;
REG_KEY *root;
const char *location;
+ const char *credentials = NULL;
const char *patch;
- char *backend = "dir";
+ const char *backend = "dir";
REG_HANDLE *h;
int fullpath = 0, no_values = 0;
+ WERROR error;
struct poptOption long_options[] = {
POPT_AUTOHELP
{"backend", 'b', POPT_ARG_STRING, &backend, 'b', "backend to use", NULL},
+ {"credentials", 'c', POPT_ARG_STRING, &credentials, 'c', "credentials (user%password", NULL},
POPT_TABLEEND
};
@@ -760,7 +785,7 @@ int main (int argc, char **argv)
return 1;
}
- h = reg_open(backend, location, True);
+ error = reg_open(backend, location, credentials, &h);
if(!h) {
fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location, backend);
return 1;
@@ -770,7 +795,15 @@ int main (int argc, char **argv)
if(!patch) patch = "/dev/stdin";
poptFreeContext(pc);
- nt_apply_reg_command_file(h, patch);
+ error = reg_get_root(h, &root);
+ if(!W_ERROR_IS_OK(error)) {
+ DEBUG(0, ("Error opening root!\n"));
+ return 1;
+ }
+
+ nt_apply_reg_command_file(root, patch);
+
+ reg_free(h);
return 0;
}
diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c
index e6b5fa51ee..d60ca1ff46 100644
--- a/source4/lib/registry/tools/regshell.c
+++ b/source4/lib/registry/tools/regshell.c
@@ -40,10 +40,14 @@ static REG_KEY *cmd_set(REG_KEY *cur, int argc, char **argv)
static REG_KEY *cmd_ck(REG_KEY *cur, int argc, char **argv)
{
REG_KEY *new;
+ WERROR error;
if(argc < 2) {
new = cur;
} else {
- new = reg_open_key(cur, argv[1]);
+ error = reg_open_key(cur, argv[1], &new);
+ if(!W_ERROR_IS_OK(error)) {
+ DEBUG(0, ("Error opening specified key\n"));
+ }
}
if(!new) new = cur;
@@ -56,28 +60,32 @@ static REG_KEY *cmd_ck(REG_KEY *cur, int argc, char **argv)
static REG_KEY *cmd_ls(REG_KEY *cur, int argc, char **argv)
{
int i, num;
- num = reg_key_num_subkeys(cur);
- for(i = 0; i < num; i++) {
- REG_KEY *sub = reg_key_get_subkey_by_index(cur, 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));
}
- num = reg_key_num_values(cur);
- for(i = 0; i < num; i++) {
- REG_VAL *sub = reg_key_get_value_by_index(cur, i);
- printf("V %s %s %s\n", reg_val_name(sub), str_regtype(reg_val_type(sub)), reg_val_data_string(sub));
+ if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while browsing thru keys\n"));
+ }
+
+ 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));
}
return NULL;
}
static REG_KEY *cmd_mkkey(REG_KEY *cur, int argc, char **argv)
{
+ REG_KEY *tmp;
if(argc < 2) {
fprintf(stderr, "Usage: mkkey <keyname>\n");
return NULL;
}
- if(!reg_key_add_name(cur, argv[1])) {
+ if(!W_ERROR_IS_OK(reg_key_add_name(cur, argv[1], 0, NULL, &tmp))) {
fprintf(stderr, "Error adding new subkey '%s'\n", argv[1]);
return NULL;
}
@@ -95,13 +103,12 @@ static REG_KEY *cmd_rmkey(REG_KEY *cur, int argc, char **argv)
return NULL;
}
- key = reg_open_key(cur, argv[1]);
- if(!key) {
+ if(!W_ERROR_IS_OK(reg_open_key(cur, argv[1], &key))) {
fprintf(stderr, "No such subkey '%s'\n", argv[1]);
return NULL;
}
- if(!reg_key_del(key)) {
+ if(!W_ERROR_IS_OK(reg_key_del(key))) {
fprintf(stderr, "Error deleting '%s'\n", argv[1]);
} else {
fprintf(stderr, "Successfully deleted '%s'\n", argv[1]);
@@ -118,13 +125,12 @@ static REG_KEY *cmd_rmval(REG_KEY *cur, int argc, char **argv)
return NULL;
}
- val = reg_key_get_value_by_name(cur, argv[1]);
- if(!val) {
+ if(!W_ERROR_IS_OK(reg_key_get_value_by_name(cur, argv[1], &val))) {
fprintf(stderr, "No such value '%s'\n", argv[1]);
return NULL;
}
- if(!reg_val_del(val)) {
+ if(!W_ERROR_IS_OK(reg_val_del(val))) {
fprintf(stderr, "Error deleting value '%s'\n", argv[1]);
} else {
fprintf(stderr, "Successfully deleted value '%s'\n", argv[1]);
@@ -196,13 +202,16 @@ int main (int argc, char **argv)
uint32 setparms, checkparms;
int opt;
char *backend = "dir";
+ char *credentials = NULL;
REG_KEY *curkey = NULL;;
poptContext pc;
+ WERROR error;
REG_HANDLE *h;
struct poptOption long_options[] = {
POPT_AUTOHELP
POPT_COMMON_SAMBA
{"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
+ {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials", NULL},
POPT_TABLEEND
};
@@ -211,8 +220,8 @@ int main (int argc, char **argv)
while((opt = poptGetNextOpt(pc)) != -1) {
}
- h = reg_open(backend, poptPeekArg(pc), True);
- if(!h) {
+ error = reg_open(backend, poptPeekArg(pc), credentials, &h);
+ if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Unable to open '%s' with backend '%s'\n", poptGetArg(pc), backend);
return 1;
}
@@ -220,9 +229,9 @@ int main (int argc, char **argv)
setup_logging("regtree", True);
- curkey = reg_get_root(h);
+ error = reg_get_root(h, &curkey);
- if(!curkey) return 1;
+ if(!W_ERROR_IS_OK(error)) return 1;
while(True) {
char *line, *prompt;
diff --git a/source4/lib/registry/tools/regtree.c b/source4/lib/registry/tools/regtree.c
index 80cbccf48f..548a702d48 100644
--- a/source4/lib/registry/tools/regtree.c
+++ b/source4/lib/registry/tools/regtree.c
@@ -23,31 +23,38 @@
void print_tree(int l, REG_KEY *p, int fullpath, int novals)
{
- int num_subkeys, i, num_values;
+ REG_KEY *subkey;
+ REG_VAL *value;
+ WERROR error;
+ int i;
for(i = 0; i < l; i++) putchar(' ');
if(fullpath) printf("%s\n", reg_key_get_path(p));
else printf("%s\n", reg_key_name(p));
- num_subkeys = reg_key_num_subkeys(p);
- for(i = 0; i < num_subkeys; i++) {
- REG_KEY *subkey = reg_key_get_subkey_by_index(p, i);
+ for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(p, i, &subkey)); i++) {
print_tree(l+1, subkey, fullpath, novals);
reg_key_free(subkey);
}
+ if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while fetching subkeys for '%s'\n", reg_key_get_path(p)));
+ }
+
if(!novals) {
- num_values = reg_key_num_values(p);
- for(i = 0; i < num_values; i++) {
+ for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(p, i, &value)); i++) {
int j;
char *desc;
- REG_VAL *value = reg_key_get_value_by_index(p, i);
for(j = 0; j < l+1; j++) putchar(' ');
desc = reg_val_description(value);
printf("%s\n", desc);
free(desc);
reg_val_free(value);
}
+
+ if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
+ DEBUG(0, ("Error occured while fetching subkeys for '%s'\n", reg_key_get_path(p)));
+ }
}
}
@@ -55,15 +62,17 @@ int main (int argc, char **argv)
{
uint32 setparms, checkparms;
int opt;
- char *backend = "dir";
+ char *backend = "dir", *credentials = NULL;
poptContext pc;
REG_KEY *root;
REG_HANDLE *h;
+ WERROR error;
int fullpath = 0, no_values = 0;
struct poptOption long_options[] = {
POPT_AUTOHELP
{"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
{"fullpath", 'f', POPT_ARG_NONE, &fullpath, 0, "show full paths", NULL},
+ {"credentials", 'c', POPT_ARG_NONE, &credentials, 0, "credentials (user%password)", NULL},
{"no-values", 'V', POPT_ARG_NONE, &no_values, 0, "don't show values", NULL},
POPT_TABLEEND
};
@@ -75,15 +84,15 @@ int main (int argc, char **argv)
setup_logging("regtree", True);
- h = reg_open(backend, poptPeekArg(pc), True);
- if(!h) {
+ error = reg_open(backend, poptPeekArg(pc), credentials, &h);
+ if(!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Unable to open '%s' with backend '%s'\n", poptGetArg(pc), backend);
return 1;
}
poptFreeContext(pc);
- root = reg_get_root(h);
- if(!root) return 1;
+ error = reg_get_root(h, &root);
+ if(!W_ERROR_IS_OK(error)) return 1;
print_tree(0, root, fullpath, no_values);