aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld2018-11-21 03:16:11 +0100
committerJason A. Donenfeld2018-11-25 06:01:34 +0100
commit898b9e19e0eacd67456ddcc91ff173055e1c0e99 (patch)
tree3f056db3a9d329b43a0fa7c567ad54672ace5bfb
parenta22855747e97e55a7b7a2622fe671b8ca9af0981 (diff)
downloadcgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.tar.gz
cgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.tar.bz2
cgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.zip
auth-filter: pass url with query string attached
Otherwise redirections come out wrong. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--cgit.c2
-rw-r--r--ui-shared.c37
-rw-r--r--ui-shared.h1
3 files changed, 37 insertions, 3 deletions
diff --git a/cgit.c b/cgit.c
index 6301b87..2f07e6d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -645,7 +645,7 @@ static inline void open_auth_filter(const char *function)
645 ctx.env.https ? ctx.env.https : "", 645 ctx.env.https ? ctx.env.https : "",
646 ctx.qry.repo ? ctx.qry.repo : "", 646 ctx.qry.repo ? ctx.qry.repo : "",
647 ctx.qry.page ? ctx.qry.page : "", 647 ctx.qry.page ? ctx.qry.page : "",
648 ctx.qry.url ? ctx.qry.url : "", 648 cgit_currentfullurl(),
649 cgit_loginurl()); 649 cgit_loginurl());
650} 650}
651 651
diff --git a/ui-shared.c b/ui-shared.c
index b53c56d..7a4c726 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -68,15 +68,48 @@ char *cgit_hosturl(void)
68char *cgit_currenturl(void) 68char *cgit_currenturl(void)
69{ 69{
70 const char *root = cgit_rooturl(); 70 const char *root = cgit_rooturl();
71 size_t len = strlen(root);
72 71
73 if (!ctx.qry.url) 72 if (!ctx.qry.url)
74 return xstrdup(root); 73 return xstrdup(root);
75 if (len && root[len - 1] == '/') 74 if (root[0] && root[strlen(root) - 1] == '/')
76 return fmtalloc("%s%s", root, ctx.qry.url); 75 return fmtalloc("%s%s", root, ctx.qry.url);
77 return fmtalloc("%s/%s", root, ctx.qry.url); 76 return fmtalloc("%s/%s", root, ctx.qry.url);
78} 77}
79 78
79char *cgit_currentfullurl(void)
80{
81 const char *root = cgit_rooturl();
82 const char *orig_query = ctx.env.query_string ? ctx.env.query_string : "";
83 size_t len = strlen(orig_query);
84 char *query = xmalloc(len + 2), *start_url, *ret;
85
86 /* Remove all url=... parts from query string */
87 memcpy(query + 1, orig_query, len + 1);
88 query[0] = '?';
89 start_url = query;
90 while ((start_url = strstr(start_url, "url=")) != NULL) {
91 if (start_url[-1] == '?' || start_url[-1] == '&') {
92 const char *end_url = strchr(start_url, '&');
93 if (end_url)
94 memmove(start_url, end_url + 1, strlen(end_url));
95 else
96 start_url[0] = '\0';
97 } else
98 ++start_url;
99 }
100 if (!query[1])
101 query[0] = '\0';
102
103 if (!ctx.qry.url)
104 ret = fmtalloc("%s%s", root, query);
105 else if (root[0] && root[strlen(root) - 1] == '/')
106 ret = fmtalloc("%s%s%s", root, ctx.qry.url, query);
107 else
108 ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query);
109 free(query);
110 return ret;
111}
112
80const char *cgit_rooturl(void) 113const char *cgit_rooturl(void)
81{ 114{
82 if (ctx.cfg.virtual_root) 115 if (ctx.cfg.virtual_root)
diff --git a/ui-shared.h b/ui-shared.h
index 4d5978b..6964873 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -5,6 +5,7 @@ extern const char *cgit_httpscheme(void);
5extern char *cgit_hosturl(void); 5extern char *cgit_hosturl(void);
6extern const char *cgit_rooturl(void); 6extern const char *cgit_rooturl(void);
7extern char *cgit_currenturl(void); 7extern char *cgit_currenturl(void);
8extern char *cgit_currentfullurl(void);
8extern const char *cgit_loginurl(void); 9extern const char *cgit_loginurl(void);
9extern char *cgit_repourl(const char *reponame); 10extern char *cgit_repourl(const char *reponame);
10extern char *cgit_fileurl(const char *reponame, const char *pagename, 11extern char *cgit_fileurl(const char *reponame, const char *pagename,