Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / lib / registry / tools / regtree.c
index f95fc1968df13d649bc1734b0790e62bc068276d..68579406722dcfa7103a92938c8a6d008aea3c99 100644 (file)
  * @param fullpath Whether the full pat hshould be printed or just the last bit
  * @param novals Whether values should not be printed
  */
-static void print_tree(int level, struct registry_key *p,
+static void print_tree(unsigned int level, struct registry_key *p,
                       const char *name,
                       bool fullpath, bool novals)
 {
        struct registry_key *subkey;
-       const char *valuename;
-       const char *keyname;
-       uint32_t value_type;
-       DATA_BLOB value_data;
+       const char *valuename, *keyname;
+       uint32_t valuetype;
+       DATA_BLOB valuedata;
        struct security_descriptor *sec_desc;
        WERROR error;
-       int i;
+       unsigned int i;
        TALLOC_CTX *mem_ctx;
 
        for(i = 0; i < level; i++) putchar(' '); puts(name);
@@ -56,40 +55,38 @@ static void print_tree(int level, struct registry_key *p,
                                                                      &keyname,
                                                                      NULL,
                                                                      NULL)); i++) {
-               SMB_ASSERT(strlen(keyname) > 0);
+
+               SMB_ASSERT(strlen(keyname) > 0);
                if (!W_ERROR_IS_OK(reg_open_key(mem_ctx, p, keyname, &subkey)))
-                       continue;
+                       continue;
+
                print_tree(level+1, subkey, (fullpath && strlen(name))?
-                                               talloc_asprintf(mem_ctx, "%s\\%s",
-                                                               name, keyname):
-                                               keyname, fullpath, novals);
+                                               talloc_asprintf(mem_ctx, "%s\\%s",
+                                                               name, keyname):
+                                               keyname, fullpath, novals);
+               talloc_free(subkey);
        }
        talloc_free(mem_ctx);
 
        if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
-               DEBUG(0, ("Error occured while fetching subkeys for '%s': %s\n",
+               DEBUG(0, ("Error occurred while fetching subkeys for '%s': %s\n",
                                  name, win_errstr(error)));
        }
 
        if (!novals) {
                mem_ctx = talloc_init("print_tree");
-               for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(mem_ctx,
-                                                                           p,
-                                                                           i,
-                                                                           &valuename,
-                                                                           &value_type,
-                                                                           &value_data)); i++) {
-                       int j;
-                       char *desc;
+               for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(
+                       mem_ctx, p, i, &valuename, &valuetype, &valuedata));
+                       i++) {
+                       unsigned int j;
                        for(j = 0; j < level+1; j++) putchar(' ');
-                       desc = reg_val_description(mem_ctx, valuename,
-                                                  value_type, value_data);
-                       printf("%s\n", desc);
+                       printf("%s\n",  reg_val_description(mem_ctx,
+                               valuename, valuetype, valuedata));
                }
                talloc_free(mem_ctx);
 
                if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
-                       DEBUG(0, ("Error occured while fetching values for '%s': %s\n",
+                       DEBUG(0, ("Error occurred while fetching values for '%s': %s\n",
                                name, win_errstr(error)));
                }
        }
@@ -103,12 +100,14 @@ static void print_tree(int level, struct registry_key *p,
 
 int main(int argc, char **argv)
 {
-       int opt, i;
+       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[] = {
@@ -128,12 +127,14 @@ int main(int argc, char **argv)
        while((opt = poptGetNextOpt(pc)) != -1) {
        }
 
+       ev_ctx = s4_event_context_init(NULL);
+
        if (remote != NULL) {
-               h = reg_common_open_remote(remote, cmdline_credentials);
+               h = reg_common_open_remote(remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials);
        } else if (file != NULL) {
-               start_key = reg_common_open_file(file, cmdline_credentials);
+               start_key = reg_common_open_file(file, ev_ctx, cmdline_lp_ctx, cmdline_credentials);
        } else {
-               h = reg_common_open_local(cmdline_credentials, global_loadparm);
+               h = reg_common_open_local(cmdline_credentials, ev_ctx, cmdline_lp_ctx);
        }
 
        if (h == NULL && start_key == NULL)