From: Mark Wooding <mdw@distorted.org.uk>
To: git@vger.kernel.org
Subject: [PATCH 3/3] daemon: Support a --user-path option.
Date: Fri, 03 Feb 2006 20:27:06 +0000 [thread overview]
Message-ID: <20060203202706.1895.70864.stgit@metalzone.distorted.org.uk> (raw)
In-Reply-To: <20060203202330.1895.60474.stgit@metalzone.distorted.org.uk>
From: Mark Wooding <mwooding@ponder.ncipher.com>
If we're invoked with --user-path=FOO option, then a URL of the form
git://~USER/PATH/... resolves to the path HOME/FOO/PATH/..., where HOME
is USER's home directory. This is done instead of any transformation
due to --base-path, so you can use both at the same time. This lets
users set up their own git repositories to be served by a central
daemon, without them all having to be in the same place, and without the
git-daemon being allowed to roam the entire filesystem freely, or
exposing details of filesystem layout on URLs.
Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
---
Documentation/git-daemon.txt | 11 +++++++++--
daemon.c | 36 +++++++++++++++++++++++++++++++++---
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
index a20e053..2e48a10 100644
--- a/Documentation/git-daemon.txt
+++ b/Documentation/git-daemon.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all]
[--timeout=n] [--init-timeout=n] [--strict-paths]
- [--base-path=path] [directory...]
+ [--base-path=path] [--user-path=path] [directory...]
DESCRIPTION
-----------
@@ -43,7 +43,7 @@ OPTIONS
'--base-path=/srv/git' on example.com, then if you later try to pull
'git://example.com/hello.git', `git-daemon` will interpret the path
as '/srv/git/hello.git'. Home directories (the '~login' notation)
- access is disabled.
+ access is disabled unless '--user-path' is also given.
--export-all::
Allow pulling from all directories that look like GIT repositories
@@ -70,6 +70,13 @@ OPTIONS
Log to syslog instead of stderr. Note that this option does not imply
--verbose, thus by default only error conditions will be logged.
+--user-path::
+ Rewrite a request for "~user/something" to
+ "home/user-path/something". Useful in conjunction with
+ '--base-path', if you want to restrict the daemon from roaming
+ the entire filesystem without preventing users from publishing
+ their own repositories.
+
--verbose::
Log details about the incoming connections and requested files.
diff --git a/daemon.c b/daemon.c
index 6b88c0c..95b9c7e 100644
--- a/daemon.c
+++ b/daemon.c
@@ -6,6 +6,7 @@
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <pwd.h>
#include <syslog.h>
#include "pkt-line.h"
#include "cache.h"
@@ -17,7 +18,7 @@ static int verbose;
static const char daemon_usage[] =
"git-daemon [--verbose] [--syslog] [--inetd | --port=n] [--export-all]\n"
" [--timeout=n] [--init-timeout=n] [--strict-paths]\n"
-" [--base-path=path] [directory...]";
+" [--base-path=path] [--user-path=path] [directory...]";
/* List of acceptable pathname prefixes */
static char **ok_paths = NULL;
@@ -28,6 +29,7 @@ static int export_all_trees = 0;
/* Take all paths relative to this one if non-NULL */
static char *base_path = NULL;
+static char *user_path = NULL;
/* Timeout, and initial timeout */
static unsigned int timeout = 0;
@@ -137,14 +139,34 @@ static int avoid_alias(char *p)
static char *path_ok(char *dir)
{
char *path;
+ static char rpath[PATH_MAX];
if (avoid_alias(dir)) {
logerror("'%s': aliased", dir);
return NULL;
}
- if (base_path) {
- static char rpath[PATH_MAX];
+ if (user_path && *dir == '~') {
+ struct passwd *pw;
+ char *u, *p;
+
+ u = dir + 1;
+ p = strchr(u, '/');
+ if (!p) {
+ logerror("'%s': Missing / after user name", dir);
+ return NULL;
+ }
+ *p = 0;
+ pw = getpwnam(u);
+ *p++ = '/';
+ if (!pw) {
+ logerror("'%s': User not found", u);
+ return NULL;
+ }
+ snprintf(rpath, PATH_MAX, "%s/%s/%s",
+ pw->pw_dir, user_path, p);
+ dir = rpath;
+ } else if (base_path) {
if (*dir != '/') {
/* Forbid possible base-path evasion using ~paths. */
logerror("'%s': Non-absolute path denied (base-path active)", dir);
@@ -491,6 +513,10 @@ static int socksetup(int port, int **soc
/* Note: error is not fatal */
}
#endif
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes))) {
+ close(sockfd);
+ continue; /* not fatal */
+ }
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
&yes, sizeof(yes))) {
@@ -673,6 +699,10 @@ int main(int argc, char **argv)
base_path = arg+12;
continue;
}
+ if (!strncmp(arg, "--user-path=", 12)) {
+ user_path = arg+12;
+ continue;
+ }
if (!strcmp(arg, "--")) {
ok_paths = &argv[i+1];
break;
next prev parent reply other threads:[~2006-02-03 20:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-03 20:23 [PATCH 0/3] git-daemon hacking Mark Wooding
2006-02-03 20:27 ` [PATCH 1/3] daemon: Provide missing argument for logerror() call Mark Wooding
2006-02-03 20:27 ` [PATCH 2/3] daemon: Set SO_REUSEADDR on listening sockets Mark Wooding
2006-02-03 20:57 ` Junio C Hamano
2006-02-04 8:49 ` Junio C Hamano
2006-02-04 10:16 ` Mark Wooding
2006-02-03 20:27 ` Mark Wooding [this message]
2006-02-03 20:52 ` [PATCH 3/3] daemon: Support a --user-path option Junio C Hamano
2006-02-04 8:50 ` Junio C Hamano
2006-02-04 10:02 ` Mark Wooding
2006-02-04 12:40 ` Junio C Hamano
2006-02-04 19:13 ` Mark Wooding
2006-02-04 22:02 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060203202706.1895.70864.stgit@metalzone.distorted.org.uk \
--to=mdw@distorted.org.uk \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).