summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 64fdc08)
raw | patch | inline | side by side (parent: 64fdc08)
author | Greg Brockman <gdb@MIT.EDU> | |
Thu, 29 Jul 2010 00:31:01 +0000 (17:31 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 12 Aug 2010 22:16:15 +0000 (15:16 -0700) |
This provides a mechanism for the server to expose custom
functionality to clients. My particular use case is that I would like
a way of discovering all repositories available for cloning. A
client that clones via
git clone user@example.com
can invoke a command by
ssh user@example.com $command
Signed-off-by: Greg Brockman <gdb@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
functionality to clients. My particular use case is that I would like
a way of discovering all repositories available for cloning. A
client that clones via
git clone user@example.com
can invoke a command by
ssh user@example.com $command
Signed-off-by: Greg Brockman <gdb@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
shell.c | patch | blob | history |
index e4864e04da3b0e237342c2ca0548c0ec0082c171..5b5e10501d58d5413e1673df2f1fd5a3ba948b3a 100644 (file)
--- a/shell.c
+++ b/shell.c
#include "exec_cmd.h"
#include "strbuf.h"
+#define COMMAND_DIR "git-shell-commands"
+
static int do_generic_cmd(const char *me, char *arg)
{
const char *my_argv[4];
return execv_git_cmd(cvsserver_argv);
}
+static int is_valid_cmd_name(const char *cmd)
+{
+ /* Test command contains no . or / characters */
+ return cmd[strcspn(cmd, "./")] == '\0';
+}
+
+static char *make_cmd(const char *prog)
+{
+ char *prefix = xmalloc((strlen(prog) + strlen(COMMAND_DIR) + 2));
+ strcpy(prefix, COMMAND_DIR);
+ strcat(prefix, "/");
+ strcat(prefix, prog);
+ return prefix;
+}
+
+static void cd_to_homedir(void)
+{
+ const char *home = getenv("HOME");
+ if (!home)
+ die("could not determine user's home directory; HOME is unset");
+ if (chdir(home) == -1)
+ die("could not chdir to user's home directory");
+}
static struct commands {
const char *name;
int main(int argc, char **argv)
{
char *prog;
+ const char **user_argv;
struct commands *cmd;
int devnull_fd;
else if (argc != 3 || strcmp(argv[1], "-c"))
die("What do you think I am? A shell?");
- prog = argv[2];
+ prog = xstrdup(argv[2]);
if (!strncmp(prog, "git", 3) && isspace(prog[3]))
/* Accept "git foo" as if the caller said "git-foo". */
prog[3] = '-';
}
exit(cmd->exec(cmd->name, arg));
}
- die("unrecognized command '%s'", prog);
+
+ cd_to_homedir();
+ if (split_cmdline(prog, &user_argv) != -1) {
+ if (is_valid_cmd_name(user_argv[0])) {
+ prog = make_cmd(user_argv[0]);
+ user_argv[0] = prog;
+ execv(user_argv[0], (char *const *) user_argv);
+ }
+ free(prog);
+ free(user_argv);
+ die("unrecognized command '%s'", argv[2]);
+ } else {
+ free(prog);
+ die("invalid command format '%s'", argv[2]);
+ }
}