diff options
Diffstat (limited to 'gitosis/serve.py')
-rw-r--r-- | gitosis/serve.py | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/gitosis/serve.py b/gitosis/serve.py index 867249e..2ba8a75 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -9,11 +9,11 @@ import logging import sys, os, re from gitosis import access +from gitosis import configutil from gitosis import repository -from gitosis import gitweb -from gitosis import gitdaemon from gitosis import app from gitosis import util +from gitosis import run_hook log = logging.getLogger('gitosis.serve') @@ -53,11 +53,11 @@ class WriteAccessDenied(AccessDenied): class ReadAccessDenied(AccessDenied): """Repository read access denied""" -def serve( - cfg, - user, - command, - ): +def serve(cfg, user, command): + """Check the git command for sanity, and then run the git command.""" + + log = logging.getLogger('gitosis.serve.serve') + if '\n' in command: raise CommandMayNotContainNewlineError() @@ -80,6 +80,23 @@ def serve( if (verb not in COMMANDS_WRITE and verb not in COMMANDS_READONLY): raise UnknownCommandError() + + log.debug('Got command %(cmd)r and args %(args)r' % dict( + cmd=verb, + args=args, + )) + + if args.startswith("'/") and args.endswith("'"): + args = args[1:-1] + repos = util.getRepositoryDir(cfg) + reposreal = os.path.realpath(repos) + if args.startswith(repos): + args = os.path.realpath(args)[len(repos)+1:] + elif args.startswith(reposreal): + args = os.path.realpath(args)[len(reposreal)+1:] + else: + args = args[1:] + args = "'%s'" % (args, ) match = ALLOW_RE.match(args) if match is None: @@ -137,23 +154,20 @@ def serve( # authorized to do that: create the repository on the fly # create leading directories - p = topdir + path = topdir + newdirmode = configutil.get_default(cfg, 'repo %s' % (relpath, ), 'dirmode', None) + if newdirmode is None: + newdirmode = configutil.get_default(cfg, 'gitosis', 'dirmode', '0750') + + # Convert string as octal to a number + newdirmode = int(newdirmode, 8) + for segment in repopath.split(os.sep)[:-1]: - p = os.path.join(p, segment) - util.mkdir(p, 0750) + path = os.path.join(path, segment) + util.mkdir(path, newdirmode) - repository.init(path=fullpath) - gitweb.set_descriptions( - config=cfg, - ) - generated = util.getGeneratedFilesDir(config=cfg) - gitweb.generate_project_list( - config=cfg, - path=os.path.join(generated, 'projects.list'), - ) - gitdaemon.set_export_ok( - config=cfg, - ) + repository.init(path=fullpath, mode=newdirmode) + run_hook.build_reposistory_data(cfg) # put the verb back together with the new path newcmd = "%(verb)s '%(path)s'" % dict( @@ -163,14 +177,21 @@ def serve( return newcmd class Main(app.App): + """gitosis-serve program.""" + # W0613 - They also might ignore arguments here, where the descendant + # methods won't. + # pylint: disable-msg=W0613 + def create_parser(self): + """Declare the input for this program.""" parser = super(Main, self).create_parser() parser.set_usage('%prog [OPTS] USER') parser.set_description( 'Allow restricted git operations under DIR') return parser - def handle_args(self, parser, cfg, options, args): + def handle_args(self, parser, cfg, options, args): #pragma: no cover + """Parse the input for this program.""" try: (user,) = args except ValueError: |