If I disable git-shell's interactive mode by removing the
~/git-shell-commands directory, attempts to use 'ssh' in produce a
message intended for the administrator:

        $ ssh git@myserver
        fatal: Interactive git shell is not enabled.
        hint: ~/git-shell-commands should exist and have read and execute 

That is helpful for the new admin who is wondering "What? Why isn't
the git-shell I just set up working?", but once the site setup is
complete, it would be better to give the user a friendly hint that she
is on the right track, like GitHub does.

        Hi <username>! You've successfully authenticated, but
        GitHub does not provide shell access.

An appropriate greeting might even include more complex dynamic
information, like gitolite's list of repositories the user has access
to.  Add support for a ~/git-shell-commands/no-interactive-login
command that generates an arbitrary greeting.  When the user tries to
log in:

 * If the file ~/git-shell-commands/no-interactive-login exists,
   run no-interactive-login to let the server say what it likes,
   then hang up.

 * Otherwise, if ~/git-shell-commands/ is present, start an
   interactive read-eval-print loop.

 * Otherwise, print the usual configuration hint and hang up.

Reported-by: Ethan Reesor <firelizz...@gmail.com>
Signed-off-by: Jonathan Nieder <jrnie...@gmail.com>
Improved-by: Jeff King <p...@peff.net>
v2 jammed this functionality into the "help" command, which was kind
of silly.  Hopefully this version's better.

This is not urgent at all.  If it looks like a good change, I'd be
happy to see it be a part of the 1.8.3 cycle.


 Documentation/git-shell.txt | 20 ++++++++++++++++++++
 shell.c                     | 13 +++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/git-shell.txt b/Documentation/git-shell.txt
index 544b21aa..c35051ba 100644
--- a/Documentation/git-shell.txt
+++ b/Documentation/git-shell.txt
@@ -59,6 +59,26 @@ users to list repositories they have access to, create, 
delete, or
 rename repositories, or change repository descriptions and
+If a `no-interactive-login` command exists, then it is run and the
+interactive shell is aborted.
+To disable interactive logins, displaying a greeting instead:
+$ chsh -s /usr/bin/git-shell
+$ mkdir $HOME/git-shell-commands
+$ cat >$HOME/git-shell-commands/no-interactive-login <<\EOF
+printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
+printf '%s\n' "provide interactive shell access."
+exit 128
+$ chmod +x $HOME/git-shell-commands/no-interactive-login
diff --git a/shell.c b/shell.c
index 84b237fe..1429870a 100644
--- a/shell.c
+++ b/shell.c
@@ -6,6 +6,7 @@
 #define COMMAND_DIR "git-shell-commands"
+#define NOLOGIN_COMMAND COMMAND_DIR "/no-interactive-login"
 static int do_generic_cmd(const char *me, char *arg)
@@ -65,6 +66,18 @@ static void run_shell(void)
        int done = 0;
        static const char *help_argv[] = { HELP_COMMAND, NULL };
+       if (!access(NOLOGIN_COMMAND, F_OK)) {
+               /* Interactive login disabled. */
+               const char *argv[] = { NOLOGIN_COMMAND, NULL };
+               int status;
+               status = run_command_v_opt(argv, 0);
+               if (status < 0)
+                       exit(127);
+               exit(status);
+       }
        /* Print help if enabled */
        run_command_v_opt(help_argv, RUN_SILENT_EXEC_FAILURE);

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to