|
Packit Service |
99d1c0 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit Service |
99d1c0 |
/*
|
|
Packit Service |
99d1c0 |
* Copyright (C) 2004 by the Massachusetts Institute of Technology,
|
|
Packit Service |
99d1c0 |
* Cambridge, MA, USA. All Rights Reserved.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* This software is being provided to you, the LICENSEE, by the
|
|
Packit Service |
99d1c0 |
* Massachusetts Institute of Technology (M.I.T.) under the following
|
|
Packit Service |
99d1c0 |
* license. By obtaining, using and/or copying this software, you agree
|
|
Packit Service |
99d1c0 |
* that you have read, understood, and will comply with these terms and
|
|
Packit Service |
99d1c0 |
* conditions:
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* Export of this software from the United States of America may
|
|
Packit Service |
99d1c0 |
* require a specific license from the United States Government.
|
|
Packit Service |
99d1c0 |
* It is the responsibility of any person or organization contemplating
|
|
Packit Service |
99d1c0 |
* export to obtain such a license before exporting.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute
|
|
Packit Service |
99d1c0 |
* this software and its documentation for any purpose and without fee or
|
|
Packit Service |
99d1c0 |
* royalty is hereby granted, provided that you agree to comply with the
|
|
Packit Service |
99d1c0 |
* following copyright notice and statements, including the disclaimer, and
|
|
Packit Service |
99d1c0 |
* that the same appear on ALL copies of the software and documentation,
|
|
Packit Service |
99d1c0 |
* including modifications that you make for internal use or for
|
|
Packit Service |
99d1c0 |
* distribution:
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
|
|
Packit Service |
99d1c0 |
* OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not
|
|
Packit Service |
99d1c0 |
* limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
|
Packit Service |
99d1c0 |
* MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
|
|
Packit Service |
99d1c0 |
* THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
|
|
Packit Service |
99d1c0 |
* PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* The name of the Massachusetts Institute of Technology or M.I.T. may NOT
|
|
Packit Service |
99d1c0 |
* be used in advertising or publicity pertaining to distribution of the
|
|
Packit Service |
99d1c0 |
* software. Title to copyright in this software and any associated
|
|
Packit Service |
99d1c0 |
* documentation shall at all times remain with M.I.T., and USER agrees to
|
|
Packit Service |
99d1c0 |
* preserve same.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* Furthermore if you modify this software you must label
|
|
Packit Service |
99d1c0 |
* your software as modified software and not distribute it in such a
|
|
Packit Service |
99d1c0 |
* fashion that it might be confused with the original M.I.T. software.
|
|
Packit Service |
99d1c0 |
*/
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
/*
|
|
Packit Service |
99d1c0 |
* Approach overview:
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* If a system version is available but buggy, save handles to it,
|
|
Packit Service |
99d1c0 |
* redefine the names to refer to static functions defined here, and
|
|
Packit Service |
99d1c0 |
* in those functions, call the system versions and fix up the
|
|
Packit Service |
99d1c0 |
* returned data. Use the native data structures and flag values.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* If no system version exists, use gethostby* and fake it. Define
|
|
Packit Service |
99d1c0 |
* the data structures and flag values locally.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* On macOS, getaddrinfo results aren't cached (though gethostbyname
|
|
Packit Service |
99d1c0 |
* results are), so we need to build a cache here. Now things are
|
|
Packit Service |
99d1c0 |
* getting really messy. Because the cache is in use, we use
|
|
Packit Service |
99d1c0 |
* getservbyname, and throw away thread safety. (Not that the cache
|
|
Packit Service |
99d1c0 |
* is thread safe, but when we get locking support, that'll be dealt
|
|
Packit Service |
99d1c0 |
* with.) This code needs tearing down and rebuilding, soon.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* Note that recent Windows developers' code has an interesting hack:
|
|
Packit Service |
99d1c0 |
* When you include the right header files, with the right set of
|
|
Packit Service |
99d1c0 |
* macros indicating system versions, you'll get an inline function
|
|
Packit Service |
99d1c0 |
* that looks for getaddrinfo (or whatever) in the system library, and
|
|
Packit Service |
99d1c0 |
* calls it if it's there. If it's not there, it fakes it with
|
|
Packit Service |
99d1c0 |
* gethostby* calls.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* We're taking a simpler approach: A system provides these routines or
|
|
Packit Service |
99d1c0 |
* it does not.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* Someday, we may want to take into account different versions (say,
|
|
Packit Service |
99d1c0 |
* different revs of GNU libc) where some are broken in one way, and
|
|
Packit Service |
99d1c0 |
* some work or are broken in another way. Cross that bridge when we
|
|
Packit Service |
99d1c0 |
* come to it.
|
|
Packit Service |
99d1c0 |
*/
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
/* To do, maybe:
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* + For AIX 4.3.3, using the RFC 2133 definition: Implement
|
|
Packit Service |
99d1c0 |
* AI_NUMERICHOST. It's not defined in the header file.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* For certain (old?) versions of GNU libc, AI_NUMERICHOST is
|
|
Packit Service |
99d1c0 |
* defined but not implemented.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* + Use gethostbyname2, inet_aton and other IPv6 or thread-safe
|
|
Packit Service |
99d1c0 |
* functions if available. But, see
|
|
Packit Service |
99d1c0 |
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=135182 for one
|
|
Packit Service |
99d1c0 |
* gethostbyname2 problem on Linux. And besides, if a platform is
|
|
Packit Service |
99d1c0 |
* supporting IPv6 at all, they really should be doing getaddrinfo
|
|
Packit Service |
99d1c0 |
* by now.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* + inet_ntop, inet_pton
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* + Conditionally export/import the function definitions, so a
|
|
Packit Service |
99d1c0 |
* library can have a single copy instead of multiple.
|
|
Packit Service |
99d1c0 |
*
|
|
Packit Service |
99d1c0 |
* + Upgrade host requirements to include working implementations of
|
|
Packit Service |
99d1c0 |
* these functions, and throw all this away. Pleeease? :-)
|
|
Packit Service |
99d1c0 |
*/
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
#include "k5-platform.h"
|
|
Packit Service |
99d1c0 |
#include "k5-thread.h"
|
|
Packit Service |
99d1c0 |
#include "port-sockets.h"
|
|
Packit Service |
99d1c0 |
#include "socket-utils.h"
|
|
Packit Service |
99d1c0 |
#include "fake-addrinfo.h"
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
#if defined (__APPLE__) && defined (__MACH__) && 0
|
|
Packit Service |
99d1c0 |
#define FAI_CACHE
|
|
Packit Service |
99d1c0 |
#endif
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
struct face {
|
|
Packit Service |
99d1c0 |
struct in_addr *addrs4;
|
|
Packit Service |
99d1c0 |
struct in6_addr *addrs6;
|
|
Packit Service |
99d1c0 |
unsigned int naddrs4, naddrs6;
|
|
Packit Service |
99d1c0 |
time_t expiration;
|
|
Packit Service |
99d1c0 |
char *canonname, *name;
|
|
Packit Service |
99d1c0 |
struct face *next;
|
|
Packit Service |
99d1c0 |
};
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
/* fake addrinfo cache */
|
|
Packit Service |
99d1c0 |
struct fac {
|
|
Packit Service |
99d1c0 |
k5_mutex_t lock;
|
|
Packit Service |
99d1c0 |
struct face *data;
|
|
Packit Service |
99d1c0 |
};
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
extern struct fac krb5int_fac;
|
|
Packit Service |
99d1c0 |
|
|
Packit Service |
99d1c0 |
extern int krb5int_init_fac (void);
|
|
Packit Service |
99d1c0 |
extern void krb5int_fini_fac (void);
|