static bool test_reg_val_description_nullname(struct torture_context *ctx) { struct registry_value val; val.name = NULL; val.data_type = REG_SZ; val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", strlen("west berlin"), (void **)&val.data.data); torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin", reg_val_description(ctx, &val), "description with null name failed"); return true; }
static bool test_reg_val_description(struct torture_context *ctx) { struct registry_value val; val.name = "camel"; val.data_type = REG_SZ; val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "stationary traveller", strlen("stationary traveller"), (void **)&val.data.data); torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", reg_val_description(ctx, &val), "reg_val_description failed"); return true; }
/** * Print a registry key recursively * * @param level Level at which to print * @param p Key to print * @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(unsigned int level, struct registry_key *p, const char *name, bool fullpath, bool novals) { struct registry_key *subkey; const char *valuename, *keyname; uint32_t valuetype; DATA_BLOB valuedata; struct security_descriptor *sec_desc; WERROR error; unsigned int i; TALLOC_CTX *mem_ctx; for(i = 0; i < level; i++) putchar(' '); puts(name); mem_ctx = talloc_init("print_tree"); for (i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, p, i, &keyname, NULL, NULL)); i++) { SMB_ASSERT(strlen(keyname) > 0); if (!W_ERROR_IS_OK(reg_open_key(mem_ctx, p, keyname, &subkey))) continue; print_tree(level+1, subkey, (fullpath && strlen(name))? 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 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, &valuetype, &valuedata)); i++) { unsigned int j; for(j = 0; j < level+1; j++) putchar(' '); 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 occurred while fetching values for '%s': %s\n", name, win_errstr(error))); } } mem_ctx = talloc_init("sec_desc"); if (!W_ERROR_IS_OK(reg_get_sec_desc(mem_ctx, p, &sec_desc))) { DEBUG(0, ("Error getting security descriptor\n")); } talloc_free(mem_ctx); }