def test_htaccess_disabled(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') os.mkdir(path) writeFile(htaccess.htaccess_path(path), '') cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) eq(htaccess.gen_htaccess_if_enabled(config=cfg),False) exported(path, '')
) # re-read config to get up-to-date settings cfg.read(os.path.join(export, '..', 'gitosis.conf')) autoinit_repos(config=cfg) 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, ) if htaccess.gen_htaccess_if_enabled(config=cfg): group.generate_group_list( config=cfg, path=os.path.join(generated, 'groups'), ) authorized_keys = util.getSSHAuthorizedKeysPath(config=cfg) ssh.writeAuthorizedKeys( path=authorized_keys, keydir=os.path.join(export, 'keydir'), ) def update_mirrors(cfg, git_dir): mirror.push_mirrors(cfg, git_dir) class Main(app.App):
def serve( cfg, user, command, ): if '\n' in command: raise CommandMayNotContainNewlineError() try: verb, args = command.split(None, 1) except ValueError: # all known "git-foo" commands take one argument; improve # if/when needed raise UnknownCommandError() if verb == 'git': try: subverb, args = args.split(None, 1) except ValueError: # all known "git foo" commands take one argument; improve # if/when needed raise UnknownCommandError() verb = '%s %s' % (verb, subverb) elif verb == 'cvs': try: args, server = args.split(None, 1) except: raise UnknownCommandError() if server != 'server': raise UnknownCommandError() path = path_from_args(args) newpath = path_for_write(cfg=cfg, user=user, path=path) if newpath is None: raise WriteAccessDenied() (topdir, repopath) = construct_path(newpath) # Put the repository and base path in the environment repos_dir = util.getRepositoryDir(cfg) fullpath = os.path.join(repos_dir, repopath) os.environ['GIT_CVSSERVER_BASE_PATH'] = repos_dir os.environ['GIT_CVSSERVER_ROOTS'] = fullpath # Put the user's information in the environment try: section = 'user %s' % user name = cfg.get(section, 'name') email = cfg.get(section, 'email') except: log.error('Missing name or email for user "%s"' % user) raise WriteAccessDenied() os.environ['GIT_AUTHOR_NAME'] = name os.environ['GIT_AUTHOR_EMAIL'] = email return 'cvs server' if (verb not in COMMANDS_WRITE and verb not in COMMANDS_READONLY): raise UnknownCommandError() path = path_from_args(args) # write access is always sufficient newpath = path_for_write( cfg=cfg, user=user, path=path) if newpath is None: # didn't have write access newpath = access.haveAccess( config=cfg, user=user, mode='readonly', path=path) if newpath is None: raise ReadAccessDenied() if verb in COMMANDS_WRITE: # didn't have write access and tried to write raise WriteAccessDenied() (topdir, repopath) = construct_path(newpath) fullpath = os.path.join(topdir, repopath) if not os.path.exists(fullpath): # it doesn't exist on the filesystem, but the configuration # refers to it, we're serving a write request, and the user is # authorized to do that: create the repository on the fly auto_init_repo(cfg,topdir,repopath) 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, ) htaccess.gen_htaccess_if_enabled( config=cfg, ) # put the verb back together with the new path newcmd = "%(verb)s '%(path)s'" % dict( verb=verb, path=fullpath, ) return newcmd
def serve( cfg, user, command, ): if '\n' in command: raise CommandMayNotContainNewlineError() try: verb, args = command.split(None, 1) except ValueError: # all known "git-foo" commands take one argument; improve # if/when needed raise UnknownCommandError() if verb == 'git': try: subverb, args = args.split(None, 1) except ValueError: # all known "git foo" commands take one argument; improve # if/when needed raise UnknownCommandError() verb = '%s %s' % (verb, subverb) if (verb not in COMMANDS_WRITE and verb not in COMMANDS_READONLY): raise UnknownCommandError() match = ALLOW_RE.match(args) if match is None: raise UnsafeArgumentsError() path = match.group('path') # write access is always sufficient newpath = access.haveAccess( config=cfg, user=user, mode='writable', path=path) if newpath is None: # didn't have write access; try once more with the popular # misspelling newpath = access.haveAccess( config=cfg, user=user, mode='writeable', path=path) if newpath is not None: log.warning( 'Repository %r config has typo "writeable", ' +'should be "writable"', path, ) if newpath is None: # didn't have write access newpath = access.haveAccess( config=cfg, user=user, mode='readonly', path=path) if newpath is None: raise ReadAccessDenied() if verb in COMMANDS_WRITE: # didn't have write access and tried to write raise WriteAccessDenied() (topdir, relpath) = newpath assert not relpath.endswith('.git'), \ 'git extension should have been stripped: %r' % relpath repopath = '%s.git' % relpath fullpath = os.path.join(topdir, repopath) if (not os.path.exists(fullpath) and verb in COMMANDS_WRITE): # it doesn't exist on the filesystem, but the configuration # refers to it, we're serving a write request, and the user is # authorized to do that: create the repository on the fly auto_init_repo(cfg,topdir,repopath) 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, ) htaccess.gen_htaccess_if_enabled( config=cfg, ) # put the verb back together with the new path newcmd = "%(verb)s '%(path)s'" % dict( verb=verb, path=fullpath, ) return newcmd