Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-3]: src/libexec/rshd Pull up revision 1.41 (requested by lukem in...



details:   https://anonhg.NetBSD.org/src/rev/288d562d9194
branches:  netbsd-3
changeset: 576516:288d562d9194
user:      tron <tron%NetBSD.org@localhost>
date:      Sat Jul 09 22:45:02 2005 +0000

description:
Pull up revision 1.41 (requested by lukem in ticket #532):
KNF, WARNS == 3. Reported by John Nemeth

diffstat:

 libexec/rshd/rshd.c |  160 +++++++++++++++++++++++++--------------------------
 1 files changed, 79 insertions(+), 81 deletions(-)

diffs (truncated from 453 to 300 lines):

diff -r adea4b208950 -r 288d562d9194 libexec/rshd/rshd.c
--- a/libexec/rshd/rshd.c       Sat Jul 09 22:44:55 2005 +0000
+++ b/libexec/rshd/rshd.c       Sat Jul 09 22:45:02 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rshd.c,v 1.40 2005/03/13 01:48:54 christos Exp $       */
+/*     $NetBSD: rshd.c,v 1.40.2.1 2005/07/09 22:45:02 tron Exp $       */
 
 /*
  * Copyright (C) 1998 WIDE Project.
@@ -69,7 +69,7 @@
 #if 0
 static char sccsid[] = "@(#)rshd.c     8.2 (Berkeley) 4/6/94";
 #else
-__RCSID("$NetBSD: rshd.c,v 1.40 2005/03/13 01:48:54 christos Exp $");
+__RCSID("$NetBSD: rshd.c,v 1.40.2.1 2005/07/09 22:45:02 tron Exp $");
 #endif
 #endif /* not lint */
 
@@ -137,10 +137,10 @@
 int    log_success;            /* If TRUE, log all successful accesses */
 int    sent_null;
 
-void    doit(struct sockaddr *);
+void    doit(struct sockaddr *) __attribute__((__noreturn__));
 void    rshd_errx(int, const char *, ...)
      __attribute__((__noreturn__, __format__(__printf__, 2, 3)));
-void    getstr(char *, int, char *);
+void    getstr(char *, int, const char *);
 int     local_domain(char *);
 char   *topdomain(char *);
 void    usage(void);
@@ -185,10 +185,10 @@
        argc -= optind;
        argv += optind;
 
-       fromlen = sizeof (from); /* xxx */
-       if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
+       fromlen = sizeof(from); /* xxx */
+       if (getpeername(STDIN_FILENO, (struct sockaddr *)&from, &fromlen) < 0) {
                syslog(LOG_ERR, "getpeername: %m");
-               exit(1);
+               return EXIT_FAILURE;
        }
 #if 0
        if (((struct sockaddr *)&from)->sa_family == AF_INET6 &&
@@ -200,12 +200,12 @@
                    sizeof(struct sockaddr_in);
 
                sin6 = (struct sockaddr_in6 *)&from;
-               memset(&sin, 0, sizeof(sin));
+               (void)memset(&sin, 0, sizeof(sin));
                sin.sin_family = AF_INET;
                sin.sin_len = sizeof(struct sockaddr_in);
-               memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[off],
+               (void)memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[off],
                    sizeof(sin.sin_addr));
-               memcpy(&from, &sin, sizeof(sin));
+               (void)memcpy(&from, &sin, sizeof(sin));
                fromlen = sin.sin_len;
        }
 #else
@@ -218,25 +218,22 @@
                }
                syslog(LOG_ERR, "malformed \"from\" address (v4 mapped, %s)",
                    hbuf);
-               exit(1);
+               return EXIT_FAILURE;
        }
 #endif
        if (keepalive &&
-           setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
+           setsockopt(STDIN_FILENO, 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,
+       if (setsockopt(STDIN_FILENO, SOL_SOCKET, SO_LINGER, (char *)&linger,
            sizeof (linger)) < 0)
                syslog(LOG_WARNING, "setsockopt (SO_LINGER): %m");
        proto = getprotobyname("tcp");
-       setsockopt(0, proto->p_proto, TCP_NODELAY, &on, sizeof(on));
+       (void)setsockopt(STDIN_FILENO, proto->p_proto, TCP_NODELAY, &on,
+           sizeof(on));
        doit((struct sockaddr *)&from);
-       /* NOTREACHED */
-#ifdef __GNUC__
-       exit(0);
-#endif
 }
 
 char   username[20] = "USER=";
@@ -275,14 +272,14 @@
        const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
        const char *errormsg = NULL, *errorstr = NULL;
 
-       (void) signal(SIGINT, SIG_DFL);
-       (void) signal(SIGQUIT, SIG_DFL);
-       (void) signal(SIGTERM, SIG_DFL);
+       (void)signal(SIGINT, SIG_DFL);
+       (void)signal(SIGQUIT, SIG_DFL);
+       (void)signal(SIGTERM, SIG_DFL);
 #ifdef DEBUG
        { 
-               int t = open(_PATH_TTY, 2);
+               int t = open(_PATH_TTY, O_RDWR);
                if (t >= 0) {
-                       ioctl(t, TIOCNOTTY, (char *)0);
+                       ioctl(t, TIOCNOTTY, NULL);
                        (void)close(t);
                }
        }
@@ -298,12 +295,12 @@
 #endif
        default:
                syslog(LOG_ERR, "malformed \"from\" address (af %d)", af);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
        if (getnameinfo(fromp, fromp->sa_len, naddr, sizeof(naddr),
                        pbuf, sizeof(pbuf), niflags) != 0) {
                syslog(LOG_ERR, "malformed \"from\" address (af %d)", af);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 #ifdef IP_OPTIONS
        if (af == AF_INET) {
@@ -327,7 +324,7 @@
                                    inet_ntoa((
                                    (struct sockaddr_in *)fromp)->sin_addr),
                                    c == IPOPT_LSRR ? "LSRR" : "SSRR");
-                               exit(1);
+                               exit(EXIT_FAILURE);
                        }
                        if (c == IPOPT_EOL)
                                break;
@@ -337,11 +334,11 @@
        }
 #endif
        if (ntohs(*portp) >= IPPORT_RESERVED
-           || ntohs(*portp) < IPPORT_RESERVED/2) {
+           || ntohs(*portp) < IPPORT_RESERVED / 2) {
                syslog(LOG_NOTICE|LOG_AUTH,
                    "Connection from %s on illegal port %u",
                    naddr, ntohs(*portp));
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        (void) alarm(60);
@@ -352,8 +349,8 @@
                if ((cc = read(STDIN_FILENO, &c, 1)) != 1) {
                        if (cc < 0)
                                syslog(LOG_ERR, "read: %m");
-                       shutdown(0, SHUT_RDWR);
-                       exit(1);
+                       (void)shutdown(0, SHUT_RDWR);
+                       exit(EXIT_FAILURE);
                }
                if (c == 0)
                        break;
@@ -366,25 +363,25 @@
                s = rresvport_af(&lport, af);
                if (s < 0) {
                        syslog(LOG_ERR, "can't get stderr port: %m");
-                       exit(1);
+                       exit(EXIT_FAILURE);
                }
                if (port >= IPPORT_RESERVED) {
                        syslog(LOG_ERR, "2nd port not reserved");
-                       exit(1);
+                       exit(EXIT_FAILURE);
                }
                *portp = htons(port);
                if (connect(s, fromp, fromp->sa_len) < 0) {
                        syslog(LOG_ERR, "connect second port %d: %m", port);
-                       exit(1);
+                       exit(EXIT_FAILURE);
                }
        }
 
 
 #ifdef notdef
        /* from inetd, socket is already on 0, 1, 2 */
-       dup2(f, 0);
-       dup2(f, 1);
-       dup2(f, 2);
+       (void)dup2(f, STDIN_FILENO);
+       (void)dup2(f, STDOUT_FILENO);
+       (void)dup2(f, STDERR_FILENO);
 #endif
        if (getnameinfo(fromp, fromp->sa_len, saddr, sizeof(saddr),
                        NULL, 0, NI_NAMEREQD) == 0) {
@@ -397,9 +394,9 @@
                hostname = saddr;
                res0 = NULL;
                if (check_all || local_domain(saddr)) {
-                       strlcpy(remotehost, saddr, sizeof(remotehost));
+                       (void)strlcpy(remotehost, saddr, sizeof(remotehost));
                        errorhost = remotehost;
-                       memset(&hints, 0, sizeof(hints));
+                       (void)memset(&hints, 0, sizeof(hints));
                        hints.ai_family = fromp->sa_family;
                        hints.ai_socktype = SOCK_STREAM;
                        hints.ai_flags = AI_CANONNAME;
@@ -440,12 +437,12 @@
                                }
                        }
                }
-               strlcpy(hostnamebuf, hostname, sizeof(hostnamebuf));
+               (void)strlcpy(hostnamebuf, hostname, sizeof(hostnamebuf));
                hostname = hostnamebuf;
                if (res0)
                        freeaddrinfo(res0);
        } else {
-               strlcpy(hostnamebuf, naddr, sizeof(hostnamebuf));
+               (void)strlcpy(hostnamebuf, naddr, sizeof(hostnamebuf));
                errorhost = hostname = hostnamebuf;
        }
 
@@ -460,20 +457,20 @@
        if (pam_err != PAM_SUCCESS) {
                syslog(LOG_ERR|LOG_AUTH, "pam_start(): %s",
                    pam_strerror(pamh, pam_err));
-               rshd_errx(1, incorrect);
+               rshd_errx(EXIT_FAILURE, incorrect);
        }
 
        if ((pam_err = pam_set_item(pamh, PAM_RUSER, remuser)) != PAM_SUCCESS ||
            (pam_err = pam_set_item(pamh, PAM_RHOST, hostname) != PAM_SUCCESS)){
                syslog(LOG_ERR|LOG_AUTH, "pam_set_item(): %s",
                    pam_strerror(pamh, pam_err));
-               rshd_errx(1, incorrect);
+               rshd_errx(EXIT_FAILURE, incorrect);
        }
 
        pam_err = pam_authenticate(pamh, 0);
        if (pam_err == PAM_SUCCESS) {
                if ((pam_err = pam_get_user(pamh, &cp, NULL)) == PAM_SUCCESS) {
-                       strlcpy(locuser, cp, sizeof(locuser));
+                       (void)strlcpy(locuser, cp, sizeof(locuser));
                        /* XXX truncation! */
                }
                pam_err = pam_acct_mgmt(pamh, 0);
@@ -492,7 +489,7 @@
                    remuser, hostname, locuser, cmdbuf);
                if (errorstr == NULL)
                        errorstr = "Permission denied.";
-               rshd_errx(1, errorstr, errorhost);
+               rshd_errx(EXIT_FAILURE, errorstr, errorhost);
        }
 #ifdef LOGIN_CAP
        lc = login_getclass(pwd ? pwd->pw_class : NULL);
@@ -507,7 +504,7 @@
                        syslog(LOG_INFO|LOG_AUTH,
                            "%s@%s as %s: no home directory. cmd='%.80s'",
                            remuser, hostname, locuser, cmdbuf);
-                       rshd_errx(0, "No remote home directory.");
+                       rshd_errx(EXIT_SUCCESS, "No remote home directory.");
                }
        }
 
@@ -523,7 +520,7 @@
        }
 
        if (pwd->pw_uid && !access(_PATH_NOLOGIN, F_OK))
-               rshd_errx(1, "Logins currently disabled.");
+               rshd_errx(EXIT_FAILURE, "Logins currently disabled.");
 #endif
 
 #ifdef LOGIN_CAP
@@ -534,7 +531,7 @@
         */
        if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETGROUP) != 0) {
                syslog(LOG_ERR, "setusercontext: %m");
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 #else
        initgroups(pwd->pw_name, pwd->pw_gid);
@@ -550,22 +547,22 @@
        }
 #endif
 
-       (void) write(STDERR_FILENO, "\0", 1);
+       (void)write(STDERR_FILENO, "\0", 1);
        sent_null = 1;
 
        if (port) {
                if (pipe(pv) < 0)
-                       rshd_errx(1, "Can't make pipe. (%s)", strerror(errno));
+                       rshd_errx(EXIT_FAILURE, "Can't make pipe. (%s)",
+                           strerror(errno));
                pid = fork();
                if (pid == -1)
-                       rshd_errx(1, "Can't fork. (%s)", strerror(errno));
+                       rshd_errx(EXIT_FAILURE, "Can't fork. (%s)",
+                           strerror(errno));
                if (pid) {
-                       {



Home | Main Index | Thread Index | Old Index