~ubuntu-branches/ubuntu/karmic/openvpn/karmic

« back to all changes in this revision

Viewing changes to options.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-05 14:25:37 UTC
  • mfrom: (1.1.12 upstream) (10.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090505142537-vq38z4k80bpltxb9
Tags: 2.1~rc15-1ubuntu1
* Merge from debian unstable (LP: #372358), remaining changes:
  - debian/openvpn.init.d: 
    - Do not use start-stop-daemon and use < /dev/null to avoid blocking boot
    - show per-VPN result messages 
    - add "--script-security 2" by default for backwards compatibility
    - Added lsb-base>=3.2-14 depend to allow status_of_proc()

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *             packet encryption, packet authentication, and
6
6
 *             packet compression.
7
7
 *
8
 
 *  Copyright (C) 2002-2008 Telethra, Inc. <sales@openvpn.net>
 
8
 *  Copyright (C) 2002-2008 OpenVPN Technologies, Inc. <sales@openvpn.net>
9
9
 *
10
10
 *  This program is free software; you can redistribute it and/or modify
11
11
 *  it under the terms of the GNU General Public License version 2
191
191
  "                  flag to add a direct route to DHCP server, bypassing tunnel.\n"
192
192
  "                  Add 'bypass-dns' flag to similarly bypass tunnel for DNS.\n"
193
193
  "--setenv name value : Set a custom environmental variable to pass to script.\n"
194
 
  "--script-security level : 0 -- strictly no calling of external programs\n"
195
 
  "                          1 -- (default) only call built-ins such as ifconfig\n"
196
 
  "                          2 -- allow calling of built-ins and scripts\n"
197
 
  "                          3 -- allow password to be passed to scripts via env\n"
 
194
  "--setenv FORWARD_COMPATIBLE 1 : Relax config file syntax checking to allow\n"
 
195
  "                  directives for future OpenVPN versions to be ignored.\n"
 
196
  "--script-security level mode : mode='execve' (default) or 'system', level=\n"
 
197
  "                  0 -- strictly no calling of external programs\n"
 
198
  "                  1 -- (default) only call built-ins such as ifconfig\n"
 
199
  "                  2 -- allow calling of built-ins and scripts\n"
 
200
  "                  3 -- allow password to be passed to scripts via env\n"
198
201
  "--shaper n      : Restrict output to peer to n bytes per second.\n"
199
202
  "--keepalive n m : Helper option for setting timeouts in server mode.  Send\n"
200
203
  "                  ping once every n seconds, restart if ping not received\n"
294
297
  "--mute n        : Log at most n consecutive messages in the same category.\n"
295
298
  "--status file n : Write operational status to file every n seconds.\n"
296
299
  "--status-version [n] : Choose the status file format version number.\n"
297
 
  "                  Currently, n can be 1 or 2 (default=1).\n"
 
300
  "                  Currently, n can be 1, 2, or 3 (default=1).\n"
298
301
#ifdef ENABLE_OCC
299
302
  "--disable-occ   : Disable options consistency check between peers.\n"
300
303
#endif
311
314
  "--management ip port [pass] : Enable a TCP server on ip:port to handle\n"
312
315
  "                  management functions.  pass is a password file\n"
313
316
  "                  or 'stdin' to prompt from console.\n"
 
317
#if UNIX_SOCK_SUPPORT
 
318
  "                  To listen on a unix domain socket, specific the pathname\n"
 
319
  "                  in place of ip and use 'unix' as the port number.\n"
 
320
#endif
314
321
  "--management-client : Management interface will connect as a TCP client to\n"
315
322
  "                      ip/port rather than listen as a TCP server.\n"
316
323
  "--management-query-passwords : Query management channel for private key\n"
322
329
  "                                 event occurs.\n"
323
330
  "--management-log-cache n : Cache n lines of log file history for usage\n"
324
331
  "                  by the management channel.\n"
 
332
#if UNIX_SOCK_SUPPORT
 
333
  "--management-client-user u  : When management interface is a unix socket, only\n"
 
334
  "                              allow connections from user u.\n"
 
335
  "--management-client-group g : When management interface is a unix socket, only\n"
 
336
  "                              allow connections from group g.\n"
 
337
#endif
325
338
#ifdef MANAGEMENT_DEF_AUTH
326
339
  "--management-client-auth : gives management interface client the responsibility\n"
327
340
  "                           to authenticate clients after their client certificate\n"
371
384
  "                  run script cmd to verify.  If method='via-env', pass\n"
372
385
  "                  user/pass via environment, if method='via-file', pass\n"
373
386
  "                  user/pass via temporary file.\n"
 
387
  "--opt-verify    : Clients that connect with options that are incompatible\n"
 
388
  "                  with those of the server will be disconnected.\n"
 
389
  "--auth-user-pass-optional : Allow connections by clients that don't\n"
 
390
  "                  specify a username/password.\n"
 
391
  "--no-name-remapping : Allow Common Name and X509 Subject to include\n"
 
392
  "                      any printable character.\n"
374
393
  "--client-to-client : Internally route client-to-client traffic.\n"
375
394
  "--duplicate-cn  : Allow multiple clients with the same common name to\n"
376
395
  "                  concurrently connect.\n"
383
402
  "                  virtual address table to v.\n"
384
403
  "--bcast-buffers n : Allocate n broadcast buffers.\n"
385
404
  "--tcp-queue-limit n : Maximum number of queued TCP output packets.\n"
 
405
  "--tcp-nodelay   : Macro that sets TCP_NODELAY socket flag on the server\n"
 
406
  "                  as well as pushes it to connecting clients.\n"
386
407
  "--learn-address cmd : Run script cmd to validate client virtual addresses.\n"
387
408
  "--connect-freq n s : Allow a maximum of n new connections per s seconds.\n"
388
409
  "--max-clients n : Allow a maximum of n simultaneously connected clients.\n"
425
446
  "--cipher alg    : Encrypt packets with cipher algorithm alg\n"
426
447
  "                  (default=%s).\n"
427
448
  "                  Set alg=none to disable encryption.\n"
 
449
  "--prng alg [nsl] : For PRNG, use digest algorithm alg, and\n"
 
450
  "                   nonce_secret_len=nsl.  Set alg=none to disable PRNG.\n"
428
451
#ifdef HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH
429
452
  "--keysize n     : Size of cipher key in bits (optional).\n"
430
453
  "                  If unspecified, defaults to cipher-specific default.\n"
700
723
  o->ciphername_defined = true;
701
724
  o->authname = "SHA1";
702
725
  o->authname_defined = true;
 
726
  o->prng_hash = "SHA1";
 
727
  o->prng_nonce_secret_len = 16;
703
728
  o->replay = true;
704
729
  o->replay_window = DEFAULT_SEQ_BACKTRACK;
705
730
  o->replay_time = DEFAULT_TIME_BACKTRACK;
955
980
  SHOW_INT (cf_per);
956
981
  SHOW_INT (max_clients);
957
982
  SHOW_INT (max_routes_per_client);
958
 
  SHOW_BOOL (client_cert_not_required);
959
 
  SHOW_BOOL (username_as_common_name)
960
983
  SHOW_STR (auth_user_pass_verify_script);
961
984
  SHOW_BOOL (auth_user_pass_verify_script_via_file);
 
985
  SHOW_INT (ssl_flags);
962
986
#if PORT_SHARE
963
987
  SHOW_STR (port_share_host);
964
988
  SHOW_INT (port_share_port);
1240
1264
  SHOW_INT (management_log_history_cache);
1241
1265
  SHOW_INT (management_echo_buffer_size);
1242
1266
  SHOW_STR (management_write_peer_info_file);
 
1267
  SHOW_STR (management_client_user);
 
1268
  SHOW_STR (management_client_group);
1243
1269
  SHOW_INT (management_flags);
1244
1270
#endif
1245
1271
#ifdef ENABLE_PLUGIN
1254
1280
  SHOW_STR (ciphername);
1255
1281
  SHOW_BOOL (authname_defined);
1256
1282
  SHOW_STR (authname);
 
1283
  SHOW_STR (prng_hash);
 
1284
  SHOW_INT (prng_nonce_secret_len);
1257
1285
  SHOW_INT (keysize);
1258
1286
  SHOW_BOOL (engine);
1259
1287
  SHOW_BOOL (replay);
1554
1582
       || options->management_write_peer_info_file
1555
1583
       || options->management_log_history_cache != defaults.management_log_history_cache))
1556
1584
    msg (M_USAGE, "--management is not specified, however one or more options which modify the behavior of --management were specified");
 
1585
 
 
1586
  if ((options->management_flags & (MF_LISTEN_UNIX|MF_CONNECT_AS_CLIENT))
 
1587
      == (MF_LISTEN_UNIX|MF_CONNECT_AS_CLIENT))
 
1588
    msg (M_USAGE, "--management-client does not support unix domain sockets");
 
1589
 
 
1590
  if ((options->management_client_user || options->management_client_group)
 
1591
      && !(options->management_flags & MF_LISTEN_UNIX))
 
1592
    msg (M_USAGE, "--management-client-(user|group) can only be used on unix domain sockets");
1557
1593
#endif
1558
1594
 
1559
1595
  /*
1682
1718
                             || PLUGIN_OPTION_LIST (options)
1683
1719
                             || MAN_CLIENT_AUTH_ENABLED (options));
1684
1720
          const char *postfix = "must be used with --management-client-auth, an --auth-user-pass-verify script, or plugin";
1685
 
          if (options->client_cert_not_required && !ccnr)
 
1721
          if ((options->ssl_flags & SSLF_CLIENT_CERT_NOT_REQUIRED) && !ccnr)
1686
1722
            msg (M_USAGE, "--client-cert-not-required %s", postfix);
1687
 
          if (options->username_as_common_name && !ccnr)
 
1723
          if ((options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) && !ccnr)
1688
1724
            msg (M_USAGE, "--username-as-common-name %s", postfix);
 
1725
          if ((options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL) && !ccnr)
 
1726
            msg (M_USAGE, "--auth-user-pass-optional %s", postfix);
1689
1727
        }
 
1728
 
 
1729
        if ((options->ssl_flags & SSLF_NO_NAME_REMAPPING) && script_method == SM_SYSTEM)
 
1730
          msg (M_USAGE, "--script-security method='system' cannot be combined with --no-name-remapping");
1690
1731
    }
1691
1732
  else
1692
1733
    {
1715
1756
        msg (M_USAGE, "--duplicate-cn requires --mode server");
1716
1757
      if (options->cf_max || options->cf_per)
1717
1758
        msg (M_USAGE, "--connect-freq requires --mode server");
1718
 
      if (options->client_cert_not_required)
 
1759
      if (options->ssl_flags & SSLF_CLIENT_CERT_NOT_REQUIRED)
1719
1760
        msg (M_USAGE, "--client-cert-not-required requires --mode server");
1720
 
      if (options->username_as_common_name)
 
1761
      if (options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME)
1721
1762
        msg (M_USAGE, "--username-as-common-name requires --mode server");
 
1763
      if (options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL)
 
1764
        msg (M_USAGE, "--auth-user-pass-optional requires --mode server");
 
1765
      if (options->ssl_flags & SSLF_NO_NAME_REMAPPING)
 
1766
        msg (M_USAGE, "--no-name-remapping requires --mode server");
 
1767
      if (options->ssl_flags & SSLF_OPT_VERIFY)
 
1768
        msg (M_USAGE, "--opt-verify requires --mode server");
 
1769
      if (options->server_flags & SF_TCP_NODELAY_HELPER)
 
1770
        msg (M_USAGE, "--tcp-nodelay requires --mode server");
1722
1771
      if (options->auth_user_pass_verify_script)
1723
1772
        msg (M_USAGE, "--auth-user-pass-verify requires --mode server");
1724
1773
#if PORT_SHARE
2020
2069
   */
2021
2070
  helper_client_server (o);
2022
2071
  helper_keepalive (o);
 
2072
  helper_tcp_nodelay (o);
2023
2073
 
2024
2074
  options_postprocess_mutate_invariant (o);
2025
2075
 
2679
2729
{
2680
2730
  msg (M_INFO|M_NOPREFIX, "%s", title_string);
2681
2731
  msg (M_INFO|M_NOPREFIX, "Developed by James Yonan");
2682
 
  msg (M_INFO|M_NOPREFIX, "Copyright (C) 2002-2008 Telethra, Inc. <sales@openvpn.net>");
 
2732
  msg (M_INFO|M_NOPREFIX, "Copyright (C) 2002-2008 OpenVPN Technologies, Inc. <sales@openvpn.net>");
2683
2733
  openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
2684
2734
}
2685
2735
 
2814
2864
          if (backslash && out)
2815
2865
            {
2816
2866
              if (!(out == '\\' || out == '\"' || space (out)))
 
2867
                {
2817
2868
#ifdef ENABLE_SMALL
2818
 
                msg (msglevel, "%sOptions warning: Bad backslash ('\\') usage in %s:%d", error_prefix, file, line_num);
 
2869
                  msg (msglevel, "%sOptions warning: Bad backslash ('\\') usage in %s:%d", error_prefix, file, line_num);
2819
2870
#else
2820
 
                msg (msglevel, "%sOptions warning: Bad backslash ('\\') usage in %s:%d: remember that backslashes are treated as shell-escapes and if you need to pass backslash characters as part of a Windows filename, you should use double backslashes such as \"c:\\\\" PACKAGE "\\\\static.key\"", error_prefix, file, line_num);
 
2871
                  msg (msglevel, "%sOptions warning: Bad backslash ('\\') usage in %s:%d: remember that backslashes are treated as shell-escapes and if you need to pass backslash characters as part of a Windows filename, you should use double backslashes such as \"c:\\\\" PACKAGE "\\\\static.key\"", error_prefix, file, line_num);
2821
2872
#endif
 
2873
                  return 0;
 
2874
                }
2822
2875
            }
2823
2876
          backslash = false;
2824
2877
        }
3240
3293
    return true;
3241
3294
}
3242
3295
 
 
3296
static inline int
 
3297
msglevel_forward_compatible (struct options *options, const int msglevel)
 
3298
{
 
3299
  return options->forward_compatible ? M_WARN : msglevel;
 
3300
}
 
3301
 
3243
3302
static void
3244
3303
add_option (struct options *options,
3245
3304
            char *p[],
3253
3312
{
3254
3313
  struct gc_arena gc = gc_new ();
3255
3314
  const bool pull_mode = BOOL_CAST (permission_mask & OPT_P_PULL_MODE);
 
3315
  int msglevel_fc = msglevel_forward_compatible (options, msglevel);
3256
3316
 
3257
3317
  ASSERT (MAX_PARMS >= 5);
3258
3318
  if (!file)
3319
3379
#ifdef ENABLE_MANAGEMENT
3320
3380
  else if (streq (p[0], "management") && p[1] && p[2])
3321
3381
    {
3322
 
      int port;
 
3382
      int port = 0;
3323
3383
 
3324
3384
      VERIFY_PERMISSION (OPT_P_GENERAL);
3325
 
      port = atoi (p[2]);
3326
 
      if (!legal_ipv4_port (port))
 
3385
      if (streq (p[2], "unix"))
3327
3386
        {
3328
 
          msg (msglevel, "port number associated with --management directive is out of range");
 
3387
#if UNIX_SOCK_SUPPORT
 
3388
          options->management_flags |= MF_LISTEN_UNIX;
 
3389
#else
 
3390
          msg (msglevel, "MANAGEMENT: this platform does not support unix domain sockets");
3329
3391
          goto err;
 
3392
#endif
 
3393
        }
 
3394
      else
 
3395
        {
 
3396
          port = atoi (p[2]);
 
3397
          if (!legal_ipv4_port (port))
 
3398
            {
 
3399
              msg (msglevel, "port number associated with --management directive is out of range");
 
3400
              goto err;
 
3401
            }
3330
3402
        }
3331
3403
 
3332
3404
      options->management_addr = p[1];
3336
3408
          options->management_user_pass = p[3];
3337
3409
        }
3338
3410
    }
 
3411
  else if (streq (p[0], "management-client-user") && p[1])
 
3412
    {
 
3413
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
3414
      options->management_client_user = p[1];
 
3415
    }
 
3416
  else if (streq (p[0], "management-client-group") && p[1])
 
3417
    {
 
3418
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
3419
      options->management_client_group = p[1];
 
3420
    }
3339
3421
  else if (streq (p[0], "management-query-passwords"))
3340
3422
    {
3341
3423
      VERIFY_PERMISSION (OPT_P_GENERAL);
3436
3518
  else if (streq (p[0], "lladdr") && p[1])
3437
3519
    {
3438
3520
      VERIFY_PERMISSION (OPT_P_UP);
3439
 
      if (ip_addr_dotted_quad_safe (p[1])) /* FQDN -- IP address only */
 
3521
      if (mac_addr_safe (p[1])) /* MAC address only */
3440
3522
        options->lladdr = p[1];
3441
3523
      else
3442
3524
        {
3443
 
          msg (msglevel, "lladdr parm '%s' must be an IP address", p[1]);
 
3525
          msg (msglevel, "lladdr parm '%s' must be a MAC address", p[1]);
3444
3526
          goto err;
3445
3527
        }
3446
3528
    }
3790
3872
 
3791
3873
      VERIFY_PERMISSION (OPT_P_GENERAL);
3792
3874
      version = atoi (p[1]);
3793
 
      if (version < 1 || version > 2)
 
3875
      if (version < 1 || version > 3)
3794
3876
        {
3795
 
          msg (msglevel, "--status-version must be 1 or 2");
 
3877
          msg (msglevel, "--status-version must be 1 to 3");
3796
3878
          goto err;
3797
3879
        }
3798
3880
      options->status_file_version = version;
4328
4410
  else if (streq (p[0], "setenv") && p[1])
4329
4411
    {
4330
4412
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
4413
      if (streq (p[1], "FORWARD_COMPATIBLE") && p[2] && streq (p[2], "1"))
 
4414
        {
 
4415
          options->forward_compatible = true;
 
4416
          msglevel_fc = msglevel_forward_compatible (options, msglevel);
 
4417
        }
4331
4418
      setenv_str (es, p[1], p[2] ? p[2] : "");
4332
4419
    }
4333
4420
  else if (streq (p[0], "setenv-safe") && p[1])
4339
4426
    {
4340
4427
      VERIFY_PERMISSION (OPT_P_GENERAL);
4341
4428
      script_security = atoi (p[1]);
4342
 
    }  
 
4429
      if (p[2])
 
4430
        {
 
4431
          if (streq (p[2], "execve"))
 
4432
            script_method = SM_EXECVE;
 
4433
          else if (streq (p[2], "system"))
 
4434
            script_method = SM_SYSTEM;
 
4435
          else
 
4436
            {
 
4437
              msg (msglevel, "unknown --script-security method: %s", p[2]);
 
4438
              goto err;
 
4439
            }
 
4440
        }
 
4441
      else
 
4442
        script_method = SM_EXECVE;
 
4443
    }
4343
4444
  else if (streq (p[0], "mssfix"))
4344
4445
    {
4345
4446
      VERIFY_PERMISSION (OPT_P_GENERAL);
4450
4551
      options->ifconfig_pool_defined = true;
4451
4552
      options->ifconfig_pool_start = start;
4452
4553
      options->ifconfig_pool_end = end;
4453
 
      options->ifconfig_pool_netmask = netmask;
 
4554
      if (netmask)
 
4555
        options->ifconfig_pool_netmask = netmask;
4454
4556
    }
4455
4557
  else if (streq (p[0], "ifconfig-pool-persist") && p[1])
4456
4558
    {
4517
4619
  else if (streq (p[0], "client-cert-not-required"))
4518
4620
    {
4519
4621
      VERIFY_PERMISSION (OPT_P_GENERAL);
4520
 
      options->client_cert_not_required = true;
 
4622
      options->ssl_flags |= SSLF_CLIENT_CERT_NOT_REQUIRED;
4521
4623
    }
4522
4624
  else if (streq (p[0], "username-as-common-name"))
4523
4625
    {
4524
4626
      VERIFY_PERMISSION (OPT_P_GENERAL);
4525
 
      options->username_as_common_name = true;
 
4627
      options->ssl_flags |= SSLF_USERNAME_AS_COMMON_NAME;
 
4628
    }
 
4629
  else if (streq (p[0], "auth-user-pass-optional"))
 
4630
    {
 
4631
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
4632
      options->ssl_flags |= SSLF_AUTH_USER_PASS_OPTIONAL;
 
4633
    }
 
4634
  else if (streq (p[0], "no-name-remapping"))
 
4635
    {
 
4636
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
4637
      options->ssl_flags |= SSLF_NO_NAME_REMAPPING;
 
4638
    }
 
4639
  else if (streq (p[0], "opt-verify"))
 
4640
    {
 
4641
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
4642
      options->ssl_flags |= SSLF_OPT_VERIFY;
4526
4643
    }
4527
4644
  else if (streq (p[0], "auth-user-pass-verify") && p[1])
4528
4645
    {
4685
4802
      VERIFY_PERMISSION (OPT_P_INSTANCE);
4686
4803
      options->disable = true;
4687
4804
    }
 
4805
  else if (streq (p[0], "tcp-nodelay"))
 
4806
    {
 
4807
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
4808
      options->server_flags |= SF_TCP_NODELAY_HELPER;
 
4809
    }
4688
4810
#endif /* P2MP_SERVER */
4689
4811
 
4690
4812
  else if (streq (p[0], "client"))
5063
5185
      VERIFY_PERMISSION (OPT_P_CRYPTO);
5064
5186
      options->ciphername_defined = true;
5065
5187
    }
 
5188
  else if (streq (p[0], "prng") && p[1])
 
5189
    {
 
5190
      VERIFY_PERMISSION (OPT_P_CRYPTO);
 
5191
      if (streq (p[1], "none"))
 
5192
        options->prng_hash = NULL;
 
5193
      else
 
5194
        options->prng_hash = p[1];
 
5195
      if (p[2])
 
5196
        {
 
5197
          const int sl = atoi (p[2]);
 
5198
          if (sl >= NONCE_SECRET_LEN_MIN && sl <= NONCE_SECRET_LEN_MAX)
 
5199
            {
 
5200
              options->prng_nonce_secret_len = sl;
 
5201
            }
 
5202
          else
 
5203
            {
 
5204
              msg (msglevel, "prng parameter nonce_secret_len must be between %d and %d",
 
5205
                   NONCE_SECRET_LEN_MIN, NONCE_SECRET_LEN_MAX);
 
5206
              goto err;
 
5207
            }
 
5208
        }
 
5209
    }
5066
5210
  else if (streq (p[0], "no-replay"))
5067
5211
    {
5068
5212
      VERIFY_PERMISSION (OPT_P_CRYPTO);
5480
5624
  else
5481
5625
    {
5482
5626
      if (file)
5483
 
        msg (msglevel, "Unrecognized option or missing parameter(s) in %s:%d: %s (%s)", file, line, p[0], PACKAGE_VERSION);
 
5627
        msg (msglevel_fc, "Unrecognized option or missing parameter(s) in %s:%d: %s (%s)", file, line, p[0], PACKAGE_VERSION);
5484
5628
      else
5485
 
        msg (msglevel, "Unrecognized option or missing parameter(s): --%s (%s)", p[0], PACKAGE_VERSION);
 
5629
        msg (msglevel_fc, "Unrecognized option or missing parameter(s): --%s (%s)", p[0], PACKAGE_VERSION);
5486
5630
    }
5487
5631
 err:
5488
5632
  gc_free (&gc);