summaryrefslogtreecommitdiff
path: root/lib/libwrap/rfc931.c
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-10-14 00:56:17 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-10-14 00:56:17 +0000
commitf6091bbe12538b3e722800dcd3e43cf014dc17e6 (patch)
tree0061ec9397b880b94546484b17273eac081d654d /lib/libwrap/rfc931.c
parentea55ada60b971559c0cd36421576ee1f0502d9a3 (diff)
tcp wrapper support for IPv6. from netbsd.
TODO: scoped address support may need more consideration (we are taking safer side now - rejects too much).
Diffstat (limited to 'lib/libwrap/rfc931.c')
-rw-r--r--lib/libwrap/rfc931.c98
1 files changed, 81 insertions, 17 deletions
diff --git a/lib/libwrap/rfc931.c b/lib/libwrap/rfc931.c
index 4bb94294e6c..8986d105a88 100644
--- a/lib/libwrap/rfc931.c
+++ b/lib/libwrap/rfc931.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rfc931.c,v 1.1 1997/02/26 03:06:56 downsj Exp $ */
+/* $OpenBSD: rfc931.c,v 1.2 2000/10/14 00:56:15 itojun Exp $ */
/*
* rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC
@@ -15,7 +15,7 @@
#if 0
static char sccsid[] = "@(#) rfc931.c 1.10 95/01/02 16:11:34";
#else
-static char rcsid[] = "$OpenBSD: rfc931.c,v 1.1 1997/02/26 03:06:56 downsj Exp $";
+static char rcsid[] = "$OpenBSD: rfc931.c,v 1.2 2000/10/14 00:56:15 itojun Exp $";
#endif
#endif
@@ -75,19 +75,61 @@ int sig;
/* rfc931 - return remote user name, given socket structures */
void rfc931(rmt_sin, our_sin, dest)
-struct sockaddr_in *rmt_sin;
-struct sockaddr_in *our_sin;
+struct sockaddr *rmt_sin;
+struct sockaddr *our_sin;
char *dest;
{
unsigned rmt_port;
unsigned our_port;
- struct sockaddr_in rmt_query_sin;
- struct sockaddr_in our_query_sin;
+ struct sockaddr_storage rmt_query_sin;
+ struct sockaddr_storage our_query_sin;
char user[256]; /* XXX */
char buffer[512]; /* XXX */
char *cp;
char *result = unknown;
FILE *fp;
+ int salen;
+ u_short *rmt_portp;
+ u_short *our_portp;
+
+ /* address family must be the same */
+ if (rmt_sin->sa_family != our_sin->sa_family) {
+ STRN_CPY(dest, result, STRING_LENGTH);
+ return;
+ }
+ switch (rmt_sin->sa_family) {
+ case AF_INET:
+ salen = sizeof(struct sockaddr_in);
+ rmt_portp = &((struct sockaddr_in *)&rmt_sin)->sin_port;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ salen = sizeof(struct sockaddr_in6);
+ rmt_portp = &((struct sockaddr_in6 *)&rmt_sin)->sin6_port;
+ break;
+#endif
+ default:
+ STRN_CPY(dest, result, STRING_LENGTH);
+ return;
+ }
+ switch (our_sin->sa_family) {
+ case AF_INET:
+ our_portp = &((struct sockaddr_in *)&our_sin)->sin_port;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ our_portp = &((struct sockaddr_in6 *)&our_sin)->sin6_port;
+ break;
+#endif
+ default:
+ STRN_CPY(dest, result, STRING_LENGTH);
+ return;
+ }
+
+#ifdef __GNUC__
+ (void)&result; /* Avoid longjmp clobbering */
+ (void)&fp; /* XXX gcc */
+#endif
/*
* Use one unbuffered stdio stream for writing to and for reading from
@@ -99,7 +141,7 @@ char *dest;
* sockets.
*/
- if ((fp = fsocket(AF_INET, SOCK_STREAM, 0)) != 0) {
+ if ((fp = fsocket(rmt_sin->sa_family, SOCK_STREAM, 0)) != 0) {
setbuf(fp, (char *) 0);
/*
@@ -119,15 +161,37 @@ char *dest;
* addresses from the query socket.
*/
- our_query_sin = *our_sin;
- our_query_sin.sin_port = htons(ANY_PORT);
- rmt_query_sin = *rmt_sin;
- rmt_query_sin.sin_port = htons(RFC931_PORT);
+ memcpy(&our_query_sin, our_sin, salen);
+ switch (our_query_sin.ss_family) {
+ case AF_INET:
+ ((struct sockaddr_in *)&our_query_sin)->sin_port =
+ htons(ANY_PORT);
+ break;
+#ifdef INET6
+ case AF_INET6:
+ ((struct sockaddr_in6 *)&our_query_sin)->sin6_port =
+ htons(ANY_PORT);
+ break;
+#endif
+ }
+ memcpy(&rmt_query_sin, rmt_sin, salen);
+ switch (rmt_query_sin.ss_family) {
+ case AF_INET:
+ ((struct sockaddr_in *)&rmt_query_sin)->sin_port =
+ htons(RFC931_PORT);
+ break;
+#ifdef INET6
+ case AF_INET6:
+ ((struct sockaddr_in6 *)&rmt_query_sin)->sin6_port =
+ htons(RFC931_PORT);
+ break;
+#endif
+ }
if (bind(fileno(fp), (struct sockaddr *) & our_query_sin,
- sizeof(our_query_sin)) >= 0 &&
+ salen) >= 0 &&
connect(fileno(fp), (struct sockaddr *) & rmt_query_sin,
- sizeof(rmt_query_sin)) >= 0) {
+ salen) >= 0) {
/*
* Send query to server. Neglect the risk that a 13-byte
@@ -136,8 +200,8 @@ char *dest;
*/
fprintf(fp, "%u,%u\r\n",
- ntohs(rmt_sin->sin_port),
- ntohs(our_sin->sin_port));
+ ntohs(*rmt_portp),
+ ntohs(*our_portp));
fflush(fp);
/*
@@ -151,8 +215,8 @@ char *dest;
&& ferror(fp) == 0 && feof(fp) == 0
&& sscanf(buffer, "%u , %u : USERID :%*[^:]:%255s",
&rmt_port, &our_port, user) == 3
- && ntohs(rmt_sin->sin_port) == rmt_port
- && ntohs(our_sin->sin_port) == our_port) {
+ && ntohs(*rmt_portp) == rmt_port
+ && ntohs(*our_portp) == our_port) {
/*
* Strip trailing carriage return. It is part of the