diff options
author | Daniel Pinto <danielpinto52@gmail.com> | 2017-05-18 23:44:16 +0100 |
---|---|---|
committer | Daniel Pinto <danielpinto52@gmail.com> | 2017-05-18 23:44:16 +0100 |
commit | ba3a5f82f11388237a3ba4995ddf0b6ffaaf492a (patch) | |
tree | c0cf4342524cd040e24fe9cc420bb70e21c0a9d5 /src/common/util.c | |
parent | ec6b2bbf9bb561e34f9fbe6663d1eb691604348d (diff) | |
download | tor-ba3a5f82f11388237a3ba4995ddf0b6ffaaf492a.tar.gz tor-ba3a5f82f11388237a3ba4995ddf0b6ffaaf492a.zip |
Add support for %include funcionality on torrc #1922
config_get_lines is now split into two functions:
- config_get_lines which is the same as before we had %include
- config_get_lines_include which actually processes %include
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index ca2a0c4a9c..5c455585e7 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -3045,6 +3045,41 @@ unescape_string(const char *s, char **result, size_t *size_out) } } +/** Removes enclosing quotes from <b>path</b> and unescapes quotes between the + * enclosing quotes. Backslashes are not unescaped. Return the unquoted + * <b>path</b> on sucess or 0 if <b>path</b> is not quoted correctly. */ +char * +get_unquoted_path(const char *path) +{ + int len = strlen(path); + + if (len == 0) { + return tor_strdup(""); + } + + int has_start_quote = (path[0] == '\"'); + int has_end_quote = (len > 0 && path[len-1] == '\"'); + if (has_start_quote != has_end_quote || (len == 1 && has_start_quote)) { + return NULL; + } + + char *unquoted_path = tor_malloc(len - has_start_quote - has_end_quote + 1); + char *s = unquoted_path; + int i; + for (i = has_start_quote; i < len - has_end_quote; i++) { + if (path[i] == '\"' && (i > 0 && path[i-1] == '\\')) { + *(s-1) = path[i]; + } else if (path[i] != '\"') { + *s++ = path[i]; + } else { /* unescaped quote */ + tor_free(unquoted_path); + return NULL; + } + } + *s = '\0'; + return unquoted_path; +} + /** Expand any homedir prefix on <b>filename</b>; return a newly allocated * string. */ char * |