options.c

来自「OpenVPN -- A Secure tunneling daemon」· C语言 代码 · 共 1,267 行 · 第 1/3 页

C
1,267
字号
      if (!options->inetd)	{	  options->inetd = true;	  save_inetd_socket_descriptor ();	  open_syslog (p2);	  if (p2)	    ++i;	}    }  else if (streq (p1, "mlock"))    {      options->mlock = true;    }  else if (streq (p1, "verb") && p2)    {      ++i;      options->verbosity = positive (atoi (p2));    }  else if (streq (p1, "mute") && p2)    {      ++i;      options->mute = positive (atoi (p2));    }  else if (streq (p1, "udp-mtu") && p2)    {      ++i;      options->udp_mtu = positive (atoi (p2));      options->udp_mtu_defined = true;    }  else if (streq (p1, "tun-mtu") && p2)    {      ++i;      options->tun_mtu = positive (atoi (p2));      options->tun_mtu_defined = true;    }  else if (streq (p1, "tun-mtu-extra") && p2)    {      ++i;      options->tun_mtu_extra = positive (atoi (p2));    }#ifdef FRAGMENT_ENABLE  else if (streq (p1, "mtu-dynamic"))    {      options->mtu_dynamic = true;      if (p2)	{	  if ((options->mtu_min = positive (atoi (p2))))	    options->mtu_min_defined = true;	  ++i;	}      if (p3)	{	  if ((options->mtu_max = positive (atoi (p3))))	    options->mtu_max_defined = true;	  ++i;	}    }  else if (streq (p1, "mtu-noicmp"))    {      options->mtu_icmp = false;    }#endif  else if (streq (p1, "mtu-disc") && p2)    {      ++i;      options->mtu_discover_type = translate_mtu_discover_type_name (p2);    }  else if (streq (p1, "nice") && p2)    {      ++i;      options->nice = atoi (p2);    }#ifdef USE_PTHREAD  else if (streq (p1, "nice-work") && p2)    {      ++i;      options->nice_work = atoi (p2);    }#endif  else if (streq (p1, "shaper") && p2)    {#ifdef HAVE_GETTIMEOFDAY      ++i;      options->shaper = atoi (p2);      if (options->shaper < SHAPER_MIN || options->shaper > SHAPER_MAX)	{	  msg (M_WARN, "bad shaper value, must be between %d and %d",	       SHAPER_MIN, SHAPER_MAX);	  usage_small ();	}#else /* HAVE_GETTIMEOFDAY */      msg (M_WARN, "--shaper requires the gettimeofday() function which is missing");      usage_small ();#endif /* HAVE_GETTIMEOFDAY */    }  else if (streq (p1, "port") && p2)    {      ++i;      options->local_port = options->remote_port = atoi (p2);      if (options->local_port <= 0 || options->remote_port <= 0)	{	  msg (M_WARN, "Bad port number: %s", p2);	  usage_small ();	}    }  else if (streq (p1, "lport") && p2)    {      ++i;      options->local_port = atoi (p2);      if (options->local_port <= 0)	{	  msg (M_WARN, "Bad local port number: %s", p2);	  usage_small ();	}    }  else if (streq (p1, "rport") && p2)    {      ++i;      options->remote_port = atoi (p2);      if (options->remote_port <= 0)	{	  msg (M_WARN, "Bad remote port number: %s", p2);	  usage_small ();	}    }  else if (streq (p1, "nobind"))    {      options->bind_local = false;    }  else if (streq (p1, "inactive") && p2)    {      ++i;      options->inactivity_timeout = positive (atoi (p2));    }  else if (streq (p1, "ping") && p2)    {      ++i;      options->ping_send_timeout = positive (atoi (p2));    }  else if (streq (p1, "ping-exit") && p2)    {      ++i;      if (options->ping_rec_timeout_action)	ping_rec_err();      options->ping_rec_timeout = positive (atoi (p2));      options->ping_rec_timeout_action = PING_EXIT;    }  else if (streq (p1, "ping-restart") && p2)    {      ++i;      if (options->ping_rec_timeout_action)	ping_rec_err();      options->ping_rec_timeout = positive (atoi (p2));      options->ping_rec_timeout_action = PING_RESTART;    }  else if (streq (p1, "ping-timer-rem"))    {      options->ping_timer_remote = true;    }  else if (streq (p1, "persist-tun"))    {      options->persist_tun = true;    }  else if (streq (p1, "persist-key"))    {      options->persist_key = true;    }  else if (streq (p1, "persist-local-ip"))    {      options->persist_local_ip = true;    }  else if (streq (p1, "persist-remote-ip"))    {      options->persist_remote_ip = true;    }#if PASSTOS_CAPABILITY  else if (streq (p1, "passtos"))    {      options->passtos = true;    }#endif#ifdef USE_LZO  else if (streq (p1, "comp-lzo"))    {      options->comp_lzo = true;    }  else if (streq (p1, "comp-noadapt"))    {      options->comp_lzo_adaptive = false;    }#endif /* USE_LZO */#ifdef USE_CRYPTO  else if (streq (p1, "show-ciphers"))    {      options->show_ciphers = true;    }  else if (streq (p1, "show-digests"))    {      options->show_digests = true;    }  else if (streq (p1, "secret") && p2)    {      ++i;      options->shared_secret_file = p2;    }  else if (streq (p1, "genkey"))    {      options->genkey = true;    }  else if (streq (p1, "auth") && p2)    {      ++i;      options->authname_defined = true;      options->authname = p2;      if (streq (options->authname, "none"))	{	  options->authname_defined = false;	  options->authname = NULL;	}    }  else if (streq (p1, "auth"))    {      options->authname_defined = true;    }  else if (streq (p1, "cipher") && p2)    {      ++i;      options->ciphername_defined = true;      options->ciphername = p2;      if (streq (options->ciphername, "none"))	{	  options->ciphername_defined = false;	  options->ciphername = NULL;	}    }  else if (streq (p1, "cipher"))    {      options->ciphername_defined = true;    }  else if (streq (p1, "no-replay"))    {      options->packet_id = false;    }  else if (streq (p1, "no-iv"))    {      options->iv = false;    }  else if (streq (p1, "replay-persist") && p2)    {      ++i;      options->packet_id_file = p2;    }  else if (streq (p1, "test-crypto"))    {      options->test_crypto = true;    }#ifdef HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH  else if (streq (p1, "keysize") && p2)    {      ++i;      options->keysize = atoi (p2) / 8;      if (options->keysize < 0 || options->keysize > MAX_CIPHER_KEY_LENGTH)	{	  msg (M_WARN, "Bad keysize: %s", p2);	  usage_small ();	}    }#endif#ifdef USE_SSL  else if (streq (p1, "show-tls"))    {      options->show_tls_ciphers = true;    }  else if (streq (p1, "tls-server"))    {      options->tls_server = true;    }  else if (streq (p1, "tls-client"))    {      options->tls_client = true;    }  else if (streq (p1, "ca") && p2)    {      ++i;      options->ca_file = p2;    }  else if (streq (p1, "dh") && p2)    {      ++i;      options->dh_file = p2;    }  else if (streq (p1, "cert") && p2)    {      ++i;      options->cert_file = p2;    }  else if (streq (p1, "key") && p2)    {      ++i;      options->priv_key_file = p2;    }  else if (streq (p1, "askpass"))    {      options->askpass = true;    }  else if (streq (p1, "single-session"))    {      options->single_session = true;    }  else if (streq (p1, "disable-occ"))    {      options->disable_occ = true;    }  else if (streq (p1, "tls-cipher") && p2)    {      ++i;      options->cipher_list = p2;    }  else if (streq (p1, "tls-verify") && p2)    {      ++i;      options->tls_verify = comma_to_space (p2);    }  else if (streq (p1, "tls_timeout") && p2)    {      ++i;      options->tls_timeout = positive (atoi (p2));    }  else if (streq (p1, "reneg-bytes") && p2)    {      ++i;      options->renegotiate_bytes = positive (atoi (p2));    }  else if (streq (p1, "reneg-pkts") && p2)    {      ++i;      options->renegotiate_packets = positive (atoi (p2));    }  else if (streq (p1, "reneg-sec") && p2)    {      ++i;      options->renegotiate_seconds = positive (atoi (p2));    }  else if (streq (p1, "hand-window") && p2)    {      ++i;      options->handshake_window = positive (atoi (p2));    }  else if (streq (p1, "tran-window") && p2)    {      ++i;      options->transition_window = positive (atoi (p2));    }  else if (streq (p1, "tls-auth") && p2)    {      ++i;      options->tls_auth_file = p2;    }#endif /* USE_SSL */#endif /* USE_CRYPTO */#ifdef TUNSETPERSIST  else if (streq (p1, "rmtun"))    {      options->persist_config = true;      options->persist_mode = 0;    }  else if (streq (p1, "mktun"))    {      options->persist_config = true;      options->persist_mode = 1;    }#endif  else    {      if (file)	msg (M_WARN, "Unrecognized option or missing parameter(s) in %s:%d: %s", file, line, p1);      else	msg (M_WARN, "Unrecognized option or missing parameter(s): --%s", p1);      usage_small ();    }  return i;}voidparse_argv (struct options* options, int argc, char *argv[]){  int i;  /* usage message */  if (argc <= 1)    usage ();  /* parse command line */  for (i = 1; i < argc; ++i)    {      char *p1 = argv[i];      char *p2 = NULL;      char *p3 = NULL;      if (strncmp(p1, "--", 2))	{	  msg (M_WARN, "I'm trying to parse \"%s\" as an --option parameter but I don't see a leading '--'", p1);	  usage_small ();	}      p1 += 2;      if (i + 1 < argc)	{	  p2 = argv[i + 1];	  if (!strncmp (p2, "--", 2))	    p2 = NULL;	}      if (i + 2 < argc && p2)	{	  p3 = argv[i + 2];	  if (!strncmp (p3, "--", 2))	    p3 = NULL;	}      i = add_option (options, i, p1, p2, p3, NULL, 0, 0);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?