Ticket #8405: 0001-Bug-8405-Report-SOCKS-username-password-in-CIRC-stat.patch

File 0001-Bug-8405-Report-SOCKS-username-password-in-CIRC-stat.patch, 3.0 KB (added by arthuredelstein, 6 years ago)
  • src/common/util.c

    From a298c77f7eba232154ff08ca1119b05ccd9eee9e Mon Sep 17 00:00:00 2001
    From: Arthur Edelstein <arthuredelstein@gmail.com>
    Date: Tue, 15 Jul 2014 21:27:59 -0700
    Subject: [PATCH] Bug #8405: Report SOCKS username/password in CIRC status
     events
    
    Introduces two new circuit status name-value parameters: SOCKS_USERNAME
    and SOCKS_PASSWORD. Values are enclosing in quotes and unusual characters
    are escaped.
    
    Example:
    
        650 CIRC 5 EXTENDED [...] SOCKS_USERNAME="my_username" SOCKS_PASSWORD="my_password"
    ---
     src/common/util.c | 14 ++++++++++++++
     src/common/util.h |  1 +
     src/or/control.c  | 14 ++++++++++++++
     3 files changed, 29 insertions(+)
    
    diff --git a/src/common/util.c b/src/common/util.c
    index 8589344..64cee56 100644
    a b esc_for_log(const char *s) 
    12221222  return result;
    12231223}
    12241224
     1225/** Similar to esc_for_log. Allocate and return a new string representing
     1226 * the first n characters in <b>chars</b>, surround by quotes and using
     1227 * standard C escapes. If a NUL character is encountered in <b>chars</b>,
     1228 * the resulting string will be terminated there.
     1229 */
     1230char *
     1231esc_for_log_len(const char *chars, size_t n)
     1232{
     1233  char *string = tor_strndup(chars, n);
     1234  char *string_escaped = esc_for_log(string);
     1235  tor_free(string);
     1236  return string_escaped;
     1237}
     1238
    12251239/** Allocate and return a new string representing the contents of <b>s</b>,
    12261240 * surrounded by quotes and using standard C escapes.
    12271241 *
  • src/common/util.h

    diff --git a/src/common/util.h b/src/common/util.h
    index 97367a9..50c5a3d 100644
    a b int tor_mem_is_zero(const char *mem, size_t len); 
    229229int tor_digest_is_zero(const char *digest);
    230230int tor_digest256_is_zero(const char *digest);
    231231char *esc_for_log(const char *string) ATTR_MALLOC;
     232char *esc_for_log_len(const char *chars, size_t n) ATTR_MALLOC;
    232233const char *escaped(const char *string);
    233234
    234235char *tor_escape_str_for_pt_args(const char *string,
  • src/or/control.c

    diff --git a/src/or/control.c b/src/or/control.c
    index 9285fc5..aa46df6 100644
    a b circuit_describe_status_for_controller(origin_circuit_t *circ) 
    18621862    smartlist_add_asprintf(descparts, "TIME_CREATED=%s", tbuf);
    18631863  }
    18641864
     1865  // Show username and/or password if available.
     1866  if (circ->socks_username_len > 0) {
     1867    char* socks_username_escaped = esc_for_log_len(circ->socks_username,
     1868                                     (size_t) circ->socks_username_len);
     1869    smartlist_add_asprintf(descparts, "SOCKS_USERNAME=%s", socks_username_escaped);
     1870    tor_free(socks_username_escaped);
     1871  }
     1872  if (circ->socks_password_len > 0) {
     1873    char* socks_password_escaped = esc_for_log_len(circ->socks_password,
     1874                                     (size_t) circ->socks_password_len);
     1875    smartlist_add_asprintf(descparts, "SOCKS_PASSWORD=%s", socks_password_escaped);
     1876    tor_free(socks_password_escaped);
     1877  }
     1878
    18651879  rv = smartlist_join_strings(descparts, " ", 0, NULL);
    18661880
    18671881  SMARTLIST_FOREACH(descparts, char *, cp, tor_free(cp));