Skip to content

Commit 03bd0d6

Browse files
PhilMillergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 902f235 commit 03bd0d6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Documentation/git-cvsserver.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,21 @@ In `dbdriver` and `dbuser` you can use the following variables:
277277
If no name can be determined, the
278278
numeric uid is used.
279279

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+
280295
Eclipse CVS Client Notes
281296
------------------------
282297

git-cvsserver.perl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@
104104
my $usage =
105105
"Usage: git cvsserver [options] [pserver|server] [<directory> ...]\n".
106106
" --base-path <path> : Prepend to requested CVSROOT\n".
107+
" Can be read from GIT_CVSSERVER_BASE_PATH\n".
107108
" --strict-paths : Don't allow recursing into subdirectories\n".
108109
" --export-all : Don't check for gitcvs.enabled in config\n".
109110
" --version, -V : Print version information and exit\n".
110111
" --help, -h, -H : Print usage information and exit\n".
111112
"\n".
112113
"<directory> ... is a list of allowed directories. If no directories\n".
113114
"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";
115117

116118
my @opts = ( 'help|h|H', 'version|V',
117119
'base-path=s', 'strict-paths', 'export-all' );
@@ -148,6 +150,24 @@
148150
die "--export-all can only be used together with an explicit whitelist\n";
149151
}
150152

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+
151171
# if we are called with a pserver argument,
152172
# deal with the authentication cat before entering the
153173
# main loop

0 commit comments

Comments
 (0)