Ticket #4806: 0003-Fixed-to-use-tor-framework-functions.patch

File 0003-Fixed-to-use-tor-framework-functions.patch, 3.0 KB (added by cypherpunks, 7 years ago)
  • src/common/compat.c

    From 17709a5b0e4598cc541c42133de3d093dc2332f6 Mon Sep 17 00:00:00 2001
    From: Aki Tuomi <cmouse@cmouse.fi>
    Date: Fri, 24 Aug 2012 00:24:08 +0300
    Subject: [PATCH 3/3] Fixed to use tor framework functions
    
    ---
     src/common/compat.c |   44 ++++++++++++++------------------------------
     1 file changed, 14 insertions(+), 30 deletions(-)
    
    diff --git a/src/common/compat.c b/src/common/compat.c
    index 7d33de7..4789681 100644
    a b check_ipv6_tempaddr(int verbose) 
    31293129  /* then we check the interfaces */
    31303130  dir = opendir("/proc/sys/net/ipv6/conf");
    31313131  if (dir == NULL) {
    3132     if (verbose != 0)
    3133       log_warn(LD_GENERAL, "Could not open /proc/sys/net/ipv6/conf");
     3132    log_warn(LD_GENERAL, "Could not open /proc/sys/net/ipv6/conf");
    31343133    return -1;
    31353134  }
    31363135
    31373136  n_of_interfaces = 0;
    31383137  while ((ent = readdir(dir) ) != NULL) {
     3138     long use_tempaddr = 0;
    31393139     char fname[1024] = {0};
    3140 
     3140     char *str;
    31413141     /* skip dot-files */
    31423142     if (ent->d_name[0] == '.') continue;
    31433143     /* not an interface */
    check_ipv6_tempaddr(int verbose) 
    31473147         /* localhost is not outbound */
    31483148         !strncmp(ent->d_name, "lo", 2)) continue;
    31493149
    3150      snprintf(fname, sizeof fname, "%s/%s", "/proc/sys/net/ipv6/conf",
     3150     tor_snprintf(fname, sizeof fname, "%s/%s", "/proc/sys/net/ipv6/conf",
    31513151              ent->d_name);
    31523152     if (stat(fname, &buf) == 0) {
    31533153       if (!S_ISDIR(buf.st_mode)) continue; /* not a directory */
    check_ipv6_tempaddr(int verbose) 
    31553155       continue; /* not accessible */
    31563156     }
    31573157
    3158      snprintf(fname, sizeof fname, "%s/%s/use_tempaddr",
     3158     tor_snprintf(fname, sizeof fname, "%s/%s/use_tempaddr",
    31593159              "/proc/sys/net/ipv6/conf", ent->d_name);
    3160      if (stat(fname, &buf) == 0) {
    3161         int state;
    3162         FILE *f;
    3163         /* read the value */
    3164         f = fopen(fname, "r");
    3165         if (f == NULL) {
    3166            if (verbose)
    3167              log_warn(LD_GENERAL, "Cannot check use_tempaddr for interface %s",
    3168                       ent->d_name);
    3169            continue;
    3170         }
    3171         state = 0;
    3172         if (fscanf(f, "%d", &state) == 1) {
    3173            if (state == 0) {
    3174              n_of_interfaces++;
    3175              if (verbose)
    3176                 log_warn(LD_GENERAL, "Interface %s might expose your MAC \
     3160     str = read_file_to_str(fname, 0, NULL);
     3161     if (str == NULL) continue; /* we failed to read the file */
     3162     use_tempaddr = atoi(str); /* it's a base 10 number */
     3163     tor_free(str);
     3164     if (use_tempaddr == 0) {
     3165         n_of_interfaces++;
     3166         if (verbose) {
     3167           log_warn(LD_GENERAL, "Interface %s might expose your MAC \
    31773168address to world, you can fix this with \
    31783169sysctl -p net.ipv6.conf.%s.use_tempaddr=2", ent->d_name, ent->d_name);
    3179            }
    3180         } else {
    3181             if (verbose)
    3182               log_warn(LD_GENERAL,
    3183                        "Cannot check use_tempaddr for interface %s",
    3184                        ent->d_name);
    3185         }
    3186         fclose(f);
     3170         }
    31873171     }
    31883172  }
    31893173  closedir(dir);