workarounds.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2001 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Workarounds for known system software bugs. This module provides wrappers
* around library functions and system calls that are known to have problems
* on some systems. Most of these workarounds won't do any harm on regular
* systems.
*
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#ifndef lint
char sccsid[] = "@(#) workarounds.c 1.6 96/03/19 16:22:25";
#endif
#include <netdb.h>
#include <errno.h>
#include <stdio.h>
#include <syslog.h>
#include <string.h>
extern int errno;
#include "tcpd.h"
/*
* Some AIX versions advertise a too small MAXHOSTNAMELEN value (32).
* Result: long hostnames would be truncated, and connections would be
* dropped because of host name verification failures. Adrian van Bloois
* (A.vanBloois@info.nic.surfnet.nl) figured out what was the problem.
*/
#if (MAXHOSTNAMELEN < 64)
#endif
#ifndef MAXHOSTNAMELEN
#endif
/*
* You have this problem when the compiler complains about illegal lvalues
* or something like that. The following code fixes this mutant behaviour.
* It should not be enabled on "normal" systems.
*
* Bug reported by ben@piglet.cr.usgs.gov (Rev. Ben A. Mesander).
*/
#ifdef INET_ADDR_BUG
long fix_inet_addr(string)
char *string;
{
}
#endif /* INET_ADDR_BUG */
/*
* With some System-V versions, the fgets() library function does not
* account for partial reads from e.g. sockets. The result is that fgets()
* gives up too soon, causing username lookups to fail. Problem first
* reported for IRIX 4.0.5, by Steve Kotsopoulos <steve@ecf.toronto.edu>.
* The following code works around the problem. It does no harm on "normal"
* systems.
*/
#ifdef BROKEN_FGETS
char *buf;
int len;
{
int c;
/*
* Copy until the buffer fills up, until EOF, or until a newline is
* found.
*/
len--;
*cp++ = c;
if (c == '\n')
break;
}
/*
* Return 0 if nothing was read. This is correct even when a silly buffer
* length was specified.
*/
*cp = 0;
return (buf);
} else {
return (0);
}
}
#endif /* BROKEN_FGETS */
/*
* With early SunOS 5 versions, recvfrom() does not completely fill in the
* source address structure when doing a non-destructive read. The following
* code works around the problem. It does no harm on "normal" systems.
*/
#ifdef RECVFROM_BUG
int sock;
char *buf;
int buflen;
int flags;
int *fromlen;
{
int ret;
/* Assume that both ends of a socket belong to the same address family. */
int my_addr_len = sizeof(my_addr);
tcpd_warn("getsockname: %m");
} else {
}
}
}
return (ret);
}
#endif /* RECVFROM_BUG */
/*
* The Apollo SR10.3 and some SYSV4 getpeername(2) versions do not return an
* error in case of a datagram-oriented socket. Instead, they claim that all
* UDP requests come from address 0.0.0.0. The following code works around
* the problem. It does no harm on "normal" systems.
*/
#ifdef GETPEERNAME_BUG
int sock;
int *len;
{
int ret;
return (-1);
} else {
return (ret);
}
}
#endif /* GETPEERNAME_BUG */
/*
* According to Karl Vogel (vogelke@c-17igp.wpafb.af.mil) some Pyramid
* versions have no yp_default_domain() function. We use getdomainname()
* instead.
*/
#ifdef USE_GETDOMAIN
int yp_get_default_domain(ptr)
char **ptr;
{
static char mydomain[MAXHOSTNAMELEN];
}
#endif /* USE_GETDOMAIN */
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
/*
* Solaris 2.4 gethostbyname() has problems with multihomed hosts. When
* doing DNS through NIS, only one host address ends up in the address list.
* All other addresses end up in the hostname alias list, interspersed with
* copies of the official host name. This would wreak havoc with tcpd's
* hostname double checks. Below is a workaround that should do no harm when
* accidentally left in. A side effect of the workaround is that address
* list members are no longer properly aligned for structure access.
*/
#ifdef SOLARIS_24_GETHOSTBYNAME_BUG
char *name;
{
char **o_addr_list;
char **o_aliases;
char **n_addr_list;
int broken_gethostbyname = 0;
broken_gethostbyname = 1;
}
}
if (broken_gethostbyname) {
*n_addr_list = 0;
}
}
return (hp);
}
#endif /* SOLARIS_24_GETHOSTBYNAME_BUG */
/*
* Horror! Some FreeBSD 2.0 libc routines call strtok(). Since tcpd depends
* heavily on strtok(), strange things may happen. Workaround: use our
* private strtok(). This has been fixed in the meantime.
*/
#ifdef USE_STRSEP
char *buf;
char *sep;
{
static char *state;
char *result;
if (buf)
/* void */ ;
return (result);
}
#endif /* USE_STRSEP */
/*
* IRIX 5.3 (and possibly earlier versions, too) library routines call the
* non-reentrant strtok() library routine, causing hosts to slip through
* strtok() function. FreeBSD 2.0 has a similar problem (fixed in 2.0.5).
*/
#ifdef LIBC_CALLS_STRTOK
char *buf;
char *sep;
{
static char *state;
char *result;
if (buf)
/*
* Skip over separator characters and detect end of string.
*/
return (0);
/*
* Skip over non-separator characters and terminate result.
*/
*state++ = 0;
return (result);
}
#endif /* LIBC_CALLS_STRTOK */