00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Copyright (c) 2000-2007 CollabNet. All rights reserved. 00005 * 00006 * This software is licensed as described in the file COPYING, which 00007 * you should have received as part of this distribution. The terms 00008 * are also available at http://subversion.tigris.org/license-1.html. 00009 * If newer versions of this license are posted there, you may use a 00010 * newer version instead, at your option. 00011 * 00012 * This software consists of voluntary contributions made by many 00013 * individuals. For exact contribution history, see the revision 00014 * history and logs, available at http://subversion.tigris.org/. 00015 * ==================================================================== 00016 * @endcopyright 00017 * 00018 * @file svn_config.h 00019 * @brief Accessing SVN configuration files. 00020 */ 00021 00022 00023 00024 #ifndef SVN_CONFIG_H 00025 #define SVN_CONFIG_H 00026 00027 #include <apr_pools.h> 00028 00029 #include "svn_types.h" 00030 #include "svn_error.h" 00031 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif /* __cplusplus */ 00036 00037 00038 /************************************************************************** 00039 *** *** 00040 *** For a description of the SVN configuration file syntax, see *** 00041 *** your ~/.subversion/README, which is written out automatically by *** 00042 *** svn_config_ensure(). *** 00043 *** *** 00044 **************************************************************************/ 00045 00046 00047 /** Opaque structure describing a set of configuration options. */ 00048 typedef struct svn_config_t svn_config_t; 00049 00050 00051 /*** Configuration Defines ***/ 00052 00053 /** 00054 * @name Client configuration files strings 00055 * Strings for the names of files, sections, and options in the 00056 * client configuration files. 00057 * @{ 00058 */ 00059 #define SVN_CONFIG_CATEGORY_SERVERS "servers" 00060 #define SVN_CONFIG_SECTION_GROUPS "groups" 00061 #define SVN_CONFIG_SECTION_GLOBAL "global" 00062 #define SVN_CONFIG_OPTION_HTTP_PROXY_HOST "http-proxy-host" 00063 #define SVN_CONFIG_OPTION_HTTP_PROXY_PORT "http-proxy-port" 00064 #define SVN_CONFIG_OPTION_HTTP_PROXY_USERNAME "http-proxy-username" 00065 #define SVN_CONFIG_OPTION_HTTP_PROXY_PASSWORD "http-proxy-password" 00066 #define SVN_CONFIG_OPTION_HTTP_PROXY_EXCEPTIONS "http-proxy-exceptions" 00067 #define SVN_CONFIG_OPTION_HTTP_TIMEOUT "http-timeout" 00068 #define SVN_CONFIG_OPTION_HTTP_COMPRESSION "http-compression" 00069 #define SVN_CONFIG_OPTION_NEON_DEBUG_MASK "neon-debug-mask" 00070 #define SVN_CONFIG_OPTION_HTTP_AUTH_TYPES "http-auth-types" 00071 #define SVN_CONFIG_OPTION_SSL_AUTHORITY_FILES "ssl-authority-files" 00072 #define SVN_CONFIG_OPTION_SSL_TRUST_DEFAULT_CA "ssl-trust-default-ca" 00073 #define SVN_CONFIG_OPTION_SSL_CLIENT_CERT_FILE "ssl-client-cert-file" 00074 #define SVN_CONFIG_OPTION_SSL_CLIENT_CERT_PASSWORD "ssl-client-cert-password" 00075 #define SVN_CONFIG_OPTION_SSL_PKCS11_PROVIDER "ssl-pkcs11-provider" 00076 #define SVN_CONFIG_OPTION_HTTP_LIBRARY "http-library" 00077 00078 #define SVN_CONFIG_CATEGORY_CONFIG "config" 00079 #define SVN_CONFIG_SECTION_AUTH "auth" 00080 #define SVN_CONFIG_OPTION_STORE_PASSWORDS "store-passwords" 00081 #define SVN_CONFIG_OPTION_STORE_AUTH_CREDS "store-auth-creds" 00082 #define SVN_CONFIG_SECTION_HELPERS "helpers" 00083 #define SVN_CONFIG_OPTION_EDITOR_CMD "editor-cmd" 00084 #define SVN_CONFIG_OPTION_DIFF_CMD "diff-cmd" 00085 #define SVN_CONFIG_OPTION_DIFF3_CMD "diff3-cmd" 00086 #define SVN_CONFIG_OPTION_DIFF3_HAS_PROGRAM_ARG "diff3-has-program-arg" 00087 #define SVN_CONFIG_OPTION_MERGE_TOOL_CMD "merge-tool-cmd" 00088 #define SVN_CONFIG_SECTION_MISCELLANY "miscellany" 00089 #define SVN_CONFIG_OPTION_GLOBAL_IGNORES "global-ignores" 00090 #define SVN_CONFIG_OPTION_LOG_ENCODING "log-encoding" 00091 #define SVN_CONFIG_OPTION_USE_COMMIT_TIMES "use-commit-times" 00092 #define SVN_CONFIG_OPTION_TEMPLATE_ROOT "template-root" 00093 #define SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS "enable-auto-props" 00094 #define SVN_CONFIG_OPTION_NO_UNLOCK "no-unlock" 00095 #define SVN_CONFIG_OPTION_MIMETYPES_FILE "mime-types-file" 00096 #define SVN_CONFIG_OPTION_PRESERVED_CF_EXTS "preserved-conflict-file-exts" 00097 #define SVN_CONFIG_OPTION_INTERACTIVE_CONFLICTS "interactive-conflicts" 00098 #define SVN_CONFIG_SECTION_TUNNELS "tunnels" 00099 #define SVN_CONFIG_SECTION_AUTO_PROPS "auto-props" 00100 /** @} */ 00101 00102 /** @name Repository conf directory configuration files strings 00103 * Strings for the names of sections and options in the 00104 * repository conf directory configuration files. 00105 * @{ 00106 */ 00107 /* For repository svnserve.conf files */ 00108 #define SVN_CONFIG_SECTION_GENERAL "general" 00109 #define SVN_CONFIG_OPTION_ANON_ACCESS "anon-access" 00110 #define SVN_CONFIG_OPTION_AUTH_ACCESS "auth-access" 00111 #define SVN_CONFIG_OPTION_PASSWORD_DB "password-db" 00112 #define SVN_CONFIG_OPTION_REALM "realm" 00113 #define SVN_CONFIG_OPTION_AUTHZ_DB "authz-db" 00114 #define SVN_CONFIG_SECTION_SASL "sasl" 00115 #define SVN_CONFIG_OPTION_USE_SASL "use-sasl" 00116 #define SVN_CONFIG_OPTION_MIN_SSF "min-encryption" 00117 #define SVN_CONFIG_OPTION_MAX_SSF "max-encryption" 00118 00119 /* For repository password database */ 00120 #define SVN_CONFIG_SECTION_USERS "users" 00121 /** @} */ 00122 00123 /*** Configuration Default Values ***/ 00124 00125 /* '*' matches leading dots, e.g. '*.rej' matches '.foo.rej'. */ 00126 /* We want this to be printed on two lines in the generated config file, 00127 * but we don't want the # character to end up in the variable. 00128 */ 00129 #define SVN_CONFIG__DEFAULT_GLOBAL_IGNORES_LINE_1 \ 00130 "*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo" 00131 #define SVN_CONFIG__DEFAULT_GLOBAL_IGNORES_LINE_2 \ 00132 "*.rej *~ #*# .#* .*.swp .DS_Store" 00133 00134 #define SVN_CONFIG_DEFAULT_GLOBAL_IGNORES \ 00135 SVN_CONFIG__DEFAULT_GLOBAL_IGNORES_LINE_1 " " \ 00136 SVN_CONFIG__DEFAULT_GLOBAL_IGNORES_LINE_2 00137 00138 #define SVN_CONFIG_TRUE "TRUE" 00139 #define SVN_CONFIG_FALSE "FALSE" 00140 00141 00142 /** Read configuration information from the standard sources and merge it 00143 * into the hash @a *cfg_hash. If @a config_dir is not NULL it specifies a 00144 * directory from which to read the configuration files, overriding all 00145 * other sources. Otherwise, first read any system-wide configurations 00146 * (from a file or from the registry), then merge in personal 00147 * configurations (again from file or registry). The hash and all its data 00148 * are allocated in @a pool. 00149 * 00150 * @a *cfg_hash is a hash whose keys are @c const char * configuration 00151 * categories (@c SVN_CONFIG_CATEGORY_SERVERS, 00152 * @c SVN_CONFIG_CATEGORY_CONFIG, etc.) and whose values are the @c 00153 * svn_config_t * items representing the configuration values for that 00154 * category. 00155 */ 00156 svn_error_t *svn_config_get_config(apr_hash_t **cfg_hash, 00157 const char *config_dir, 00158 apr_pool_t *pool); 00159 00160 00161 /** Read configuration data from @a file (a file or registry path) into 00162 * @a *cfgp, allocated in @a pool. 00163 * 00164 * If @a file does not exist, then if @a must_exist, return an error, 00165 * otherwise return an empty @c svn_config_t. 00166 */ 00167 svn_error_t *svn_config_read(svn_config_t **cfgp, 00168 const char *file, 00169 svn_boolean_t must_exist, 00170 apr_pool_t *pool); 00171 00172 /** Like svn_config_read(), but merges the configuration data from @a file 00173 * (a file or registry path) into @a *cfg, which was previously returned 00174 * from svn_config_read(). This function invalidates all value 00175 * expansions in @a cfg, so that the next svn_config_get() takes the 00176 * modifications into account. 00177 */ 00178 svn_error_t *svn_config_merge(svn_config_t *cfg, 00179 const char *file, 00180 svn_boolean_t must_exist); 00181 00182 00183 /** Find the value of a (@a section, @a option) pair in @a cfg, set @a 00184 * *valuep to the value. 00185 * 00186 * If @a cfg is @c NULL, just sets @a *valuep to @a default_value. If 00187 * the value does not exist, expand and return @a default_value. @a 00188 * default_value can be NULL. 00189 * 00190 * The returned value will be valid at least until the next call to 00191 * svn_config_get(), or for the lifetime of @a default_value. It is 00192 * safest to consume the returned value immediately. 00193 * 00194 * This function may change @a cfg by expanding option values. 00195 */ 00196 void svn_config_get(svn_config_t *cfg, const char **valuep, 00197 const char *section, const char *option, 00198 const char *default_value); 00199 00200 /** Add or replace the value of a (@a section, @a option) pair in @a cfg with 00201 * @a value. 00202 * 00203 * This function invalidates all value expansions in @a cfg. 00204 * 00205 * To remove an option, pass NULL for the @c value. 00206 */ 00207 void svn_config_set(svn_config_t *cfg, 00208 const char *section, const char *option, 00209 const char *value); 00210 00211 /** Like svn_config_get(), but for boolean values. 00212 * 00213 * Parses the option as a boolean value. The recognized representations 00214 * are 'TRUE'/'FALSE', 'yes'/'no', 'on'/'off', '1'/'0'; case does not 00215 * matter. Returns an error if the option doesn't contain a known string. 00216 */ 00217 svn_error_t *svn_config_get_bool(svn_config_t *cfg, svn_boolean_t *valuep, 00218 const char *section, const char *option, 00219 svn_boolean_t default_value); 00220 00221 /** Like svn_config_set(), but for boolean values. 00222 * 00223 * Sets the option to 'TRUE'/'FALSE', depending on @a value. 00224 */ 00225 void svn_config_set_bool(svn_config_t *cfg, 00226 const char *section, const char *option, 00227 svn_boolean_t value); 00228 00229 /** Similar to @c svn_config_section_enumerator2_t, but is not 00230 * provided with a memory pool argument. 00231 * 00232 * See svn_config_enumerate_sections() for the details of this type. 00233 * 00234 * @deprecated Provided for backwards compatibility with the 1.2 API. 00235 */ 00236 typedef svn_boolean_t (*svn_config_section_enumerator_t)(const char *name, 00237 void *baton); 00238 00239 /** Similar to svn_config_enumerate_sections2(), but uses a memory pool of 00240 * @a cfg instead of one that is explicitely provided. 00241 * 00242 * @deprecated Provided for backwards compatibility with the 1.2 API. 00243 */ 00244 int svn_config_enumerate_sections(svn_config_t *cfg, 00245 svn_config_section_enumerator_t callback, 00246 void *baton); 00247 00248 /** A callback function used in enumerating config sections. 00249 * 00250 * See svn_config_enumerate_sections2() for the details of this type. 00251 * 00252 * @since New in 1.3. 00253 */ 00254 typedef svn_boolean_t (*svn_config_section_enumerator2_t)(const char *name, 00255 void *baton, 00256 apr_pool_t *pool); 00257 00258 /** Enumerate the sections, passing @a baton and the current section's name 00259 * to @a callback. Continue the enumeration if @a callback returns @c TRUE. 00260 * Return the number of times @a callback was called. 00261 * 00262 * ### See kff's comment to svn_config_enumerate2(). It applies to this 00263 * function, too. ### 00264 * 00265 * @a callback's @a name parameter is only valid for the duration of the call. 00266 * 00267 * @since New in 1.3. 00268 */ 00269 int svn_config_enumerate_sections2(svn_config_t *cfg, 00270 svn_config_section_enumerator2_t callback, 00271 void *baton, apr_pool_t *pool); 00272 00273 /** Similar to @c svn_config_enumerator2_t, but is not 00274 * provided with a memory pool argument. 00275 * See svn_config_enumerate() for the details of this type. 00276 * 00277 * @deprecated Provided for backwards compatibility with the 1.2 API. 00278 */ 00279 typedef svn_boolean_t (*svn_config_enumerator_t)(const char *name, 00280 const char *value, 00281 void *baton); 00282 00283 /** Similar to svn_config_enumerate2(), but uses a memory pool of 00284 * @a cfg instead of one that is explicitely provided. 00285 * 00286 * @deprecated Provided for backwards compatibility with the 1.2 API. 00287 */ 00288 int svn_config_enumerate(svn_config_t *cfg, const char *section, 00289 svn_config_enumerator_t callback, void *baton); 00290 00291 00292 /** A callback function used in enumerating config options. 00293 * 00294 * See svn_config_enumerate2() for the details of this type. 00295 * 00296 * @since New in 1.3. 00297 */ 00298 typedef svn_boolean_t (*svn_config_enumerator2_t)(const char *name, 00299 const char *value, 00300 void *baton, 00301 apr_pool_t *pool); 00302 00303 /** Enumerate the options in @a section, passing @a baton and the current 00304 * option's name and value to @a callback. Continue the enumeration if 00305 * @a callback returns @c TRUE. Return the number of times @a callback 00306 * was called. 00307 * 00308 * ### kff asks: A more usual interface is to continue enumerating 00309 * while @a callback does not return error, and if @a callback does 00310 * return error, to return the same error (or a wrapping of it) 00311 * from svn_config_enumerate(). What's the use case for 00312 * svn_config_enumerate()? Is it more likely to need to break out 00313 * of an enumeration early, with no error, than an invocation of 00314 * @a callback is likely to need to return an error? ### 00315 * 00316 * @a callback's @a name and @a value parameters are only valid for the 00317 * duration of the call. 00318 * 00319 * @since New in 1.3. 00320 */ 00321 int svn_config_enumerate2(svn_config_t *cfg, const char *section, 00322 svn_config_enumerator2_t callback, void *baton, 00323 apr_pool_t *pool); 00324 00325 /** 00326 * Return @c TRUE if @a section exists in @a cfg, @c FALSE otherwise. 00327 * 00328 * @since New in 1.4. 00329 */ 00330 svn_boolean_t svn_config_has_section(svn_config_t *cfg, const char *section); 00331 00332 /** Enumerate the group @a master_section in @a cfg. Each variable 00333 * value is interpreted as a list of glob patterns (separated by comma 00334 * and optional whitespace). Return the name of the first variable 00335 * whose value matches @a key, or @c NULL if no variable matches. 00336 */ 00337 const char *svn_config_find_group(svn_config_t *cfg, const char *key, 00338 const char *master_section, 00339 apr_pool_t *pool); 00340 00341 /** Retrieve value corresponding to @a option_name for a given 00342 * @a server_group in @a cfg , or return @a default_value if none is found. 00343 * 00344 * The config will first be checked for a default, then will be checked for 00345 * an override in a server group. 00346 */ 00347 const char *svn_config_get_server_setting(svn_config_t *cfg, 00348 const char* server_group, 00349 const char* option_name, 00350 const char* default_value); 00351 00352 /** Retrieve value into @a result_value corresponding to @a option_name for a 00353 * given @a server_group in @a cfg, or return @a default_value if none is 00354 * found. 00355 * 00356 * The config will first be checked for a default, then will be checked for 00357 * an override in a server group. If the value found is not a valid integer, 00358 * a @c svn_error_t* will be returned. 00359 */ 00360 svn_error_t *svn_config_get_server_setting_int(svn_config_t *cfg, 00361 const char *server_group, 00362 const char *option_name, 00363 apr_int64_t default_value, 00364 apr_int64_t *result_value, 00365 apr_pool_t *pool); 00366 00367 00368 /** Try to ensure that the user's ~/.subversion/ area exists, and create 00369 * no-op template files for any absent config files. Use @a pool for any 00370 * temporary allocation. If @a config_dir is not @c NULL it specifies a 00371 * directory from which to read the config overriding all other sources. 00372 * 00373 * Don't error if something exists but is the wrong kind (for example, 00374 * ~/.subversion exists but is a file, or ~/.subversion/servers exists 00375 * but is a directory). 00376 * 00377 * Also don't error if trying to create something and failing -- it's 00378 * okay for the config area or its contents not to be created. 00379 * However, if creating a config template file succeeds, return an 00380 * error if unable to initialize its contents. 00381 */ 00382 svn_error_t *svn_config_ensure(const char *config_dir, apr_pool_t *pool); 00383 00384 00385 00386 00387 /** Accessing cached authentication data in the user config area. 00388 * 00389 * @defgroup cached_authentication_data Cached authentication data 00390 * @{ 00391 */ 00392 00393 00394 /** A hash-key pointing to a realmstring. Every file containing 00395 * authentication data should have this key. 00396 */ 00397 #define SVN_CONFIG_REALMSTRING_KEY "svn:realmstring" 00398 00399 /** Use @a cred_kind and @a realmstring to locate a file within the 00400 * ~/.subversion/auth/ area. If the file exists, initialize @a *hash 00401 * and load the file contents into the hash, using @a pool. If the 00402 * file doesn't exist, set @a *hash to NULL. 00403 * 00404 * If @a config_dir is not NULL it specifies a directory from which to 00405 * read the config overriding all other sources. 00406 * 00407 * Besides containing the original credential fields, the hash will 00408 * also contain @c SVN_CONFIG_REALMSTRING_KEY. The caller can examine 00409 * this value as a sanity-check that the correct file was loaded. 00410 * 00411 * The hashtable will contain <tt>const char *</tt> keys and 00412 * <tt>svn_string_t *</tt> values. 00413 */ 00414 svn_error_t * svn_config_read_auth_data(apr_hash_t **hash, 00415 const char *cred_kind, 00416 const char *realmstring, 00417 const char *config_dir, 00418 apr_pool_t *pool); 00419 00420 /** Use @a cred_kind and @a realmstring to create or overwrite a file 00421 * within the ~/.subversion/auth/ area. Write the contents of @a hash into 00422 * the file. If @a config_dir is not NULL it specifies a directory to read 00423 * the config overriding all other sources. 00424 * 00425 * Also, add @a realmstring to the file, with key @c 00426 * SVN_CONFIG_REALMSTRING_KEY. This allows programs (or users) to 00427 * verify exactly which set credentials live within the file. 00428 * 00429 * The hashtable must contain <tt>const char *</tt> keys and 00430 * <tt>svn_string_t *</tt> values. 00431 */ 00432 svn_error_t * svn_config_write_auth_data(apr_hash_t *hash, 00433 const char *cred_kind, 00434 const char *realmstring, 00435 const char *config_dir, 00436 apr_pool_t *pool); 00437 00438 /** @} */ 00439 00440 #ifdef __cplusplus 00441 } 00442 #endif /* __cplusplus */ 00443 00444 #endif /* SVN_CONFIG_H */