cgit

commit a431326e8fab8153905fbde036dd3c9fb4cc8eaa

Author: Jason A. Donenfeld <Jason@zx2c4.com>

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>

 cgit.c | 3 ++-
 cgitrc.5.txt | 5 +++--
 filter.c | 2 +-
 filters/simple-authentication.lua | 7 +------
 ui-shared.c | 8 ++++++++
 ui-shared.h | 1 +


diff --git a/cgit.c b/cgit.c
index be1265da6cb03ce99da6e1a68476164d660b10b9..994957f38a2b9116aed879fb4fcfb9461ac0f8e2 100644
--- a/cgit.c
+++ b/cgit.c
@@ -611,7 +611,8 @@ 		ctx->env.http_host ? ctx->env.http_host : "",
 		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 682d8bb46f2202b3df3b469350cdf76974f4ae3b..8eafc4a8ff4ff031d5b792236253b59ce013c890 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -645,7 +645,7 @@ 	file that is to be filtered is available on standard input and the
 	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 @@ 	  - http https flag
 	  - 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




diff --git a/filter.c b/filter.c
index a5e5e4b93ef6b25718bf18e7b1c2fe8d51a03098..5ee4e71db3e6b239142fe612d6fb8fafa1f49a80 100644
--- a/filter.c
+++ b/filter.c
@@ -417,7 +417,7 @@ 		colon = NULL;
 
 	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 5c4f074b8b1a6d84572aeeac3eb507f88aa2eca3..92913024d1c5d0cda8ae18dbb72fae8840279147 100644
--- a/filters/simple-authentication.lua
+++ b/filters/simple-authentication.lua
@@ -122,12 +122,7 @@ 	cgit = {}
 	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 4f47c507054b1d3c7ca854c0481fccd9cf9f5847..0838e18f3578bf08712f5e9a1830232584598555 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -73,6 +73,14 @@ 	else
 		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 5987e77cafb2cfce3f589a7c89ab3c425152a0f4..889c28fa565821ca27cb96eb218b8b576051232e 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);