git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Greg Brockman <gdb@MIT.EDU>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC 1/4] Allow creation of arbitrary git-shell commands
Date: Wed, 14 Jul 2010 08:27:58 -0700	[thread overview]
Message-ID: <7vbpaaytfl.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1279076475-27730-2-git-send-email-gdb@mit.edu> (Greg Brockman's message of "Tue\, 13 Jul 2010 23\:01\:12 -0400")

Greg Brockman <gdb@MIT.EDU> writes:

> 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

Please have a blank line above and below sample command display like these
for readability.

> Signed-off-by: Greg Brockman <gdb@mit.edu>
> ---
>  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);

Hmm, could you justify "should be" above please?

An example would be "All of the custom commands I wrote to give added
features to users at my installation wanted to be in that directory, not
at the user's home directory, as they mostly operated on files in that
directory", but please do not make me (or other reviewers) guess why.

What I am getting at is that it may be more natural and useful to run
these custom commands in the user's $HOME directory---you would need to
make sure that execl() finds the command you get from the request, perhaps
by prefixing COMMAND_DIR / to the command name, though.

> +	if (is_valid_cmd_name(prog))
> +		execl(prog, prog, (char *) NULL);
> +
>  	die("unrecognized command '%s'", prog);
>  }

  reply	other threads:[~2010-07-14 15:28 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-14  3:01 [PATCH/RFC 0/4] Providing mechanism to list available repositories Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 1/4] Allow creation of arbitrary git-shell commands Greg Brockman
2010-07-14 15:27   ` Junio C Hamano [this message]
2010-07-14 17:42     ` Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 2/4] git-shell-commands: Add a command to list bare repos Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 3/4] git-shell-commands: Add a help command Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 4/4] Add interactive mode to git-shell for user-friendliness Greg Brockman
2010-07-14  9:04   ` Ævar Arnfjörð Bjarmason
2010-07-14 13:59     ` Kevin P. Fleming
2010-07-14 15:24       ` Bernhard R. Link
2010-07-14 15:40         ` Thomas Rast
     [not found]           ` <20100714160730.GA27078@pcpool00.mathematik.uni-freiburg.de>
     [not found]             ` <AANLkTikEjMeKPkyY4RdRq-ESkmmq4PvqCFPgp8yvLVBz@mail.gmail.com>
2010-07-17  4:12               ` Greg Brockman
2010-07-17  5:52                 ` Jonathan Nieder
2010-07-17 14:53                   ` Greg Brockman
2010-07-24 15:20           ` [PATCH] Cast execl*() NULL sentinels to (char *) Thomas Rast
2010-07-24 15:27             ` Ævar Arnfjörð Bjarmason
2010-07-14 10:27   ` [PATCH/RFC 4/4] Add interactive mode to git-shell for user-friendliness Johannes Sixt
2010-07-14 19:11 ` [PATCH/RFC 0/4] Providing mechanism to list available repositories Junio C Hamano
2010-07-14 19:29   ` Greg Brockman

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=7vbpaaytfl.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=gdb@MIT.EDU \
    --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.
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).