Commit afd88ee8 authored by George Kadianakis's avatar George Kadianakis
Browse files

Merge remote-tracking branch 'tor-gitlab/mr/88'

parents 04926126 fcf4954c
Loading
Loading
Loading
Loading

changes/bug40062

0 → 100644
+6 −0
Original line number Diff line number Diff line
  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.
+1 −1
Original line number Diff line number Diff line
@@ -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;
+6 −11
Original line number Diff line number Diff line
@@ -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,16 +870,12 @@ 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. */

  cp = read_file_to_str(keydir, RFTS_IGNORE_MISSING, NULL);
  if (!cp || strcmp(cp, fingerprint_line)) {
    if (write_str_to_file(keydir, fingerprint_line, 0)) {
  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");
    goto done;
  }
  }

  log_notice(LD_GENERAL, "Your Tor %s identity key %s fingerprint is '%s %s'",
             hashed ? "bridge's hashed" : "server's",
@@ -888,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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
  }
+20 −0
Original line number Diff line number Diff line
@@ -718,6 +718,26 @@ read_file_to_str, (const char *filename, int flags, struct stat *stat_out))
  return string;
}

/** Attempt to read a file <b>fname</b>. If the file's contents is
 * equal to the string <b>str</b>, return 0. Otherwise, attempt to
 * overwrite the file with the contents of <b>str</b> and return
 * the value of write_str_to_file().
 */
int
write_str_to_file_if_not_equal(const char *fname, const char *str)
{
  char *fstr = read_file_to_str(fname, RFTS_IGNORE_MISSING, NULL);
  int rv;

  if (!fstr || strcmp(str, fstr)) {
    rv = write_str_to_file(fname, str, 0);
  } else {
    rv = 0;
  }
  tor_free(fstr);
  return rv;
}

#if !defined(HAVE_GETDELIM) || defined(TOR_UNIT_TESTS)
#include "ext/getdelim.c"
#endif
Loading