svn_error_t * svn_repos_authz_parse(svn_authz_t **authz_p, svn_stream_t *stream, svn_stream_t *groups_stream, apr_pool_t *pool) { svn_authz_t *authz = apr_palloc(pool, sizeof(*authz)); /* Parse the authz stream */ SVN_ERR(svn_config_parse(&authz->cfg, stream, TRUE, TRUE, pool)); if (groups_stream) { svn_config_t *groups_cfg; /* Parse the groups stream */ SVN_ERR(svn_config_parse(&groups_cfg, groups_stream, TRUE, TRUE, pool)); SVN_ERR(authz_copy_groups(authz, groups_cfg, pool)); } /* Make sure there are no errors in the configuration. */ SVN_ERR(svn_repos__authz_validate(authz, pool)); *authz_p = authz; return SVN_NO_ERROR; }
static svn_error_t * test_serialization(apr_pool_t *pool) { svn_stringbuf_t *original_content; svn_stringbuf_t *written_content; svn_config_t *cfg; const struct { const char *section; const char *option; const char *value; } test_data[] = { { "my section", "value1", "some" }, { "my section", "value2", "something" }, { "another Section", "value1", "one" }, { "another Section", "value2", "two" }, { "another Section", "value 3", "more" }, }; int i; /* Format the original with the same formatting that the writer will use. */ original_content = svn_stringbuf_create("\n[my section]\n" "value1=some\n" "value2=%(value1)sthing\n" "\n[another Section]\n" "value1=one\n" "value2=two\n" "value 3=more\n", pool); written_content = svn_stringbuf_create_empty(pool); SVN_ERR(svn_config_parse(&cfg, svn_stream_from_stringbuf(original_content, pool), TRUE, TRUE, pool)); SVN_ERR(svn_config__write(svn_stream_from_stringbuf(written_content, pool), cfg, pool)); SVN_ERR(svn_config_parse(&cfg, svn_stream_from_stringbuf(written_content, pool), TRUE, TRUE, pool)); /* The serialized and re-parsed config must have the expected contents. */ for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); ++i) { const char *val; svn_config_get(cfg, &val, test_data[i].section, test_data[i].option, NULL); SVN_TEST_STRING_ASSERT(val, test_data[i].value); } return SVN_NO_ERROR; }
static svn_error_t * test_invalid_bom(apr_pool_t *pool) { svn_config_t *cfg; svn_error_t *err; svn_string_t *cfg_string; svn_stream_t *stream; cfg_string = svn_string_create("\xEF", pool); stream = svn_stream_from_string(cfg_string, pool); err = svn_config_parse(&cfg, stream, TRUE, TRUE, pool); SVN_TEST_ASSERT_ERROR(err, SVN_ERR_MALFORMED_FILE); cfg_string = svn_string_create("\xEF\xBB", pool); stream = svn_stream_from_string(cfg_string, pool); err = svn_config_parse(&cfg, stream, TRUE, TRUE, pool); SVN_TEST_ASSERT_ERROR(err, SVN_ERR_MALFORMED_FILE); return SVN_NO_ERROR; }
static svn_error_t * test_ignore_bom(apr_pool_t *pool) { svn_config_t *cfg; svn_string_t *cfg_string = svn_string_create("\xEF\xBB\xBF[s1]\nfoo=bar\n", pool); svn_stream_t *stream = svn_stream_from_string(cfg_string, pool); SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool)); if (! svn_config_has_section(cfg, "s1")) return fail(pool, "failed to find section s1"); return SVN_NO_ERROR; }
static svn_error_t * test_stream_interface(const svn_test_opts_t *opts, apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file; svn_stream_t *stream; SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_stream_open_readonly(&stream, cfg_file, pool, pool)); SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool)); /* nominal test to make sure cfg is populated with something since * svn_config_parse will happily return an empty cfg if the stream is * empty. */ if (! svn_config_has_section(cfg, "section1")) return fail(pool, "Failed to find section1"); return SVN_NO_ERROR; }
/* Retrieve the file at DIRENT (contained in a repo) then parse it as a config * file placing the result into CFG_P allocated in POOL. * * If DIRENT cannot be parsed as a config file then an error is returned. The * contents of CFG_P is then undefined. If MUST_EXIST is TRUE, a missing * authz file is also an error. The CASE_SENSITIVE controls the lookup * behavior for section and option names alike. * * SCRATCH_POOL will be used for temporary allocations. */ static svn_error_t * authz_retrieve_config_repo(svn_config_t **cfg_p, const char *dirent, svn_boolean_t must_exist, svn_boolean_t case_sensitive, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { svn_error_t *err; svn_repos_t *repos; const char *repos_root_dirent; const char *fs_path; svn_fs_t *fs; svn_fs_root_t *root; svn_revnum_t youngest_rev; svn_node_kind_t node_kind; svn_stream_t *contents; /* Search for a repository in the full path. */ repos_root_dirent = svn_repos_find_root_path(dirent, scratch_pool); if (!repos_root_dirent) return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_NOT_FOUND, NULL, "Unable to find repository at '%s'", dirent); /* Attempt to open a repository at repos_root_dirent. */ SVN_ERR(svn_repos_open3(&repos, repos_root_dirent, NULL, scratch_pool, scratch_pool)); fs_path = &dirent[strlen(repos_root_dirent)]; /* Root path is always a directory so no reason to go any further */ if (*fs_path == '\0') return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL, "'/' is not a file in repo '%s'", repos_root_dirent); /* We skip some things that are non-important for how we're going to use * this repo connection. We do not set any capabilities since none of * the current ones are important for what we're doing. We also do not * setup the environment that repos hooks would run under since we won't * be triggering any. */ /* Get the filesystem. */ fs = svn_repos_fs(repos); /* Find HEAD and the revision root */ SVN_ERR(svn_fs_youngest_rev(&youngest_rev, fs, scratch_pool)); SVN_ERR(svn_fs_revision_root(&root, fs, youngest_rev, scratch_pool)); SVN_ERR(svn_fs_check_path(&node_kind, root, fs_path, scratch_pool)); if (node_kind == svn_node_none) { if (!must_exist) { SVN_ERR(svn_config_create2(cfg_p, case_sensitive, case_sensitive, result_pool)); return SVN_NO_ERROR; } else { return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL, "'%s' path not found in repo '%s'", fs_path, repos_root_dirent); } } else if (node_kind != svn_node_file) { return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL, "'%s' is not a file in repo '%s'", fs_path, repos_root_dirent); } SVN_ERR(svn_fs_file_contents(&contents, root, fs_path, scratch_pool)); err = svn_config_parse(cfg_p, contents, case_sensitive, case_sensitive, result_pool); /* Add the URL to the error stack since the parser doesn't have it. */ if (err != SVN_NO_ERROR) return svn_error_createf(err->apr_err, err, "Error while parsing config file: '%s' in repo '%s':", fs_path, repos_root_dirent); return SVN_NO_ERROR; }