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@xxxxxxxxxxx can invoke a command by ssh user@xxxxxxxxxxx $command Signed-off-by: Greg Brockman <gdb@xxxxxxx> --- shell.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/shell.c b/shell.c index e4864e0..3fee0ed 100644 --- a/shell.c +++ b/shell.c @@ -3,6 +3,8 @@ #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]; @@ -33,6 +35,12 @@ static int do_cvs_cmd(const char *me, char *arg) 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 struct commands { const char *name; @@ -99,5 +107,13 @@ int main(int argc, char **argv) } exit(cmd->exec(cmd->name, arg)); } + + /* Shell should be spawned with cwd in the git user's home directory */ + if (chdir(COMMAND_DIR)) + die("unrecognized command '%s'", prog); + + if (is_valid_cmd_name(prog)) + execl(prog, prog, (char *) NULL); + die("unrecognized command '%s'", prog); } -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html