diff options
author | shin <shin@FreeBSD.org> | 2000-01-25 14:52:10 +0000 |
---|---|---|
committer | shin <shin@FreeBSD.org> | 2000-01-25 14:52:10 +0000 |
commit | fc29f7bcf7236935ba5c171ea553ac7dca533e8c (patch) | |
tree | 13e93b815761d57bc661099e5a2b7bcb2882b762 /lib | |
parent | 4497b0fbabcff52472040173a4ea879ec212ecaa (diff) | |
download | FreeBSD-src-fc29f7bcf7236935ba5c171ea553ac7dca533e8c.zip FreeBSD-src-fc29f7bcf7236935ba5c171ea553ac7dca533e8c.tar.gz |
several tcp apps IPv6 update
-inetd
-rshd
-rlogind
-telnetd
-rsh
-rlogin
Reviewed by: freebsd-arch, cvs-committers
Obtained from: KAME project
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/net/rcmd.3 | 21 | ||||
-rw-r--r-- | lib/libc/net/rcmd.c | 13 | ||||
-rw-r--r-- | lib/libutil/Makefile | 3 | ||||
-rw-r--r-- | lib/libutil/libutil.h | 3 | ||||
-rw-r--r-- | lib/libutil/realhostname.3 | 3 | ||||
-rw-r--r-- | lib/libutil/realhostname.c | 95 | ||||
-rw-r--r-- | lib/libutil/realhostname_sa.3 | 135 |
8 files changed, 270 insertions, 7 deletions
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 87ac304..cde2734 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -58,7 +58,9 @@ MLINKS+=if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ if_indextoname.3 if_freenameindex.3 MLINKS+=linkaddr.3 link_addr.3 linkaddr.3 link_ntoa.3 #MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 -MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 +MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ + rcmd.3 iruserok_af.3 rcmd.3 rresvport_af.3 rcmd.3 ruserok_af.3 \ + rcmd.3 rcmd_af.3 MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ resolver.3 res_mkquery.3 resolver.3 res_query.3 \ resolver.3 res_search.3 resolver.3 res_send.3 diff --git a/lib/libc/net/rcmd.3 b/lib/libc/net/rcmd.3 index b00f94a..ed6478b 100644 --- a/lib/libc/net/rcmd.3 +++ b/lib/libc/net/rcmd.3 @@ -40,6 +40,7 @@ .Nm rresvport , .Nm iruserok , .Nm ruserok , +.Nm rcmd_af , .Nm rresvport_af , .Nm iruserok_af , .Nm ruserok_af @@ -55,7 +56,9 @@ .Ft int .Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" .Ft int -.Fn rresvport_af "int *port" "int family" +.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" +.Ft int +.Fn rresvport_af "int *port" "int af" .Ft int .Fn iruserok_af "void *raddr" "int superuser" "const char *ruser" "const char *luser" "int af" .Ft int @@ -184,17 +187,26 @@ It requires trusting the local DNS at most, while the function requires trusting the entire DNS, which can be spoofed. .Pp Functions with ``_af'' suffix, i.e. +.Fn rcmd_af , .Fn rresvport_af , -.Fn iruserok_af and +.Fn iruserok_af +and .Fn ruserok_af , works just as same as functions without ``_af'', and is capable of handling both IPv6 port and IPv4 port. +Functions without +.Dq Li _af +works for IPv4 only. To switch address family, .Fa af argument must be filled with -.Dv AF_INET +.Dv AF_INET , or .Dv AF_INET6 . +For +.Fn rcmd_af , +.Dv PF_UNSPEC +is also allowed. .Sh DIAGNOSTICS The .Fn rcmd @@ -230,6 +242,9 @@ functions appeared in .Fn rresvport_af appeared in RFC2292, and implemented by WIDE project for Hydrangea IPv6 protocol stack kit. +.Fn rcmd_af +appeared in draft-ietf-ipngwg-rfc2292bis-01.txt, +and implemented by WIDE/KAME IPv6 protocol stack kit. .Fn iruserok_af and .Fn rusreok_af diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index a1416ed..8130410 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -80,6 +80,17 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) const char *locuser, *remuser, *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; +{ struct addrinfo hints, *res, *ai; struct sockaddr_storage from; fd_set reads; @@ -94,7 +105,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p) memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; - hints.ai_family = AF_UNSPEC; + hints.ai_family = af; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0; (void)snprintf(num, sizeof(num), "%d", ntohs(rport)); diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index f0e9fda..e79b4ad 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -5,6 +5,7 @@ LIB= util SHLIB_MAJOR= 2 SHLIB_MINOR= 2 CFLAGS+=-Wall -DLIBC_SCCS -I${.CURDIR} -I${.CURDIR}/../../sys +CFLAGS+=-DINET6 SRCS= login.c login_tty.c logout.c logwtmp.c pty.c setproctitle.c \ login_cap.c login_class.c login_auth.c login_times.c login_ok.c \ _secure_path.c uucplock.c property.c auth.c realhostname.c fparseln.c \ @@ -13,7 +14,7 @@ INCS= libutil.h login_cap.h MAN3+= login.3 login_auth.3 login_tty.3 logout.3 logwtmp.3 pty.3 \ setproctitle.3 login_cap.3 login_class.3 login_times.3 login_ok.3 \ _secure_path.3 uucplock.3 property.3 auth.3 realhostname.3 \ - trimdomain.3 fparseln.3 + realhostname_sa.3 trimdomain.3 fparseln.3 MAN5+= login.conf.5 auth.conf.5 MLINKS+= property.3 properties_read.3 property.3 properties_free.3 MLINKS+= property.3 property_find.3 diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index 4923700..927a384 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -60,6 +60,9 @@ void properties_free __P((properties list)); char *property_find __P((properties list, const char *name)); char *auth_getval __P((const char *name)); int realhostname __P((char *host, size_t hsize, const struct in_addr *ip)); +struct sockaddr; +int realhostname_sa __P((char *host, size_t hsize, struct sockaddr *addr, + int addrlen)); #ifdef _STDIO_H_ /* avoid adding new includes */ char *fparseln __P((FILE *, size_t *, size_t *, const char[3], int)); #endif diff --git a/lib/libutil/realhostname.3 b/lib/libutil/realhostname.3 index 1f2e6a9..acf370b 100644 --- a/lib/libutil/realhostname.3 +++ b/lib/libutil/realhostname.3 @@ -103,4 +103,5 @@ now contains the numeric value of .Sh SEE ALSO .Xr gethostbyaddr 3 , .Xr gethostbyname 3 , -.Xr inet_ntoa 3 +.Xr inet_ntoa 3 , +.Xr realhostname_sa 3 diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c index fa7f4b1..7236890 100644 --- a/lib/libutil/realhostname.c +++ b/lib/libutil/realhostname.c @@ -38,6 +38,17 @@ #include "libutil.h" +/* wrapper for KAME-special getnameinfo() */ +#ifndef NI_WITHSCOPEID +#define NI_WITHSCOPEID 0 +#endif + +struct sockinet { + u_char si_len; + u_char si_family; + u_short si_port; +}; + int realhostname(char *host, size_t hsize, const struct in_addr *ip) { @@ -71,3 +82,87 @@ realhostname(char *host, size_t hsize, const struct in_addr *ip) return result; } + +int +realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen) +{ + int result, error; + + result = HOSTNAME_INVALIDADDR; + + error = getnameinfo(addr, addrlen, host, hsize, NULL, 0, 0); + if (error == NULL) { + struct addrinfo hints, *res, *ores; + struct sockaddr *sa; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + + error = getaddrinfo(host, NULL, &hints, &res); + if (error) { + result = HOSTNAME_INVALIDNAME; + goto numeric; + } else for (ores = res; ; res = res->ai_next) { + if (res == NULL) { + freeaddrinfo(ores); + result = HOSTNAME_INCORRECTNAME; + goto numeric; + } + sa = res->ai_addr; + if (sa == NULL) { + freeaddrinfo(ores); + result = HOSTNAME_INCORRECTNAME; + goto numeric; + } + if (sa->sa_len == addrlen && + sa->sa_family == addr->sa_family) { + u_int16_t port; + + port = ((struct sockinet *)addr)->si_port; + ((struct sockinet *)addr)->si_port = 0; + if (!memcmp(sa, addr, sa->sa_len)) { + strncpy(host, res->ai_canonname, + hsize); + result = HOSTNAME_FOUND; + ((struct sockinet *)addr)->si_port = + port; + break; + } + ((struct sockinet *)addr)->si_port = port; + } +#ifdef INET6 + /* + * XXX IPv4 mapped IPv6 addr consideraton, + * specified in rfc2373. + */ + if (sa->sa_family == AF_INET && + addr->sa_family == AF_INET6) { + struct in_addr *in; + struct in6_addr *in6; + + in = &((struct sockaddr_in *)sa)->sin_addr; + in6 = &((struct sockaddr_in6 *)addr)->sin6_addr; + if (IN6_IS_ADDR_V4MAPPED(in6) && + !memcmp(&in6->s6_addr[12], in, + sizeof(*in))) { + strncpy(host, res->ai_canonname, + hsize); + result = HOSTNAME_FOUND; + break; + } + } +#endif + } + freeaddrinfo(ores); + } else { + numeric: + getnameinfo(addr, addrlen, host, hsize, NULL, 0, + NI_NUMERICHOST|NI_WITHSCOPEID); + /* XXX: do 'error' check */ + } + + return result; +} + + diff --git a/lib/libutil/realhostname_sa.3 b/lib/libutil/realhostname_sa.3 new file mode 100644 index 0000000..6fef960 --- /dev/null +++ b/lib/libutil/realhostname_sa.3 @@ -0,0 +1,135 @@ +.\" Copyright (C) 1995, 1996, 1997, 1998, 1999, and 2000 WIDE Project. +.\" 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. Neither the name of the project 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 PROJECT 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 PROJECT 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. +.\" +.\" Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" +.Dd January 11, 2000 +.Os +.Dt REALHOSTNAME_SA 3 +.Sh NAME +.Nm realhostname_sa +.Nd "convert an struct sockaddr to the real host name" +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <netinet/in.h> +.Fd #include <libutil.h> +.Ft int +.Fn realhostname_sa "char *host" "size_t hsize" "struct sockaddr *addr" \ +"int addrlen" +.Pp +Link with +.Va -lutil +on the +.Xr cc 1 +command line. +.Sh DESCRIPTION +The function +.Fn realhostname_sa +converts +.Ar addr +to the corresponding host name. This is done by resolving +.Ar addr +to a host name and then ensuring that the host name resolves +back to +.Ar addr . +.Pp +.Ar host +must point to a buffer of at least +.Ar hsize +bytes, and will always be written to by this function. +.Pp +If the name resolution doesn't work both ways or if the host name is longer +than +.Ar hsize +bytes, +.Xr getnameinfo 3 +with NI_NUMERICHOST specified, is used to convert +.Ar addr +to an ASCII form. +.Pp +If the string written to +.Ar host +is +.Ar hsize +bytes long, +.Ar host +will not be NUL terminated. +.Sh RETURN VALUES +.Fn realhostname_sa +will return one of the following constants which are defined in +.Pa libutil.h : +.Pp +.Bl -tag -width XXX -offset XXX +.It Li HOSTNAME_FOUND +A valid host name was found. +.It Li HOSTNAME_INCORRECTNAME +A host name was found, but it did not resolve back to the passed +.Ar ip . +.Ar host +now contains the numeric value of +.Ar ip . +.It Li HOSTNAME_INVALIDADDR +.Ar ip +could not be resolved. +.Ar host +now contains the numeric value of +.Ar ip . +.It Li HOSTNAME_INVALIDNAME +A host name was found, but it could not be resolved back to any ip number. +.Ar host +now contains the numeric value of +.Ar ip . +.El +.Sh SEE ALSO +.Xr getaddrinfo 3 , +.Xr getnameinfo 3 , +.Xr realhostname 3 + |