1251881Speter/* repos.h : interface to Subversion repository, private to libsvn_repos 2251881Speter * 3251881Speter * ==================================================================== 4251881Speter * Licensed to the Apache Software Foundation (ASF) under one 5251881Speter * or more contributor license agreements. See the NOTICE file 6251881Speter * distributed with this work for additional information 7251881Speter * regarding copyright ownership. The ASF licenses this file 8251881Speter * to you under the Apache License, Version 2.0 (the 9251881Speter * "License"); you may not use this file except in compliance 10251881Speter * with the License. You may obtain a copy of the License at 11251881Speter * 12251881Speter * http://www.apache.org/licenses/LICENSE-2.0 13251881Speter * 14251881Speter * Unless required by applicable law or agreed to in writing, 15251881Speter * software distributed under the License is distributed on an 16251881Speter * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17251881Speter * KIND, either express or implied. See the License for the 18251881Speter * specific language governing permissions and limitations 19251881Speter * under the License. 20251881Speter * ==================================================================== 21251881Speter */ 22251881Speter 23251881Speter#ifndef SVN_LIBSVN_REPOS_H 24251881Speter#define SVN_LIBSVN_REPOS_H 25251881Speter 26251881Speter#include <apr_pools.h> 27251881Speter#include <apr_hash.h> 28251881Speter 29251881Speter#include "svn_fs.h" 30251881Speter 31251881Speter#ifdef __cplusplus 32251881Speterextern "C" { 33251881Speter#endif /* __cplusplus */ 34251881Speter 35251881Speter 36251881Speter/* Repository format number. 37251881Speter 38251881Speter Formats 0, 1 and 2 were pre-1.0. 39251881Speter 40251881Speter Format 3 was current for 1.0 through to 1.3. 41251881Speter 42251881Speter Format 4 was an abortive experiment during the development of the 43251881Speter locking feature in the lead up to 1.2. 44251881Speter 45251881Speter Format 5 was new in 1.4, and is the first format which may contain 46251881Speter BDB or FSFS filesystems with a FS format other than 1, since prior 47251881Speter formats are accepted by some versions of Subversion which do not 48251881Speter pay attention to the FS format number. 49251881Speter*/ 50251881Speter#define SVN_REPOS__FORMAT_NUMBER SVN_REPOS__FORMAT_NUMBER_1_4 51251881Speter#define SVN_REPOS__FORMAT_NUMBER_1_4 5 52251881Speter#define SVN_REPOS__FORMAT_NUMBER_LEGACY 3 53251881Speter 54251881Speter 55251881Speter/*** Repository layout. ***/ 56251881Speter 57251881Speter/* The top-level repository dir contains a README and various 58251881Speter subdirectories. */ 59251881Speter#define SVN_REPOS__README "README.txt" /* Explanation for trespassers. */ 60251881Speter#define SVN_REPOS__FORMAT "format" /* Stores the current version 61251881Speter of the repository. */ 62251881Speter#define SVN_REPOS__DB_DIR "db" /* Where Berkeley lives. */ 63251881Speter#define SVN_REPOS__DAV_DIR "dav" /* DAV sandbox, for pre-1.5 */ 64251881Speter#define SVN_REPOS__LOCK_DIR "locks" /* Lock files live here. */ 65251881Speter#define SVN_REPOS__HOOK_DIR "hooks" /* Hook programs. */ 66251881Speter#define SVN_REPOS__CONF_DIR "conf" /* Configuration files. */ 67251881Speter 68251881Speter/* Things for which we keep lockfiles. */ 69251881Speter#define SVN_REPOS__DB_LOCKFILE "db.lock" /* Our Berkeley lockfile. */ 70251881Speter#define SVN_REPOS__DB_LOGS_LOCKFILE "db-logs.lock" /* BDB logs lockfile. */ 71251881Speter 72251881Speter/* In the repository hooks directory, look for these files. */ 73251881Speter#define SVN_REPOS__HOOK_START_COMMIT "start-commit" 74251881Speter#define SVN_REPOS__HOOK_PRE_COMMIT "pre-commit" 75251881Speter#define SVN_REPOS__HOOK_POST_COMMIT "post-commit" 76251881Speter#define SVN_REPOS__HOOK_READ_SENTINEL "read-sentinels" 77251881Speter#define SVN_REPOS__HOOK_WRITE_SENTINEL "write-sentinels" 78251881Speter#define SVN_REPOS__HOOK_PRE_REVPROP_CHANGE "pre-revprop-change" 79251881Speter#define SVN_REPOS__HOOK_POST_REVPROP_CHANGE "post-revprop-change" 80251881Speter#define SVN_REPOS__HOOK_PRE_LOCK "pre-lock" 81251881Speter#define SVN_REPOS__HOOK_POST_LOCK "post-lock" 82251881Speter#define SVN_REPOS__HOOK_PRE_UNLOCK "pre-unlock" 83251881Speter#define SVN_REPOS__HOOK_POST_UNLOCK "post-unlock" 84251881Speter 85251881Speter 86251881Speter/* The extension added to the names of example hook scripts. */ 87251881Speter#define SVN_REPOS__HOOK_DESC_EXT ".tmpl" 88251881Speter 89251881Speter/* The file which contains a custom set of environment variables 90251881Speter * passed inherited to hook scripts, in the repository conf directory. */ 91251881Speter#define SVN_REPOS__CONF_HOOKS_ENV "hooks-env" 92251881Speter/* The name of the default section in the hooks-env config file. */ 93251881Speter#define SVN_REPOS__HOOKS_ENV_DEFAULT_SECTION "default" 94251881Speter 95251881Speter/* The configuration file for svnserve, in the repository conf directory. */ 96251881Speter#define SVN_REPOS__CONF_SVNSERVE_CONF "svnserve.conf" 97251881Speter 98251881Speter/* In the svnserve default configuration, these are the suggested 99251881Speter locations for the passwd, authz and groups files (in the repository 100251881Speter conf directory), and we put example templates there. */ 101251881Speter#define SVN_REPOS__CONF_PASSWD "passwd" 102251881Speter#define SVN_REPOS__CONF_AUTHZ "authz" 103251881Speter#define SVN_REPOS__CONF_GROUPS "groups" 104251881Speter 105251881Speter/* The Repository object, created by svn_repos_open2() and 106251881Speter svn_repos_create(). */ 107251881Speterstruct svn_repos_t 108251881Speter{ 109251881Speter /* A Subversion filesystem object. */ 110251881Speter svn_fs_t *fs; 111251881Speter 112251881Speter /* The path to the repository's top-level directory. */ 113251881Speter char *path; 114251881Speter 115251881Speter /* The path to the repository's conf directory. */ 116251881Speter char *conf_path; 117251881Speter 118251881Speter /* The path to the repository's hooks directory. */ 119251881Speter char *hook_path; 120251881Speter 121251881Speter /* The path to the repository's locks directory. */ 122251881Speter char *lock_path; 123251881Speter 124251881Speter /* The path to the Berkeley DB filesystem environment. */ 125251881Speter char *db_path; 126251881Speter 127251881Speter /* The format number of this repository. */ 128251881Speter int format; 129251881Speter 130251881Speter /* The path to the repository's hooks enviroment file. If NULL, hooks run 131251881Speter * in an empty environment. */ 132251881Speter const char *hooks_env_path; 133251881Speter 134251881Speter /* The FS backend in use within this repository. */ 135251881Speter const char *fs_type; 136251881Speter 137251881Speter /* If non-null, a list of all the capabilities the client (on the 138251881Speter current connection) has self-reported. Each element is a 139251881Speter 'const char *', one of SVN_RA_CAPABILITY_*. 140251881Speter 141251881Speter Note: it is somewhat counterintuitive that we store the client's 142251881Speter capabilities, which are session-specific, on the repository 143251881Speter object. You'd think the capabilities here would represent the 144251881Speter *repository's* capabilities, but no, they represent the 145251881Speter client's -- we just don't have any other place to persist them. */ 146251881Speter const apr_array_header_t *client_capabilities; 147251881Speter 148251881Speter /* Maps SVN_REPOS_CAPABILITY_foo keys to "yes" or "no" values. 149251881Speter If a capability is not yet discovered, it is absent from the table. 150251881Speter Most likely the keys and values are constants anyway (and 151251881Speter sufficiently well-informed internal code may just compare against 152251881Speter those constants' addresses, therefore). */ 153251881Speter apr_hash_t *repository_capabilities; 154251881Speter 155251881Speter /* Pool from which this structure was allocated. Also used for 156251881Speter auxiliary repository-related data that requires a matching 157251881Speter lifespan. (As the svn_repos_t structure tends to be relatively 158251881Speter long-lived, please be careful regarding this pool's usage.) */ 159251881Speter apr_pool_t *pool; 160251881Speter}; 161251881Speter 162251881Speter 163251881Speter/*** Hook-running Functions ***/ 164251881Speter 165251881Speter/* Set *HOOKS_ENV_P to the parsed contents of the hooks-env file 166251881Speter LOCAL_ABSPATH, allocated in RESULT_POOL. (This result is suitable 167251881Speter for delivery to the various hook wrapper functions which accept a 168251881Speter 'hooks_env' parameter.) If LOCAL_ABSPATH is NULL, set *HOOKS_ENV_P 169251881Speter to NULL. 170251881Speter 171251881Speter Use SCRATCH_POOL for temporary allocations. */ 172251881Spetersvn_error_t * 173251881Spetersvn_repos__parse_hooks_env(apr_hash_t **hooks_env_p, 174251881Speter const char *local_abspath, 175251881Speter apr_pool_t *result_pool, 176251881Speter apr_pool_t *scratch_pool); 177251881Speter 178251881Speter/* Run the start-commit hook for REPOS. Use POOL for any temporary 179251881Speter allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE. 180251881Speter 181251881Speter HOOKS_ENV is a hash of hook script environment information returned 182251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 183251881Speter available). 184251881Speter 185251881Speter USER is the authenticated name of the user starting the commit. 186251881Speter 187251881Speter CAPABILITIES is a list of 'const char *' capability names (using 188251881Speter SVN_RA_CAPABILITY_*) that the client has self-reported. Note that 189251881Speter there is no guarantee the client is telling the truth: the hook 190251881Speter should not make security assumptions based on the capabilities. 191251881Speter 192251881Speter TXN_NAME is the name of the commit transaction that's just been 193251881Speter created. */ 194251881Spetersvn_error_t * 195251881Spetersvn_repos__hooks_start_commit(svn_repos_t *repos, 196251881Speter apr_hash_t *hooks_env, 197251881Speter const char *user, 198251881Speter const apr_array_header_t *capabilities, 199251881Speter const char *txn_name, 200251881Speter apr_pool_t *pool); 201251881Speter 202251881Speter/* Run the pre-commit hook for REPOS. Use POOL for any temporary 203251881Speter allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE. 204251881Speter 205251881Speter HOOKS_ENV is a hash of hook script environment information returned 206251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 207251881Speter available). 208251881Speter 209251881Speter TXN_NAME is the name of the transaction that is being committed. */ 210251881Spetersvn_error_t * 211251881Spetersvn_repos__hooks_pre_commit(svn_repos_t *repos, 212251881Speter apr_hash_t *hooks_env, 213251881Speter const char *txn_name, 214251881Speter apr_pool_t *pool); 215251881Speter 216251881Speter/* Run the post-commit hook for REPOS. Use POOL for any temporary 217251881Speter allocations. If the hook fails, run SVN_ERR_REPOS_HOOK_FAILURE. 218251881Speter 219251881Speter HOOKS_ENV is a hash of hook script environment information returned 220251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 221251881Speter available). 222251881Speter 223251881Speter REV is the revision that was created as a result of the commit. */ 224251881Spetersvn_error_t * 225251881Spetersvn_repos__hooks_post_commit(svn_repos_t *repos, 226251881Speter apr_hash_t *hooks_env, 227251881Speter svn_revnum_t rev, 228251881Speter const char *txn_name, 229251881Speter apr_pool_t *pool); 230251881Speter 231251881Speter/* Run the pre-revprop-change hook for REPOS. Use POOL for any 232251881Speter temporary allocations. If the hook fails, return 233251881Speter SVN_ERR_REPOS_HOOK_FAILURE. 234251881Speter 235251881Speter HOOKS_ENV is a hash of hook script environment information returned 236251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 237251881Speter available). 238251881Speter 239251881Speter REV is the revision whose property is being changed. 240251881Speter AUTHOR is the authenticated name of the user changing the prop. 241251881Speter NAME is the name of the property being changed. 242251881Speter NEW_VALUE is the new value of the property. 243251881Speter ACTION is indicates if the property is being 'A'dded, 'M'odified, 244251881Speter or 'D'eleted. 245251881Speter 246251881Speter The pre-revprop-change hook will have the new property value 247251881Speter written to its stdin. If the property is being deleted, no data 248251881Speter will be written. */ 249251881Spetersvn_error_t * 250251881Spetersvn_repos__hooks_pre_revprop_change(svn_repos_t *repos, 251251881Speter apr_hash_t *hooks_env, 252251881Speter svn_revnum_t rev, 253251881Speter const char *author, 254251881Speter const char *name, 255251881Speter const svn_string_t *new_value, 256251881Speter char action, 257251881Speter apr_pool_t *pool); 258251881Speter 259251881Speter/* Run the pre-revprop-change hook for REPOS. Use POOL for any 260251881Speter temporary allocations. If the hook fails, return 261251881Speter SVN_ERR_REPOS_HOOK_FAILURE. 262251881Speter 263251881Speter HOOKS_ENV is a hash of hook script environment information returned 264251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 265251881Speter available). 266251881Speter 267251881Speter REV is the revision whose property was changed. 268251881Speter AUTHOR is the authenticated name of the user who changed the prop. 269251881Speter NAME is the name of the property that was changed, and OLD_VALUE is 270251881Speter that property's value immediately before the change, or null if 271251881Speter none. ACTION indicates if the property was 'A'dded, 'M'odified, 272251881Speter or 'D'eleted. 273251881Speter 274251881Speter The old value will be passed to the post-revprop hook on stdin. If 275251881Speter the property is being created, no data will be written. */ 276251881Spetersvn_error_t * 277251881Spetersvn_repos__hooks_post_revprop_change(svn_repos_t *repos, 278251881Speter apr_hash_t *hooks_env, 279251881Speter svn_revnum_t rev, 280251881Speter const char *author, 281251881Speter const char *name, 282251881Speter const svn_string_t *old_value, 283251881Speter char action, 284251881Speter apr_pool_t *pool); 285251881Speter 286251881Speter/* Run the pre-lock hook for REPOS. Use POOL for any temporary 287251881Speter allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE. 288251881Speter 289251881Speter HOOKS_ENV is a hash of hook script environment information returned 290251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 291251881Speter available). 292251881Speter 293251881Speter PATH is the path being locked, USERNAME is the person doing it, 294251881Speter COMMENT is the comment of the lock, and is treated as an empty 295251881Speter string when NULL is given. STEAL-LOCK is a flag if the user is 296251881Speter stealing the lock. 297251881Speter 298251881Speter If TOKEN is non-null, set *TOKEN to a new lock token generated by 299251881Speter the pre-lock hook, if any (see the pre-lock hook template for more 300251881Speter information). If TOKEN is non-null but the hook does not return 301251881Speter any token, then set *TOKEN to empty string. */ 302251881Speter 303251881Spetersvn_error_t * 304251881Spetersvn_repos__hooks_pre_lock(svn_repos_t *repos, 305251881Speter apr_hash_t *hooks_env, 306251881Speter const char **token, 307251881Speter const char *path, 308251881Speter const char *username, 309251881Speter const char *comment, 310251881Speter svn_boolean_t steal_lock, 311251881Speter apr_pool_t *pool); 312251881Speter 313251881Speter/* Run the post-lock hook for REPOS. Use POOL for any temporary 314251881Speter allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE. 315251881Speter 316251881Speter HOOKS_ENV is a hash of hook script environment information returned 317251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 318251881Speter available). 319251881Speter 320251881Speter PATHS is an array of paths being locked, USERNAME is the person 321251881Speter who did it. */ 322251881Spetersvn_error_t * 323251881Spetersvn_repos__hooks_post_lock(svn_repos_t *repos, 324251881Speter apr_hash_t *hooks_env, 325251881Speter const apr_array_header_t *paths, 326251881Speter const char *username, 327251881Speter apr_pool_t *pool); 328251881Speter 329251881Speter/* Run the pre-unlock hook for REPOS. Use POOL for any temporary 330251881Speter allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE. 331251881Speter 332251881Speter HOOKS_ENV is a hash of hook script environment information returned 333251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 334251881Speter available). 335251881Speter 336251881Speter PATH is the path being unlocked, USERNAME is the person doing it, 337251881Speter TOKEN is the lock token to be unlocked which should not be NULL, 338251881Speter and BREAK-LOCK is a flag if the user is breaking the lock. */ 339251881Spetersvn_error_t * 340251881Spetersvn_repos__hooks_pre_unlock(svn_repos_t *repos, 341251881Speter apr_hash_t *hooks_env, 342251881Speter const char *path, 343251881Speter const char *username, 344251881Speter const char *token, 345251881Speter svn_boolean_t break_lock, 346251881Speter apr_pool_t *pool); 347251881Speter 348251881Speter/* Run the post-unlock hook for REPOS. Use POOL for any temporary 349251881Speter allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE. 350251881Speter 351251881Speter HOOKS_ENV is a hash of hook script environment information returned 352251881Speter via svn_repos__parse_hooks_env() (or NULL if no such information is 353251881Speter available). 354251881Speter 355251881Speter PATHS is an array of paths being unlocked, USERNAME is the person 356251881Speter who did it. */ 357251881Spetersvn_error_t * 358251881Spetersvn_repos__hooks_post_unlock(svn_repos_t *repos, 359251881Speter apr_hash_t *hooks_env, 360251881Speter const apr_array_header_t *paths, 361251881Speter const char *username, 362251881Speter apr_pool_t *pool); 363251881Speter 364251881Speter 365251881Speter/*** Authz Functions ***/ 366251881Speter 367251881Speter/* Read authz configuration data from PATH into *AUTHZ_P, allocated 368251881Speter in POOL. If GROUPS_PATH is set, use the global groups parsed from it. 369251881Speter 370251881Speter PATH and GROUPS_PATH may be a dirent or a registry path and iff ACCEPT_URLS 371251881Speter is set it may also be an absolute file url. 372251881Speter 373251881Speter If PATH or GROUPS_PATH is not a valid authz rule file, then return 374251881Speter SVN_AUTHZ_INVALID_CONFIG. The contents of *AUTHZ_P is then 375251881Speter undefined. If MUST_EXIST is TRUE, a missing authz or global groups file 376251881Speter is also an error. */ 377251881Spetersvn_error_t * 378251881Spetersvn_repos__authz_read(svn_authz_t **authz_p, 379251881Speter const char *path, 380251881Speter const char *groups_path, 381251881Speter svn_boolean_t must_exist, 382251881Speter svn_boolean_t accept_urls, 383251881Speter apr_pool_t *pool); 384251881Speter 385251881Speter 386251881Speter/*** Utility Functions ***/ 387251881Speter 388251881Speter/* Set *CHANGED_P to TRUE if ROOT1/PATH1 and ROOT2/PATH2 have 389251881Speter different contents, FALSE if they have the same contents. 390251881Speter Use POOL for temporary allocation. */ 391251881Spetersvn_error_t * 392251881Spetersvn_repos__compare_files(svn_boolean_t *changed_p, 393251881Speter svn_fs_root_t *root1, 394251881Speter const char *path1, 395251881Speter svn_fs_root_t *root2, 396251881Speter const char *path2, 397251881Speter apr_pool_t *pool); 398251881Speter 399251881Speter/* Set *PREV_PATH and *PREV_REV to the path and revision which 400251881Speter represent the location at which PATH in FS was located immediately 401251881Speter prior to REVISION iff there was a copy operation (to PATH or one of 402251881Speter its parent directories) between that previous location and 403251881Speter PATH@REVISION, and set *APPEARED_REV to the first revision in which 404251881Speter PATH@REVISION appeared at PATH as a result of that copy operation. 405251881Speter 406251881Speter If there was no such copy operation in that portion 407251881Speter of PATH's history, set *PREV_PATH to NULL, and set *PREV_REV and 408251881Speter *APPEARED_REV to SVN_INVALID_REVNUM. 409251881Speter 410251881Speter NOTE: Any of PREV_PATH, PREV_REV, and APPEARED_REV may be NULL to 411251881Speter if that information is of no interest to the caller. */ 412251881Spetersvn_error_t * 413251881Spetersvn_repos__prev_location(svn_revnum_t *appeared_rev, 414251881Speter const char **prev_path, 415251881Speter svn_revnum_t *prev_rev, 416251881Speter svn_fs_t *fs, 417251881Speter svn_revnum_t revision, 418251881Speter const char *path, 419251881Speter apr_pool_t *pool); 420251881Speter 421251881Speter#ifdef __cplusplus 422251881Speter} 423251881Speter#endif /* __cplusplus */ 424251881Speter 425251881Speter#endif /* SVN_LIBSVN_REPOS_H */ 426