rfc931.c (56977) | rfc931.c (63152) |
---|---|
1 /* 2 * rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC 3 * 1413 protocols. It queries an RFC 931 etc. compatible daemon on a remote 4 * host to look up the owner of a connection. The information should not be 5 * used for authentication purposes. This routine intercepts alarm signals. 6 * 7 * Diagnostics are reported through syslog(3). 8 * 9 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 10 * | 1 /* 2 * rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC 3 * 1413 protocols. It queries an RFC 931 etc. compatible daemon on a remote 4 * host to look up the owner of a connection. The information should not be 5 * used for authentication purposes. This routine intercepts alarm signals. 6 * 7 * Diagnostics are reported through syslog(3). 8 * 9 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 10 * |
11 * $FreeBSD: head/contrib/tcp_wrappers/rfc931.c 56977 2000-02-03 10:27:03Z shin $ | 11 * $FreeBSD: head/contrib/tcp_wrappers/rfc931.c 63152 2000-07-14 15:07:37Z dwmalone $ |
12 */ 13 14#ifndef lint 15static char sccsid[] = "@(#) rfc931.c 1.10 95/01/02 16:11:34"; 16#endif 17 18/* System libraries. */ 19 20#include <stdio.h> 21#include <syslog.h> 22#include <sys/types.h> 23#include <sys/socket.h> 24#include <netinet/in.h> 25#include <setjmp.h> 26#include <signal.h> 27#include <string.h> 28 | 12 */ 13 14#ifndef lint 15static char sccsid[] = "@(#) rfc931.c 1.10 95/01/02 16:11:34"; 16#endif 17 18/* System libraries. */ 19 20#include <stdio.h> 21#include <syslog.h> 22#include <sys/types.h> 23#include <sys/socket.h> 24#include <netinet/in.h> 25#include <setjmp.h> 26#include <signal.h> 27#include <string.h> 28 |
29#ifndef SEEK_SET 30#define SEEK_SET 0 31#endif 32 |
|
29/* Local stuff. */ 30 31#include "tcpd.h" 32 33#define RFC931_PORT 113 /* Semi-well-known port */ 34#define ANY_PORT 0 /* Any old port will do */ 35 36int rfc931_timeout = RFC931_TIMEOUT;/* Global so it can be changed */ --- 73 unchanged lines hidden (view full) --- 110 break; 111 default: 112 STRN_CPY(dest, result, STRING_LENGTH); 113 return; 114 } 115#endif 116 117 /* | 33/* Local stuff. */ 34 35#include "tcpd.h" 36 37#define RFC931_PORT 113 /* Semi-well-known port */ 38#define ANY_PORT 0 /* Any old port will do */ 39 40int rfc931_timeout = RFC931_TIMEOUT;/* Global so it can be changed */ --- 73 unchanged lines hidden (view full) --- 114 break; 115 default: 116 STRN_CPY(dest, result, STRING_LENGTH); 117 return; 118 } 119#endif 120 121 /* |
118 * Use one unbuffered stdio stream for writing to and for reading from 119 * the RFC931 etc. server. This is done because of a bug in the SunOS 120 * 4.1.x stdio library. The bug may live in other stdio implementations, 121 * too. When we use a single, buffered, bidirectional stdio stream ("r+" 122 * or "w+" mode) we read our own output. Such behaviour would make sense | 122 * If we use a single, buffered, bidirectional stdio stream ("r+" or 123 * "w+" mode) we may read our own output. Such behaviour would make sense |
123 * with resources that support random-access operations, but not with | 124 * with resources that support random-access operations, but not with |
124 * sockets. | 125 * sockets. ANSI C suggests several functions which can be called when 126 * you want to change IO direction, fseek seems the most portable. |
125 */ 126 127#ifdef INET6 128 if ((fp = fsocket(our_sin->sa_family, SOCK_STREAM, 0)) != 0) { 129#else 130 if ((fp = fsocket(AF_INET, SOCK_STREAM, 0)) != 0) { 131#endif | 127 */ 128 129#ifdef INET6 130 if ((fp = fsocket(our_sin->sa_family, SOCK_STREAM, 0)) != 0) { 131#else 132 if ((fp = fsocket(AF_INET, SOCK_STREAM, 0)) != 0) { 133#endif |
132 setbuf(fp, (char *) 0); 133 | |
134 /* 135 * Set up a timer so we won't get stuck while waiting for the server. 136 */ 137 138 if (setjmp(timebuf) == 0) { 139 signal(SIGALRM, timeout); 140 alarm(rfc931_timeout); 141 --- 46 unchanged lines hidden (view full) --- 188#ifdef INET6 189 ntohs(((struct sockaddr_in *)rmt_sin)->sin_port), 190 ntohs(((struct sockaddr_in *)our_sin)->sin_port)); 191#else 192 ntohs(rmt_sin->sin_port), 193 ntohs(our_sin->sin_port)); 194#endif 195 fflush(fp); | 134 /* 135 * Set up a timer so we won't get stuck while waiting for the server. 136 */ 137 138 if (setjmp(timebuf) == 0) { 139 signal(SIGALRM, timeout); 140 alarm(rfc931_timeout); 141 --- 46 unchanged lines hidden (view full) --- 188#ifdef INET6 189 ntohs(((struct sockaddr_in *)rmt_sin)->sin_port), 190 ntohs(((struct sockaddr_in *)our_sin)->sin_port)); 191#else 192 ntohs(rmt_sin->sin_port), 193 ntohs(our_sin->sin_port)); 194#endif 195 fflush(fp); |
196 fseek(fp, 0, SEEK_SET); |
|
196 197 /* 198 * Read response from server. Use fgets()/sscanf() so we can 199 * work around System V stdio libraries that incorrectly 200 * assume EOF when a read from a socket returns less than 201 * requested. 202 */ 203 --- 28 unchanged lines hidden --- | 197 198 /* 199 * Read response from server. Use fgets()/sscanf() so we can 200 * work around System V stdio libraries that incorrectly 201 * assume EOF when a read from a socket returns less than 202 * requested. 203 */ 204 --- 28 unchanged lines hidden --- |