~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/config.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
 
25
25
 
 
26
#include <assert.h>
 
27
 
26
28
#define APR_WANT_STRFUNC
27
29
#define APR_WANT_MEMFUNC
28
30
#include <apr_want.h>
36
38
 
37
39
#include "svn_private_config.h"
38
40
#include "private/svn_dep_compat.h"
 
41
#include "private/svn_subr_private.h"
39
42
 
40
43
 
41
44
 
92
95
  cfg->tmp_value = svn_stringbuf_create_empty(result_pool);
93
96
  cfg->section_names_case_sensitive = section_names_case_sensitive;
94
97
  cfg->option_names_case_sensitive = option_names_case_sensitive;
 
98
  cfg->read_only = FALSE;
95
99
 
96
100
  *cfgp = cfg;
97
101
  return SVN_NO_ERROR;
188
192
#ifdef WIN32
189
193
  if (sys_registry_path)
190
194
    {
191
 
      SVN_ERR(svn_config_read2(cfgp, sys_registry_path, FALSE, FALSE, pool));
 
195
      SVN_ERR(svn_config_read3(cfgp, sys_registry_path, FALSE, FALSE, FALSE,
 
196
                               pool));
192
197
      red_config = TRUE;
193
198
    }
194
199
#endif /* WIN32 */
214
219
        SVN_ERR(svn_config_merge(*cfgp, usr_registry_path, FALSE));
215
220
      else
216
221
        {
217
 
          SVN_ERR(svn_config_read2(cfgp, usr_registry_path,
218
 
                                   FALSE, FALSE, pool));
 
222
          SVN_ERR(svn_config_read3(cfgp, usr_registry_path,
 
223
                                   FALSE, FALSE, FALSE, pool));
219
224
          red_config = TRUE;
220
225
        }
221
226
    }
242
247
 
243
248
/* CONFIG_DIR provides an override for the default behavior of reading
244
249
   the default set of overlay files described by read_all()'s doc
245
 
   string. */
 
250
   string.  Returns non-NULL *CFG or an error. */
246
251
static svn_error_t *
247
252
get_category_config(svn_config_t **cfg,
248
253
                    const char *config_dir,
259
264
    {
260
265
#ifdef WIN32
261
266
      sys_reg_path = apr_pstrcat(pool, SVN_REGISTRY_SYS_CONFIG_PATH,
262
 
                                 category, NULL);
 
267
                                 category, SVN_VA_NULL);
263
268
      usr_reg_path = apr_pstrcat(pool, SVN_REGISTRY_USR_CONFIG_PATH,
264
 
                                 category, NULL);
 
269
                                 category, SVN_VA_NULL);
265
270
#endif /* WIN32 */
266
271
 
267
272
      err = svn_config__sys_config_path(&sys_cfg_path, category, pool);
291
296
  svn_config_t *cfg;
292
297
  *cfg_hash = apr_hash_make(pool);
293
298
 
294
 
#define CATLEN (sizeof(SVN_CONFIG_CATEGORY_SERVERS) - 1)
295
299
  SVN_ERR(get_category_config(&cfg, config_dir, SVN_CONFIG_CATEGORY_SERVERS,
296
300
                              pool));
297
 
  if (cfg)
298
 
    apr_hash_set(*cfg_hash, SVN_CONFIG_CATEGORY_SERVERS, CATLEN, cfg);
299
 
#undef CATLEN
 
301
  svn_hash_sets(*cfg_hash, SVN_CONFIG_CATEGORY_SERVERS, cfg);
300
302
 
301
 
#define CATLEN (sizeof(SVN_CONFIG_CATEGORY_CONFIG) - 1)
302
303
  SVN_ERR(get_category_config(&cfg, config_dir, SVN_CONFIG_CATEGORY_CONFIG,
303
304
                              pool));
304
 
  if (cfg)
305
 
    apr_hash_set(*cfg_hash, SVN_CONFIG_CATEGORY_CONFIG, CATLEN, cfg);
306
 
#undef CATLEN
 
305
  svn_hash_sets(*cfg_hash, SVN_CONFIG_CATEGORY_CONFIG, cfg);
 
306
 
 
307
  return SVN_NO_ERROR;
 
308
}
 
309
 
 
310
svn_error_t *
 
311
svn_config__get_default_config(apr_hash_t **cfg_hash,
 
312
                               apr_pool_t *pool)
 
313
{
 
314
  svn_config_t *empty_cfg;
 
315
  *cfg_hash = apr_hash_make(pool);
 
316
 
 
317
  SVN_ERR(svn_config_create2(&empty_cfg, FALSE, FALSE, pool));
 
318
  svn_hash_sets(*cfg_hash, SVN_CONFIG_CATEGORY_CONFIG, empty_cfg);
 
319
 
 
320
  SVN_ERR(svn_config_create2(&empty_cfg, FALSE, FALSE, pool));
 
321
  svn_hash_sets(*cfg_hash, SVN_CONFIG_CATEGORY_SERVERS, empty_cfg);
307
322
 
308
323
  return SVN_NO_ERROR;
309
324
}
415
430
  return key;
416
431
}
417
432
 
 
433
/* Return the value for KEY in HASH.  If CASE_SENSITIVE is FALSE,
 
434
   BUFFER will be used to construct the normalized hash key. */
 
435
static void *
 
436
get_hash_value(apr_hash_t *hash,
 
437
               svn_stringbuf_t *buffer,
 
438
               const char *key,
 
439
               svn_boolean_t case_sensitive)
 
440
{
 
441
  apr_size_t i;
 
442
  apr_size_t len = strlen(key);
 
443
 
 
444
  if (case_sensitive)
 
445
    return apr_hash_get(hash, key, len);
 
446
 
 
447
  svn_stringbuf_ensure(buffer, len);
 
448
  for (i = 0; i < len; ++i)
 
449
    buffer->data[i] = (char)apr_tolower(key[i]);
 
450
 
 
451
  return apr_hash_get(hash, buffer->data, len);
 
452
}
418
453
 
419
454
/* Return a pointer to an option in CFG, or NULL if it doesn't exist.
420
455
   if SECTIONP is non-null, return a pointer to the option's section.
423
458
find_option(svn_config_t *cfg, const char *section, const char *option,
424
459
            cfg_section_t **sectionp)
425
460
{
426
 
  void *sec_ptr;
427
 
 
428
 
  /* Canonicalize the hash key */
429
 
  svn_stringbuf_set(cfg->tmp_key, section);
430
 
  if (! cfg->section_names_case_sensitive)
431
 
    make_hash_key(cfg->tmp_key->data);
432
 
 
433
 
  sec_ptr = apr_hash_get(cfg->sections, cfg->tmp_key->data,
434
 
                         cfg->tmp_key->len);
 
461
  void *sec_ptr = get_hash_value(cfg->sections, cfg->tmp_key, section,
 
462
                                 cfg->section_names_case_sensitive);
435
463
  if (sectionp != NULL)
436
464
    *sectionp = sec_ptr;
437
465
 
438
466
  if (sec_ptr != NULL && option != NULL)
439
467
    {
440
468
      cfg_section_t *sec = sec_ptr;
441
 
      cfg_option_t *opt;
442
 
 
443
 
      /* Canonicalize the option key */
444
 
      svn_stringbuf_set(cfg->tmp_key, option);
445
 
      if (! cfg->option_names_case_sensitive)
446
 
        make_hash_key(cfg->tmp_key->data);
447
 
 
448
 
      opt = apr_hash_get(sec->options, cfg->tmp_key->data,
449
 
                         cfg->tmp_key->len);
 
469
      cfg_option_t *opt = get_hash_value(sec->options, cfg->tmp_key, option,
 
470
                                         cfg->option_names_case_sensitive);
450
471
      /* NOTE: ConfigParser's sections are case sensitive. */
451
472
      if (opt == NULL
452
473
          && apr_strnatcasecmp(section, SVN_CONFIG__DEFAULT_SECTION) != 0)
482
503
       */
483
504
      if (opt->value && strchr(opt->value, '%'))
484
505
        {
485
 
          apr_pool_t *tmp_pool = (x_pool ? x_pool : svn_pool_create(cfg->x_pool));
 
506
          apr_pool_t *tmp_pool;
 
507
 
 
508
          /* setting read-only mode should have expanded all values
 
509
           * automatically. */
 
510
          assert(!cfg->read_only);
 
511
 
 
512
          tmp_pool = (x_pool ? x_pool : svn_pool_create(cfg->x_pool));
486
513
 
487
514
          expand_option_value(cfg, section, opt->value, &opt->x_value, tmp_pool);
488
515
          opt->expanded = TRUE;
642
669
  *opt = o;
643
670
}
644
671
 
 
672
svn_boolean_t
 
673
svn_config__is_expanded(svn_config_t *cfg,
 
674
                        const char *section,
 
675
                        const char *option)
 
676
{
 
677
  cfg_option_t *opt;
 
678
 
 
679
  if (cfg == NULL)
 
680
    return FALSE;
 
681
 
 
682
  /* does the option even exist? */
 
683
  opt = find_option(cfg, section, option, NULL);
 
684
  if (opt == NULL)
 
685
    return FALSE;
 
686
 
 
687
  /* already expanded? */
 
688
  if (opt->expanded)
 
689
    return TRUE;
 
690
 
 
691
  /* needs expansion? */
 
692
  if (opt->value && strchr(opt->value, '%'))
 
693
    return FALSE;
 
694
 
 
695
  /* no expansion necessary */
 
696
  return TRUE;
 
697
}
 
698
 
645
699
 
646
700
void
647
701
svn_config_get(svn_config_t *cfg, const char **valuep,
659
713
        }
660
714
      else
661
715
        /* before attempting to expand an option, check for the placeholder.
662
 
         * If none is there, there is no point in calling expand_option_value.
 
716
         * If there is none, there is no point in calling expand_option_value.
663
717
         */
664
718
        if (default_value && strchr(default_value, '%'))
665
719
          {
666
 
            apr_pool_t *tmp_pool = svn_pool_create(cfg->x_pool);
 
720
            apr_pool_t *tmp_pool = svn_pool_create(cfg->pool);
667
721
            const char *x_default;
668
722
            expand_option_value(cfg, sec, default_value, &x_default, tmp_pool);
669
723
            if (x_default)
686
740
  cfg_section_t *sec;
687
741
  cfg_option_t *opt;
688
742
 
 
743
  /* Ignore write attempts to r/o configurations.
 
744
   *
 
745
   * Since we should never try to modify r/o data, trigger an assertion
 
746
   * in debug mode.
 
747
   */
 
748
#ifdef SVN_DEBUG
 
749
  SVN_ERR_ASSERT_NO_RETURN(!cfg->read_only);
 
750
#endif
 
751
  if (cfg->read_only)
 
752
    return;
 
753
 
689
754
  remove_expansions(cfg);
690
755
 
691
756
  opt = find_option(cfg, section, option, &sec);
930
995
  if (sec == NULL)
931
996
    return 0;
932
997
 
933
 
  subpool = svn_pool_create(cfg->x_pool);
 
998
  subpool = svn_pool_create(cfg->pool);
934
999
  count = 0;
935
1000
  for (opt_ndx = apr_hash_first(subpool, sec->options);
936
1001
       opt_ndx != NULL;
1059
1124
 
1060
1125
svn_error_t *
1061
1126
svn_config_dup(svn_config_t **cfgp,
1062
 
               svn_config_t *src,
 
1127
               const svn_config_t *src,
1063
1128
               apr_pool_t *pool)
1064
1129
{
1065
1130
  apr_hash_index_t *sectidx;
1197
1262
svn_boolean_t
1198
1263
svn_config_has_section(svn_config_t *cfg, const char *section)
1199
1264
{
1200
 
  cfg_section_t *sec;
1201
 
 
1202
 
  /* Canonicalize the hash key */
1203
 
  svn_stringbuf_set(cfg->tmp_key, section);
1204
 
  if (! cfg->section_names_case_sensitive)
1205
 
    make_hash_key(cfg->tmp_key->data);
1206
 
 
1207
 
  sec = svn_hash_gets(cfg->sections, cfg->tmp_key->data);
1208
 
  return sec != NULL;
 
1265
  return NULL != get_hash_value(cfg->sections, cfg->tmp_key, section,
 
1266
                                cfg->section_names_case_sensitive);
1209
1267
}