{"thread":{"id":"2913","subject":"[PATCH] git-daemon --base-path","startedAt":"2005-12-23T01:27:40Z","lastAt":"2005-12-23T04:19:55Z","messageCount":2,"participants":["Petr Baudis","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13970","messageId":"20051223012739.29168.55858.stgit@machine.or.cz","threadId":"2913","inReplyTo":null,"subject":"[PATCH] git-daemon --base-path","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-12-23T01:27:40Z","receivedAt":"2005-12-23T01:27:40Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Tommi Virtanen expressed a wish on #git to be able to use short and elegant\ngit URLs by making git-daemon 'root' in a given directory. This patch\nimplements this, causing git-daemon to interpret all paths relative to\nthe given base path if any is given.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n Documentation/git-daemon.txt |   11 ++++++++++-\n daemon.c                     |   21 ++++++++++++++++++++-\n 2 files changed, 30 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt\nindex 2a8f371..ac67ac2 100644\n--- a/Documentation/git-daemon.txt\n+++ b/Documentation/git-daemon.txt\n@@ -8,7 +8,8 @@ git-daemon - A really simple server for \n SYNOPSIS\n --------\n 'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all]\n-             [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]\n+             [--timeout=n] [--init-timeout=n] [--strict-paths]\n+             [--base-path=path] [directory...]\n \n DESCRIPTION\n -----------\n@@ -35,6 +36,14 @@ OPTIONS\n \tgit-daemon will refuse to start when this option is enabled and no\n \twhitelist is specified.\n \n+--base-path::\n+\tRemap all the path requests as relative to the given path.\n+\tThis is sort of \"GIT root\" - if you run git-daemon with\n+\t'--base-path=/srv/git' on example.com, then if you later try to pull\n+\t'git://example.com/hello.git', `git-daemon` will interpret the path\n+\tas '/srv/git/hello.git'. Home directories (the '~login' notation)\n+\taccess is disabled.\n+\n --export-all::\n \tAllow pulling from all directories that look like GIT repositories\n \t(have the 'objects' and 'refs' subdirectories), even if they\ndiff --git a/daemon.c b/daemon.c\nindex 539f6e8..3bd1426 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -15,7 +15,8 @@ static int verbose;\n \n static const char daemon_usage[] =\n \"git-daemon [--verbose] [--syslog] [--inetd | --port=n] [--export-all]\\n\"\n-\"           [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]\";\n+\"           [--timeout=n] [--init-timeout=n] [--strict-paths]\\n\"\n+\"           [--base-path=path] [directory...]\";\n \n /* List of acceptable pathname prefixes */\n static char **ok_paths = NULL;\n@@ -24,6 +25,9 @@ static int strict_paths = 0;\n /* If this is set, git-daemon-export-ok is not required */\n static int export_all_trees = 0;\n \n+/* Take all paths relative to this one if non-NULL */\n+static char *base_path = NULL;\n+\n /* Timeout, and initial timeout */\n static unsigned int timeout = 0;\n static unsigned int init_timeout = 0;\n@@ -138,6 +142,17 @@ static char *path_ok(char *dir)\n \t\treturn NULL;\n \t}\n \n+\tif (base_path) {\n+\t\tstatic char rpath[PATH_MAX];\n+\t\tif (*dir != '/') {\n+\t\t\t/* Forbid possible base-path evasion using ~paths. */\n+\t\t\tlogerror(\"'%s': Non-absolute path denied (base-path active)\");\n+\t\t\treturn NULL;\n+\t\t}\n+\t\tsnprintf(rpath, PATH_MAX, \"%s%s\", base_path, dir);\n+\t\tdir = rpath;\n+\t}\n+\n \tpath = enter_repo(dir, strict_paths);\n \n \tif (!path) {\n@@ -639,6 +654,10 @@ int main(int argc, char **argv)\n \t\t\tstrict_paths = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strncmp(arg, \"--base-path=\", 12)) {\n+\t\t\tbase_path = arg+12;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(arg, \"--\")) {\n \t\t\tok_paths = &argv[i+1];\n \t\t\tbreak;\n"},{"id":"13971","messageId":"7vlkycfnro.fsf@assigned-by-dhcp.cox.net","threadId":"2913","inReplyTo":"20051223012739.29168.55858.stgit@machine.or.cz","subject":"Re: [PATCH] git-daemon --base-path","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-23T04:19:55Z","receivedAt":"2005-12-23T04:19:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> Tommi Virtanen expressed a wish on #git to be able to use short and elegant\n> git URLs by making git-daemon 'root' in a given directory. This patch\n> implements this, causing git-daemon to interpret all paths relative to\n> the given base path if any is given.\n\nThis is much nicer than chrooting or having a symlink hanging\nunder /.  Another possibility would be to have ~git/ a symlink\nto such directory and make it a whitelist -- then you do not\nneed this patch.  The URL would be \"git://ho.st/~git/xxx\" which\nis short-and-sweet.\n\n> +\t\tsnprintf(rpath, PATH_MAX, \"%s%s\", base_path, dir);\n> +\t\tdir = rpath;\n> +\t}\n\nWe probably would want to verify base_path exists and is without\nexcess trailing slash when parsing arguments, if we are going to\ndo this.\n"}]}