xref: /titanic_52/usr/src/lib/gss_mechs/mech_krb5/include/cache-addrinfo.h (revision 159d09a20817016f09b3ea28d1bdada4a336bb91)
1 
2 /*
3  * Copyright (C) 2004 by the Massachusetts Institute of Technology,
4  * Cambridge, MA, USA.  All Rights Reserved.
5  *
6  * This software is being provided to you, the LICENSEE, by the
7  * Massachusetts Institute of Technology (M.I.T.) under the following
8  * license.  By obtaining, using and/or copying this software, you agree
9  * that you have read, understood, and will comply with these terms and
10  * conditions:
11  *
12  * Export of this software from the United States of America may
13  * require a specific license from the United States Government.
14  * It is the responsibility of any person or organization contemplating
15  * export to obtain such a license before exporting.
16  *
17  * WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute
18  * this software and its documentation for any purpose and without fee or
19  * royalty is hereby granted, provided that you agree to comply with the
20  * following copyright notice and statements, including the disclaimer, and
21  * that the same appear on ALL copies of the software and documentation,
22  * including modifications that you make for internal use or for
23  * distribution:
24  *
25  * THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
26  * OR WARRANTIES, EXPRESS OR IMPLIED.  By way of example, but not
27  * limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
28  * MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
29  * THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
30  * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
31  *
32  * The name of the Massachusetts Institute of Technology or M.I.T. may NOT
33  * be used in advertising or publicity pertaining to distribution of the
34  * software.  Title to copyright in this software and any associated
35  * documentation shall at all times remain with M.I.T., and USER agrees to
36  * preserve same.
37  *
38  * Furthermore if you modify this software you must label
39  * your software as modified software and not distribute it in such a
40  * fashion that it might be confused with the original M.I.T. software.
41  */
42 
43 /* Approach overview:
44 
45    If a system version is available but buggy, save handles to it,
46    redefine the names to refer to static functions defined here, and
47    in those functions, call the system versions and fix up the
48    returned data.  Use the native data structures and flag values.
49 
50    If no system version exists, use gethostby* and fake it.  Define
51    the data structures and flag values locally.
52 
53 
54    On Mac OS X, getaddrinfo results aren't cached (though
55    gethostbyname results are), so we need to build a cache here.  Now
56    things are getting really messy.  Because the cache is in use, we
57    use getservbyname, and throw away thread safety.  (Not that the
58    cache is thread safe, but when we get locking support, that'll be
59    dealt with.)  This code needs tearing down and rebuilding, soon.
60 
61 
62    Note that recent Windows developers' code has an interesting hack:
63    When you include the right header files, with the right set of
64    macros indicating system versions, you'll get an inline function
65    that looks for getaddrinfo (or whatever) in the system library, and
66    calls it if it's there.  If it's not there, it fakes it with
67    gethostby* calls.
68 
69    We're taking a simpler approach: A system provides these routines or
70    it does not.
71 
72    Someday, we may want to take into account different versions (say,
73    different revs of GNU libc) where some are broken in one way, and
74    some work or are broken in another way.  Cross that bridge when we
75    come to it.  */
76 
77 /* To do, maybe:
78 
79    + For AIX 4.3.3, using the RFC 2133 definition: Implement
80      AI_NUMERICHOST.  It's not defined in the header file.
81 
82      For certain (old?) versions of GNU libc, AI_NUMERICHOST is
83      defined but not implemented.
84 
85    + Use gethostbyname2, inet_aton and other IPv6 or thread-safe
86      functions if available.  But, see
87      http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=135182 for one
88      gethostbyname2 problem on Linux.  And besides, if a platform is
89      supporting IPv6 at all, they really should be doing getaddrinfo
90      by now.
91 
92    + inet_ntop, inet_pton
93 
94    + Conditionally export/import the function definitions, so a
95      library can have a single copy instead of multiple.
96 
97    + Upgrade host requirements to include working implementations of
98      these functions, and throw all this away.  Pleeease?  :-)  */
99 
100 #include "port-sockets.h"
101 #include "socket-utils.h"
102 #include "k5-platform.h"
103 #include "k5-thread.h"
104 
105 #include "fake-addrinfo.h"
106 
107 #if defined (__APPLE__) && defined (__MACH__)
108 #define FAI_CACHE
109 #endif
110 
111 struct face {
112     struct in_addr *addrs4;
113     struct in6_addr *addrs6;
114     unsigned int naddrs4, naddrs6;
115     time_t expiration;
116     char *canonname, *name;
117     struct face *next;
118 };
119 
120 /* fake addrinfo cache */
121 struct fac {
122     k5_mutex_t lock;
123     struct face *data;
124 };
125 
126 extern struct fac krb5int_fac;
127 
128 extern int krb5int_init_fac (void);
129 extern void krb5int_fini_fac (void);
130