[PATCH]: contrib/cygwin/ssh-host-config

Corinna Vinschen vinschen at redhat.com
Wed Mar 7 21:15:07 EST 2001


Hi,

below is a patch to contrib/cygwin/ssh-host-config and the corresponding
README in the same dir. It adds a `--port' option to the config script
to allow setting another port than 22 for sshd.

Additionally the script used to add `sshd 22/tcp' to the services file
while the IANA proposes `ssh 22/tcp' and `ssh 22/udp' as services entries.
The new version removes old `sshd' entries from services and inetd.conf
and substitutes them with `ssh' entries.

The patch file is relative to the contrib/cygwin dir:

Index: README
===================================================================
RCS file: /cvs/openssh_cvs/contrib/cygwin/README,v
retrieving revision 1.2
diff -u -p -r1.2 README
--- README	2001/01/19 05:37:32	1.2
+++ README	2001/03/07 10:13:00
@@ -15,12 +15,8 @@ filesystem (which is recommended) due to
 features of the FAT/FAT32 filesystems.
 ===========================================================================
 
-Since this package is part of the base distribution now, the location
-of the files has changed from /usr/local to /usr. The global configuration
-files are in /etc now.
-
-If you are installing OpenSSH the first time, you can generate
-global config files and server keys by running
+If you are installing OpenSSH the first time, you can generate global config
+files and server keys by running
    
    /usr/bin/ssh-host-config
 
@@ -39,6 +35,7 @@ Options:
     --debug      -d        Enable shell's debug output.
     --yes        -y        Answer all questions with "yes" automatically.
     --no         -n        Answer all questions with "no" automatically.
+    --port       -p <n>    sshd listens on port n.
 
 You can create the private and public keys for a user now by running
 
Index: ssh-host-config
===================================================================
RCS file: /cvs/openssh_cvs/contrib/cygwin/ssh-host-config,v
retrieving revision 1.1
diff -u -p -r1.1 ssh-host-config
--- ssh-host-config	2001/01/19 05:37:32	1.1
+++ ssh-host-config	2001/03/07 10:13:04
@@ -16,6 +16,7 @@ OLDSYSCONFDIR=${OLDPREFIX}/etc
 
 progname=$0
 auto_answer=""
+port_number=22
 
 request()
 {
@@ -67,6 +68,11 @@ do
     auto_answer=no
     ;;
 
+  -p | --port )
+    port_number=$1
+    shift
+    ;;
+
   *)
     echo "usage: ${progname} [OPTION]..."
     echo
@@ -76,6 +82,7 @@ do
     echo "    --debug  -d     Enable shell's debug output."
     echo "    --yes    -y     Answer all questions with \"yes\" automatically."
     echo "    --no     -n     Answer all questions with \"no\" automatically."
+    echo "    --port   -p <n> sshd listens on port n."
     echo
     exit 1
     ;;
@@ -254,6 +261,11 @@ Host *
         IdentityFile ~/.ssh/id_rsa
         IdentityFile ~/.ssh/id_dsa
 EOF
+  if [ "$port_number" != "22" ]
+  then
+    echo "Host localhost" >> ${SYSCONFDIR}/ssh_config
+    echo "    Port $port_number" >> ${SYSCONFDIR}/ssh_config
+  fi
 fi
 
 # Check if sshd_config exists. If yes, ask for overwriting
@@ -278,7 +290,7 @@ then
   cat > ${SYSCONFDIR}/sshd_config << EOF
 # This is ssh server systemwide configuration file.
 
-Port 22
+Port $port_number
 #
 Protocol 2,1
 ListenAddress 0.0.0.0
@@ -330,7 +342,7 @@ UseLogin no
 EOF
 fi
 
-# Add port 22/tcp to services
+# Care for services file
 _sys="`uname -a`"
 _nt=`expr "$_sys" : "CYGWIN_NT"`
 if [ $_nt -gt 0 ]
@@ -344,33 +356,86 @@ fi
 _services=`cygpath -u "${_wservices}"`
 _serv_tmp=`cygpath -u "${_wserv_tmp}"`
 
-mount -b -f "${_wservices}" "${_services}"
-mount -b -f "${_wserv_tmp}" "${_serv_tmp}"
+mount -t -f "${_wservices}" "${_services}"
+mount -t -f "${_wserv_tmp}" "${_serv_tmp}"
+
+# Remove sshd 22/port from services
+if [ `grep -q 'sshd[ \t][ \t]*22' "${_services}"; echo $?` -eq 0 ]
+then
+  grep -v 'sshd[ \t][ \t]*22' "${_services}" > "${_serv_tmp}"
+  if [ -f "${_serv_tmp}" ]
+  then 
+    if mv "${_serv_tmp}" "${_services}"
+    then
+      echo "Removing sshd from ${_services}"
+    else
+      echo "Removing sshd from ${_services} failed\!"
+    fi 
+    rm -f "${_serv_tmp}"
+  else
+    echo "Removing sshd from ${_services} failed\!"
+  fi
+fi
 
-if [ `grep -q 'sshd[ \t][ \t]*22' "${_services}"; echo $?` -ne 0 ]
+# Add ssh 22/tcp  and ssh 22/udp to services
+if [ `grep -q 'ssh[ \t][ \t]*22' "${_services}"; echo $?` -ne 0 ]
 then
-  awk '{ if ( $2 ~ /^23\/tcp/ ) print "sshd               22/tcp                           #SSH daemon\r"; print $0; }' < "${_services}" > "${_serv_tmp}"
+  awk '{ if ( $2 ~ /^23\/tcp/ ) print "ssh                22/tcp                           #SSH Remote Login Protocol\nssh                22/udp                           #SSH Remote Login Protocol"; print $0; }' < "${_services}" > "${_serv_tmp}"
   if [ -f "${_serv_tmp}" ]
   then
     if mv "${_serv_tmp}" "${_services}"
     then
-      echo "Added sshd to ${_services}"
+      echo "Added ssh to ${_services}"
     else
-      echo "Adding sshd to ${_services} failed\!"
+      echo "Adding ssh to ${_services} failed\!"
     fi
     rm -f "${_serv_tmp}"
   else
-    echo "Adding sshd to ${_services} failed\!"
+    echo "Adding ssh to ${_services} failed\!"
   fi
 fi
 
 umount "${_services}"
 umount "${_serv_tmp}"
 
-# Add sshd line to inetd.conf
-if [ -f /etc/inetd.conf ]
-then
-  grep -q "^[# \t]*sshd" /etc/inetd.conf || echo "# sshd  stream  tcp     nowait  root    /usr/sbin/sshd -i" >> /etc/inetd.conf
+# Care for inetd.conf file
+_inetcnf="/etc/inetd.conf"
+_inetcnf_tmp="/etc/inetd.conf.$$"
+
+if [ -f "${_inetcnf}" ]
+then
+  # Check if ssh service is already in use as sshd
+  with_comment=1
+  grep -q '^[ \t]*sshd' "${_inetcnf}" && with_comment=0
+  # Remove sshd line from inetd.conf
+  if [ `grep -q '^[# \t]*sshd' "${_inetcnf}"; echo $?` -eq 0 ]
+  then
+    grep -v '^[# \t]*sshd' "${_inetcnf}" >> "${_inetcnf_tmp}"
+    if [ -f "${_inetcnf_tmp}" ]
+    then
+      if mv "${_inetcnf_tmp}" "${_inetcnf}"
+      then
+        echo "Removed sshd from ${_inetcnf}"
+      else
+        echo "Removing sshd from ${_inetcnf} failed\!"
+      fi
+      rm -f "${_inetcnf_tmp}"
+    else
+      echo "Removing sshd from ${_inetcnf} failed\!"
+    fi
+  fi
+
+  # Add ssh line to inetd.conf
+  if [ `grep -q '^[# \t]*ssh' "${_inetcnf}"; echo $?` -ne 0 ]
+  then
+    if [ "${with_comment}" -eq 0 ]
+    then
+      echo 'ssh  stream  tcp     nowait  root    /usr/sbin/sshd -i' >> "${_inetcnf}"
+    else
+      echo '# ssh  stream  tcp     nowait  root    /usr/sbin/sshd -i' >> "${_inetcnf}"
+    fi
+    echo "Added ssh to ${_inetcnf}"
+  fi
 fi
 
 if [ "${old_install}" = "1" ]

Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Developer
Red Hat, Inc.
mailto:vinschen at redhat.com





More information about the openssh-unix-dev mailing list