@matheusbsbs / matheus-bagliano / commits / 03bd0d601e
Fork 0

CVS Server: Support reading base and roots from environment

The Gitosis single-account Git/ssh hosting system runs git commands through git-shell after confirming that the connecting user is authorized to access the requested repository. This works well for upload-pack and receive-pack, which take a repository argument through git-shell. This doesn't work so well for `cvs server', which is passed through literally, with no arguments. Allowing arguments risks sneaking in `--export-all', so that restriction should be maintained. Despite that, passing a repository root is necessary for per-user access control by the hosting software, and passing a base path improves usability without weakening security. Thus, git-cvsserver needs to come up with these values at runtime by some other means. Since git-shell preserves the environment for other purposes, the environment can carry these arguments as well. Thus, modify git-cvsserver to read $GIT_CVSSERVER_{BASE_PATH,ROOT} in the absence of equivalent command line arguments. Signed-off-by: Phil Miller <mille121@illinois.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phil Miller committed Dec 30, 2009 at 13:35 UTC 03bd0d601ea842b2db5bd40a1f7f036989f9b517
2 files changed +36 -1
Documentation/git-cvsserver.txt
+15
@@ -277,6 +277,21 @@ In `dbdriver` and `dbuser` you can use the following variables:
277 If no name can be determined, the
278 numeric uid is used.
279
280 +ENVIRONMENT
281 +-----------
282 +
283 +These variables obviate the need for command-line options in some
284 +circumstances, allowing easier restricted usage through git-shell.
285 +
286 +GIT_CVSSERVER_BASE_PATH takes the place of the argument to --base-path.
287 +
288 +GIT_CVSSERVER_ROOT specifies a single-directory whitelist. The
289 +repository must still be configured to allow access through
290 +git-cvsserver, as described above.
291 +
292 +When these environment variables are set, the corresponding
293 +command-line arguments may not be used.
294 +
295 Eclipse CVS Client Notes
296 ------------------------
297
git-cvsserver.perl
+21 -1
@@ -104,6 +104,7 @@ $log->info("--------------- STARTING -----------------");
104 my $usage =
105 "Usage: git cvsserver [options] [pserver|server] [<directory> ...]\n".
106 " --base-path <path> : Prepend to requested CVSROOT\n".
107 + " Can be read from GIT_CVSSERVER_BASE_PATH\n".
108 " --strict-paths : Don't allow recursing into subdirectories\n".
109 " --export-all : Don't check for gitcvs.enabled in config\n".
110 " --version, -V : Print version information and exit\n".
@@ -111,7 +112,8 @@ my $usage =
112 "\n".
113 "<directory> ... is a list of allowed directories. If no directories\n".
114 "are given, all are allowed. This is an additional restriction, gitcvs\n".
114 - "access still needs to be enabled by the gitcvs.enabled config option.\n";
115 + "access still needs to be enabled by the gitcvs.enabled config option.\n".
116 + "Alternately, one directory may be specified in GIT_CVSSERVER_ROOT.\n";
117
118 my @opts = ( 'help|h|H', 'version|V',
119 'base-path=s', 'strict-paths', 'export-all' );
@@ -148,6 +150,24 @@ if ($state->{'export-all'} && !@{$state->{allowed_roots}}) {
150 die "--export-all can only be used together with an explicit whitelist\n";
151 }
152
153 +# Environment handling for running under git-shell
154 +if (exists $ENV{GIT_CVSSERVER_BASE_PATH}) {
155 + if ($state->{'base-path'}) {
156 + die "Cannot specify base path both ways.\n";
157 + }
158 + my $base_path = $ENV{GIT_CVSSERVER_BASE_PATH};
159 + $state->{'base-path'} = $base_path;
160 + $log->debug("Picked up base path '$base_path' from environment.\n");
161 +}
162 +if (exists $ENV{GIT_CVSSERVER_ROOT}) {
163 + if (@{$state->{allowed_roots}}) {
164 + die "Cannot specify roots both ways: @ARGV\n";
165 + }
166 + my $allowed_root = $ENV{GIT_CVSSERVER_ROOT};
167 + $state->{allowed_roots} = [ $allowed_root ];
168 + $log->debug("Picked up allowed root '$allowed_root' from environment.\n");
169 +}
170 +
171 # if we are called with a pserver argument,
172 # deal with the authentication cat before entering the
173 # main loop