3
# Copyright (C) 2005 Matthew Good <trac@matt-good.net>
5
# "THE BEER-WARE LICENSE" (Revision 42):
6
# <trac@matt-good.net> wrote this file. As long as you retain this notice you
7
# can do whatever you want with this stuff. If we meet some day, and you think
8
# this stuff is worth it, you can buy me a beer in return. Matthew Good
10
# Author: Matthew Good <trac@matt-good.net>
14
from trac.core import *
15
from trac.config import Configuration
16
from trac.versioncontrol import RepositoryManager
18
from api import IPasswordStore
19
from util import EnvRelativePathOption
21
class SvnServePasswordStore(Component):
22
"""PasswordStore implementation for reading svnserve's password file format
25
implements(IPasswordStore)
27
filename = EnvRelativePathOption('account-manager', 'password_file',
28
doc='Path to the users file. Leave '
29
'blank to locate the users file '
30
'by reading svnserve.conf')
33
repo_dir = RepositoryManager(self.env).repository_dir
34
self._svnserve_conf = Configuration(os.path.join(repo_dir, 'svnserve.conf'))
38
filename = self.filename
40
self._svnserve_conf.parse_if_needed()
41
filename = self._svnserve_conf['general'].getpath('password-db')
42
if self._userconf is None or filename != self._userconf.filename:
43
self._userconf = Configuration(filename)
45
self._userconf.parse_if_needed()
47
_config = property(_config)
49
# IPasswordStore methods
52
return [user for (user,password) in self._config.options('users')]
54
def has_user(self, user):
55
return user in self._config['users']
57
def set_password(self, user, password):
59
cfg.set('users', user, password)
62
def check_password(self, user, password):
63
return password == self._config.get('users', user)
65
def delete_user(self, user):
67
cfg.remove('users', user)