~ubuntu-branches/ubuntu/oneiric/openvpn/oneiric

« back to all changes in this revision

Viewing changes to options.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-06-16 18:33:37 UTC
  • mfrom: (1.1.17 upstream) (10.2.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110616183337-fv50u3kmiabewjq0
Tags: 2.2.0-2ubuntu1
* Merge from debian unstable.  Remaining changes:
 + debian/openvpn.init.d:
    - Do not use start-stop-daemon and </dev/null to avoid blocking boot.
    - Show per-VPN result messages.
    - Add "--script-security 2" by default for backwards compatabliity.
  + debian/control: Add lsb-base >= 3.2-14 to allow status_of_proc()
  + debian/update-resolv-conf: Support multiple domains.
  + fix bug where '--script-security 2' would be passed for all
    daemons after the first. (LP: #794916

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include "pool.h"
49
49
#include "helper.h"
50
50
#include "manage.h"
 
51
#include "forward.h"
 
52
#include "configure.h"
 
53
#include <ctype.h>
51
54
 
52
55
#include "memdbg.h"
53
56
 
70
73
#ifdef PRODUCT_TAP_DEBUG
71
74
  " [TAPDBG]"
72
75
#endif
73
 
#ifdef USE_PTHREAD
74
 
  " [PTHREAD]"
75
 
#endif
76
76
#ifdef ENABLE_PKCS11
77
77
  " [PKCS11]"
78
78
#endif
79
 
#ifdef ENABLE_IP_PKTINFO
 
79
#ifdef ENABLE_EUREPHIA
 
80
  " [eurephia]"
 
81
#endif
 
82
#if ENABLE_IP_PKTINFO
80
83
  " [MH]"
81
84
#endif
82
85
#ifdef USE_PF_INET6
83
86
  " [PF_INET6]"
84
87
#endif
85
 
  " [eurephia]"
 
88
  " [IPv6 payload 20110424-2 (2.2RC2)]"
86
89
  " built on " __DATE__
87
90
;
88
91
 
104
107
  "--mode m        : Major mode, m = 'p2p' (default, point-to-point) or 'server'.\n"
105
108
  "--proto p       : Use protocol p for communicating with peer.\n"
106
109
  "                  p = udp (default), tcp-server, or tcp-client\n"
 
110
  "--proto-force p : only consider protocol p in list of connection profiles.\n"
107
111
#ifdef USE_PF_INET6
108
112
  "                  p = udp6, tcp6-server, or tcp6-client (ipv6)\n"
109
113
#endif
132
136
  "                  AGENT user-agent\n"
133
137
#endif
134
138
#ifdef ENABLE_SOCKS
135
 
  "--socks-proxy s [p]: Connect to remote host through a Socks5 proxy at address\n"
136
 
  "                  s and port p (default port = 1080).\n"
 
139
  "--socks-proxy s [p] [up] : Connect to remote host through a Socks5 proxy at\n"
 
140
  "                  address s and port p (default port = 1080).\n"
 
141
  "                  If proxy authentication is required,\n"
 
142
  "                  up is a file containing username/password on 2 lines, or\n"
 
143
  "                  'stdin' to prompt for console.\n"
137
144
  "--socks-proxy-retry : Retry indefinitely on Socks proxy errors.\n"
138
145
#endif
139
146
  "--resolv-retry n: If hostname resolve fails for --remote, retry\n"
174
181
  "                  addresses outside of the subnets used by either peer.\n"
175
182
  "                  TAP: configure device to use IP address l as a local\n"
176
183
  "                  endpoint and rn as a subnet mask.\n"
 
184
  "--ifconfig-ipv6 l r : configure device to use IPv6 address l as local\n"
 
185
  "                      endpoint (as a /64) and r as remote endpoint\n"
177
186
  "--ifconfig-noexec : Don't actually execute ifconfig/netsh command, instead\n"
178
187
  "                    pass --ifconfig parms by environment to scripts.\n"
179
188
  "--ifconfig-nowarn : Don't warn if the --ifconfig option on this side of the\n"
184
193
  "                  netmask default: 255.255.255.255\n"
185
194
  "                  gateway default: taken from --route-gateway or --ifconfig\n"
186
195
  "                  Specify default by leaving blank or setting to \"nil\".\n"
 
196
  "--route-ipv6 network/bits [gateway] [metric] :\n"
 
197
  "                  Add IPv6 route to routing table after connection\n"
 
198
  "                  is established.  Multiple routes can be specified.\n"
 
199
  "                  gateway default: taken from --route-ipv6-gateway or --ifconfig\n"
187
200
  "--max-routes n :  Specify the maximum number of routes that may be defined\n"
188
201
  "                  or pulled from a server.\n"
189
202
  "--route-gateway gw|'dhcp' : Specify a default gateway for use with --route.\n"
300
313
  "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n"
301
314
  "--writepid file : Write main process ID to file.\n"
302
315
  "--nice n        : Change process priority (>0 = lower, <0 = higher).\n"
303
 
#if 0
304
 
#ifdef USE_PTHREAD
305
 
  "--nice-work n   : Change thread priority of work thread.  The work\n"
306
 
  "                  thread is used for background processing such as\n"
307
 
  "                  RSA key number crunching.\n"
308
 
#endif
309
 
#endif
310
316
  "--echo [parms ...] : Echo parameters to log output.\n"
311
317
  "--verb n        : Set output verbosity to n (default=%d):\n"
312
318
  "                  (Level 3 is recommended if you want a good summary\n"
379
385
  "\n"
380
386
  "Multi-Client Server options (when --mode server is used):\n"
381
387
  "--server network netmask : Helper option to easily configure server mode.\n"
 
388
  "--server-ipv6 network/bits : Configure IPv6 server mode.\n"
382
389
  "--server-bridge [IP netmask pool-start-IP pool-end-IP] : Helper option to\n"
383
390
  "                    easily configure ethernet bridging server mode.\n"
384
391
  "--push \"option\" : Push a config file option back to the peer for remote\n"
392
399
  "--ifconfig-pool-persist file [seconds] : Persist/unpersist ifconfig-pool\n"
393
400
  "                  data to file, at seconds intervals (default=600).\n"
394
401
  "                  If seconds=0, file will be treated as read-only.\n"
 
402
  "--ifconfig-ipv6-pool base-IP/bits : set aside an IPv6 network block\n"
 
403
  "                  to be dynamically allocated to connecting clients.\n"
395
404
  "--ifconfig-push local remote-netmask : Push an ifconfig option to remote,\n"
396
405
  "                  overrides --ifconfig-pool dynamic allocation.\n"
397
406
  "                  Only valid in a client-specific config file.\n"
 
407
  "--ifconfig-ipv6-push local/bits remote : Push an ifconfig-ipv6 option to\n"
 
408
  "                  remote, overrides --ifconfig-ipv6-pool allocation.\n"
 
409
  "                  Only valid in a client-specific config file.\n"
398
410
  "--iroute network [netmask] : Route subnet to client.\n"
 
411
  "--iroute-ipv6 network/bits : Route IPv6 subnet to client.\n"
399
412
  "                  Sets up internal routes only.\n"
400
413
  "                  Only valid in a client-specific config file.\n"
401
414
  "--disable       : Client is disabled.\n"
422
435
  "--client-disconnect cmd : Run script cmd on client disconnection.\n"
423
436
  "--client-config-dir dir : Directory for custom client config files.\n"
424
437
  "--ccd-exclusive : Refuse connection unless custom client config is found.\n"
425
 
  "--tmp-dir dir   : Temporary directory, used for --client-connect return file.\n"
 
438
  "--tmp-dir dir   : Temporary directory, used for --client-connect return file and plugin communication.\n"
426
439
  "--hash-size r v : Set the size of the real address hash table to r and the\n"
427
440
  "                  virtual address table to v.\n"
428
441
  "--bcast-buffers n : Allocate n broadcast buffers.\n"
516
529
  "--key file      : Local private key in .pem format.\n"
517
530
  "--pkcs12 file   : PKCS#12 file containing local private key, local certificate\n"
518
531
  "                  and optionally the root CA certificate.\n"
 
532
#ifdef ENABLE_X509ALTUSERNAME
 
533
  "--x509-username-field : Field used in x509 certificat to be username.\n"
 
534
  "                        Default is CN.\n"
 
535
#endif
519
536
#ifdef WIN32
520
537
  "--cryptoapicert select-string : Load the certificate and private key from the\n"
521
538
  "                  Windows Certificate System Store.\n"
546
563
  "                  tests of certification.  cmd should return 0 to allow\n"
547
564
  "                  TLS handshake to proceed, or 1 to fail.  (cmd is\n"
548
565
  "                  executed as 'cmd certificate_depth X509_NAME_oneline')\n"
 
566
  "--tls-export-cert [directory] : Get peer cert in PEM format and store it \n"
 
567
  "                  in an openvpn temporary file in [directory]. Peer cert is \n"
 
568
  "                  stored before tls-verify script execution and deleted after.\n"
549
569
  "--tls-remote x509name: Accept connections only from a host with X509 name\n"
550
570
  "                  x509name. The remote host must also pass all other tests\n"
551
571
  "                  of verification.\n"
706
726
  o->route_delay_window = 30;
707
727
  o->max_routes = MAX_ROUTES_DEFAULT;
708
728
  o->resolve_retry_seconds = RESOLV_RETRY_INFINITE;
 
729
  o->proto_force = -1;
709
730
#ifdef ENABLE_OCC
710
731
  o->occ = true;
711
732
#endif
734
755
  o->tuntap_options.dhcp_masq_offset = 0;       /* use network address as internal DHCP server address */
735
756
  o->route_method = ROUTE_METHOD_ADAPTIVE;
736
757
#endif
737
 
#ifdef USE_PTHREAD
738
 
  o->n_threads = 1;
739
 
#endif
740
758
#if P2MP_SERVER
741
759
  o->real_hash_size = 256;
742
760
  o->virtual_hash_size = 256;
768
786
  o->renegotiate_seconds = 3600;
769
787
  o->handshake_window = 60;
770
788
  o->transition_window = 3600;
771
 
#endif
772
 
#endif
 
789
#ifdef ENABLE_X509ALTUSERNAME
 
790
  o->x509_username_field = X509_USERNAME_FIELD_DEFAULT;
 
791
#endif
 
792
#endif /* USE_SSL */
 
793
#endif /* USE_CRYPTO */
773
794
#ifdef ENABLE_PKCS11
774
795
  o->pkcs11_pin_cache_period = -1;
775
796
#endif                  /* ENABLE_PKCS11 */
 
797
 
 
798
  /* Set default --tmp-dir */
 
799
#ifdef WIN32
 
800
  /* On Windows, find temp dir via enviroment variables */
 
801
  o->tmp_dir = win_get_tempdir();
 
802
#else
 
803
  /* Non-windows platforms use $TMPDIR, and if not set, default to '/tmp' */
 
804
  o->tmp_dir = getenv("TMPDIR");
 
805
  if( !o->tmp_dir ) {
 
806
          o->tmp_dir = "/tmp";
 
807
  }
 
808
#endif /* WIN32 */
776
809
}
777
810
 
778
811
void
860
893
  return ret;
861
894
}
862
895
 
 
896
/* helper: parse a text string containing an IPv6 address + netbits
 
897
 * in "standard format" (2001:dba::/32)
 
898
 * "/nn" is optional, default to /64 if missing
 
899
 *
 
900
 * return true if parsing succeeded, modify *network and *netbits
 
901
 * return address part without "/nn" in *printable_ipv6 (if != NULL)
 
902
 */
 
903
bool
 
904
get_ipv6_addr( const char * prefix_str, struct in6_addr *network,
 
905
               unsigned int * netbits, char ** printable_ipv6, int msglevel )
 
906
{
 
907
    int rc;
 
908
    char * sep, * endp;
 
909
    int bits;
 
910
    struct in6_addr t_network;
 
911
 
 
912
    sep = strchr( prefix_str, '/' );
 
913
    if ( sep == NULL )
 
914
      {
 
915
        bits = 64;
 
916
      }
 
917
    else
 
918
      {
 
919
        bits = strtol( sep+1, &endp, 10 );
 
920
        if ( *endp != '\0' || bits < 0 || bits > 128 )
 
921
          {
 
922
            msg (msglevel, "IPv6 prefix '%s': invalid '/bits' spec", prefix_str);
 
923
            return false;
 
924
          }
 
925
      }
 
926
 
 
927
    /* temporary replace '/' in caller-provided string with '\0', otherwise
 
928
     * inet_pton() will refuse prefix string
 
929
     * (alternative would be to strncpy() the prefix to temporary buffer)
 
930
     */
 
931
 
 
932
    if ( sep != NULL ) *sep = '\0';
 
933
 
 
934
    rc = inet_pton( AF_INET6, prefix_str, &t_network );
 
935
 
 
936
    if ( rc == 1 && printable_ipv6 != NULL )
 
937
      {
 
938
        *printable_ipv6 = string_alloc( prefix_str, NULL );
 
939
      }
 
940
 
 
941
    if ( sep != NULL ) *sep = '/';
 
942
 
 
943
    if ( rc != 1 )
 
944
      {
 
945
        msg (msglevel, "IPv6 prefix '%s': invalid IPv6 address", prefix_str);
 
946
        return false;
 
947
      }
 
948
 
 
949
    if ( netbits != NULL )
 
950
      {
 
951
        *netbits = bits;
 
952
      }
 
953
    if ( network != NULL )
 
954
      {
 
955
        *network = t_network;
 
956
      }
 
957
    return true;                /* parsing OK, values set */
 
958
}
 
959
 
 
960
static bool ipv6_addr_safe_hexplusbits( const char * ipv6_prefix_spec )
 
961
{
 
962
    struct in6_addr t_addr;
 
963
    unsigned int t_bits;
 
964
 
 
965
    return get_ipv6_addr( ipv6_prefix_spec, &t_addr, &t_bits, NULL, M_WARN );
 
966
}
 
967
 
863
968
static char *
864
969
string_substitute (const char *src, int from, int to, struct gc_arena *gc)
865
970
{
885
990
      || o->persist_key
886
991
      || o->persist_local_ip
887
992
      || o->persist_remote_ip
888
 
#ifdef USE_PTHREAD
889
 
      || o->n_threads >= 2
890
 
#endif
891
993
    ;
892
994
}
893
995
 
981
1083
#if P2MP_SERVER
982
1084
  msg (D_SHOW_PARMS, "  server_network = %s", print_in_addr_t (o->server_network, 0, &gc));
983
1085
  msg (D_SHOW_PARMS, "  server_netmask = %s", print_in_addr_t (o->server_netmask, 0, &gc));
 
1086
  msg (D_SHOW_PARMS, "  server_network_ipv6 = %s", print_in6_addr (o->server_network_ipv6, 0, &gc) );
 
1087
  SHOW_INT (server_netbits_ipv6);
984
1088
  msg (D_SHOW_PARMS, "  server_bridge_ip = %s", print_in_addr_t (o->server_bridge_ip, 0, &gc));
985
1089
  msg (D_SHOW_PARMS, "  server_bridge_netmask = %s", print_in_addr_t (o->server_bridge_netmask, 0, &gc));
986
1090
  msg (D_SHOW_PARMS, "  server_bridge_pool_start = %s", print_in_addr_t (o->server_bridge_pool_start, 0, &gc));
1001
1105
  msg (D_SHOW_PARMS, "  ifconfig_pool_netmask = %s", print_in_addr_t (o->ifconfig_pool_netmask, 0, &gc));
1002
1106
  SHOW_STR (ifconfig_pool_persist_filename);
1003
1107
  SHOW_INT (ifconfig_pool_persist_refresh_freq);
 
1108
  SHOW_BOOL (ifconfig_ipv6_pool_defined);
 
1109
  msg (D_SHOW_PARMS, "  ifconfig_ipv6_pool_base = %s", print_in6_addr (o->ifconfig_ipv6_pool_base, 0, &gc));
 
1110
  SHOW_INT (ifconfig_ipv6_pool_netbits);
1004
1111
  SHOW_INT (n_bcast_buf);
1005
1112
  SHOW_INT (tcp_queue_limit);
1006
1113
  SHOW_INT (real_hash_size);
1014
1121
  SHOW_BOOL (push_ifconfig_defined);
1015
1122
  msg (D_SHOW_PARMS, "  push_ifconfig_local = %s", print_in_addr_t (o->push_ifconfig_local, 0, &gc));
1016
1123
  msg (D_SHOW_PARMS, "  push_ifconfig_remote_netmask = %s", print_in_addr_t (o->push_ifconfig_remote_netmask, 0, &gc));
 
1124
  SHOW_BOOL (push_ifconfig_ipv6_defined);
 
1125
  msg (D_SHOW_PARMS, "  push_ifconfig_ipv6_local = %s/%d", print_in6_addr (o->push_ifconfig_ipv6_local, 0, &gc), o->push_ifconfig_ipv6_netbits );
 
1126
  msg (D_SHOW_PARMS, "  push_ifconfig_ipv6_remote = %s", print_in6_addr (o->push_ifconfig_ipv6_remote, 0, &gc));
1017
1127
  SHOW_BOOL (enable_c2c);
1018
1128
  SHOW_BOOL (duplicate_cn);
1019
1129
  SHOW_INT (cf_max);
1068
1178
  o->iroutes = ir;
1069
1179
}
1070
1180
 
 
1181
static void
 
1182
option_iroute_ipv6 (struct options *o,
 
1183
               const char *prefix_str,
 
1184
               int msglevel)
 
1185
{
 
1186
  struct iroute_ipv6 *ir;
 
1187
 
 
1188
  ALLOC_OBJ_GC (ir, struct iroute_ipv6, &o->gc);
 
1189
 
 
1190
  if ( get_ipv6_addr (prefix_str, &ir->network, &ir->netbits, NULL, msglevel ) < 0 )
 
1191
    {
 
1192
      msg (msglevel, "in --iroute-ipv6 %s: Bad IPv6 prefix specification",
 
1193
           prefix_str);
 
1194
      return;
 
1195
    }
 
1196
 
 
1197
  ir->next = o->iroutes_ipv6;
 
1198
  o->iroutes_ipv6 = ir;
 
1199
}
1071
1200
#endif /* P2MP_SERVER */
1072
1201
#endif /* P2MP */
1073
1202
 
1105
1234
    options->routes = new_route_option_list (options->max_routes, &options->gc);
1106
1235
}
1107
1236
 
 
1237
void
 
1238
rol6_check_alloc (struct options *options)
 
1239
{
 
1240
  if (!options->routes_ipv6)
 
1241
    options->routes_ipv6 = new_route_ipv6_option_list (options->max_routes, &options->gc);
 
1242
}
 
1243
 
1108
1244
#ifdef ENABLE_DEBUG
1109
1245
static void
1110
1246
show_connection_entry (const struct connection_entry *o)
1195
1331
  SHOW_STR (ifconfig_remote_netmask);
1196
1332
  SHOW_BOOL (ifconfig_noexec);
1197
1333
  SHOW_BOOL (ifconfig_nowarn);
 
1334
  SHOW_STR (ifconfig_ipv6_local);
 
1335
  SHOW_INT (ifconfig_ipv6_netbits);
 
1336
  SHOW_STR (ifconfig_ipv6_remote);
1198
1337
 
1199
1338
#ifdef HAVE_GETTIMEOFDAY
1200
1339
  SHOW_INT (shaper);
1346
1485
#endif
1347
1486
  SHOW_STR (cipher_list);
1348
1487
  SHOW_STR (tls_verify);
 
1488
  SHOW_STR (tls_export_cert);
1349
1489
  SHOW_STR (tls_remote);
1350
1490
  SHOW_STR (crl_file);
1351
1491
  SHOW_INT (ns_cert_type);
1897
2037
      if (options->connection_list)
1898
2038
        msg (M_USAGE, "<connection> cannot be used with --mode server");
1899
2039
#endif
 
2040
#if 0
1900
2041
      if (options->tun_ipv6)
1901
2042
        msg (M_USAGE, "--tun-ipv6 cannot be used with --mode server");
 
2043
#endif
1902
2044
      if (options->shaper)
1903
2045
        msg (M_USAGE, "--shaper cannot be used with --mode server");
1904
2046
      if (options->inetd)
1931
2073
        msg (M_USAGE, "--up-delay cannot be used with --mode server");
1932
2074
      if (!options->ifconfig_pool_defined && options->ifconfig_pool_persist_filename)
1933
2075
        msg (M_USAGE, "--ifconfig-pool-persist must be used with --ifconfig-pool");
 
2076
      if (options->ifconfig_ipv6_pool_defined && !options->ifconfig_ipv6_local )
 
2077
        msg (M_USAGE, "--ifconfig-ipv6-pool needs --ifconfig-ipv6");
 
2078
      if (options->ifconfig_ipv6_local && !options->tun_ipv6 )
 
2079
        msg (M_INFO, "Warning: --ifconfig-ipv6 without --tun-ipv6 will not do IPv6");
 
2080
 
1934
2081
      if (options->auth_user_pass_file)
1935
2082
        msg (M_USAGE, "--auth-user-pass cannot be used with --mode server (it should be used on the client side only)");
1936
2083
      if (options->ccd_exclusive && !options->client_config_dir)
1962
2109
       */
1963
2110
      if (options->ifconfig_pool_defined || options->ifconfig_pool_persist_filename)
1964
2111
        msg (M_USAGE, "--ifconfig-pool/--ifconfig-pool-persist requires --mode server");
 
2112
      if (options->ifconfig_ipv6_pool_defined)
 
2113
        msg (M_USAGE, "--ifconfig-ipv6-pool requires --mode server");
1965
2114
      if (options->real_hash_size != defaults.real_hash_size
1966
2115
          || options->virtual_hash_size != defaults.virtual_hash_size)
1967
2116
        msg (M_USAGE, "--hash-size requires --mode server");
1971
2120
        msg (M_USAGE, "--client-connect requires --mode server");
1972
2121
      if (options->client_disconnect_script)
1973
2122
        msg (M_USAGE, "--client-disconnect requires --mode server");
1974
 
      if (options->tmp_dir)
1975
 
        msg (M_USAGE, "--tmp-dir requires --mode server");
1976
2123
      if (options->client_config_dir || options->ccd_exclusive)
1977
2124
        msg (M_USAGE, "--client-config-dir/--ccd-exclusive requires --mode server");
1978
2125
      if (options->enable_c2c)
2125
2272
      MUST_BE_UNDEF (pkcs12_file);
2126
2273
      MUST_BE_UNDEF (cipher_list);
2127
2274
      MUST_BE_UNDEF (tls_verify);
 
2275
      MUST_BE_UNDEF (tls_export_cert);
2128
2276
      MUST_BE_UNDEF (tls_remote);
2129
2277
      MUST_BE_UNDEF (tls_timeout);
2130
2278
      MUST_BE_UNDEF (renegotiate_bytes);
2197
2345
 
2198
2346
  if (!ce->bind_local)
2199
2347
    ce->local_port = 0;
 
2348
 
 
2349
  /* if protocol forcing is enabled, disable all protocols except for the forced one */
 
2350
  if (o->proto_force >= 0 && is_proto_tcp(o->proto_force) != is_proto_tcp(ce->proto))
 
2351
    ce->flags |= CE_DISABLED;
2200
2352
}
2201
2353
 
2202
2354
static void
2504
2656
                     o->topology,
2505
2657
                     o->ifconfig_local,
2506
2658
                     o->ifconfig_remote_netmask,
 
2659
                     o->ifconfig_ipv6_local,
 
2660
                     o->ifconfig_ipv6_remote,
2507
2661
                     (in_addr_t)0,
2508
2662
                     (in_addr_t)0,
2509
2663
                     false,
2971
3125
  msg (M_INFO|M_NOPREFIX, "%s", title_string);
2972
3126
  msg (M_INFO|M_NOPREFIX, "Originally developed by James Yonan");
2973
3127
  msg (M_INFO|M_NOPREFIX, "Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net>");
 
3128
#ifndef ENABLE_SMALL
 
3129
#ifdef CONFIGURE_CALL
 
3130
  msg (M_INFO|M_NOPREFIX, "\n%s\n", CONFIGURE_CALL);
 
3131
#endif
 
3132
#ifdef CONFIGURE_DEFINES
 
3133
  msg (M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
 
3134
#endif
 
3135
#endif
2974
3136
  openvpn_exit (OPENVPN_EXIT_STATUS_USAGE); /* exit point */
2975
3137
}
2976
3138
 
3005
3167
  return i < 0 ? 0 : i;
3006
3168
}
3007
3169
 
 
3170
#ifdef WIN32  /* This function is only used when compiling on Windows */
3008
3171
static unsigned int
3009
3172
atou (const char *str)
3010
3173
{
3012
3175
  sscanf (str, "%u", &val);
3013
3176
  return val;
3014
3177
}
 
3178
#endif
3015
3179
 
3016
3180
static inline bool
3017
3181
space (unsigned char c)
3819
3983
          goto err;
3820
3984
        }
3821
3985
    }
 
3986
  else if (streq (p[0], "ifconfig-ipv6") && p[1] && p[2] )
 
3987
    {
 
3988
      unsigned int netbits;
 
3989
      char * ipv6_local;
 
3990
        
 
3991
      VERIFY_PERMISSION (OPT_P_UP);
 
3992
      if ( get_ipv6_addr( p[1], NULL, &netbits, &ipv6_local, msglevel ) &&
 
3993
           ipv6_addr_safe( p[2] ) )
 
3994
        {
 
3995
          if ( netbits < 64 || netbits > 124 )
 
3996
            {
 
3997
              msg( msglevel, "ifconfig-ipv6: /netbits must be between 64 and 124, not '/%d'", netbits );
 
3998
              goto err;
 
3999
            }
 
4000
          options->ifconfig_ipv6_local = ipv6_local;
 
4001
          options->ifconfig_ipv6_netbits = netbits;
 
4002
          options->ifconfig_ipv6_remote = p[2];
 
4003
        }
 
4004
      else
 
4005
        {
 
4006
          msg (msglevel, "ifconfig-ipv6 parms '%s' and '%s' must be valid addresses", p[1], p[2]);
 
4007
          goto err;
 
4008
        }
 
4009
    }
3822
4010
  else if (streq (p[0], "ifconfig-noexec"))
3823
4011
    {
3824
4012
      VERIFY_PERMISSION (OPT_P_UP);
4272
4460
      goto err;
4273
4461
#endif
4274
4462
    }
4275
 
#ifdef USE_PTHREAD
4276
 
  else if (streq (p[0], "nice-work") && p[1])
4277
 
    {
4278
 
      VERIFY_PERMISSION (OPT_P_NICE);
4279
 
      options->nice_work = atoi (p[1]);
4280
 
    }
4281
 
  else if (streq (p[0], "threads") && p[1])
4282
 
    {
4283
 
      int n_threads;
4284
 
 
4285
 
      VERIFY_PERMISSION (OPT_P_GENERAL);
4286
 
      n_threads = positive_atoi (p[1]);
4287
 
      if (n_threads < 1)
4288
 
        {
4289
 
          msg (msglevel, "--threads parameter must be at least 1");
4290
 
          goto err;
4291
 
        }
4292
 
      options->n_threads = n_threads;
4293
 
    }
4294
 
#endif
4295
4463
  else if (streq (p[0], "shaper") && p[1])
4296
4464
    {
4297
4465
#ifdef HAVE_GETTIMEOFDAY
4391
4559
        }
4392
4560
      options->ce.proto = proto;
4393
4561
    }
 
4562
  else if (streq (p[0], "proto-force") && p[1])
 
4563
    {
 
4564
      int proto_force;
 
4565
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
4566
      proto_force = ascii2proto (p[1]);
 
4567
      if (proto_force < 0)
 
4568
        {
 
4569
          msg (msglevel, "Bad --proto-force protocol: '%s'", p[1]);
 
4570
          goto err;
 
4571
        }
 
4572
      options->proto_force = proto_force;
 
4573
      options->force_connection_list = true;
 
4574
    }
4394
4575
#ifdef GENERAL_PROXY_SUPPORT
4395
4576
  else if (streq (p[0], "auto-proxy"))
4396
4577
    {
4532
4713
          options->ce.socks_proxy_port = 1080;
4533
4714
        }
4534
4715
      options->ce.socks_proxy_server = p[1];
 
4716
      options->ce.socks_proxy_authfile = p[3]; /* might be NULL */
4535
4717
    }
4536
4718
  else if (streq (p[0], "socks-proxy-retry"))
4537
4719
    {
4625
4807
        }
4626
4808
      add_route_to_option_list (options->routes, p[1], p[2], p[3], p[4]);
4627
4809
    }
 
4810
  else if (streq (p[0], "route-ipv6") && p[1])
 
4811
    {
 
4812
      VERIFY_PERMISSION (OPT_P_ROUTE);
 
4813
      rol6_check_alloc (options);
 
4814
      if (pull_mode)
 
4815
        {
 
4816
          if (!ipv6_addr_safe_hexplusbits (p[1]))
 
4817
            {
 
4818
              msg (msglevel, "route-ipv6 parameter network/IP '%s' must be a valid address", p[1]);
 
4819
              goto err;
 
4820
            }
 
4821
          if (p[2] && !ipv6_addr_safe (p[2]))
 
4822
            {
 
4823
              msg (msglevel, "route-ipv6 parameter gateway '%s' must be a valid address", p[2]);
 
4824
              goto err;
 
4825
            }
 
4826
          /* p[3] is metric, if present */
 
4827
        }
 
4828
      add_route_ipv6_to_option_list (options->routes_ipv6, p[1], p[2], p[3]);
 
4829
    }
4628
4830
  else if (streq (p[0], "max-routes") && p[1])
4629
4831
    {
4630
4832
      int max_routes;
4836
5038
            }
4837
5039
        }
4838
5040
    }
 
5041
  else if (streq (p[0], "server-ipv6") && p[1] )
 
5042
    {
 
5043
      const int lev = M_WARN;
 
5044
      struct in6_addr network;
 
5045
      unsigned int netbits = 0;
 
5046
 
 
5047
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
5048
      if ( ! get_ipv6_addr (p[1], &network, &netbits, NULL, lev) )
 
5049
        {
 
5050
          msg (msglevel, "error parsing --server-ipv6 parameter");
 
5051
          goto err;
 
5052
        }
 
5053
      if ( netbits != 64 )
 
5054
        {
 
5055
          msg( msglevel, "--server-ipv6 settings: only /64 supported right now (not /%d)", netbits );
 
5056
          goto err;
 
5057
        }
 
5058
      options->server_ipv6_defined = true;
 
5059
      options->server_network_ipv6 = network;
 
5060
      options->server_netbits_ipv6 = netbits;
 
5061
 
 
5062
      if (p[2])         /* no "nopool" options or similar for IPv6 */
 
5063
        {
 
5064
          msg (msglevel, "error parsing --server-ipv6: %s is not a recognized flag", p[3]);
 
5065
          goto err;
 
5066
        }
 
5067
    }
4839
5068
  else if (streq (p[0], "server-bridge") && p[1] && p[2] && p[3] && p[4])
4840
5069
    {
4841
5070
      const int lev = M_WARN;
4920
5149
      VERIFY_PERMISSION (OPT_P_GENERAL);
4921
5150
      options->topology = TOP_P2P;
4922
5151
    }
 
5152
  else if (streq (p[0], "ifconfig-ipv6-pool") && p[1] )
 
5153
    {
 
5154
      const int lev = M_WARN;
 
5155
      struct in6_addr network;
 
5156
      unsigned int netbits = 0;
 
5157
 
 
5158
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
5159
      if ( ! get_ipv6_addr (p[1], &network, &netbits, NULL, lev ) )
 
5160
        {
 
5161
          msg (msglevel, "error parsing --ifconfig-ipv6-pool parameters");
 
5162
          goto err;
 
5163
        }
 
5164
      if ( netbits != 64 )
 
5165
        {
 
5166
          msg( msglevel, "--ifconfig-ipv6-pool settings: only /64 supported right now (not /%d)", netbits );
 
5167
          goto err;
 
5168
        }
 
5169
 
 
5170
      options->ifconfig_ipv6_pool_defined = true;
 
5171
      options->ifconfig_ipv6_pool_base = network;
 
5172
      options->ifconfig_ipv6_pool_netbits = netbits;
 
5173
    }
4923
5174
  else if (streq (p[0], "hash-size") && p[1] && p[2])
4924
5175
    {
4925
5176
      int real, virtual;
5115
5366
        }
5116
5367
      option_iroute (options, p[1], netmask, msglevel);
5117
5368
    }
 
5369
  else if (streq (p[0], "iroute-ipv6") && p[1])
 
5370
    {
 
5371
      VERIFY_PERMISSION (OPT_P_INSTANCE);
 
5372
      option_iroute_ipv6 (options, p[1], msglevel);
 
5373
    }
5118
5374
  else if (streq (p[0], "ifconfig-push") && p[1] && p[2])
5119
5375
    {
5120
5376
      in_addr_t local, remote_netmask;
5153
5409
          goto err;
5154
5410
        }
5155
5411
    }
 
5412
  else if (streq (p[0], "ifconfig-ipv6-push") && p[1] )
 
5413
    {
 
5414
      struct in6_addr local, remote;
 
5415
      unsigned int netbits;
 
5416
 
 
5417
      VERIFY_PERMISSION (OPT_P_INSTANCE);
 
5418
 
 
5419
      if ( ! get_ipv6_addr( p[1], &local, &netbits, NULL, msglevel ) )
 
5420
        {
 
5421
          msg (msglevel, "cannot parse --ifconfig-ipv6-push addresses");
 
5422
          goto err;
 
5423
        }
 
5424
 
 
5425
      if ( p[2] )
 
5426
        {
 
5427
          if ( !get_ipv6_addr( p[2], &remote, NULL, NULL, msglevel ) )
 
5428
            {
 
5429
              msg( msglevel, "cannot parse --ifconfig-ipv6-push addresses");
 
5430
              goto err;
 
5431
            }
 
5432
        }
 
5433
      else
 
5434
        {
 
5435
          if ( ! options->ifconfig_ipv6_local ||
 
5436
               ! get_ipv6_addr( options->ifconfig_ipv6_local, &remote, 
 
5437
                                NULL, NULL, msglevel ) )
 
5438
            {
 
5439
              msg( msglevel, "second argument to --ifconfig-ipv6-push missing and no global --ifconfig-ipv6 address set");
 
5440
              goto err;
 
5441
            }
 
5442
        }
 
5443
 
 
5444
      options->push_ifconfig_ipv6_defined = true;
 
5445
      options->push_ifconfig_ipv6_local = local;
 
5446
      options->push_ifconfig_ipv6_netbits = netbits;
 
5447
      options->push_ifconfig_ipv6_remote = remote;
 
5448
    }
5156
5449
  else if (streq (p[0], "disable"))
5157
5450
    {
5158
5451
      VERIFY_PERMISSION (OPT_P_INSTANCE);
5393
5686
      VERIFY_PERMISSION (OPT_P_IPWIN32);
5394
5687
      options->tuntap_options.register_dns = true;
5395
5688
    }
5396
 
  else if (streq (p[0], "rdns-internal")) /* standalone method for internal use */
 
5689
  else if (streq (p[0], "rdns-internal"))
 
5690
     /* standalone method for internal use
 
5691
      *
 
5692
      * (if --register-dns is set, openvpn needs to call itself in a
 
5693
      *  sub-process to execute the required functions in a non-blocking
 
5694
      *  way, and uses --rdns-internal to signal that to itself)
 
5695
      */
5397
5696
    {
5398
5697
      VERIFY_PERMISSION (OPT_P_GENERAL);
5399
5698
      set_debug_level (options->verbosity, SDL_CONSTRAIN);
5765
6064
    {
5766
6065
      VERIFY_PERMISSION (OPT_P_GENERAL);
5767
6066
      options->pkcs12_file = p[1];
 
6067
#if ENABLE_INLINE_FILES
 
6068
      if (streq (p[1], INLINE_FILE_TAG) && p[2])
 
6069
        {
 
6070
          options->pkcs12_file_inline = p[2];
 
6071
        }
 
6072
#endif
5768
6073
    }
5769
6074
  else if (streq (p[0], "askpass"))
5770
6075
    {
5816
6121
      warn_multiple_script (options->tls_verify, "tls-verify");
5817
6122
      options->tls_verify = string_substitute (p[1], ',', ' ', &options->gc);
5818
6123
    }
 
6124
  else if (streq (p[0], "tls-export-cert") && p[1])
 
6125
    {
 
6126
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
6127
      options->tls_export_cert = p[1];
 
6128
    }
5819
6129
  else if (streq (p[0], "tls-remote") && p[1])
5820
6130
    {
5821
6131
      VERIFY_PERMISSION (OPT_P_GENERAL);
5941
6251
        }
5942
6252
      options->key_method = key_method;
5943
6253
    }
 
6254
#ifdef ENABLE_X509ALTUSERNAME
 
6255
  else if (streq (p[0], "x509-username-field") && p[1])
 
6256
    {
 
6257
      char *s = p[1];
 
6258
      VERIFY_PERMISSION (OPT_P_GENERAL);
 
6259
      while ((*s = toupper(*s)) != '\0') s++; /* Uppercase if necessary */
 
6260
      options->x509_username_field = p[1];
 
6261
    }
 
6262
#endif /* ENABLE_X509ALTUSERNAME */
5944
6263
#endif /* USE_SSL */
5945
6264
#endif /* USE_CRYPTO */
5946
6265
#ifdef ENABLE_PKCS11