1 /* authz.c : path-based access control
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
20 * ====================================================================
26 #include <apr_pools.h>
27 #include <apr_file_io.h>
30 #include "svn_pools.h"
31 #include "svn_error.h"
32 #include "svn_dirent_uri.h"
34 #include "svn_repos.h"
35 #include "svn_config.h"
36 #include "svn_ctype.h"
37 #include "private/svn_fspath.h"
38 #include "private/svn_repos_private.h"
44 /* Information for the config enumerators called during authz
46 struct authz_lookup_baton {
47 /* The authz configuration. */
50 /* The user to authorize. */
53 /* Explicitly granted rights. */
54 svn_repos_authz_access_t allow;
55 /* Explicitly denied rights. */
56 svn_repos_authz_access_t deny;
58 /* The rights required by the caller of the lookup. */
59 svn_repos_authz_access_t required_access;
61 /* The following are used exclusively in recursive lookups. */
63 /* The path in the repository (an fspath) to authorize. */
64 const char *repos_path;
65 /* repos_path prefixed by the repository name and a colon. */
66 const char *qualified_repos_path;
68 /* Whether, at the end of a recursive lookup, access is granted. */
72 /* Information for the config enumeration functions called during the
73 validation process. */
74 struct authz_validate_baton {
75 svn_config_t *config; /* The configuration file being validated. */
76 svn_error_t *err; /* The error being thrown out of the
77 enumerator, if any. */
80 /* Currently this structure is just a wrapper around a svn_config_t.
81 Please update authz_pool if you modify this structure. */
89 /*** Checking access. ***/
91 /* Determine whether the REQUIRED access is granted given what authz
92 * to ALLOW or DENY. Return TRUE if the REQUIRED access is
95 * Access is granted either when no required access is explicitly
96 * denied (implicit grant), or when the required access is explicitly
97 * granted, overriding any denials.
100 authz_access_is_granted(svn_repos_authz_access_t allow,
101 svn_repos_authz_access_t deny,
102 svn_repos_authz_access_t required)
104 svn_repos_authz_access_t stripped_req =
105 required & (svn_authz_read | svn_authz_write);
107 if ((deny & required) == svn_authz_none)
109 else if ((allow & required) == stripped_req)
116 /* Decide whether the REQUIRED access has been conclusively
117 * determined. Return TRUE if the given ALLOW/DENY authz are
118 * conclusive regarding the REQUIRED authz.
120 * Conclusive determination occurs when any of the REQUIRED authz are
121 * granted or denied by ALLOW/DENY.
124 authz_access_is_determined(svn_repos_authz_access_t allow,
125 svn_repos_authz_access_t deny,
126 svn_repos_authz_access_t required)
128 if ((deny & required) || (allow & required))
134 /* Return TRUE is USER equals ALIAS. The alias definitions are in the
135 "aliases" sections of CFG. Use POOL for temporary allocations during
138 authz_alias_is_user(svn_config_t *cfg,
145 svn_config_get(cfg, &value, "aliases", alias, NULL);
149 if (strcmp(value, user) == 0)
156 /* Return TRUE if USER is in GROUP. The group definitions are in the
157 "groups" section of CFG. Use POOL for temporary allocations during
160 authz_group_contains_user(svn_config_t *cfg,
166 apr_array_header_t *list;
169 svn_config_get(cfg, &value, "groups", group, NULL);
171 list = svn_cstring_split(value, ",", TRUE, pool);
173 for (i = 0; i < list->nelts; i++)
175 const char *group_user = APR_ARRAY_IDX(list, i, char *);
177 /* If the 'user' is a subgroup, recurse into it. */
178 if (*group_user == '@')
180 if (authz_group_contains_user(cfg, &group_user[1],
185 /* If the 'user' is an alias, verify it. */
186 else if (*group_user == '&')
188 if (authz_alias_is_user(cfg, &group_user[1],
193 /* If the user matches, stop. */
194 else if (strcmp(user, group_user) == 0)
202 /* Determines whether an authz rule applies to the current
203 * user, given the name part of the rule's name-value pair
204 * in RULE_MATCH_STRING and the authz_lookup_baton object
205 * B with the username in question.
208 authz_line_applies_to_user(const char *rule_match_string,
209 struct authz_lookup_baton *b,
212 /* If the rule has an inversion, recurse and invert the result. */
213 if (rule_match_string[0] == '~')
214 return !authz_line_applies_to_user(&rule_match_string[1], b, pool);
216 /* Check for special tokens. */
217 if (strcmp(rule_match_string, "$anonymous") == 0)
218 return (b->user == NULL);
219 if (strcmp(rule_match_string, "$authenticated") == 0)
220 return (b->user != NULL);
222 /* Check for a wildcard rule. */
223 if (strcmp(rule_match_string, "*") == 0)
226 /* If we get here, then the rule is:
227 * - Not an inversion rule.
228 * - Not an authz token rule.
229 * - Not a wildcard rule.
231 * All that's left over is regular user or group specifications.
234 /* If the session is anonymous, then a user/group
235 * rule definitely won't match.
240 /* Process the rule depending on whether it is
241 * a user, alias or group rule.
243 if (rule_match_string[0] == '@')
244 return authz_group_contains_user(
245 b->config, &rule_match_string[1], b->user, pool);
246 else if (rule_match_string[0] == '&')
247 return authz_alias_is_user(
248 b->config, &rule_match_string[1], b->user, pool);
250 return (strcmp(b->user, rule_match_string) == 0);
254 /* Callback to parse one line of an authz file and update the
255 * authz_baton accordingly.
258 authz_parse_line(const char *name, const char *value,
259 void *baton, apr_pool_t *pool)
261 struct authz_lookup_baton *b = baton;
263 /* Stop if the rule doesn't apply to this user. */
264 if (!authz_line_applies_to_user(name, b, pool))
267 /* Set the access grants for the rule. */
268 if (strchr(value, 'r'))
269 b->allow |= svn_authz_read;
271 b->deny |= svn_authz_read;
273 if (strchr(value, 'w'))
274 b->allow |= svn_authz_write;
276 b->deny |= svn_authz_write;
282 /* Return TRUE iff the access rules in SECTION_NAME apply to PATH_SPEC
283 * (which is a repository name, colon, and repository fspath, such as
284 * "myrepos:/trunk/foo").
287 is_applicable_section(const char *path_spec,
288 const char *section_name)
290 apr_size_t path_spec_len = strlen(path_spec);
292 return ((strncmp(path_spec, section_name, path_spec_len) == 0)
293 && (path_spec[path_spec_len - 1] == '/'
294 || section_name[path_spec_len] == '/'
295 || section_name[path_spec_len] == '\0'));
299 /* Callback to parse a section and update the authz_baton if the
300 * section denies access to the subtree the baton describes.
303 authz_parse_section(const char *section_name, void *baton, apr_pool_t *pool)
305 struct authz_lookup_baton *b = baton;
306 svn_boolean_t conclusive;
308 /* Does the section apply to us? */
309 if (!is_applicable_section(b->qualified_repos_path, section_name)
310 && !is_applicable_section(b->repos_path, section_name))
313 /* Work out what this section grants. */
314 b->allow = b->deny = 0;
315 svn_config_enumerate2(b->config, section_name,
316 authz_parse_line, b, pool);
318 /* Has the section explicitly determined an access? */
319 conclusive = authz_access_is_determined(b->allow, b->deny,
322 /* Is access granted OR inconclusive? */
323 b->access = authz_access_is_granted(b->allow, b->deny,
327 /* As long as access isn't conclusively denied, carry on. */
332 /* Validate access to the given user for the given path. This
333 * function checks rules for exactly the given path, and first tries
334 * to access a section specific to the given repository before falling
335 * back to pan-repository rules.
337 * Update *access_granted to inform the caller of the outcome of the
338 * lookup. Return a boolean indicating whether the access rights were
339 * successfully determined.
342 authz_get_path_access(svn_config_t *cfg, const char *repos_name,
343 const char *path, const char *user,
344 svn_repos_authz_access_t required_access,
345 svn_boolean_t *access_granted,
348 const char *qualified_path;
349 struct authz_lookup_baton baton = { 0 };
354 /* Try to locate a repository-specific block first. */
355 qualified_path = apr_pstrcat(pool, repos_name, ":", path, SVN_VA_NULL);
356 svn_config_enumerate2(cfg, qualified_path,
357 authz_parse_line, &baton, pool);
359 *access_granted = authz_access_is_granted(baton.allow, baton.deny,
362 /* If the first test has determined access, stop now. */
363 if (authz_access_is_determined(baton.allow, baton.deny,
367 /* No repository specific rule, try pan-repository rules. */
368 svn_config_enumerate2(cfg, path, authz_parse_line, &baton, pool);
370 *access_granted = authz_access_is_granted(baton.allow, baton.deny,
372 return authz_access_is_determined(baton.allow, baton.deny,
377 /* Validate access to the given user for the subtree starting at the
378 * given path. This function walks the whole authz file in search of
379 * rules applying to paths in the requested subtree which deny the
382 * As soon as one is found, or else when the whole ACL file has been
383 * searched, return the updated authorization status.
386 authz_get_tree_access(svn_config_t *cfg, const char *repos_name,
387 const char *path, const char *user,
388 svn_repos_authz_access_t required_access,
391 struct authz_lookup_baton baton = { 0 };
395 baton.required_access = required_access;
396 baton.repos_path = path;
397 baton.qualified_repos_path = apr_pstrcat(pool, repos_name,
398 ":", path, SVN_VA_NULL);
399 /* Default to access granted if no rules say otherwise. */
402 svn_config_enumerate_sections2(cfg, authz_parse_section,
409 /* Callback to parse sections of the configuration file, looking for
410 any kind of granted access. Implements the
411 svn_config_section_enumerator2_t interface. */
413 authz_get_any_access_parser_cb(const char *section_name, void *baton,
416 struct authz_lookup_baton *b = baton;
418 /* Does the section apply to the query? */
419 if (section_name[0] == '/'
420 || strncmp(section_name, b->qualified_repos_path,
421 strlen(b->qualified_repos_path)) == 0)
423 b->allow = b->deny = svn_authz_none;
425 svn_config_enumerate2(b->config, section_name,
426 authz_parse_line, baton, pool);
427 b->access = authz_access_is_granted(b->allow, b->deny,
430 /* Continue as long as we don't find a determined, granted access. */
432 && authz_access_is_determined(b->allow, b->deny,
433 b->required_access));
440 /* Walk through the authz CFG to check if USER has the REQUIRED_ACCESS
441 * to any path within the REPOSITORY. Return TRUE if so. Use POOL
442 * for temporary allocations. */
444 authz_get_any_access(svn_config_t *cfg, const char *repos_name,
446 svn_repos_authz_access_t required_access,
449 struct authz_lookup_baton baton = { 0 };
453 baton.required_access = required_access;
454 baton.access = FALSE; /* Deny access by default. */
455 baton.repos_path = "/";
456 baton.qualified_repos_path = apr_pstrcat(pool, repos_name,
459 /* We could have used svn_config_enumerate2 for "repos_name:/".
460 * However, this requires access for root explicitly (which the user
461 * may not always have). So we end up enumerating the sections in
462 * the authz CFG and stop on the first match with some access for
464 svn_config_enumerate_sections2(cfg, authz_get_any_access_parser_cb,
467 /* If walking the configuration was inconclusive, deny access. */
468 if (!authz_access_is_determined(baton.allow,
469 baton.deny, baton.required_access))
477 /*** Validating the authz file. ***/
479 /* Check for errors in GROUP's definition of CFG. The errors
480 * detected are references to non-existent groups and circular
481 * dependencies between groups. If an error is found, return
482 * SVN_ERR_AUTHZ_INVALID_CONFIG. Use POOL for temporary
485 * CHECKED_GROUPS should be an empty (it is used for recursive calls).
488 authz_group_walk(svn_config_t *cfg,
490 apr_hash_t *checked_groups,
494 apr_array_header_t *list;
497 svn_config_get(cfg, &value, "groups", group, NULL);
498 /* Having a non-existent group in the ACL configuration might be the
499 sign of a typo. Refuse to perform authz on uncertain rules. */
501 return svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
502 "An authz rule refers to group '%s', "
503 "which is undefined",
506 list = svn_cstring_split(value, ",", TRUE, pool);
508 for (i = 0; i < list->nelts; i++)
510 const char *group_user = APR_ARRAY_IDX(list, i, char *);
512 /* If the 'user' is a subgroup, recurse into it. */
513 if (*group_user == '@')
515 /* A circular dependency between groups is a Bad Thing. We
516 don't do authz with invalid ACL files. */
517 if (svn_hash_gets(checked_groups, &group_user[1]))
518 return svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG,
520 "Circular dependency between "
521 "groups '%s' and '%s'",
522 &group_user[1], group);
524 /* Add group to hash of checked groups. */
525 svn_hash_sets(checked_groups, &group_user[1], "");
527 /* Recurse on that group. */
528 SVN_ERR(authz_group_walk(cfg, &group_user[1],
529 checked_groups, pool));
531 /* Remove group from hash of checked groups, so that we don't
532 incorrectly report an error if we see it again as part of
534 svn_hash_sets(checked_groups, &group_user[1], NULL);
536 else if (*group_user == '&')
540 svn_config_get(cfg, &alias, "aliases", &group_user[1], NULL);
541 /* Having a non-existent alias in the ACL configuration might be the
542 sign of a typo. Refuse to perform authz on uncertain rules. */
544 return svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
545 "An authz rule refers to alias '%s', "
546 "which is undefined",
555 /* Callback to perform some simple sanity checks on an authz rule.
557 * - If RULE_MATCH_STRING references a group or an alias, verify that
558 * the group or alias definition exists.
559 * - If RULE_MATCH_STRING specifies a token (starts with $), verify
560 * that the token name is valid.
561 * - If RULE_MATCH_STRING is using inversion, verify that it isn't
562 * doing it more than once within the one rule, and that it isn't
563 * "~*", as that would never match.
564 * - Check that VALUE part of the rule specifies only allowed rule
565 * flag characters ('r' and 'w').
567 * Return TRUE if the rule has no errors. Use BATON for context and
570 static svn_boolean_t authz_validate_rule(const char *rule_match_string,
576 const char *match = rule_match_string;
577 struct authz_validate_baton *b = baton;
579 /* Make sure the user isn't using double-negatives. */
582 /* Bump the pointer past the inversion for the other checks. */
585 /* Another inversion is a double negative; we can't not stop. */
588 b->err = svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
589 "Rule '%s' has more than one "
590 "inversion; double negatives are "
596 /* Make sure that the rule isn't "~*", which won't ever match. */
597 if (strcmp(match, "*") == 0)
599 b->err = svn_error_create(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
600 "Authz rules with match string '~*' "
601 "are not allowed, because they never "
607 /* If the rule applies to a group, check its existence. */
610 const char *group = &match[1];
612 svn_config_get(b->config, &val, "groups", group, NULL);
614 /* Having a non-existent group in the ACL configuration might be
615 the sign of a typo. Refuse to perform authz on uncertain
619 b->err = svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
620 "An authz rule refers to group "
621 "'%s', which is undefined",
627 /* If the rule applies to an alias, check its existence. */
630 const char *alias = &match[1];
632 svn_config_get(b->config, &val, "aliases", alias, NULL);
636 b->err = svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
637 "An authz rule refers to alias "
638 "'%s', which is undefined",
644 /* If the rule specifies a token, check its validity. */
647 const char *token_name = &match[1];
649 if ((strcmp(token_name, "anonymous") != 0)
650 && (strcmp(token_name, "authenticated") != 0))
652 b->err = svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
653 "Unrecognized authz token '%s'.",
663 if (*val != 'r' && *val != 'w' && ! svn_ctype_isspace(*val))
665 b->err = svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
666 "The character '%c' in rule '%s' is not "
667 "allowed in authz rules", *val,
678 /* Callback to check ALIAS's definition for validity. Use
679 BATON for context and error reporting. */
680 static svn_boolean_t authz_validate_alias(const char *alias,
685 /* No checking at the moment, every alias is valid */
690 /* Callback to check GROUP's definition for cyclic dependancies. Use
691 BATON for context and error reporting. */
692 static svn_boolean_t authz_validate_group(const char *group,
697 struct authz_validate_baton *b = baton;
699 b->err = authz_group_walk(b->config, group, apr_hash_make(pool), pool);
707 /* Callback to check the contents of the configuration section given
708 by NAME. Use BATON for context and error reporting. */
709 static svn_boolean_t authz_validate_section(const char *name,
713 struct authz_validate_baton *b = baton;
715 /* Use the group checking callback for the "groups" section... */
716 if (strcmp(name, "groups") == 0)
717 svn_config_enumerate2(b->config, name, authz_validate_group,
719 /* ...and the alias checking callback for "aliases"... */
720 else if (strcmp(name, "aliases") == 0)
721 svn_config_enumerate2(b->config, name, authz_validate_alias,
723 /* ...but for everything else use the rule checking callback. */
726 /* Validate the section's name. Skip the optional REPOS_NAME. */
727 const char *fspath = strchr(name, ':');
732 if (! svn_fspath__is_canonical(fspath))
734 b->err = svn_error_createf(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
735 "Section name '%s' contains non-canonical "
741 svn_config_enumerate2(b->config, name, authz_validate_rule,
753 svn_repos__authz_validate(svn_authz_t *authz, apr_pool_t *pool)
755 struct authz_validate_baton baton = { 0 };
757 baton.err = SVN_NO_ERROR;
758 baton.config = authz->cfg;
760 /* Step through the entire rule file stopping on error. */
761 svn_config_enumerate_sections2(authz->cfg, authz_validate_section,
769 /* Retrieve the file at DIRENT (contained in a repo) then parse it as a config
770 * file placing the result into CFG_P allocated in POOL.
772 * If DIRENT cannot be parsed as a config file then an error is returned. The
773 * contents of CFG_P is then undefined. If MUST_EXIST is TRUE, a missing
774 * authz file is also an error. The CASE_SENSITIVE controls the lookup
775 * behavior for section and option names alike.
777 * SCRATCH_POOL will be used for temporary allocations. */
779 authz_retrieve_config_repo(svn_config_t **cfg_p,
781 svn_boolean_t must_exist,
782 svn_boolean_t case_sensitive,
783 apr_pool_t *result_pool,
784 apr_pool_t *scratch_pool)
788 const char *repos_root_dirent;
792 svn_revnum_t youngest_rev;
793 svn_node_kind_t node_kind;
794 svn_stream_t *contents;
796 /* Search for a repository in the full path. */
797 repos_root_dirent = svn_repos_find_root_path(dirent, scratch_pool);
798 if (!repos_root_dirent)
799 return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_NOT_FOUND, NULL,
800 "Unable to find repository at '%s'", dirent);
802 /* Attempt to open a repository at repos_root_dirent. */
803 SVN_ERR(svn_repos_open3(&repos, repos_root_dirent, NULL, scratch_pool,
806 fs_path = &dirent[strlen(repos_root_dirent)];
808 /* Root path is always a directory so no reason to go any further */
809 if (*fs_path == '\0')
810 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
811 "'/' is not a file in repo '%s'",
814 /* We skip some things that are non-important for how we're going to use
815 * this repo connection. We do not set any capabilities since none of
816 * the current ones are important for what we're doing. We also do not
817 * setup the environment that repos hooks would run under since we won't
818 * be triggering any. */
820 /* Get the filesystem. */
821 fs = svn_repos_fs(repos);
823 /* Find HEAD and the revision root */
824 SVN_ERR(svn_fs_youngest_rev(&youngest_rev, fs, scratch_pool));
825 SVN_ERR(svn_fs_revision_root(&root, fs, youngest_rev, scratch_pool));
827 SVN_ERR(svn_fs_check_path(&node_kind, root, fs_path, scratch_pool));
828 if (node_kind == svn_node_none)
832 SVN_ERR(svn_config_create2(cfg_p, case_sensitive, case_sensitive,
838 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
839 "'%s' path not found in repo '%s'", fs_path,
843 else if (node_kind != svn_node_file)
845 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
846 "'%s' is not a file in repo '%s'", fs_path,
850 SVN_ERR(svn_fs_file_contents(&contents, root, fs_path, scratch_pool));
851 err = svn_config_parse(cfg_p, contents, case_sensitive, case_sensitive,
854 /* Add the URL to the error stack since the parser doesn't have it. */
855 if (err != SVN_NO_ERROR)
856 return svn_error_createf(err->apr_err, err,
857 "Error while parsing config file: '%s' in repo '%s':",
858 fs_path, repos_root_dirent);
864 svn_repos__retrieve_config(svn_config_t **cfg_p,
866 svn_boolean_t must_exist,
867 svn_boolean_t case_sensitive,
870 if (svn_path_is_url(path))
874 apr_pool_t *scratch_pool = svn_pool_create(pool);
876 err = svn_uri_get_dirent_from_file_url(&dirent, path, scratch_pool);
878 if (err == SVN_NO_ERROR)
879 err = authz_retrieve_config_repo(cfg_p, dirent, must_exist,
880 case_sensitive, pool, scratch_pool);
882 /* Close the repos and streams we opened. */
883 svn_pool_destroy(scratch_pool);
889 /* Outside of repo file or Windows registry*/
890 SVN_ERR(svn_config_read3(cfg_p, path, must_exist, case_sensitive,
891 case_sensitive, pool));
898 /* Callback to copy (name, value) group into the "groups" section
899 of another configuration. */
901 authz_copy_group(const char *name, const char *value,
902 void *baton, apr_pool_t *pool)
904 svn_config_t *authz_cfg = baton;
906 svn_config_set(authz_cfg, SVN_CONFIG_SECTION_GROUPS, name, value);
911 /* Copy group definitions from GROUPS_CFG to the resulting AUTHZ.
912 * If AUTHZ already contains any group definition, report an error.
913 * Use POOL for temporary allocations. */
915 authz_copy_groups(svn_authz_t *authz, svn_config_t *groups_cfg,
918 /* Easy out: we prohibit local groups in the authz file when global
919 groups are being used. */
920 if (svn_config_has_section(authz->cfg, SVN_CONFIG_SECTION_GROUPS))
922 return svn_error_create(SVN_ERR_AUTHZ_INVALID_CONFIG, NULL,
923 "Authz file cannot contain any groups "
924 "when global groups are being used.");
927 svn_config_enumerate2(groups_cfg, SVN_CONFIG_SECTION_GROUPS,
928 authz_copy_group, authz->cfg, pool);
934 svn_repos__authz_read(svn_authz_t **authz_p, const char *path,
935 const char *groups_path, svn_boolean_t must_exist,
936 svn_boolean_t accept_urls, apr_pool_t *pool)
938 svn_authz_t *authz = apr_palloc(pool, sizeof(*authz));
940 /* Load the authz file */
942 SVN_ERR(svn_repos__retrieve_config(&authz->cfg, path, must_exist, TRUE,
945 SVN_ERR(svn_config_read3(&authz->cfg, path, must_exist, TRUE, TRUE,
950 svn_config_t *groups_cfg;
953 /* Load the groups file */
955 SVN_ERR(svn_repos__retrieve_config(&groups_cfg, groups_path,
956 must_exist, TRUE, pool));
958 SVN_ERR(svn_config_read3(&groups_cfg, groups_path, must_exist,
961 /* Copy the groups from groups_cfg into authz. */
962 err = authz_copy_groups(authz, groups_cfg, pool);
964 /* Add the paths to the error stack since the authz_copy_groups
965 routine knows nothing about them. */
966 if (err != SVN_NO_ERROR)
967 return svn_error_createf(err->apr_err, err,
968 "Error reading authz file '%s' with "
969 "groups file '%s':", path, groups_path);
972 /* Make sure there are no errors in the configuration. */
973 SVN_ERR(svn_repos__authz_validate(authz, pool));
981 /*** Public functions. ***/
984 svn_repos_authz_read2(svn_authz_t **authz_p, const char *path,
985 const char *groups_path, svn_boolean_t must_exist,
988 return svn_repos__authz_read(authz_p, path, groups_path, must_exist,
994 svn_repos_authz_parse(svn_authz_t **authz_p, svn_stream_t *stream,
995 svn_stream_t *groups_stream, apr_pool_t *pool)
997 svn_authz_t *authz = apr_palloc(pool, sizeof(*authz));
999 /* Parse the authz stream */
1000 SVN_ERR(svn_config_parse(&authz->cfg, stream, TRUE, TRUE, pool));
1004 svn_config_t *groups_cfg;
1006 /* Parse the groups stream */
1007 SVN_ERR(svn_config_parse(&groups_cfg, groups_stream, TRUE, TRUE, pool));
1009 SVN_ERR(authz_copy_groups(authz, groups_cfg, pool));
1012 /* Make sure there are no errors in the configuration. */
1013 SVN_ERR(svn_repos__authz_validate(authz, pool));
1016 return SVN_NO_ERROR;
1021 svn_repos_authz_check_access(svn_authz_t *authz, const char *repos_name,
1022 const char *path, const char *user,
1023 svn_repos_authz_access_t required_access,
1024 svn_boolean_t *access_granted,
1027 const char *current_path;
1032 /* If PATH is NULL, check if the user has *any* access. */
1035 *access_granted = authz_get_any_access(authz->cfg, repos_name,
1036 user, required_access, pool);
1037 return SVN_NO_ERROR;
1041 SVN_ERR_ASSERT(path[0] == '/');
1043 /* Determine the granted access for the requested path. */
1044 path = svn_fspath__canonicalize(path, pool);
1045 current_path = path;
1047 while (!authz_get_path_access(authz->cfg, repos_name,
1053 /* Stop if the loop hits the repository root with no
1055 if (current_path[0] == '/' && current_path[1] == '\0')
1057 /* Deny access by default. */
1058 *access_granted = FALSE;
1059 return SVN_NO_ERROR;
1062 /* Work back to the parent path. */
1063 current_path = svn_fspath__dirname(current_path, pool);
1066 /* If the caller requested recursive access, we need to walk through
1067 the entire authz config to see whether any child paths are denied
1068 to the requested user. */
1069 if (*access_granted && (required_access & svn_authz_recursive))
1070 *access_granted = authz_get_tree_access(authz->cfg, repos_name, path,
1071 user, required_access, pool);
1073 return SVN_NO_ERROR;