]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_repos/repos.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / libsvn_repos / repos.h
1 /* repos.h : interface to Subversion repository, private to libsvn_repos
2  *
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  */
22
23 #ifndef SVN_LIBSVN_REPOS_H
24 #define SVN_LIBSVN_REPOS_H
25
26 #include <apr_pools.h>
27 #include <apr_hash.h>
28
29 #include "svn_fs.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34
35 \f
36 /* Repository format number.
37
38    Formats 0, 1 and 2 were pre-1.0.
39
40    Format 3 was current for 1.0 through to 1.3.
41
42    Format 4 was an abortive experiment during the development of the
43    locking feature in the lead up to 1.2.
44
45    Format 5 was new in 1.4, and is the first format which may contain
46    BDB or FSFS filesystems with a FS format other than 1, since prior
47    formats are accepted by some versions of Subversion which do not
48    pay attention to the FS format number.
49 */
50 #define SVN_REPOS__FORMAT_NUMBER         SVN_REPOS__FORMAT_NUMBER_1_4
51 #define SVN_REPOS__FORMAT_NUMBER_1_4     5
52 #define SVN_REPOS__FORMAT_NUMBER_LEGACY  3
53
54 \f
55 /*** Repository layout. ***/
56
57 /* The top-level repository dir contains a README and various
58    subdirectories.  */
59 #define SVN_REPOS__README      "README.txt" /* Explanation for trespassers. */
60 #define SVN_REPOS__FORMAT      "format"     /* Stores the current version
61                                                of the repository. */
62 #define SVN_REPOS__DB_DIR      "db"         /* Where Berkeley lives. */
63 #define SVN_REPOS__DAV_DIR     "dav"        /* DAV sandbox, for pre-1.5 */
64 #define SVN_REPOS__LOCK_DIR    "locks"      /* Lock files live here. */
65 #define SVN_REPOS__HOOK_DIR    "hooks"      /* Hook programs. */
66 #define SVN_REPOS__CONF_DIR    "conf"       /* Configuration files. */
67
68 /* Things for which we keep lockfiles. */
69 #define SVN_REPOS__DB_LOCKFILE "db.lock" /* Our Berkeley lockfile. */
70 #define SVN_REPOS__DB_LOGS_LOCKFILE "db-logs.lock" /* BDB logs lockfile. */
71
72 /* In the repository hooks directory, look for these files. */
73 #define SVN_REPOS__HOOK_START_COMMIT    "start-commit"
74 #define SVN_REPOS__HOOK_PRE_COMMIT      "pre-commit"
75 #define SVN_REPOS__HOOK_POST_COMMIT     "post-commit"
76 #define SVN_REPOS__HOOK_READ_SENTINEL   "read-sentinels"
77 #define SVN_REPOS__HOOK_WRITE_SENTINEL  "write-sentinels"
78 #define SVN_REPOS__HOOK_PRE_REVPROP_CHANGE  "pre-revprop-change"
79 #define SVN_REPOS__HOOK_POST_REVPROP_CHANGE "post-revprop-change"
80 #define SVN_REPOS__HOOK_PRE_LOCK        "pre-lock"
81 #define SVN_REPOS__HOOK_POST_LOCK       "post-lock"
82 #define SVN_REPOS__HOOK_PRE_UNLOCK      "pre-unlock"
83 #define SVN_REPOS__HOOK_POST_UNLOCK     "post-unlock"
84
85
86 /* The extension added to the names of example hook scripts. */
87 #define SVN_REPOS__HOOK_DESC_EXT        ".tmpl"
88
89 /* The file which contains a custom set of environment variables
90  * passed inherited to hook scripts, in the repository conf directory. */
91 #define SVN_REPOS__CONF_HOOKS_ENV "hooks-env"
92 /* The name of the default section in the hooks-env config file. */
93 #define SVN_REPOS__HOOKS_ENV_DEFAULT_SECTION "default"
94
95 /* The configuration file for svnserve, in the repository conf directory. */
96 #define SVN_REPOS__CONF_SVNSERVE_CONF "svnserve.conf"
97
98 /* In the svnserve default configuration, these are the suggested
99    locations for the passwd, authz and groups files (in the repository
100    conf directory), and we put example templates there. */
101 #define SVN_REPOS__CONF_PASSWD "passwd"
102 #define SVN_REPOS__CONF_AUTHZ "authz"
103 #define SVN_REPOS__CONF_GROUPS "groups"
104
105 /* The Repository object, created by svn_repos_open2() and
106    svn_repos_create(). */
107 struct svn_repos_t
108 {
109   /* A Subversion filesystem object. */
110   svn_fs_t *fs;
111
112   /* The path to the repository's top-level directory. */
113   char *path;
114
115   /* The path to the repository's conf directory. */
116   char *conf_path;
117
118   /* The path to the repository's hooks directory. */
119   char *hook_path;
120
121   /* The path to the repository's locks directory. */
122   char *lock_path;
123
124   /* The path to the Berkeley DB filesystem environment. */
125   char *db_path;
126
127   /* The format number of this repository. */
128   int format;
129
130   /* The path to the repository's hooks enviroment file. If NULL, hooks run
131    * in an empty environment. */
132   const char *hooks_env_path;
133
134   /* The FS backend in use within this repository. */
135   const char *fs_type;
136
137   /* If non-null, a list of all the capabilities the client (on the
138      current connection) has self-reported.  Each element is a
139      'const char *', one of SVN_RA_CAPABILITY_*.
140
141      Note: it is somewhat counterintuitive that we store the client's
142      capabilities, which are session-specific, on the repository
143      object.  You'd think the capabilities here would represent the
144      *repository's* capabilities, but no, they represent the
145      client's -- we just don't have any other place to persist them. */
146   const apr_array_header_t *client_capabilities;
147
148   /* Maps SVN_REPOS_CAPABILITY_foo keys to "yes" or "no" values.
149      If a capability is not yet discovered, it is absent from the table.
150      Most likely the keys and values are constants anyway (and
151      sufficiently well-informed internal code may just compare against
152      those constants' addresses, therefore). */
153   apr_hash_t *repository_capabilities;
154
155   /* Pool from which this structure was allocated.  Also used for
156      auxiliary repository-related data that requires a matching
157      lifespan.  (As the svn_repos_t structure tends to be relatively
158      long-lived, please be careful regarding this pool's usage.)  */
159   apr_pool_t *pool;
160 };
161
162 \f
163 /*** Hook-running Functions ***/
164
165 /* Set *HOOKS_ENV_P to the parsed contents of the hooks-env file
166    LOCAL_ABSPATH, allocated in RESULT_POOL.  (This result is suitable
167    for delivery to the various hook wrapper functions which accept a
168    'hooks_env' parameter.)  If LOCAL_ABSPATH is NULL, set *HOOKS_ENV_P
169    to NULL.
170
171    Use SCRATCH_POOL for temporary allocations.  */
172 svn_error_t *
173 svn_repos__parse_hooks_env(apr_hash_t **hooks_env_p,
174                            const char *local_abspath,
175                            apr_pool_t *result_pool,
176                            apr_pool_t *scratch_pool);
177
178 /* Run the start-commit hook for REPOS.  Use POOL for any temporary
179    allocations.  If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
180
181    HOOKS_ENV is a hash of hook script environment information returned
182    via svn_repos__parse_hooks_env() (or NULL if no such information is
183    available).
184
185    USER is the authenticated name of the user starting the commit.
186
187    CAPABILITIES is a list of 'const char *' capability names (using
188    SVN_RA_CAPABILITY_*) that the client has self-reported.  Note that
189    there is no guarantee the client is telling the truth: the hook
190    should not make security assumptions based on the capabilities.
191
192    TXN_NAME is the name of the commit transaction that's just been
193    created. */
194 svn_error_t *
195 svn_repos__hooks_start_commit(svn_repos_t *repos,
196                               apr_hash_t *hooks_env,
197                               const char *user,
198                               const apr_array_header_t *capabilities,
199                               const char *txn_name,
200                               apr_pool_t *pool);
201
202 /* Run the pre-commit hook for REPOS.  Use POOL for any temporary
203    allocations.  If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
204
205    HOOKS_ENV is a hash of hook script environment information returned
206    via svn_repos__parse_hooks_env() (or NULL if no such information is
207    available).
208
209    TXN_NAME is the name of the transaction that is being committed.  */
210 svn_error_t *
211 svn_repos__hooks_pre_commit(svn_repos_t *repos,
212                             apr_hash_t *hooks_env,
213                             const char *txn_name,
214                             apr_pool_t *pool);
215
216 /* Run the post-commit hook for REPOS.  Use POOL for any temporary
217    allocations.  If the hook fails, run SVN_ERR_REPOS_HOOK_FAILURE.
218
219    HOOKS_ENV is a hash of hook script environment information returned
220    via svn_repos__parse_hooks_env() (or NULL if no such information is
221    available).
222
223    REV is the revision that was created as a result of the commit.  */
224 svn_error_t *
225 svn_repos__hooks_post_commit(svn_repos_t *repos,
226                              apr_hash_t *hooks_env,
227                              svn_revnum_t rev,
228                              const char *txn_name,
229                              apr_pool_t *pool);
230
231 /* Run the pre-revprop-change hook for REPOS.  Use POOL for any
232    temporary allocations.  If the hook fails, return
233    SVN_ERR_REPOS_HOOK_FAILURE.
234
235    HOOKS_ENV is a hash of hook script environment information returned
236    via svn_repos__parse_hooks_env() (or NULL if no such information is
237    available).
238
239    REV is the revision whose property is being changed.
240    AUTHOR is the authenticated name of the user changing the prop.
241    NAME is the name of the property being changed.
242    NEW_VALUE is the new value of the property.
243    ACTION is indicates if the property is being 'A'dded, 'M'odified,
244    or 'D'eleted.
245
246    The pre-revprop-change hook will have the new property value
247    written to its stdin.  If the property is being deleted, no data
248    will be written. */
249 svn_error_t *
250 svn_repos__hooks_pre_revprop_change(svn_repos_t *repos,
251                                     apr_hash_t *hooks_env,
252                                     svn_revnum_t rev,
253                                     const char *author,
254                                     const char *name,
255                                     const svn_string_t *new_value,
256                                     char action,
257                                     apr_pool_t *pool);
258
259 /* Run the pre-revprop-change hook for REPOS.  Use POOL for any
260    temporary allocations.  If the hook fails, return
261    SVN_ERR_REPOS_HOOK_FAILURE.
262
263    HOOKS_ENV is a hash of hook script environment information returned
264    via svn_repos__parse_hooks_env() (or NULL if no such information is
265    available).
266
267    REV is the revision whose property was changed.
268    AUTHOR is the authenticated name of the user who changed the prop.
269    NAME is the name of the property that was changed, and OLD_VALUE is
270    that property's value immediately before the change, or null if
271    none.  ACTION indicates if the property was 'A'dded, 'M'odified,
272    or 'D'eleted.
273
274    The old value will be passed to the post-revprop hook on stdin.  If
275    the property is being created, no data will be written. */
276 svn_error_t *
277 svn_repos__hooks_post_revprop_change(svn_repos_t *repos,
278                                      apr_hash_t *hooks_env,
279                                      svn_revnum_t rev,
280                                      const char *author,
281                                      const char *name,
282                                      const svn_string_t *old_value,
283                                      char action,
284                                      apr_pool_t *pool);
285
286 /* Run the pre-lock hook for REPOS.  Use POOL for any temporary
287    allocations.  If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
288
289    HOOKS_ENV is a hash of hook script environment information returned
290    via svn_repos__parse_hooks_env() (or NULL if no such information is
291    available).
292
293    PATH is the path being locked, USERNAME is the person doing it,
294    COMMENT is the comment of the lock, and is treated as an empty
295    string when NULL is given.  STEAL-LOCK is a flag if the user is
296    stealing the lock.
297
298    If TOKEN is non-null, set *TOKEN to a new lock token generated by
299    the pre-lock hook, if any (see the pre-lock hook template for more
300    information).  If TOKEN is non-null but the hook does not return
301    any token, then set *TOKEN to empty string. */
302
303 svn_error_t *
304 svn_repos__hooks_pre_lock(svn_repos_t *repos,
305                           apr_hash_t *hooks_env,
306                           const char **token,
307                           const char *path,
308                           const char *username,
309                           const char *comment,
310                           svn_boolean_t steal_lock,
311                           apr_pool_t *pool);
312
313 /* Run the post-lock hook for REPOS.  Use POOL for any temporary
314    allocations.  If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
315
316    HOOKS_ENV is a hash of hook script environment information returned
317    via svn_repos__parse_hooks_env() (or NULL if no such information is
318    available).
319
320    PATHS is an array of paths being locked, USERNAME is the person
321    who did it.  */
322 svn_error_t *
323 svn_repos__hooks_post_lock(svn_repos_t *repos,
324                            apr_hash_t *hooks_env,
325                            const apr_array_header_t *paths,
326                            const char *username,
327                            apr_pool_t *pool);
328
329 /* Run the pre-unlock hook for REPOS.  Use POOL for any temporary
330    allocations.  If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
331
332    HOOKS_ENV is a hash of hook script environment information returned
333    via svn_repos__parse_hooks_env() (or NULL if no such information is
334    available).
335
336    PATH is the path being unlocked, USERNAME is the person doing it,
337    TOKEN is the lock token to be unlocked which should not be NULL,
338    and BREAK-LOCK is a flag if the user is breaking the lock.  */
339 svn_error_t *
340 svn_repos__hooks_pre_unlock(svn_repos_t *repos,
341                             apr_hash_t *hooks_env,
342                             const char *path,
343                             const char *username,
344                             const char *token,
345                             svn_boolean_t break_lock,
346                             apr_pool_t *pool);
347
348 /* Run the post-unlock hook for REPOS.  Use POOL for any temporary
349    allocations.  If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
350
351    HOOKS_ENV is a hash of hook script environment information returned
352    via svn_repos__parse_hooks_env() (or NULL if no such information is
353    available).
354
355    PATHS is an array of paths being unlocked, USERNAME is the person
356    who did it.  */
357 svn_error_t *
358 svn_repos__hooks_post_unlock(svn_repos_t *repos,
359                              apr_hash_t *hooks_env,
360                              const apr_array_header_t *paths,
361                              const char *username,
362                              apr_pool_t *pool);
363
364 \f
365 /*** Authz Functions ***/
366
367 /* Read authz configuration data from PATH into *AUTHZ_P, allocated
368    in POOL.  If GROUPS_PATH is set, use the global groups parsed from it.
369
370    PATH and GROUPS_PATH may be a dirent or a registry path and iff ACCEPT_URLS
371    is set it may also be an absolute file url.
372
373    If PATH or GROUPS_PATH is not a valid authz rule file, then return
374    SVN_AUTHZ_INVALID_CONFIG.  The contents of *AUTHZ_P is then
375    undefined.  If MUST_EXIST is TRUE, a missing authz or global groups file
376    is also an error. */
377 svn_error_t *
378 svn_repos__authz_read(svn_authz_t **authz_p,
379                       const char *path,
380                       const char *groups_path,
381                       svn_boolean_t must_exist,
382                       svn_boolean_t accept_urls,
383                       apr_pool_t *pool);
384
385 \f
386 /*** Utility Functions ***/
387
388 /* Set *CHANGED_P to TRUE if ROOT1/PATH1 and ROOT2/PATH2 have
389    different contents, FALSE if they have the same contents.
390    Use POOL for temporary allocation. */
391 svn_error_t *
392 svn_repos__compare_files(svn_boolean_t *changed_p,
393                          svn_fs_root_t *root1,
394                          const char *path1,
395                          svn_fs_root_t *root2,
396                          const char *path2,
397                          apr_pool_t *pool);
398
399 /* Set *PREV_PATH and *PREV_REV to the path and revision which
400    represent the location at which PATH in FS was located immediately
401    prior to REVISION iff there was a copy operation (to PATH or one of
402    its parent directories) between that previous location and
403    PATH@REVISION, and set *APPEARED_REV to the first revision in which
404    PATH@REVISION appeared at PATH as a result of that copy operation.
405
406    If there was no such copy operation in that portion
407    of PATH's history, set *PREV_PATH to NULL, and set *PREV_REV and
408    *APPEARED_REV to SVN_INVALID_REVNUM.
409
410    NOTE: Any of PREV_PATH, PREV_REV, and APPEARED_REV may be NULL to
411    if that information is of no interest to the caller.  */
412 svn_error_t *
413 svn_repos__prev_location(svn_revnum_t *appeared_rev,
414                          const char **prev_path,
415                          svn_revnum_t *prev_rev,
416                          svn_fs_t *fs,
417                          svn_revnum_t revision,
418                          const char *path,
419                          apr_pool_t *pool);
420
421 #ifdef __cplusplus
422 }
423 #endif /* __cplusplus */
424
425 #endif /* SVN_LIBSVN_REPOS_H */