diff options
author | Jason A. Donenfeld | 2014-01-16 23:21:54 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2014-01-16 23:21:54 +0100 |
commit | a431326e8fab8153905fbde036dd3c9fb4cc8eaa (patch) | |
tree | eaff3c6984a1c518c0180d5437853243ca6346a4 | |
parent | df00ab1096868b3cffe563c48de5572f78b50392 (diff) | |
download | cgit-a431326e8fab8153905fbde036dd3c9fb4cc8eaa.tar cgit-a431326e8fab8153905fbde036dd3c9fb4cc8eaa.tar.gz cgit-a431326e8fab8153905fbde036dd3c9fb4cc8eaa.zip |
auth: have cgit calculate login address
This way we're sure to use virtual root, or any other strangeness
encountered.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 5 | ||||
-rw-r--r-- | filter.c | 2 | ||||
-rw-r--r-- | filters/simple-authentication.lua | 7 | ||||
-rw-r--r-- | ui-shared.c | 8 | ||||
-rw-r--r-- | ui-shared.h | 1 |
6 files changed, 16 insertions, 10 deletions
@@ -611,7 +611,8 @@ static inline void open_auth_filter(struct cgit_context *ctx, const char *functi ctx->env.https ? ctx->env.https : "", ctx->qry.repo ? ctx->qry.repo : "", ctx->qry.page ? ctx->qry.page : "", - ctx->qry.url ? ctx->qry.url : ""); + ctx->qry.url ? ctx->qry.url : "", + cgit_loginurl()); } /* We intentionally keep this rather small, instead of looping and diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 682d8bb..8eafc4a 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -645,7 +645,7 @@ source filter:: filtered contents is expected on standard output. auth filter:: - The authentication filter receives 11 parameters: + The authentication filter receives 12 parameters: - filter action, explained below, which specifies which action the filter is called for - http cookie @@ -656,8 +656,9 @@ auth filter:: - cgit repo - cgit page - cgit url + - cgit login url When the filter action is "body", this filter must write to output the - HTML for displaying the login form, which POSTs to "/?p=login". When + HTML for displaying the login form, which POSTs to the login url. When the filter action is "authenticate-cookie", this filter must validate the http cookie and return a 0 if it is invalid or 1 if it is invalid, in the exit code / close function. If the filter action is @@ -417,7 +417,7 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) switch (filtertype) { case AUTH: - argument_count = 11; + argument_count = 12; break; case EMAIL: diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index 5c4f074..9291302 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -122,12 +122,7 @@ function filter_open(...) cgit["repo"] = select(9, ...) cgit["page"] = select(10, ...) cgit["url"] = select(11, ...) - - cgit["login"] = "" - for _ in cgit["url"]:gfind("/") do - cgit["login"] = cgit["login"] .. "../" - end - cgit["login"] = cgit["login"] .. "?p=login" + cgit["login"] = select(12, ...) end diff --git a/ui-shared.c b/ui-shared.c index 4f47c50..0838e18 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -73,6 +73,14 @@ const char *cgit_rooturl() return ctx.cfg.script_name; } +const char *cgit_loginurl() +{ + static const char *login_url = 0; + if (!login_url) + login_url = fmtalloc("%s?p=login", cgit_rooturl()); + return login_url; +} + char *cgit_repourl(const char *reponame) { if (ctx.cfg.virtual_root) diff --git a/ui-shared.h b/ui-shared.h index 5987e77..889c28f 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -4,6 +4,7 @@ extern const char *cgit_httpscheme(); extern const char *cgit_hosturl(); extern const char *cgit_rooturl(); +extern const char *cgit_loginurl(); extern char *cgit_repourl(const char *reponame); extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query); |