| |
| |
| |
| """ |
| (c) 2014-2018 - Copyright Red Hat Inc |
| |
| Authors: |
| Patrick Uiterwijk <puiterwijk@redhat.com> |
| |
| """ |
| |
| from __future__ import unicode_literals, print_function |
| |
| import subprocess |
| import sys |
| import os |
| |
| |
| |
| if "PAGURE_CONFIG" not in os.environ and os.path.exists( |
| "/etc/pagure/pagure.cfg" |
| ): |
| os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg" |
| |
| |
| import pagure |
| import pagure.lib |
| from pagure.utils import is_repo_user |
| from pagure.config import config as pagure_config |
| |
| |
| |
| if len(sys.argv) != 2: |
| print("Invalid call, too few arguments", file=sys.stderr) |
| sys.exit(1) |
| remoteuser = sys.argv[1] |
| |
| args = os.environ["SSH_ORIGINAL_COMMAND"].split(" ") |
| |
| if len(args) != 2: |
| print("Invalid call, too few inner arguments", file=sys.stderr) |
| sys.exit(1) |
| |
| |
| cmd = args[0] |
| path = args[1] |
| if cmd not in ("git-receive-pack", "git-upload-pack"): |
| print("Invalid call, invalid operation", file=sys.stderr) |
| sys.exit(1) |
| |
| |
| if path[0] != "'" or path[-1] != "'": |
| print("Invalid call: invalid path", file=sys.stderr) |
| sys.exit(1) |
| path = path[1:-1] |
| |
| if os.path.isabs(path): |
| print("Non-full path expected, not %s" % path, file=sys.stderr) |
| sys.exit(1) |
| |
| if not path.endswith(".git"): |
| path = path + ".git" |
| |
| session = pagure.lib.create_session(pagure_config["DB_URL"]) |
| if not session: |
| raise Exception("Unable to initialize db session") |
| |
| gitdir = os.path.join(pagure_config["GIT_FOLDER"], path) |
| (repotype, username, namespace, repo) = pagure.lib.git.get_repo_info_from_path( |
| gitdir, hide_notfound=True |
| ) |
| |
| if repo is None: |
| print("Repo not found", file=sys.stderr) |
| sys.exit(1) |
| |
| project = pagure.lib.get_authorized_project( |
| session, repo, user=username, namespace=namespace, asuser=remoteuser |
| ) |
| |
| if not project: |
| print("Repo not found", file=sys.stderr) |
| sys.exit(1) |
| |
| if repotype != "main" and not is_repo_user(project, remoteuser): |
| print("Repo not found", file=sys.stderr) |
| sys.exit(1) |
| |
| |
| |
| |
| |
| os.execvp(cmd, [cmd, gitdir]) |