Okay, I am now reasonably satisfied that I have done my best job
debugging my rcp failures and would like the experts to take a peek.  I
tried running rshd under gdb, but it didn't work, so I began copious
syslog()ing.

        The problem manifests itself simply enough.  From another machine
(Cygwin, Solaris, or OSF/1):

otherbox$ rcp cygbox:/path/to/file .
rcp: lost connection
otherbox$ ls
otherbox$

        (OSF/1 does not print the "rcp: lost connection" message)

        Attached are my latest rshd.c and `cygcheck -s -v -r`.  The oddest
thing seems to happen, since it seems to die at the `if (port)`
statement.  syslog()s that wind up in the event viewer have "/*  I
PRINT  */" comments above them in rshd.c.

        The logical explanation is that the syslog() buffer is not flushing
and the process exits later than it appears.  Is this a possibility? 
If so, suggestions on flushing, please?  `man -a syslog` only gives me
logger(1) (twice! - should it?), so I'm kinda lost on the syslog thing,
especially in how it is adapted here (the API reference only lists it
as an "Other" implemented function), would be helpful.


        TiA!

/|/|ike


__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one Place.
http://shopping.yahoo.com/
/*-
 * Copyright (c) 1988, 1989, 1992, 1993, 1994
 *      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.
 */

#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1988, 1989, 1992, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
#endif /* not lint */

#ifndef lint
static char sccsid[] = "@(#)rshd.c      8.2 (Berkeley) 4/6/94";
#endif /* not lint */

/*
 * remote shell server:
 *      [port]\0
 *      remuser\0
 *      locuser\0
 *      command\0
 *      data
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#if !defined (__GNUC__) && defined (_AIX)
 #pragma alloca
#endif
#ifndef alloca /* Make alloca work the best possible way.  */
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not __GNUC__ */
#if HAVE_ALLOCA_H
#include <alloca.h>
#else /* not __GNUC__ or HAVE_ALLOCA_H */
#ifndef _AIX /* Already did AIX, up at the top.  */
char *alloca ();
#endif /* not _AIX */
#endif /* not HAVE_ALLOCA_H */
#endif /* not __GNUC__ */
#endif /* not alloca */

#include <sys/param.h>
#include <sys/ioctl.h>
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
#include <sys/socket.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#include <pwd.h>
#include <signal.h>
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <getopt.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

int     keepalive = 1;
int     check_all;
int     log_success;            /* If TRUE, log all successful accesses */
int     sent_null;

void     doit __P((struct sockaddr_in *));
void     error __P((const char *, ...));
char    *getstr __P((char *));
int      local_domain __P((const char *));
const char *topdomain __P((const char *));
void     usage __P((void));

#ifdef  KERBEROS
#include <kerberosIV/des.h>
#include <kerberosIV/krb.h>
#define VERSION_SIZE    9
#define SECURE_MESSAGE  "This rsh session is using DES encryption for all 
transmissions.\r\n"
#define OPTIONS         "alnkvxL"
char    authbuf[sizeof(AUTH_DAT)];
char    tickbuf[sizeof(KTEXT_ST)];
int     doencrypt, use_kerberos, vacuous;
Key_schedule    schedule;
#else
#define OPTIONS "alnL"
#endif

int
main(argc, argv)
        int argc;
        char *argv[];
{
        extern int __check_rhosts_file;
        struct linger linger;
        int ch, on = 1, fromlen;
        struct sockaddr_in from;

        openlog("rshd", LOG_PID | LOG_ODELAY, LOG_DAEMON);

        opterr = 0;
        while ((ch = getopt(argc, argv, OPTIONS)) != EOF)
                switch (ch) {
                case 'a':
                        check_all = 1;
                        break;
                case 'l':
                        __check_rhosts_file = 0;
                        break;
                case 'n':
                        keepalive = 0;
                        break;
#ifdef  KERBEROS
                case 'k':
                        use_kerberos = 1;
                        break;

                case 'v':
                        vacuous = 1;
                        break;

#ifdef CRYPT
                case 'x':
                        doencrypt = 1;
                        break;
#endif
#endif
                case 'L':
                        log_success = 1;
                        break;
                case '?':
                default:
                        usage();
                        break;
                }

        argc -= optind;
        argv += optind;

#ifdef  KERBEROS
        if (use_kerberos && vacuous) {
                syslog(LOG_ERR, "only one of -k and -v allowed");
                exit(2);
        }
#ifdef CRYPT
        if (doencrypt && !use_kerberos) {
                syslog(LOG_ERR, "-k is required for -x");
                exit(2);
        }
#endif
#endif

        fromlen = sizeof (from);
        if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
                syslog(LOG_ERR, "getpeername: %m");
                _exit(1);
        }
        if (keepalive &&
            setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
            sizeof(on)) < 0)
                syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
        linger.l_onoff = 1;
        linger.l_linger = 60;                   /* XXX */
        if (setsockopt(0, SOL_SOCKET, SO_LINGER, (char *)&linger,
            sizeof (linger)) < 0)
                syslog(LOG_WARNING, "setsockopt (SO_LINGER): %m");
        doit(&from);
        /* NOTREACHED */
}

char    username[20] = "USER=";
char    homedir[64] = "HOME=";
char    shell[64] = "SHELL=";
char    path[100] = "PATH=";
char    *envinit[] =
            {homedir, shell, path, username, 0};
extern char     **environ;

void
doit(fromp)
        struct sockaddr_in *fromp;
{
        extern char *__rcmd_errstr;     /* syslog hook from libc/net/rcmd.c. */
        struct hostent *hp;
        struct passwd *pwd;
        u_short port;
        fd_set ready, readfrom;
        int cc, nfd, pv[2], pid, s;
#ifdef __CYGWIN__
        int cv[2];
#endif
        int one = 1;
        const char *hostname, *errorstr, *errorhost;
        char *cp, sig, buf[BUFSIZ];
        char *cmdbuf, *locuser, *remuser;

#ifdef  KERBEROS
        AUTH_DAT        *kdata = (AUTH_DAT *) NULL;
        KTEXT           ticket = (KTEXT) NULL;
        char            instance[INST_SZ], version[VERSION_SIZE];
        struct          sockaddr_in     fromaddr;
        int             rc;
        long            authopts;
        int             pv1[2], pv2[2];
        fd_set          wready, writeto;

        fromaddr = *fromp;
#endif

        (void) signal(SIGINT, SIG_DFL);
        (void) signal(SIGQUIT, SIG_DFL);
        (void) signal(SIGTERM, SIG_DFL);
#ifdef DEBUG
        { int t = open(PATH_TTY, O_RDWR);
          if (t >= 0) {
                ioctl(t, TIOCNOTTY, (char *)0);
                (void) close(t);
          }
        }
#endif
        fromp->sin_port = ntohs((u_short)fromp->sin_port);
        if (fromp->sin_family != AF_INET) {
                syslog(LOG_ERR, "malformed \"from\" address (af %d)\n",
                    fromp->sin_family);
                exit(1);
        }
#ifdef IP_OPTIONS
      {
        u_char optbuf[BUFSIZ/3], *cp;
        char lbuf[BUFSIZ], *lp;
        int optsize = sizeof(optbuf), ipproto;
        struct protoent *ip;

        if ((ip = getprotobyname("ip")) != NULL)
                ipproto = ip->p_proto;
        else
                ipproto = IPPROTO_IP;
        if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) &&
            optsize != 0) {
                lp = lbuf;
                for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
                        sprintf(lp, " %2.2x", *cp);
                syslog(LOG_NOTICE,
                    "Connection received from %s using IP options (ignored):%s",
                    inet_ntoa(fromp->sin_addr), lbuf);
                if (setsockopt(0, ipproto, IP_OPTIONS,
                    (char *)NULL, optsize) != 0) {
                        syslog(LOG_ERR, "setsockopt IP_OPTIONS NULL: %m");
                        exit(1);
                }
        }
      }
#endif

#ifdef  KERBEROS
        if (!use_kerberos)
#endif
                if (fromp->sin_port >= IPPORT_RESERVED ||
                    fromp->sin_port < IPPORT_RESERVED/2) {
                        syslog(LOG_NOTICE|LOG_AUTH,
                            "Connection from %s on illegal port %u",
                            inet_ntoa(fromp->sin_addr),
                            fromp->sin_port);
                        exit(1);
                }

        (void) alarm(60);
        port = 0;
        for (;;) {
                char c;
                if ((cc = read(STDIN_FILENO, &c, 1)) != 1) {
                        if (cc < 0)
                                syslog(LOG_NOTICE, "read: %m");
                        shutdown(0, 1+1);
                        exit(1);
                }
                if (c== 0)
                        /*  I PRINT  */
                        syslog(LOG_INFO|LOG_AUTH, "c is zero!");
                        break;
                port = port * 10 + c - '0';
                syslog(LOG_INFO|LOG_AUTH, "Port is %d", port);
        }

        (void) alarm(0);
        if (port != 0) {
                /*
                 * The Winsock hack for the rresvport problem. Winsock's
                 * `rresvport' function returns a socket descriptor to a
                 * reserved port which still is timing out.
                 *
                 * If we receive the message that the port is already in
                 * use we will try again until we have tried all ports
                 * from IPPORT_RESERVED-1 to IPPORT_RESERVED/2 (1023 -> 512).
                 *
                 * Thanks to Jason Gouger <[EMAIL PROTECTED]>
                 * for that solution.
                 */
                int lport = IPPORT_RESERVED;
                while (1) {
                        --lport;
                        s = rresvport(&lport);
                        if (s < 0) {
                                syslog(LOG_ERR, "can't get stderr port: %m");
                                exit(1);
                        }
#ifdef  KERBEROS
                        if (!use_kerberos)
#endif
                        if (port >= IPPORT_RESERVED) {
                                syslog(LOG_ERR, "2nd port not reserved\n");
                                exit(1);
                        }
                        fromp->sin_port = htons(port);
                        if (connect(s, (struct sockaddr *)fromp, sizeof (*fromp)) < 0) 
{
                                if ((errno != EADDRINUSE && errno != ETIMEDOUT)
                                    || lport == IPPORT_RESERVED / 2) {
                                        syslog(LOG_INFO, "connect second port %d: %m", 
port);
                                        exit(1);
                                }
                                close(s);
                        } else
                                break;
                }
        }
#ifdef  KERBEROS
        if (vacuous) {
                error("rshd: remote host requires Kerberos authentication\n");
                exit(1);
        }
#endif

#ifdef notdef
        /* from inetd, socket is already on 0, 1, 2 */
        dup2(f, 0);
        dup2(f, 1);
        dup2(f, 2);
#endif
        errorstr = NULL;
        hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof (struct in_addr),
                fromp->sin_family);
        if (hp) {
                /*
                 * If name returned by gethostbyaddr is in our domain,
                 * attempt to verify that we haven't been fooled by someone
                 * in a remote net; look up the name and check that this
                 * address corresponds to the name.
                 */
                hostname = hp->h_name;
#ifdef  KERBEROS
                if (!use_kerberos)
#endif
                if (check_all || local_domain(hp->h_name)) {
                        char *remotehost = (char *) alloca (strlen (hp->h_name) + 1);
                        if (! remotehost)
                                errorstr = "Out of memory\n";
                        else {
                                strcpy(remotehost, hp->h_name);
                                errorhost = remotehost;
                                hp = gethostbyname(remotehost);
                                if (hp == NULL) {
                                        syslog(LOG_INFO,
                                            "Couldn't look up address for %s",
                                            remotehost);
                                        errorstr =
                               "Couldn't look up address for your host (%s)\n";
                                        hostname = inet_ntoa(fromp->sin_addr);
                                } else for (; ; hp->h_addr_list++) {
                                        if (hp->h_addr_list[0] == NULL) {
                                                syslog(LOG_NOTICE,
                                         "Host addr %s not listed for host %s",
                                                    inet_ntoa(fromp->sin_addr),
                                                    hp->h_name);
                                                errorstr =
                                              "Host address mismatch for %s\n";
                                                hostname = inet_ntoa(fromp->sin_addr);
                                                break;
                                        }
                                        if (!bcmp(hp->h_addr_list[0],
                                            (caddr_t)&fromp->sin_addr,
                                            sizeof(fromp->sin_addr))) {
                                                hostname = hp->h_name;
                                                break;
                                        }
                                }
                        }
                }
        } else
                errorhost = hostname = inet_ntoa(fromp->sin_addr);
#ifdef __CYGWIN__
        {
                const char *h = hostname;
                hostname = strdup (h);
        }
#endif

#ifdef  KERBEROS
        if (use_kerberos) {
                kdata = (AUTH_DAT *) authbuf;
                ticket = (KTEXT) tickbuf;
                authopts = 0L;
                strcpy(instance, "*");
                version[VERSION_SIZE - 1] = '\0';
#ifdef CRYPT
                if (doencrypt) {
                        struct sockaddr_in local_addr;
                        rc = sizeof(local_addr);
                        if (getsockname(0, (struct sockaddr *)&local_addr,
                            &rc) < 0) {
                                syslog(LOG_ERR, "getsockname: %m");
                                error("rlogind: getsockname: %m");
                                exit(1);
                        }
                        authopts = KOPT_DO_MUTUAL;
                        rc = krb_recvauth(authopts, 0, ticket,
                                "rcmd", instance, &fromaddr,
                                &local_addr, kdata, "", schedule,
                                version);
                        des_set_key(kdata->session, schedule);
                } else
#endif
                        rc = krb_recvauth(authopts, 0, ticket, "rcmd",
                                instance, &fromaddr,
                                (struct sockaddr_in *) 0,
                                kdata, "", (bit_64 *) 0, version);
                if (rc != KSUCCESS) {
                        error("Kerberos authentication failure: %s\n",
                                  krb_err_txt[rc]);
                        exit(1);
                }
        } else
#endif
                remuser = getstr ("remuser");

        locuser = getstr ("locuser");
        cmdbuf = getstr ("command");

        setpwent();
        pwd = getpwnam(locuser);
        if (pwd == NULL) {
                /*  I PRINT  */
                syslog(LOG_INFO|LOG_AUTH,
                    "%s@%s as %s: unknown login. cmd='%.80s'",
                    remuser, hostname, locuser, cmdbuf);
                if (errorstr == NULL)
                        errorstr = "Login incorrect.\n";
                goto fail;
        }
        if (chdir(pwd->pw_dir) < 0) {
                (void) chdir("/");
#if defined(notdef) || defined(__CYGWIN__)
                syslog(LOG_INFO|LOG_AUTH,
                    "%s@%s as %s: no home directory. cmd='%.80s'",
                    remuser, hostname, locuser, cmdbuf);
                error("No remote directory.\n");
                exit(1);
#endif
        }

#ifdef  KERBEROS
        if (use_kerberos) {
                if (pwd->pw_passwd != 0 && *pwd->pw_passwd != '\0') {
                        if (kuserok(kdata, locuser) != 0) {
                                syslog(LOG_INFO|LOG_AUTH,
                                    "Kerberos rsh denied to %s.%s@%s",
                                    kdata->pname, kdata->pinst, kdata->prealm);
                                error("Permission denied.\n");
                                exit(1);
                        }
                }
        } else
#endif

                if (errorstr ||
                    pwd->pw_passwd != 0 && *pwd->pw_passwd != '\0' &&
                    iruserok(fromp->sin_addr.s_addr, pwd->pw_uid == 0,
                    remuser, locuser) < 0) {
                        if (__rcmd_errstr)
                                syslog(LOG_INFO|LOG_AUTH,
                            "%s@%s as %s: permission denied (%s). cmd='%.80s'",
                                    remuser, hostname, locuser, __rcmd_errstr,
                                    cmdbuf);
                        else
                                syslog(LOG_INFO|LOG_AUTH,
                            "%s@%s as %s: permission denied. cmd='%.80s'",
                                    remuser, hostname, locuser, cmdbuf);
fail:
                        if (errorstr == NULL)
                                errorstr = "Permission denied.\n";
                        error(errorstr, errorhost);
                        exit(1);
                }

        if (pwd->pw_uid && !access(PATH_NOLOGIN, F_OK)) {
                syslog(LOG_INFO|LOG_AUTH, "Logins currently disabled.");
                exit(1);
        }

        /*  I PRINT  */
        syslog(LOG_INFO|LOG_AUTH, "Made it to point 2");
        (void) write(STDERR_FILENO, "\0", 1);
        sent_null = 1;
        /*  I PRINT  */
        syslog(LOG_INFO|LOG_AUTH, "Made it to point 3");

        if (port) {
                syslog(LOG_INFO|LOG_AUTH, "Made it to point 4");
                if (pipe(pv) < 0) {
                        syslog(LOG_INFO|LOG_AUTH, "Can't make pipe.");
                        exit(1);
                }
        syslog(LOG_INFO|LOG_AUTH, "Made it to point 5");
#ifdef CRYPT
#ifdef KERBEROS
                if (doencrypt) {
                        if (pipe(pv1) < 0) {
                                syslog(LOG_INFO|LOG_AUTH, "Can't make 2nd pipe.");
                                exit(1);
                        }
                        if (pipe(pv2) < 0) {
                                syslog(LOG_INFO|LOG_AUTH, "Can't make 3rd pipe.");
                                exit(1);
                        }
                }
#endif
#endif
#ifdef __CYGWIN__
                if (pipe(cv) < 0) {
                        syslog(LOG_INFO|LOG_AUTH, "Can't make stdout pipe.");
                        exit(1);
                }
#endif
                pid = fork();
                if (pid == -1)  {
                        syslog(LOG_INFO|LOG_AUTH, "Can't fork; try again.");
                        exit(1);
                }
                if (pid) {
                        syslog(LOG_INFO|LOG_AUTH, "Fork suceeded for parent.");
#ifdef CRYPT
#ifdef KERBEROS
                        if (doencrypt) {
                                static char msg[] = SECURE_MESSAGE;
                                (void) close(pv1[1]);
                                (void) close(pv2[1]);
                                des_write(s, msg, sizeof(msg) - 1);

                        } else
#endif
#endif
                        {
#ifdef __CYGWIN__
                                close(cv[1]);
#else
                                (void) close(0);
                                (void) close(1);
#endif
                        }
#ifndef __CYGWIN__
                        (void) close(2);
#endif
                        (void) close(pv[1]);

                        FD_ZERO(&readfrom);
                        FD_SET(s, &readfrom);
                        FD_SET(pv[0], &readfrom);
                        if (pv[0] > s)
                                nfd = pv[0];
                        else
                                nfd = s;
#ifdef __CYGWIN__
                        FD_SET(cv[0], &readfrom);
                        if (cv[0] > s && cv[0] > pv[0])
                                nfd = cv[0];
#endif
#ifdef CRYPT
#ifdef KERBEROS
                        if (doencrypt) {
                                FD_ZERO(&writeto);
                                FD_SET(pv2[0], &writeto);
                                FD_SET(pv1[0], &readfrom);

                                nfd = MAX(nfd, pv2[0]);
                                nfd = MAX(nfd, pv1[0]);
                        } else
#endif
#endif
                                ioctl(pv[0], FIONBIO, (char *)&one);
#ifdef __CYGWIN__
                                ioctl(cv[0], FIONBIO, (char *)&one);
#endif

                        /* should set s nbio! */
                        nfd++;
                        do {
                                ready = readfrom;
#ifdef CRYPT
#ifdef KERBEROS
                                if (doencrypt) {
                                        wready = writeto;
                                        if (select(nfd, &ready,
                                            &wready, (fd_set *) 0,
                                            (struct timeval *) 0) < 0)
                                                break;
                                } else
#endif
#endif
                                        if (select(nfd, &ready, (fd_set *)0,
                                          (fd_set *)0, (struct timeval *)0) < 0)
                                                break;
                                if (FD_ISSET(s, &ready)) {
                                        int     ret;
#ifdef CRYPT
#ifdef KERBEROS
                                        if (doencrypt)
                                                ret = des_read(s, &sig, 1);
                                        else
#endif
#endif
                                                ret = read(s, &sig, 1);
                                        if (ret <= 0)
                                                FD_CLR(s, &readfrom);
                                        else {
                                                shutdown(s, 1+1);
                                                close(s);
                                                shutdown(1, 1+1);
                                                close(1);
                                                killpg(pid, sig);
                                        }
                                }
                                if (FD_ISSET(pv[0], &ready)) {
                                        errno = 0;
                                        cc = read(pv[0], buf, sizeof(buf));
                                        if (cc <= 0) {
                                                shutdown(s, 1+1);
                                                FD_CLR(pv[0], &readfrom);
                                        } else {
#ifdef CRYPT
#ifdef KERBEROS
                                                if (doencrypt)
                                                        (void)
                                                          des_write(s, buf, cc);
                                                else
#endif
#endif
                                                        (void)
                                                          write(s, buf, cc);
                                        }
                                }
#ifdef __CYGWIN__
                                if (FD_ISSET(cv[0], &ready)) {
                                        errno = 0;
                                        cc = read(cv[0], buf, sizeof(buf));
                                        if (cc <= 0) {
                                                shutdown(1, 1+1);
                                                FD_CLR(cv[0], &readfrom);
                                        } else {
                                                (void) write(1, buf, cc);
                                        }
                                }
#endif
#ifdef CRYPT
#ifdef KERBEROS
                                if (doencrypt && FD_ISSET(pv1[0], &ready)) {
                                        errno = 0;
                                        cc = read(pv1[0], buf, sizeof(buf));
                                        if (cc <= 0) {
                                                shutdown(pv1[0], 1+1);
                                                FD_CLR(pv1[0], &readfrom);
                                        } else
                                                (void) des_write(STDOUT_FILENO,
                                                    buf, cc);
                                }

                                if (doencrypt && FD_ISSET(pv2[0], &wready)) {
                                        errno = 0;
                                        cc = des_read(STDIN_FILENO,
                                            buf, sizeof(buf));
                                        if (cc <= 0) {
                                                shutdown(pv2[0], 1+1);
                                                FD_CLR(pv2[0], &writeto);
                                        } else
                                                (void) write(pv2[0], buf, cc);
                                }
#endif
#endif

                        } while (FD_ISSET(s, &readfrom) ||
#ifdef CRYPT
#ifdef KERBEROS
                            (doencrypt && FD_ISSET(pv1[0], &readfrom)) ||
#endif
#endif
#ifdef __CYGWIN__
                            FD_ISSET(cv[0], &readfrom) ||
#endif
                            FD_ISSET(pv[0], &readfrom));
#ifdef __CYGWIN__
                        waitpid(pid, NULL, 0);
                        shutdown(0, 1+1);
                        close(0);
                        shutdown(1, 1+1);
                        close(1);
                        shutdown(2, 1+1);
                        close(2);
                        shutdown(s, 1+1);
                        close(s);
#endif
                        exit(0);
                }
                syslog(LOG_INFO|LOG_AUTH, "Fork suceeded for child.");

                setpgid (0, getpid ());

                shutdown(s, 1+1);

                (void) close(s);
                (void) close(pv[0]);
#ifdef __CYGWIN__
                close(1);
                close(cv[0]);
                dup2(cv[1], 1);
                close(cv[1]);
#endif
#ifdef CRYPT
#ifdef KERBEROS
                if (doencrypt) {
                        close(pv1[0]); close(pv2[0]);
                        dup2(pv1[1], 1);
                        dup2(pv2[1], 0);
                        close(pv1[1]);
                        close(pv2[1]);
                }
#endif
#endif
                dup2(pv[1], 2);
                close(pv[1]);
        }
        if (*pwd->pw_shell == '\0')
                pwd->pw_shell = PATH_BSHELL;
#if     BSD > 43
        if (setlogin(pwd->pw_name) < 0)
                syslog(LOG_ERR, "setlogin() failed: %m");
#endif
        (void) setgid((gid_t)pwd->pw_gid);
        initgroups(pwd->pw_name, pwd->pw_gid);
        (void) setuid((uid_t)pwd->pw_uid);
        environ = envinit;
        strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
        strcat(path, PATH_DEFPATH);
        strncat(shell, pwd->pw_shell, sizeof(shell)-7);
        strncat(username, pwd->pw_name, sizeof(username)-6);
        cp = strrchr(pwd->pw_shell, '/');
        if (cp)
                cp++;
        else
                cp = pwd->pw_shell;
        endpwent();
        if (log_success || pwd->pw_uid == 0) {
#ifdef  KERBEROS
                if (use_kerberos)
                    syslog(LOG_INFO|LOG_AUTH,
                        "Kerberos shell from %s.%s@%s on %s as %s, cmd='%.80s'",
                        kdata->pname, kdata->pinst, kdata->prealm,
                        hostname, locuser, cmdbuf);
                else
#endif
                    syslog(LOG_INFO|LOG_AUTH, "%s@%s as %s: cmd='%.80s'",
                        remuser, hostname, locuser, cmdbuf);
        }
        execl(pwd->pw_shell, cp, "-c", cmdbuf, 0);
        perror(pwd->pw_shell);
        exit(1);
}

/*
 * Report error to client.  Note: can't be used until second socket has
 * connected to client, or older clients will hang waiting for that
 * connection first.
 */

void
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
error(const char *fmt, ...)
#else
error(fmt, va_alist)
        char *fmt;
        va_dcl
#endif
{
        va_list ap;
        int len;
        char *bp, buf[BUFSIZ];
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
        va_start(ap, fmt);
#else
        va_start(ap);
#endif
        bp = buf;
        if (sent_null == 0) {
                *bp++ = 1;
                len = 1;
        } else
                len = 0;
        (void)vsnprintf(bp, sizeof(buf) - 1, fmt, ap);
        (void)write(STDERR_FILENO, buf, len + strlen(bp));
}

char *
getstr(err)
        char *err;
{
        size_t buf_len = 100;
        char *buf = malloc (buf_len), *end = buf;

        if (! buf) {
                error ("Out of space reading %s\n", err);
                exit (1);
        }

        do {
                /* Oh this is efficient, oh yes.  [But what can be done?] */
                int rd = read(STDIN_FILENO, end, 1);
                if (rd <= 0) {
                        if (rd == 0)
                                error ("EOF reading %s\n", err);
                        else
                                perror (err);
                        exit(1);
                }

                end += rd;
                if ((buf + buf_len - end) < (buf_len >> 3)) {
                        /* Not very much room left in our buffer, grow it. */
                        size_t end_offs = end - buf;
                        buf_len += buf_len;
                        buf = realloc (buf, buf_len);
                        if (! buf) {
                                error ("Out of space reading %s\n", err);
                                exit (1);
                        }
                        end = buf + end_offs;
                }
        } while (*(end - 1));

        return buf;
}

/*
 * Check whether host h is in our local domain,
 * defined as sharing the last two components of the domain part,
 * or the entire domain part if the local domain has only one component.
 * If either name is unqualified (contains no '.'),
 * assume that the host is local, as it will be
 * interpreted as such.
 */
int
local_domain(h)
        const char *h;
{
        extern char *localhost ();
        char *hostname = localhost ();

        if (! hostname)
                return 0;
        else {
                int is_local = 0;
                const char *p1 = topdomain (hostname);
                const char *p2 = topdomain (h);

                if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
                        is_local = 1;

                free (hostname);

                return is_local;
        }
}

const char *
topdomain(h)
        const char *h;
{
        const char *p, *maybe = NULL;
        int dots = 0;

        for (p = h + strlen(h); p >= h; p--) {
                if (*p == '.') {
                        if (++dots == 2)
                                return (p);
                        maybe = p;
                }
        }
        return (maybe);
}

void
usage()
{

        syslog(LOG_ERR, "usage: rshd [-%s]", OPTIONS);
        exit(2);
}

Cygnus Win95/NT Configuration Diagnostics
Current System Time: Wed Nov  8 14:18:57 2000

WinNT Ver 4.0 build 1381 Service Pack 5

Path:   /usr/local/bin
        /usr/bin
        /bin
        /cygdrive/c/Perl/bin/
        /cygdrive/c/WINNT/system32
        /cygdrive/c/WINNT
        /cygdrive/c/Program Files/Rational/common
        /cygdrive/c/progfile/ccm51/bin
        /usr/local/emacs-20.4/bin
        /cygdrive/c/Program Files/Microsoft Visual Studio/Common/Tools/WinNT
        /cygdrive/c/Program Files/Microsoft Visual Studio/Common/MSDev98/Bin
        /cygdrive/c/Program Files/Microsoft Visual Studio/Common/Tools
        /cygdrive/c/Program Files/Microsoft Visual Studio/VC98/bin

SysDir: C:\WINNT\System32
WinDir: C:\WINNT

PWD = `/home/mayers/build/inetutils/inetutils-1.3.2/rshd'
USER = `mayers'
MAKE_MODE = `unix'
HOME = `/home/mayers'

NUMBER_OF_PROCESSORS = `1'
PROMPT = `$P$G'
LOGONSERVER = `\\TOTO'
OS2LIBPATH = `C:\WINNT\system32\os2\dll;'
COMSPEC = `C:\WINNT\system32\cmd.exe'
!C: = `C:\progfile\Cygwin\bin'
SYSTEMDRIVE = `C:'
HOSTNAME = `TOTO'
INCLUDE = `C:\Program Files\Microsoft Visual Studio\VC98\atl\include;C:\Program 
Files\Microsoft Visual Studio\VC98\mfc\include;C:\Program Files\Microsoft Visual 
Studio\VC98\include'
PROCESSOR_REVISION = `0702'
MSDEVDIR = `C:\Program Files\Microsoft Visual Studio\Common\MSDev98'
PATHEXT = `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH'
COMPUTERNAME = `TOTO'
WINDIR = `C:\WINNT'
USERPROFILE = `C:\WINNT\Profiles\mayers'
PS1 = `\h> '
MSINPUT = `C:\progfile\Msinput'
BASHPATH = `C:\progfile\Cygwin\bin'
MACHTYPE = `i686-pc-cygwin'
PROCESSOR_IDENTIFIER = `x86 Family 6 Model 7 Stepping 2, GenuineIntel'
OS = `Windows_NT'
OLDPWD = `/home/mayers/build/inetutils/inetutils-1.3.2/inetd'
BASH_ENV = `C:\progfile\Cygwin\etc\profile_noninteractive'
PROCESSOR_ARCHITECTURE = `x86'
TEMP = `/cygdrive/c/TEMP'
PROCESSOR_LEVEL = `6'
SYSTEMROOT = `C:\WINNT'
HOMEDRIVE = `C:'
LIB = `C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib;C:\Program 
Files\Microsoft Visual Studio\VC98\lib'
PERL5SHELL = `C:\progfile\Cygwin\bin\bash.exe'
SHLVL = `1'
HOMEPATH = `\'
USERDOMAIN = `TOTO'
USERNAME = `mayers'
SHELL = `/bin/sh'
HOSTTYPE = `i686'
CVSROOT = `:pserver:[EMAIL PROTECTED]:/cvs/src'
OSTYPE = `cygwin'
TERM = `cygwin'
_ = `/usr/bin/cygcheck'
TZ = `PST8PDT7,M4.1.0/2,M10.5.0/2'

HKEY_CURRENT_USER\Software\Cygnus Solutions
HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin
HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2
  (default) = `/cygdrive'
  cygdrive flags = 0x00000022
HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\Program Options
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\1.00.000
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2
  (default) = `/cygdrive'
  cygdrive flags = 0x0000002a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/
  (default) = `C:\progfile\Cygwin'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/d
  (default) = `d:'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/bin
  (default) = `C:/progfile/Cygwin/bin'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/lib
  (default) = `C:/progfile/Cygwin/lib'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\Program Options
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\CYGWIN.DLL setup

a:  fd           N/A    N/A                    
c:  hd  NTFS    4094Mb  68% CP CS UN PA FC     
d:  hd  NTFS    3937Mb  50% CP CS UN PA FC     
e:  cd           N/A    N/A                    

C:\progfile\Cygwin\bin  /usr/bin  system  binmode
C:\progfile\Cygwin\lib  /usr/lib  system  binmode
C:\progfile\Cygwin  /        system  binmode
d:    /d       system  binmode

Found: C:\progfile\Cygwin\bin\bash.exe
Found: C:\progfile\Cygwin\bin\cat.exe
Found: C:\progfile\Cygwin\bin\cpp.exe
Found: C:\progfile\Cygwin\bin\find.exe
Found: C:\progfile\Cygwin\bin\gcc.exe
Found: C:\progfile\Cygwin\bin\gdb.exe
Found: C:\progfile\Cygwin\bin\ld.exe
Found: C:\progfile\Cygwin\bin\ls.exe
Found: C:\progfile\Cygwin\bin\make.exe
Found: C:\progfile\Cygwin\bin\sh.exe

   18k 2000/10/23 C:\progfile\Cygwin\bin\cyggdbm.dll - os=4.0 img=1.0 sys=4.0
                  "cyggdbm.dll" v0.0 ts=2000/10/22 19:26
   14k 2000/10/23 C:\progfile\Cygwin\bin\cygintl.dll - os=4.0 img=1.0 sys=4.0
                  "cygintl.dll" v0.0 ts=2000/10/23 12:02
   83k 2000/06/11 C:\progfile\Cygwin\bin\cygitcl30.dll - os=4.0 img=1.0 sys=4.0
                  "cygitcl30.dll" v0.0 ts=2000/6/10 20:34
   35k 2000/06/11 C:\progfile\Cygwin\bin\cygitk30.dll - os=4.0 img=1.0 sys=4.0
                  "cygitk30.dll" v0.0 ts=2000/6/10 20:34
   45k 2000/10/22 C:\progfile\Cygwin\bin\cygjbig1.dll - os=4.0 img=1.0 sys=4.0
                  "cygjbig1.dll" v0.0 ts=2000/10/22 16:06
  119k 2000/10/23 C:\progfile\Cygwin\bin\cygjpeg6b.dll - os=4.0 img=1.0 sys=4.0
                  "cygjpeg6b.dll" v0.0 ts=2000/10/22 17:58
  162k 2000/10/23 C:\progfile\Cygwin\bin\cygpng2.dll - os=4.0 img=1.0 sys=4.0
                  "cygpng2.dll" v0.0 ts=2000/10/22 17:40
  402k 2000/06/11 C:\progfile\Cygwin\bin\cygtcl80.dll - os=4.0 img=1.0 sys=4.0
                  "cygtcl80.dll" v0.0 ts=2000/6/10 20:30
    5k 2000/06/11 C:\progfile\Cygwin\bin\cygtclpip80.dll - os=4.0 img=1.0 sys=4.0
   10k 2000/06/11 C:\progfile\Cygwin\bin\cygtclreg80.dll - os=4.0 img=1.0 sys=4.0
                  "cygtclreg80.dll" v0.0 ts=2000/6/10 20:30
  243k 2000/10/23 C:\progfile\Cygwin\bin\cygtiff3.dll - os=4.0 img=1.0 sys=4.0
                  "cygtiff3.dll" v0.0 ts=2000/10/22 18:14
  639k 2000/06/11 C:\progfile\Cygwin\bin\cygtk80.dll - os=4.0 img=1.0 sys=4.0
                  "cygtk80.dll" v0.0 ts=2000/6/10 20:34
   49k 2000/10/23 C:\progfile\Cygwin\bin\cygz.dll - os=4.0 img=1.0 sys=4.0
                  "cygz.dll" v0.0 ts=2000/10/22 17:22
  606k 2000/11/01 C:\progfile\Cygwin\bin\cygwin1.dll - os=4.0 img=1.0 sys=4.0
                  "cygwin1.dll" v0.0 ts=2000/10/31 21:15
    Cygwin DLL version info:
        dll major: 1001
        dll minor: 5
        dll epoch: 19
        dll bad signal mask: 19005
        dll old termios: 5
        api major: 0
        api minor: 29
        shared data: 3
        dll identifier: cygwin1
        mount registry: 2
        cygnus registry name: Cygnus Solutions
        cygwin registry name: Cygwin
        program options name: Program Options
        cygwin mount registry name: mounts v2
        build date: Wed Nov 1 00:15:33 EST 2000
        shared id: cygwin1S3

Use -h to see help about each section

--
Want to unsubscribe from this list?
Send a message to [EMAIL PROTECTED]

Reply via email to