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

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_wc/utils.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:
22
22
 
23
23
#include "svn_error.h"
24
24
#include "svn_client.h"
 
25
#include "svn_cmdline.h"
25
26
#include "svn_pools.h"
26
 
#include "private/svn_dep_compat.h"
27
27
 
28
28
#include "utils.h"
29
29
 
33
33
#include "../../libsvn_wc/wc-queries.h"
34
34
#define SVN_WC__I_AM_WC_DB
35
35
#include "../../libsvn_wc/wc_db_private.h"
36
 
 
 
36
#include "../../libsvn_wc/token-map.h"
 
37
svn_error_t *
 
38
svn_test__create_client_ctx(svn_client_ctx_t **ctx,
 
39
                            svn_test__sandbox_t *sbox,
 
40
                            apr_pool_t *result_pool)
 
41
{
 
42
  SVN_ERR(svn_client_create_context2(ctx, NULL, result_pool));
 
43
 
 
44
  SVN_ERR(svn_test__init_auth_baton(&(*ctx)->auth_baton,
 
45
                                    result_pool));
 
46
 
 
47
  if (sbox)
 
48
    (*ctx)->wc_ctx = sbox->wc_ctx;
 
49
 
 
50
  return SVN_NO_ERROR;
 
51
}
37
52
 
38
53
/* Create an empty repository and WC for the test TEST_NAME.  Set *REPOS_URL
39
 
 * to the URL of the new repository and *WC_ABSPATH to the root path of the
 
54
 * to the URL of the new repository, *REPOS_DIR to its local path and
 
55
 * *WC_ABSPATH to the root path of the
40
56
 * new WC.
41
57
 *
42
58
 * Create the repository and WC in subdirectories called
46
62
 * Register the repo and WC to be cleaned up when the test suite exits. */
47
63
static svn_error_t *
48
64
create_repos_and_wc(const char **repos_url,
 
65
                    const char **repos_dir,
49
66
                    const char **wc_abspath,
50
67
                    const char *test_name,
51
68
                    const svn_test_opts_t *opts,
66
83
 
67
84
  /* Create a repos. Register it for clean-up. Set *REPOS_URL to its path. */
68
85
  {
69
 
    svn_repos_t *repos;
70
 
 
71
86
    /* Use a subpool to create the repository and then destroy the subpool
72
87
       so the repository's underlying filesystem is closed.  If opts->fs_type
73
88
       is BDB this prevents any attempt to open a second environment handle
75
90
       only a single environment handle to be open per process. */
76
91
    apr_pool_t *subpool = svn_pool_create(pool);
77
92
 
78
 
    SVN_ERR(svn_test__create_repos(&repos, repos_path, opts, subpool));
79
 
    SVN_ERR(svn_uri_get_file_url_from_dirent(repos_url, repos_path, pool));
 
93
    SVN_ERR(svn_test__create_repos2(NULL, repos_url, repos_dir, repos_path,
 
94
                                    opts, pool, subpool));
80
95
    svn_pool_destroy(subpool);
81
96
  }
82
97
 
86
101
    svn_client_ctx_t *ctx;
87
102
    svn_opt_revision_t head_rev = { svn_opt_revision_head, {0} };
88
103
 
89
 
    SVN_ERR(svn_client_create_context2(&ctx, NULL, subpool));
 
104
    SVN_ERR(svn_test__create_client_ctx(&ctx, NULL, subpool));
90
105
    SVN_ERR(svn_dirent_get_absolute(wc_abspath, wc_path, pool));
91
106
    SVN_ERR(svn_client_checkout3(NULL, *repos_url, *wc_abspath,
92
107
                                 &head_rev, &head_rev, svn_depth_infinity,
102
117
  return SVN_NO_ERROR;
103
118
}
104
119
 
105
 
 
106
120
WC_QUERIES_SQL_DECLARE_STATEMENTS(statements);
107
121
 
108
122
svn_error_t *
109
123
svn_test__create_fake_wc(const char *wc_abspath,
110
124
                         const char *extra_statements,
111
 
                         apr_pool_t *result_pool,
 
125
                         const svn_test__nodes_data_t nodes[],
 
126
                         const svn_test__actual_data_t actuals[],
 
127
 
112
128
                         apr_pool_t *scratch_pool)
113
129
{
114
130
  const char *dotsvn_abspath = svn_dirent_join(wc_abspath, ".svn",
115
131
                                               scratch_pool);
116
 
  const char *db_abspath = svn_dirent_join(dotsvn_abspath, "wc.db",
117
 
                                           scratch_pool);
118
132
  svn_sqlite__db_t *sdb;
119
133
  const char **my_statements;
120
134
  int i;
 
135
  svn_sqlite__stmt_t *stmt;
 
136
  const apr_int64_t wc_id = 1;
121
137
 
122
138
  /* Allocate MY_STATEMENTS in RESULT_POOL because the SDB will continue to
123
139
   * refer to it over its lifetime. */
124
 
  my_statements = apr_palloc(result_pool, 6 * sizeof(const char *));
 
140
  my_statements = apr_palloc(scratch_pool, 7 * sizeof(const char *));
125
141
  my_statements[0] = statements[STMT_CREATE_SCHEMA];
126
142
  my_statements[1] = statements[STMT_CREATE_NODES];
127
143
  my_statements[2] = statements[STMT_CREATE_NODES_TRIGGERS];
128
144
  my_statements[3] = statements[STMT_CREATE_EXTERNALS];
129
 
  my_statements[4] = extra_statements;
130
 
  my_statements[5] = NULL;
 
145
  my_statements[4] = statements[STMT_INSTALL_SCHEMA_STATISTICS];
 
146
  my_statements[5] = extra_statements;
 
147
  my_statements[6] = NULL;
131
148
 
132
149
  /* Create fake-wc/SUBDIR/.svn/ for placing the metadata. */
133
150
  SVN_ERR(svn_io_make_dir_recursively(dotsvn_abspath, scratch_pool));
134
 
 
135
 
  svn_error_clear(svn_io_remove_file2(db_abspath, FALSE, scratch_pool));
136
151
  SVN_ERR(svn_wc__db_util_open_db(&sdb, wc_abspath, "wc.db",
137
152
                                  svn_sqlite__mode_rwcreate,
138
 
                                  FALSE /* exclusive */, my_statements,
139
 
                                  result_pool, scratch_pool));
 
153
                                  FALSE /* exclusive */, 0 /* timeout */,
 
154
                                  my_statements,
 
155
                                  scratch_pool, scratch_pool));
140
156
  for (i = 0; my_statements[i] != NULL; i++)
141
157
    SVN_ERR(svn_sqlite__exec_statements(sdb, /* my_statements[] */ i));
142
158
 
 
159
  SVN_ERR(svn_sqlite__close(sdb));
 
160
 
 
161
  if (!nodes && !actuals)
 
162
    return SVN_NO_ERROR;
 
163
 
 
164
  /* Re-open with normal set of statements */
 
165
  SVN_ERR(svn_wc__db_util_open_db(&sdb, wc_abspath, "wc.db",
 
166
                                  svn_sqlite__mode_readwrite,
 
167
                                  FALSE /* exclusive */, 0 /* timeout */,
 
168
                                  statements,
 
169
                                  scratch_pool, scratch_pool));
 
170
 
 
171
  if (nodes)
 
172
    {
 
173
      SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
 
174
                                        STMT_INSERT_NODE));
 
175
 
 
176
      for (i = 0; nodes[i].local_relpath; i++)
 
177
        {
 
178
          SVN_ERR(svn_sqlite__bindf(stmt, "isdsnnns",
 
179
                                wc_id,
 
180
                                nodes[i].local_relpath,
 
181
                                nodes[i].op_depth,
 
182
                                nodes[i].local_relpath[0]
 
183
                                  ? svn_relpath_dirname(nodes[i].local_relpath,
 
184
                                                        scratch_pool)
 
185
                                  : NULL,
 
186
                                nodes[i].presence));
 
187
 
 
188
          if (nodes[i].repos_relpath)
 
189
            {
 
190
                SVN_ERR(svn_sqlite__bind_int64(stmt, 5, nodes[i].repos_id));
 
191
                SVN_ERR(svn_sqlite__bind_text(stmt, 6, nodes[i].repos_relpath));
 
192
                SVN_ERR(svn_sqlite__bind_revnum(stmt, 7, nodes[i].revision));
 
193
            }
 
194
 
 
195
          if (nodes[i].depth)
 
196
            SVN_ERR(svn_sqlite__bind_text(stmt, 9, nodes[i].depth));
 
197
 
 
198
          if (nodes[i].kind != 0)
 
199
            SVN_ERR(svn_sqlite__bind_token(stmt, 10, kind_map, nodes[i].kind));
 
200
 
 
201
          if (nodes[i].last_author || nodes[i].last_date)
 
202
            {
 
203
              SVN_ERR(svn_sqlite__bind_revnum(stmt, 11, nodes[i].last_revision));
 
204
              SVN_ERR(svn_sqlite__bind_int64(stmt, 12, nodes[i].last_date));
 
205
              SVN_ERR(svn_sqlite__bind_text(stmt, 13, nodes[i].last_author));
 
206
            }
 
207
 
 
208
          if (nodes[i].checksum)
 
209
            SVN_ERR(svn_sqlite__bind_text(stmt, 14, nodes[i].checksum));
 
210
 
 
211
          if (nodes[i].properties)
 
212
            SVN_ERR(svn_sqlite__bind_text(stmt, 15, nodes[i].properties));
 
213
 
 
214
          if (nodes[i].recorded_size || nodes[i].recorded_time)
 
215
            {
 
216
              SVN_ERR(svn_sqlite__bind_int64(stmt, 16, nodes[i].recorded_size));
 
217
              SVN_ERR(svn_sqlite__bind_int64(stmt, 17, nodes[i].recorded_time));
 
218
            }
 
219
 
 
220
          /* 18 is DAV cache */
 
221
 
 
222
          if (nodes[i].symlink_target)
 
223
            SVN_ERR(svn_sqlite__bind_text(stmt, 19, nodes[i].symlink_target));
 
224
 
 
225
          if (nodes[i].file_external)
 
226
            SVN_ERR(svn_sqlite__bind_int(stmt, 20, 1));
 
227
 
 
228
          if (nodes[i].moved_to)
 
229
            SVN_ERR(svn_sqlite__bind_text(stmt, 21, nodes[i].moved_to));
 
230
 
 
231
          if (nodes[i].moved_here)
 
232
            SVN_ERR(svn_sqlite__bind_int(stmt, 22, 1));
 
233
 
 
234
          if (nodes[i].inherited_props)
 
235
            SVN_ERR(svn_sqlite__bind_text(stmt, 23, nodes[i].inherited_props));
 
236
 
 
237
          SVN_ERR(svn_sqlite__step_done(stmt));
 
238
        }
 
239
    }
 
240
 
 
241
  if (actuals)
 
242
    {
 
243
      SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
 
244
                                        STMT_INSERT_ACTUAL_NODE));
 
245
 
 
246
      for (i = 0; actuals[i].local_relpath; i++)
 
247
        {
 
248
          SVN_ERR(svn_sqlite__bindf(stmt, "isssss",
 
249
                                wc_id,
 
250
                                actuals[i].local_relpath,
 
251
                                actuals[i].local_relpath[0]
 
252
                                  ? svn_relpath_dirname(actuals[i].local_relpath,
 
253
                                                        scratch_pool)
 
254
                                  : NULL,
 
255
                                actuals[i].properties,
 
256
                                actuals[i].changelist,
 
257
                                actuals[i].conflict_data));
 
258
 
 
259
          SVN_ERR(svn_sqlite__step_done(stmt));
 
260
        }
 
261
    }
 
262
 
 
263
  SVN_ERR(svn_sqlite__close(sdb));
 
264
 
143
265
  return SVN_NO_ERROR;
144
266
}
145
267
 
151
273
                         apr_pool_t *pool)
152
274
{
153
275
  sandbox->pool = pool;
154
 
  SVN_ERR(create_repos_and_wc(&sandbox->repos_url, &sandbox->wc_abspath,
 
276
  SVN_ERR(create_repos_and_wc(&sandbox->repos_url, &sandbox->repos_dir,
 
277
                              &sandbox->wc_abspath,
155
278
                              test_name, opts, pool));
156
279
  SVN_ERR(svn_wc_context_create(&sandbox->wc_ctx, NULL, pool, pool));
157
280
  return SVN_NO_ERROR;
158
281
}
159
282
 
160
 
void
 
283
svn_error_t *
161
284
sbox_file_write(svn_test__sandbox_t *b, const char *path, const char *text)
162
285
{
163
 
  FILE *f = fopen(sbox_wc_path(b, path), "w");
164
 
 
165
 
  fputs(text, f);
166
 
  fclose(f);
 
286
  apr_file_t *f;
 
287
 
 
288
  SVN_ERR(svn_io_file_open(&f, sbox_wc_path(b, path),
 
289
                           (APR_WRITE | APR_CREATE | APR_TRUNCATE),
 
290
                           APR_OS_DEFAULT,
 
291
                           b->pool));
 
292
 
 
293
  SVN_ERR(svn_io_file_write_full(f, text, strlen(text), NULL, b->pool));
 
294
 
 
295
  SVN_ERR(svn_io_file_close(f, b->pool));
 
296
 
 
297
  return SVN_NO_ERROR;
167
298
}
168
299
 
169
300
svn_error_t *
175
306
  parent_abspath = svn_dirent_dirname(path, b->pool);
176
307
  SVN_ERR(svn_wc__acquire_write_lock(NULL, b->wc_ctx, parent_abspath, FALSE,
177
308
                                     b->pool, b->pool));
178
 
  SVN_ERR(svn_wc_add_from_disk2(b->wc_ctx, path, NULL /*props*/,
 
309
  SVN_ERR(svn_wc_add_from_disk3(b->wc_ctx, path, NULL /*props*/,
 
310
                                FALSE /* skip checks */,
179
311
                                NULL, NULL, b->pool));
180
312
  SVN_ERR(svn_wc__release_write_lock(b->wc_ctx, parent_abspath, b->pool));
181
313
  return SVN_NO_ERROR;
241
373
                                        scratch_pool, 1,
242
374
                                        sizeof(svn_client_copy_source_t *));
243
375
 
244
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, scratch_pool));
245
 
  ctx->wc_ctx = b->wc_ctx;
 
376
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, scratch_pool));
246
377
 
247
378
  if (SVN_IS_VALID_REVNUM(revision))
248
379
    {
258
389
 
259
390
  APR_ARRAY_PUSH(sources, svn_client_copy_source_t *) = src;
260
391
 
261
 
  SVN_ERR(svn_client_copy6(sources, sbox_wc_path(b, to_path),
262
 
                           FALSE, FALSE, FALSE, NULL, NULL, NULL,
 
392
  SVN_ERR(svn_client_copy7(sources, sbox_wc_path(b, to_path),
 
393
                           FALSE /* copy_as_child */,
 
394
                           FALSE /* make_parents */,
 
395
                           FALSE /* ignore_externals */,
 
396
                           FALSE /* metadata_only */,
 
397
                           FALSE, NULL /* pin_external */,
 
398
                           NULL /* revprops */,
 
399
                           NULL, NULL, /* commit_callback */
263
400
                           ctx, scratch_pool));
264
401
 
265
402
  ctx->wc_ctx = NULL;
283
420
  SVN_ERR(svn_wc__acquire_write_lock(&lock_root_abspath, b->wc_ctx,
284
421
                                     dir_abspath, FALSE /* lock_anchor */,
285
422
                                     b->pool, b->pool));
286
 
  SVN_ERR(svn_wc_revert4(b->wc_ctx, abspath, depth, FALSE, NULL,
 
423
  SVN_ERR(svn_wc_revert5(b->wc_ctx, abspath, depth,
 
424
                         FALSE /* use_commit_times */,
 
425
                         NULL /* changelist_filter */,
 
426
                         FALSE /* clear_changelists */,
 
427
                         FALSE /* metadata_only */,
287
428
                         NULL, NULL, /* cancel baton + func */
288
429
                         NULL, NULL, /* notify baton + func */
289
430
                         b->pool));
335
476
  apr_pool_t *scratch_pool = svn_pool_create(b->pool);
336
477
  svn_error_t *err;
337
478
 
338
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, scratch_pool));
339
 
  ctx->wc_ctx = b->wc_ctx;
 
479
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, scratch_pool));
340
480
 
341
481
  /* A successfull commit doesn't close the ra session, but leaves that
342
482
     to the caller. This leaves the BDB handle open, which might cause
377
517
                                             sizeof(const char *));
378
518
  svn_opt_revision_t revision;
379
519
 
380
 
  revision.kind = svn_opt_revision_number;
381
 
  revision.value.number = revnum;
 
520
  if (SVN_IS_VALID_REVNUM(revnum))
 
521
    {
 
522
      revision.kind = svn_opt_revision_number;
 
523
      revision.value.number = revnum;
 
524
    }
 
525
  else
 
526
    {
 
527
      revision.kind = svn_opt_revision_head;
 
528
    }
382
529
 
383
530
  APR_ARRAY_PUSH(paths, const char *) = sbox_wc_path(b, path);
384
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, b->pool));
385
 
  ctx->wc_ctx = b->wc_ctx;
 
531
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, b->pool));
 
532
 
386
533
  return svn_client_update4(&result_revs, paths, &revision, depth,
387
534
                            sticky, FALSE, FALSE, FALSE, FALSE,
388
535
                            ctx, b->pool);
405
552
  svn_revnum_t result_rev;
406
553
  svn_opt_revision_t head_rev = { svn_opt_revision_head, {0} };
407
554
 
408
 
  url = apr_pstrcat(b->pool, b->repos_url, url, (char*)NULL);
409
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, b->pool));
410
 
  ctx->wc_ctx = b->wc_ctx;
 
555
  url = apr_pstrcat(b->pool, b->repos_url, url, SVN_VA_NULL);
 
556
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, b->pool));
 
557
 
411
558
  return svn_client_switch3(&result_rev, sbox_wc_path(b, path), url,
412
559
                            &head_rev, &head_rev, depth,
413
560
                            FALSE /* depth_is_sticky */,
452
599
}
453
600
 
454
601
svn_error_t *
 
602
sbox_wc_resolve_prop(svn_test__sandbox_t *b, const char *path,
 
603
                     const char *propname,
 
604
                     svn_wc_conflict_choice_t conflict_choice)
 
605
{
 
606
  const char *lock_abspath;
 
607
  svn_error_t *err;
 
608
 
 
609
  SVN_ERR(svn_wc__acquire_write_lock_for_resolve(&lock_abspath, b->wc_ctx,
 
610
                                                 sbox_wc_path(b, path),
 
611
                                                 b->pool, b->pool));
 
612
  err = svn_wc__resolve_conflicts(b->wc_ctx, sbox_wc_path(b, path),
 
613
                                  svn_depth_empty,
 
614
                                  FALSE,
 
615
                                  propname,
 
616
                                  FALSE,
 
617
                                  conflict_choice,
 
618
                                  NULL, NULL, /* conflict func */
 
619
                                  NULL, NULL, /* cancellation */
 
620
                                  NULL, NULL, /* notification */
 
621
                                  b->pool);
 
622
 
 
623
  err = svn_error_compose_create(err, svn_wc__release_write_lock(b->wc_ctx,
 
624
                                                                 lock_abspath,
 
625
                                                                 b->pool));
 
626
  return err;
 
627
}
 
628
 
 
629
 
 
630
svn_error_t *
455
631
sbox_wc_move(svn_test__sandbox_t *b, const char *src, const char *dst)
456
632
{
457
633
  svn_client_ctx_t *ctx;
458
634
  apr_array_header_t *paths = apr_array_make(b->pool, 1,
459
635
                                             sizeof(const char *));
460
636
 
461
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, b->pool));
462
 
  ctx->wc_ctx = b->wc_ctx;
 
637
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, b->pool));
 
638
 
463
639
  APR_ARRAY_PUSH(paths, const char *) = sbox_wc_path(b, src);
464
640
  return svn_client_move7(paths, sbox_wc_path(b, dst),
465
641
                          FALSE /* move_as_child */,
482
658
                                             sizeof(const char *));
483
659
  svn_string_t *pval = value ? svn_string_create(value, b->pool) : NULL;
484
660
 
485
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, b->pool));
486
 
  ctx->wc_ctx = b->wc_ctx;
 
661
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, b->pool));
 
662
 
487
663
  APR_ARRAY_PUSH(paths, const char *) = sbox_wc_path(b, path);
488
664
  return svn_client_propset_local(name, pval, paths, svn_depth_empty,
489
665
                                  TRUE /* skip_checks */,
497
673
  apr_pool_t *scratch_pool = b->pool;
498
674
  svn_client_ctx_t *ctx;
499
675
 
500
 
  SVN_ERR(svn_client_create_context2(&ctx, NULL, scratch_pool));
501
 
  ctx->wc_ctx = b->wc_ctx;
 
676
  SVN_ERR(svn_test__create_client_ctx(&ctx, b, scratch_pool));
502
677
 
503
678
  SVN_ERR(svn_client_relocate2(b->wc_abspath, b->repos_url,
504
679
                               new_repos_url, FALSE, ctx,scratch_pool));
517
692
    {
518
693
      if (node->contents)
519
694
        {
520
 
          sbox_file_write(b, node->path, node->contents);
 
695
          SVN_ERR(sbox_file_write(b, node->path, node->contents));
521
696
          SVN_ERR(sbox_wc_add(b, node->path));
522
697
        }
523
698
      else