From: Greg Brockman <gdb@MIT.EDU>
To: j.sixt@viscovery.net, gitster@pobox.com, avarab@gmail.com,
jrnieder@gmail.com, git@vger.kernel.org
Cc: Greg Brockman <gdb@mit.edu>
Subject: [PATCH 1/3] Allow creation of arbitrary git-shell commands
Date: Wed, 21 Jul 2010 11:15:53 -0400 [thread overview]
Message-ID: <1279725355-23016-2-git-send-email-gdb@mit.edu> (raw)
In-Reply-To: <1279725355-23016-1-git-send-email-gdb@mit.edu>
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>
---
shell.c | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/shell.c b/shell.c
index e4864e0..34159c4 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,20 @@ 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 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 struct commands {
const char *name;
@@ -48,6 +64,7 @@ static struct commands {
int main(int argc, char **argv)
{
char *prog;
+ const char **user_argv;
struct commands *cmd;
int devnull_fd;
@@ -76,7 +93,7 @@ int main(int argc, char **argv)
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] = '-';
@@ -99,5 +116,18 @@ int main(int argc, char **argv)
}
exit(cmd->exec(cmd->name, arg));
}
- die("unrecognized command '%s'", prog);
+
+ 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]);
+ }
}
--
1.7.0.4
next prev parent reply other threads:[~2010-07-21 15:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-21 15:15 [PATCHv3] Updated patch series for providing mechanism to list available repositories Greg Brockman
2010-07-21 15:15 ` Greg Brockman [this message]
2010-07-21 15:15 ` [PATCH 2/3] Add interactive mode to git-shell for user-friendliness Greg Brockman
2010-07-21 15:15 ` [PATCH 3/3] Add sample commands for git-shell Greg Brockman
2010-07-26 22:32 ` [PATCHv3] Updated patch series for providing mechanism to list available repositories Greg Brockman
2010-07-26 22:54 ` Ævar Arnfjörð Bjarmason
2010-07-26 23:18 ` Greg Brockman
2010-07-27 9:02 ` Jakub Narebski
2010-07-26 23:28 ` Jonathan Nieder
2010-07-27 0:20 ` Greg Brockman
2010-07-27 0:50 ` Jonathan Nieder
2010-07-27 7:16 ` Johannes Sixt
2010-07-27 17:41 ` Jonathan Nieder
2010-07-27 22:43 ` Greg Brockman
2010-07-28 0:33 ` Jonathan Nieder
2010-07-28 6:15 ` Greg Brockman
2010-07-28 6:42 ` Jonathan Nieder
2010-07-28 7:06 ` Greg Brockman
2010-07-28 23:14 ` Anders Kaseorg
2010-07-28 23:52 ` Jonathan Nieder
2010-07-29 0:21 ` Greg Brockman
2010-07-29 0:33 ` Jonathan Nieder
2010-07-28 1:10 ` Jonathan Nieder
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1279725355-23016-2-git-send-email-gdb@mit.edu \
--to=gdb@mit.edu \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=jrnieder@gmail.com \
/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.
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 NNTP newsgroup(s).