# [PATCH] "git shell" won't work, need "git-shell"

28 messages from 2008-08-24 to 2008-10-28. Participants: Tommi Virtanen, Junio C Hamano, Johannes Schindelin, Paolo Bonzini, Petr Baudis, Dmitry Potapov, Mikael Magnusson, Mike Hommey, Matthieu Moy, Mike Ralphson, Dmitry V. Levin.
Thread: https://gitlist.dev/t/15193

## Tommi Virtanen, 2008-08-24 20:23

Subject: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080824202325.GA14930@eagain.net>
URL: https://gitlist.dev/e/20080824202325.GA14930%40eagain.net

```
>From 8e7935231e8a91d470b3a4a2310803031ef49fc4 Mon Sep 17 00:00:00 2001
From: Tommi Virtanen <tv@eagain.net>
Date: Sun, 24 Aug 2008 23:20:33 +0300
Subject: [PATCH] Install git-shell in bindir, again.

/etc/passwd shell field must be something execable, you can't enter
"/usr/bin/git shell" there. git-shell must be present as a separate
executable, or it is useless.

Signed-off-by: Tommi Virtanen <tv@eagain.net>
---

Hi. Recent changes moved away from "git-foo" to "git foo", except for
some commands that needed backwards compatibility. However, git-shell
as a separate binary was removed. I hope you will reinstante git-shell
as a publicly visible binary in bin. Here's why:

The shell field in /etc/passwd is *exec*ed, not interpreted via sh -c
or some such. For example, source of Debian's shadow, containing
/bin/login:

libmisc/shell.c:80:	execle (file, arg, (char *) 0, envp);

I also tested this for real, and having a

test:x:1001:1001:,,,:/home/test:/usr/bin/git-shell

line works, and

test:x:1001:1001:,,,:/home/test:/usr/bin/git shell

just makes ssh loop asking for a password, logging

"User test not allowed because shell /usr/bin/git shell does not exist"

So, as far as I understand, as it currently is, "git shell" is utterly
useless for what it was meant to do. Restoring "git-shell" will fix
it.

 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 53ab4b5..24d5809 100644
--- a/Makefile
+++ b/Makefile
@@ -1351,7 +1351,7 @@ install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-	$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X git-shell$X '$(DESTDIR_SQ)$(bindir_SQ)'
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_TCLTK
-- 
1.6.0.2.g2ebc0.dirty

-- 
:(){ :|:&};:

```

## Junio C Hamano, 2008-08-24 20:36

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <7vfxoukv56.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vfxoukv56.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080824202325.GA14930@eagain.net>

```
Tommi Virtanen <tv@eagain.net> writes:

> test:x:1001:1001:,,,:/home/test:/usr/bin/git-shell
>
> line works, and
>
> test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
>
> just makes ssh loop asking for a password, logging

Of course it would.  Does using /usr/libexec/git-core/git-shell work?

```

## Tommi Virtanen, 2008-08-24 20:38

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080824203825.GB14930@eagain.net>
URL: https://gitlist.dev/e/20080824203825.GB14930%40eagain.net
In-Reply-To: <7vfxoukv56.fsf@gitster.siamese.dyndns.org>

```
On Sun, Aug 24, 2008 at 01:36:37PM -0700, Junio C Hamano wrote:
> Of course it would.  Does using /usr/libexec/git-core/git-shell work?

It would, but do you really want people using that?

-- 
:(){ :|:&};:

```

## Junio C Hamano, 2008-08-24 21:20

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <7vbpzikt4b.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbpzikt4b.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080824203825.GB14930@eagain.net>

```
Tommi Virtanen <tv@eagain.net> writes:

> On Sun, Aug 24, 2008 at 01:36:37PM -0700, Junio C Hamano wrote:
>> Of course it would.  Does using /usr/libexec/git-core/git-shell work?
>
> It would, but do you really want people using that?

I do not have particular preference either way.  What people wanted was to
have smaller number of git-foo on $PATH, and especially as "git-shell" is
not something people would be typing from their command line, so I dunno.

```

## Tommi Virtanen, 2008-08-24 22:25

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080824222534.GC14930@eagain.net>
URL: https://gitlist.dev/e/20080824222534.GC14930%40eagain.net
In-Reply-To: <7vbpzikt4b.fsf@gitster.siamese.dyndns.org>

```
On Sun, Aug 24, 2008 at 02:20:20PM -0700, Junio C Hamano wrote:
> I do not have particular preference either way.  What people wanted was to
> have smaller number of git-foo on $PATH, and especially as "git-shell" is
> not something people would be typing from their command line, so I dunno.

That's true, but I kinda think libexec is something only used
*internally*, and you can't claim /etc/passwd to be internal to git..

At the minimum, git-shell(1) should explain that one needs to use the
libexec path.

-- 
:(){ :|:&};:

```

## Johannes Schindelin, 2008-08-25 10:37

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <alpine.DEB.1.00.0808251235430.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808251235430.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <20080824222534.GC14930@eagain.net>

```
Hi,

On Mon, 25 Aug 2008, Tommi Virtanen wrote:

> On Sun, Aug 24, 2008 at 02:20:20PM -0700, Junio C Hamano wrote:
> > I do not have particular preference either way.  What people wanted was to
> > have smaller number of git-foo on $PATH, and especially as "git-shell" is
> > not something people would be typing from their command line, so I dunno.
> 
> That's true, but I kinda think libexec is something only used
> *internally*, and you can't claim /etc/passwd to be internal to git..
> 
> At the minimum, git-shell(1) should explain that one needs to use the
> libexec path.

Or maybe the real issue can be fixed?  Namely that your configuration does 
not work?  That would involve you actually finding out what's happening, 
though.

Ciao,
Dscho

```

## Paolo Bonzini, 2008-08-25 11:44

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <48B29B2A.6000802@gnu.org>
URL: https://gitlist.dev/e/48B29B2A.6000802%40gnu.org
In-Reply-To: <alpine.DEB.1.00.0808251235430.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```

>> At the minimum, git-shell(1) should explain that one needs to use the
>> libexec path.
> 
> Or maybe the real issue can be fixed?  Namely that your configuration does 
> not work?  That would involve you actually finding out what's happening, 
> though.

He said so:

> The shell field in /etc/passwd is *exec*ed, not interpreted via sh -c
> or some such. For example, source of Debian's shadow, containing
> /bin/login:
> 
> libmisc/shell.c:80:	execle (file, arg, (char *) 0, envp);
> 
> I also tested this for real, and having a
> 
> test:x:1001:1001:,,,:/home/test:/usr/bin/git-shell
> 
> line works, and
> 
> test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
> 
> just makes ssh loop asking for a password, logging
> 
> "User test not allowed because shell /usr/bin/git shell does not exist"
> 
> So, as far as I understand, as it currently is, "git shell" is utterly
> useless for what it was meant to do. Restoring "git-shell" will fix
> it.

Rephrasing your question, do you (Dscho) actually know *anyone* who has
a working setup with "/usr/bin/git shell" in /etc/passwd?

Paolo

```

## Petr Baudis, 2008-08-25 17:08

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080825170816.GQ10544@machine.or.cz>
URL: https://gitlist.dev/e/20080825170816.GQ10544%40machine.or.cz
In-Reply-To: <7vbpzikt4b.fsf@gitster.siamese.dyndns.org>

```
On Sun, Aug 24, 2008 at 02:20:20PM -0700, Junio C Hamano wrote:
> Tommi Virtanen <tv@eagain.net> writes:
> 
> > On Sun, Aug 24, 2008 at 01:36:37PM -0700, Junio C Hamano wrote:
> >> Of course it would.  Does using /usr/libexec/git-core/git-shell work?
> >
> > It would, but do you really want people using that?
> 
> I do not have particular preference either way.  What people wanted was to
> have smaller number of git-foo on $PATH, and especially as "git-shell" is
> not something people would be typing from their command line, so I dunno.

Can we agree that direct calls of libexec stuff should never be part of
the "official" interface (i.e. not workarounds for deprecated usage)?
Considering that calling the git-shell executable directly is the _only_
sensible way of using this interface, it should follow that it has to be
in /usr/bin, no matter if users type this command or not.

(I'm actually a little confused that you bring up the "typing from their
command line" aspect at all, since that never seemed to be relevant
criterium. People type the commit command all the time, yet we do not
install git-commit. Typing the three git-* commands we do install -
git-receive-pack, git-upload-pack and git-upload-archive - should be on
the other hand pretty rare occasion. About gitk, well, 'git k' would
just look silly, I guess. ;-)

-- 
				Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC.  -- Bill Gates

```

## Dmitry Potapov, 2008-08-25 17:20

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <37fcd2780808251020j1ef51b38h7c6d6e8f050a92ce@mail.gmail.com>
URL: https://gitlist.dev/e/37fcd2780808251020j1ef51b38h7c6d6e8f050a92ce%40mail.gmail.com
In-Reply-To: <20080825170816.GQ10544@machine.or.cz>

```
On Mon, Aug 25, 2008 at 9:08 PM, Petr Baudis <pasky@suse.cz> wrote:
>
> Can we agree that direct calls of libexec stuff should never be part of
> the "official" interface (i.e. not workarounds for deprecated usage)?

Agreed. It looks somewhat strange to type the libexec path in /etc/passwd.

> Considering that calling the git-shell executable directly is the _only_
> sensible way of using this interface, it should follow that it has to be
> in /usr/bin, no matter if users type this command or not.

Perhaps, /usr/sbin would be a better place, as it is intended only for
system administration binaries.

Dmitry

```

## Tommi Virtanen, 2008-08-25 17:26

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080825172630.GH23582@eagain.net>
URL: https://gitlist.dev/e/20080825172630.GH23582%40eagain.net
In-Reply-To: <37fcd2780808251020j1ef51b38h7c6d6e8f050a92ce@mail.gmail.com>

```
On Mon, Aug 25, 2008 at 09:20:38PM +0400, Dmitry Potapov wrote:
> Perhaps, /usr/sbin would be a better place, as it is intended only for
> system administration binaries.

I'd argue that git-shell isn't *exclusively* for root, which is the
criteria for sbin. It's pretty easy to imagine a user setting up their
own ~/.ssh/authorized_keys with a special passphraseless key that
can only do git operations.

-- 
:(){ :|:&};:

```

## Dmitry Potapov, 2008-08-25 17:53

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <37fcd2780808251053j5e8ced77ye633e05837cccd6@mail.gmail.com>
URL: https://gitlist.dev/e/37fcd2780808251053j5e8ced77ye633e05837cccd6%40mail.gmail.com
In-Reply-To: <20080825172630.GH23582@eagain.net>

```
On Mon, Aug 25, 2008 at 9:26 PM, Tommi Virtanen <tv@eagain.net> wrote:
> On Mon, Aug 25, 2008 at 09:20:38PM +0400, Dmitry Potapov wrote:
>> Perhaps, /usr/sbin would be a better place, as it is intended only for
>> system administration binaries.
>
> I'd argue that git-shell isn't *exclusively* for root, which is the
> criteria for sbin.

I don't think that your criteria is correct. mysqld is also not exclusively
for root as you can run it on a non-privilege port, yet, it is placed in
/usr/sbin. Placing in /usr/sbin does not mean that users do not have access
to it, but that those binaries are not run by users from their command line.

Dmitry

```

## Johannes Schindelin, 2008-08-25 17:58

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <alpine.DEB.1.00.0808251955490.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808251955490.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <48B29B2A.6000802@gnu.org>

```
Hi,

On Mon, 25 Aug 2008, Paolo Bonzini wrote:

> > That would involve you actually finding out what's happening, though.
> 
> He said so:
> 
> > test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
> > 
> > just makes ssh loop asking for a password, logging
> > 
> > "User test not allowed because shell /usr/bin/git shell does not exist"

Okay, so this means that you cannot pass arguments to the login shell.  
Makes me wonder... I had the impression that bash was called with --login.

Ciao,
Dscho

```

## Johannes Schindelin, 2008-08-25 18:17

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <alpine.DEB.1.00.0808252015080.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808252015080.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <37fcd2780808251020j1ef51b38h7c6d6e8f050a92ce@mail.gmail.com>

```
Hi,

On Mon, 25 Aug 2008, Dmitry Potapov wrote:

> On Mon, Aug 25, 2008 at 9:08 PM, Petr Baudis <pasky@suse.cz> wrote:
> >
> > Can we agree that direct calls of libexec stuff should never be part 
> > of the "official" interface (i.e. not workarounds for deprecated 
> > usage)?
> 
> Agreed. It looks somewhat strange to type the libexec path in 
> /etc/passwd.

FWIW I do not agree.  IMNHO libexec/ is just a way to organize executable 
parts of any software package that are usually not called from the command 
line.  And a login shell qualifies for that.

> > Considering that calling the git-shell executable directly is the 
> > _only_ sensible way of using this interface, it should follow that it 
> > has to be in /usr/bin, no matter if users type this command or not.
> 
> Perhaps, /usr/sbin would be a better place, as it is intended only for 
> system administration binaries.

Does it not strike you as odd, then, that "sh" -- by far the most common 
login shell -- does not live in /usr/sbin/?

Ciao,
Dscho

```

## Mikael Magnusson, 2008-08-25 18:25

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <237967ef0808251125q3e50fa04wf0e97ff29298bef2@mail.gmail.com>
URL: https://gitlist.dev/e/237967ef0808251125q3e50fa04wf0e97ff29298bef2%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0808251955490.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
2008/8/25 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> Hi,
>
> On Mon, 25 Aug 2008, Paolo Bonzini wrote:
>
>> > That would involve you actually finding out what's happening, though.
>>
>> He said so:
>>
>> > test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
>> >
>> > just makes ssh loop asking for a password, logging
>> >
>> > "User test not allowed because shell /usr/bin/git shell does not exist"
>
> Okay, so this means that you cannot pass arguments to the login shell.
> Makes me wonder... I had the impression that bash was called with --login.

When you login, a '-' is prepended in argv[0], ie, bash checks if it's called
"-bash". This is documented in man bash, but I couldn't find it in man login
or man agetty, not sure where else it might be written down.

-- 
Mikael Magnusson

```

## Johannes Schindelin, 2008-08-25 20:08

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <alpine.DEB.1.00.0808252206150.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808252206150.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <237967ef0808251125q3e50fa04wf0e97ff29298bef2@mail.gmail.com>

```
Hi,

On Mon, 25 Aug 2008, Mikael Magnusson wrote:

> 2008/8/25 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
>
> > On Mon, 25 Aug 2008, Paolo Bonzini wrote:
> >
> >> > That would involve you actually finding out what's happening, 
> >> > though.
> >>
> >> He said so:
> >>
> >> > test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
> >> >
> >> > just makes ssh loop asking for a password, logging
> >> >
> >> > "User test not allowed because shell /usr/bin/git shell does not 
> >> > exist"
> >
> > Okay, so this means that you cannot pass arguments to the login shell. 
> > Makes me wonder... I had the impression that bash was called with 
> > --login.
> 
> When you login, a '-' is prepended in argv[0], ie, bash checks if it's 
> called "-bash". This is documented in man bash, but I couldn't find it 
> in man login or man agetty, not sure where else it might be written 
> down.

Thanks!

So does this mean that we could check in git.c if there is a leading "-" 
in argv[0]?  If so, then the builtin git-shell should be called by 
default.

At least I do not expect many instances of git being called with argv[0] 
starting with a "-"... :-)

Ciao,
Dscho

```

## Dmitry Potapov, 2008-08-25 20:26

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080825202628.GA8072@dpotapov.dyndns.org>
URL: https://gitlist.dev/e/20080825202628.GA8072%40dpotapov.dyndns.org
In-Reply-To: <alpine.DEB.1.00.0808252015080.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
On Mon, Aug 25, 2008 at 08:17:12PM +0200, Johannes Schindelin wrote:
> 
> Does it not strike you as odd, then, that "sh" -- by far the most common 
> login shell -- does not live in /usr/sbin/?

Not at all. "sh" is *often* run directly from the command line. Without
it being in PATH, system(3) and many other things would not work, but
no one tuns git-shell as the real shell to do some job.

Dmitry

```

## Johannes Schindelin, 2008-08-25 20:28

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <alpine.DEB.1.00.0808252225520.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808252225520.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <alpine.DEB.1.00.0808252206150.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
Hi,

On Mon, 25 Aug 2008, Johannes Schindelin wrote:

> On Mon, 25 Aug 2008, Mikael Magnusson wrote:
> 
> > 2008/8/25 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> >
> > > On Mon, 25 Aug 2008, Paolo Bonzini wrote:
> > >
> > >> > That would involve you actually finding out what's happening, 
> > >> > though.
> > >>
> > >> He said so:
> > >>
> > >> > test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
> > >> >
> > >> > just makes ssh loop asking for a password, logging
> > >> >
> > >> > "User test not allowed because shell /usr/bin/git shell does not 
> > >> > exist"
> > >
> > > Okay, so this means that you cannot pass arguments to the login shell. 
> > > Makes me wonder... I had the impression that bash was called with 
> > > --login.
> > 
> > When you login, a '-' is prepended in argv[0], ie, bash checks if it's 
> > called "-bash". This is documented in man bash, but I couldn't find it 
> > in man login or man agetty, not sure where else it might be written 
> > down.
> 
> Thanks!
> 
> So does this mean that we could check in git.c if there is a leading "-" 
> in argv[0]?  If so, then the builtin git-shell should be called by 
> default.
> 
> At least I do not expect many instances of git being called with argv[0] 
> starting with a "-"... :-)

Oh, well.  I just tested again, and slapped my head when it did not work, 
remembering that we do _not_ call Git as a login shell.  Instead, we call 
ssh with the "-c" option, which just passes it to the shell.  
Consequently, argv[0] does not get a "-" prepended.

I seem to remember that Hannes had some code to support "-c" as an 
indicator that Git should execute git-shell, but I just might have dreamt 
that, too.

Ciao,
Dscho

```

## Mike Hommey, 2008-08-25 20:40

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20080825204023.GA10280@glandium.org>
URL: https://gitlist.dev/e/20080825204023.GA10280%40glandium.org
In-Reply-To: <alpine.DEB.1.00.0808252015080.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
On Mon, Aug 25, 2008 at 08:17:12PM +0200, Johannes Schindelin wrote:
> Hi,
> 
> On Mon, 25 Aug 2008, Dmitry Potapov wrote:
> 
> > On Mon, Aug 25, 2008 at 9:08 PM, Petr Baudis <pasky@suse.cz> wrote:
> > >
> > > Can we agree that direct calls of libexec stuff should never be part 
> > > of the "official" interface (i.e. not workarounds for deprecated 
> > > usage)?
> > 
> > Agreed. It looks somewhat strange to type the libexec path in 
> > /etc/passwd.
> 
> FWIW I do not agree.  IMNHO libexec/ is just a way to organize executable 
> parts of any software package that are usually not called from the command 
> line.  And a login shell qualifies for that.
> 
> > > Considering that calling the git-shell executable directly is the 
> > > _only_ sensible way of using this interface, it should follow that it 
> > > has to be in /usr/bin, no matter if users type this command or not.
> > 
> > Perhaps, /usr/sbin would be a better place, as it is intended only for 
> > system administration binaries.
> 
> Does it not strike you as odd, then, that "sh" -- by far the most common 
> login shell -- does not live in /usr/sbin/?

But nologin is in /usr/sbin.

Mike

```

## Johannes Schindelin, 2008-08-25 20:51

Subject: [PATCH 1/2] git wrapper: Make while loop more reader-friendly
Message-ID: <alpine.DEB.1.00.0808252248150.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808252248150.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <alpine.DEB.1.00.0808252225520.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```

It is not a good practice to prefer performance over readability in
something as performance uncritical as finding the trailing slash
of argv[0].

So avoid head-scratching by making the loop user-readable, and not
hyper-performance-optimized.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	The original version threatened to cause eye-cancer with this
	developer, so that I had to run to the physician real quick.
	That was quite hard, as no ophtalmologist seemed to be in
	office at 10:30pm.  But I found a real good witch, and she
	diagnozed me as healthy.

 git.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index a647741..2fd74c4 100644
--- a/git.c
+++ b/git.c
@@ -427,9 +427,8 @@ int main(int argc, const char **argv)
 	 * name, and the dirname as the default exec_path
 	 * if we don't have anything better.
 	 */
-	do
-		--slash;
-	while (cmd <= slash && !is_dir_sep(*slash));
+	while (cmd <= slash && !is_dir_sep(*slash))
+		slash--;
 	if (slash < cmd) {
 		cmd = lookup_program_in_path(cmd);
 		for (slash = (char *)cmd + strlen(cmd) - 1;
-- 
1.6.0.211.ga840e.dirty

```

## Johannes Schindelin, 2008-08-25 20:52

Subject: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <alpine.DEB.1.00.0808252251450.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808252251450.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <alpine.DEB.1.00.0808252248150.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```

When a program is called via ssh's '-c' option, the login shell is called 
on the remote computer, with the given arguments.  In the case that Git 
was specified as login shell in /etc/passwd, Git used to complain that it 
does not know the '-c' option and die.

This commit assumes that '-c' indicates that Git was specified as
a login shell, and hands off to git-shell.

Noticed by Tommi Virtanen.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	This should be pretty uncontroversial, as it turns a former
	error into something useful.

	However, I would not know where in the documentation (in addition
	to git-shell.txt, I guess), this change should be described.

 git.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 2fd74c4..b16736a 100644
--- a/git.c
+++ b/git.c
@@ -419,14 +419,23 @@ static void execv_dashed_external(const char **argv)
 int main(int argc, const char **argv)
 {
 	const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
-	char *slash = (char *)cmd + strlen(cmd);
+	char *slash;
 	int done_alias = 0;
 
 	/*
+	 * When Git is called with "-c", it is either an error, or Git
+	 * was specified as a login shell in /etc/passwd.  Assuming the
+	 * latter, we continue with git-shell.
+	 */
+	if (argc > 2 && !strcmp(argv[1], "-c"))
+		cmd = "git-shell";
+
+	/*
 	 * Take the basename of argv[0] as the command
 	 * name, and the dirname as the default exec_path
 	 * if we don't have anything better.
 	 */
+	slash = (char *)cmd + strlen(cmd);
 	while (cmd <= slash && !is_dir_sep(*slash))
 		slash--;
 	if (slash < cmd) {
-- 
1.6.0.211.ga840e.dirty

```

## Tommi Virtanen, 2008-08-25 21:03

Subject: Re: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <20080825210345.GE14930@eagain.net>
URL: https://gitlist.dev/e/20080825210345.GE14930%40eagain.net
In-Reply-To: <alpine.DEB.1.00.0808252251450.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
On Mon, Aug 25, 2008 at 10:52:46PM +0200, Johannes Schindelin wrote:
> When a program is called via ssh's '-c' option, the login shell is called 
> on the remote computer, with the given arguments.  In the case that Git 
> was specified as login shell in /etc/passwd, Git used to complain that it 
> does not know the '-c' option and die.
> 
> This commit assumes that '-c' indicates that Git was specified as
> a login shell, and hands off to git-shell.
> 
> Noticed by Tommi Virtanen.

My imagination is insufficient in coming up with an uglier kludge, and
I sincerely hope my name isn't associated with this in any way.

-- 
:(){ :|:&};:

```

## Johannes Schindelin, 2008-08-25 22:05

Subject: Re: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <alpine.DEB.1.00.0808260001390.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808260001390.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <20080825210345.GE14930@eagain.net>

```
Hi,

On Tue, 26 Aug 2008, Tommi Virtanen wrote:

> On Mon, Aug 25, 2008 at 10:52:46PM +0200, Johannes Schindelin wrote:
> > When a program is called via ssh's '-c' option, the login shell is called 
> > on the remote computer, with the given arguments.  In the case that Git 
> > was specified as login shell in /etc/passwd, Git used to complain that it 
> > does not know the '-c' option and die.
> > 
> > This commit assumes that '-c' indicates that Git was specified as
> > a login shell, and hands off to git-shell.
> > 
> > Noticed by Tommi Virtanen.
> 
> My imagination is insufficient in coming up with an uglier kludge, and
> I sincerely hope my name isn't associated with this in any way.

I have no problems deleting your name from the commit message.  None at 
all.  Even if you actually did notice the issue.

I do disagree with you that it is a kludge though.  I think it makes 
complete sense to add this to Documentation/git.txt in addition to other 
documentation that is lacking from my patch, though:

-- snip --
-c <command>::
	execute <command> in git-shell.
-- snap --

Ciao,
Dscho

```

## Tommi Virtanen, 2008-08-25 22:20

Subject: Re: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <20080825222002.GF14930@eagain.net>
URL: https://gitlist.dev/e/20080825222002.GF14930%40eagain.net
In-Reply-To: <alpine.DEB.1.00.0808260001390.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
On Tue, Aug 26, 2008 at 12:05:21AM +0200, Johannes Schindelin wrote:
> I do disagree with you that it is a kludge though.  I think it makes 
> complete sense to add this to Documentation/git.txt in addition to other 
> documentation that is lacking from my patch, though:
> 
> -- snip --
> -c <command>::
> 	execute <command> in git-shell.
> -- snap --

All I'm going to say is that that's not the way you build trustable
software. You take a minimal interface and restrict untrusted users to
that, you don't add a feature to the widest possible interface..

-- 
:(){ :|:&};:

```

## Johannes Schindelin, 2008-08-26 00:52

Subject: Re: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <alpine.DEB.1.00.0808260249090.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808260249090.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <20080825222002.GF14930@eagain.net>

```
Hi,

On Tue, 26 Aug 2008, Tommi Virtanen wrote:

> On Tue, Aug 26, 2008 at 12:05:21AM +0200, Johannes Schindelin wrote:
> > I do disagree with you that it is a kludge though.  I think it makes 
> > complete sense to add this to Documentation/git.txt in addition to 
> > other documentation that is lacking from my patch, though:
> > 
> > -- snip --
> > -c <command>::
> > 	execute <command> in git-shell.
> > -- snap --
> 
> All I'm going to say is that that's not the way you build trustable 
> software. You take a minimal interface and restrict untrusted users to 
> that, you don't add a feature to the widest possible interface..

I do not get your point.

But then, I think I start not to care anymore, as I think your reasoning 
is bogus.  "widest possible interface", "trustable software", etc.  Sounds 
pretty buzzy-wordy to me.

Yeah, you would need to audit it.  Maybe you would even have to check for 
"*argv[0] == '-'" and set argv[0] to "git-shell" if so.  But buzz-wording 
just makes me go away and not listen anymore.

Whatever,
Dscho

```

## Matthieu Moy, 2008-08-26 06:53

Subject: Re: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <vpqy72ktgg7.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqy72ktgg7.fsf%40bauges.imag.fr
In-Reply-To: <alpine.DEB.1.00.0808260249090.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Tue, 26 Aug 2008, Tommi Virtanen wrote:
>
>> All I'm going to say is that that's not the way you build trustable 
>> software. You take a minimal interface and restrict untrusted users to 
>> that, you don't add a feature to the widest possible interface..
>
> I do not get your point.

With your patch, AAUI, one would put /usr/bin/git as a shell in
passwd. It's pretty clear that someone calling the shell with -c will
get the restriction of git-shell, but I'd hardly guarantee that the
shell in /etc/passwd will never be called without -c. At least, if the
user tries to login, he will execute git without argument (which
fortunately isn't serious, he'll just get the help message for git,
which is unhelpful but not dangerous). My knowledge in Unix isn't
sufficient to be sure there's no way at all to call git in a dangerous
way here. With git-shell, it's much simpler to understand: either you
give -c, and you get the restricted command set, or you don't, and you
get nothing.

-- 
Matthieu

```

## Mike Ralphson, 2008-08-26 08:50

Subject: Re: [PATCH 1/2] git wrapper: Make while loop more reader-friendly
Message-ID: <e2b179460808260150p15b7da0ev913eced3709c2cd1@mail.gmail.com>
URL: https://gitlist.dev/e/e2b179460808260150p15b7da0ev913eced3709c2cd1%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0808252248150.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
2008/8/25 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
>
> It is not a good practice to prefer performance over readability in
> something as performance uncritical as finding the trailing slash
> of argv[0].
>
> So avoid head-scratching by making the loop user-readable, and not
> hyper-performance-optimized.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>
>  git.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/git.c b/git.c
> index a647741..2fd74c4 100644
> --- a/git.c
> +++ b/git.c
> @@ -427,9 +427,8 @@ int main(int argc, const char **argv)
>         * name, and the dirname as the default exec_path
>         * if we don't have anything better.
>         */
> -       do
> -               --slash;
> -       while (cmd <= slash && !is_dir_sep(*slash));
> +       while (cmd <= slash && !is_dir_sep(*slash))
> +               slash--;
>        if (slash < cmd) {
>                cmd = lookup_program_in_path(cmd);
>                for (slash = (char *)cmd + strlen(cmd) - 1;
> --
> 1.6.0.211.ga840e.dirty

Isn't it more likely that this form was chosen to indicate that the
loop body was expected to execute at least once, rather than zero or
more times?

Mike

```

## Junio C Hamano, 2008-08-26 17:43

Subject: Re: [PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'
Message-ID: <7vod3facz7.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vod3facz7.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <vpqy72ktgg7.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> On Tue, 26 Aug 2008, Tommi Virtanen wrote:
>>
>>> All I'm going to say is that that's not the way you build trustable 
>>> software. You take a minimal interface and restrict untrusted users to 
>>> that, you don't add a feature to the widest possible interface..
>>
>> I do not get your point.
>
> With your patch, AAUI, one would put /usr/bin/git as a shell in
> passwd....

Well, it was sheer stupidity of mine.

Let's stop this and apply this patch instead.  The patch text is obvious
so I won't quote.

-- * --
From: Junio C Hamano <gitster@pobox.com>
Date: Mon, 25 Aug 2008 22:39:17 -0700
Subject: [PATCH] Revert "Build-in "git-shell""

This reverts commit daa0cc9a92c9c2c714aa5f7da6d0ff65b93e0698.
It was a stupid idea to do this; when run as a log-in shell,
it is spawned with argv[0] set to "-git-shell", so the usual
name-based dispatch would not work to begin with.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

 Makefile        |    2 +-
 builtin-shell.c |   90 -------------------------------------------------------
 builtin.h       |    1 -
 git.c           |    1 -
 shell.c         |   89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 90 insertions(+), 93 deletions(-)
-- 
1.6.0.1.113.g0a79b

```

## Dmitry V. Levin, 2008-10-28 11:11

Subject: Re: [PATCH] "git shell" won't work, need "git-shell"
Message-ID: <20081028111157.GD1682@wo.int.altlinux.org>
URL: https://gitlist.dev/e/20081028111157.GD1682%40wo.int.altlinux.org
In-Reply-To: <20080824202325.GA14930@eagain.net>

```
Hi,

Please apply this compatibility fix (commit v1.6.0.1-90-g27a6ed4)
to maint as well.

On Sun, Aug 24, 2008 at 11:23:25PM +0300, Tommi Virtanen wrote:
> >From 8e7935231e8a91d470b3a4a2310803031ef49fc4 Mon Sep 17 00:00:00 2001
> From: Tommi Virtanen <tv@eagain.net>
> Date: Sun, 24 Aug 2008 23:20:33 +0300
> Subject: [PATCH] Install git-shell in bindir, again.
> 
> /etc/passwd shell field must be something execable, you can't enter
> "/usr/bin/git shell" there. git-shell must be present as a separate
> executable, or it is useless.
> 
> Signed-off-by: Tommi Virtanen <tv@eagain.net>
> ---
> 
> Hi. Recent changes moved away from "git-foo" to "git foo", except for
> some commands that needed backwards compatibility. However, git-shell
> as a separate binary was removed. I hope you will reinstante git-shell
> as a publicly visible binary in bin. Here's why:
> 
> The shell field in /etc/passwd is *exec*ed, not interpreted via sh -c
> or some such. For example, source of Debian's shadow, containing
> /bin/login:
> 
> libmisc/shell.c:80:	execle (file, arg, (char *) 0, envp);
> 
> I also tested this for real, and having a
> 
> test:x:1001:1001:,,,:/home/test:/usr/bin/git-shell
> 
> line works, and
> 
> test:x:1001:1001:,,,:/home/test:/usr/bin/git shell
> 
> just makes ssh loop asking for a password, logging
> 
> "User test not allowed because shell /usr/bin/git shell does not exist"
> 
> So, as far as I understand, as it currently is, "git shell" is utterly
> useless for what it was meant to do. Restoring "git-shell" will fix
> it.
> 
>  Makefile |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 53ab4b5..24d5809 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1351,7 +1351,7 @@ install: all
>  	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
>  	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
>  	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
> -	$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X '$(DESTDIR_SQ)$(bindir_SQ)'
> +	$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X git-shell$X '$(DESTDIR_SQ)$(bindir_SQ)'
>  	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
>  	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
>  ifndef NO_TCLTK
> -- 
> 1.6.0.2.g2ebc0.dirty


-- 
ldv

```
