git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Make http-backend REMOTE_USER configurable
@ 2012-03-29 19:58 William Strecker-Kellogg
  2012-03-29 22:02 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: William Strecker-Kellogg @ 2012-03-29 19:58 UTC (permalink / raw)
  To: Git List; +Cc: William Strecker-Kellogg, spearce

The http-backend looks at $REMOTE_USER and sets $GIT_COMMITTER_NAME to
that for use in the hooks. At our site we have a third party
authentication module for our proxy (Shibboleth) which sets an alternative
environment variable that our backend sees instead of REMOTE USER.

This patch adds the config option http.remoteuser which changes what
environment variable is inspected by the http-backend code (it defaults
to REMOTE_USER).

Reported-by: Jason Smith <smithj4@bnl.gov>
Tested-by: William Strecker-Kellogg <willsk@bnl.gov>
Signed-off-by: William Strecker-Kellogg <willsk@bnl.gov>
---

I do not know if anyone else may find this useful, but FWIW, this works
for us. It may even be a good idea to add the ability to overwrite other
default CGI environment variables, although I can't think of any other
ones at the moment.


 Documentation/git-http-backend.txt |   14 ++++++++++----
 http-backend.c                     |   13 +++++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index f4e0741..b320a45 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -42,6 +42,10 @@ http.getanyfile::
 	It is enabled by default, but a repository can disable it
 	by setting this configuration item to `false`.
 
+http.remoteuser::
+	This setting, if present, changes what environment variable is inspected
+	to determine the remote user (the default is "REMOTE_USER").
+
 http.uploadpack::
 	This serves 'git fetch-pack' and 'git ls-remote' clients.
 	It is enabled by default, but a repository can disable it
@@ -175,10 +179,12 @@ The GIT_HTTP_EXPORT_ALL environmental variable may be passed to
 'git-http-backend' to bypass the check for the "git-daemon-export-ok"
 file in each repository before allowing export of that repository.
 
-The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
-GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
-ensuring that any reflogs created by 'git-receive-pack' contain some
-identifying information of the remote user who performed the push.
+The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' (or
+if http.remoteuser is present it sets it to $\{http.remoteuser\})
+and GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
+ensuring that any reflogs created by 'git-receive-pack' contain
+some identifying information of the remote user who performed the
+push.
 
 All CGI environment variables are available to each of the hooks
 invoked by the 'git-receive-pack'.
diff --git a/http-backend.c b/http-backend.c
index 869d515..69756f0 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -11,6 +11,7 @@
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
 static const char last_modified[] = "Last-Modified";
+static char *remoteuser = "REMOTE_USER";
 static int getanyfile = 1;
 
 static struct string_list *query_params;
@@ -225,6 +226,14 @@ static int http_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if(!strcmp(var, "http.remoteuser")) {
+		char *tmp;
+		if(git_config_string(&tmp, var, value) == 0) {
+			remoteuser = tmp;
+		}
+		return 0;
+	}
+
 	if (!prefixcmp(var, "http.")) {
 		int i;
 
@@ -261,7 +270,7 @@ static struct rpc_service *select_service(const char *name)
 		forbidden("Unsupported service: '%s'", name);
 
 	if (svc->enabled < 0) {
-		const char *user = getenv("REMOTE_USER");
+		const char *user = getenv(remoteuser);
 		svc->enabled = (user && *user) ? 1 : 0;
 	}
 	if (!svc->enabled)
@@ -315,7 +324,7 @@ done:
 static void run_service(const char **argv)
 {
 	const char *encoding = getenv("HTTP_CONTENT_ENCODING");
-	const char *user = getenv("REMOTE_USER");
+	const char *user = getenv(remoteuser);
 	const char *host = getenv("REMOTE_ADDR");
 	char *env[3];
 	struct strbuf buf = STRBUF_INIT;
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-03-30 16:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-29 19:58 [PATCH] Make http-backend REMOTE_USER configurable William Strecker-Kellogg
2012-03-29 22:02 ` Junio C Hamano
2012-03-29 22:22   ` Jeff King
2012-03-29 22:26     ` Jeff King
2012-03-30  1:52       ` Junio C Hamano
2012-03-30  3:24         ` William Strecker-Kellogg
2012-03-30  7:01         ` Jeff King
2012-03-30 16:13           ` Junio C Hamano

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).