commit 67a62ccf51f46bde75e0675b1ee19c024152f088 Author: Neel Chauhan neel@neelc.org Date: Fri Jul 24 18:23:50 2020 -0700
Use write_str_if_not_equal() for onion services --- changes/bug40062 | 6 ++++++ src/feature/hs/hs_service.c | 2 +- src/feature/relay/router.c | 5 ++--- src/feature/rend/rendservice.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/changes/bug40062 b/changes/bug40062 new file mode 100644 index 0000000000..9f18685a94 --- /dev/null +++ b/changes/bug40062 @@ -0,0 +1,6 @@ + o Minor features (onion services): + - When writing an onion service hostname file, first read it to make + sure it contains what we want before attempting to write it. Now + onion services can set their existing onion service directories to + read-only and Tor will still work. Resolves ticket 40062. Patch by + Neel Chauhan. diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c index b56b7f4368..3e264b4686 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -990,7 +990,7 @@ write_address_to_file(const hs_service_t *service, const char *fname_) tor_asprintf(&addr_buf, "%s.%s\n", service->onion_address, address_tld); /* Notice here that we use the given "fname_". */ fname = hs_path_from_filename(service->config.directory_path, fname_); - if (write_str_to_file(fname, addr_buf, 0) < 0) { + if (write_str_to_file_if_not_equal(fname, addr_buf)) { log_warn(LD_REND, "Could not write onion address to hostname file %s", escaped(fname)); goto end; diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c index 25263468c8..675b977ade 100644 --- a/src/feature/relay/router.c +++ b/src/feature/relay/router.c @@ -835,7 +835,7 @@ router_initialize_tls_context(void) STATIC int router_write_fingerprint(int hashed, int ed25519_identity) { - char *keydir = NULL, *cp = NULL; + char *keydir = NULL; const char *fname = hashed ? "hashed-fingerprint" : (ed25519_identity ? "fingerprint-ed25519" : "fingerprint"); @@ -870,7 +870,7 @@ router_write_fingerprint(int hashed, int ed25519_identity) tor_asprintf(&fingerprint_line, "%s %s\n", options->Nickname, fingerprint);
/* Check whether we need to write the (hashed-)fingerprint file. */ - if (write_str_if_not_equal(keydir, fingerprint_line)) { + if (write_str_to_file_if_not_equal(keydir, fingerprint_line)) { log_err(LD_FS, "Error writing %s%s line to file", hashed ? "hashed " : "", ed25519_identity ? "ed25519 identity" : "fingerprint"); @@ -884,7 +884,6 @@ router_write_fingerprint(int hashed, int ed25519_identity)
result = 0; done: - tor_free(cp); tor_free(keydir); tor_free(fingerprint_line); return result; diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c index 1ac88d0eb7..8e1a22fb39 100644 --- a/src/feature/rend/rendservice.c +++ b/src/feature/rend/rendservice.c @@ -1554,7 +1554,7 @@ rend_service_load_keys(rend_service_t *s) fname = rend_service_path(s, hostname_fname);
tor_snprintf(buf, sizeof(buf),"%s.onion\n", s->service_id); - if (write_str_to_file(fname,buf,0)<0) { + if (write_str_to_file_if_not_equal(fname, buf)) { log_warn(LD_CONFIG, "Could not write onion address to hostname file."); goto err; }
tor-commits@lists.torproject.org