git-daemon support for user-relative paths.
PATCH 4/4 git-daemon support for user-relative paths.
Dropped a fair amount of redundant functionality in favour of the library code in path.c. git-upload-pack is now called with canonicalized paths.
Added option --strict-paths to retain old behaviour (documented).
---
Documentation/git-daemon.txt | 17 +++++- daemon.c | 128 ++++++++++++++---------------------------- 2 files changed, 58 insertions(+), 87 deletions(-)
applies-to: c40ce0cb704af8d7d1d655bcf709e7621db60e0e e35eb905a06718894a6c79f73d763122fff2a61a
Documentation/git-daemon.txt +14 -3
@@ -8,7 +8,7 @@ git-daemon - A really simple server for SYNOPSIS -------- 'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all] - [--timeout=n] [--init-timeout=n] [directory...] + [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...] DESCRIPTION -----------
@@ -29,10 +29,16 @@ This is ideally suited for read-only upd OPTIONS ------- +--strict-paths:: + Match paths exactly (i.e. don't allow "/foo/repo" when the real path is + "/foo/repo.git" or "/foo/repo/.git") and don't do user-relative paths. + git-daemon will refuse to start when this option is enabled and no + whitelist is specified. + --export-all:: Allow pulling from all directories that look like GIT repositories - (have the 'objects' subdirectory and a 'HEAD' file), even if they - do not have the 'git-daemon-export-ok' file. + (have the 'objects' and 'refs' subdirectories as well as a 'HEAD' file), + even if they do not have the 'git-daemon-export-ok' file. --inetd:: Have the server run as an inetd service.
@@ -57,6 +63,11 @@ OPTIONS --verbose:: Log details about the incoming connections and requested files. +<directory>:: + A directory to add to the whitelist of allowed directory. Unless + --strict-paths is specified this will also include subdirectories + of each named directory. + Author ------ Written by Linus Torvalds <[email protected]> and YOSHIFUJI Hideaki <[email protected]>
daemon.c +44 -84
200 lines not on this page · raw message
---
0.99.9.GIT
Quoted 1 line · Andreas Ericsson
+ [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]
Why not just --strict?
daemon.c line 13
Quoted 6 lines
daemon.c +1
-1@@ -10,16 +10,18 @@#include "pkt-line.h" #include "cache.h" -static int log_syslog; +static int log_syslog =0 ;
I'd drop this.
Quoted 18 lines
daemon.c +6
-1/* If this is set, git-daemon-export-ok is not required */ static int export_all_trees =0 ;@@ -81,69 +83,49 @@ static void loginfo(const char *err, ...va_end (params); } -static int path_ok (const char *dir) +static const char *path_ok (const char *dir) { +const char *path =is_git_repo (dir, strict_paths); +/* No such directory or not a git archive */ +if (!path) { +logerror ("'%s': unable to chdir or not a git archive" , dir); +return NULL ; }if ( ok_paths && *ok_paths ) {
daemon.c static void loginfo(const char *err, ... · line 105
Quoted 10 lines
daemon.c +5
-0+char **pp =NULL ; +int dirlen =strlen (path);for ( pp = ok_paths ; *pp ; pp++ ) {int len =strlen (*pp); +if ( len <= dirlen && !strncmp (*pp, path, len) ) { +if ( path[len] =='\0' || (!strict_paths && path[len] =='/' ) ) +return path; } }
Sorry, but I am a bit confused. Does this mean that you need to list all directories under --strict-paths, instead of saying "/pub/scm and everything under it is OK"?
I like the general direction this set is taking, but let's let it simmer for a while.
Quoted 13 lines · Junio C Hamano
Quoted 1 line · Andreas Ericsson
+ [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]
Why not just --strict?
Quoted 4 lines
daemon.c +0
-0@@ -10,16 +10,18 @@#include "pkt-line.h" #include "cache.h"
Quoted 6 lines
daemon.c line 13
Quoted 2 lines
daemon.c +1
-1-static int log_syslog; +static int log_syslog =0 ;I'd drop this.
No can do. It has to be set either here or down in main. It's nice to have the default in the declaration.
Quoted 22 lines
Quoted 22 lines
daemon.c +8
-1/* If this is set, git-daemon-export-ok is not required */ static int export_all_trees =0 ;@@ -81,69 +83,49 @@ static void loginfo(const char *err, ...va_end (params); } -static int path_ok (const char *dir) +static const char *path_ok (const char *dir) { +const char *path =is_git_repo (dir, strict_paths); +/* No such directory or not a git archive */ +if (!path) { +logerror ("'%s': unable to chdir or not a git archive" , dir); +return NULL ; }if ( ok_paths && *ok_paths ) { +char **pp =NULL ; +int dirlen =strlen (path);
Quoted 13 lines
daemon.c static void loginfo(const char *err, ... · line 106
Quoted 7 lines
daemon.c +3
-0for ( pp = ok_paths ; *pp ; pp++ ) {int len =strlen (*pp); +if ( len <= dirlen && !strncmp (*pp, path, len) ) { +if ( path[len] =='\0' || (!strict_paths && path[len] =='/' ) ) +return path; } }Sorry, but I am a bit confused. Does this mean that you need to list all directories under --strict-paths, instead of saying "/pub/scm and everything under it is OK"?
Only if --strict-paths is set, otherwise it works as usual. It's documented in the man-page, but perhaps it's a bit too paranoid.
Quoted 3 lines
I like the general direction this set is taking, but let's let it simmer for a while.
Ok. I'll take that to mean "hold off on the --server-root and --userdir patch for a while" then.
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231
Quoted 7 lines · Andreas Ericsson
Quoted 3 lines · Junio C Hamano
daemon.c line 13
Quoted 2 lines
daemon.c +1
-1-static int log_syslog; +static int log_syslog =0 ;I'd drop this.
No can do. It has to be set either here or down in main. It's nice to have the default in the declaration.
Isn't "static int log_syslog" in BSS to be initialized to zero anyway?
Quoted 5 lines
Quoted 2 lines
I like the general direction this set is taking, but let's let it simmer for a while.
Ok. I'll take that to mean "hold off on the --server-root and --userdir patch for a while" then.
I do not mind keeping it in the proposed updates branch for people to see and experiment with, but not in the master branch, at least for now.
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Andreas Ericsson
Quoted 4 lines · Junio C Hamano
daemon.c line 13
Quoted 2 lines
daemon.c +1
-1-static int log_syslog; +static int log_syslog =0 ;I'd drop this.
Quoted 5 lines
Quoted 1 line
No can do. It has to be set either here or down in main. It's nice to have the default in the declaration.
Isn't "static int
log_syslog" in BSS to be initialized to zero anyway?
I would have thought so, but it wasn't when I tested it. This could be a compiler-bug in my end, I suppose, but spelling it out enhances readability and leaves no room for doubt which is always nice.
Quoted 8 lines
Quoted 2 lines
Ok. I'll take that to mean "hold off on the --server-root and --userdir patch for a while" then.
I do not mind keeping it in the proposed updates branch for people to see and experiment with, but not in the master branch, at least for now.
I'll cook it up then.
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231
Quoted 8 lines · Junio C Hamano
Quoted 1 line · Andreas Ericsson
+ [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]
Why not just --strict?
It's a bit clearer what it is that's strict, and allows for future --strict-* options to be added without breaking anyones init-scripts.
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231