This provides a mechanism for cgit to query an external program for repository
authorisation, e.g. gitolite. An additional config variable 'authorization'
contains the path and name of the executable to use.

Signed-off-by: Valentin Haenel <[email protected]>
---
 cgit.c       |   22 ++++++++++++++++++++++
 cgit.h       |    1 +
 cgitrc.5.txt |    6 ++++++
 3 files changed, 29 insertions(+)

diff --git a/cgit.c b/cgit.c
index 92e35ae958..d62c1a748d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -128,6 +128,8 @@ void config_cb(const char *name, const char *value)
                ctx.cfg.readme = xstrdup(value);
        else if (!strcmp(name, "user-envvar"))
                ctx.cfg.user_envvar = xstrdup(value);
+       else if (!strcmp(name, "authz-exec"))
+               ctx.cfg.authz_exec = xstrdup(value);
        else if (!strcmp(name, "root-title"))
                ctx.cfg.root_title = xstrdup(value);
        else if (!strcmp(name, "root-desc"))
@@ -381,6 +383,7 @@ static void prepare_context(struct cgit_context *ctx)
        ctx->cfg.summary_tags = 10;
        ctx->cfg.max_atom_items = 10;
        ctx->cfg.ssdiff = 0;
+       ctx->cfg.authz_exec = NULL;
        ctx->cfg.user_envvar = "REMOTE_USER";
        ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG"));
        ctx->env.http_host = xstrdupn(getenv("HTTP_HOST"));
@@ -554,6 +557,25 @@ static void process_request(void *cbdata)
                return;
        }
 
+       /* Here we do the authorization check.
+        *
+        * TODO figure out if this is the correct place to do the check
+        *
+        */
+       if (ctx->cfg.authz_exec && ctx->repo &&
+                                       system(fmt("%s %s %s",
+                                       ctx->cfg.authz_exec,
+                                       ctx->repo->name,
+                                       ctx->env.remote_user)) != 0) {
+               cgit_print_http_headers(ctx);
+               cgit_print_docstart(ctx);
+               cgit_print_pageheader(ctx);
+               cgit_print_error(fmt("Authorization failed for repo: '%s' and 
user: '%s'",
+                                       ctx->repo->name, ctx->env.remote_user));
+               cgit_print_docend();
+               return;
+       }
+
        if (ctx->repo && prepare_repo_cmd(ctx))
                return;
 
diff --git a/cgit.h b/cgit.h
index 016baa8e7d..14fc2fb777 100644
--- a/cgit.h
+++ b/cgit.h
@@ -167,6 +167,7 @@ struct cgit_query {
 struct cgit_config {
        char *agefile;
        char *user_envvar;
+       char *authz_exec;
        char *cache_root;
        char *clone_prefix;
        char *clone_url;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 7a479d1d84..79625cf055 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -40,6 +40,12 @@ agefile::
        function in libgit. Recommended timestamp-format is "yyyy-mm-dd
        hh:mm:ss". Default value: "info/web/last-modified".
 
+authorization::
+       Specifies a path to authorization executable. The executable must take 
two
+       arguments: "<repository> <user> [<permissions>]". The permission is the
+       type of permission we wish to check for, e.g. "R" or "RW" or "RW+". 
Default
+       value: none.
+
 cache-root::
        Path used to store the cgit cache entries. Default value:
        "/var/cache/cgit". See also: "MACRO EXPANSION".
-- 
1.7.9.5


_______________________________________________
cgit mailing list
[email protected]
http://hjemli.net/mailman/listinfo/cgit

Reply via email to