* implementor.texinfo (Thread Shim Layer Implementation): New node.
[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 @c @set EDITION b7-1
21 @set EDITION [working copy]
22
23 @finalout                               @c don't print black warning boxes
24
25 @titlepage
26 @title @value{PRODUCT} Implementor's Guide
27 @subtitle Release:  @value{RELEASE}
28 @subtitle Document Edition:  @value{EDITION}
29 @subtitle Last updated:  @value{UPDATED}
30 @author @value{COMPANY}
31
32 @page
33 @vskip 0pt plus 1filll
34
35 @iftex
36 @include copyright.texinfo
37 @end iftex
38 @end titlepage
39
40 @node Top, Introduction, (dir), (dir)
41 @comment  node-name,  next,  previous,  up
42
43 @ifinfo
44 This file contains internal implementor's information for the
45 @value{RELEASE} release of @value{PRODUCT}.  
46
47 @include copyright.texinfo
48
49 @end ifinfo
50
51 @c The master menu is updated using emacs19's M-x texinfo-all-menus-update
52 @c function.  Don't forget to run M-x texinfo-every-node-update after
53 @c you add a new section or subsection, or after you've rearranged the
54 @c order of sections or subsections.  Also, don't forget to add an @node
55 @c comand before each @section or @subsection!  All you need to enter
56 @c is:
57 @c
58 @c @node New Section Name
59
60 @c @section New Section Name
61 @c
62 @c M-x texinfo-every-node-update will take care of calculating the
63 @c node's forward and back pointers.
64 @c
65 @c ---------------------------------------------------------------------
66
67 @menu
68 * Introduction::                
69 * Compiler and OS Requirements::  
70 * Socket API::                  
71 * IPv6 Support::                
72 * Local Addresses::             
73 * Host Address Lookup::         
74 * Thread Safety::               
75 * Shared Libraries::            
76 * Porting Issues::              
77 @end menu
78
79 @node Introduction, Compiler and OS Requirements, Top, Top
80 @chapter Introduction
81
82 This file contains internal implementor's information for
83 @value{PRODUCT}.  It is currently contains information that was removed
84 from install.texi; eventually it will have more detailed information on
85 the internals of the @value{PRODUCT}.
86
87 @node Compiler and OS Requirements, Socket API, Introduction, Top
88 @chapter Compiler and OS Requirements
89
90 The basic Kerberos libraries are entirely written in C.
91 However, we do assume full ANSI C (1989) support, typical 32- or
92 64-bit twos-complement architectures (@code{char} is 8 bits,
93 @code{short} is 16 bits, @code{int} is 32 bits, byte order is 1234 or
94 4321), and a few aspects of ISO C 1999:
95
96 @itemize @bullet
97 @item
98 support for inline functions, even if the keyword isn't @code{inline}
99 @item
100 64-bit arithmetic types (needed for sequence numbers in GSSAPI)
101 @end itemize
102
103 These are handled through the internal header file
104 @file{k5-platform.h}.
105
106 We also conditionally tailor code for the GNU C compiler in a few
107 places where it helps performance or debugging, but the code should
108 still work fine with other C compilers.
109
110 On UNIX platforms, ... @i{(should outline what POSIX stuff we
111 require)}.
112
113 See also @ref{Advanced Shared Library Requirements}, for UNIX and
114 Windows systems.
115
116 Our makefiles are intended to support building from the top level with
117 a POSIX-compliant version of @code{make}, and parallel builds using
118 GNU @code{make}.  The latter sometimes comes at the cost of efficiency with
119 non-GNU versions; for example, some targets in some directories will
120 always be rebuilt with certain versions of @code{make}, even though
121 the real dependencies are not out of date, because some versions of
122 @code{make} don't understand how we're using phony intermediate
123 targets to manage building in subdirectories in parallel builds.
124 (Actually, this is more my view of how we've been doing things than
125 official policy.  ---Ken)
126
127 @node Socket API, IPv6 Support, Compiler and OS Requirements, Top
128 @chapter Socket API
129
130 Someone should describe the API subset we're allowed to use with
131 sockets, how and when to use @code{SOCKET_ERRNO}, @i{etc}.
132
133 Note that all new code doing hostname and address translation should
134 use @code{getaddrinfo} and friends.  (@xref{Host Address Lookup}.)
135
136 @node IPv6 Support, Local Addresses, Socket API, Top
137 @chapter IPv6 Support
138
139 Most of the IPv6 support is keyed on the macro @code{KRB5_USE_INET6}.
140 If this macro is not defined, there should be no references to
141 @code{AF_INET6}, @code{struct sockaddr_in6}, @i{etc}.
142
143 The @code{configure} scripts will check for the existence of various
144 functions, macros and structure types to decide whether to enable the
145 IPv6 support.  You can also use the @samp{--enable-ipv6} or
146 @samp{--disable-ipv6} options to override this decision.
147
148 Regardless of the setting of @code{KRB5_USE_INET6}, some aspects of
149 the new APIs devised for IPv6 are used throughout the code, because it
150 would be too difficult maintain code for the IPv6 APIs and for the old
151 APIs at the same time.  But for backwards compatibility, we try to
152 fake them if the system libraries don't provide them, at least for
153 now.  This means we sometimes use slightly modified versions of the
154 APIs, but we try to keep the modifications as non-intrusive as
155 possible.  Macros are used to rename struct tags and function names,
156 so don't @code{#undef} any of these names.
157
158 @table @code
159
160 @item getaddrinfo
161 @itemx getnameinfo
162 @itemx freeaddrinfo
163 @itemx gai_strerror
164 @itemx struct addrinfo
165 Always include the header file @file{fake-addrinfo.h} before using
166 these.  If the native system doesn't provide them, the header file
167 will, using support functions that will call @code{gethostbyname} and
168 the like in the native libraries.  (This is similar to how the Winsock
169 2 headers work, depending on some of the predefined macros indicating
170 the target OS version, though they define the support functions
171 directly in the header, as our code used to do.)
172
173 We also provide ``wrapper'' versions on some systems where a native
174 implementation exists but the data it returns is broken in some way.
175
176 So these may not always be thread-safe, and they may not always
177 provide IPv6 support, but the API will be consistent.
178
179 @item struct sockaddr_storage
180 @itemx socklen_t
181 These are provided by @file{socket-utils.h}, if the native headers
182 don't provide them.  @code{sockaddr_storage} contains a
183 @code{sockaddr_in}, so by definition it's big enough to hold one; it
184 also has some extra padding which will probably make it big enough to
185 hold a @code{sockaddr_in6} if the resulting binary should get run on a
186 kernel with IPv6 support.
187
188 Question: Should these simply be moved into @file{port-sockets.h}?
189
190 @end table
191
192 IRIX 6.5.7 has no IPv6 support.  Of the systems most actively in the
193 MIT's Athena environment (used by MIT's Kerberos UNIX developers),
194 this is the only one without built-in IPv6 support.  In another year
195 or so we probably won't be using those systems any more, and we may
196 consider dropping support for systems without IPv6 support.
197
198 Somewhere between IRIX 6.5.14 and 6.5.16, partial IPv6 support was
199 introduced to the extent that the configuration system detects the
200 IPv6 support and attempts to use it.  Code compiles, but then upon
201 linking, one discovers that ``in6addr_any'' is not defined in any
202 system library.  The header file @file{fake-addrinfo.h} provides a
203 static copy as a workaround.  This run time IPv6 code has still not
204 been tested.
205
206 Some utility functions or macros are also provided to give a
207 convenient shorthand for some operations, and to retain compile-time
208 type checking when possible (generally using inline functions but only
209 when compiling with GCC).
210
211 @table @code
212
213 @item socklen(struct sockaddr *)
214 Returns the length of the @code{sockaddr} structure, by looking at the
215 @code{sa_len} field if it exists, or by returning the known sizes of
216 @code{AF_INET} and @code{AF_INET6} address structures.
217
218 @item sa2sin(struct sockaddr *)
219 @itemx sa2sin6(struct sockaddr *)
220 @itemx ss2sa(struct sockaddr_storage *)
221 @itemx ss2sin(struct sockaddr_storage *)
222 @itemx ss2sin6(struct sockaddr_storage *)
223 Pointer type conversions.  Use these instead of plain casts, to get
224 type checking under GCC.
225
226 @end table
227
228 @node Local Addresses, Host Address Lookup, IPv6 Support, Top
229 @chapter Local Addresses
230
231 (Last update: 2005-04-21, but most of the information dates back to
232 early 2002.)
233
234 Different systems have different ways of finding the local network
235 addresses.
236
237 On Windows, @code{gethostbyname} is called on the local host name to get a
238 set of addresses.  If that fails, a UDP socket is ``connected'' to a
239 particular IPv4 address, and the local socket name is retrieved, its
240 address being treated as the one local network address.  Future
241 versions of the Windows code should be able to actually examine local
242 interfaces.
243
244 On (most?) UNIX systems, there is an @code{ioctl} called
245 @code{SIOCGIFCONF} which gets interface configuration information.
246 The behavior of this @code{ioctl} varies across UNIX systems though.
247 It takes as input a buffer to fill with data structures, but if the
248 buffer isn't big enough, the behavior isn't well defined.  Sometimes
249 you get an error, sometimes you get incomplete data.  Sometimes you
250 get a clear indication that more space was needed, sometimes not.  A
251 couple of systems have additional @code{ioctl}s that can be used to
252 determine or at least estimate the correct size for the buffer.  In
253 Solaris, Sun has introduced @code{SIOCGLIFCONF} for querying IPv6
254 addresses, and restricts @code{SIOCGIFCONF} to IPv4 only.  (** We
255 should actually check if that's true.)  They also added
256 @code{SIOCGIFNUM} and @code{SIOCGLIFNUM} for querying the number of
257 interfaces.  HP-UX 11 also has @code{SIOCGLIFCONF}, but it requires a
258 different data structure, and we haven't finished that support yet.
259
260 We (Ken Raeburn in particular) ran some tests on various systems to
261 see what would happen with buffers of various sizes from much smaller
262 to much larger than needed for the actual data.  The buffers were
263 filled with specific byte values, and then checked to see how much of
264 the buffer was actually written to.  The ``largest gap'' values listed
265 below are the largest number of bytes we've seen left unused at the
266 end of the supplied buffer when there were more entries to return.
267 These values may of coures be dependent on the configurations of the
268 particular systems we wre testing with.  (See
269 @file{lib/krb5/os/t_gifconf.c} for the test program.)
270
271 NetBSD 1.5-alpha: The returned @code{ifc_len} is the desired amount of
272 space, always.  The returned list may be truncated if there isn't
273 enough room; no overrun.  Largest gap: 43.  However, NetBSD has
274 @code{getifaddrs}, which hides all the ugliness within the C library.
275
276 BSD/OS 4.0.1 (courtesy djm): The returned @code{ifc_len} is equal to
277 or less than the supplied @code{ifc_len}.  Sometimes the entire buffer
278 is used; sometimes N-1 bytes; occasionally, the buffer must have quite
279 a bit of extra room before the next structure will be added.  Largest
280 gap: 39.
281
282 Solaris 7,8,9: Return @code{EINVAL} if the buffer space is too small
283 for all the data to be returned, including when @code{ifc_len} is 0.
284 Solaris is the only system I've found so far that actually returns an
285 error.  No gap.  However, @code{SIOCGIFNUM} may be used to query the
286 number of interfaces.
287
288 Linux 2.2.12 (Red Hat 6.1 distribution, x86), 2.4.9 (RH 7.1, x86): The
289 buffer is filled in with as many entries as will fit, and the size
290 used is returned in @code{ifc_len}.  The list is truncated if needed,
291 with no indication.  Largest gap: 31.  @emph{However}, this interface
292 does not return any IPv6 addresses.  They must be read from a file
293 under @file{/proc}.  (This appears to be what the @samp{ifconfig}
294 program does.)
295
296 IRIX 6.5.7: The buffer is filled in with as many entries as will fit
297 in N-1 bytes, and the size used is returned in @code{ifc_len}.
298 Providing exactly the desired number of bytes is inadequate; the
299 buffer must be @emph{bigger} than needed.  (E.g., 32->0, 33->32.)  The
300 returned @code{ifc_len} is always less than the supplied one.  Largest
301 gap: 32.
302
303 AIX 4.3.3: Sometimes the returned @code{ifc_len} is bigger than the
304 supplied one, but it may not be big enough for @emph{all} the
305 interfaces.  Sometimes it's smaller than the supplied value, even if
306 the returned list is truncated.  The list is filled in with as many
307 entries as will fit; no overrun.  Largest gap: 143.
308
309 Older AIX: We're told by W. David Shambroom in RT ticket 919 that
310 older versions of AIX have a bug in the @code{SIOCGIFCONF}
311 @code{ioctl} which can cause them to overrun the supplied buffer.
312 However, we don't yet have details as to which version, whether the
313 overrun amount was bounded (e.g., one @code{ifreq}'s worth) or not,
314 whether it's a real buffer overrun or someone assuming it was because
315 @code{ifc_len} was increased, @i{etc}.  Once we've got details, we can
316 try to work around the problem.
317
318 Digital UNIX 4.0F: If input @code{ifc_len} is zero, return an
319 @code{ifc_len} that's big enough to include all entries.  (Actually,
320 on our system, it appears to be larger than that by 32.)  If input
321 @code{ifc_len} is nonzero, fill in as many entries as will fit, and
322 set @code{ifc_len} accordingly.  (Tested only with buffer previously
323 filled with zeros.)
324
325 Tru64 UNIX 5.1A: Like Digital UNIX 4.0F, except the ``extra'' space
326 indicated when the input @code{ifc_len} is zero is larger.  (We got
327 400 out when 320 appeared to be needed.)
328
329 So... if the returned @code{ifc_len} is bigger than the supplied one,
330 we'll need at least that much space -- but possibly more -- to hold
331 all the results.  If the returned value is a little smaller or the
332 same, we may still need more space.
333
334 The heuristic we're using on most systems now is to keep growing the
335 buffer until the unused space is larger than an @code{ifreq} structure
336 by some safe margin.
337
338 @node Host Address Lookup, Thread Safety, Local Addresses, Top
339 @chapter Host Address Lookup
340
341 The traditional @code{gethostbyname} function is not thread-safe, and
342 does not support looking up IPv6 addresses, both of which are becoming
343 more important.  New standards have been in development that should
344 address both of these problems.  The most promising is
345 @code{getaddrinfo} and friends, which is part of the Austin Group and
346 UNIX 98(?) specifications.  Code in the MIT tree has mostly been
347 converted to use this interface.
348
349 @quotation
350 (Question: What about @code{inet_ntop} and @code{inet_pton}?  We're
351 not using them at the moment, but some bits of code would be
352 simplified if we were to do so, when plain addresses and not socket
353 addresses are already presented to us.)
354 @end quotation
355
356 The @code{getaddrinfo} function takes a host name and service name and
357 returns a linked list of structures indicating the address family,
358 length, and actual data in ``sockaddr'' form.  (That is, it includes a
359 pointer to a @code{sockaddr_in} or @code{sockaddr_in6} structure.)
360 Depending on options set via the @code{hints} input argument, the results
361 can be limited to a single address family (@i{e.g.}, for IPv4
362 applications), and the canonical name of the indicated host can be
363 returned.  Either the host or service can be a null pointer, in which
364 case only the other is looked up; they can also be expressed in
365 numeric form.  This interface is extensible to additional address
366 families in the future.  The returned linked list can be freed with
367 the @code{freeaddrinfo} function.
368
369 The @code{getnameinfo} function does the reverse -- given an address
370 in ``sockaddr'' form, it converts the address and port values into
371 printable forms.
372
373 Errors returned by either of these functions -- as return values, not
374 global variables -- can be translated into printable form with the
375 @code{gai_strerror} function.
376
377 Some vendors are starting to implement @code{getaddrinfo} and friends,
378 however, some of the implementations are deficient in one way or
379 another.
380
381 @table @asis
382
383 @item AIX
384 As of AIX 4.3.3, @code{getaddrinfo} returns sockaddr structures
385 without the family and length fields filled in.
386
387 @item GNU libc
388 The GNU C library, used on GNU/Linux systems, has had a few problems
389 in this area.  One version would drop some IPv4 addresses for some
390 hosts that had multiple IPv4 and IPv6 addresses.
391
392 In GNU libc 2.2.4, when the DNS is used, the name referred to by PTR
393 records for each of the addresses is looked up and stored in the
394 @code{ai_canonname} field, or the printed numeric form of the address
395 is, both of which are wrong.
396
397 @item IRIX
398 No known bugs here, but as of IRIX 6.5.7, the version we're using at
399 MIT, these functions had not been implemented.
400
401 @item Mac OS X
402 Two problems have been found with @code{getaddrinfo} on Mac OS X, at
403 least under version 10.3.  First, while @code{gethostbyname} data is
404 cached to make multiple lookups of the same name (@i{e.g.}, by
405 different parts of the code that need to know about the same server
406 host), @code{getaddrinfo} results are not cached, so multiple queries
407 mean multiple DNS requests, which means more delays if the DNS servers
408 are not close by and fast to respond.  We've implemented a cache of
409 our own to work around this, though it only applies to multiple
410 lookups in a short period of time within the same application process,
411 and it's only implemented for the Mac at the moment.
412
413 Second, the Mac libraries will generate a DNS SRV RR query; as far as
414 I [Ken] can tell this is a bug, but Apple seems to consider it a
415 feature.  (Call @code{getaddrinfo("example.com", "telnet", ...)} and
416 you get a SRV record query, but the spec on SRV records says you must
417 not use them unless the specification for the service in question says
418 to.)  Yet more network traffic for each name to look up.
419
420 @item NetBSD
421 As of NetBSD 1.5, this function is not thread-safe.  In 1.5X
422 (intermediate code snapshot between 1.5 and 1.6 releases), the
423 @code{ai_canonname} field can be empty, even if the
424 @code{AI_CANONNAME} flag was passed.  In particular, this can happen
425 if a numeric host address string is provided.  Also, numeric service
426 names appear not to work unless the stream type is given; specifying
427 the TCP protocol is not enough.
428
429 @item Tru64 UNIX
430 In Tru64 UNIX 5.0, @code{getaddrinfo} is available, but requires that
431 @code{<netdb.h>} be included before its use; that header file defines
432 @code{getaddrinfo} as a macro expanding to either @code{ogetaddrinfo}
433 or @code{ngetaddrinfo}, and apparently the symbol @code{getaddrinfo}
434 is not present in the system library, causing the @code{configure}
435 test for it to fail.  Technically speaking, I [Ken] think Compaq has
436 it wrong here, I think the symbol is supposed to be available even if
437 the application uses @code{#undef}, but I have not confirmed it in the
438 spec.
439
440 @item Windows
441 According to Windows documentation, the returned @code{ai_canonname}
442 field can be null even if the @code{AI_CANONNAME} flag is given.
443
444 @end table
445
446 For most systems where @code{getaddrinfo} returns incorrect data,
447 we've provided wrapper versions that call the system version and then
448 try to fix up the returned data.
449
450 For systems that don't provide these functions at all, we've provided
451 replacement versions that neither are thread-safe nor support IPv6,
452 but will allow us to convert the rest of our code to assume the
453 availability of @code{getaddrinfo}, rather than having to use two
454 branches everywhere, one for @code{getaddrinfo} and one for
455 @code{gethostbyname}.  These replacement functions do use
456 @code{gethostbyname} and the like; for some systems it would be
457 possible to use @code{gethostbyname2} or @code{gethostbyname_r} or
458 other such functions, to provide thread safety or IPv6 support, but
459 this has not been a priority for us, since most modern systems have
460 these functions anyways.  And if they don't, they probably don't have
461 real IPv6 support either.
462
463 Including @file{fake-addrinfo.h} will enable the wrapper or
464 replacement versions when needed.  The functions are actually defined
465 in the support library in @file{src/util/support}, added in the 1.4
466 release.
467
468 Do not assume that @code{ai_canonname} will be set when the
469 @code{AI_CANONNAME} flag is set.  Check for a null pointer before
470 using it.
471
472 @node Thread Safety, Shared Libraries, Host Address Lookup, Top
473 @chapter Thread Safety
474
475 Work is still needed as this section is being written.  However, we've
476 made a lot of progress.
477
478 @menu
479 * Kerberos API Thread Safety::  
480 * Thread System Requirements::  
481 * Internal Thread API::         
482 * Thread Shim Layer Implementation::  
483 @end menu
484
485 @node Kerberos API Thread Safety, Thread System Requirements, Thread Safety, Thread Safety
486 @section Kerberos API Thread Safety
487
488 We assume that a @code{krb5_context} or a @code{krb5_auth_context}
489 will be used in only one thread at a time, and any non-opaque object
490 clearly being modified by the application code (@i{e.g.}, a
491 @code{krb5_principal} having a field replaced) is not being used in
492 another thread at the same time.
493
494 A credentials cache, key table, or replay cache object, once the C
495 object is created, may be used in multiple threads simultaneously;
496 internal locking is done by the implementations of those objects.  (We
497 assume that object destructors are invoked only when all other threads
498 are finished with the object.)  @i{(Iterators?  Probably okay now, but
499 needs review.)}  However, this doesn't mean that we've fixed any
500 problems there may be regarding simultaneous access to on-disk files
501 from multiple processes, and in fact if a process opens a disk file
502 multiple times, the same problems may come up.
503
504 Any file locking issues may become worse, actually.  UNIX file locking
505 with @code{flock} is done on a per-process basis, and closing a file
506 descriptor that was opened on a file releases any locks the process
507 may have on that file, even if they were obtained using other,
508 still-open file descriptors.  UNIX file locks are used for credentials
509 caches and keytab files; the replay cache implementation is already
510 known to be unsafe in not using file locking.
511
512 We MAY implement --- but haven't yet --- a ``fix'' whereby open files
513 are tracked by name (and per object type), and a new attempt to open
514 one gets a handle that uses the same open file descriptor, even if it
515 appears as two objects to the application.  This won't address the
516 problem of getting the same file via two names that look different,
517 but it may be ``good enough.''
518
519 GSSAPI ....
520
521 Strictly speaking, the GSSAPI specification says nothing about thread
522 safety, so for best portability, a GSSAPI application probably should
523 not assume that a GSSAPI implementation is thread-safe in any way.  On
524 the other hand, the GSSAPI specification doesn't explicitly say that
525 it's safe to use in a program that uses the Berkeley sockets API,
526 either; at some point, you have to start making some assumptions.
527
528 A GSSAPI security context, like a @code{krb5_context}, may be used
529 only in one thread at a time.  The GSSAPI specification gives precise
530 definitions of C data structures for buffers, object identifiers, OID
531 sets, and channel bindings, that do not allow for the addition of a
532 mutex.  Thus, these objects must not be modified by one thread while
533 in use by another.  (All of the GSSAPI functions that modify these
534 types of objects should be obvious; they're listed as ``modify''
535 parameters in the specification.  In fact, aside from the case of
536 @code{gss_add_oid_set_member}, they're generally output arguments,
537 with the previous value ignored.)
538
539 The function @code{gss_add_cred} can modify the
540 @code{input_cred_handle} object, if a null @code{output_cred_handle}
541 argument is supplied.  Thus, all @code{gss_cred_id_t} objects must
542 have mutexes, and all accesses (except in the functions creating or
543 destroying them) must acquire the mutex first.
544
545 Note that the use of @code{const} in the GSSAPI C bindings is not a
546 useful guide to when an object might or might not be modified.  In
547 most cases, @code{const} is applied to handle arguments, which are
548 defined as arithmetic or pointer types.  It applies to the argument
549 itself, not the data pointed to @i{if} the type is a pointer; this
550 would mean that the GSSAPI function in question cannot modify the
551 value of its handle parameter, and puts no constraints on
552 modifications to the object indicated by the handle.  And according to
553 the C type compatibility rules, the function definition can omit those
554 @code{const} qualifiers anyways.@footnote{If you're thinking that this
555 means the use of @code{const} in the GSSAPI C bindings is confusing
556 and/or useless, you're right.}
557
558
559
560
561 @node Thread System Requirements, Internal Thread API, Kerberos API Thread Safety, Thread Safety
562 @section Thread System Requirements
563
564 We support a few types of environments with regard to thread support:
565
566 @itemize @bullet
567
568 @item
569 Windows native threads.  The objects used by the Windows thread
570 support functions generally need run-time initialization; this is done
571 through the library initialization function.  (@xref{Advanced Shared
572 Library Requirements}.)
573
574 @item
575 POSIX threads, with weak reference support so we can tell whether the
576 thread code was actually linked into the current executable.  If the
577 functions aren't available, we assume the process is single-threaded
578 and ignore locks.  (We do assume that the thread support functions
579 won't show up half-way through execution of the program.)  In order to
580 support single-threaded programs wanting to load Kerberos or GSSAPI
581 modules through a plug-in mechanism, we don't list the pthread library
582 in the dependencies of our shared libraries.
583
584 @item
585 POSIX threads, with the library functions always available, even if
586 they're stub versions that behave normally but don't permit the
587 creation of new threads.
588
589 On AIX 4.3.3, we do not get weak references or useful stub functions,
590 and calling @code{dlopen} apparently causes the pthread library to get
591 loaded, so we've decided to link against the pthread library always.
592
593 On Tru64 UNIX 5.1, we again do not get weak references or useful stub
594 functions.  Rather than look for yet another approach for this one
595 platform, we decided to always link against the pthread library on
596 this platform as well.  This may break single-threaded applications
597 that load the Kerberos libraries after startup.  A clean solution,
598 even if platform-dependent, would be welcome.
599
600 @item
601 Single-threaded.  No locking is performed, any ``thread-local''
602 storage is in fact global, @i{etc}.
603
604 @end itemize
605
606 If @code{pthread_once} is not provided in functional form in the
607 default libraries, and weak references are not supported, we always
608 link against the pthread libraries.  (Tru64, AIX.)
609
610 System routines: @code{getaddrinfo} (not always implemented
611 thread-safe), @code{gethostbyname_r}, @code{gmtime_r},
612 @code{getpwnam_r} (but interfaces vary, see @file{k5-platform.h}),
613 @code{res_nsearch} (but watch for resource leaks).
614
615 Unsafe system routines: @code{setenv}, @code{setlocale}.
616
617 @node Internal Thread API, Thread Shim Layer Implementation, Thread System Requirements, Thread Safety
618 @section Internal Thread API
619
620 Some ideas were discussed on the @samp{krbdev} mailing list, and while
621 the current implementation does largely resemble the scheme Ken
622 Raeburn proposed, some details have changed.
623
624 The following macros in @file{k5-thread.h} implement a locking scheme
625 similar to POSIX threads, with fewer features.
626
627 @deftp {Data type} k5_mutex_t
628 This is the type of a mutex to be used by the Kerberos libraries.  Any
629 object of this type needs initialization.  If the object is
630 dynamically allocated, @code{k5_mutex_init} must be used; if the
631 object is allocated statically, it should be initialized at compile
632 time with @code{K5_MUTEX_PARTIAL_INITIALIZER} and then
633 @code{k5_mutex_finish_init} should be called at run time.  (In
634 general, one of these will do the work, and the other will do nothing
635 interesting, depending on the platform.  When the debugging code is
636 turned on, it will check that both were done.  However, as far as I
637 know, it should work to use just @code{k5_mutex_init} on a mutex in
638 static storage.)
639
640 The mutex may be used only within the current process.  It should not
641 be created in memory shared between processes.  (Will it work in a
642 child process after @code{fork()}?  I think so.)
643
644 The @code{k5_mutex_t} object contains more than an operating-system
645 mutex; it may also contain debugging information such as the file and
646 line number in the Kerberos code where the last mutex operation was
647 performed, information for gathering statistics on mutex usage,
648 @i{etc}., depending on compile-time options.
649
650 This type @emph{is not} a simple typedef for the native OS mutex
651 object, to prevent programmers from accidentally assuming that
652 arbitrary features of the native thread system will always be
653 available.  (If someone wishes to make use of native thread system
654 features in random library code, they'll have to go further out of
655 their way to do it, and such changes probably won't be accepted in the
656 main Kerberos code base at MIT.)
657
658 If thread support is disabled, a simple flag will be stored in place
659 of the operating-system mutex.  This flag indicates the ``locked''
660 state, and is checked in the @code{k5_mutex_lock} and
661 @code{k5_mutex_unlock} macros so that we can detect some cases of
662 improperly written code even if thread support is not built in.  The
663 other debugging fields will still be present as well.
664
665 If POSIX thread support and weak references are available, both the
666 POSIX mutex and a flag will be included; which one is used is
667 determined at run time depending on whether the thread support
668 routines are available.
669 @end deftp
670
671 @defvr Macro K5_MUTEX_PARTIAL_INITIALIZER
672 Value to be used for compile-time initialization of a mutex in static
673 storage.
674 @end defvr
675
676 @deftypefn Macro int k5_mutex_finish_init (k5_mutex_t *@var{m})
677 Finishes run-time initialization, if such is needed, of a mutex that
678 was initialized with @code{K5_MUTEX_PARTIAL_INITIALIZER}.  This macro
679 must be called before the mutex can be locked; usually this is done
680 from library initialization functions.
681 @end deftypefn
682
683 @deftypefn Macro int k5_mutex_init (k5_mutex_t *@var{m})
684 Initializes a mutex.
685 @end deftypefn
686
687 @deftypefn Macro int k5_mutex_destroy (k5_mutex_t *@var{m})
688 Destroys a mutex, whether allocated in static or heap storage.  All
689 mutexes should be destroyed before the containing storage is freed, in
690 case additional system resources have been allocated to manage them.
691 @end deftypefn
692
693 @deftypefn Macro int k5_mutex_lock (k5_mutex_t *@var{m})
694 @deftypefnx Macro int k5_mutex_unlock (k5_mutex_t *@var{m})
695 Lock or unlock a mutex, returning a system error code if an error
696 happened, or zero for success.  (Typically, the return code from
697 @code{k5_mutex_unlock} is ignored.)
698 @end deftypefn
699
700 @deftypefn Macro void k5_mutex_assert_locked (k5_mutex_t *@var{m})
701 @deftypefnx Macro void k5_mutex_assert_unlocked (k5_mutex_t *@var{m})
702 These macros may be used in functions that require that a certain
703 mutex be locked by the current thread, or not, at certain points
704 (typically on entry to the function).  They may generate error
705 messages or debugger traps, or abort the program, if the mutex is not
706 in the expected state.  Or, they may simply do nothing.
707
708 It is not required that the OS mutex interface let the application
709 code determine the state of a mutex; hence these are not specified as
710 a single macro returning the current state, to be checked with
711 @code{assert}.
712 @end deftypefn
713
714 Mutexes should be assumed not to be recursive; if a thread has the
715 mutex locked already, attempting to lock it again is an error and may
716 have unpredictable results (error return, abort, data corruption).
717 There is also no support assumed for ``trylock'' or ``lock with
718 timeout'' operations.
719
720 Kerberos library code should use the macros above, and ports to new
721 thread systems should be done through the @code{k5_os_} layer.
722 (@xref{Thread Shim Layer Implementation}.)
723
724 Thread-local storage is managed through another interface layer:
725
726 @deftp {Enumerator} k5_key_t
727 This is an enumeration type which indicates which of the per-thread
728 data objects is to be referenced.
729 @end deftp
730
731 @deftypefn Macro int k5_key_register (k5_key_t @var{key}, void (*@var{destructor})(void*))
732 Registers a thread-local storage key and a function to destroy a
733 stored object if the thread exits.  This function must be called
734 before @code{k5_setspecific} can be used.  Currently @var{destructor}
735 must not be a null pointer; note, however, that the standard library
736 function @code{free} is of the correct type to be used here if the
737 allocated data doesn't require any special cleanup besides releasing
738 one block of storage.
739 @end deftypefn
740
741 @deftypefn Macro void *k5_getspecific (k5_key_t @var{key})
742 @deftypefnx Macro int k5_setspecific (k5_key_t @var{key}, void *@var{value})
743 As with the POSIX interface, retrieve or store the value for the
744 current thread.  Storing a value may return an error indication.  If
745 an error occurs retrieving a value, @code{NULL} is returned.
746 @end deftypefn
747
748 @deftypefn Macro int k5_key_delete (k5_key_t @var{key})
749 Called to indicate that the key value will no longer be used, for
750 example if the library is in the process of being unloaded.  The
751 destructor function should be called on objects of this type currently
752 allocated in any thread.  (XXX Not implemented yet.)
753 @end deftypefn
754
755 If support functions are needed to implement any of these macros,
756 they'll be in the Kerberos support library, and any exported symbols
757 will use the @code{krb5int_} prefix.  The shorter @code{k5_} prefix is
758 just for convenience, and should not be visible to any application
759 code.
760
761 @node Thread Shim Layer Implementation,  , Internal Thread API, Thread Safety
762 @section Thread Shim Layer Implementation
763
764 Each of the @code{k5_mutex_} macros has a corresponding
765 @code{k5_os_mutex_} macro which incorporates the operating system's
766 mutex object, a flag for non-threaded systems, or both if the use of
767 the OS pthread support is left until run time.  The @code{k5_mutex_}
768 wrappers add debugging information like the file and line number of
769 the last lock or unlock call, where the mutex was created, @i{etc}.
770 There may also be statistical information gathered, such as how long a
771 thread waits for a mutex or how long the mutex is held.  This is all
772 defined in @file{k5-thread.h}.
773
774 The thread-specific storage support is defined as macros expanding to
775 similar function names with the @code{krb5int_} prefix, which
776 functions are defined in @file{util/support/threads.c}.  POSIX,
777 Windows, and non-threaded versions are defined so far.
778
779 The code for collecting and reporting statistics is also mainly in
780 that file.  Macros defined in @file{k5-thread.h} will expand to
781 include calls to these functions, if @code{DEBUG_THREADS_STATS} is
782 defined, or do nothing.
783
784 @node Shared Libraries, Porting Issues, Thread Safety, Top
785 @chapter Shared Libraries
786
787 (These sections are old -- they should get updated.)
788
789 @menu
790 * Shared Library Theory::       
791 * Advanced Shared Library Requirements::  
792 * Operating System Notes for Shared Libraries::  
793 @end menu
794
795 @node Shared Library Theory, Advanced Shared Library Requirements, Shared Libraries, Shared Libraries
796 @section Theory of How Shared Libraries are Used
797
798 An explanation of how shared libraries are implemented on a given
799 platform is too broad a topic for this manual. Instead this will touch
800 on some of the issues that the Kerberos V5 tree uses to support version
801 numbering and alternate install locations.
802
803 Normally when one builds a shared library and then links with it, the
804 name of the shared library is stored in the object
805 (i.e. libfoo.so). Most operating systems allows one to change name that
806 is referenced and we have done so, placing the version number into the
807 shared library (i.e. libfoo.so.0.1). At link time, one would reference
808 libfoo.so, but when one executes the program, the shared library loader
809 would then look for the shared library with the alternate name.  Hence
810 multiple versions of shared libraries may be supported relatively
811 easily. @footnote{Under AIX for the RISC/6000, multiple versions of
812 shared libraries are supported by combining two or more versions of the
813 shared library into one file.  The Kerberos build procedure produces
814 shared libraries with version numbers in the internal module names, so
815 that the shared libraries are compatible with this scheme.
816 Unfortunately, combining two shared libraries requires internal
817 knowledge of the AIX shared library system beyond the scope of this
818 document.  Practically speaking, only one version of AIX shared libraries
819 can be supported on a system, unless the multi-version library is
820 constructed by a programmer familiar with the AIX internals.}
821
822 All operating systems (that we have seen) provide a means for programs
823 to specify the location of shared libraries.  On different operating
824 systems, this is either specified when creating the shared library, and
825 link time, or both.@footnote{Both are necessary sometimes as the shared
826 libraries are dependent on other shared libraries.}  The build process
827 will hardwire a path to the installed destination.
828
829 @node Advanced Shared Library Requirements, Operating System Notes for Shared Libraries, Shared Library Theory, Shared Libraries
830 @section Advanced Shared Library Requirements
831
832 In order to better support some multithreading models, and permit the
833 libraries to clean up internally maintained caches of information,
834 we've imposed new requirements on the OS shared library support.
835
836 Specifically, we want the ability to run certain bits of code in a
837 thread-safe manner at library load time, on multithreading platforms
838 not supporting @code{pthread_once}, and we want the ability to run
839 cleanup code when the library is unloaded.
840
841 In general, where platforms have initialization functions, we don't
842 always get an opportunity to return an error from them.  However, the
843 system functions we call can return errors.  So a framework has been
844 built that attempts to combine the @code{pthread_once} and load-time
845 initialization approaches, and add the ability to store an error code
846 indicating success or failure of the initialization routine.
847
848 The main implementation of this framework is in @file{k5-platform.h}.
849 Some additional information, specifically the names of the
850 initialization and finalization functions, are stored in the makefiles
851 used to generate each of the UNIX libraries, in @file{win_glue.c}, and
852 somewhere in the Mac OS X support (XXX not added yet?).  How the
853 information is used depends on the platform:
854
855 @itemize @bullet
856
857 @item
858 On platforms without any thread support, a simple flag is used, on the
859 assumption that the library code will have sole control over the
860 process execution until the initialization function returns.  (It's
861 generally a bad idea to call any ``interesting'' function like
862 @code{longjmp} or Kerberos functions from signal handlers; now it's a
863 slightly worse idea.)
864
865 @item
866 On platforms supporting @code{pthread_once}, library initialization is
867 generally delayed until the point where the library code needs to
868 verify that the initialization succeeded.  If @code{pthread_once} may
869 not have been linked into the executable and we can tell (for example,
870 with weak symbol references), this is combined with the simple-flag
871 approach above.
872
873 @item
874 On Windows, the library initialization function is run from
875 @file{win_glue.c} at load time; it should complete before the
876 library's symbol table is made accessible to the calling process.
877
878 Windows note: There are limitations on what @code{DllMain} should do
879 in the initialization and finalization cases, and unfortunately we've
880 found that we do some of these things (specifically, calling
881 @code{WSAStartup} and @code{WSACleanup}, and loading other libraries
882 which do so also).  Until we can rectify this problem, there is a
883 chance that explicitly unloading an MIT Kerberos library from an
884 application (more specifically, from within the @code{DllMain} of
885 another library) may cause a deadlock.
886 @end itemize
887
888 Library finalization is similarly dependent on the platform and
889 configuration:
890
891 @itemize @bullet
892
893 @item
894 In static-library builds, since the library will be unloaded only when
895 the entire process calls @code{exit} or @code{exec} or otherwise
896 ceases to exist in its current form, freeing up memory resources in
897 the process, finalization can be skipped.
898
899 @item
900 On UNIX platforms with library finalization support in shared
901 libraries, the (OS-level) finalization function is specified to run
902 the library's (shim-level) finalization function.  If @code{gcc}'s
903 ``destructor'' attribute appears to work, we use that.
904
905 @item
906 On UNIX platforms without library finalization function support,
907 the finalization functions won't get called if the library is
908 unloaded.  Resources (probably just memory) will be leaked.
909
910 @item
911 On Windows, the finalization code is run out of @code{DllMain} in
912 @file{win_glue.c} at unload time.  See the warnings above.
913
914 @end itemize
915
916 If there are other limitations on what operations can be performed in
917 shared library initialization and finalization routines on some
918 systems, the MIT Kerberos team would appreciate specific information
919 on these limitations.
920
921 The internal interface currently used within the code of the Kerberos
922 libraries consists of four macros:
923
924 @defmac MAKE_INIT_FUNCTION (@var{fname})
925 Used at the top level of the file (@i{i.e.}, not within a function),
926 with a semicolon after it, declares @var{fname}, a function taking no
927 arguments and returning @code{int}, to be an initialization function.
928 This macro must be used before the function is declared, and it must
929 be defined in the current file as:
930 @example
931 int @var{fname} (void) @{ ... @}
932 @end example
933 This macro may define additional data and function objects,
934 and will declare @var{fname}, though it may or may not declare
935 @var{fname} as @code{static}.  (Under C rules, the declaration above
936 is compatible with a declaration of the function as @code{static}, and
937 @code{static} linkage does apply, as long as the @code{static} declaration
938 comes first.)
939
940 When the function is invoked, the return value --- zero or an error
941 code --- will be saved away, and returned any time
942 @code{CALL_INIT_FUNCTION} is used.
943
944 There can be multiple initialization functions defined this way in a
945 library.
946 @end defmac
947
948 @defmac MAKE_FINI_FUNCTION (@var{fname})
949 This is similar to @code{MAKE_INIT_FUNCTION} except that @var{fname}
950 is to be a library finalization function, called when the library is
951 no longer in use and is being unloaded from the address space.
952 @example
953 void @var{fname} (void) @{ ... @}
954 @end example
955
956 There may be multiple finalization functions defined for a library.
957 @end defmac
958
959 @deftypefn Macro int CALL_INIT_FUNCTION (@var{fname})
960 This macro ensures that the initialization function @var{fname} is
961 called at this point, if it has not been called already.  The macro
962 returns an error code that indicates success (zero), an error in the
963 OS support (@i{e.g.}, if @code{pthread_once} returns an error), or an
964 error returned by the initialization function.
965
966 Currently, all uses of @code{CALL_INIT_FUNCTION} must be in the same
967 file as the use of @code{MAKE_INIT_FUNCTION}, and must come after it.
968 @end deftypefn
969
970 @deftypefn Macro int INITIALIZER_RAN (@var{fname})
971 This macro returns non-zero iff the initialization function designated
972 by @var{fname} (and previously declared in the current file with
973 @code{MAKE_INIT_FUNCTION}) has been run, and returned no error
974 indication.
975
976 Since the finalization function might always be invoked through linker
977 support and initialization functions only sometimes invoked via
978 @code{pthread_once} in other functions that may not ever be called,
979 finalization functions should check whether the objects to be
980 destroyed have actually been created.  This macro provides one way of
981 doing that.
982 @end deftypefn
983
984 The @file{Makefile.in} for the library must define two variables,
985 @code{LIBINITFUNC} and @code{LIBFINIFUNC}, containing a (possibly
986 empty) list of the names of the initialization and finalization
987 functions for the library as built under UNIX, ordered from
988 lowest-level (initialized first, finalized last) to highest-level.
989 (Windows and Mac OS X builds work differently.)
990
991 Note that all of this assumes shared libraries.  If static linking is
992 done, our options are a bit more limited.  We assume
993 @code{pthread_once} is available if there is any thread support
994 (@i{i.e.}, we don't support static linking on Windows), and we assume
995 that finalization code would be called only when the process is
996 exiting, at which point all resources should be freed up anyways, so
997 it doesn't really matter whether our cleanup code gets called.  In
998 fact, it should be more efficient if it does not.
999
1000 While one of our goals is to be able to repeatedly load, use, and
1001 unload the MIT Kerberos libraries under a plugin architecture without
1002 memory or other resource leaks, the main goal was to provide hooks
1003 through which the library threading support could be properly
1004 initialized on various platforms.  The hooks we've added should be
1005 sufficient for each library to free up any internal caches of
1006 information at unload time, and we have added some of that support,
1007 but it is not complete at this time.
1008
1009
1010 We have also started limiting the list of exported symbols from shared
1011 libraries on some UNIX platforms, and intend to start doing symbol
1012 versioning on platforms that support it.  The symbol lists we use for
1013 UNIX at the moment are fairly all-inclusive, because we need more
1014 symbols exported than are in the lists used for Windows and Mac
1015 platforms, and we have not yet narrowed them down.  The current lists
1016 should not be taken as an indication of what we intend to export and
1017 support in the future; see @file{krb5.h} for that.
1018
1019 The export lists are stored in the directories in which each UNIX
1020 library is built, and the commands set up at configuration time by
1021 @file{shlib.conf} can specify any processing to be done on those files
1022 (@i{e.g.}, insertion of leading underscores or linker command-line
1023 arguments).
1024
1025 For some systems with somewhat non-trivial commands that need to be
1026 run to convert the export list into the proper form, file targets can be
1027 defined in @file{config/lib.in}.  
1028
1029 @node Operating System Notes for Shared Libraries,  , Advanced Shared Library Requirements, Shared Libraries
1030 @section Operating System Notes for Shared Libraries
1031
1032 From time to time users or developers suggest using GNU @code{Libtool}
1033 or some other mechanism to  generate shared libraries.  Experience
1034 with other packages suggests that Libtool tends to be difficult to
1035 debug and when it works incorrectly, patches are required to generated
1036 scripts to work around problems.  So far, the Kerberos shared library
1037 build mechanism, which sets a variety of makefile variables based on
1038 operating system type and then uses those variables in the build
1039 process has proven to be easier to debug and adequate to the task of
1040 building shared libraries for Kerberos.
1041
1042 @menu
1043 * AIX Shared Library Support::  
1044 * Alpha OSF/1 Shared Library Support::  
1045 @end menu
1046
1047 @node AIX Shared Library Support, Alpha OSF/1 Shared Library Support, Operating System Notes for Shared Libraries, Operating System Notes for Shared Libraries
1048 @subsection AIX Shared Library Support
1049
1050         AIX specifies shared library versions by combining multiple
1051 versions into a single file.  Because of the complexity of this process,
1052 no automatic procedure for building multi-versioned shared libraries is
1053 provided. Therefore, supporting multiple versions of the Kerberos shared
1054 libraries under AIX will require significant work on the part of a
1055 programmer famiiliar with AIX internals.  
1056
1057         AIX allows a single library to be used both as a static library
1058 and as a shared library.  For this reason, the @samp{--enable-shared}
1059 switch to configure builds only shared libraries.  On other operating
1060 systems, both shared and static libraries are built when this switch is
1061 specified.  As with all other operating systems, only non-shared static
1062 libraries are built when @samp{--enable-shared} is not specified.
1063
1064         The AIX 3.2.5 linker dumps core trying to build a shared
1065 @samp{libkrb5.a} produced with the GNU C compiler.  The native AIX
1066 compiler works fine.  In addition, the AIX 4.1 linker is able to build a
1067 shared @samp{libkrb5.a} when GNU C is used.
1068
1069
1070 @node Alpha OSF/1 Shared Library Support,  , AIX Shared Library Support, Operating System Notes for Shared Libraries
1071 @subsection Alpha OSF/1 Shared Library Support
1072
1073 Shared library support has been tested with V2.1 and higher of the
1074 operating system. Shared libraries may be compiled both with GCC and the
1075 native compiler.
1076
1077 One of the nice features on this platform is that the paths to the
1078 shared libraries is specified in the library itself without requiring
1079 that one specify the same at link time. 
1080
1081 We are using the @samp{-rpath} option to @samp{ld} to place the library
1082 load path into the executables. The one disadvantage of this is during
1083 testing where we want to make sure that we are using the build tree
1084 instead of a possibly installed library. The loader uses the contents of
1085 @samp{-rpath} before LD_LIBRARY_PATH so we must specify a dummy _RLD_ROOT
1086 and complete LD_LIBRARY_PATH in our tests.
1087
1088 The one disadvantage with the method we are using....
1089
1090 @node Porting Issues,  , Shared Libraries, Top
1091 @chapter Porting Issues
1092
1093 [Snipped from email from Ken Raeburn in reply to email asking about
1094 porting MIT Kerberos to pSOS; maybe it'll be of use to someone else.]
1095
1096 > - Any Porting issues to be considered?
1097
1098 Yes.  Our build procedure currently assumes that the machine used for
1099 building is either a UNIX (or similar) system, or running Windows; it
1100 also assumes that it's a native compilation, not a cross compilation.
1101 I'm not familiar with pSOS, but assuming that you do cross compilation
1102 on another OS, how you deal with that depends on the host system.
1103
1104 UNIX host: The configure script attempts to learn a bunch of
1105 attributes about the host system (program names, availability of
1106 header files and functions and libraries) and uses them to decide how
1107 to build the krb5 libraries and programs.  Many attributes are tested
1108 by running the compiler with various options and test source files, so
1109 if you tell the configure script to run a cross compiler, it may come
1110 up with most of the right answers, if you can arrange for success and
1111 failure indications to be given at compile/link time.  (This probably
1112 wouldn't work well for VxWorks, for example, where symbol resolution
1113 is done when the object code is loaded into the OS.)
1114
1115 The configure script generates include/krb5/autoconf.h to influence
1116 whether certain calls are made or certain headers are included, and
1117 Makefile in each directory to indicate compilation options.  Each
1118 source directory has a Makefile.in, and config/pre.in and
1119 config/post.in are incorporated into each generate Makefile.  Various
1120 @@FOO@@ sequences are substituted based on the system attributes or
1121 configure options.  (Aside from always using the config/ fragments,
1122 this is typical of GNU Autoconf based software configuration.)
1123
1124 Windows host: The "wconfig" program generates the Makefiles in
1125 subdirectories, with config/win-pre.in and config/win-post.in used in
1126 combination with each Makefile.in, and lines starting "##WIN32##" are
1127 uncommented, but @@FOO@@ substitutions are not done.  Instead of
1128 generating autoconf.h, it's copied from include/win-mac.h, where we've
1129 hardcoded some of the parameters we care about, and just left a bunch
1130 of others out.  If you work with a Windows host, you may want to
1131 provide your own makefile fragments, and a replacement for win-mac.h
1132 or some additional data to go into it conditionalized on some
1133 preprocessor symbol for pSOS.
1134
1135 There are also places where we assume that certain header files or
1136 functions are available, because both (most) UNIX and Windows
1137 platforms (that we care about currently) provide them.  And probably a
1138 handful of places where we check for _WIN32 to decide between "the
1139 Windows way" and "everything else" (i.e., UNIX); you might need to add
1140 a third branch for pSOS.  And some places where we've got hooks for
1141 Kerberos for Mac support, which you can probably ignore.
1142
1143 Our build environment assumes that Perl is available, but it's only
1144 needed in the build process, not for run time.  If Tcl is available,
1145 on UNIX, a few more programs may be built that are used for testing
1146 some interfaces, but a cross compiler should notice that it can't link
1147 against the native Tcl libraries, and configure should choose not to
1148 build those programs.
1149
1150 In the current 1.4 beta code, our library wants to find routines for
1151 making DNS queries (SRV and TXT RR queries specifically) that are
1152 outside the scope of getaddrinfo and friends.  We also look for
1153 /dev/random as a strong random number source, and text files for
1154 configuration information.  Our code assumes that allocating and
1155 reallocating lots of little (or not so little) bits of memory isn't
1156 too horribly expensive, and we don't take any special pains to keep
1157 our stack size small.  Depending how pSOS works, you may need to add
1158 to the thread support code.  (The MIT code doesn't create threads, but
1159 will do locking and such to allow multiple threads to share global
1160 data.  The code in include/k5-thread.h is, uh, kind of involved, and
1161 some pains have been taken to use macros whenever possible to allow
1162 assert() calls during debugging to report useful line numbers.)  There
1163 are probably other minor issues to deal with, I'm just making some
1164 guesses.
1165
1166 > - what type of Data formats exchanged between Client and Server?
1167
1168 If you're aiming for a server implementation only, it'll depend on the
1169 exact protocol you wish to use, but typically the Kerberos application
1170 server needs to accept the AP-REQ message and generate the AP-REP
1171 message.  Protection for the data to be transferred depends on on the
1172 application protocol.  For example, Kerberos provides some message
1173 types for encapsulating application data with or without encryption;
1174 the Kerberos mechanism for GSSAPI uses the Kerberos session key to
1175 protect application data in a different message format.
1176
1177 The server implementation would also need some secure means of getting
1178 the service principal's key stored away.
1179
1180 If you want client code support as well under pSOS, then you may have
1181 to deal with DNS queries to find the KDC,
1182 AS-REQ/AS-REP/TGS-REQ/TGS-REP message exchanges, and generating AP-REQ
1183 and accepting AP-REP messages, etc.
1184
1185
1186 @contents
1187 @bye