git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC 1/4] Allow creation of arbitrary git-shell commands

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 14, 2010, 15:27 UTC
Message-ID
<7vbpaaytfl.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1279076475-27730-2-git-send-email-gdb@mit.edu>
Greg Brockman <gdb@MIT.EDU> writes:
Show 7 quoted lines
> 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.

Show 39 quoted lines
> 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.

Show 5 quoted lines
> +	if (is_valid_cmd_name(prog))
> +		execl(prog, prog, (char *) NULL);
> +
>  	die("unrecognized command '%s'", prog);
>  }
Previous: Greg BrockmanNext: Greg Brockman
Message 3 of 19 in “Providing mechanism to list available repositories”
  1. 0/4 Providing mechanism to list available repositoriesGreg Brockman, Jul 14, 2010
  2. 1/4 Allow creation of arbitrary git-shell commandsGreg Brockman, Jul 14, 2010
  3. Junio C HamanoJul 14, 2010
  4. Greg BrockmanJul 14, 2010
  5. 2/4 git-shell-commands: Add a command to list bare reposGreg Brockman, Jul 14, 2010
  6. 3/4 git-shell-commands: Add a help commandGreg Brockman, Jul 14, 2010
  7. 4/4 Add interactive mode to git-shell for user-friendlinessGreg Brockman, Jul 14, 2010
  8. Ævar Arnfjörð BjarmasonJul 14, 2010
  9. Kevin P. FlemingJul 14, 2010
  10. Bernhard R. LinkJul 14, 2010
  11. Thomas RastJul 14, 2010
  12. Cast execl*() NULL sentinels to (char *)Thomas Rast, Jul 24, 2010
  13. Ævar Arnfjörð BjarmasonJul 24, 2010
  14. Johannes SixtJul 14, 2010
  15. Junio C HamanoJul 14, 2010
  16. Greg BrockmanJul 14, 2010
  17. Greg BrockmanJul 17, 2010
  18. Jonathan NiederJul 17, 2010
  19. Greg BrockmanJul 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.