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

Corinna Vinschen vinschen at redhat.com
Wed Nov 21 00:01:19 EST 2001


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

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 12:44:22
@@ -162,7 +162,7 @@ configure are used for the Cygwin binary
 
 	--prefix=/usr \
 	--sysconfdir=/etc \
-	--libexecdir='${exec_prefix}/sbin \
+	--libexecdir='${exec_prefix}/sbin' \
 	--with-pcre
 
 You must have installed the zlib, openssl and regex packages to
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 12:44:23
@@ -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 12:44:23
@@ -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 12:44:23
@@ -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