19
19
# You should have received a copy of the GNU General Public License
20
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
23
###############################################################################
40
40
the users belonging to the given groups. (User names must be separated by
43
Right now only one section is supported [/], defining the permissions for the
44
repository. The options in those sections are user names or group references
45
(group name with a leading '@'), the corresponding values are the
46
permissions: 'rw', 'r' and '' (without the quotes)
47
for read-write, read-only and no access, respectively.
43
All other sections names should be path names (starting with '/'), defining
44
the permissions for the given path. The options in those sections are user
45
names or group references (group name with a leading '@'), the corresponding
46
values are the permissions: 'rw', 'r' and '' (without the quotes) for
47
read-write, read-only and no access, respectively.
49
Only the options in the section with the longest matching name are evaluated.
50
The last relevant option for the user is used.
49
52
Sample bzr_access.conf::
53
56
devels = beta, gamma, delta
59
67
This allows you to set up a single SSH user, and customize the access based on
60
68
ssh key. Your ``.ssh/authorized_key`` file should look something like this::
123
131
self.groups[group] = set([ s.strip() for s in users.split(",")])
126
def permission(self, user):
134
def permission(self, user, path):
127
135
"""Determines the permission for a given user and a given path
128
136
:param user: user to look for.
137
:param path: path to look for.
129
138
:return: permission.
140
if not path.startswith("/"):
132
142
perm = PERM_DENIED
133
pathFound = self.config.has_section(configSection)
135
options = reversed(self.config.options(configSection))
136
for option in options:
137
value = PERM_DICT.get(self.config.get(configSection, option),
139
if self._is_relevant(option, user):
144
while not pathFound and path != "/":
145
print >>sys.stderr, "DEBUG:", path
146
pathFound = self.config.has_section(path)
148
options = reversed(self.config.options(path))
149
for option in options:
150
value = PERM_DICT.get(self.config.get(path, option),
152
if self._is_relevant(option, user):
155
path = os.path.dirname(path)
144
159
def _is_relevant(self, option, user):
145
160
"""Decides if a certain option is relevant for a given user.
210
225
error("Can't read config file.", EXIT_NOCONF)
212
227
# Determine permission and execute bzr with appropriate options
213
perm = accessMan.permission(user)
214
command = [bzrExec] + BZR_OPTIONS + [repoRoot]
228
perm = accessMan.permission(user, directory)
229
absDir = os.path.join(repoRoot, directory)
230
command = [bzrExec] + BZR_OPTIONS + [absDir]
215
231
if perm == PERM_READ:
216
232
# Nothing extra needed for readonly operations