Ticket #29: 0001-Make-some-push-options-not-resetable-by-ccd-config.patch

File 0001-Make-some-push-options-not-resetable-by-ccd-config.patch, 8.8 KB (added by Emmanuel Bretelle, 14 years ago)
  • helper.c

    From 05a33ce2a522e404d99b0815f4dca8eb914bd642 Mon Sep 17 00:00:00 2001
    From: chantra <chantra@debuntu.org>
    Date: Thu, 29 Jul 2010 10:14:26 +0200
    Subject: [PATCH] Make some push options not resetable by ccd config
    
    Fixes bug ticket 29
    <https://community.openvpn.net/openvpn/ticket/29>
    
    When client configuration has a 'push-reset' option,
    non-immutable global options will not be pushed to client.
    
    Only options added after the *last* push-reset will be set
    immutable.
    
    This way, if push-reset is given in ccd files and plugin
    returned list, only the configuration options from the plugin
    will be set immutable.
    
    Signed-off-by: chantra <chantra@debuntu.org>
    ---
     helper.c   |    5 ++++
     multi.c    |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
     options.c  |    3 +-
     options.h  |    1 +
     push.c     |    3 +-
     pushlist.h |    1 +
     6 files changed, 76 insertions(+), 3 deletions(-)
    
    diff --git a/helper.c b/helper.c
    index a9d7fd9..44723b4 100644
    a b helper_client_server (struct options *o) 
    256256              o->ifconfig_pool_netmask = o->server_netmask;
    257257                 
    258258              push_option (o, print_opt_route_gateway (o->server_network + 1, &o->gc), M_USAGE);
     259              o->push_list.tail->immutable = true;
    259260            }
    260261          else
    261262            ASSERT (0);
    262263
    263264          push_option (o, print_opt_topology (topology, &o->gc), M_USAGE);
     265          o->push_list.tail->immutable = true;
    264266        }
    265267      else if (dev == DEV_TYPE_TAP)
    266268        {
    helper_client_server (struct options *o) 
    283285          o->ifconfig_pool_netmask = o->server_netmask;
    284286
    285287          push_option (o, print_opt_route_gateway (o->server_network + 1, &o->gc), M_USAGE);
     288          o->push_list.tail->immutable = true;
    286289        }
    287290      else
    288291        {
    helper_client_server (struct options *o) 
    355358          ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
    356359          o->ifconfig_pool_netmask = o->server_bridge_netmask;
    357360          push_option (o, print_opt_route_gateway (o->server_bridge_ip, &o->gc), M_USAGE);
     361          o->push_list.tail->immutable = true;
    358362        }
    359363      else if (o->server_bridge_proxy_dhcp && !(o->server_flags & SF_NO_PUSH_ROUTE_GATEWAY))
    360364        {
    361365          push_option (o, print_opt_route_gateway_dhcp (&o->gc), M_USAGE);
     366          o->push_list.tail->immutable = true;
    362367        }
    363368    }
    364369  else
  • multi.c

    diff --git a/multi.c b/multi.c
    index dc26a02..899a345 100644
    a b multi_set_virtual_addr_env (struct multi_context *m, struct multi_instance *mi) 
    12831283}
    12841284
    12851285/*
     1286 * Set list entry immutable flag to immutable
     1287 * until end of list
     1288 */
     1289static void
     1290multi_client_connect_post_set_immutable (struct push_entry *e,
     1291                           bool immutable)
     1292{
     1293        while( e ){
     1294                e->immutable = immutable;
     1295                e = e->next;
     1296        }
     1297}
     1298
     1299/*
    12861300 * Called after client-connect script is called
    12871301 */
    12881302static void
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    14421456    {
    14431457      struct gc_arena gc = gc_new ();
    14441458      unsigned int option_types_found = 0;
     1459      struct push_entry *immutable_from_option = NULL, *last_option = NULL;
     1460      bool push_reset = false;
    14451461
    14461462      const unsigned int option_permissions_mask =
    14471463          OPT_P_INSTANCE
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    14871503          /* try common-name file */
    14881504          if (test_file (ccd_file))
    14891505            {
     1506              last_option = mi->context.options.push_list.tail;
    14901507              options_server_import (&mi->context.options,
    14911508                                     ccd_file,
    14921509                                     D_IMPORT_ERRORS|M_OPTERR,
    14931510                                     option_permissions_mask,
    14941511                                     &option_types_found,
    14951512                                     mi->context.c2.es);
     1513              if (mi->context.options.push_reset){
     1514                                     immutable_from_option = last_option;
     1515                                     push_reset = true;
     1516                                     mi->context.options.push_reset = false;
     1517                                        }
    14961518            }
    14971519          else /* try default file */
    14981520            {
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    15021524
    15031525              if (test_file (ccd_file))
    15041526                {
     1527                  last_option = mi->context.options.push_list.tail;
    15051528                  options_server_import (&mi->context.options,
    15061529                                         ccd_file,
    15071530                                         D_IMPORT_ERRORS|M_OPTERR,
    15081531                                         option_permissions_mask,
    15091532                                         &option_types_found,
    15101533                                         mi->context.c2.es);
     1534
     1535                   if (mi->context.options.push_reset){
     1536                                         immutable_from_option = last_option;
     1537                                         push_reset = true;
     1538                                         mi->context.options.push_reset = false;
     1539             }
    15111540                }
    15121541            }
    15131542        }
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    15451574            }
    15461575          else
    15471576            {
     1577              last_option = mi->context.options.push_list.tail;
    15481578              multi_client_connect_post (m, mi, dc_file, option_permissions_mask, &option_types_found);
     1579              if (mi->context.options.push_reset){
     1580                                                immutable_from_option = last_option;
     1581                                                push_reset = true;
     1582                                                mi->context.options.push_reset = false;
     1583              }
     1584
    15491585              ++cc_succeeded_count;
    15501586            }
    15511587        script_depr_failed:
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    15661602            }
    15671603          else
    15681604            {
     1605              last_option = mi->context.options.push_list.tail;
    15691606              multi_client_connect_post_plugin (m, mi, &pr, option_permissions_mask, &option_types_found);
    15701607              ++cc_succeeded_count;
     1608              if (mi->context.options.push_reset){
     1609                                                immutable_from_option = last_option;
     1610                                                push_reset = true;
     1611                                                mi->context.options.push_reset = false;
     1612                                }
     1613
    15711614            }
    15721615
    15731616          plugin_return_free (&pr);
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    15961639
    15971640          if (openvpn_execve_check (&argv, mi->context.c2.es, S_SCRIPT, "client-connect command failed"))
    15981641            {
     1642              last_option = mi->context.options.push_list.tail;
    15991643              multi_client_connect_post (m, mi, dc_file, option_permissions_mask, &option_types_found);
    16001644              ++cc_succeeded_count;
     1645              if (mi->context.options.push_reset){
     1646                                                immutable_from_option = last_option;
     1647                                                push_reset = true;
     1648                                                mi->context.options.push_reset = false;
     1649              }
    16011650            }
    16021651          else
    16031652            cc_succeeded = false;
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    16111660#ifdef MANAGEMENT_DEF_AUTH
    16121661      if (cc_succeeded && mi->cc_config)
    16131662        {
     1663          last_option = mi->context.options.push_list.tail;
    16141664          multi_client_connect_mda (m, mi, mi->cc_config, option_permissions_mask, &option_types_found);
    16151665          ++cc_succeeded_count;
     1666          if (mi->context.options.push_reset){
     1667                    immutable_from_option = last_option;
     1668                    push_reset = true;
     1669                    mi->context.options.push_reset = false;
     1670          }
    16161671        }
    16171672#endif
    16181673
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    16251680          msg (D_MULTI_ERRORS, "MULTI: client has been rejected due to 'disable' directive");
    16261681          cc_succeeded = false;
    16271682        }
    1628 
     1683  /*
     1684   * Set option push_reset to true if push-reset option
     1685   * was ever encountered, and set to immutable
     1686   * options added since last push-reset
     1687   */
     1688  mi->context.options.push_reset = push_reset;
     1689  if( push_reset ){
     1690                multi_client_connect_post_set_immutable(
     1691                        immutable_from_option ? immutable_from_option->next : mi->context.options.push_list.head, true);
     1692  }
    16291693      if (cc_succeeded)
    16301694        {
    16311695          /*
  • options.c

    diff --git a/options.c b/options.c
    index b78158e..20c5f60 100644
    a b init_options (struct options *o, const bool init_gc) 
    691691  o->route_delay_window = 30;
    692692  o->max_routes = MAX_ROUTES_DEFAULT;
    693693  o->resolve_retry_seconds = RESOLV_RETRY_INFINITE;
     694  o->push_reset = false;
    694695#ifdef ENABLE_OCC
    695696  o->occ = true;
    696697#endif
    add_option (struct options *options, 
    47894790  else if (streq (p[0], "push-reset"))
    47904791    {
    47914792      VERIFY_PERMISSION (OPT_P_INSTANCE);
    4792       push_reset (options);
     4793      options->push_reset = true;
    47934794    }
    47944795  else if (streq (p[0], "ifconfig-pool") && p[1] && p[2])
    47954796    {
  • options.h

    diff --git a/options.h b/options.h
    index 240f3bb..4b1597f 100644
    a b struct options 
    378378  in_addr_t server_bridge_pool_end;
    379379
    380380  struct push_list push_list;
     381  bool push_reset;
    381382  bool ifconfig_pool_defined;
    382383  in_addr_t ifconfig_pool_start;
    383384  in_addr_t ifconfig_pool_end;
  • push.c

    diff --git a/push.c b/push.c
    index 1320bec..9d994a5 100644
    a b send_push_reply (struct context *c) 
    183183
    184184  while (e)
    185185    {
    186       if (e->enable)
     186      if (e->enable && (!c->options.push_reset || e->immutable))
    187187        {
    188188          const int l = strlen (e->option);
    189189          if (BLEN (&buf) + l >= safe_cap)
    clone_push_list (struct options *o) 
    290290      while (e)
    291291        {
    292292          push_option_ex (o, string_alloc (e->option, &o->gc), true, M_FATAL);
     293          o->push_list.tail->immutable = e->immutable;
    293294          e = e->next;
    294295        }
    295296    }
  • pushlist.h

    diff --git a/pushlist.h b/pushlist.h
    index b252676..11356dd 100644
    a b  
    3030struct push_entry {
    3131  struct push_entry *next;
    3232  bool enable;
     33  bool immutable;
    3334  const char *option;
    3435};
    3536