]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
start honoring the recommended_versions string
authorRoger Dingledine <arma@torproject.org>
Sat, 23 Aug 2003 10:09:25 +0000 (10:09 +0000)
committerRoger Dingledine <arma@torproject.org>
Sat, 23 Aug 2003 10:09:25 +0000 (10:09 +0000)
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

src/or/config.c
src/or/cpuworker.c
src/or/main.c
src/or/or.h
src/or/routers.c
src/or/test.c

index 59113ef86293c1fe52d55760a2fc4b2632c96c80..85762757759417e5a623aabdf247f8a54efd30ee 100644 (file)
@@ -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);
index c2437e5a52bcfd1093716bc0e9324b982a170f0f..0b92733f2b2df1e7321256a56851d44cfe74fbeb 100644 (file)
@@ -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 {
index 0913c28ae17acc91217156dbe3a8b0ef4874d98f..720be45fe1dfe3e675cca8b0d30240ef77915596 100644 (file)
@@ -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);
index 53033f0fcda4785f49cab73cf5dc1c7a2f5e0f14..77477497a6b7ca8c141e9d065728260627237457 100644 (file)
@@ -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;
index 4ed858732c86831b72703139b234bed2e48239dd..c6e4d1012f795a0dc84c1b9f3477d2b3e2b3a64a 100644 (file)
@@ -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;
 }
 
index 3d769c39aaccd426241964f17f21caf8ca31f201..547f73a079b8bb98203da0b1b5fcde1d73a1f26f 100644 (file)
@@ -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