@matheusbsbs / matheus-bagliano / commits / b21c31c9a5
Fork 0

git-daemon --base-path

Tommi Virtanen expressed a wish on #git to be able to use short and elegant git URLs by making git-daemon 'root' in a given directory. This patch implements this, causing git-daemon to interpret all paths relative to the given base path if any is given. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Petr Baudis committed Dec 23, 2005 at 02:27 UTC b21c31c9a5edfd90d6f85481517f979352da4eed
2 files changed +30 -2
Documentation/git-daemon.txt
+10 -1
@@ -9,7 +9,8 @@ SYNOPSIS
9 --------
10 [verse]
11 'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all]
12 - [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]
12 + [--timeout=n] [--init-timeout=n] [--strict-paths]
13 + [--base-path=path] [directory...]
14
15 DESCRIPTION
16 -----------
@@ -36,6 +37,14 @@ OPTIONS
37 git-daemon will refuse to start when this option is enabled and no
38 whitelist is specified.
39
40 +--base-path::
41 + Remap all the path requests as relative to the given path.
42 + This is sort of "GIT root" - if you run git-daemon with
43 + '--base-path=/srv/git' on example.com, then if you later try to pull
44 + 'git://example.com/hello.git', `git-daemon` will interpret the path
45 + as '/srv/git/hello.git'. Home directories (the '~login' notation)
46 + access is disabled.
47 +
48 --export-all::
49 Allow pulling from all directories that look like GIT repositories
50 (have the 'objects' and 'refs' subdirectories), even if they
daemon.c
+20 -1
@@ -15,7 +15,8 @@ static int verbose;
15
16 static const char daemon_usage[] =
17 "git-daemon [--verbose] [--syslog] [--inetd | --port=n] [--export-all]\n"
18 -" [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]";
18 +" [--timeout=n] [--init-timeout=n] [--strict-paths]\n"
19 +" [--base-path=path] [directory...]";
20
21 /* List of acceptable pathname prefixes */
22 static char **ok_paths = NULL;
@@ -24,6 +25,9 @@ static int strict_paths = 0;
25 /* If this is set, git-daemon-export-ok is not required */
26 static int export_all_trees = 0;
27
28 +/* Take all paths relative to this one if non-NULL */
29 +static char *base_path = NULL;
30 +
31 /* Timeout, and initial timeout */
32 static unsigned int timeout = 0;
33 static unsigned int init_timeout = 0;
@@ -138,6 +142,17 @@ static char *path_ok(char *dir)
142 return NULL;
143 }
144
145 + if (base_path) {
146 + static char rpath[PATH_MAX];
147 + if (*dir != '/') {
148 + /* Forbid possible base-path evasion using ~paths. */
149 + logerror("'%s': Non-absolute path denied (base-path active)");
150 + return NULL;
151 + }
152 + snprintf(rpath, PATH_MAX, "%s%s", base_path, dir);
153 + dir = rpath;
154 + }
155 +
156 path = enter_repo(dir, strict_paths);
157
158 if (!path) {
@@ -639,6 +654,10 @@ int main(int argc, char **argv)
654 strict_paths = 1;
655 continue;
656 }
657 + if (!strncmp(arg, "--base-path=", 12)) {
658 + base_path = arg+12;
659 + continue;
660 + }
661 if (!strcmp(arg, "--")) {
662 ok_paths = &argv[i+1];
663 break;