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.gz cgit-a431326e8fab8153905fbde036dd3c9fb4cc8eaa.tar.bz2 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 | |||
611 | ctx->env.https ? ctx->env.https : "", | 611 | ctx->env.https ? ctx->env.https : "", |
612 | ctx->qry.repo ? ctx->qry.repo : "", | 612 | ctx->qry.repo ? ctx->qry.repo : "", |
613 | ctx->qry.page ? ctx->qry.page : "", | 613 | ctx->qry.page ? ctx->qry.page : "", |
614 | ctx->qry.url ? ctx->qry.url : ""); | 614 | ctx->qry.url ? ctx->qry.url : "", |
615 | cgit_loginurl()); | ||
615 | } | 616 | } |
616 | 617 | ||
617 | /* We intentionally keep this rather small, instead of looping and | 618 | /* 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:: | |||
645 | filtered contents is expected on standard output. | 645 | filtered contents is expected on standard output. |
646 | 646 | ||
647 | auth filter:: | 647 | auth filter:: |
648 | The authentication filter receives 11 parameters: | 648 | The authentication filter receives 12 parameters: |
649 | - filter action, explained below, which specifies which action the | 649 | - filter action, explained below, which specifies which action the |
650 | filter is called for | 650 | filter is called for |
651 | - http cookie | 651 | - http cookie |
@@ -656,8 +656,9 @@ auth filter:: | |||
656 | - cgit repo | 656 | - cgit repo |
657 | - cgit page | 657 | - cgit page |
658 | - cgit url | 658 | - cgit url |
659 | - cgit login url | ||
659 | When the filter action is "body", this filter must write to output the | 660 | When the filter action is "body", this filter must write to output the |
660 | HTML for displaying the login form, which POSTs to "/?p=login". When | 661 | HTML for displaying the login form, which POSTs to the login url. When |
661 | the filter action is "authenticate-cookie", this filter must validate | 662 | the filter action is "authenticate-cookie", this filter must validate |
662 | the http cookie and return a 0 if it is invalid or 1 if it is invalid, | 663 | the http cookie and return a 0 if it is invalid or 1 if it is invalid, |
663 | in the exit code / close function. If the filter action is | 664 | 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) | |||
417 | 417 | ||
418 | switch (filtertype) { | 418 | switch (filtertype) { |
419 | case AUTH: | 419 | case AUTH: |
420 | argument_count = 11; | 420 | argument_count = 12; |
421 | break; | 421 | break; |
422 | 422 | ||
423 | case EMAIL: | 423 | 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(...) | |||
122 | cgit["repo"] = select(9, ...) | 122 | cgit["repo"] = select(9, ...) |
123 | cgit["page"] = select(10, ...) | 123 | cgit["page"] = select(10, ...) |
124 | cgit["url"] = select(11, ...) | 124 | cgit["url"] = select(11, ...) |
125 | 125 | cgit["login"] = select(12, ...) | |
126 | cgit["login"] = "" | ||
127 | for _ in cgit["url"]:gfind("/") do | ||
128 | cgit["login"] = cgit["login"] .. "../" | ||
129 | end | ||
130 | cgit["login"] = cgit["login"] .. "?p=login" | ||
131 | 126 | ||
132 | end | 127 | end |
133 | 128 | ||
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() | |||
73 | return ctx.cfg.script_name; | 73 | return ctx.cfg.script_name; |
74 | } | 74 | } |
75 | 75 | ||
76 | const char *cgit_loginurl() | ||
77 | { | ||
78 | static const char *login_url = 0; | ||
79 | if (!login_url) | ||
80 | login_url = fmtalloc("%s?p=login", cgit_rooturl()); | ||
81 | return login_url; | ||
82 | } | ||
83 | |||
76 | char *cgit_repourl(const char *reponame) | 84 | char *cgit_repourl(const char *reponame) |
77 | { | 85 | { |
78 | if (ctx.cfg.virtual_root) | 86 | 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 @@ | |||
4 | extern const char *cgit_httpscheme(); | 4 | extern const char *cgit_httpscheme(); |
5 | extern const char *cgit_hosturl(); | 5 | extern const char *cgit_hosturl(); |
6 | extern const char *cgit_rooturl(); | 6 | extern const char *cgit_rooturl(); |
7 | extern const char *cgit_loginurl(); | ||
7 | extern char *cgit_repourl(const char *reponame); | 8 | extern char *cgit_repourl(const char *reponame); |
8 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 9 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
9 | const char *filename, const char *query); | 10 | const char *filename, const char *query); |