[PATCH/cygwin] Fix cygwin specific Makefile and a bug in the ssh-host-config script

Corinna Vinschen vinschen at redhat.com
Sat Nov 8 02:56:21 EST 2008


On Nov  7 09:23, Daniel Kahn Gillmor wrote:
> On Fri 2008-11-07 05:54:58 -0500, Corinna Vinschen wrote:
> 
> > diff -u -p -r1.22 ssh-host-config
> > --- contrib/cygwin/ssh-host-config	14 Jul 2008 02:12:54 -0000	1.22
> > +++ contrib/cygwin/ssh-host-config	7 Nov 2008 10:49:30 -0000
> > @@ -456,7 +456,7 @@ done
> >  
> >  # Check for running ssh/sshd processes first. Refuse to do anything while
> >  # some ssh processes are still running
> > -if ps -ef | grep -v grep | grep -q ssh
> > +if ps -ef | grep -v grep | grep -q 'sshd*$'
> >  then
> >    echo
> >    csih_error "There are still ssh processes running. Please shut them down first."
> 
> This regular expression seems to match any line that ends in
> sshddddd...  That is, sshd* matches sshd followed by any number of d
> characters.  Is that really what is intended?

Thanks for pointing this out.  That's not intended of course.

> Also, it seems that this check (with the grep -v grep) will also
> *miss* any processes owned by usernames that contain the string
> "grep".

Huh!  Another good point.  The script was apparently just lucky that
this doesn't occur very often.  Especially since the grep command
isn't found by the grep -q expression anyway due to the way ps -ef
prints the processes.

> On my debian box, some sshd processes look like this due to privsep
> (e.g. for the sales representative for bags and backpacks):
> 
> bagrep    26479 26476  0 01:02 ?        00:00:00 sshd: bagrep at pts/5
> 
> If you're trying to match this kind of process, it would get missed by
> the above invocation.

That doesn't happen on Cygwin.  ps -ef always prints the full path to
the application as the rightmost string, without any Windows .exe suffix
and without any arguments.  So what the script has to catch are the
strings ssh$ and sshd$.  The above quick fix was just the first and
easiest and (*blush*) laziest which came to mind.

So it appears a much better solution is

  if ps -ef | grep -q 'sshd\?$'

The patch to ssh-host-config would be:


Index: contrib/cygwin/ssh-host-config
===================================================================
RCS file: /cvs/openssh/contrib/cygwin/ssh-host-config,v
retrieving revision 1.22
diff -u -p -r1.22 ssh-host-config
--- contrib/cygwin/ssh-host-config	14 Jul 2008 02:12:54 -0000	1.22
+++ contrib/cygwin/ssh-host-config	7 Nov 2008 15:43:52 -0000
@@ -456,7 +456,7 @@ done
 
 # Check for running ssh/sshd processes first. Refuse to do anything while
 # some ssh processes are still running
-if ps -ef | grep -v grep | grep -q ssh
+if ps -ef | grep -q 'sshd\?$'
 then
   echo
   csih_error "There are still ssh processes running. Please shut them down first."

I just hope I didn't miss anything else...


Thanks again,
Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


More information about the openssh-unix-dev mailing list