public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Win98se and using SSHD as a TRUE service
  2001-11-11  8:26 Win98se and using SSHD as a TRUE service JAmes Coleman
@ 2001-11-11  8:26 ` Gerald Villemure
  2001-11-11  8:26   ` JAmes Coleman
  2001-11-11  8:26   ` Corinna Vinschen
  0 siblings, 2 replies; 6+ messages in thread
From: Gerald Villemure @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin, JAmes Coleman

The idea here is to have SSHD start as a true service in Win9x such that it
will NOT dies when a user logs out.  To do this the process must make the
system call "RegisterServiceProcess" which only exist in Win95, Win98 and
WinMe.

James Coleman:  I tryied adding the #include "windows.h" line but I still
have compile errors:

$ make
gcc -g -O2 -Wall -Wpointer-arith -Wno-uninitialized -I. -I.. -I. -I./..  -DH
AVE_CONFIG_H -c daemon.c
daemon.c: In function `daemon':
daemon.c:67: parse error before `kerneldll'
daemon.c:68: `kerneldll' undeclared (first use in this function)
daemon.c:68: (Each undeclared identifier is reported only once
daemon.c:68: for each function it appears in.)
daemon.c:72: parse error before `('
daemon.c:73: `RegisterService' undeclared (first use in this function)
daemon.c:79: `RegisterService' used prior to declaration
daemon.c:79: warning: implicit declaration of function `RegisterService'
make: *** [daemon.o] Error 1

The source is at the end of this email.

The problem may be easy to spot but its beyond me.

I am trying to fix the right file for this right?

Thanks for any help,
Gérald

----- Original Message -----
From: "JAmes Coleman" <james.coleman@s3group.com>
To: <cygwin@cygwin.com>; <GVillemure@ik.ca>
Sent: Wednesday, November 14, 2001 2:41 PM
Subject: Re: Win98se and using SSHD as a TRUE service


>
> What are your compile errors?
> The whole point of cygnus is (kindof) mixing windows & unix code.
> Perhaps adding #include <windows.h> would solve your problems?

---- souce file --------
$ cat daemon.c
/*-
 * Copyright (c) 1990, 1993
 *      The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include "includes.h"
#include "windows.h"

#ifndef HAVE_DAEMON

#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: daemon.c,v 1.2 1996/08/19 08:22:13 tholo
Exp $";
#endif /* LIBC_SCCS and not lint */

int
daemon(nochdir, noclose)
        int nochdir, noclose;
{
        int fd;

        switch (fork()) {
        case -1:
                return (-1);
        case 0:
                break;
        default:
#ifdef HAVE_CYGWIN
                /*
                 * This sleep avoids a race condition which kills the
                 * child process if parent is started by a NT/W2K service.
                 */
                sleep(1);

                /*
                 * This is the code that I took from WinVNC
                 * The best solution would be to enclose this in a IF Win9x
clause
                 * that is if I knew propers C syntax I could do this
                 */

                        // Obtain a handle to the kernel library
                        HINSTANCE kerneldll = LoadLibrary("KERNEL32.DLL");
                        if (kerneldll == NULL)
                                break;

                        // And find the RegisterServiceProcess function
                        DWORD (*RegisterService)(DWORD, DWORD);
                        RegisterService = (DWORD (*)(DWORD, DWORD))
                                GetProcAddress(kerneldll,
"RegisterServiceProcess");
                        if (RegisterService == NULL)
                                break;

                        // Register this process with the OS as a service!
                        RegisterService(NULL, 1);


#endif
                _exit(0);
        }

        if (setsid() == -1)
                return (-1);

        if (!nochdir)
                (void)chdir("/");

        if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
                (void)dup2(fd, STDIN_FILENO);
                (void)dup2(fd, STDOUT_FILENO);
                (void)dup2(fd, STDERR_FILENO);
                if (fd > 2)
                        (void)close (fd);
        }
        return (0);
}

#endif /* !HAVE_DAEMON */



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Win98se and using SSHD as a TRUE service
  2001-11-11  8:26   ` JAmes Coleman
@ 2001-11-11  8:26     ` Gerald Villemure
  0 siblings, 0 replies; 6+ messages in thread
From: Gerald Villemure @ 2001-11-11  8:26 UTC (permalink / raw)
  To: JAmes Coleman; +Cc: cygwin

----- Original Message -----
From: "JAmes Coleman" <james.coleman@s3group.com>
To: "Gerald Villemure" <GVillemure@ik.ca>
Cc: <cygwin@cygwin.com>
Sent: Thursday, November 15, 2001 12:18 PM
Subject: Re: Win98se and using SSHD as a TRUE service

-- stuff cut --

> The following compiles okay for me (with only the one error I introduced
> which you shouldn't have)

Ok I introduced your changes and I was able to complie SSHD.EXE.

Unfortunately it dosen't work.  When I checked with WinTOP the proccess is
still NOT listed as a service.

This is a show stopper for me.  For example if I am using SSHD on a machine
while the user is also on the machine and for some reason the user desides
to logout, then SSHD dies and my session with it... worse I can no loger get
back in since SSHD is dead!  So much for remote admin.

It should be noted that SSHD dose not die so long as I don't use it.  The
user can open and close a session on this machine without killing SSHD.  But
if I use SSHD, even if only for a second, then the next time the user logs
out SSHD will die.

The goal here for me is to use cygwin for remote administration.  Almost ALL
machines are Win98se and I can't change that fact.  This bug if you can call
it that realy has me dead in the water.

Unfortunatly I am a sysadmin, I am not a developer and I don't have the
skillset to fix this bug/problem myself.

Am I realy the only one that wants to use SSHD and Cygwin on Win9x
platforms?
Gérald


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Win98se and using SSHD as a TRUE service
  2001-11-11  8:26 ` Gerald Villemure
  2001-11-11  8:26   ` JAmes Coleman
@ 2001-11-11  8:26   ` Corinna Vinschen
  2001-11-11  8:26     ` Win98se and using SSHD as a TRUE service (solution) Gerald Villemure
  1 sibling, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin

On Thu, Nov 15, 2001 at 03:18:43AM +0100, Gerald Villemure wrote:
>         switch (fork()) {
>         case -1:
>                 return (-1);
>         case 0:
>                 break;
>         default:
> #ifdef HAVE_CYGWIN
>                 /*
>                  * This sleep avoids a race condition which kills the
>                  * child process if parent is started by a NT/W2K service.
>                  */
>                 sleep(1);
> 
>                 /*
>                  * This is the code that I took from WinVNC
>                  * The best solution would be to enclose this in a IF Win9x
> clause
>                  * that is if I knew propers C syntax I could do this
>                  */
> 
>                         // Obtain a handle to the kernel library
>                         HINSTANCE kerneldll = LoadLibrary("KERNEL32.DLL");
>                         if (kerneldll == NULL)
>                                 break;
> 
>                         // And find the RegisterServiceProcess function
>                         DWORD (*RegisterService)(DWORD, DWORD);
>                         RegisterService = (DWORD (*)(DWORD, DWORD))
>                                 GetProcAddress(kerneldll,
> "RegisterServiceProcess");
>                         if (RegisterService == NULL)
>                                 break;
> 
>                         // Register this process with the OS as a service!
>                         RegisterService(NULL, 1);
> 
> 
> #endif

You added the code to the parent's branch.  It's the child which
has to register as service.  Move the code (not the sleep(!))
to the `case 0:' branch, right before the `break;'.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Win98se and using SSHD as a TRUE service
@ 2001-11-11  8:26 JAmes Coleman
  2001-11-11  8:26 ` Gerald Villemure
  0 siblings, 1 reply; 6+ messages in thread
From: JAmes Coleman @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin, GVillemure


What are your compile errors?
The whole point of cygnus is (kindof) mixing windows & unix code.
Perhaps adding #include <windows.h> would solve your problems?

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Win98se and using SSHD as a TRUE service (solution)
  2001-11-11  8:26   ` Corinna Vinschen
@ 2001-11-11  8:26     ` Gerald Villemure
  0 siblings, 0 replies; 6+ messages in thread
From: Gerald Villemure @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Corinna Vinschen

----- Original Message -----
From: "Corinna Vinschen" <cygwin@cygwin.com>
To: <cygwin@cygwin.com>
Sent: Thursday, November 15, 2001 10:25 PM
Subject: Re: Win98se and using SSHD as a TRUE service


--stuff cut---

> You added the code to the parent's branch.  It's the child which
> has to register as service.  Move the code (not the sleep(!))
> to the `case 0:' branch, right before the `break;'.
>
> Corinna

Well Corinna.... THANK YOU, THANK YOU, THANK YOU!!!

I finaly has a viable remote admin solution for win9x boxes.  Needless to
say I am very happy about this.

Included is the new source for daemon.c which makes SSHD register itslef as
a service in Win9x boxes.

Its should be noted that only the master SSHD process is set at a service so
if you hapen to be loged on while the user quits his session you will be
bumped off.  The point is that NOW you can get back on the system and
manualy kill the zomby BASH proccess that was left behind.  No more fear of
being locked out of the system.

I would like to say a thanks to:

Max Bowsher
James Coleman
Corinna Vinschen

I could not have done it without you... "Merci beaucoup" as they say here in
Paris.

Ok here is the code:


$ cat daemon.c
/*-
 * Copyright (c) 1990, 1993
 *      The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

//#include "includes.h"
#include "windows.h"
#include <sys/types.h>
     #include <unistd.h>
#include <sys/types.h>
     #include <sys/stat.h>
     #include <fcntl.h>
#define HAVE_CYGWIN


#ifndef HAVE_DAEMON

#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: daemon.c,v 1.2 1996/08/19 08:22:13 tholo
Exp $";
#endif /* LIBC_SCCS and not lint */

int
daemon(nochdir, noclose)
        int nochdir, noclose;
{
        int fd;

        HINSTANCE kerneldll;
        DWORD (*RegisterService)(DWORD, DWORD);

        switch (fork()) {
        case -1:
                return (-1);
        case 0:
                kerneldll = LoadLibrary("KERNEL32.DLL");
                RegisterService = (DWORD (*)(DWORD, DWORD))
GetProcAddress(kerneldll, "RegisterServiceProcess");
                RegisterService(NULL, 1);
                break;
        default:
#ifdef HAVE_CYGWIN
                /*
                 * This sleep avoids a race condition which kills the
                 * child process if parent is started by a NT/W2K service.
                 */
                sleep(1);

#endif
                _exit(0);
        }

        if (setsid() == -1)
                return (-1);

        if (!nochdir)
                (void)chdir("/");

        if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
                (void)dup2(fd, STDIN_FILENO);
                (void)dup2(fd, STDOUT_FILENO);
                (void)dup2(fd, STDERR_FILENO);
                if (fd > 2)
                        (void)close (fd);
        }
        return (0);
}

#endif /* !HAVE_DAEMON */


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Win98se and using SSHD as a TRUE service
  2001-11-11  8:26 ` Gerald Villemure
@ 2001-11-11  8:26   ` JAmes Coleman
  2001-11-11  8:26     ` Gerald Villemure
  2001-11-11  8:26   ` Corinna Vinschen
  1 sibling, 1 reply; 6+ messages in thread
From: JAmes Coleman @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Gerald Villemure; +Cc: cygwin

Hi Gerald,

Gerald Villemure wrote:
> 
> The idea here is to have SSHD start as a true service in Win9x such that it
> will NOT dies when a user logs out.  To do this the process must make the
> system call "RegisterServiceProcess" which only exist in Win95, Win98 and
> WinMe.
> 
> James Coleman:  I tryied adding the #include "windows.h" line but I still
> have compile errors:
> 
> $ make
> gcc -g -O2 -Wall -Wpointer-arith -Wno-uninitialized -I. -I.. -I. -I./..  -DH
> AVE_CONFIG_H -c daemon.c
> daemon.c: In function `daemon':
> daemon.c:67: parse error before `kerneldll'
> daemon.c:68: `kerneldll' undeclared (first use in this function)
> daemon.c:68: (Each undeclared identifier is reported only once
> daemon.c:68: for each function it appears in.)
> daemon.c:72: parse error before `('
> daemon.c:73: `RegisterService' undeclared (first use in this function)
> daemon.c:79: `RegisterService' used prior to declaration
> daemon.c:79: warning: implicit declaration of function `RegisterService'
> make: *** [daemon.o] Error 1

I had a go at compiling what you sent, obviously I can't compile it
properly
 but I can test the syntax anyway.
 I just had to remove #include "includes.h"
 For me, gcc version 2.9-cygwin-990830, I got similar errors to you and
others 
 which I got rid of by fixing includes ... (except for one).

daemon.c: In function `daemon':
daemon.c:82: parse error before `kerneldll'
daemon.c:83: `kerneldll' undeclared (first use in this function)
daemon.c:83: (Each undeclared identifier is reported only once
daemon.c:83: for each function it appears in.)
daemon.c:87: parse error before `('
daemon.c:88: `RegisterService' undeclared (first use in this function)
daemon.c:95: `RegisterService' used prior to declaration
daemon.c:95: warning: implicit declaration of function `RegisterService'
daemon.c:108: `_PATH_DEVNULL' undeclared (first use in this function)


(I add the following includes)
//#include <includes.h>
#include <sys/types.h>
     #include <unistd.h>
#include <sys/types.h>
     #include <sys/stat.h>
     #include <fcntl.h>
#define HAVE_CYGWIN


ANYWAY

Two things .... (possibly caused by command line options?)

  1. compiler doesn't like // comments

  2. compiler doesn't like declaration of variables except at start of
function

The following compiles okay for me (with only the one error I introduced
which you shouldn't have)

int
daemon(nochdir, noclose)
        int nochdir, noclose;
{
        int fd;
        HINSTANCE kerneldll;
        DWORD (*RegisterService)(DWORD, DWORD);

        switch (fork()) {
        case -1:
                return (-1);
        case 0:
                break;
        default:
#ifdef HAVE_CYGWIN
                /*
                 * This sleep avoids a race condition which kills the
                 * child process if parent is started by a NT/W2K
service.
                 */
                sleep(1);

                /*
                 * This is the code that I took from WinVNC
                 * The best solution would be to enclose this in a IF
Win9x
clause
                 * that is if I knew propers C syntax I could do this
                 */

                         /* Obtain a handle to the kernel library */
                         kerneldll = LoadLibrary("KERNEL32.DLL");
                         if (kerneldll == NULL)
                                 break;
 
                         /* And find the RegisterServiceProcess function
*/
                         RegisterService = (DWORD (*)(DWORD, DWORD))
                                 GetProcAddress(kerneldll,
"RegisterServiceProcess");
                         if (RegisterService == NULL)
                                 break;
 
                         /* Register this process with the OS as a
service! */
                         RegisterService(NULL, 1);


#endif
                _exit(0);
        }

        if (setsid() == -1)
                return (-1);

        if (!nochdir)
                (void)chdir("/");

        if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
                (void)dup2(fd, STDIN_FILENO);
                (void)dup2(fd, STDOUT_FILENO);
                (void)dup2(fd, STDERR_FILENO);
                if (fd > 2)
                        (void)close (fd);
        }
        return (0);
}




> 
> The source is at the end of this email.
> 
> The problem may be easy to spot but its beyond me.

I can help a bit with C and a little with cygwin but I don't do all that
much
cygwin+windows programming.   Hopefully this is useful.

> 
> I am trying to fix the right file for this right?

:)

That's a very good question .... and I really don't know the answer to
it :-7

Last time I played with services was on msdos5.something!

> 
> Thanks for any help,
> Gérald
> 

Good Luck!

JAmes.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-11-15 22:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-11  8:26 Win98se and using SSHD as a TRUE service JAmes Coleman
2001-11-11  8:26 ` Gerald Villemure
2001-11-11  8:26   ` JAmes Coleman
2001-11-11  8:26     ` Gerald Villemure
2001-11-11  8:26   ` Corinna Vinschen
2001-11-11  8:26     ` Win98se and using SSHD as a TRUE service (solution) Gerald Villemure

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).