Ticket #4997 (new enhancement)
Check SVN authz permissions with svn_authz_check_access
| Reported by: | hyugaricdeau@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.13 |
| Component: | version control | Version: | 0.10.3 |
| Severity: | normal | Keywords: | authz swig svn consider |
| Cc: | peter.wihl@… |
Description
I'm just wondering if there's a good reason not to use the Subversion SWIG bindings to check access in authz files. My motivation here is that I would like to take advantage of certain authz syntax available in currently in Subversion's trunk, such as aliases, and special tokens like "$authorized" and "$anonymous".
The simplest solution, rather than reimplement those features in Python, was just to rewrite RealSubversionAuthorizer in svn_authz.py like so:
import svn.repos class RealSubversionAuthorizer(Authorizer): auth_name = '' module_name = '' conf_authz = None def __init__(self, repos, auth_name, module_name, cfg_file): self.repos = repos # Because the username 'anonymous' doesn't mean anything # special to Subversion, it interprets 'anonymous' as an # authenticated user. if auth_name == 'anonymous': self.auth_name = None else: self.auth_name = auth_name self.module_name = module_name self.authz = svn.repos.authz_read(cfg_file, False) def has_permission(self, path): if path is None: return True # svn_authz_check_access will crash your machine if the path # is not rooted at /, so this is crucial. # A trailing slash is also bad, as Subversion doesn't consider # that canonical. path = '/' + path.strip('/') return svn.repos.authz_check_access(self.authz, self.module_name, path, self.auth_name, svn.repos.svn_authz_read) # has_permission_for_changeset is unchanged
This could probably be improved here or there, but it seems to work well enough. I say 'seems' because the one downside I see is that this implementation anyways breaks the unit tests (svn.repos.read_authz() can't take a file pointer as an argument).
However, there may be more esoteric problems with doing it this way, so that's what I would like to confirm.
Thanks.


