summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/rcmd.c
diff options
context:
space:
mode:
authorshin <shin@FreeBSD.org>2000-02-01 15:55:56 +0000
committershin <shin@FreeBSD.org>2000-02-01 15:55:56 +0000
commit9742b65930b8abd4b6bb0418e50cbca5331b631d (patch)
tree391da68b04533321280e67b6f27f0cbdc2bd2d14 /lib/libc/net/rcmd.c
parent6f79c7e06bf635130575f20941730e8d7164a7c1 (diff)
downloadFreeBSD-src-9742b65930b8abd4b6bb0418e50cbca5331b631d.zip
FreeBSD-src-9742b65930b8abd4b6bb0418e50cbca5331b631d.tar.gz
sync iruserok() extension API with other BSDs
Some of rcmd related function is need to be updated to support IPv6. Some of them are already updated as standard document. But there is also several de-facto functions and they are not listed in standard documents. They are, iruserok() (used by rlogind, rshd) ruserok() (used by kerberos, etc) KAME package updated those functions in original way. iruserok_af() ruserok_af() But recently there was discussion on IETF IPng mailing list about how to sync those API, and it is decided, -Those function is not standard and not documented. -But let BSDs sync their API as de-facto. And after some discussion, it is announced that -add update to iruserok() as iruserok_sa() -no ruserok() API change(it is only updated internaly) So I sync those API before 4.0 is released. The changes are, -prototype changes -ruserok() internal update (use iruserok_sa() inside) -removal of ruserok_af() -change iruserok_af() as static functioin, and also prefix the name with __. -add iruserok_sa() (Just call __iruserok_af() inside) -adding flag AI_ALL to getipnodebyaddr() called from __icheckhost(). This is necessary to support IPv4 communication via AF_INET6 socket could be correctly authenticated via iruserok_sa() -irusreok_af() call is replaced to iruserok_sa() call in rlogind, and rshd. Approved by: jkh
Diffstat (limited to 'lib/libc/net/rcmd.c')
-rw-r--r--lib/libc/net/rcmd.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index 1448f14..63ea58f 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -68,6 +68,7 @@ extern int innetgr __P(( const char *, const char *, const char *, const char *
#define max(a, b) ((a > b) ? a : b)
+static int __iruserok_af __P((void *, int, const char *, const char *, int));
int __ivaliduser __P((FILE *, u_int32_t, const char *, const char *));
static int __icheckhost __P((void *, char *, int, int));
@@ -354,34 +355,25 @@ ruserok(rhost, superuser, ruser, luser)
const char *rhost, *ruser, *luser;
int superuser;
{
- return ruserok_af(rhost, superuser, ruser, luser, AF_INET);
-}
+ struct addrinfo hints, *res, *r;
+ int error;
-int
-ruserok_af(rhost, superuser, ruser, luser, af)
- const char *rhost, *ruser, *luser;
- int superuser, af;
-{
- struct hostent *hp;
- union {
- struct in_addr addr_in;
- struct in6_addr addr_in6;
- } addr;
- char **ap;
- int ret, h_error;
-
- if ((hp = getipnodebyname(rhost, af, AI_DEFAULT, &h_error)) == NULL)
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM; /*dummy*/
+ error = getaddrinfo(rhost, "0", &hints, &res);
+ if (error)
return (-1);
- ret = -1;
- for (ap = hp->h_addr_list; *ap; ++ap) {
- bcopy(*ap, &addr, hp->h_length);
- if (iruserok_af(&addr, superuser, ruser, luser, af) == 0) {
- ret = 0;
- break;
+
+ for (r = res; r; r = r->ai_next) {
+ if (iruserok_sa(r->ai_addr, r->ai_addrlen, superuser, ruser,
+ luser) == 0) {
+ freeaddrinfo(res);
+ return (0);
}
}
- freehostent(hp);
- return (ret);
+ freeaddrinfo(res);
+ return (-1);
}
/*
@@ -399,11 +391,12 @@ iruserok(raddr, superuser, ruser, luser)
int superuser;
const char *ruser, *luser;
{
- return iruserok_af(&raddr, superuser, ruser, luser, AF_INET);
+ return __iruserok_af(&raddr, superuser, ruser, luser, AF_INET);
}
-int
-iruserok_af(raddr, superuser, ruser, luser, af)
+/* Other AF support extension of iruserok. */
+static int
+__iruserok_af(raddr, superuser, ruser, luser, af)
void *raddr;
int superuser;
const char *ruser, *luser;
@@ -486,6 +479,37 @@ again:
}
/*
+ * AF independent extension of iruserok. We are passed an sockaddr, and
+ * then call iruserok_af() as the type of sockaddr.
+ *
+ * Returns 0 if ok, -1 if not ok.
+ */
+int
+iruserok_sa(addr, addrlen, superuser, ruser, luser)
+ const void *addr;
+ int addrlen;
+ int superuser;
+ const char *ruser, *luser;
+{
+ struct sockaddr *sa;
+ void *raddr = NULL;
+
+ sa = (struct sockaddr *)addr;
+ switch (sa->sa_family) {
+ case AF_INET:
+ raddr = &((struct sockaddr_in *)sa)->sin_addr;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ raddr = &((struct sockaddr_in6 *)sa)->sin6_addr;
+ break;
+#endif
+ }
+
+ __iruserok_af(raddr, superuser, ruser, luser, sa->sa_family);
+}
+
+/*
* XXX
* Don't make static, used by lpd(8).
*
@@ -648,7 +672,8 @@ __icheckhost(raddr, lhost, af, len)
}
/* Better be a hostname. */
- if ((hp = getipnodebyname(lhost, af, AI_DEFAULT, &h_error)) == NULL)
+ if ((hp = getipnodebyname(lhost, af, AI_ALL|AI_DEFAULT, &h_error))
+ == NULL)
return (0);
/* Spin through ip addresses. */
OpenPOWER on IntegriCloud