[PATCH]: Allow SSHD to install as service under WIndows 9x/Me

Corinna Vinschen vinschen at redhat.com
Wed Nov 21 00:13:59 EST 2001


On Tue, Nov 20, 2001 at 02:01:19PM +0100, Corinna Vinschen wrote:
> Hi,
> 
> the following patch is a (hopefully least intrusive) extension
> when sshd is started so that it daemonizes itself.  In that case
> Windows 9x/Me has a slight problem with sshd as soon as the current
> user logs off.  The sshd daemon will be killed as well.  Since 
> installing services is very different between NT and 9x, the way
> used for NT boxes isn't working well for 9x.  For that reason
> several 9x users have asked for a solution which allows _real_
> daemonizing sshd on their boxes.  The following patch allows to do that.
> 
> When the function daemon() forks, the child process is registered as a
> service when started on a 9x system.  The functionality is outsourced
> to bsd-cygwin_util.c, the daemon.c code just contains a conditionalized
> call to the new function.  Hope, that's ok.
> 
> Additionally I added a patch to contrib/cygwin/README, which just fixes
> a typo.
> 
> Thanks in advance,
> Corinna

Sorry.  I just found another error in the README and I thought it
might be better to add a hint which discribes the new functionality
for 9x users.  So the following patch substitutes the previous one.

Thanks,
Corinna

Index: contrib/cygwin/README
===================================================================
RCS file: /cvs/openssh_cvs/contrib/cygwin/README,v
retrieving revision 1.6
diff -u -p -r1.6 README
--- contrib/cygwin/README	2001/07/18 16:25:42	1.6
+++ contrib/cygwin/README	2001/11/20 13:12:39
@@ -1,6 +1,14 @@
 This package is the actual port of OpenSSH to Cygwin 1.3.
 
 ===========================================================================
+Important change since 3.0.1p1-2:
+
+This version introduces the ability to register sshd as service on
+Windows 9x/Me systems.  This is done only when the options -D and/or
+-d are not given.
+===========================================================================
+
+===========================================================================
 Important change since 2.9p2:
 
 Since Cygwin is able to switch user context without password beginning
@@ -162,12 +170,10 @@ configure are used for the Cygwin binary
 
 	--prefix=/usr \
 	--sysconfdir=/etc \
-	--libexecdir='${exec_prefix}/sbin \
-	--with-pcre
+	--libexecdir='${exec_prefix}/sbin'
 
 You must have installed the zlib, openssl and regex packages to
-be able to build OpenSSH! The `--with-pcre' option requires
-the installation of the pcre package.
+be able to build OpenSSH!
 
 Please send requests, error reports etc. to cygwin at cygwin.com.
 
Index: openbsd-compat/bsd-cygwin_util.c
===================================================================
RCS file: /cvs/openssh_cvs/openbsd-compat/bsd-cygwin_util.c,v
retrieving revision 1.5
diff -u -p -r1.5 bsd-cygwin_util.c
--- openbsd-compat/bsd-cygwin_util.c	2001/07/18 16:19:49	1.5
+++ openbsd-compat/bsd-cygwin_util.c	2001/11/20 13:12:39
@@ -139,4 +139,26 @@ int check_ntsec(const char *filename)
 	return 0;
 }
 
+void register_9x_service(void)
+{
+        HINSTANCE kerneldll;
+        DWORD (*RegisterServiceProcess)(DWORD, DWORD);
+
+	/* The service register mechanism in 9x/Me is pretty different from
+	 * NT/2K/XP.  In NT/2K/XP we're using a special service starter
+	 * application to register and control sshd as service.  This method
+	 * doesn't play nicely with 9x/Me.  For that reason we register here
+	 * as service when running under 9x/Me.  This function is only called
+	 * by the child sshd when it's going to daemonize.
+	 */
+	if (is_winnt)
+		return;
+	if (! (kerneldll = LoadLibrary("KERNEL32.DLL")))
+		return;
+	if (! (RegisterServiceProcess = (DWORD (*)(DWORD, DWORD))
+			  GetProcAddress(kerneldll, "RegisterServiceProcess")))
+		return;
+	RegisterServiceProcess(0, 1);
+}
+
 #endif /* HAVE_CYGWIN */
Index: openbsd-compat/bsd-cygwin_util.h
===================================================================
RCS file: /cvs/openssh_cvs/openbsd-compat/bsd-cygwin_util.h,v
retrieving revision 1.4
diff -u -p -r1.4 bsd-cygwin_util.h
--- openbsd-compat/bsd-cygwin_util.h	2001/04/13 14:28:43	1.4
+++ openbsd-compat/bsd-cygwin_util.h	2001/11/20 13:12:39
@@ -26,6 +26,7 @@ int binary_open(const char *filename, in
 int binary_pipe(int fd[2]);
 int check_nt_auth(int pwd_authenticated, uid_t uid);
 int check_ntsec(const char *filename);
+void register_9x_service(void);
 
 #define open binary_open
 #define pipe binary_pipe
Index: openbsd-compat/daemon.c
===================================================================
RCS file: /cvs/openssh_cvs/openbsd-compat/daemon.c,v
retrieving revision 1.1
diff -u -p -r1.1 daemon.c
--- openbsd-compat/daemon.c	2001/01/31 21:52:03	1.1
+++ openbsd-compat/daemon.c	2001/11/20 13:12:39
@@ -49,6 +49,9 @@ daemon(nochdir, noclose)
 	case -1:
 		return (-1);
 	case 0:
+#ifdef HAVE_CYGWIN
+		register_9x_service();
+#endif
 		break;
 	default:
 #ifdef HAVE_CYGWIN


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



More information about the openssh-unix-dev mailing list