Skip to content

Commit 0c696fe

Browse files
dschospearce
authored andcommitted
Support cvs via git-shell
This adds cvs support to the git-shell; You can now give new users a restricted git-shell and they still can commit via git's cvs emulator. Note that either the gecos information must be accurate, or you must provide a $HOME/.gitconfig with the appropriate user credentials. Since the git-shell is too restricted to allow the user to do it (on purpose!), it is up to the administrator to take care of that. Based on an idea by Jan Wielemaker. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent a2a9150 commit 0c696fe

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

shell.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22
#include "quote.h"
33
#include "exec_cmd.h"
4+
#include "strbuf.h"
45

56
static int do_generic_cmd(const char *me, char *arg)
67
{
@@ -18,12 +19,34 @@ static int do_generic_cmd(const char *me, char *arg)
1819
return execv_git_cmd(my_argv);
1920
}
2021

22+
static int do_cvs_cmd(const char *me, char *arg)
23+
{
24+
const char *cvsserver_argv[3] = {
25+
"cvsserver", "server", NULL
26+
};
27+
const char *oldpath = getenv("PATH");
28+
struct strbuf newpath = STRBUF_INIT;
29+
30+
if (!arg || strcmp(arg, "server"))
31+
die("git-cvsserver only handles server: %s", arg);
32+
33+
strbuf_addstr(&newpath, git_exec_path());
34+
strbuf_addch(&newpath, ':');
35+
strbuf_addstr(&newpath, oldpath);
36+
37+
setenv("PATH", strbuf_detach(&newpath, NULL), 1);
38+
39+
return execv_git_cmd(cvsserver_argv);
40+
}
41+
42+
2143
static struct commands {
2244
const char *name;
2345
int (*exec)(const char *me, char *arg);
2446
} cmd_list[] = {
2547
{ "git-receive-pack", do_generic_cmd },
2648
{ "git-upload-pack", do_generic_cmd },
49+
{ "cvs", do_cvs_cmd },
2750
{ NULL },
2851
};
2952

@@ -32,8 +55,10 @@ int main(int argc, char **argv)
3255
char *prog;
3356
struct commands *cmd;
3457

58+
if (argc == 2 && !strcmp(argv[1], "cvs server"))
59+
argv--;
3560
/* We want to see "-c cmd args", and nothing else */
36-
if (argc != 3 || strcmp(argv[1], "-c"))
61+
else if (argc != 3 || strcmp(argv[1], "-c"))
3762
die("What do you think I am? A shell?");
3863

3964
prog = argv[2];

0 commit comments

Comments
 (0)