~ubuntu-branches/ubuntu/wily/openvpn/wily-proposed

« back to all changes in this revision

Viewing changes to src/openvpn/init.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2015-07-08 12:28:54 UTC
  • mfrom: (1.1.22) (10.2.37 sid)
  • Revision ID: package-import@ubuntu.com-20150708122854-i5dlow8x2hssv42e
Tags: 2.3.7-1ubuntu1
* Merge with Debian unstable. Remaining Ubuntu 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.
  - Demote easy-rsa to Suggests
  - Run openvpn@.service before systemd-user-sessions.service to avoid
    gettys and lightdm starting on top of possible password prompts. This
    provides the equivalent of the init.d script's X-Start-Before:.

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
  if (management)
184
184
    {
185
185
      gc = gc_new ();
186
 
      struct buffer out = alloc_buf_gc (256, &gc);
187
 
      buf_printf (&out, ">PROXY:%u,%s,%s", (l ? l->current : 0) + 1,
188
 
                  (proto_is_udp (ce->proto) ? "UDP" : "TCP"), np (ce->remote));
189
 
      management_notify_generic (management, BSTR (&out));
 
186
      {
 
187
        struct buffer out = alloc_buf_gc (256, &gc);
 
188
        buf_printf (&out, ">PROXY:%u,%s,%s", (l ? l->current : 0) + 1,
 
189
                    (proto_is_udp (ce->proto) ? "UDP" : "TCP"), np (ce->remote));
 
190
        management_notify_generic (management, BSTR (&out));
 
191
      }
190
192
      ce->flags |= CE_MAN_QUERY_PROXY;
191
193
      while (ce->flags & CE_MAN_QUERY_PROXY)
192
194
        {
908
910
bool
909
911
do_persist_tuntap (const struct options *options)
910
912
{
911
 
#ifdef ENABLE_FEATURE_TUN_PERSIST
912
913
  if (options->persist_config)
913
914
    {
914
915
      /* sanity check on options for --mktun or --rmtun */
924
925
        )
925
926
        msg (M_FATAL|M_OPTERR,
926
927
             "options --mktun or --rmtun should only be used together with --dev");
 
928
#ifdef ENABLE_FEATURE_TUN_PERSIST
927
929
      tuncfg (options->dev, options->dev_type, options->dev_node,
928
930
              options->persist_mode,
929
931
              options->username, options->groupname, &options->tuntap_options);
930
932
      if (options->persist_mode && options->lladdr)
931
933
        set_lladdr(options->dev, options->lladdr, NULL);
932
934
      return true;
 
935
#else
 
936
      msg( M_FATAL|M_OPTERR,
 
937
        "options --mktun and --rmtun are not available on your operating "
 
938
        "system.  Please check 'man tun' (or 'tap'), whether your system "
 
939
        "supports using 'ifconfig %s create' / 'destroy' to create/remove "
 
940
        "persistant tunnel interfaces.", options->dev );
 
941
#endif
933
942
    }
934
 
#endif
935
943
  return false;
936
944
}
937
945
 
939
947
 * Should we become a daemon?
940
948
 * Return true if we did it.
941
949
 */
942
 
static bool
943
 
possibly_become_daemon (const struct options *options, const bool first_time)
 
950
bool
 
951
possibly_become_daemon (const struct options *options)
944
952
{
945
953
  bool ret = false;
946
 
  if (first_time && options->daemon)
 
954
  if (options->daemon)
947
955
    {
948
956
      ASSERT (!options->inetd);
949
 
      if (daemon (options->cd_dir != NULL, options->log) < 0)
 
957
      /* Don't chdir immediately, but the end of the init sequence, if needed */
 
958
      if (daemon (1, options->log) < 0)
950
959
        msg (M_ERR, "daemon() failed or unsupported");
951
960
      restore_signal_state ();
952
961
      if (options->log)
953
962
        set_std_files_to_null (true);
954
963
 
955
 
#if defined(ENABLE_PKCS11)
956
 
      pkcs11_forkFixup ();
957
 
#endif
958
 
 
959
964
      ret = true;
960
965
    }
961
966
  return ret;
1481
1486
      msg (M_INFO, "Preserving previous TUN/TAP instance: %s",
1482
1487
           c->c1.tuntap->actual_name);
1483
1488
 
 
1489
      /* explicitly set the ifconfig_* env vars */
 
1490
      do_ifconfig_setenv(c->c1.tuntap, c->c2.es);
 
1491
 
1484
1492
      /* run the up script if user specified --up-restart */
1485
1493
      if (c->options.up_restart)
1486
1494
        run_up_down (c->options.up_script,
1709
1717
    | OPT_P_MESSAGES
1710
1718
    | OPT_P_EXPLICIT_NOTIFY
1711
1719
    | OPT_P_ECHO
1712
 
    | OPT_P_PULL_MODE;
 
1720
    | OPT_P_PULL_MODE
 
1721
    | OPT_P_PEER_ID;
1713
1722
 
1714
1723
  if (!c->options.route_nopull)
1715
1724
    flags |= (OPT_P_ROUTE | OPT_P_IPWIN32);
1788
1797
    msg (D_PUSH, "OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified");
1789
1798
  if (found & OPT_P_SETENV)
1790
1799
    msg (D_PUSH, "OPTIONS IMPORT: environment modified");
 
1800
 
 
1801
#ifdef ENABLE_SSL
 
1802
  if (found & OPT_P_PEER_ID)
 
1803
    {
 
1804
      msg (D_PUSH, "OPTIONS IMPORT: peer-id set");
 
1805
      c->c2.tls_multi->use_peer_id = true;
 
1806
      c->c2.tls_multi->peer_id = c->options.peer_id;
 
1807
      frame_add_to_extra_frame(&c->c2.frame, +3);       /* peer-id overhead */
 
1808
      if ( !c->options.ce.link_mtu_defined )
 
1809
        {
 
1810
          frame_add_to_link_mtu(&c->c2.frame, +3);
 
1811
          msg (D_PUSH, "OPTIONS IMPORT: adjusting link_mtu to %d",
 
1812
                                EXPANDED_SIZE(&c->c2.frame));
 
1813
        }
 
1814
      else
 
1815
        {
 
1816
          msg (M_WARN, "OPTIONS IMPORT: WARNING: peer-id set, but link-mtu"
 
1817
                       " fixed by config - reducing tun-mtu to %d, expect"
 
1818
                       " MTU problems", TUN_MTU_SIZE(&c->c2.frame) );
 
1819
        }
 
1820
    }
 
1821
#endif
1791
1822
}
1792
1823
 
1793
1824
/*
1794
1825
 * Possible hold on initialization
1795
1826
 */
1796
1827
static bool
1797
 
do_hold (struct context *c)
 
1828
do_hold (void)
1798
1829
{
1799
1830
#ifdef ENABLE_MANAGEMENT
1800
1831
  if (management)
1801
1832
    {
1802
 
      /* if c is defined, daemonize before hold */
1803
 
      if (c && c->options.daemon && management_should_daemonize (management))
1804
 
        do_init_first_time (c);
1805
 
 
1806
1833
      /* block until management hold is released */
1807
1834
      if (management_hold (management))
1808
1835
        return true;
1868
1895
  c->persist.restart_sleep_seconds = 0;
1869
1896
 
1870
1897
  /* do managment hold on context restart, i.e. second, third, fourth, etc. initialization */
1871
 
  if (do_hold (NULL))
 
1898
  if (do_hold ())
1872
1899
    sec = 0;
1873
1900
 
1874
1901
  if (sec)
1887
1914
  if (!c->first_time)
1888
1915
    socket_restart_pause (c);
1889
1916
  else
1890
 
    do_hold (NULL); /* do management hold on first context initialization */
 
1917
    do_hold (); /* do management hold on first context initialization */
1891
1918
}
1892
1919
 
1893
1920
/*
2159
2186
                               options->use_iv);
2160
2187
 
2161
2188
  /* In short form, unique datagram identifier is 32 bits, in long form 64 bits */
2162
 
  packet_id_long_form = cfb_ofb_mode (&c->c1.ks.key_type);
 
2189
  packet_id_long_form = cipher_kt_mode_ofb_cfb (c->c1.ks.key_type.cipher);
2163
2190
 
2164
2191
  /* Compute MTU parameters */
2165
2192
  crypto_adjust_frame_parameters (&c->c2.frame,
2242
2269
  to.tmp_dir = options->tmp_dir;
2243
2270
  if (options->ccd_exclusive)
2244
2271
    to.client_config_dir_exclusive = options->client_config_dir;
 
2272
  to.auth_user_pass_file = options->auth_user_pass_file;
2245
2273
#endif
2246
2274
 
2247
2275
#ifdef ENABLE_X509_TRACK
2388
2416
   */
2389
2417
  frame_finalize_options (c, NULL);
2390
2418
 
 
2419
  /* packets with peer-id (P_DATA_V2) need 3 extra bytes in frame (on client)
 
2420
   * and need link_mtu+3 bytes on socket reception (on server).
 
2421
   *
 
2422
   * accomodate receive path in f->extra_link
 
2423
   *            send path in f->extra_buffer (+leave room for alignment)
 
2424
   *
 
2425
   * f->extra_frame is adjusted when peer-id option is push-received
 
2426
   */
 
2427
  frame_add_to_extra_link(&c->c2.frame, 3);
 
2428
  frame_add_to_extra_buffer(&c->c2.frame, 8);
 
2429
 
2391
2430
#ifdef ENABLE_FRAGMENT
2392
2431
  /*
2393
2432
   * Set frame parameter for fragment code.  This is necessary because
2724
2763
static void
2725
2764
do_init_first_time (struct context *c)
2726
2765
{
2727
 
  if (c->first_time && !c->did_we_daemonize && !c->c0)
 
2766
  if (c->first_time && !c->c0)
2728
2767
    {
2729
2768
      struct context_0 *c0;
2730
2769
 
2739
2778
      /* get --writepid file descriptor */
2740
2779
      get_pid_file (c->options.writepid, &c0->pid_state);
2741
2780
 
2742
 
      /* become a daemon if --daemon */
2743
 
      c->did_we_daemonize = possibly_become_daemon (&c->options, c->first_time);
2744
 
 
2745
 
      /* should we disable paging? */
2746
 
      if (c->options.mlock && c->did_we_daemonize)
2747
 
        platform_mlockall (true);       /* call again in case we daemonized */
 
2781
      /* perform postponed chdir if --daemon */
 
2782
      if (c->did_we_daemonize && c->options.cd_dir == NULL)
 
2783
        platform_chdir("/");
2748
2784
 
2749
2785
      /* save process ID in a file */
2750
2786
      write_pid (&c0->pid_state);
3185
3221
            }
3186
3222
 
3187
3223
          /* initial management hold, called early, before first context initialization */
3188
 
          do_hold (c);
 
3224
          do_hold ();
3189
3225
          if (IS_SIG (c))
3190
3226
            {
3191
3227
              msg (M_WARN, "Signal received from management interface, exiting");