diff options
author | David Goulet <dgoulet@torproject.org> | 2016-12-22 16:40:21 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2017-04-07 09:22:52 -0400 |
commit | 419c0c07881c71050546c1049173a7eadf936799 (patch) | |
tree | a5b371cbea93ae0bdeec9c9b135451d07cc185f7 /src/or/hs_common.c | |
parent | 489ef6b38ba66f59bb6562a4702c0500478a7495 (diff) | |
download | tor-419c0c07881c71050546c1049173a7eadf936799.tar.gz tor-419c0c07881c71050546c1049173a7eadf936799.zip |
hs: Move service check private dir to hs_common.c
Another building blocks for prop224 service work. This also makes the function
takes specific argument instead of the or_option_t object.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/hs_common.c')
-rw-r--r-- | src/or/hs_common.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c index 7e0b6ca1bc..4af3081502 100644 --- a/src/or/hs_common.c +++ b/src/or/hs_common.c @@ -16,6 +16,40 @@ #include "hs_common.h" #include "rendcommon.h" +/* Make sure that the directory for <b>service</b> is private, using the config + * <b>username</b>. + * If <b>create</b> is true: + * - if the directory exists, change permissions if needed, + * - if the directory does not exist, create it with the correct permissions. + * If <b>create</b> is false: + * - if the directory exists, check permissions, + * - if the directory does not exist, check if we think we can create it. + * Return 0 on success, -1 on failure. */ +int +hs_check_service_private_dir(const char *username, const char *path, + unsigned int dir_group_readable, + unsigned int create) +{ + cpd_check_t check_opts = CPD_NONE; + + tor_assert(path); + + if (create) { + check_opts |= CPD_CREATE; + } else { + check_opts |= CPD_CHECK_MODE_ONLY; + check_opts |= CPD_CHECK; + } + if (dir_group_readable) { + check_opts |= CPD_GROUP_READ; + } + /* Check/create directory */ + if (check_private_dir(path, check_opts, username) < 0) { + return -1; + } + return 0; +} + /* Create a new rend_data_t for a specific given <b>version</b>. * Return a pointer to the newly allocated data structure. */ static rend_data_t * |