Просмотр исходного кода

start honoring the recommended_versions string

your client exits if you're running a version not in the
directory's list of acceptable versions (unless you have a
config variable set to override).


svn:r408
Roger Dingledine 21 лет назад
Родитель
Сommit
36f055e7ee
6 измененных файлов с 53 добавлено и 5 удалено
  1. 2 0
      src/or/config.c
  2. 0 3
      src/or/cpuworker.c
  3. 3 1
      src/or/main.c
  4. 3 0
      src/or/or.h
  5. 31 1
      src/or/routers.c
  6. 14 0
      src/or/test.c

+ 2 - 0
src/or/config.c

@@ -185,6 +185,7 @@ void config_assign(or_options_t *options, struct config_line *list) {
     config_compare(list, "Daemon",          CONFIG_TYPE_BOOL, &options->Daemon) ||
     config_compare(list, "TrafficShaping",  CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
     config_compare(list, "LinkPadding",     CONFIG_TYPE_BOOL, &options->LinkPadding) ||
+    config_compare(list, "IgnoreVersion",   CONFIG_TYPE_BOOL, &options->IgnoreVersion) ||
 
     /* float options */
     config_compare(list, "CoinWeight",     CONFIG_TYPE_DOUBLE, &options->CoinWeight)
@@ -260,6 +261,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
   config_free_lines(cl);
 
 /* print config */
+/* XXX this section is rotting. Should maybe remove it sometime. */
   if (options->loglevel == LOG_DEBUG) {
     printf("LogLevel=%s\n",
            options->LogLevel);

+ 0 - 3
src/or/cpuworker.c

@@ -39,7 +39,6 @@ int connection_cpu_process_inbuf(connection_t *conn) {
   if(conn->inbuf_reached_eof) {
     log_fn(LOG_ERR,"Read eof. Worker dying.");
     if(conn->state != CPUWORKER_STATE_IDLE) {
-      onion_pending_remove(conn->circ);
       circuit_close(conn->circ);
       conn->circ = NULL;
       num_cpuworkers_busy--;
@@ -59,11 +58,9 @@ int connection_cpu_process_inbuf(connection_t *conn) {
     if(*buf == 0 || conn->circ->p_conn == NULL ||
        onionskin_process(conn->circ, buf+1, buf+1+DH_KEY_LEN) < 0) {
       log_fn(LOG_DEBUG,"decoding onion, onionskin_process, or p_conn failed. Closing.");
-//      onion_pending_remove(conn->circ);
       circuit_close(conn->circ);
     } else {
       log_fn(LOG_DEBUG,"onionskin_process succeeded. Yay.");
-//      onion_pending_remove(conn->circ);
     }
     conn->circ = NULL;
   } else {

+ 3 - 1
src/or/main.c

@@ -765,7 +765,9 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
   eos = s+maxlen;
   strncpy(s, 
           "signed-directory\n"
-          "recommended-software 0.0.2pre4,0.0.2pre5,0.0.2pre6\n" /* XXX make this real */
+          "recommended-software "
+          RECOMMENDED_SOFTWARE_VERSIONS
+          "\n"
           , maxlen);
   
   i = strlen(s);

+ 3 - 0
src/or/or.h

@@ -93,6 +93,8 @@
 #include "../common/log.h"
 #include "../common/util.h"
 
+#define RECOMMENDED_SOFTWARE_VERSIONS "0.0.2pre6,0.0.2pre7"
+
 #define MAXCONNECTIONS 1000 /* upper bound on max connections.
                               can be lowered by config file */
 
@@ -459,6 +461,7 @@ typedef struct {
    int OnionRouter;
    int TrafficShaping;
    int LinkPadding;
+   int IgnoreVersion;
    int DirRebuildPeriod;
    int DirFetchPeriod;
    int KeepalivePeriod;

+ 31 - 1
src/or/routers.c

@@ -168,6 +168,7 @@ void directory_free(directory_t *directory)
   for (i = 0; i < directory->n_routers; ++i)
     routerinfo_free(directory->routers[i]);
   free(directory->routers);
+  /* XXX are we leaking directory->software_versions here? */
   free(directory);
 }
 
@@ -506,6 +507,25 @@ static int router_get_dir_hash(char *s, char *digest)
   return 0;
 }
 
+/* return 0 if myversion is in start. Else return -1. */
+int compare_recommended_versions(char *myversion, char *start) {
+  int len_myversion = strlen(myversion);
+  char *comma;
+  char *end = start + strlen(start);
+
+  log_fn(LOG_DEBUG,"checking '%s' in '%s'.", myversion, start);
+  
+  for(;;) {
+    comma = strchr(start, ',');
+    if( ((comma ? comma : end) - start == len_myversion) &&
+       !strncmp(start, myversion, len_myversion)) /* only do strncmp if the length matches */
+        return 0; /* success, it's there */
+    if(!comma)
+      return -1; /* nope */
+    start = comma+1;
+  }
+}
+
 int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey)
 {
   if (router_get_dir_from_string_impl(s, &directory, pkey)) {
@@ -516,7 +536,17 @@ int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey)
     log(LOG_ERR, "Error resolving directory");
     return -1;
   }
-  /* XXXX Check version number */
+  if (compare_recommended_versions(VERSION, directory->software_versions) < 0) {
+    log(LOG_ERR, "You are running tor version %s, which is no longer supported.\nPlease upgrade to one of %s.", VERSION, RECOMMENDED_SOFTWARE_VERSIONS);
+    if(options.IgnoreVersion) {
+      log(LOG_WARNING, "IgnoreVersion is set. If it breaks, we told you so.");
+    } else {
+      log(LOG_ERR,"Set IgnoreVersion config variable if you want to survive this error.");
+      fflush(0);
+      exit(0);
+    }
+  }
+
   return 0;
 }
 

+ 14 - 0
src/or/test.c

@@ -485,6 +485,9 @@ test_onion_handshake() {
 int dump_router_to_string(char *s, int maxlen, routerinfo_t *router);
 void dump_directory_to_string(char *s, int maxlen);
 
+/* from routers.c */
+int compare_recommended_versions(char *myversion, char *start);
+
 void
 test_dir_format()
 {
@@ -608,6 +611,17 @@ test_dir_format()
   if (rp2) routerinfo_free(rp2);
   if (dir1) free(dir1); /* And more !*/
   if (dir1) free(dir2); /* And more !*/
+
+  /* make sure compare_recommended_versions() works */
+  test_eq(0, compare_recommended_versions("abc", "abc"));
+  test_eq(0, compare_recommended_versions("abc", "ab,abd,abde,abc,abcde"));
+  test_eq(0, compare_recommended_versions("abc", "ab,abd,abde,abcde,abc"));
+  test_eq(0, compare_recommended_versions("abc", "abc,abd,abde,abc,abcde"));
+  test_eq(0, compare_recommended_versions("a", "a,ab,abd,abde,abc,abcde"));
+  test_eq(-1, compare_recommended_versions("a", "ab,abd,abde,abc,abcde"));
+  test_eq(-1, compare_recommended_versions("abb", "ab,abd,abde,abc,abcde"));
+  test_eq(-1, compare_recommended_versions("a", ""));
+  test_eq(0, compare_recommended_versions(VERSION, RECOMMENDED_SOFTWARE_VERSIONS));
 }
 
 int