Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/net PR/45007: rcmd_af(3) and thusly rsh(1) ignore r...
details: https://anonhg.NetBSD.org/src/rev/cd26533cc8a2
branches: trunk
changeset: 765583:cd26533cc8a2
user: christos <christos%NetBSD.org@localhost>
date: Tue May 31 06:49:26 2011 +0000
description:
PR/45007: rcmd_af(3) and thusly rsh(1) ignore requested address family
Pass in the address family to rshrcmd and DTRT.
While here KNF.
diffstat:
lib/libc/net/rcmd.c | 271 +++++++++++++++++++++++----------------------------
1 files changed, 122 insertions(+), 149 deletions(-)
diffs (truncated from 671 to 300 lines):
diff -r 78b5293527a1 -r cd26533cc8a2 lib/libc/net/rcmd.c
--- a/lib/libc/net/rcmd.c Tue May 31 06:19:11 2011 +0000
+++ b/lib/libc/net/rcmd.c Tue May 31 06:49:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rcmd.c,v 1.65 2007/01/03 11:46:22 ws Exp $ */
+/* $NetBSD: rcmd.c,v 1.66 2011/05/31 06:49:26 christos Exp $ */
/*
* Copyright (c) 1983, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
#else
-__RCSID("$NetBSD: rcmd.c,v 1.65 2007/01/03 11:46:22 ws Exp $");
+__RCSID("$NetBSD: rcmd.c,v 1.66 2011/05/31 06:49:26 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -70,39 +70,31 @@
#include "pathnames.h"
-int orcmd __P((char **, u_int, const char *, const char *, const char *,
- int *));
-int orcmd_af __P((char **, u_int, const char *, const char *, const char *,
- int *, int));
-int __ivaliduser __P((FILE *, u_int32_t, const char *, const char *));
-int __ivaliduser_sa __P((FILE *, const struct sockaddr *, socklen_t,
- const char *, const char *));
-static int rshrcmd __P((char **, u_int32_t, const char *, const char *,
- const char *, int *, const char *));
-static int resrcmd __P((struct addrinfo *, char **, u_int32_t, const char *,
- const char *, const char *, int *));
-static int __icheckhost __P((const struct sockaddr *, socklen_t,
- const char *));
-static char *__gethostloop __P((const struct sockaddr *, socklen_t));
+int orcmd(char **, u_int, const char *, const char *, const char *, int *);
+int orcmd_af(char **, u_int, const char *, const char *, const char *,
+ int *, int);
+int __ivaliduser(FILE *, u_int32_t, const char *, const char *);
+int __ivaliduser_sa(FILE *, const struct sockaddr *, socklen_t,
+ const char *, const char *);
+static int rshrcmd(int, char **, u_int32_t, const char *,
+ const char *, const char *, int *, const char *);
+static int resrcmd(struct addrinfo *, char **, u_int32_t, const char *,
+ const char *, const char *, int *);
+static int __icheckhost(const struct sockaddr *, socklen_t,
+ const char *);
+static char *__gethostloop(const struct sockaddr *, socklen_t);
int
-rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
- char **ahost;
- u_short rport;
- const char *locuser, *remuser, *cmd;
- int *fd2p;
+rcmd(char **ahost, int rport, const char *locuser, const char *remuser,
+ const char *cmd, int *fd2p)
{
return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET);
}
int
-rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
- char **ahost;
- u_short rport;
- const char *locuser, *remuser, *cmd;
- int *fd2p;
- int af;
+rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser,
+ const char *cmd, int *fd2p, int af)
{
static char hbuf[MAXHOSTNAMELEN];
char pbuf[NI_MAXSERV];
@@ -124,7 +116,7 @@
error = getaddrinfo(*ahost, pbuf, &hints, &res);
if (error) {
warnx("%s: %s", *ahost, gai_strerror(error)); /*XXX*/
- return (-1);
+ return -1;
}
if (res->ai_canonname) {
/*
@@ -142,33 +134,26 @@
*/
sp = getservbyname("shell", "tcp");
if (sp != NULL && sp->s_port == rport)
- error = rshrcmd(ahost, (u_int32_t)rport,
+ error = rshrcmd(af, ahost, (u_int32_t)rport,
locuser, remuser, cmd, fd2p, getenv("RCMD_CMD"));
else
error = resrcmd(res, ahost, (u_int32_t)rport,
locuser, remuser, cmd, fd2p);
freeaddrinfo(res);
- return (error);
+ return error;
}
/* this is simply a wrapper around hprcmd() that handles ahost first */
int
-orcmd(ahost, rport, locuser, remuser, cmd, fd2p)
- char **ahost;
- u_int rport;
- const char *locuser, *remuser, *cmd;
- int *fd2p;
+orcmd(char **ahost, u_int rport, const char *locuser, const char *remuser,
+ const char *cmd, int *fd2p)
{
return orcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET);
}
int
-orcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
- char **ahost;
- u_int rport;
- const char *locuser, *remuser, *cmd;
- int *fd2p;
- int af;
+orcmd_af(char **ahost, u_int rport, const char *locuser, const char *remuser,
+ const char *cmd, int *fd2p, int af)
{
static char hbuf[MAXHOSTNAMELEN];
char pbuf[NI_MAXSERV];
@@ -189,7 +174,7 @@
error = getaddrinfo(*ahost, pbuf, &hints, &res);
if (error) {
warnx("%s: %s", *ahost, gai_strerror(error)); /*XXX*/
- return (-1);
+ return -1;
}
if (res->ai_canonname) {
strlcpy(hbuf, res->ai_canonname, sizeof(hbuf));
@@ -198,17 +183,13 @@
error = resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p);
freeaddrinfo(res);
- return (error);
+ return error;
}
/*ARGSUSED*/
static int
-resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p)
- struct addrinfo *res;
- char **ahost;
- u_int32_t rport;
- const char *locuser, *remuser, *cmd;
- int *fd2p;
+resrcmd(struct addrinfo *res, char **ahost, u_int32_t rport,
+ const char *locuser, const char *remuser, const char *cmd, int *fd2p)
{
struct addrinfo *r;
struct sockaddr_storage from;
@@ -246,7 +227,7 @@
continue;
} else {
(void)sigprocmask(SIG_SETMASK, &omask, NULL);
- return (-1);
+ return -1;
}
}
fcntl(s, F_SETOWN, pid);
@@ -287,7 +268,7 @@
(void)fprintf(stderr, "%s: %s\n", res->ai_canonname,
strerror(errno));
(void)sigprocmask(SIG_SETMASK, &omask, NULL);
- return (-1);
+ return -1;
}
lport--;
if (fd2p == 0) {
@@ -318,7 +299,8 @@
if (errno != 0)
warn("poll: setting up stderr");
else
- warnx("poll: protocol failure in circuit setup");
+ warnx(
+ "poll: protocol failure in circuit setup");
(void)close(s2);
goto bad;
}
@@ -339,7 +321,8 @@
NULL, 0, num, sizeof(num), NI_NUMERICSERV) != 0 ||
(atoi(num) >= IPPORT_RESERVED ||
atoi(num) < IPPORT_RESERVED / 2)) {
- warnx("rcmd: protocol failure in circuit setup.");
+ warnx(
+ "rcmd: protocol failure in circuit setup.");
goto bad2;
}
break;
@@ -364,14 +347,14 @@
goto bad2;
}
(void)sigprocmask(SIG_SETMASK, &omask, NULL);
- return (s);
+ return s;
bad2:
if (lport)
(void)close(*fd2p);
bad:
(void)close(s);
(void)sigprocmask(SIG_SETMASK, &omask, NULL);
- return (-1);
+ return -1;
}
/*
@@ -379,12 +362,8 @@
*/
/* ARGSUSED */
static int
-rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd)
- char **ahost;
- u_int32_t rport;
- const char *locuser, *remuser, *cmd;
- int *fd2p;
- const char *rshcmd;
+rshrcmd(int af, char **ahost, u_int32_t rport, const char *locuser,
+ const char *remuser, const char *cmd, int *fd2p, const char *rshcmd)
{
pid_t pid;
int sp[2], ep[2];
@@ -405,28 +384,28 @@
/* locuser must exist on this host. */
if (getpwnam_r(locuser, &pwres, pwbuf, sizeof(pwbuf), &pw) != 0 ||
pw == NULL) {
- warnx("rshrcmd: unknown user: %s", locuser);
- return(-1);
+ warnx("%s: unknown user: %s", __func__, locuser);
+ return -1;
}
/* get a socketpair we'll use for stdin and stdout. */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sp) < 0) {
- warn("rshrcmd: socketpair");
- return (-1);
+ warn("%s: socketpair", __func__);
+ return -1;
}
/* we will use this for the fd2 pointer */
if (fd2p) {
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, ep) < 0) {
- warn("rshrcmd: socketpair");
- return (-1);
+ warn("%s: socketpair", __func__);
+ return -1;
}
*fd2p = ep[0];
}
pid = fork();
if (pid < 0) {
- warn("rshrcmd: fork");
- return (-1);
+ warn("%s: fork", __func__);
+ return -1;
}
if (pid == 0) {
/*
@@ -436,25 +415,25 @@
*/
(void)close(sp[0]);
if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) {
- warn("rshrcmd: dup2");
+ warn("%s: dup2", __func__);
_exit(1);
}
(void)close(sp[1]);
if (fd2p) {
if (dup2(ep[1], 2) < 0) {
- warn("rshrcmd: dup2");
+ warn("%s: dup2", __func__);
_exit(1);
}
(void)close(ep[0]);
(void)close(ep[1]);
} else if (dup2(0, 2) < 0) {
- warn("rshrcmd: dup2");
+ warn("%s: dup2", __func__);
_exit(1);
}
/* fork again to lose parent. */
pid = fork();
if (pid < 0) {
- warn("rshrcmd: second fork");
+ warn("%s: second fork", __func__);
_exit(1);
}
if (pid > 0)
@@ -462,13 +441,13 @@
/* Orphan. Become local user for rshprog. */
if (setuid(pw->pw_uid)) {
- warn("rshrcmd: setuid(%lu)", (u_long)pw->pw_uid);
+ warn("%s: setuid(%lu)", __func__, (u_long)pw->pw_uid);
_exit(1);
}
Home |
Main Index |
Thread Index |
Old Index