{"thread":{"id":"21593","subject":"[PATCH] (to improve gitosis support) CVS Server: Support reading base and roots from environment","startedAt":"2009-11-12T17:25:36Z","lastAt":"2009-11-18T04:11:58Z","messageCount":2,"participants":["Phil Miller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"127463","messageId":"81f018ac0911120925w848594dt276735955681e8f@mail.gmail.com","threadId":"21593","inReplyTo":null,"subject":"[PATCH] (to improve gitosis support) CVS Server: Support reading base and roots from environment","fromName":"Phil Miller","fromEmail":"mille121@illinois.edu","sentAt":"2009-11-12T17:25:36Z","receivedAt":"2009-11-12T17:25:36Z","isPatch":true,"sender":{"key":"mille121@illinois.edu","avatar":"https://avatars.githubusercontent.com/u/126464?v=4"},"body":"The Gitosis single-account Git/ssh hosting system runs git commands\nthrough git-shell after confirming that the connecting user is\nauthorized to access the requested repository. This works well for\nupload-pack and receive-pack, which take a repository argument through\ngit-shell. This doesn't work so well for `cvs server', which is passed\nthrough literally, with no arguments. Allowing arguments risks\nsneaking in `--export-all', so that restriction should be maintained.\n\nDespite that, passing a list of repository roots is necessary for\nper-user access control by the hosting software, and passing a base\npath improves usability without weakening security. Thus,\ngit-cvsserver needs to come up with these values at runtime by some\nother means. Since git-shell preserves the environment for other\npurposes, the environment can carry these arguments as well.\n\nThus, modify git-cvsserver to read $GIT_CVSSERVER_{BASE_PATH,ROOTS} in\nthe absence of equivalent command line arguments.\n\nSigned-off-by: Phil Miller <mille121@illinois.edu>\n\n\nFrom f5c911ab8d7f17d2676fc520539f0e87f4cfe015 Mon Sep 17 00:00:00 2001\nFrom: Phil Miller <mille121@illinois.edu>\nDate: Wed, 14 Oct 2009 23:20:09 -0500\nSubject: [PATCH] CVS Server: Support reading base and roots from environment\n\nThe Gitosis single-account Git/ssh hosting system runs git commands\nthrough git-shell after confirming that the connecting user is\nauthorized to access the requested repository. This works well for\nupload-pack and receive-pack, which take a repository argument through\ngit-shell. This doesn't work so well for `cvs server', which is passed\nthrough literally, with no arguments. Allowing arguments risks\nsneaking in `--export-all', so that restriction should be maintained.\n\nDespite that, passing a list of repository roots is necessary for\nper-user access control by the hosting software, and passing a base\npath improves usability without weakening security. Thus,\ngit-cvsserver needs to come up with these values at runtime by some\nother means. Since git-shell preserves the environment for other\npurposes, the environment can carry these arguments as well.\n\nThus, modify git-cvsserver to read $GIT_CVSSERVER_{BASE_PATH,ROOTS} in\nthe absence of equivalent command line arguments.\n\nSigned-off-by: Phil Miller <mille121@illinois.edu>\n---\n git-cvsserver.perl |   21 ++++++++++++++++++++-\n 1 files changed, 20 insertions(+), 1 deletions(-)\n\ndiff --git a/git-cvsserver.perl b/git-cvsserver.perl\nindex 6dc45f5..9e58d2a 100755\n--- a/git-cvsserver.perl\n+++ b/git-cvsserver.perl\n@@ -104,6 +104,7 @@ $log->info(\"--------------- STARTING -----------------\");\n my $usage =\n     \"Usage: git cvsserver [options] [pserver|server] [<directory> ...]\\n\".\n     \"    --base-path <path>  : Prepend to requested CVSROOT\\n\".\n+    \"                          Can be read from GIT_CVSSERVER_BASE_PATH\\n\".\n     \"    --strict-paths      : Don't allow recursing into subdirectories\\n\".\n     \"    --export-all        : Don't check for gitcvs.enabled in config\\n\".\n     \"    --version, -V       : Print version information and exit\\n\".\n@@ -111,7 +112,8 @@ my $usage =\n     \"\\n\".\n     \"<directory> ... is a list of allowed directories. If no directories\\n\".\n     \"are given, all are allowed. This is an additional restriction, gitcvs\\n\".\n-    \"access still needs to be enabled by the gitcvs.enabled config option.\\n\";\n+    \"access still needs to be enabled by the gitcvs.enabled config option.\\n\".\n+    \"Alternately, these directories may be specified in GIT_CVSSERVER_ROOTS.\\n\";\n \n my @opts = ( 'help|h|H', 'version|V',\n \t     'base-path=s', 'strict-paths', 'export-all' );\n@@ -148,6 +150,23 @@ if ($state->{'export-all'} && !@{$state->{allowed_roots}}) {\n     die \"--export-all can only be used together with an explicit whitelist\\n\";\n }\n \n+# Environment handling for running under git-shell\n+if ($ENV{GIT_CVSSERVER_BASE_PATH}) {\n+    if ($state->{'base-path'}) {\n+\tdie \"Cannot specify base path both ways.\\n\";\n+    }\n+    my $base_path = $ENV{GIT_CVSSERVER_BASE_PATH};\n+    $state->{'base-path'} = $base_path;\n+    $log->debug(\"Picked up base path '$base_path' from environment.\\n\");\n+}\n+if ($ENV{GIT_CVSSERVER_ROOTS}) {\n+    if (@{$state->{allowed_roots}}) {\n+\tdie \"Cannot specify roots both ways: @ARGV\\n\";\n+    }\n+    my @allowed_root = split(',', $ENV{GIT_CVSSERVER_ROOTS});\n+    $state->{allowed_roots} = [ @allowed_root ];\n+}\n+\n # if we are called with a pserver argument,\n # deal with the authentication cat before entering the\n # main loop\n-- \n1.6.5.2.411.gf7c0f.dirty\n\n"},{"id":"127809","messageId":"81f018ac0911172011la6948cfk8b5e95e6d8f796e@mail.gmail.com","threadId":"21593","inReplyTo":"81f018ac0911120925w848594dt276735955681e8f@mail.gmail.com","subject":"Re: [PATCH] (to improve gitosis support) CVS Server: Support reading base and roots from environment","fromName":"Phil Miller","fromEmail":"mille121@illinois.edu","sentAt":"2009-11-18T04:11:58Z","receivedAt":"2009-11-18T04:11:58Z","isPatch":true,"sender":{"key":"mille121@illinois.edu","avatar":"https://avatars.githubusercontent.com/u/126464?v=4"},"body":"I've seen no response or comment on this since sending it in. Does it\nneed revision of some sort? Did it just get lost in the shuffle? I'll\nbe happy to do the legwork to get this integrated, so that I don't\nhave to carry it in a private git tree.\n\nPhil\n\nOn Thu, Nov 12, 2009 at 11:25, Phil Miller <mille121@illinois.edu> wrote:\n> The Gitosis single-account Git/ssh hosting system runs git commands\n> through git-shell after confirming that the connecting user is\n> authorized to access the requested repository. This works well for\n> upload-pack and receive-pack, which take a repository argument through\n> git-shell. This doesn't work so well for `cvs server', which is passed\n> through literally, with no arguments. Allowing arguments risks\n> sneaking in `--export-all', so that restriction should be maintained.\n>\n> Despite that, passing a list of repository roots is necessary for\n> per-user access control by the hosting software, and passing a base\n> path improves usability without weakening security. Thus,\n> git-cvsserver needs to come up with these values at runtime by some\n> other means. Since git-shell preserves the environment for other\n> purposes, the environment can carry these arguments as well.\n>\n> Thus, modify git-cvsserver to read $GIT_CVSSERVER_{BASE_PATH,ROOTS} in\n> the absence of equivalent command line arguments.\n>\n> Signed-off-by: Phil Miller <mille121@illinois.edu>\n>\n"}]}