git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: John 'Warthog9' Hawley <warthog9@kernel.org>,
	admin@repo.or.cz, Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH 2/5] gitweb: Check permissions first in git_search
Date: Wed, 22 Jun 2011 17:28:52 +0200	[thread overview]
Message-ID: <1308756535-29701-3-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1308756535-29701-1-git-send-email-jnareb@gmail.com>

Check first if relevant features: 'search', 'pickaxe', 'grep', as
appropriate, are enabled before doing anything else in git_search.
This should make git_search code more clear.

While at it, expand a bit error message (e.g. 'Pickaxe' ->
'Pickaxe search').

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index fd93d45..32e50b4 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -7094,7 +7094,23 @@ sub git_history {
 }
 
 sub git_search {
-	gitweb_check_feature('search') or die_error(403, "Search is disabled");
+	$searchtype ||= 'commit';
+
+	# check if appropriate features are enabled
+	gitweb_check_feature('search')
+		or die_error(403, "Search is disabled");
+	if ($searchtype eq 'pickaxe') {
+		# pickaxe may take all resources of your box and run for several minutes
+		# with every query - so decide by yourself how public you make this feature
+		gitweb_check_feature('pickaxe')
+			or die_error(403, "Pickaxe search is disabled");
+	}
+	if ($searchtype eq 'grep') {
+		# grep search might be potentially CPU-intensive, too
+		gitweb_check_feature('grep')
+			or die_error(403, "Grep search is disabled");
+	}
+
 	if (!defined $searchtext) {
 		die_error(400, "Text field is empty");
 	}
@@ -7109,18 +7125,6 @@ sub git_search {
 		$page = 0;
 	}
 
-	$searchtype ||= 'commit';
-	if ($searchtype eq 'pickaxe') {
-		# pickaxe may take all resources of your box and run for several minutes
-		# with every query - so decide by yourself how public you make this feature
-		gitweb_check_feature('pickaxe')
-		    or die_error(403, "Pickaxe is disabled");
-	}
-	if ($searchtype eq 'grep') {
-		gitweb_check_feature('grep')
-		    or die_error(403, "Grep is disabled");
-	}
-
 	git_header_html();
 
 	if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
-- 
1.7.5

  parent reply	other threads:[~2011-06-22 15:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-22 15:28 [PATCH 0/5] gitweb: Improve search code Jakub Narebski
2011-06-22 15:28 ` [PATCHv3 1/5] gitweb: 'pickaxe' and 'grep' features requires 'search' to be enabled Jakub Narebski
2011-06-22 15:28 ` Jakub Narebski [this message]
2011-06-22 15:28 ` [PATCH 3/5] gitweb: Split body of git_search into subroutines Jakub Narebski
2011-06-22 15:28 ` [PATCH 4/5] gitweb: Clean up code in git_search_* subroutines Jakub Narebski
2011-06-22 15:28 ` [PATCH 5/5] gitweb: Make git_search_* subroutines render whole pages Jakub Narebski
2011-06-22 17:10 ` [PATCH 0/5] gitweb: Improve search code Phil Hord
2011-06-22 18:00   ` Jakub Narebski
2011-06-22 19:24     ` Phil Hord
2011-06-22 18:55 ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=1308756535-29701-3-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=admin@repo.or.cz \
    --cc=git@vger.kernel.org \
    --cc=warthog9@kernel.org \
    /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.
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 NNTP newsgroup(s).