28 static smartlist_t *config_get_file_list(
const char *path,
30 static int config_get_included_config(
const char *path,
int recursion_level,
34 static int config_process_include(
const char *path,
int recursion_level,
50 int extended,
int *has_include,
54 opened_lst, 1, NULL, config_process_include);
62 expand_glob(
const char *pattern,
smartlist_t *opened_files)
73 log_err(
LD_CONFIG,
"Sandbox is active, but the configuration pattern "
74 "\"%s\" listed with %%include would access files or folders not "
75 "allowed by it. Cannot proceed.", pattern);
84 smartlist_free(matches);
88 smartlist_free(glob_opened);
104 config_get_file_list(
const char *pattern,
smartlist_t *opened_files)
106 smartlist_t *glob_matches = expand_glob(pattern, opened_files);
111 bool error_found =
false;
117 if (sandbox_interned_string_is_missing(path)) {
118 log_err(
LD_CONFIG,
"Sandbox is active, but a new configuration "
119 "file \"%s\" has been listed with %%include. Cannot proceed.",
126 if (file_type == FN_FILE) {
128 }
else if (file_type == FN_DIR) {
141 tor_asprintf(&fullname,
"%s"PATH_SEPARATOR
"%s", path, f);
152 } SMARTLIST_FOREACH_END(f);
154 smartlist_free(all_files);
155 }
else if (file_type == FN_EMPTY) {
161 } SMARTLIST_FOREACH_END(path);
163 smartlist_free(glob_matches);
167 smartlist_free(file_list);
179 config_get_included_config(
const char *path,
int recursion_level,
int extended,
183 char *included_conf = read_file_to_str(path, 0, NULL);
184 if (!included_conf) {
189 opened_lst, recursion_level+1, config_last,
190 config_process_include) < 0) {
204 config_process_include(
const char *pattern,
int recursion_level,
int extended,
211 smartlist_t *config_files = config_get_file_list(pattern, opened_lst);
218 if (sandbox_interned_string_is_missing(config_file)) {
219 log_err(
LD_CONFIG,
"Sandbox is active, but a new configuration "
220 "file \"%s\" has been listed with %%include. Cannot proceed.",
225 log_notice(
LD_CONFIG,
"Including configuration file \"%s\".", config_file);
228 if (config_get_included_config(config_file, recursion_level, extended,
229 &included_config, &included_config_last,
234 *next = included_config;
235 if (included_config_last) {
236 next = &included_config_last->next;
237 *list_last = included_config_last;
239 } SMARTLIST_FOREACH_END(config_file);
245 smartlist_free(config_files);
Read configuration files from disk, with full include support.
int config_get_lines_include(const char *string, struct config_line_t **result, int extended, int *has_include, struct smartlist_t *opened_lst)
int config_get_lines_aux(const char *string, config_line_t **result, int extended, int allow_include, int *has_include, struct smartlist_t *opened_lst, int recursion_level, config_line_t **last, include_handler_fn handle_include)
smartlist_t * tor_listdir(const char *dirname)
Wrappers for reading and writing data to files on disk.
file_status_t file_status(const char *filename)
Headers for util_malloc.c.
struct smartlist_t * tor_glob(const char *pattern)
bool has_glob(const char *s)
struct smartlist_t * get_glob_opened_files(const char *pattern)
int tor_asprintf(char **strp, const char *fmt,...)
Header file for sandbox.c.
void smartlist_sort_strings(smartlist_t *sl)
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)