source: trunk/third/cns/doc/kerbapi.texi @ 8789

Revision 8789, 88.5 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r8788, which included commits to RCS files with non-trunk default branches.
Line 
1\input texinfo    @c -*-texinfo-*-
2@c @smallbook @c COMMENT THIS OUT w/CYGNUS FORMAT
3@finalout
4@setfilename kerb-API
5@ifinfo
6@emph{Cygnus Network Security Programmer's Guide---Applications
7Interface for Unix and PC's} by Cygnus Support.  CNS includes
8documentation and software developed at the Massachusetts Institute of
9Technology, which includes this copyright information: Copyright
10@copyright{} 1989 by the Massachusetts Institute of Technology
11@quotation
12Export of software employing encryption from the United States of
13America is assumed to require a specific license from the United States
14Government.  It is the responsibility of any person or organization
15contemplating export to obtain such a license before exporting.
16@end quotation
17WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
18this software and its documentation for any purpose and without fee is
19hereby granted, provided that the above copyright notice appear in all
20copies and that both that copyright notice and this permission notice
21appear in supporting documentation, and that the name of M.I.T.  not be
22used in advertising or publicity pertaining to distribution of the
23software without specific, written prior permission.  M.I.T. makes no
24representations about the suitability of this software for any purpose.
25It is provided ``as is'' without express or implied warranty.  Copyright
26@copyright{} 1991, 1992, 1994, 1995 Cygnus Support.  Permission is granted
27to make and distribute verbatim copies of this manual provided the
28copyright notice and this permission notice are preserved on all copies.
29@ignore
30Permission is granted to process this file through TeX and print the
31results, provided the printed document carries a copying permission
32notice identical to this one except for the removal of this paragraph
33(this paragraph not being relevant to the printed manual).
34@end ignore
35Permission is granted to copy and distribute modified versions of this
36manual under the conditions for verbatim copying, provided also that the
37entire resulting derived work is distributed under the terms of a
38permission notice identical to this one.  Permission is granted to copy
39and distribute translations of this manual into another language, under
40the above conditions for modified versions.
41@end ifinfo
42@setchapternewpage odd
43@settitle CNS Programmer's Guide
44@titlepage
45@finalout
46@title Cygnus Network Security
47@subtitle Application Programmer's Interface
48@sp 2
49@subtitle January 1995
50@vfill
51@author John Gilmore -- Cygnus Support
52@page
53@vskip 0pt plus 1filll
54@emph{Cygnus Network Security Programmer's Guide---Applications
55Interface for Unix and PC's} by Cygnus Support.
56
57@emph{Cygnus Editor:  John Gilmore}
58
59CNS includes man pages and software developed at the Massachusetts
60Institute of Technology, which includes this copyright information:
61
62Copyright @copyright{} 1989 by the Massachusetts Institute of Technology
63
64@quotation
65Export of software employing encryption from the United States of
66America is assumed to require a specific license from the United States
67Government.  It is the responsibility of any person or organization
68contemplating export to obtain such a license before exporting.
69@end quotation
70
71WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
72this software and its documentation for any purpose and without fee is
73hereby granted, provided that the above copyright notice appear in all
74copies and that both that copyright notice and this permission notice
75appear in supporting documentation, and that the name of M.I.T.  not be
76used in advertising or publicity pertaining to distribution of the
77software without specific, written prior permission.  M.I.T. makes no
78representations about the suitability of this software for any purpose.
79It is provided ``as is'' without express or implied warranty.
80
81Copyright @copyright{} 1992, 1994, 1995 Cygnus Support.  Permission is
82granted to make and distribute verbatim copies of this manual provided
83the copyright notice and this permission notice are preserved on all
84copies.
85
86Permission is granted to copy and distribute modified versions of this
87manual under the conditions for verbatim copying, provided also that the
88entire resulting derived work is distributed under the terms of a
89permission notice identical to this one.
90
91Permission is granted to copy and distribute translations of this manual
92into another language, under the above conditions for modified versions.
93
94@end titlepage
95
96
97@ifinfo
98@node Top
99@top CNS Programmer's Guide
100@menu
101* Introduction::                A brief introduction to CNS
102
103* Common Kerberos Library API:: Kerberos Library API for portability
104* Unix Library API::            Kerberos Library API for Unix
105* Macintosh Library API::       Kerberos Library API for Macintosh
106* MS-Windows Library API::      Kerberos Library API for MS-Windows
107* Function Index::              Index to functions
108@end menu
109@end ifinfo
110
111@node Introduction
112@chapter Introduction
113
114Cygnus Support developed Cygnus Network Security (CNS) to provide strong
115system access security, with minimal impact on users' ease of access.
116Using Kerberos Version 4 encryption and client-server technology, CNS
117assures that user identities can be checked securely without
118transmitting unencrypted passwords over the Net.
119
120This document describes the application programmer interface for CNS.
121The interface is identical on Unix, the MacOS, and MS-Windows.  Some
122facilities beyond the common subset are available on some of these
123operating systems.  These are documented in separate chapters.
124
125The reader is hereby warned that the U.S. Government may impose
126limits on the export of the software described herein.  Check with
127a good lawyer before exporting the software or making it available
128to non-citizens.
129
130
131@node Common Kerberos Library API
132@chapter CNS Common Kerberos Library API
133
134@menu
135* Kerberos Principals::      How authenticatable things are named
136* krb.h---include file::     How to call Kerberos from your programs
137* Generic Operations::       Overall control and error handling
138* Configuration Suite::      Configuration functions
139* Credential Suite::         Credential functions
140* High-level Suite::         High-Level Kerberos functions
141* Transformation Suite::     Message Transformation functions
142* Encryption Suite::         Encryption functions
143* Stream Suite::             Stream functions   
144@end menu
145
146This section describes the standard application programmer interface to
147Kerberos.  It provides facilities for configuration, shared credentials,
148high-level operations, and transformation routines.  Though most of the
149suites in this section are available on all platforms, there are a few
150that have not yet been ported to particular machines.  This is noted
151where applicable.
152
153@node Kerberos Principals
154@section Kerberos Principals
155
156Kerberos @dfn{principals} are the users and application servers that act
157within Kerberos.  Each principal has a Kerberos principal name.  A
158Kerberos principal name contains three parts: name, instance and realm.
159
160For a user, the principal @dfn{name} is the user name.  For an
161application server, the principal name is the name of the service being
162provided (e.g., the CNS @code{rlogin}, @code{rsh} and @code{rcp}
163programs use the principal name @code{rcmd}).
164
165A principal @dfn{instance} is usually null for users, though some users
166may have privileged instances such as @samp{root} or @samp{admin}.  For
167an application server, the instance is the name of the machine on which
168it runs (e.g., the @code{rlogin} service running on the machine
169@samp{abc} uses the name @samp{rcmd.abc}, while on the machine
170@samp{xyz} it uses @samp{rcmd.xyz}).  The instance name for an
171application server is not the complete domain name, but just the first
172element (that is, the machine @samp{abc.company.org} uses an instance
173name of just @samp{abc}).
174
175A principal @dfn{realm} is simply the Kerberos realm in which the
176principal is defined.
177
178The Kerberos principal name is separated from the instance (if not null)
179by a period.  The realm (if not the local realm) follows the principal
180name and instance and is preceded by an `@@' sign.  The following are
181examples of valid Kerberos names:
182
183@smallexample
184gumby
185ambar.admin
186eichin@@CYGNUS.COM
187raeburn.root@@CYGNUS.COM
188rcmd.oursun@@CYGNUS.COM
189@end smallexample
190
191It is possible for principals to be under-specified.  If an
192@var{instance} is missing, it is assumed to be null.  If @var{realm} is
193missing, it is assumed to be the local realm as determined by
194@ref{krb_realmofhost,,krb_get_lrealm}.  The canonical form is a complete
195@var{name}[.@var{instance}][@@@var{realm}].
196
197Principal names may not contain the `.' or `@@' characters.  Instance
198names may not contain the `@@' character.
199
200@ignore
201@subsubheading SEE ALSO
202@table @ref
203@item kdestroy
204@item kinit
205@item klist
206@item kpasswd
207@item des_crypt
208@item Kerberos
209@item kadmin
210@end table
211@subsubheading BUGS
212@end ignore
213
214@node krb.h---include file
215@section krb.h---include file
216@smallexample
217#include "krb.h"
218@end smallexample
219
220This include file declares data structures and function prototypes for
221all Kerberos operations.  Any program module that uses Kerberos
222facilities should @code{#include} this file.
223
224To provide application portability among Unix, Macintosh, and MS-Windows,
225@file{krb.h} can declare various other system interfaces in addition to
226the minimal Kerberos V4 interface.  These interfaces are controlled by
227@code{#ifdef}s, which must be set in the application source code before
228the @code{#include "krb.h"}.  They are:
229
230@table @code
231@item DEFINE_SOCKADDR
232Defines symbols necessary for network programming using sockets,
233including @code{struct sockaddr_in}.
234@item NEED_TIME_H
235Defines symbols necessary for getting time-of-day from the C library.
236@end table
237
238The network programming interface uses ordinary sockets on Unix, WinSock
2391.1 on MS-Windows, and a fake socket implementation on Macintosh built
240on top of MacTCP.  We defined some of our own infrastructure where
241putting the WinSock coding into a Unix program would not be appropriate.
242They are as follows:
243
244@table @code
245@item SOCKET_INITIALIZE()       
246Must be called before any other socket calls.
247@item SOCKET_CLEANUP()
248Must be called after finishing socket calls.
249@item SOCKET_ERRNO
250Returns the error code from the last socket call.
251@item SOCKET_SET_ERRNO(x)
252Sets the error code to be returned by @code{SOCKET_ERRNO}.
253@item SOCKET_NFDS(f)
254Returns a suitable first argument for @code{select()}, given a file
255descriptor to be selected upon.
256@item SOCKET_READ(fd, b, l)
257Equivalent to Unix @code{read} on a socket.
258@item SOCKET_WRITE(fd, b, l)
259Equivalent to Unix @code{write} on a socket.
260@item SOCKET_EINTR
261The error code returned when an I/O operation was interrupted (equivalent
262to EINTR on Unix).
263@end table
264
265
266@node Generic Operations
267@section Generic Operations
268
269These operations deal with the overall operation of Kerberos,
270or with error handling.
271
272@menu
273* krb_start_session::           Begin Kerberos library operations
274* krb_end_session::             End Kerberos library operations
275* kname_parse::                 Parse Kerberos names
276* krb_get_err_text::            Interpret errors for humans
277@end menu
278
279@node krb_start_session
280@subsection krb_start_session
281@findex krb_start_session
282@code{int
283krb_start_session(char *cache_name);}
284
285Begins a Kerberos session (an interaction with the ticket cache).
286In some implementations, the Kerberos support may destroy the tickets
287obtained by various applications when all the applications exit,
288for improved security on single-user machines.  Applications should
289neither depend on this behavior nor depend on its absence.
290
291If @code{cache_name} is a null pointer, the default shared ticket cache
292is used (the usual case).  If @code{cache_name} is non-null, then a
293named-ticket cache may be used.  If an implementation
294does not implemented named
295caches, then the @code{cache_name} parameter is ignored.
296
297In some environments, krb_start_session also locates and initializes the
298Kerberos driver or library as well as preparing an interaction with the
299ticket cache.
300
301Each application should call @code{krb_start_session} once, and should
302also call @code{krb_end_session} before it ends.
303
304@node krb_end_session
305@subsection krb_end_session
306@findex krb_end_session
307@code{int
308krb_end_session(char *cache_name);}
309
310Ends a Kerberos session (an interaction with the ticket cache).
311In some implementations, the Kerberos support may destroy the tickets
312obtained by various applications when all the applications exit,
313for improved security on single-user machines.  Applications should
314neither depend on this behavior nor depend on its absence.
315
316If @code{cache_name} is a null pointer, the default shared ticket cache
317session is ended (the usual case).  If @code{cache_name} is non-null,
318then a named ticket cache session may be ended.  If a driver does not
319implement named caches, then the @code{cache_name} parameter is
320ignored.
321
322@code{krb_end_session} must be called if and only if the
323application previously called @code{krb_start_session}.
324@code{krb_start_session} and @code{krb_end_session} must be called in
325pairs.
326
327@node kname_parse
328@subsection kname_parse
329@findex kname_parse
330@code{int
331kname_parse (char *name, char *instance, char *realm, char *fullname);}
332
333This routine parses @var{fullname} into the three fields @var{name},
334@var{instance}, and @var{realm}, which should point to memory of sizes
335@code{ANAME_SZ}, @code{INST_SZ}, and @code{REALM_SZ} bytes respectively.
336These fields must be initialized by the caller, since each remains
337unchanged if @var{fullname} does not include that field.  Callers
338typically initialize them to null strings or to the local realm name.
339
340It returns an error code based on the parse.  Only the syntax of the
341name is checked, not its validity in a database or on the network.
342
343
344@node krb_get_err_text
345@subsection krb_get_err_text
346@findex krb_get_err_text
347@code{char *
348krb_get_err_text (int error_code);}
349
350This returns the ASCII text string description
351associated with a Kerberos error code,
352as returned by many Kerberos functions.
353
354
355
356
357@node Configuration Suite
358@section Configuration suite
359
360These routines deal with extracting configuration information stored
361in the system.  This includes the default realm, Key Distribution Center
362(KDC) servers (@file{krb.conf}) and host/realm mappings (@file{krb.realms}).
363
364@menu
365* krb_get_lrealm::
366* krb_realmofhost::
367* krb_get_krbhst::
368* krb_get_admhst::
369* krb_get_default_user::
370* krb_set_default_user::
371
372@end menu
373
374
375@node krb_get_lrealm
376@subsection krb_get_lrealm
377@findex krb_get_lrealm
378@code{int
379krb_get_lrealm(char *realm, int n);}
380
381This operation fills in the name of the default or local realm.
382@var{realm} must be at least @code{REALM_SZ} (40) bytes long.  The value
383of @var{n} must always be `1', for historical reasons.
384
385On Unix machines, this information is currently stored in a file called
386@file{/usr/kerberos/lib/krb.conf}.  In MS-Windows, it is in
387@file{krb.conf}, in the directory @file{\windows\krb.rea}.  On the
388Macintosh, it is stored in the ``Kerberos Client'' Preferences file.
389
390@node krb_realmofhost
391@subsection krb_realmofhost
392@findex krb_realmofhost
393@code{char *
394krb_realmofhost(char *host);}
395
396Returns the Kerberos realm of the host @var{host}.
397@var{host} should be the fully-qualified domain-style primary
398host name of the host in question.
399
400@var{realm} must be at least @code{REALM_SZ} (40) bytes long.
401
402On Unix machines, this information is currently stored in a file called
403@file{/usr/kerberos/lib/krb.realms}.  In MS-Windows, it is stored in a
404file called @file{krb.rea}, whose name is contained in the
405@file{kerberos.ini} file.  In Macintosh, it is stored in the ``Kerberos
406Client'' Preferences file.  In order to prevent certain security
407attacks, this routine must either have @emph{a priori} knowledge of a
408host's realm, or obtain such information securely.
409
410The format of the translation file on Unix is described in the
411@emph{Cygnus Network Security---User and Administrator Documentation for
412CNS Version 1,} manual.  If @var{host} exactly matches a host_name line,
413the corresponding realm is returned.  Otherwise, if the domain portion
414of @var{host} matches a domain_name line, the corresponding realm is
415returned.  If @var{host} contains a domain, but no translation is found,
416@var{host's} domain is converted to upper-case and returned.  If
417@var{host} contains no discernible domain, or an error occurs, the local
418realm name, as supplied by @ref{krb_realmofhost,,krb_get_lrealm}, is
419returned.
420
421@node krb_get_krbhst
422@subsection krb_get_krbhst
423@findex krb_get_krbhst
424@code{int
425krb_get_krbhst(char *host, char *realm, int n);}
426
427@code{krb_get_krbhst} fills in @var{host} with the hostname of the
428@var{n}th host running a Kerberos key distribution center (KDC) for
429realm @var{realm}.  @var{host} must be large enough to hold any hostname.
430(You can get a portable definition of @code{MAXHOSTNAMELEN} by using
431@code{#define DEFINE_SOCKADDR} before including @file{"krb.h"}).
432
433If the host is successfully filled in, the routine returns
434@code{KSUCCESS}.  If the configuration information is unavailable, and
435@var{n} equals `1', then the routine fills in @var{host} with
436@samp{kerberos.@var{realm}} and returns @code{KSUCCESS}.  If there are
437fewer than @var{n} hosts running a Kerberos KDC for the requested realm,
438or the configuration information is malformed, the routine returns
439@code{KFAILURE}.
440
441To locate all key distribution centers, the application
442can re-call with a larger @var{n} as long as the result continues to
443be @code{KSUCCESS}.
444
445On Unix machines, this information is currently stored in an ASCII
446configuration file called @file{/usr/kerberos/lib/krb.conf} and
447described in the @emph{Cygnus Network Security---User and Administrator
448Documentation for CNS Version 1,} manual.  In MS-Windows, it is
449@file{krb.conf}.  The default location for @file{krb.conf} is in
450@file{\windows\krb.rea}.  Macintosh, it is stored in the ``Kerberos
451Client'' Preferences file.
452
453@node krb_get_admhst
454@subsection krb_get_admhst
455@findex krb_get_admhst
456@code{extern int
457krb_get_admhst(char *host, char *realm, int n);}
458
459@code{krb_get_admhst} fills in @var{host} with the hostname of the
460@var{n}th host running a Kerberos KDC database administration server
461for realm @var{realm}.  If the configuration information is unavailable
462or is malformed, or there are fewer than @var{n} hosts running a
463Kerberos KDC database administration server, the routine returns
464@code{KFAILURE}.
465
466@var{host} must be large enough to hold any hostname
467(@code{MAXHOSTNAMELEN} from @file{<sys/param.h>}).
468
469On Unix machines, this information is currently stored in a file called
470@file{/usr/kerberos/lib/krb.conf}.  In MS-Windows, it is
471@file{krb.conf}.  The default location for @file{krb.conf} is in
472@file{\windows\krb.rea}.  Macintosh, it is stored in the ``Kerberos
473Client'' Preferences file.
474
475@node krb_get_default_user
476@subsection krb_get_default_user
477@findex krb_get_default_user
478@code{char *
479krb_get_default_user(void);}
480
481Returns the default @var{user} as configured, if the Kerberos
482implementation has the concept of a default @var{user name}.  The
483result may include a user name, an instance field, and possibly a
484realm name.
485
486On Unix machines, the result is the current logged-in user name.
487In MS-Windows and Macintosh, it is the last name set with
488@code{krb_set_default_user}.
489
490
491@node krb_set_default_user
492@subsection krb_set_default_user
493@findex krb_set_default_user
494@code{int
495krb_set_default_user(char *user);}
496
497Sets the default @var{user} name to be used in future Kerberos
498interactions with the user.  This call can be used by applications to
499override the default @var{user} configured in the Kerberos
500implementation.  On some platforms, this setting persists after
501reboots.
502
503
504@node Credential Suite
505@section Credential suite
506
507These routines give access to credentials which are saved for the
508duration of the user's interaction with their computer.  The storage
509for these credentials is called the @samp{credentials cache}, or in
510older parlance inherited from the first implementation, a @samp{ticket file}.
511
512@menu
513* krb_get_cred::                Get a credential by matching service names.
514* krb_save_credentials::        Save a new credential in the cache
515* krb_get_num_cred::            Count how many credentials there are.
516* krb_get_nth_cred::            Get one credential, by number.
517* krb_get_tf_fullname::         Get the principal name of the current user.
518* dest_tkt::                    Destroy all tickets in the cache.
519@end menu
520
521@node krb_get_cred
522@subsection krb_get_cred
523@findex krb_get_cred
524@code{int krb_get_cred (char *service, char *instance, char *realm,
525struct credentials *credp);}
526
527Retrieves a given credential (specified by the triple of @var{service},
528@var{instance}, and @var{realm}) from the current ticket cache.  The
529resulting credential is stored through the argument pointer @var{credp}.
530
531The result is an error code.
532
533@code{krb_get_cred} searches the caller's ticket cache for a ticket for
534the given service, instance, and realm; and, if a ticket is found,
535fills in the given @code{CREDENTIALS} structure with the ticket
536information.  If the ticket is found, @code{krb_get_cred} returns
537@code{GC_OK}. If the ticket file cannot be found, cannot be read, does not
538belong to the user (other than @samp{root}), is not a regular file, or
539is in the wrong mode, the error @code{GC_TKFIL} is returned.
540
541
542@node krb_save_credentials
543@subsection krb_save_credentials
544@findex krb_save_credentials
545@code{
546int
547krb_save_credentials ((char *service, char *instance, char *realm,
548        C_Block session, int lifetime, int kvno, KTEXT ticket,
549        long issue_date))}
550
551Saves the given credential into the current ticket cache.
552
553@node krb_get_num_cred
554@subsection krb_get_num_cred
555@findex krb_get_num_cred
556@code{int
557krb_get_num_cred(void)}
558
559Returns the number of credentials in the current ticket cache, or `-1'
560if an error occurs.
561
562@node krb_get_nth_cred
563@subsection krb_get_nth_cred
564@findex krb_get_nth_cred
565@code{int
566krb_get_nth_cred(char *name, char *instance, char *realm, int n)}
567
568Retrieves the @var{n}th (where @var{n} starts at zero) credential from
569the current ticket cache and returns its name, instance and realm
570through the supplied @samp{char *}s, which must point to memory areas at
571least @samp{NAME_SZ}, @samp{INST_SZ}, and @samp{REALM_SZ} bytes long.
572The result is a Kerberos error code or KSUCCESS.  The full credential
573may then be obtained by using krb_get_cred.
574
575@node krb_get_tf_fullname
576@subsection krb_get_tf_fullname
577@findex krb_get_tf_fullname
578@code{int
579krb_get_tf_fullname (char *tktfile, char *name, char *instance, char *realm)}
580
581Returns the name, instance, and realm of the principal in the current
582credential cache (also known as a ticket file).  The ticket file name
583is the first parameter.  The default name is used if the argument
584is a null pointer.  Name, instance, and realm must point to areas
585of memory at least
586@samp{NAME_SZ}, @samp{INST_SZ}, and @samp{REALM_SZ} bytes long.
587The result is KSUCCESS or a Kerberos error code.
588
589@node dest_tkt
590@subsection dest_tkt
591@findex dest_tkt
592@code{int
593dest_tkt(void);}
594
595Destroys all the credentials in the current ticket cache.
596The result is KSUCCESS or a Kerberos error code.
597
598
599
600@node High-level Suite
601@section High-level Suite
602
603This library supports network authentication and various related operations.
604The following calls form the high-level Kerberos suite. 
605
606@menu
607* krb_mk_auth::         
608@end menu
609
610@node krb_mk_auth
611@subsection krb_mk_auth
612@findex krb_mk_auth
613
614@code{int krb_mk_auth(long options, KTEXT ticket, char *service, char
615*instance, char *realm, unsigned KRBINT32 checksum, char *version, KTEXT
616buf);}
617
618Generates an authenticator that is equivalent to that used by
619the standard Kerberos V4 @var{krb_sendauth} routine.
620
621Using initial tickets stored in the current ticket cache, it gets a
622ticket (authenticator) for the service @var{service} on the host
623@var{instance}, in the realm @var{realm}.  @var{service} should be the
624single component name for the service (@code{pop}, @code{rcmd}, etc).
625@var{instance} should be the name of the application server host;
626@code{krb_mk_auth} normally canonicalizes it using @code{krb_get_phost}.
627
628The @var{options} available are
629@table @code
630@item KOPT_DONT_CANON
631Don't canonicalize instance as a hostname.  (If this option is not
632chosen, @code{krb_get_phost} is called to canonicalize it.)
633@item KOPT_DONT_MK_REQ
634Don't request server ticket from Kerberos.  A ticket must be supplied in
635the @var{ticket} argument.  (If this option is not chosen, and there is no
636ticket for the given server in the ticket cache, one will be fetched
637using @code{krb_mk_req} and returned in @var{ticket}.)
638@item KOPT_DO_MUTUAL
639Do mutual authentication, requiring that the receiving server return the
640@var{checksum}@code{+1} encrypted in the session key.  The mutual
641authentication is done using @code{krb_mk_priv} on the other side (see
642@file{recvauth.c}) and @code{krb_rd_priv} on this side.
643@end table
644
645@var{checksum} is an application-provided checksum that is cryptographically
646transmitted in the authenticator; if the application needs no checksum
647securely transferred, use zero.  The @var{version} argument allows the
648client program to pass an application-specific version string that the
649server program can then match against its own version string.  The
650resulting byte string, which should be transmitted to the application's
651server, is placed into the buffer @file{buf}.
652
653If doing mutual authentication, the application should then read a
654response from the application server, using application-dependent
655means, and call @code{krb_check_auth} to check its validity.
656
657To make a call that is compatible with the Unix @code{sendauth} and
658@code{recvauth} calls requires some work.  See the source code in
659@file{lib/krb/sendauth.c} for full details.  @code{sendauth}
660compatibility is deprecated because it involves sending binary data
661across an otherwise application-controlled TCP socket.  Instead, the
662application should control the manner in which the authenticator gets
663from the client to the server, using a protocol harmonious with the rest
664of the traffic on that socket.
665
666@node Transformation Suite
667@section Transformation Suite
668
669These routines create authenticated messages which can be
670passed between clients and servers.
671
672The @code{KTEXT} structure is used to pass around text of varying
673lengths.  It consists of a buffer for the data, and a length.
674@code{krb_rd_req} takes an argument of this type containing the
675authenticator, and @code{krb_mk_req} returns the authenticator in a
676structure of this type.  @code{KTEXT} itself is really a pointer to the
677structure.  The actual structure is of type @code{KTEXT_ST}.
678
679The @code{AUTH_DAT} structure is filled in by @code{krb_rd_req}.  It
680must be allocated before calling @code{krb_rd_req}, and a pointer to it
681is passed.  The structure is filled in with data obtained from
682Kerberos. The @code{MSG_DAT} structure is filled in by either
683@code{krb_rd_priv}, @code{krb_rd_safe}, or @code{krb_rd_err}.  It must
684be allocated before the call and a pointer to it is passed. The
685structure is filled in with data obtained from Kerberos.
686
687Note that the caller of @code{krb_rd_req}, @code{krb_rd_priv}, and
688@code{krb_rd_safe} must check time order and for replay attempts.
689
690@menu
691* krb_mk_req::
692* krb_rd_req::
693* krb_mk_priv::
694* krb_rd_priv::
695* krb_mk_safe::
696* krb_rd_safe::
697@end menu
698
699@node krb_mk_req
700@subsection krb_mk_req
701@findex krb_mk_req
702
703@code{int
704krb_mk_req(KTEXT authent, char *service_name,
705char *instance, char *realm, long int xsum);}
706
707Generates an authenticator for the service @var{service_name} on the
708host @var{instance}, in realm @var{realm}.  Using initial tickets stored
709in the default ticket cache, it connects to the Key Distribution Center
710to retrieve a service ticket.  @var{service_name} should be the single
711component name for the service (@code{pop}, @code{discuss}, etc).
712@var{instance} should be the unqualified name of the application server
713host, perhaps as obtained by a call to @code{krb_get_phost}.  @var{xsum}
714is a checksum that is cryptographically transmitted in the
715authenticator.
716
717@code{krb_mk_req} takes a pointer to a text structure in which an
718authenticator is to be built.  It also takes the name, instance, and
719realm of the service to be used and an optional checksum.  It is up to
720the application to decide how to generate the checksum.
721@code{krb_mk_req} then retrieves a ticket for the desired service and
722creates an authenticator.  The authenticator is built in @var{authent}
723and is accessible to the calling procedure.  It is up to the application
724to get the authenticator to the service where it is read by
725@code{krb_rd_req}.  Unless an attacker possesses the session key
726contained in the ticket, it cannot modify the authenticator.  Thus, the
727checksum can be used to verify the authenticity of the other data that
728pass through a connection.
729
730
731@node krb_rd_req
732@subsection krb_rd_req
733@findex krb_rd_req
734
735@code{int krb_rd_req(KTEXT @var{authent},char *@var{service},
736                char *@var{instance}, long @var{from_addr},
737                AUTH_DAT *@var{ad}, char *@var{filename})}
738
739@code{krb_rd_req} takes an authenticator of type @code{KTEXT}, a service
740name, an instance, the address of the host originating the request, and
741a pointer to a structure of type @code{AUTH_DAT} which is filled in with
742information obtained from the authenticator.  Optionally, it also takes
743the name of the file in which it finds the secret key(s) for the
744service.  If the supplied instance contains @samp{*}, then the first
745service key with the same service name found in the service key file is
746used, and the @var{instance} argument is filled in with the chosen
747instance.  This means that the caller must provide space for such an
748instance name.
749
750If the last argument is an empty string, @code{krb_rd_req} uses the file
751@file{/etc/krb-srvtab} to find its keys.  If the last argument is
752@code{NULL}, it assumes that the key in the authenticator has been set
753by @code{krb_set_key} and does not look further.
754
755This routine is used to find out information about the principal when a
756request has been made to a service.  It is up to the application
757protocol to get the authenticator from the client to the service.  The
758routine then passes the authenticator to @code{krb_rd_req} to extract
759the desired information.
760
761@code{krb_rd_req} returns zero (@code{RD_AP_OK}) upon successful
762authentication.  If a packet were forged, modified, or replayed,
763authentication fails.  If authentication fails, a non-zero value is
764returned indicating the particular problem encountered.  See
765@file{krb.h} for the list of error codes.
766
767
768@node krb_mk_priv
769@subsection krb_mk_priv
770@findex krb_mk_priv
771@code{krb_mk_priv(char *in, char *out, unsigned KRB_INT32 in_length,
772Key_schedule schedule, C_Block *key, struct sockaddr_in *sender, struct
773sockaddr_in *receiver);}
774
775long krb_mk_priv(u_char *@var{in}, u_char *@var{out}, u_long
776@var{in_length},
777des_cblock @var{key}, des_key_schedule @var{schedule}; struct
778sockaddr_in *@var{sender},
779                struct sockaddr_in *@var{receiver});
780
781@code{krb_mk_priv} creates an encrypted, authenticated message from any
782arbitrary application data, pointed to by @var{in} and @var{in_length}
783bytes long.  The private session key, pointed to by @var{key} and the
784key schedule, @var{schedule}, are used to encrypt the data and some
785header information using PCBC encryption.  @var{sender} and
786@var{receiver} point to the Internet address of the two parties.  In
787addition to providing privacy, this protocol message protects against
788modifications, insertions or replays.  The encapsulated message and
789header are placed in the area pointed to by @var{out}, which should be
790able to hold @code{in_length + 32} bytes.  The routine returns the
791length of the output, or `-1' indicating an error.
792
793
794@node krb_rd_priv
795@subsection krb_rd_priv
796@findex krb_rd_priv
797@code{int krb_rd_priv(char *in, unsigned KRB_INT32 in_length, char
798*schedule, char *key, struct sockaddr *sender, struct sockaddr
799*receiver, MSG_DAT *msg_data);}
800
801long krb_rd_priv(u_char *@var{in}, u_long @var{in_length},
802Key_schedule @var{schedule}, des_cblock @var{key}, struct
803sockaddr_in *@var{sender},
804                struct sockaddr_in *@var{receiver},
805                MSG_DAT *@var{msg_data});
806
807This routine is used to decrypt and authenticate a message created by
808@code{krb_mk_priv}.  @var{in} points to the beginning of the received
809message, the length of which is specified in @var{in_length}.  The
810private session key, pointed to by @var{key}, is used to decrypt and
811verify the received message.  If @var{schedule} is non-null,
812@var{schedule} points to the calculated key schedule for the key.  The
813routine fills in fields in the @var{msg_data} structure with information
814retrieved from the message.
815
816@code{krb_rd_priv} decrypts and authenticates a received
817@code{krb_mk_priv} message.  The private session key, pointed to by
818@var{key}, and the key schedule, @var{schedule}, are used to decrypt and
819verify the received message.  @var{msg_data} is a pointer to a
820@code{MSG_DAT} struct.  The routine fills in the @code{app_data} field
821with a pointer to the decrypted application data, @code{app_length} with
822the length of the @code{app_data} field, @code{time_sec} and
823@code{time_5ms} with the timestamps in the message, and @code{swap} with
824a `1' if the byte order of the receiver is different than that of the
825sender.  (The application must still determine if it is appropriate to
826byte-swap application data; the Kerberos protocol fields are already
827taken care of).  The routine returns zero if okay, or a Kerberos error
828code.  Modified messages and old messages cause errors, but the caller
829must check the time sequence of messages.
830
831
832@node krb_mk_safe
833@subsection krb_mk_safe
834@findex krb_mk_safe
835@code{krb_mk_safe(unsigned char *in, unsigned char *out,
836unsigned KRB_INT32 in_length, C_Block *key, struct sockaddr_in *sender,
837struct sockaddr_in *receiver);}
838
839long krb_mk_safe(u_char *@var{in}, u_char *@var{out}, u_long
840@var{in_length},
841                des_cblock @var{key},
842                struct sockaddr_in *@var{sender},
843                struct sockaddr_in *@var{receiver});
844
845This routine makes an authenticated, but unencrypted message from any
846arbitrary application data, pointed to by @var{in} and @var{in_length}
847bytes long.  The private session key, pointed to by @var{key}, is used
848to seed the @var{quad_cksum} checksum algorithm used as part of the
849authentication. @var{sender} and @var{receiver} point to the Internet
850addresses of the two parties.  The encapsulated message and header are
851placed in the area pointed to by @var{out}.  This area should be to hold
852@var{in_length + 32} bytes.  The routine returns the length of the
853output, or `-1' indicating an error.
854
855This message does
856not provide privacy, but does protect (via detection) against
857modifications, insertions or replays.  The
858authentication provided by this routine is not as strong as that
859provided by @code{krb_mk_priv} or by computing the checksum using
860@code{cbc_cksum} instead, both of which authenticate via DES.
861
862
863@node krb_rd_safe
864@subsection krb_rd_safe
865@findex krb_rd_safe
866@code{long krb_rd_safe(u_char *@var{in}, u_long @var{in_length},
867                des_cblock @var{key},
868                struct sockaddr_in *@var{sender},
869                struct sockaddr_in *@var{receiver},
870                MSG_DAT *@var{msg_data})}
871
872This routine is used to authenticate a message created by
873@code{krb_mk_safe}.  @var{in} points to the beginning of the received
874message, whose length is specified in @var{in_length}.  The private
875session key, pointed to by @var{key}, is used to verify the
876authentication checksum of the received message.
877
878@var{msg_data} is a pointer to a @code{MSG_DAT} struct, defined in
879@file{krb.h}. The routine fills in these @code{MSG_DAT} fields: the
880@code{app_data} field with a pointer to the application data,
881@code{app_length} with the length of the @code{app_data} field,
882@code{time_sec} and @code{time_5ms} with the timestamps in the message,
883and @code{swap} with a `1' if the byte order of the receiver is
884different than that of the sender.  (The application must still
885determine if it is appropriate to byteswap application data; the
886Kerberos protocol fields are already taken care of).
887
888The routine returns zero if okay, or a Kerberos error code.  Modified
889messages and old messages cause errors, but the caller must check the
890time sequence of messages.
891
892
893@node Encryption Suite
894@section Encryption suite
895
896The Kerberos library supports various DES encryption related
897operations.  It differs from the @code{crypt}, @code{setkey}, and
898@code{encrypt} library routines in that it provides a true DES
899encryption, without modifying the algorithm, and executes much faster.
900
901For each key that may be simultaneously active, create a
902@code{des_key_schedule} struct.  Next, create key schedules (from the
9038-byte keys) as needed, via @code{des_key_sched}, prior to using the
904encryption or checksum routines.  Then set up the input and output areas
905(lengths are restricted to be multiples of eight bytes).  Finally,
906invoke the encryption/decryption routine, @code{des_cbc_encrypt} or
907@code{des_pcbc_encrypt}.
908
909A @code{des_cblock} struct is an 8-byte block used as the fundamental
910unit for DES data and keys, and is defined as:
911@smallexample
912typedef unsigned char des_cblock[8];
913@end smallexample
914@noindent
915and a @code{des_key_schedule} is defined as:
916@smallexample
917typedef struct des_ks_struct
918        @{des_cblock _;@}
919des_key_schedule[16];
920@end smallexample
921
922@menu
923* des_key_sched::
924* des_cbc_encrypt::
925* des_string_to_key::
926@end menu
927
928@node des_key_sched
929@subsection des_key_sched
930@findex des_key_sched
931@code{des_key_sched(des_cblock *key, des_key_schedule *schedule);}
932
933This routine calculates a key schedule from the input @var{key},
934and outputs the schedule into @var{schedule}.  The key schedule may then be
935used in subsequent encryption/decryption operations.
936The user must overwrite or clear all keys and
937schedules as soon as no longer needed, to discourage their disclosure
938in memory dumps.
939
940@node des_cbc_encrypt
941@subsection des_cbc_encrypt
942@findex des_cbc_encrypt
943
944@code{int des_cbc_encrypt(des_cblock *@var{input},des_cblock
945*@var{output}, long @var{length}, des_key_schedule @var{schedule},
946des_cblock *@var{ivec}, int @var{encrypt})}
947
948This routine encrypts or decrypts data using @code{DES CBC} mode.  The
949data pointed to by @var{data}, of length @var{data_len}, are encrypted
950with the pre-calculated key schedule @var{schedule} and initialization
951vector @var{ivec}, and placed in @var{data_out}.  If @var{encrypt_flag}
952is zero, then decryption is performed.  If @var{encrypt_flag} is
953`1', then encryption is performed.
954
955This routine encrypts or decrypts a block of data using the
956cipher-block-chaining (CBC) mode of DES.
957
958If the @var{encrypt} argument is non-zero, the routine CBC-encrypts the
959cleartext data pointed to by the @var{input} argument.  This is done
960into the ciphertext pointed to by the @var{output} argument, using the
961key schedule provided by the @var{schedule} argument, and initialization
962vector provided by the @var{ivec} argument. If the @var{length} argument
963is not an integral multiple of eight bytes, the last block is zero
964filled (highest addresses).  The output is always an integral multiple
965of eight bytes.
966
967If @var{encrypt} is zero, the routine CBC decrypts the ciphertext data
968pointed to by the @var{input} argument.  The result is put into
969cleartext pointed to by the @var{output} argument.  This is done using
970the key schedule provided by the @var{schedule} argument, and
971initialization vector provided by the @var{ivec} argument.  Decryption
972always operates on integral multiples of 8 bytes, so it rounds the
973length provided up to the appropriate multiple.  Consequently, it always
974produces the rounded-up number of bytes of output cleartext. The
975application must determine if the output cleartext was zero-padded due
976to original cleartext lengths that were not integral multiples of 8.
977
978No errors or meaningful values are returned.  @code{void} is not used
979for compatibility with older compilers.
980
981A characteristic of CBC mode is that changing even a single bit of the
982cleartext affects all the subsequent ciphertext.  This makes
983cryptanalysis much more difficult.  However, modifying a single bit of
984the ciphertext, then decrypting, only affects the resulting cleartext
985from the modified block and the succeeding block.  The
986@code{des_pcbc_encrypt} routine was designed to detect modifications.
987However, because of problems, CBC mode in no longer recommended.
988
989@node des_string_to_key
990@subsection des_string_to_key
991@findex des_string_to_key
992@code{int des_string_to_key (char *string, char *key);}
993
994This routine converts an arbitrary length null-terminated @var{string}
995to an 8-byte DES key @var{key}, with odd byte parity.  A one-way
996function is used to convert the string to a key, making it very
997difficult to reconstruct the string from the key.  No meaningful value
998is returned. @code{void} is not used for compatibility with older
999compilers.
1000
1001@c If options is @var{krb_afs_flag}, then a Transarc string to key
1002@c algorithm is used, and @var{realm} should be the realm name to be used
1003@c in the transformation.
1004
1005@node Stream Suite
1006@section Stream functions
1007
1008@menu
1009* Kstream Overview::            Overview
1010* Kstream implementation::      sample stream implementation
1011@end menu
1012
1013@node Kstream Overview
1014@subsection Kstream Overview
1015
1016The @code{kstream} suite provides similar functions to the Standard I/O
1017Library (@file{stdio}).  It permits you to create encrypted and
1018plaintext (unencrypted) I/O streams.  You can create a @code{kstream},
1019read from it or write to it, and destroy it.  You also have some control
1020of buffering.  At this time, the @code{kstream} suite is not available
1021for the Mac.
1022
1023The encryption system used (if any) is determined at the time of
1024creation.  There are several create routines provided.
1025@table @samp
1026@findex kstream_create_rlogin_from_fd
1027@item kstream_create_rlogin_from_fd
1028creates a @code{kstream} using the same encryption mechanism that the
1029CNS @code{rlogin} program uses on a file descriptor
1030passed as an argument
1031@findex kstream_create_rcp_from_fd
1032@item kstream_create_rcp_from_fd
1033is the same as the @code{rlogin} version except that @code{rcp} pads
1034short blocks in a different way than @code{rlogin}.
1035@findex kstream_create_from_fd
1036@item kstream_create_from_fd
1037is a generic creation routine which takes a
1038@samp{kstream_crypt_ctl_block} which is simply a vector of pointers to
1039functions for encryption, decryption, initialization, and cleanup.
1040
1041@end table
1042
1043After creating a @code{kstream}, you simply call @code{kstream_read} or
1044@code{kstream_write} just as you would normally call @code{read} or
1045@code{write}.  @code{kstream_flush} explicitly flushes any buffered data
1046out to the underlying file descriptor.  @code{kstream_set_buffer_mode}
1047is used to turn buffering on or off; it defaults to on, but interactive
1048applications such as @code{rlogin} explicitly turn it off.
1049
1050@example
1051kstream kstream_create_from_fd (int fd,
1052                                const struct kstream_crypt_ctl_block *ctl,
1053                                kstream_ptr data);
1054
1055 kstream_create_rlogin_from_fd (int fd, void* sched,
1056                                       unsigned char (*ivec)[8]);
1057kstream kstream_create_rcp_from_fd (int fd, void* sched,
1058                                    unsigned char (*ivec)[8]);
1059
1060int kstream_write (kstream, void*, size_t);
1061int kstream_read (kstream, void*, size_t);
1062int kstream_flush (kstream);
1063int kstream_destroy (kstream);
1064void kstream_set_buffer_mode (kstream, int);
1065@end example
1066
1067@node Kstream implementation
1068@subsection Sample implementation of a stream encryption package
1069
1070First, a brief description of the stream protocols in use.
1071
1072The data stream consists of four bytes representing a net-order (MSB
1073first) integer, followed by enough data to produce that many cleartext
1074bytes.  This means the size of those data must be rounded up to a
1075multiple of 8.  For blocks of less than eight bytes, most software pads
1076on the @var{left} with random values.
1077
1078
1079There are some internal routines whose behavior should be considered
1080carefully.  Start from the top, in the @code{kstream_crypt_ctl_block}
1081entries.
1082
1083@table @code
1084@item init
1085simply takes a @code{kstream} and @code{kstream_des_init_block} (which
1086is just a key and an 8 byte initialization vector) and stuffs them into
1087the private data of the @code{kstream}. The buffers and lengths are
1088initialized to zero, and @code{no_right_justify} is cleared.
1089@item rcp_init
1090is the same as @code{init} except @code{no_right_justify} is set, since
1091@code{rcp} and @code{rlogin} use subtly different protocols.
1092@item encrypt
1093gets a pair of @code{kstream_data_block}s (just a pointer and length)
1094for output and input. Since we can always encrypt and send the
1095data we have, this routine just comes up with padding and then calls
1096@code{do_encrypt} to put the data into the outgoing stream.  It returns
1097the number of successfully encrypted bytes (in this case, all of them.)
1098@item decrypt
1099also gets a pair of @code{kstream_data_block}s. Here, we do not
1100necessarily have enough data to decrypt the block.  We need at least
1101four bytes even to read the length (and if we do not get that, we ask
1102for at least 12 total just so we have a chance).  If we are doing an
1103@code{rlogin}, we also filter out extra characters that can slip in
1104before the length.
1105@item destroy
1106frees the output buffer, wipes the private data and then frees that
1107memory also.
1108@item do_encrypt
1109is not in the vector.  It does the actual encryption work.  This routine
1110handles blocks of any size up to 16 bytes, or any multiple of 8 over
1111that.  It makes the padding a little easier to write it this way.
1112Handling sizes between 8 and 16 is an annoyance, but @code{rlogin}
1113actually relies on being able to send 12 bytes in one block.
1114@end table
1115
1116@node Unix Library API
1117@chapter CNS Unix Applications Programming Interface
1118
1119On Unix systems, the full set of Common API functions are available.
1120In addition, the following Unix-specific (or server-specific)
1121functions are also available.
1122
1123These application programming interfaces are only available on
1124Unix.  They are typically used to write servers, or have not yet
1125been ported to other platforms.
1126
1127@menu
1128* Access Control Lists::       
1129* Error Reporting::             
1130* Encryption::                 
1131* Authentication::             
1132* Realms::                     
1133* Ticket Files::               
1134* Other::                       
1135@end menu
1136
1137@node Access Control Lists
1138@section Access Control Lists
1139@menu
1140* ACL overview::               
1141* acl_canonicalize_principal:: 
1142* acl_check::
1143* acl_exact_match::             
1144* acl_add::                     
1145* acl_delete::                 
1146* acl_initialize::             
1147* ACL concurrency note::       
1148@end menu
1149@node ACL overview
1150@subsection ACL overview
1151@smallexample
1152cc @var{files} -lacl -lkrb
1153#include "krb.h"
1154acl_canonicalize_principal(char *@var{principal}, char *@file{buf})
1155acl_check(char *@var{acl}, char *@var{principal})
1156acl_exact_match(char *@var{acl}, char *@var{principal})
1157acl_add(char *@var{acl}, char *@var{principal})
1158acl_delete(char *@var{acl}, char *@var{principal})
1159acl_initialize(char *@var{acl_file}, int @var{mode})
1160@end smallexample
1161@c @subsubheading DESCRIPTION
1162An access control list (ACL) is a list of principals.  Each principal is
1163represented by a text string which cannot contain whitespace.  The
1164library allows application programs to refer to named access control
1165lists to test membership and to atomically add and delete principals
1166using a natural and intuitive interface.  At present, the names of
1167access control lists are required to be Unix filenames, and refer to
1168human-readable Unix files. @c ; in the future, when a
1169@c networked ACL server is implemented, the names may refer to a different
1170@c namespace specific to the ACL service.
1171
1172@node acl_canonicalize_principal
1173@subsection acl_canonicalize_principal
1174@findex acl_canonicalize_principal
1175@code{acl_canonicalize_principal}
1176stores the canonical form of principal in @file{buf}.  @file{buf} must
1177contain enough space to store a principal, given the limits on the sizes
1178of @var{name}, @var{instance}, and @var{realm} specified as
1179@code{ANAME_SZ}, @code{INST_SZ}, and @code{REALM_SZ}, respectively, in
1180@file{/usr/kerberos/include/krb.h}.
1181
1182@node acl_check
1183@subsection acl_check
1184@findex acl_check
1185@code{acl_check} returns nonzero if @var{principal} appears in the ACL.
1186Returns zero if @var{principal} does not appear in ACL, or if an error
1187occurs.  Canonicalizes @var{principal} before checking, and allows the
1188ACL to contain wildcards.  The only supported wildcards are entries of
1189the form @samp{@var{name}.*@@@var{realm}}, @samp{*.*@@@var{realm}}, and
1190@samp{*.*@@*}.  An asterisk matches any value in the component field.
1191For example, @samp{jtkohl.*@@*} would match principal @samp{jtkohl},
1192with any @var{instance} and any @var{realm}.
1193
1194@node acl_exact_match
1195@subsection acl_exact_match
1196@findex acl_exact_match
1197@code{acl_exact_match}
1198performs like @code{acl_check}, but does no canonicalization or wildcard
1199matching.
1200
1201@node acl_add
1202@subsection acl_add
1203@findex acl_add
1204@code{acl_add} atomically adds @var{principal} to the ACL.  Returns zero
1205if successful, nonzero if unsuccessful.  It is considered a failure if
1206@var{principal} is already in the ACL.  This routine canonicalizes
1207@var{principal}, but treats wildcards literally.
1208
1209@node acl_delete
1210@subsection acl_delete
1211@findex acl_delete
1212@code{acl_delete} atomically deletes @var{principal} from the ACL.
1213Returns zero if successful, nonzero if unsuccessful.  It is considered a
1214failure if @var{principal} is not already in the ACL.  This routine
1215canonicalizes @var{principal}, but treats wildcards literally.
1216
1217@node acl_initialize
1218@subsection acl_initialize
1219@findex acl_initialize
1220@code{acl_initialize}
1221initializes @var{acl_file}.  If the file @var{acl_file} does not exist,
1222@code{acl_initialize} creates it with mode mode.  If the file
1223@var{acl_file} exists, @code{acl_initialize} removes all
1224members. Returns zero if successful, nonzero unsuccessful.
1225@strong{WARNING:} @var{mode} argument is likely to change with the
1226eventual introduction of an ACL service.
1227
1228@node ACL concurrency note
1229@subsection ACL concurrency note
1230@c @subsubheading NOTES
1231If there is concurrency (two or more people using these functions),
1232there is a very small chance of @code{acl_add} or @code{acl_delete}
1233erroneously reporting an error.  This is an unavoidable side effect when
1234using lock files for concurrency control rather than @code{flock}(2),
1235which is not supported by NFS.  The current implementation caches ACLs
1236in memory in a hash table for increased efficiency in checking
1237membership; one effect of the caching scheme is that one file descriptor
1238is kept open for each ACL cached, up to a maximum of 8.
1239@ignore
1240@subsubheading SEE ALSO
1241@table @ref
1242@item Kerberos
1243@item krb_realmofhost,,krb_get_lrealm
1244@end table
1245@end ignore
1246@node Error Reporting
1247@section Error Reporting
1248@menu
1249* com_err::             com_err
1250* compile_et::          compile_et
1251@end menu
1252@node com_err
1253@subsection com_err
1254@findex com_err
1255@c @subsubheading SYNOPSIS
1256@smallexample
1257#include <com_err.h>
1258void com_err (const char @var{whoami}, long @var{code},
1259        const char *@var{format}, @dots{});
1260@var{proc} = set_com_err_hook (@var{proc});
1261void (* @var{proc} ) (const char *, long, const char *,
1262        va_list);
1263@var{proc} = reset_com_err_hook ();
1264void initialize_@var{XXXX}_error_table ();
1265@end smallexample
1266@c @subsubheading DESCRIPTION
1267@code{com_err} displays an error message on the standard error stream
1268@code{stderr} (see @samp{stdio}(3S)) composed of the @var{whoami}
1269string, which should specify the program name or some sub-portion of a
1270program, followed by an error message generated from the code value
1271(derived from @ref{compile_et}), and a string produced using the string
1272and any following arguments, in the same style as @samp{fprintf}(3).
1273The behavior of @code{com_err} can be modified using
1274@code{set_com_err_hook}; this defines a procedure which is called with
1275the arguments passed to @code{com_err}, instead of the default internal
1276procedure which sends the formatted text to error output.  Thus the
1277error messages from a program can all easily be diverted to another form
1278of diagnostic logging, such as @samp{syslog}(3).
1279@code{reset_com_err_hook} may be used to restore the behavior of
1280@code{com_err} to its default form.  Both procedures return the previous
1281hook value.  These hook procedures must have the declaration given for
1282@var{proc} above.  The @code{initialize_@var{XXXX}_error_table} routine
1283is generated mechanically by @code{compile_et} (see @ref{compile_et})
1284from a source file containing names and associated strings.  Each table
1285has a name of up to four characters, which is used in place of the
1286@var{XXXX} in the name of the routine. These routines should be called
1287before any of the corresponding error codes are used, so that the
1288@file{com_err} library recognizes error codes from these tables when
1289they are used.  The @file{com_err.h} header file should be included in
1290any source file that uses routines from the @file{com_err} library;
1291executable files must be linked using @code{-lcom_err} in order to cause
1292the @file{com_err} library to be included.
1293@ignore
1294@subsubheading SEE ALSO
1295@c @xref{compile_et}, @samp{syslog}(3).
1296Ken Raeburn, "A Common Error Description Library for UNIX".
1297@end ignore
1298@node compile_et
1299@subsection compile_et
1300@ignore
1301@c @subsubheading SYNOPSIS
1302@smallexample
1303compile_et @var{file}
1304@end smallexample
1305@c @subsubheading DESCRIPTION
1306@end ignore
1307@code{compile_et} converts a table listing error-code names and
1308associated messages into a C source file suitable for use with the
1309@file{com_err} library (see @ref{com_err}).  The source file name must
1310end with a suffix of @file{.et}; the file consists of a declaration
1311supplying the name (up to four characters long) of the error-code table:
1312@smallexample
1313error_table @var{name}
1314@end smallexample
1315@noindent
1316followed by up to 256 entries of the form:
1317@smallexample
1318error_code @var{name}, "@var{string}"
1319@end smallexample
1320@noindent
1321and a final
1322@smallexample
1323end
1324@end smallexample
1325@noindent
1326to indicate the end of the table.  The name of the table is used to
1327construct the name of a subroutine
1328@code{initialize_@var{XXXX}_error_table} which must be called in order
1329for the @file{com_err} library to recognize the error table.  The
1330various error codes defined are assigned sequentially increasing numbers
1331(starting with a large number computed as a hash function of the name of
1332the table); thus for compatibility it is suggested that new codes be
1333added only to the end of an existing table, and that no codes be removed
1334from tables.  The names defined in the table are placed into a C header
1335file with preprocessor directives defining them as integer constants of
1336up to 32 bits in magnitude.  A C source file is also generated which
1337should be compiled and linked with the object files which reference
1338these error codes; it contains the text of the messages and the
1339initialization subroutine.  Both C files have names derived from that of
1340the original source file, with the @file{.et} suffix replaced by
1341@file{.c} and @file{.h}.  A @samp{#} in the source file is treated as a
1342comment character, and all remaining text to the end of the source line
1343is ignored.
1344@ignore
1345@subsubheading BUGS
1346Since @code{compile_et} uses a very simple parser based on
1347@code{yacc}(1), its error recovery leaves much to be desired.
1348@subsubheading SEE ALSO
1349@xref{com_err}.
1350Ken Raeburn, "A Common Error Description Library for UNIX".
1351@end ignore
1352
1353@node Encryption
1354@section Encryption
1355@menu
1356* Encryption overview::         
1357* des_read_password::           
1358* des_random_key::             
1359* des_set_key::                 
1360* des_ecb_encrypt::             
1361* des_pcbc_encrypt::           
1362* des_cbc_cksum::               
1363* quad_cksum::                 
1364* des_init_random_number_generator::
1365* des_new_random_key::
1366@end menu
1367
1368@node Encryption overview
1369@subsection Encryption overview
1370This library supports various DES encryption related operations.  It
1371differs from the Unix @code{crypt}, @code{setkey}, and @code{encrypt}
1372library routines in that it provides a true DES encryption, without
1373modifying the algorithm, and executes much faster.  To use, create a
1374@code{des_key_schedule} struct, defined in @file{des.h} for each key
1375that may be simultaneously active.  Next, create key schedules (from the
13768-byte keys) as needed, via @code{des_set_key}, prior to using the
1377encryption or checksum routines. Then setup the input and output areas
1378(note that lengths are restricted to be multiples of eight
1379bytes). Finally, invoke the encryption/decryption routines,
1380@code{des_ecb_encrypt} or @code{des_cbc_encrypt} or
1381@code{des_pcbc_encrypt}, or, to generate a cryptographic checksum, use
1382@code{quad_cksum} (fast) or @code{des_cbc_cksum} (slow).
1383@smallexample
1384#include "des.h"
1385int des_read_password(des_cblock *@var{key}, char *@var{prompt}, int
1386        @var{verify})
1387int des_string_to_key(char *@var{str}, des_cblock @var{key})
1388int des_random_key(des_cblock *@var{key})
1389int des_set_key(des_cblock *@var{key}, des_key_schedule @var{schedule})
1390int des_ecb_encrypt(des_cblock *@var{input},des_cblock *@var{output},
1391        des_key_schedule @var{schedule},int @var{encrypt})
1392int des_pcbc_encrypt(des_cblock *@var{input},des_cblock *@var{output}, long
1393        @var{length}, des_key_schedule @var{schedule},
1394        des_cblock *@var{ivec}, int @var{encrypt})
1395unsigned long quad_cksum(des_cblock *@var{input},des_cblock *@var{output},
1396        long @var{length}, int @var{out_count},
1397        des_cblock *@var{seed})
1398@end smallexample
1399
1400@node des_read_password
1401@subsection des_read_password
1402@findex des_read_password
1403@code{des_read_password} writes the string specified by @var{prompt} to
1404the standard output, turns off echo (if possible) and reads an input
1405string from standard input until terminated with a newline.  If
1406@var{verify} is non-zero, it prompts and reads input again, for use in
1407applications such as changing a password; both versions are compared,
1408and the input is requested repeatedly until they match.  Then
1409@code{des_read_password} converts the input string into a valid DES key,
1410internally using the @code{des_string_to_key} routine.  The newly
1411created key is copied to the area pointed to by the @var{key} argument.
1412@code{des_read_password} returns a zero if no errors occurred, or a `-1'
1413indicating that an error occurred trying to manipulate the terminal
1414echo.
1415
1416@node des_random_key
1417@subsection des_random_key
1418@findex des_random_key
1419@code{des_random_key} generates a random DES encryption key (eight
1420bytes), set to odd parity per FIPS specifications.  This routine uses
1421the current time, process ID, and a counter as a seed for the random
1422number generator.  The caller must supply space for the output key,
1423pointed to by argument @var{key}, then after calling
1424@code{des_random_key} should call the @code{des_set_key} routine when
1425needed.  No meaningful value is returned.  @code{void} is not used for
1426historical reasons.
1427
1428This function is deprecated. @code{des_init_random_number_generator}
1429should be used to set a key for the @code{des_new_random_key} generator,
1430which is much stronger due to the use of DES and the use of a secret
1431key. (Programs that operate directly on the database can use the master
1432key; for client programs like @samp{ksrvutil} it may be sufficient to
1433use a current session key.)
1434
1435@node des_set_key
1436@subsection des_set_key
1437@findex des_set_key
1438@code{des_set_key} calculates a key schedule from all eight bytes of the
1439input key, pointed to by the @var{key} argument, and outputs the
1440schedule into the @code{des_key_schedule} indicated by the
1441@var{schedule} argument. You must pass a valid eight byte key; no
1442padding is done.  The key schedule may then be used in subsequent
1443encryption/decryption/checksum operations.  Many key schedules may be
1444cached for later use.  The user must clear keys and schedules as soon as
1445no longer needed, to prevent their disclosure.  The routine also checks
1446the key parity, and returns a zero if the key parity is correct (odd), a
1447`-1' indicating a key parity error, or a `-2' indicating use of a weak
1448key. If an error is returned, the key schedule was not created.
1449
1450@node des_ecb_encrypt
1451@subsection des_ecb_encrypt
1452@findex des_ecb_encrypt
1453@code{des_ecb_encrypt} is the basic DES encryption routine that
1454encrypts or decrypts a single 8-byte block in electronic code book
1455mode.  It always transforms the input data, pointed to by @var{input},
1456into the output data, pointed to by the @var{output} argument.  If the
1457@var{encrypt} argument is non-zero, the input (cleartext) is encrypted
1458into the output (ciphertext) using the @code{key_schedule} specified by
1459the @var{schedule} argument, previously set via @code{des_set_key}.  If
1460@var{encrypt} is zero, the input (now ciphertext) is decrypted into the
1461output (now cleartext).  Input and output may overlap.  No meaningful
1462value is returned.  @code{void} is not used for historical reasons.
1463
1464@node des_pcbc_encrypt
1465@subsection des_pcbc_encrypt
1466@findex des_pcbc_encrypt
1467@code{des_pcbc_encrypt} encrypts/decrypts using a modified block
1468chaining mode.  Its calling sequence is identical to
1469@code{des_cbc_encrypt}. It differs in its error propagation
1470characteristics.  @code{des_pcbc_encrypt} is not recommended for most
1471encryption purposes.  Modification of a single bit of the ciphertext
1472affects all the subsequent (decrypted) cleartext.  Similarly, modifying
1473a single bit of the cleartext affects all the subsequent (encrypted)
1474ciphertext.  `PCBC' mode, on encryption, `XORs' both the cleartext of
1475block @var{N} and the ciphertext resulting from block @var{N} with the
1476cleartext for block @var{N}+1 prior to encrypting block @var{N}+1.
1477However, this mode has been shown to have inherent weaknesses.
1478
1479@node des_cbc_cksum
1480@subsection des_cbc_cksum
1481@findex des_cbc_cksum
1482@code{des_cbc_cksum} produces an 8-byte cryptographic checksum by
1483cipher-block-chain encrypting the cleartext data pointed to by the
1484@var{input} argument. All of the ciphertext output is discarded, except
1485the last 8-byte ciphertext block, which is written into the area pointed
1486to by the @var{output} argument.  It uses the key schedule, provided by
1487the @var{schedule} argument and initialization vector provided by the
1488@var{ivec} argument.  If the @var{length} argument is not an integral
1489multiple of eight bytes, the last cleartext block is copied to a temp
1490and zero filled at the highest addresses.  The output is ALWAYS eight
1491bytes.  The routine also returns an @code{unsigned long}, which is the
1492last (highest address) half of the 8 byte checksum computed.  This
1493result is probably byte-order dependent.
1494
1495@node quad_cksum
1496@subsection quad_cksum
1497@findex quad_cksum
1498@code{quad_cksum} produces a checksum by chaining quadratic operations
1499on the cleartext data pointed to by the @var{input} argument. The
1500@var{length} argument specifies the length of the input---only exactly
1501that many bytes are included for the checksum, without any padding.  The
1502algorithm may be iterated over the same input data, if the
1503@var{out_count} argument is `2', `3' or `4', and the optional
1504@var{output} argument is a non-null pointer.  The default is one
1505iteration, and it does not run more than four times.  Multiple
1506iterations run more slowly, but provide a longer checksum, if desired.
1507The @var{seed} argument provides an 8-byte seed for the first
1508iteration. If multiple iterations are requested, the results of one
1509iteration are automatically used as the seed for the next iteration.  It
1510returns both an @code{unsigned long} checksum value, and if the
1511@var{output} argument is not a null pointer, up to 16 bytes of the
1512computed checksum are written into the output.
1513
1514@node des_init_random_number_generator
1515@subsection des_init_random_number_generator
1516@findex des_init_random_number_generator
1517@code{des_init_random_number_generator} sets the key for the new random
1518number generator. It also sets the initial sequence number from a
1519microsecond clock, the host id, and process id if available.
1520
1521@node des_new_random_key
1522@subsection des_new_random_key
1523@findex des_new_random_key
1524@code{des_new_random_key} encrypts the sequence number with the
1525previously selected key and advances the sequence number. This produces
1526a key with strong unpredictablity (due to the use of DES and a secret
1527key.) This function will only generate valid non-weak keys.
1528
1529@node Authentication
1530@section Authentication
1531@menu
1532* Authentication overview::     
1533* krb_kntoln::                 
1534* krb_set_key::                 
1535* krb_mk_err::                 
1536* krb_rd_err::                 
1537* krb_sendauth::               
1538* krb_recvauth::               
1539* krb_net_write and krb_net_read:: 
1540@end menu
1541@node Authentication overview
1542@subsection Authentication overview
1543@smallexample
1544#include "krb.h"
1545int krb_kntoln(AUTH_DAT *@var{ad}, char *@var{lname});
1546int krb_set_key(char *@var{key}, int @var{cvt});
1547int krb_get_cred(char *@var{service}, char *@var{instance}, char
1548*@var{realm}, CREDENTIALS *@var{c});
1549long krb_mk_err(u_char *@var{out}, long @var{code}, char *@var{string});
1550long krb_rd_err(u_char *@var{in}, u_long @var{length},
1551                long @var{code}, MSG_DAT *@var{msg_data});
1552@end smallexample
1553
1554The following functions, which are built on top of the core Kerberos
1555library, provide a convenient means for client and server programs to
1556send authentication messages to one another through network connections.
1557
1558@smallexample
1559#define DEFINE_SOCKADDR
1560#include "krb.h"
1561int krb_sendauth(long @var{options}, int @var{fd}, KTEXT @var{ktext}, char
1562*@var{service}, char *@var{inst}, char *@var{realm}, u_long @var{checksum},
1563MSG_DAT *msg_@var{data},
1564        CREDENTIALS *@var{cred},
1565        Key_schedule @var{schedule},
1566        struct sockaddr_in *@var{laddr},
1567        struct sockaddr_in *@var{faddr},
1568        char *@var{version});
1569int krb_recvauth(long @var{options}, int @var{fd}, KTEXT @var{ktext}, char
1570*@var{service}, char *@var{inst},
1571        struct sockaddr_in *@var{laddr},
1572        struct sockaddr_in *@var{faddr},
1573        AUTH_DAT *@var{auth_data},
1574        char *@var{filename},
1575        Key_schedule @var{schedule},
1576        char *@var{version});
1577int krb_net_write(int @var{fd}, char *@file{buf}, int @var{format});
1578int krb_net_read(int @var{fd}, char *@file{buf}, int @var{format});
1579@end smallexample
1580
1581@node krb_kntoln
1582@subsection krb_kntoln
1583@findex krb_kntoln
1584@code{krb_kntoln} converts a Kerberos name (supplied in an
1585@code{AUTH_DAT} structure) to a local Unix username.  If the instance is
1586the null string and the realm is the local realm, then the name is
1587copied to the @var{lname} argument.  If the realm is not the local realm
1588or the instance is non-null, or some error occurs, @code{KFAILURE} is
1589returned, otherwise @code{KSUCCESS} is returned.  The local name
1590returned might be used by an application to change user IDs,
1591directories, or other parameters.  This function is not an integral part
1592of Kerberos, but is instead provided to support the use of Kerberos in
1593existing utilities.
1594
1595@node krb_set_key
1596@subsection krb_set_key
1597@findex krb_set_key
1598@code{krb_set_key} takes as an argument a DES key.  It then creates a
1599key schedule from it and saves the original key to be used as an
1600initialization vector.  It is used to set the server's key which must be
1601used to decrypt tickets.  If called with a non-zero second argument,
1602@code{krb_set_key} first converts the input from a string of arbitrary
1603length to a DES key by encrypting it with a one-way function.  In most
1604cases it should not be necessary to call @code{krb_set_key}. The
1605necessary keys are usually obtained and set inside
1606@code{krb_rd_req}. @code{krb_set_key} is provided for those applications
1607that do not wish to place the application keys on disk.
1608
1609@node krb_mk_err
1610@subsection krb_mk_err
1611@findex krb_mk_err
1612@code{krb_mk_err} constructs an application level error message that
1613may be used along with @code{krb_mk_priv} or @code{krb_mk_safe}.
1614@var{out} is a pointer to the output buffer, @var{code} is an
1615application specific error code, and @var{string} is an application
1616specific error string.
1617
1618@node krb_rd_err
1619@subsection krb_rd_err
1620@findex krb_rd_err
1621@code{krb_rd_err} unpacks a received @code{krb_mk_err} message.
1622@var{in} points to the beginning of the received message, whose length
1623is specified in @var{in_length}.  @var{code} is a pointer to a value to
1624be filled in with the error value provided by the application.
1625@var{msg_data} is a pointer to a @code{MSG_DAT} struct, defined in
1626@file{krb.h}. The routine fills in these @code{MSG_DAT} fields: the
1627@code{app_data} field with a pointer to the application error text,
1628@code{app_length} with the length of the @code{app_data} field, and
1629@code{swap} with a `1' if the byte order of the receiver is different
1630than that of the sender.  (The application must still determine if it is
1631appropriate to byte-swap application data; the Kerberos protocol fields
1632are already taken care of).  The routine returns zero if the error
1633message has been successfully received, or a Kerberos error code.
1634
1635@node krb_sendauth
1636
1637@subsection krb_sendauth
1638@findex krb_sendauth
1639
1640The @code{krb_sendauth} function sends an authenticated ticket from the
1641client program to the server program by writing the ticket to a network
1642socket.  The @code{krb_recvauth} function receives the ticket from the
1643client by reading from a network socket.
1644
1645@code{krb_sendauth}
1646writes the ticket to the network socket specified by the file
1647descriptor @var{fd}, returning @code{KSUCCESS} if the write proceeds
1648successfully, and an error code if it does not.  The @var{ktext}
1649argument should point to an allocated @code{KTEXT_ST} structure.  The
1650@var{service}, @var{inst}, and @var{realm} arguments specify the server
1651program's Kerberos principal name, instance, and realm.  If you are
1652writing a client that uses the local realm exclusively, you can set the
1653@var{realm} argument to NULL.  The @var{version} argument allows the
1654client program to pass an application-specific version string that the
1655server program can then match against its own version string.  The
1656version string can be up to @code{KSEND_VNO_LEN} (see @file{krb.h})
1657characters in length.  The @var{checksum} argument can be used to pass
1658checksum information to the server program. The client program is
1659responsible for specifying this information. This checksum information
1660is difficult to corrupt because @code{krb_sendauth} passes it over the
1661network in encrypted form.  The checksum argument is passed as the
1662checksum argument to @code{krb_mk_req}.  You can set
1663@code{krb_sendauth}'s other arguments to NULL unless you want the
1664client and server programs to mutually authenticate themselves. In the
1665case of mutual authentication, the client authenticates itself to the
1666server program, and demands that the server in turn authenticate itself
1667to the client.
1668
1669If you want mutual authentication, make sure that you read all pending
1670data from the local socket before calling @code{krb_sendauth}.  Set
1671@code{krb_sendauth}'s options argument to @code{KOPT_DO_MUTUAL} (this
1672macro is defined in the @file{krb.h} file); make sure that the
1673@var{laddr} argument points to the address of the local socket, and that
1674@var{faddr} points to the foreign socket's network address.
1675@code{krb_sendauth} fills in the other arguments---@var{msg_data},
1676@var{cred}, and @var{schedule}---before sending the ticket to the server
1677program. You must, however, allocate space for these arguments before
1678calling the function.  @code{krb_sendauth} supports two other options:
1679@code{KOPT_DONT_MK_REQ}, and @code{KOPT_DONT_CANON}.  If called with
1680options set as @code{KOPT_DONT_MK_REQ}, @code{krb_sendauth} does not use
1681the @code{krb_mk_req} function to retrieve the ticket from the Kerberos
1682server.  The @var{ktext} argument must point to an existing ticket and
1683authenticator (such as would be created by @code{krb_mk_req}), and the
1684@var{service}, @var{inst}, and @var{realm} arguments can be set to NULL.
1685
1686@code{krb_sendauth} does not convert the service's instance to canonical
1687form using @ref{krb_realmofhost,,krb_get_phost}, if called with options
1688set as @code{KOPT_DONT_CANON}.  If you want to call @code{krb_sendauth}
1689with a multiple options specification, construct options as a bitwise-OR
1690of the options you want to specify.
1691
1692Note that @code{krb_sendauth}, @code{krb_recvauth},
1693@code{krb_net_write}, and @code{krb_net_read} do not work properly on
1694sockets set to non-blocking I/O mode.
1695
1696@node krb_recvauth
1697@subsection krb_recvauth
1698@findex krb_recvauth
1699The @code{krb_recvauth} function reads a
1700ticket/authenticator pair from the socket pointed to by the @var{fd}
1701argument.  Set the @var{options} argument as a bitwise-OR of the options
1702desired.  Currently only @code{KOPT_DO_MUTUAL} is useful to the
1703receiver.
1704
1705The @code{ktext} argument should point to an allocated @code{KTEXT_ST}
1706structure.  @code{krb_recvauth} fills @code{ktext} with the
1707ticket/authenticator pair read from @var{fd}, then passes it to
1708@code{krb_rd_req}.  The @var{service} and @var{inst} arguments specify
1709the expected service and instance for which the ticket was generated.
1710They are also passed to @code{krb_rd_req}. The @var{inst} argument may
1711be set to @samp{*} if the caller wishes @code{krb_mk_req} to fill in the
1712instance used (note that there must be space in the @var{inst} argument
1713to hold a full instance name, see @xref{krb_mk_req}.)  The
1714@var{faddr} argument should point to the address of the peer which is
1715presenting the ticket.  It is also passed to @code{krb_rd_req}.  If the
1716client and server plan to mutually authenticate one another, the
1717@var{laddr} argument should point to the local address of the file
1718descriptor.  Otherwise you can set this argument to NULL.
1719
1720The @var{auth_data} argument should point to an allocated
1721@code{AUTH_DAT} area. It is passed to and filled in by
1722@code{krb_rd_req}.  The checksum passed to the corresponding
1723@code{krb_sendauth} is available as part of the filled-in
1724@code{AUTH_DAT} area.  The @var{filename} argument specifies the
1725filename which the service program should use to obtain its service key.
1726@code{krb_recvauth} passes filename to the @code{krb_rd_req} function.
1727If you set this argument to null, @code{krb_rd_req} looks for the
1728service key in the file @file{/etc/krb-srvtab}.  If the client and
1729server are performing mutual authentication, the schedule argument should
1730point to an allocated @code{Key_schedule}.  Otherwise it is ignored and
1731may be NULL.  The @var{version} argument should point to a character
1732array of at least @code{KSEND_VNO_LEN} characters. It is filled in with
1733the version string passed by the client to @code{krb_sendauth}.
1734
1735Note that @code{krb_sendauth}, @code{krb_recvauth},
1736@code{krb_net_write}, and @code{krb_net_read} do not work properly on
1737sockets set to non-blocking I/O mode.
1738
1739@c
1740@c krb_rd_auth was never implmented, since it was used only by servers,
1741@c and all servers were done on Unix where sockets are file descriptors.
1742@c For completeness it should be done, but we ran out of time.
1743@c
1744@c @item krb_rd_auth
1745@c @smallexample
1746@c csCode= krbReadSendauthCode (2025)
1747@c transform.data      = data      [input]
1748@c transform.data_len  = data_len  [input]
1749@c transform.principal = service   [input]
1750@c transform.instance  = instance  [input]
1751@c transform.from_addr = from_addr [input]
1752@c transform.key       = service_key [input]
1753@c transform.auth_data = auth_data [output by ref]
1754@c transform.version   = version   [output by ref]
1755@c @end smallexample
1756@c
1757@c This routine is used to interpret and authenticate an authenticator that
1758@c is sent over the network using the @code{krb_sendauth}
1759@c routine. @var{data} points to the beginning of the received message,
1760@c whose length is specified by @var{data_len}.  @var{service name} and
1761@c @var{instance} specify the Kerberos service being authenticated;
1762@c @var{from_addr} is the Internet address of the host originating the
1763@c request.  This routine fills information obtained from the
1764@c authenticator, fills in the session key in @var{key}, and returns the
1765@c version information in @var{version}.  @var{version} must point to an
1766@c area @code{KSEND_VNO_LEN} bytes long.
1767@c
1768@c This routine is similar to the original @code{krb_recvauth} routine,
1769@c except that it takes the authenticator as an argument instead of reading
1770@c a file descriptor, and @var{service key} as an argument instead of
1771@c reading a @file{srvtab} file.  If mutual authentication is requested,
1772@c the application is responsible to use @code{KrbMakePrivate} to send back
1773@c the checksum + 1 in network byte order.
1774@node krb_net_write and krb_net_read
1775@subsection krb_net_write and krb_net_read
1776@findex krb_net_write
1777@findex krb_net_read
1778The @code{krb_net_write} function emulates the @code{write}(2) system
1779call, but guarantees that all data specified is written to @var{fd}
1780before returning, unless an error condition occurs.  The
1781@code{krb_net_read} function emulates the @code{read}(2) system call,
1782but guarantees that the requested amount of data is read from @var{fd}
1783before returning, unless an error condition occurs.
1784
1785@c @subsubheading BUGS
1786Note that @code{krb_sendauth}, @code{krb_recvauth},
1787@code{krb_net_write}, and @code{krb_net_read} do not work properly on
1788sockets set to non-blocking I/O mode.
1789@ignore
1790@subsubheading SEE ALSO
1791@table @ref
1792@item Kerberos,,krb_mk_req
1793@item Kerberos,,krb_rd_req
1794@item krb_realmofhost,,krb_get_phost
1795@end table
1796
1797@subsubheading RESTRICTIONS
1798Copyright 1988, Massachusetts Institute of Technology.  For copying and
1799distribution information, please see the file @file{<mit-copyright.h>}.
1800@end ignore
1801
1802
1803@node Realms
1804@section Realms
1805@subsection krb_get_phost
1806@findex krb_get_phost
1807
1808@code{char *krb_get_phost(char *@var{alias})}
1809
1810@code{krb_get_phost} converts the hostname @var{alias} (which can be
1811either an official name or an alias) into the instance name to be used
1812in obtaining Kerberos tickets for most services, including the Berkeley
1813@code{rcmd} suite (@code{rlogin}, @code{rcp}, @code{rsh}).  The current
1814convention is to return the first segment of the official domain-style
1815name after conversion to lower case.
1816
1817@node Ticket Files
1818@section Ticket Files
1819
1820These routines are the original interface to the credentials cache.
1821This interface worked poorly on non-Unix platforms, so it has been
1822superseded by the routines described in the Common API section.
1823
1824This group of routines is provided to manipulate a Kerberos ticket
1825file.  A @dfn{ticket file} has the following layout:
1826
1827@itemize @bullet
1828@item          principal's name (a null-terminated string)
1829@item          principal's instance (a null-terminated string)
1830@item          @var{CREDENTIAL_1}
1831@item          @var{CREDENTIAL_2}
1832@item            @dots{}
1833@item          @var{CREDENTIAL_n}
1834@item          EOF
1835@end itemize
1836
1837@var{CREDENTIAL_x} consists of the following fixed-length fields
1838from the @code{CREDENTIALS} structure (defined in @file{"krb.h"}):
1839
1840@smallexample
1841char service[ANAME_SZ]
1842char instance[INST_SZ]
1843char realm[REALM_SZ]
1844des_cblock session
1845int lifetime
1846int kvno
1847KTEXT_ST ticket_st
1848long issue_date
1849@end smallexample
1850
1851@menu
1852* tf_init::                     
1853* tf_get_pname::               
1854* tf_get_pinst::               
1855* tf_get_cred::                 
1856* tf_close::                   
1857@end menu
1858
1859
1860@node tf_init
1861@subsection tf_init
1862@findex tf_init
1863@code{tf_init} must be called before the other ticket file routines.  It
1864takes the name of the ticket file to use, and a read/write flag as an
1865argument.  It tries to open the ticket file, checks the mode and if
1866everything is okay, locks the file. If it is opened for reading, the
1867lock is shared.  If it is opened for writing, the lock is exclusive.
1868@code{KSUCCESS} is returned if all goes well, otherwise one of the
1869following messages is returned:
1870@table @code
1871@item NO_TKT_FIL
1872- file was not there
1873@item TKT_FIL_ACC
1874- file was in wrong mode, etc.
1875@item TKT_FIL_LCK
1876- could not lock the file, even after a retry
1877@end table
1878
1879@node tf_get_pname
1880@subsection tf_get_pname
1881@findex tf_get_pname
1882The @code{tf_get_pname} function reads the principal's name from a ticket
1883file. It should only be called after @code{tf_init} has been called.
1884The principal's name is filled into the @var{pname} parameter.  If all
1885goes well, @code{KSUCCESS} is returned.  If @code{tf_init} is not
1886called, @code{TKT_FIL_INI} is returned.  If the principal's name is
1887null, or @code{EOF} is encountered, or the name is longer than
1888@code{ANAME_SZ}, @code{TKT_FIL_FMT} is returned. 
1889
1890@node tf_get_pinst
1891@subsection tf_get_pinst
1892@findex tf_get_pinst
1893The
1894@code{tf_get_pinst} reads the principal's instance from a ticket file.
1895It should only be called after @code{tf_init} and @code{tf_get_pname}
1896are called.  The principal's instance is filled into the
1897@var{pinst} parameter.  If all goes well, @code{KSUCCESS} is returned.
1898If @code{tf_init} is not called, @code{TKT_FIL_INI} is returned.  If
1899@code{EOF} is encountered, or the name is longer than @code{INST_SZ},
1900@code{TKT_FIL_FMT} is returned.  Note that, unlike the principal name,
1901the instance name may be null. 
1902
1903@node tf_get_cred
1904@subsection tf_get_cred
1905@findex tf_get_cred
1906The @code{tf_get_cred} routine reads a
1907@var{CREDENTIALS} record from a ticket file and fills in the given
1908structure.  It should only be called after @code{tf_init},
1909@code{tf_get_pname}, and @code{tf_get_pinst} are called.  If all
1910goes well, @code{KSUCCESS} is returned.  Possible error codes are:
1911@table @code
1912@item TKT_FIL_INI
1913- @code{tf_init} was not called first
1914@item TKT_FIL_FMT
1915- bad format
1916@item EOF
1917- end of file encountered
1918@end table
1919
1920@node tf_close
1921@subsection tf_close
1922@findex tf_close
1923@code{tf_close} closes the ticket file and releases the lock on it.
1924@ignore
1925@subsubheading SEE ALSO
1926@xref{Kerberos}.
1927@subsubheading BUGS
1928The ticket file routines have to be called in a certain order.
1929@subsubheading RESTRICTIONS
1930Copyright 1987 Massachusetts Institute of Technology
1931@end ignore
1932
1933
1934@node Other
1935@section Other
1936@menu
1937* krb_set_tkt_string::  krb_set_tkt_string
1938* kuserok::             kuserok
1939@end menu
1940
1941
1942@node krb_set_tkt_string
1943@subsection krb_set_tkt_string
1944@findex krb_set_tkt_string
1945
1946@smallexample
1947#include "krb.h"
1948void krb_set_tkt_string(char *@var{filename});
1949@end smallexample
1950
1951@code{krb_set_tkt_string} sets the name of the file that holds the
1952user's cache of Kerberos server tickets and associated session keys.
1953The string @var{filename} passed in is copied into local storage.  Only
1954@code{MAXPATHLEN-1} characters of the filename are copied in for use as
1955the cache file name.  This routine should be called during
1956initialization, before other Kerberos routines are called; otherwise the
1957routines which fetch the ticket cache file name may be called and return
1958an undesired ticket file name until this routine is called.  The default
1959ticket file name (unless the environment variable @code{KRBTKFILE} is
1960set) is @file{/tmp/tkt@var{uid}}), where @var{uid} denotes the user's
1961ID, in decimal.
1962
1963
1964@node kuserok
1965@subsection kuserok
1966@findex kuserok
1967
1968@smallexample
1969#include "krb.h"
1970kuserok(AUTH_DAT *@var{auth_data}, char *@var{localuser});
1971@end smallexample
1972
1973@code{kuserok} determines whether a Kerberos principal described by the
1974structure @var{auth_data} is authorized to login as user @var{localuser}
1975according to the authorization file (@file{~localuser/.klogin} by
1976default).  It returns zero if authorized, `1' if not authorized.  If
1977there is no account for @var{localuser} on the local machine,
1978authorization is not granted.  If there is no authorization file, and
1979the Kerberos principal described by @var{auth_data} translates to
1980@var{localuser} (using @pxref{krb_kntoln}), authorization is granted.
1981If the authorization file can not be accessed, or the file is not owned
1982by @var{localuser}, authorization is denied.  Otherwise, the file is
1983searched for a matching principal name, and realm.  If a match is found,
1984authorization is granted, else authorization is denied.  The file
1985entries are in the format:
1986@smallexample
1987@var{name}.@var{instance}@@@var{realm}
1988@end smallexample
1989@noindent
1990with one entry per line.
1991@ignore
1992@subsubheading SEE ALSO
1993@table @ref
1994@item Kerberos
1995@item Kerberos,,krb_kntoln
1996@end table
1997@code{ruserok}(3)
1998
1999@subsubheading FILES
2000@table @file
2001@item ~localuser/.klogin
2002authorization list
2003@end table
2004@end ignore
2005
2006
2007@node Macintosh Library API
2008@chapter CNS Macintosh Library API
2009
2010This chapter documents Macintosh-specific aspects of the Cygnus Network
2011Support Kerberos programming interface.
2012 
2013On the Macintosh, the standard Kerberos API is available, as
2014documented in the common API section.  These standard
2015routines are implemented as
2016glue code which in turn calls a driver.  In the driver is more glue code
2017which then calls the real routines.
2018
2019@emph{We STRONGLY recommend that you write your programs to use the
2020ordinary Kerberos subroutine call API.  The low-level Macintosh
2021interface is not
2022guaranteed to remain stable.  It's a lot easier to program with
2023simple subroutine calls instead of I/O traps too.}
2024
2025Application programs which have unusual requirements can call the
2026driver directly, though this is discouraged.  To call the driver
2027directly, examine the file @file{mac_stubs.c} in the source code
2028distribution of Cygnus Network Security, in the @file{src/lib/krb}
2029directory.
2030
2031The low-level Kerberos interface is designed to be compatible with the
2032@code{kclient} program from Cornell, and borrows some code from the
2033@code{kclient} and @code{kconfig} programs.  Programs written to work
2034with the @code{kclient} Mac Kerberos driver will probably work with
2035Cygnus Network Security's driver as well.  One feature of the @code{kclient}
2036program that is not implemented by CNS is multiple named credential caches.
2037Supporting this feature would have required changing the basic
2038API for several Kerberos functions.
2039
2040None of the CNS driver operations work asynchronously; the driver must
2041be called synchronously.
2042
2043
2044@menu
2045* Compiling and Linking your Macintosh Program::
2046@end menu
2047
2048@node Compiling and Linking your Macintosh Program
2049@section Compiling and Linking your Macintosh Program
2050
2051The Macintosh Kerberos driver is installed into the @samp{Extensions}
2052folder in the @samp{System Folder} on the disk drive from which you boot.
2053It installs itself into the system at boot time, putting a small icon
2054along the bottom of the screen for a short time.  By the time the system
2055comes up, the driver is ready for use.
2056
2057The preferred way to use the driver is to @code{#include "krb.h"}
2058in all of your source modules that call Kerberos routines.  Make
2059sure that your program calls @code{krb_start_session} before calling any
2060other Kerberos routines.  Compile and link your code with the
2061@file{mac_stubs.c} file, which provides the short `stub' routines
2062which translate the Common Kerberos Library API into the arcane calling
2063conventions of Macintosh drivers.
2064
2065If @code{krb_start_session} does not return @code{KSUCCESS}, it is
2066unable to locate or initialize a Kerberos driver in your Macintosh.
2067Check your Extensions folder to make sure that the driver is being
2068installed on each reboot.  You must reboot after putting the driver in
2069the Extensions folder as well.
2070
2071@node MS-Windows Library API
2072@chapter MS-Windows Application Programmer Interface
2073
2074This chapter documents Microsoft Windows-specific aspects of the
2075Cygnus Network Support Kerberos programming interface.
2076 
2077On MS-Windows, the standard Kerberos API is available, as
2078documented in the common API section.  These standard
2079routines are implemented in a Dynamic Link Library called
2080@file{KERBEROS.DLL}.
2081
2082Due to the standard DLL calling conventions,
2083all pointers passed to or returned from the MS-Windows Kerberos
2084implementation are
2085FAR pointers.  The interface file @file{kerberos.h}, which is included
2086by the usual @file{krb.h} include file, provides function
2087prototypes that cause any pointers arguments to be converted to
2088FAR pointers.  You must ensure that any result values which are pointers
2089are handled properly as FAR pointers.
2090
2091Values which are specified as @code{int} are 16 bit numbers using
2092MS-Windows compilers.
2093
2094@menu
2095* Compiling and Linking your MS-Windows Program::
2096* Password changing calls::     Interface for changing a user's password
2097* Ticket cache notification::   Finding out when the cache changes
2098* Timekeeping::                 Time epochs and clock access
2099@end menu
2100
2101@node Compiling and Linking your MS-Windows Program
2102@section Compiling and Linking your MS-Windows Program
2103
2104The @file{KERBEROS.DLL} file can be installed anywhere on
2105the search path.
2106
2107The preferred way to use the driver is to @code{#include "krb.h"} in all
2108of your source modules that call Kerberos routines.  Make sure that your
2109program calls @code{krb_start_session} before calling any other Kerberos
2110routines.  Link your code with the @file{KERBEROS.LIB} file, which
2111causes calls to @file{KERBEROS.DLL} to occur when running the program.
2112
2113@node Password changing calls
2114@section Password changing calls
2115
2116Due to the need to formally externalize calls from a DLL, a number of
2117routines which are only used in @code{kpasswd} on UNIX are visible in
2118the MS-Windows interface.  The routines are used by the @code{CNS} user
2119interface program on Windows.  On Unix, these routines reside within the
2120@code{kadm} library; they are not usually called by users.
2121
2122@smallexample
2123int kadm_change_pw (des_cblock key);
2124
2125int kadm_change_pw2 (des_cblock key, char *password,
2126unsigned char **ret_st);
2127
2128int kadm_init_link (char *pwserv_name, char *krb_master,
2129char *realm);
2130@end smallexample
2131
2132@node Ticket cache notification
2133@section Ticket cache notification
2134
2135This MS-Windows-specific API call gives an interactive application
2136notification when the contents of the ticket cache change.  The call
2137returns the number of the unique message which are sent to all top level
2138windows after the ticket cache changes.  The @code{CNS} program uses
2139this message to keep its display current.  The prototype is as follows:
2140
2141@smallexample
2142int krb_get_notification_message(void)
2143@end smallexample
2144
2145
2146@node Timekeeping
2147@section Timekeeping
2148
2149The Kerberos protocol uses timestamps based on an epoch
2150in which time begins at
215100:00 January 1, 1970.  All times expected and returned by the
2152Kerberos API are in these
2153units, independent of what the C library returns.  Note that Microsoft C 7.0
2154starts time at January 1, 1900, though they backed that change out in
2155version 7.0.1.  Our code can run in either environment.
2156
2157Kerberos reads time from the hardware clock using BIOS interrupt
21580x1A.  This avoids problems with the software clock drifting as the
2159system runs.
2160
2161The local time zone is set by the @code{TZ} environment variable.
2162
2163@node Function Index
2164@chapter Function Index
2165
2166@printindex fn
2167
2168@contents
2169@c end of texinfo file
2170@bye
2171@c (modify-syntax-entry ?_ "w" para-mode-syntax-table)
2172@c (modify-syntax-entry ?- "w" para-mode-syntax-table)
2173@c (modify-syntax-entry ?/ "w" para-mode-syntax-table)
Note: See TracBrowser for help on using the repository browser.