* implementor.texinfo: Don't use @smallbook.
[krb5.git] / doc / implementor.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c
3 @c Note: the above texinfo file must include the "doubleleftarrow"
4 @c definitions added by jcb.
5 @c %**start of header
6 @c guide
7 @setfilename krb5-implement.info
8 @settitle Kerberos V5 Installation Guide
9 @setchapternewpage odd                  @c chapter begins on next odd page
10 @c @setchapternewpage on                   @c chapter begins on next page
11 @c @smallbook                              @c Format for 7" X 9.25" paper
12 @c %**end of header
13
14 @paragraphindent 0
15 @iftex
16 @parskip 6pt plus 6pt
17 @end iftex
18
19 @include definitions.texinfo
20 @set EDITION b7-1
21
22 @finalout                               @c don't print black warning boxes
23
24 @titlepage
25 @title @value{PRODUCT} Implementor's Guide
26 @subtitle Release:  @value{RELEASE}
27 @subtitle Document Edition:  @value{EDITION}
28 @subtitle Last updated:  @value{UPDATED}
29 @author @value{COMPANY}
30
31 @page
32 @vskip 0pt plus 1filll
33
34 @iftex
35 @include copyright.texinfo
36 @end iftex
37 @end titlepage
38
39 @node Top, Introduction, (dir), (dir)
40 @comment  node-name,  next,  previous,  up
41
42 @ifinfo
43 This file contains internal implementor's information for the
44 @value{RELEASE} release of @value{PRODUCT}.  
45
46 @include copyright.texinfo
47
48 @end ifinfo
49
50 @c The master menu is updated using emacs19's M-x texinfo-all-menus-update
51 @c function.  Don't forget to run M-x texinfo-every-node-update after
52 @c you add a new section or subsection, or after you've rearranged the
53 @c order of sections or subsections.  Also, don't forget to add an @node
54 @c comand before each @section or @subsection!  All you need to enter
55 @c is:
56 @c
57 @c @node New Section Name
58
59 @c @section New Section Name
60 @c
61 @c M-x texinfo-every-node-update will take care of calculating the
62 @c node's forward and back pointers.
63 @c
64 @c ---------------------------------------------------------------------
65
66 @menu
67 * Introduction::                
68 * Socket API::                  
69 * IPv6 Support::                
70 * Local Addresses::             
71 * Host Address Lookup::         
72 * Thread Safety::               
73 * Shared Libraries::            
74 @end menu
75
76 @node Introduction, Socket API, Top, Top
77 @chapter Introduction
78
79 This file contains internal implementor's information for
80 @value{PRODUCT}.  It is currently contains information that was removed
81 from install.texi; eventually it will have more detailed information on
82 the internals of the @value{PRODUCT}.
83
84 @node Socket API, IPv6 Support, Introduction, Top
85 @chapter Socket API
86
87 Someone should describe the API subset we're allowed to use with
88 sockets, how and when to use @code{SOCKET_ERRNO}, @i{etc}.
89
90 @node IPv6 Support, Local Addresses, Socket API, Top
91 @chapter IPv6 Support
92
93 Most of the IPv6 support is keyed on the macro @code{KRB5_USE_INET6}.
94 If this macro is not defined, there should be no references to
95 @code{AF_INET6}, @code{struct sockaddr_in6}, @i{etc}.
96
97 The @code{configure} scripts will check for the existence of various
98 functions, macros and structure types to decide whether to enable the
99 IPv6 support.  You can also use the @samp{--enable-ipv6} or
100 @samp{--disable-ipv6} options to override this decision.
101
102 Regardless of the setting of @code{KRB5_USE_INET6}, some aspects of
103 the new APIs devised for IPv6 are used throughout the code, because it
104 would be too difficult maintain code for the IPv6 APIs and for the old
105 APIs at the same time.  But for backwards compatibility, we try to
106 fake them if the system libraries don't provide them, at least for
107 now.  This means we sometimes use slightly modified versions of the
108 APIs, but we try to keep the modifications as non-intrusive as
109 possible.  Macros are used to rename struct tags and function names,
110 so don't @code{#undef} any of these names.
111
112 @table @code
113
114 @item getaddrinfo
115 @itemx getnameinfo
116 @itemx freeaddrinfo
117 @itemx gai_strerror
118 @itemx struct addrinfo
119 Always include the header file @code{fake-addrinfo.h} before using
120 these.  If the native system doesn't provide them, the header file
121 will, using static functions that will call @code{gethostbyname} and
122 the like in the native libraries.  (This also happens to be the way
123 the Winsock 2 headers work, depending on some of the predefined macros
124 indicating the target OS version.)
125
126 We also provide ``wrapper'' versions on some systems where a native
127 implementation exists but the data it returns is broken in some way.
128
129 So these may not always be thread-safe, and they may not always
130 provide IPv6 support, but the API will be consistent.
131
132 @item struct sockaddr_storage
133 @itemx socklen_t
134 These are provided by @code{socket-utils.h}, if the native headers
135 don't provide them.  @code{sockaddr_storage} contains a
136 @code{sockaddr_in}, so by definition it's big enough to hold one; it
137 also has some extra padding which will probably make it big enough to
138 hold a @code{sockaddr_in6} if the resulting binary should get run on a
139 kernel with IPv6 support.
140
141 Question: Should these simply be moved into @code{port-sockets.h}?
142
143 @end table
144
145 IRIX 6.5.7 has no IPv6 support.  Of the systems most actively in the
146 MIT's Athena environment (used by MIT's Kerberos UNIX developers),
147 this is the only one without built-in IPv6 support.  In another year
148 or so we probably won't be using those systems any more, and we may
149 consider dropping support for systems without IPv6 support.
150
151 Some utility functions or macros are also provided to give a
152 convenient shorthand for some operations, and to retain compile-time
153 type checking when possible (generally using inline functions but only
154 when compiling with GCC).
155
156 @table @code
157
158 @item socklen(struct sockaddr *)
159 Returns the length of the @code{sockaddr} structure, by looking at the
160 @code{sa_len} field if it exists, or by returning the known sizes of
161 @code{AF_INET} and @code{AF_INET6} address structures.
162
163 @item sa2sin(struct sockaddr *)
164 @itemx sa2sin6(struct sockaddr *)
165 @itemx ss2sa(struct sockaddr_storage *)
166 @itemx ss2sin(struct sockaddr_storage *)
167 @itemx ss2sin6(struct sockaddr_storage *)
168 Pointer type conversions.  Use these instead of plain casts, to get
169 type checking under GCC.
170
171 @end table
172
173 @node Local Addresses, Host Address Lookup, IPv6 Support, Top
174 @chapter Local Addresses
175
176 (Last update: 2002-03-13.)
177
178 Different systems have different ways of finding the local network
179 addresses.
180
181 On Windows, @code{gethostbyname} is called on the local host name to get a
182 set of addresses.  If that fails, a UDP socket is ``connected'' to a
183 particular IPv4 address, and the local socket name is retrieved, its
184 address being treated as the one local network address.  Future
185 versions of the Windows code should be able to actually examine local
186 interfaces.
187
188 On Mac OS 9 and earlier, a Mac-specific interface is used to look up
189 local addresses.  Presumably, on Mac OS X we'll use that or the
190 general UNIX code.
191
192 On (most?) UNIX systems, there is an @code{ioctl} called
193 @code{SIOCGIFCONF} which gets interface configuration information.
194 The behavior of this @code{ioctl} varies across UNIX systems though.
195 It takes as input a buffer to fill with data structures, but if the
196 buffer isn't big enough, the behavior isn't well defined.  Sometimes
197 you get an error, sometimes you get incomplete data.  Sometimes you
198 get a clear indication that more space was needed, sometimes not.  A
199 couple of systems have additional @code{ioctl}s that can be used to
200 determine or at least estimate the correct size for the buffer.
201 Solaris has introduced @code{SIOCGLIFCONF} for querying IPv6
202 addresses, and restricts @code{SIOCGIFCONF} to IPv4 only.  (** We
203 should actually check if that's true.)
204
205 We (Ken Raeburn in particular) ran some tests on various systems to
206 see what would happen with buffers of various sizes from much smaller
207 to much larger than needed for the actual data.  The buffers were
208 filled with specific byte values, and then checked to see how much of
209 the buffer was actually written to.  The "largest gap" values listed
210 below are the largest number of bytes we've seen left unused at the
211 end of the supplied buffer when there were more entries to return.
212 These values may of coures be dependent on the configurations of the
213 particular systems we wre testing with.  (See
214 @code{lib/krb5/os/t_gifconf.c} for the test program.)
215
216 NetBSD 1.5-alpha: The returned @code{ifc_len} is the desired amount of
217 space, always.  The returned list may be truncated if there isn't
218 enough room; no overrun.  Largest gap: 43.  However, NetBSD has
219 @code{getifaddrs}, which hides all the ugliness within the C library.
220
221 BSD/OS 4.0.1 (courtesy djm): The returned @code{ifc_len} is equal to
222 or less than the supplied @code{ifc_len}.  Sometimes the entire buffer
223 is used; sometimes N-1 bytes; occasionally, the buffer must have quite
224 a bit of extra room before the next structure will be added.  Largest
225 gap: 39.
226
227 Solaris 7,8: Return @code{EINVAL} if the buffer space is too small for
228 all the data to be returned, including when @code{ifc_len} is 0.
229 Solaris is the only system I've found so far that actually returns an
230 error.  No gap.  However, @code{SIOCGIFNUM} may be used to query the
231 number of interfaces.
232
233 Linux 2.2.12 (Red Hat 6.1 distribution, x86), 2.4.9 (RH 7.1, x86): The
234 buffer is filled in with as many entries as will fit, and the size
235 used is returned in @code{ifc_len}.  The list is truncated if needed,
236 with no indication.  Largest gap: 31.  @emph{However}, this interface
237 does not return any IPv6 addresses.  They must be read from a file
238 under @code{/proc}.  (This appears to be what the @samp{ifconfig}
239 program does.)
240
241 IRIX 6.5.7: The buffer is filled in with as many entries as will fit
242 in N-1 bytes, and the size used is returned in @code{ifc_len}.
243 Providing exactly the desired number of bytes is inadequate; the
244 buffer must be @emph{bigger} than needed.  (E.g., 32->0, 33->32.)  The
245 returned @code{ifc_len} is always less than the supplied one.  Largest
246 gap: 32.
247
248 AIX 4.3.3: Sometimes the returned @code{ifc_len} is bigger than the
249 supplied one, but it may not be big enough for @emph{all} the
250 interfaces.  Sometimes it's smaller than the supplied value, even if
251 the returned list is truncated.  The list is filled in with as many
252 entries as will fit; no overrun.  Largest gap: 143.
253
254 Older AIX: We're told by W. David Shambroom (DShambroom@@gte.com) in
255 PR krb5-kdc/919 that older versions of AIX have a bug in the
256 @code{SIOCGIFCONF} @code{ioctl} which can cause them to overrun the
257 supplied buffer.  However, we don't yet have details as to which
258 version, whether the overrun amount was bounded (e.g., one
259 @code{ifreq}'s worth) or not, whether it's a real buffer overrun or
260 someone assuming it was because @code{ifc_len} was increased, etc.
261 Once we've got details, we can try to work around the problem.
262
263 Digital UNIX 4.0F: If input @code{ifc_len} is zero, return an
264 @code{ifc_len} that's big enough to include all entries.  (Actually,
265 on our system, it appears to be larger than that by 32.)  If input
266 @code{ifc_len} is nonzero, fill in as many entries as will fit, and
267 set @code{ifc_len} accordingly.  (Tested only with buffer previously
268 filled with zeros.)
269
270 Tru64 UNIX 5.1A: Like Digital UNIX 4.0F, except the ``extra'' space
271 indicated when the input @code{ifc_len} is zero is larger.  (We got
272 400 out when 320 appeared to be needed.)
273
274 So... if the returned @code{ifc_len} is bigger than the supplied one,
275 we'll need at least that much space -- but possibly more -- to hold
276 all the results.  If the returned value is smaller or the same, we may
277 still need more space.
278
279 The heuristic we're using on most systems now is to keep growing the
280 buffer until the unused space is larger than an @code{ifreq} structure
281 by some safe margin.
282
283 @node Host Address Lookup, Thread Safety, Local Addresses, Top
284 @chapter Host Address Lookup
285
286 The traditional @code{gethostbyname} function is not thread-safe, and
287 does not support looking up IPv6 addresses, both of which are becoming
288 more important.  New standards have been in development that should
289 address both of these problems.  The most promising is
290 @code{getaddrinfo} and friends, which is part of the Austin Group and
291 UNIX 98(?) specifications.  Code in the MIT tree is gradually being
292 converted to use this interface.
293
294 @quotation
295 (Question: What about @code{inet_ntop} and @code{inet_pton}?  We're
296 not using them at the moment, but some bits of code would be
297 simplified if we were to do so, when plain addresses and not socket
298 addresses are already presented to us.)
299 @end quotation
300
301 The @code{getaddrinfo} function takes a host name and service name and
302 returns a linked list of structures indicating the address family,
303 length, and actual data in ``sockaddr'' form.  (That is, it includes a
304 pointer to a @code{sockaddr_in} or @code{sockaddr_in6} structure.)
305 Depending on options set via the @code{hints} input argument, the results
306 can be limited to a single address family (@i{e.g.}, for IPv4
307 applications), and the canonical name of the indicated host can be
308 returned.  Either the host or service can be a null pointer, in which
309 case only the other is looked up; they can also be expressed in
310 numeric form.  This interface is extensible to additional address
311 families in the future.  The returned linked list can be freed with
312 the @code{freeaddrinfo} function.
313
314 The @code{getnameinfo} function does the reverse -- given an address
315 in ``sockaddr'' form, it converts the address and port values into
316 printable forms.
317
318 Errors returned by either of these functions -- as return values, not
319 global variables -- can be translated into printable form with the
320 @code{gai_strerror} function.
321
322 Some vendors are starting to implement @code{getaddrinfo} and friends,
323 however, some of the implementations are deficient in one way or
324 another.
325
326 @table @asis
327
328 @item AIX
329 As of AIX 4.3.3, @code{getaddrinfo} returns sockaddr structures
330 without the family and length fields filled in.
331
332 @item GNU libc
333 The GNU C library, used on GNU/Linux systems, has had a few problems
334 in this area.  One version would drop some IPv4 addresses for some
335 hosts that had multiple IPv4 and IPv6 addresses.
336
337 In GNU libc 2.2.4, when the DNS is used, the name referred to by PTR
338 records for each of the addresses is looked up and stored in the
339 @code{ai_canonname} field, or the printed numeric form of the address
340 is, both of which are wrong.
341
342 @item IRIX
343 No known bugs here, but as of IRIX 6.5.7, the version we're using at
344 MIT, these functions had not been implemented.
345
346 @item NetBSD
347 As of NetBSD 1.5, this function is not thread-safe.
348
349 @item Tru64 UNIX
350 In Tru64 UNIX 5.0, @code{getaddrinfo} is available, but requires that
351 @code{<netdb.h>} be included before its use; that header file defines
352 @code{getaddrinfo} as a macro expanding to either @code{ogetaddrinfo}
353 or @code{ngetaddrinfo}, and apparently the symbol @code{getaddrinfo}
354 is not present in the system library, causing the @code{configure}
355 test for it to fail.  Technically speaking, I [Ken] think Compaq has
356 it wrong here, I think the symbol is supposed to be available even if
357 the application uses @code{#undef}, but I have not confirmed it in the
358 spec.
359
360 @end table
361
362 For systems where @code{getaddrinfo} returns incorrect data, we've
363 provided wrapper versions that call the system version and then try to
364 fix up the returned data.
365
366 For systems that don't provide these functions at all, we've provided
367 replacement versions that neither are thread-safe nor support IPv6,
368 but will allow us to convert the rest of our code to assume the
369 availability of @code{getaddrinfo}, rather than having to use two
370 branches everywhere, one for @code{getaddrinfo} and one for
371 @code{gethostbyname}.  These replacement functions do use
372 @code{gethostbyname} and the like; for some systems it would be
373 possible to use @code{gethostbyname2} or @code{gethostbyname_r} or
374 other such functions, to provide thread safety or IPv6 support, but
375 this has not been a priority for us, since most modern systems have
376 these functions anyways.  And if they don't, they probably don't have
377 real IPv6 support either.
378
379 Including @code{fake-addrinfo.h} will enable the wrapper or
380 replacement versions when needed.  Depending on the system
381 configuration, this header file may define several static functions
382 (and declare them @code{inline} under GNU C), and leave it to the
383 compiler to discard any unused code.  This may produce warnings on
384 some systems, and if the compiler isn't being too clever, may cause
385 several kilobytes of excess storage to be consumed on these backwards
386 systems.
387
388 @node Thread Safety, Shared Libraries, Host Address Lookup, Top
389 @chapter Thread Safety
390
391 Hahahahahaha...  We're not even close.
392
393 We have started talking about it, though.  Some stuff is ``kind of''
394 thread safe because it operates on a @code{krb5_context} and we simply
395 assert that a context can be used only in one thread at a time.  But
396 there are places where we use unsafe C library functions, and a few
397 places where we have modifiable static data in the libraries.
398
399 Even if the Kerberos or C library functions aren't using static data
400 themselves, there are other instances of per-process data that have to
401 be dealt with before our library can become thread-safe.  For example,
402 file locking with UNIX @code{flock()} is on a per-process basis;
403 for a single thread to be able to lock a file against accesses from
404 other threads, we'll have to implement per-thread locks for files on
405 top of the operating system per-process locks, and that means a global
406 (per-process) table listing all the locks.  So it seems unlikely that
407 we will find an approach that eliminates all static modifiable data
408 from the library.
409
410 A rough proposal for hooks for implementing locking was put forth, and
411 an IBM Linux group is experimenting with a trial implementation of it,
412 with a few changes.  A few issues with the proposal have been
413 discussed on the @samp{krbdev} mailing list, and you can find the
414 discussion in the list archives.
415
416 @node Shared Libraries,  , Thread Safety, Top
417 @chapter Shared Libraries
418
419 (These sections are old -- they should get updated.)
420
421 @menu
422 * Shared Library Theory::       
423 * Operating System Notes for Shared Libraries::  
424 @end menu
425
426 @node Shared Library Theory, Operating System Notes for Shared Libraries, Shared Libraries, Shared Libraries
427 @section Theory of How Shared Libraries are Used
428
429 An explanation of how shared libraries are implemented on a given
430 platform is too broad a topic for this manual. Instead this will touch
431 on some of the issues that the Kerberos V5 tree uses to support version
432 numbering and alternate install locations.
433
434 Normally when one builds a shared library and then links with it, the
435 name of the shared library is stored in the object
436 (i.e. libfoo.so). Most operating systems allows one to change name that
437 is referenced and we have done so, placing the version number into the
438 shared library (i.e. libfoo.so.0.1). At link time, one would reference
439 libfoo.so, but when one executes the program, the shared library loader
440 would then look for the shared library with the alternate name.  Hence
441 multiple versions of shared libraries may be supported relatively
442 easily. @footnote{Under AIX for the RISC/6000, multiple versions of
443 shared libraries are supported by combining two or more versions of the
444 shared library into one file.  The Kerberos build procedure produces
445 shared libraries with version numbers in the internal module names, so
446 that the shared libraries are compatible with this scheme.
447 Unfortunately, combining two shared libraries requires internal
448 knowledge of the AIX shared library system beyond the scope of this
449 document.  Practicallyspeaking, only one version of AIX shared libraries
450 can be supported on a system, unless the multi-version library is
451 constructed by a programmer familiar with the AIX internals.}
452
453 All operating systems (that we have seen) provide a means for programs
454 to specify the location of shared libraries. On different operating
455 systems, this is either specified when creating the shared library, and
456 link time, or both.@footnote{Both are necessary sometimes as the shared
457 libraries are dependent on other shared libraries} The build process
458 will hardwire a path to the installed destination.
459
460 @node Operating System Notes for Shared Libraries,  , Shared Library Theory, Shared Libraries
461 @section Operating System Notes for Shared Libraries
462
463 It would be nice to let some external package like GNU @code{libtool}
464 handle all of this for us, but the last time we tried it,
465 @code{libtool} was too slow, and didn't handle everything we need.
466 So, for now, we deal with it all manually.
467
468 @menu
469 * NetBSD Shared Library Support::  
470 * AIX Shared Library Support::  
471 * Solaris 5.3 Shared Library Support::  
472 * Alpha OSF/1 Shared Library Support::  
473 @end menu
474
475 @node NetBSD Shared Library Support, AIX Shared Library Support, Operating System Notes for Shared Libraries, Operating System Notes for Shared Libraries
476 @subsection NetBSD Shared Library Support
477
478 Shared library support has been tested under NetBSD 1.0A using 
479 GCC 2.4.5. Due to the vagaries of the loader in the operating system,
480 the library load path needs to be specified in building libraries and in
481 linking with them. Unless the library is placed in a standard location
482 to search for libraries, this may make it difficult for developers to
483 work with the shared libraries.
484
485 @node AIX Shared Library Support, Solaris 5.3 Shared Library Support, NetBSD Shared Library Support, Operating System Notes for Shared Libraries
486 @subsection AIX Shared Library Support
487
488         AIX specifies shared library versions by combining multiple
489 versions into a single file.  Because of the complexity of this process,
490 no automatic procedure for building multi-versioned shared libraries is
491 provided. Therefore, supporting multiple versions of the Kerberos shared
492 libraries under AIX will require significant work on the part of a
493 programmer famiiliar with AIX internals.  
494
495         AIX allows a single library to be used both as a static library
496 and as a shared library.  For this reason, the @samp{--enable-shared}
497 switch to configure builds only shared libraries.  On other operating
498 systems, both shared and static libraries are built when this switch is
499 specified.  As with all other operating systems, only non-shared static
500 libraries are built when @samp{--enable-shared} is not specified.
501
502         The AIX 3.2.5 linker dumps core trying to build a shared
503 @samp{libkrb5.a} produced with the GNU C compiler.  The native AIX
504 compiler works fine.  In addition, the AIX 4.1 linker is able to build a
505 shared @samp{libkrb5.a} when GNU C is used.
506
507
508 @node Solaris 5.3 Shared Library Support, Alpha OSF/1 Shared Library Support, AIX Shared Library Support, Operating System Notes for Shared Libraries
509 @subsection Solaris 5.3 Shared Library Support
510
511 Shared library support only works when using the Sunsoft C compiler. We
512 are currently using version 3.0.1. 
513
514 The path to the shared library must be specified at link time as well as
515 when creating libraries. 
516
517 @node Alpha OSF/1 Shared Library Support,  , Solaris 5.3 Shared Library Support, Operating System Notes for Shared Libraries
518 @subsection Alpha OSF/1 Shared Library Support
519
520 Shared library support has been tested with V2.1 and higher of the
521 operating system. Shared libraries may be compiled both with GCC and the
522 native compiler.
523
524 One of the nice features on this platform is that the paths to the
525 shared libraries is specified in the library itself without requiring
526 that one specify the same at link time. 
527
528 We are using the @samp{-rpath} option to @samp{ld} to place the library
529 load path into the executables. The one disadvantage of this is during
530 testing where we want to make sure that we are using the build tree
531 instead of a possibly installed library. The loader uses the contents of
532 @samp{-rpath} before LD_LIBRARY_PATH so we must specify a dummy _RLD_ROOT
533 and complete LD_LIBRARY_PATH in our tests.
534
535 The one disadvantage with the method we are using....
536
537 @contents
538 @bye