git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Bernhard R. Link" <brl+git@mail.brlink.eu>
To: Junio C Hamano <gitster@pobox.com>, Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH v5 1/5] gitweb: prepare git_get_projects_list for use outside 'forks'.
Date: Mon, 30 Jan 2012 12:44:47 +0100	[thread overview]
Message-ID: <20120130114447.GA9267@server.brlink.eu> (raw)
In-Reply-To: <20120130095252.GA6183@server.brlink.eu>

Use of the filter option of git_get_projects_list is currently
limited to forks. It hard codes removal of ".git" suffixes from
the filter and assumes the project belonging to the filter directory
was already validated to be visible in the project list.

To make it more generic move the .git suffix removal to the callers
and add an optional argument to denote visibility verification is
still needed.

If there is a projects list file (GITWEB_LIST) only projects from
this list are returned anyway, so no more checks needed.

If there is no projects list file and the caller requests strict
checking (GITWEB_STRICT_EXPORT), do not jump directly to the
given directory but instead do a normal search and filter the
results instead.

The only (hopefully non-existing) effect of GITWEB_STRICT_EXPORT
without GITWEB_LIST is to make sure no project can be viewed without
also be found starting from project root. git_get_projects_list without
this patch does not enforce this but all callers only call it with
a filter already checked this way. With this parameter a caller
can request this check if the filter cannot be checked this way.

Signed-off-by: Bernhard R. Link <brlink@debian.org>
---

Changes to v4:
	- split patch in smaller parts
	- move ".git" suffix removal from filters to forks specific code
          (if you want this as patch on top of the previous series, let me know)
	- improve the descriptions of all patches
---
 gitweb/gitweb.perl |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9cf7e71..acf1bae 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2829,10 +2829,9 @@ sub git_get_project_url_list {
 
 sub git_get_projects_list {
 	my $filter = shift || '';
+	my $paranoid = shift;
 	my @list;
 
-	$filter =~ s/\.git$//;
-
 	if (-d $projects_list) {
 		# search in directory
 		my $dir = $projects_list;
@@ -2841,7 +2840,7 @@ sub git_get_projects_list {
 		my $pfxlen = length("$dir");
 		my $pfxdepth = ($dir =~ tr!/!!);
 		# when filtering, search only given subdirectory
-		if ($filter) {
+		if ($filter and not $paranoid) {
 			$dir .= "/$filter";
 			$dir =~ s!/+$!!;
 		}
@@ -2866,6 +2865,10 @@ sub git_get_projects_list {
 				}
 
 				my $path = substr($File::Find::name, $pfxlen + 1);
+				# paranoidly only filter here
+				if ($paranoid && $filter && $path !~ m!^\Q$filter\E/!) {
+					next;
+				}
 				# we check related file in $projectroot
 				if (check_export_ok("$projectroot/$path")) {
 					push @list, { path => $path };
@@ -6007,7 +6010,7 @@ sub git_forks {
 		die_error(400, "Unknown order parameter");
 	}
 
-	my @list = git_get_projects_list($project);
+	my @list = git_get_projects_list($project =~ s/\.git$//r);
 	if (!@list) {
 		die_error(404, "No forks found");
 	}
@@ -6066,7 +6069,7 @@ sub git_summary {
 
 	if ($check_forks) {
 		# find forks of a project
-		@forklist = git_get_projects_list($project);
+		@forklist = git_get_projects_list($project =~ s/\.git$//r);
 		# filter out forks of forks
 		@forklist = filter_forks_from_projects_list(\@forklist)
 			if (@forklist);
-- 
1.7.8.3

  reply	other threads:[~2012-01-30 11:44 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-28 16:56 [PATCH v2 1/2] gitweb: add project_filter to limit project list to a subdirectory Bernhard R. Link
2012-01-28 16:57 ` [PATCH v2 2/2] gitweb: place links to parent directories in page header Bernhard R. Link
2012-01-28 22:54   ` Jakub Narebski
2012-01-28 22:45 ` [PATCH v2 1/2] gitweb: add project_filter to limit project list to a subdirectory Jakub Narebski
2012-01-29  1:22   ` [PATCH v3] " Bernhard R. Link
2012-01-29 12:54     ` Jakub Narebski
2012-01-29 16:06       ` [PATCH v4 1/2] " Bernhard R. Link
2012-01-29 16:13         ` [PATCH v4 2/2] gitweb: place links to parent directories in page header Bernhard R. Link
2012-01-29 16:46           ` Jakub Narebski
2012-01-29 16:41         ` [PATCH v4 1/2] gitweb: add project_filter to limit project list to a subdirectory Jakub Narebski
2012-01-29 21:06         ` Junio C Hamano
2012-01-29 23:06           ` Jakub Narebski
2012-01-30  9:52           ` Bernhard R. Link
2012-01-30 11:44             ` Bernhard R. Link [this message]
2012-01-30 13:42               ` [PATCH v5 1/5] gitweb: prepare git_get_projects_list for use outside 'forks' Jakub Narebski
2012-01-30 14:55                 ` [PATCH v5.5 " Bernhard R. Link
2012-01-30 15:40                   ` Jakub Narebski
2012-01-30 16:29                     ` Bernhard R. Link
2012-01-30 11:45             ` [PATCH v5 2/5] gitweb: add project_filter to limit project list to a subdirectory Bernhard R. Link
2012-01-30 15:57               ` Jakub Narebski
2012-01-30 20:03                 ` Bernhard R. Link
2012-01-30 20:05                   ` [PATCH 1/6] gitweb: move hard coded .git suffix out of git_get_projects_list Bernhard R. Link
2012-01-30 20:06                   ` [PATCH v6 2/6] gitweb: prepare git_get_projects_list for use outside 'forks' Bernhard R. Link
2012-01-30 20:07                   ` [PATCH v6 3/6] gitweb: add project_filter to limit project list to a subdirectory Bernhard R. Link
2012-01-30 20:09                   ` [PATCH v6 4/6] gitweb: limit links to alternate forms of project_list to active project_filter Bernhard R. Link
2012-01-30 20:09                   ` [PATCH v6 5/6] gitweb: show active project_filter in project_list page header Bernhard R. Link
2012-01-30 20:10                   ` [PATCH v6 6/6] gitweb: place links to parent directories in " Bernhard R. Link
2012-01-30 20:34                   ` [PATCH v5 2/5] gitweb: add project_filter to limit project list to a subdirectory Junio C Hamano
2012-01-30 20:48                     ` Jakub Narebski
2012-01-30 21:05                       ` Junio C Hamano
2012-01-30 21:08                       ` Junio C Hamano
2012-01-30 20:48                     ` Bernhard R. Link
2012-02-01 16:59                     ` Bernhard R. Link
2012-02-01 20:55                       ` Junio C Hamano
2012-01-30 11:47             ` [PATCH 3/5] gitweb: limit links to alternate forms of project_list to active project_filter Bernhard R. Link
2012-01-30 16:09               ` Jakub Narebski
2012-01-30 11:48             ` [PATCH v5 4/5] gitweb: show active project_filter in project_list page header Bernhard R. Link
2012-01-30 16:38               ` Jakub Narebski
2012-01-30 11:50             ` [PATCH v5 5/5] gitweb: place links to parent directories in " Bernhard R. Link
2012-01-30 17:10               ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120130114447.GA9267@server.brlink.eu \
    --to=brl+git@mail.brlink.eu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).