]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'Ryman/bug6384'
authorNick Mathewson <nickm@torproject.org>
Fri, 13 Sep 2013 16:55:53 +0000 (12:55 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 13 Sep 2013 16:55:53 +0000 (12:55 -0400)
Conflicts:
src/or/config.c
src/or/main.c

1  2 
src/common/crypto.c
src/or/config.c
src/or/main.c

Simple merge
diff --cc src/or/config.c
index 9a8d1e77f52aaef13a9a1077536d793e6be23915,b00f0d6e11276c8b8ba2f8630717b3595d240d25..5ce7bad493880891aa78f34ac00ad178e79efeb4
@@@ -1794,48 -1791,15 +1795,49 @@@ options_act(const or_options_t *old_opt
    return 0;
  }
  
 -/** Helper: Read a list of configuration options from the command line.
 - * If successful, put them in *<b>result</b> and return 0, and return
 - * -1 and leave *<b>result</b> alone. */
 -static int
 -config_get_commandlines(int argc, char **argv, config_line_t **result)
 +static const struct {
 +  const char *name;
 +  int takes_argument;
 +} CMDLINE_ONLY_OPTIONS[] = {
 +  { "-f",                     1 },
 +  { "--defaults-torrc",       1 },
 +  { "--hash-password",        1 },
 +  { "--dump-config",          1 },
 +  { "--list-fingerprint",     0 },
 +  { "--verify-config",        0 },
 +  { "--ignore-missing-torrc", 0 },
 +  { "--quiet",                0 },
 +  { "--hush",                 0 },
 +  { "--version",              0 },
++  { "--library-versions",     0 },
 +  { "-h",                     0 },
 +  { "--help",                 0 },
 +  { "--list-torrc-options",   0 },
 +  { "--digests",              0 },
 +  { "--nt-service",           0 },
 +  { "-nt-service",            0 },
 +  { NULL, 0 },
 +};
 +
 +/** Helper: Read a list of configuration options from the command line.  If
 + * successful, or if ignore_errors is set, put them in *<b>result</b>, put the
 + * commandline-only options in *<b>cmdline_result</b>, and return 0;
 + * otherwise, return -1 and leave *<b>result</b> and <b>cmdline_result</b>
 + * alone. */
 +int
 +config_parse_commandline(int argc, char **argv, int ignore_errors,
 +                         config_line_t **result,
 +                         config_line_t **cmdline_result)
  {
 +  config_line_t *param = NULL;
 +
    config_line_t *front = NULL;
    config_line_t **new = &front;
 -  char *s;
 +
 +  config_line_t *front_cmdline = NULL;
 +  config_line_t **new_cmdline = &front_cmdline;
 +
 +  char *s, *arg;
    int i = 1;
  
    while (i < argc) {
@@@ -3932,24 -3817,48 +3934,41 @@@ options_init_from_torrc(int argc, char 
      printf("Tor version %s.\n",get_version());
      exit(0);
    }
 -  if (argc > 1 && (!strcmp(argv[1],"--digests"))) {
 +  if (config_line_find(cmdline_only_options, "--digests")) {
      printf("Tor version %s.\n",get_version());
      printf("%s", libor_get_digests());
      printf("%s", tor_get_digests());
      exit(0);
    }
  
 -  if (argc > 1 && (!strcmp(argv[1],"--library-versions"))) {
++  if (config_line_find(cmdline_only_options, "--library-versions")) {
+     printf("Tor version %s. \n", get_version());
+     printf("Library versions\tCompiled\t\tRuntime\n");
+     printf("Libevent\t\t%-15s\t\t%s\n",
+                       tor_libevent_get_header_version_str(),
+                       tor_libevent_get_version_str());
+     printf("OpenSSL \t\t%-15s\t\t%s\n",
+                       crypto_openssl_get_header_version_str(),
+                       crypto_openssl_get_version_str());
+     printf("Zlib    \t\t%-15s\t\t%s\n",
+                       tor_zlib_get_header_version_str(),
+                       tor_zlib_get_version_str());
+     //TODO: Hex versions?
+     exit(0);
+   }
 -  /* Go through command-line variables */
 -  if (!global_cmdline_options) {
 -    /* Or we could redo the list every time we pass this place.
 -     * It does not really matter */
 -    if (config_get_commandlines(argc, argv, &global_cmdline_options) < 0) {
 -      goto err;
 -    }
 -  }
 -
    command = CMD_RUN_TOR;
 -  for (i = 1; i < argc; ++i) {
 -    if (!strcmp(argv[i],"--list-fingerprint")) {
 +  for (p_index = cmdline_only_options; p_index; p_index = p_index->next) {
 +    if (!strcmp(p_index->key,"--list-fingerprint")) {
        command = CMD_LIST_FINGERPRINT;
 -    } else if (!strcmp(argv[i],"--hash-password")) {
 +    } else if (!strcmp(p_index->key, "--hash-password")) {
        command = CMD_HASH_PASSWORD;
 -      command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : "");
 -      ++i;
 -    } else if (!strcmp(argv[i],"--verify-config")) {
 +      command_arg = p_index->value;
 +    } else if (!strcmp(p_index->key, "--dump-config")) {
 +      command = CMD_DUMP_CONFIG;
 +      command_arg = p_index->value;
 +    } else if (!strcmp(p_index->key, "--verify-config")) {
        command = CMD_VERIFY_CONFIG;
      }
    }
diff --cc src/or/main.c
index ceee29ce66d31812e1b9d34f8d2fdefa3a1c1337,2d6ca74d8d18b4a3d21c07909c63ea28a5d7ec2d..ac756de5d22d91f57a24671db122a552f5d8faf1
@@@ -2339,28 -2333,19 +2339,29 @@@ tor_init(int argc, char *argv[]
    addressmap_init(); /* Init the client dns cache. Do it always, since it's
                        * cheap. */
  
 +  {
    /* We search for the "quiet" option first, since it decides whether we
     * will log anything at all to the command line. */
 -  for (i=1;i<argc;++i) {
 -    if (!strcmp(argv[i], "--hush"))
 -      quiet = 1;
 -    if (!strcmp(argv[i], "--quiet"))
 -      quiet = 2;
 -    /* --version implies --quiet */
 -    if (!strcmp(argv[i], "--version"))
 -      quiet = 2;
 -    if (!strcmp(argv[i], "--library-versions"))
 -      quiet = 2;
 +    config_line_t *opts = NULL, *cmdline_opts = NULL;
 +    const config_line_t *cl;
 +    (void) config_parse_commandline(argc, argv, 1, &opts, &cmdline_opts);
 +    for (cl = cmdline_opts; cl; cl = cl->next) {
 +      if (!strcmp(cl->key, "--hush"))
 +        quiet = 1;
 +      if (!strcmp(cl->key, "--quiet") ||
 +          !strcmp(cl->key, "--dump-config"))
 +        quiet = 2;
-       /* --version, --digests, and --help imply --husth */
++      /* --version, --digests, and --help imply --hush */
 +      if (!strcmp(cl->key, "--version") || !strcmp(cl->key, "--digests") ||
 +          !strcmp(cl->key, "--list-torrc-options") ||
++          !strcmp(cl->key, "--library-versions") ||
 +          !strcmp(cl->key, "-h") || !strcmp(cl->key, "--help"))
 +        quiet = 1;
 +    }
 +    config_free_lines(opts);
 +    config_free_lines(cmdline_opts);
    }
 +
   /* give it somewhere to log to initially */
    switch (quiet) {
      case 2: