Rename PAC type constants to avoid conflicts
[krb5.git] / src / include / krb5 / krb5.hin
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* General definitions for Kerberos version 5. */
3 /*
4  * Copyright 1989, 1990, 1995, 2001, 2003, 2007, 2011 by the Massachusetts
5  * Institute of Technology.  All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26 /*
27  * Copyright (C) 1998 by the FundsXpress, INC.
28  *
29  * All rights reserved.
30  *
31  * Export of this software from the United States of America may require
32  * a specific license from the United States Government.  It is the
33  * responsibility of any person or organization contemplating export to
34  * obtain such a license before exporting.
35  *
36  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
37  * distribute this software and its documentation for any purpose and
38  * without fee is hereby granted, provided that the above copyright
39  * notice appear in all copies and that both that copyright notice and
40  * this permission notice appear in supporting documentation, and that
41  * the name of FundsXpress. not be used in advertising or publicity pertaining
42  * to distribution of the software without specific, written prior
43  * permission.  FundsXpress makes no representations about the suitability of
44  * this software for any purpose.  It is provided "as is" without express
45  * or implied warranty.
46  *
47  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
48  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
49  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
50  */
51
52 #ifndef KRB5_GENERAL__
53 #define KRB5_GENERAL__
54
55 /* By default, do not expose deprecated interfaces. */
56 #ifndef KRB5_DEPRECATED
57 #define KRB5_DEPRECATED 0
58 #endif
59
60 #if defined(__MACH__) && defined(__APPLE__)
61 #       include <TargetConditionals.h>
62 #    if TARGET_RT_MAC_CFM
63 #       error "Use KfM 4.0 SDK headers for CFM compilation."
64 #    endif
65 #endif
66
67 #if defined(_MSDOS) || defined(_WIN32)
68 #include <win-mac.h>
69 #endif
70
71 #ifndef KRB5_CONFIG__
72 #ifndef KRB5_CALLCONV
73 #define KRB5_CALLCONV
74 #define KRB5_CALLCONV_C
75 #endif /* !KRB5_CALLCONV */
76 #endif /* !KRB5_CONFIG__ */
77
78 #ifndef KRB5_CALLCONV_WRONG
79 #define KRB5_CALLCONV_WRONG
80 #endif
81
82 #ifndef THREEPARAMOPEN
83 #define THREEPARAMOPEN(x,y,z) open(x,y,z)
84 #endif
85
86 #define KRB5_OLD_CRYPTO
87
88 #include <stdlib.h>
89 #include <limits.h>             /* for *_MAX */
90 #include <stdarg.h>
91
92 #ifndef KRB5INT_BEGIN_DECLS
93 #if defined(__cplusplus)
94 #define KRB5INT_BEGIN_DECLS     extern "C" {
95 #define KRB5INT_END_DECLS       }
96 #else
97 #define KRB5INT_BEGIN_DECLS
98 #define KRB5INT_END_DECLS
99 #endif
100 #endif
101
102 KRB5INT_BEGIN_DECLS
103
104 #if TARGET_OS_MAC
105 #    pragma pack(push,2)
106 #endif
107
108 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 30203
109 # define KRB5_ATTR_DEPRECATED __attribute__((deprecated))
110 #elif defined _WIN32
111 # define KRB5_ATTR_DEPRECATED __declspec(deprecated)
112 #else
113 # define KRB5_ATTR_DEPRECATED
114 #endif
115
116 /* from profile.h */
117 struct _profile_t;
118 /* typedef struct _profile_t *profile_t; */
119
120 /*
121  * begin wordsize.h
122  */
123
124 /*
125  * Word-size related definition.
126  */
127
128 typedef unsigned char   krb5_octet;
129
130 #if INT_MAX == 0x7fff
131 typedef int     krb5_int16;
132 typedef unsigned int    krb5_ui_2;
133 #elif SHRT_MAX == 0x7fff
134 typedef short   krb5_int16;
135 typedef unsigned short  krb5_ui_2;
136 #else
137 #error undefined 16 bit type
138 #endif
139
140 #if INT_MAX == 0x7fffffffL
141 typedef int     krb5_int32;
142 typedef unsigned int    krb5_ui_4;
143 #elif LONG_MAX == 0x7fffffffL
144 typedef long    krb5_int32;
145 typedef unsigned long   krb5_ui_4;
146 #elif SHRT_MAX == 0x7fffffffL
147 typedef short   krb5_int32;
148 typedef unsigned short  krb5_ui_4;
149 #else
150 #error: undefined 32 bit type
151 #endif
152
153 #define VALID_INT_BITS    INT_MAX
154 #define VALID_UINT_BITS   UINT_MAX
155
156 #define KRB5_INT32_MAX  2147483647
157 /* this strange form is necessary since - is a unary operator, not a sign
158    indicator */
159 #define KRB5_INT32_MIN  (-KRB5_INT32_MAX-1)
160
161 #define KRB5_INT16_MAX 65535
162 /* this strange form is necessary since - is a unary operator, not a sign
163    indicator */
164 #define KRB5_INT16_MIN  (-KRB5_INT16_MAX-1)
165
166 /*
167  * end wordsize.h
168  */
169
170 /*
171  * begin "base-defs.h"
172  */
173
174 /*
175  * Basic definitions for Kerberos V5 library
176  */
177
178 #ifndef FALSE
179 #define FALSE   0
180 #endif
181 #ifndef TRUE
182 #define TRUE    1
183 #endif
184
185 typedef unsigned int krb5_boolean;
186 typedef unsigned int krb5_msgtype;
187 typedef unsigned int krb5_kvno;
188
189 typedef krb5_int32 krb5_addrtype;
190 typedef krb5_int32 krb5_enctype;
191 typedef krb5_int32 krb5_cksumtype;
192 typedef krb5_int32 krb5_authdatatype;
193 typedef krb5_int32 krb5_keyusage;
194 typedef krb5_int32 krb5_cryptotype;
195
196 typedef krb5_int32      krb5_preauthtype; /* This may change, later on */
197 typedef krb5_int32      krb5_flags;
198 typedef krb5_int32      krb5_timestamp;
199 typedef krb5_int32      krb5_error_code;
200 typedef krb5_int32      krb5_deltat;
201
202 typedef krb5_error_code krb5_magic;
203
204 typedef struct _krb5_data {
205     krb5_magic magic;
206     unsigned int length;
207     char *data;
208 } krb5_data;
209
210 typedef struct _krb5_octet_data {
211     krb5_magic magic;
212     unsigned int length;
213     krb5_octet *data;
214 } krb5_octet_data;
215
216 /*
217  * Hack length for crypto library to use the afs_string_to_key It is
218  * equivalent to -1 without possible sign extension
219  * We also overload for an unset salt type length - which is also -1, but
220  * hey, why not....
221  */
222 #define SALT_TYPE_AFS_LENGTH UINT_MAX
223 #define SALT_TYPE_NO_LENGTH  UINT_MAX
224
225 typedef void * krb5_pointer;
226 typedef void const * krb5_const_pointer;
227
228 typedef struct krb5_principal_data {
229     krb5_magic magic;
230     krb5_data realm;
231     krb5_data *data;            /**< An array of strings */
232     krb5_int32 length;
233     krb5_int32 type;
234 } krb5_principal_data;
235
236 typedef krb5_principal_data * krb5_principal;
237
238 /*
239  * Per V5 spec on definition of principal types
240  */
241
242 /* Name type not known */
243 #define KRB5_NT_UNKNOWN                 0
244 /* Just the name of the principal as in DCE, or for users */
245 #define KRB5_NT_PRINCIPAL               1
246 /* Service and other unique instance (krbtgt) */
247 #define KRB5_NT_SRV_INST                2
248 /* Service with host name as instance (telnet, rcommands) */
249 #define KRB5_NT_SRV_HST                 3
250 /* Service with host as remaining components */
251 #define KRB5_NT_SRV_XHST                4
252 /* Unique ID */
253 #define KRB5_NT_UID                     5
254 /* PKINIT */
255 #define KRB5_NT_X500_PRINCIPAL          6
256 /* Name in form of SMTP email name */
257 #define KRB5_NT_SMTP_NAME               7
258 /* Windows 2000 UPN */
259 #define KRB5_NT_ENTERPRISE_PRINCIPAL    10
260 #define KRB5_NT_WELLKNOWN               11
261 /* First component of NT_WELLKNOWN principals */
262 #define KRB5_WELLKNOWN_NAMESTR          "WELLKNOWN"
263 /* Windows 2000 UPN and SID */
264 #define KRB5_NT_MS_PRINCIPAL            -128
265 /* NT 4 style name */
266 #define KRB5_NT_MS_PRINCIPAL_AND_ID     -129
267 /* NT 4 style name and SID */
268 #define KRB5_NT_ENT_PRINCIPAL_AND_ID    -130
269
270 /** Constant version of krb5_principal_data */
271 typedef const krb5_principal_data *krb5_const_principal;
272
273 #define krb5_princ_realm(context, princ) (&(princ)->realm)
274 #define krb5_princ_set_realm(context, princ,value) ((princ)->realm = *(value))
275 #define krb5_princ_set_realm_length(context, princ,value) (princ)->realm.length = (value)
276 #define krb5_princ_set_realm_data(context, princ,value) (princ)->realm.data = (value)
277 #define krb5_princ_size(context, princ) (princ)->length
278 #define krb5_princ_type(context, princ) (princ)->type
279 #define krb5_princ_name(context, princ) (princ)->data
280 #define krb5_princ_component(context, princ,i)  \
281     (((i) < krb5_princ_size(context, princ))    \
282      ? (princ)->data + (i)                      \
283      : NULL)
284
285 /** Constant for realm referrals. */
286 #define        KRB5_REFERRAL_REALM      ""
287
288 /*
289  * Referral-specific functions.
290  */
291
292 /**
293  * Check for a match with KRB5_REFERRAL_REALM.
294  *
295  * @param [in] r                Realm to check
296  *
297  * @return @c TRUE if @a r is zero-length, @c FALSE otherwise
298  */
299 krb5_boolean KRB5_CALLCONV
300 krb5_is_referral_realm(const krb5_data *r);
301
302 /**
303  * Return an anonymous realm data.
304  *
305  * This function returns constant storage that must not be freed.
306  *
307  * @sa #KRB5_ANONYMOUS_REALMSTR
308  */
309 const krb5_data *KRB5_CALLCONV
310 krb5_anonymous_realm(void);
311
312 /**
313  * Build an anonymous principal.
314  *
315  * This function returns constant storage that must not be freed.
316  *
317  * @sa KRB5_ANONYMOUS_PRINCSTR
318  */
319 krb5_const_principal KRB5_CALLCONV
320 krb5_anonymous_principal(void);
321
322 #define KRB5_ANONYMOUS_REALMSTR "WELLKNOWN:ANONYMOUS"
323 #define KRB5_ANONYMOUS_PRINCSTR "ANONYMOUS" /* wellknown name type */
324 /*
325  * end "base-defs.h"
326  */
327
328 /*
329  * begin "hostaddr.h"
330  */
331
332 /** Structure for address */
333 typedef struct _krb5_address {
334     krb5_magic magic;
335     krb5_addrtype addrtype;
336     unsigned int length;
337     krb5_octet *contents;
338 } krb5_address;
339
340 /* per Kerberos v5 protocol spec */
341 #define ADDRTYPE_INET           0x0002
342 #define ADDRTYPE_CHAOS          0x0005
343 #define ADDRTYPE_XNS            0x0006
344 #define ADDRTYPE_ISO            0x0007
345 #define ADDRTYPE_DDP            0x0010
346 #define ADDRTYPE_NETBIOS        0x0014
347 #define ADDRTYPE_INET6          0x0018
348 /* not yet in the spec... */
349 #define ADDRTYPE_ADDRPORT       0x0100
350 #define ADDRTYPE_IPPORT         0x0101
351
352 /* macros to determine if a type is a local type */
353 #define ADDRTYPE_IS_LOCAL(addrtype) (addrtype & 0x8000)
354
355 /*
356  * end "hostaddr.h"
357  */
358
359
360 struct _krb5_context;
361 typedef struct _krb5_context * krb5_context;
362
363 struct _krb5_auth_context;
364 typedef struct _krb5_auth_context * krb5_auth_context;
365
366 struct _krb5_cryptosystem_entry;
367
368 /*
369  * begin "encryption.h"
370  */
371
372 /** Exposed contents of a key. */
373 typedef struct _krb5_keyblock {
374     krb5_magic magic;
375     krb5_enctype enctype;
376     unsigned int length;
377     krb5_octet *contents;
378 } krb5_keyblock;
379
380 struct krb5_key_st;
381 /**
382  * Opaque identifier for a key.
383  *
384  * Use with the krb5_k APIs for better performance for repeated operations with
385  * the same key and usage.  Key identifiers must not be used simultaneously
386  * within multiple threads, as they may contain mutable internal state and are
387  * not mutex-protected.
388  */
389 typedef struct krb5_key_st *krb5_key;
390
391 #ifdef KRB5_OLD_CRYPTO
392 typedef struct _krb5_encrypt_block {
393     krb5_magic magic;
394     krb5_enctype crypto_entry;          /* to call krb5_encrypt_size, you need
395                                            this.  it was a pointer, but it
396                                            doesn't have to be.  gross. */
397     krb5_keyblock *key;
398 } krb5_encrypt_block;
399 #endif
400
401 typedef struct _krb5_checksum {
402     krb5_magic magic;
403     krb5_cksumtype checksum_type;       /* checksum type */
404     unsigned int length;
405     krb5_octet *contents;
406 } krb5_checksum;
407
408 typedef struct _krb5_enc_data {
409     krb5_magic magic;
410     krb5_enctype enctype;
411     krb5_kvno kvno;
412     krb5_data ciphertext;
413 } krb5_enc_data;
414
415 /**
416  * Structure to describe a region of text to be encrypted or decrypted.
417  *
418  * The @a flags member describes the type of the iov.
419  * The @a data member points to the memory that will be manipulated.
420  * All iov APIs take a pointer to the first element of an array of krb5_crypto_iov's
421  * along with the size of that array. Buffer contents are manipulated in-place;
422  * data is overwritten. Callers must allocate the right number of krb5_crypto_iov
423  * structures before calling into an iov API.
424  */
425 typedef struct _krb5_crypto_iov {
426     krb5_cryptotype flags; /**< @ref KRB5_CRYPTO_TYPE type of the iov */
427     krb5_data data;
428 } krb5_crypto_iov;
429
430 /* per Kerberos v5 protocol spec */
431 #define ENCTYPE_NULL            0x0000
432 #define ENCTYPE_DES_CBC_CRC     0x0001  /**< DES cbc mode with CRC-32 */
433 #define ENCTYPE_DES_CBC_MD4     0x0002  /**< DES cbc mode with RSA-MD4 */
434 #define ENCTYPE_DES_CBC_MD5     0x0003  /**< DES cbc mode with RSA-MD5 */
435 #define ENCTYPE_DES_CBC_RAW     0x0004  /**< @deprecated DES cbc mode raw */
436 #define ENCTYPE_DES3_CBC_SHA    0x0005  /**< @deprecated DES-3 cbc with SHA1 */
437 #define ENCTYPE_DES3_CBC_RAW    0x0006  /**< @deprecated DES-3 cbc mode raw */
438 #define ENCTYPE_DES_HMAC_SHA1   0x0008  /**< @deprecated */
439 /* PKINIT */
440 #define ENCTYPE_DSA_SHA1_CMS    0x0009  /**< DSA with SHA1, CMS signature */
441 #define ENCTYPE_MD5_RSA_CMS     0x000a  /**< MD5 with RSA, CMS signature */
442 #define ENCTYPE_SHA1_RSA_CMS    0x000b  /**< SHA1 with RSA, CMS signature */
443 #define ENCTYPE_RC2_CBC_ENV     0x000c  /**< RC2 cbc mode, CMS enveloped data */
444 #define ENCTYPE_RSA_ENV         0x000d  /**< RSA encryption, CMS enveloped data */
445 #define ENCTYPE_RSA_ES_OAEP_ENV 0x000e  /**< RSA w/OEAP encryption, CMS enveloped data */
446 #define ENCTYPE_DES3_CBC_ENV    0x000f  /**< DES-3 cbc mode, CMS enveloped data */
447
448 #define ENCTYPE_DES3_CBC_SHA1           0x0010
449 #define ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011 /**< RFC 3962 */
450 #define ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012 /**< RFC 3962 */
451 #define ENCTYPE_ARCFOUR_HMAC            0x0017
452 #define ENCTYPE_ARCFOUR_HMAC_EXP        0x0018
453 #define ENCTYPE_UNKNOWN                 0x01ff
454
455 #define CKSUMTYPE_CRC32         0x0001
456 #define CKSUMTYPE_RSA_MD4       0x0002
457 #define CKSUMTYPE_RSA_MD4_DES   0x0003
458 #define CKSUMTYPE_DESCBC        0x0004
459 /* des-mac-k */
460 /* rsa-md4-des-k */
461 #define CKSUMTYPE_RSA_MD5       0x0007
462 #define CKSUMTYPE_RSA_MD5_DES   0x0008
463 #define CKSUMTYPE_NIST_SHA      0x0009
464 #define CKSUMTYPE_HMAC_SHA1_DES3      0x000c
465 #define CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f /**< RFC 3962. Used with
466                                                   ENCTYPE_AES128_CTS_HMAC_SHA1_96 */
467 #define CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010 /**< RFC 3962. Used with
468                                                   ENCTYPE_AES256_CTS_HMAC_SHA1_96 */
469 #define CKSUMTYPE_MD5_HMAC_ARCFOUR -137 /*Microsoft netlogon cksumtype*/
470 #define CKSUMTYPE_HMAC_MD5_ARCFOUR -138 /*Microsoft md5 hmac cksumtype*/
471
472 /*
473  * The following are entropy source designations. Whenever
474  * krb5_C_random_add_entropy is called, one of these source ids is passed in.
475  * This allows the library to better estimate bits of entropy in the sample and
476  * to keep track of what sources of entropy have contributed enough entropy.
477  * Sources marked internal MUST NOT be used by applications outside the
478  * Kerberos library
479  */
480
481 enum {
482     KRB5_C_RANDSOURCE_OLDAPI = 0, /*calls to krb5_C_RANDOM_SEED (INTERNAL)*/
483     KRB5_C_RANDSOURCE_OSRAND = 1, /* /dev/random or equivalent (internal)*/
484     KRB5_C_RANDSOURCE_TRUSTEDPARTY = 2, /* From KDC or other trusted party*/
485     /*
486      * This source should be used carefully; data in this category
487      * should be from a third party trusted to give random bits
488      * For example keys issued by the KDC in the application server.
489      */
490     KRB5_C_RANDSOURCE_TIMING = 3, /* Timing of operations*/
491     KRB5_C_RANDSOURCE_EXTERNAL_PROTOCOL = 4, /*Protocol data possibly from attacker*/
492     KRB5_C_RANDSOURCE_MAX = 5 /*Do not use; maximum source ID*/
493 };
494
495 #ifndef krb5_roundup
496 /* round x up to nearest multiple of y */
497 #define krb5_roundup(x, y) ((((x) + (y) - 1)/(y))*(y))
498 #endif /* roundup */
499
500 /* macro function definitions to help clean up code */
501
502 #if 1
503 #define krb5_x(ptr,args) ((ptr)?((*(ptr)) args):(abort(),1))
504 #define krb5_xc(ptr,args) ((ptr)?((*(ptr)) args):(abort(),(char*)0))
505 #else
506 #define krb5_x(ptr,args) ((*(ptr)) args)
507 #define krb5_xc(ptr,args) ((*(ptr)) args)
508 #endif
509
510 /**
511  * Encrypt data using a key (operates on keyblock).
512  *
513  * @param [in]     context      Library context
514  * @param [in]     key          Encryption key
515  * @param [in]     usage        Key usage (see @ref KRB5_KEYUSAGE types)
516  * @param [in,out] cipher_state Cipher state; specify NULL if not needed
517  * @param [in]     input        Data to be encrypted
518  * @param [out]    output       Encrypted data
519  *
520  * This function encrypts the data block @a input and stores the output into @a
521  * output.  The actual encryption key will be derived from @a key and @a usage
522  * if key derivation is specified for the encryption type.  If non-null, @a
523  * cipher_state specifies the beginning state for the encryption operation, and
524  * is updated with the state to be passed as input to the next operation.
525  *
526  * @note The caller must initialize @a output and allocate at least enough
527  * space for the result (using krb5_c_encrypt_length() to determine the amount
528  * of space needed).  @a output->length will be set to the actual length of the
529  * ciphertext.
530  *
531  * @retval 0 Success; otherwise - Kerberos error codes
532  */
533 krb5_error_code KRB5_CALLCONV
534 krb5_c_encrypt(krb5_context context, const krb5_keyblock *key,
535                krb5_keyusage usage, const krb5_data *cipher_state,
536                const krb5_data *input, krb5_enc_data *output);
537
538 /**
539  * Decrypt data using a key (operates on keyblock).
540  *
541  * @param [in]     context      Library context
542  * @param [in]     key          Encryption key
543  * @param [in]     usage        Key usage (see @ref KRB5_KEYUSAGE types)
544  * @param [in,out] cipher_state Cipher state; specify NULL if not needed
545  * @param [in]     input        Encrypted data
546  * @param [out]    output       Decrypted data
547  *
548  * This function decrypts the data block @a input and stores the output into @a
549  * output. The actual decryption key will be derived from @a key and @a usage
550  * if key derivation is specified for the encryption type.  If non-null, @a
551  * cipher_state specifies the beginning state for the decryption operation, and
552  * is updated with the state to be passed as input to the next operation.
553  *
554  * @note The caller must initialize @a output and allocate at least enough
555  * space for the result.  The usual practice is to allocate an output buffer as
556  * long as the ciphertext, and let krb5_c_decrypt() trim @a output->length.
557  * For some enctypes, the resulting @a output->length may include padding
558  * bytes.
559  *
560  * @retval 0 Success; otherwise - Kerberos error codes
561  */
562 krb5_error_code KRB5_CALLCONV
563 krb5_c_decrypt(krb5_context context, const krb5_keyblock *key,
564                krb5_keyusage usage, const krb5_data *cipher_state,
565                const krb5_enc_data *input, krb5_data *output);
566
567 /**
568  * Compute encrypted data length.
569  *
570  * @param [in]  context         Library context
571  * @param [in]  enctype         Encryption type
572  * @param [in]  inputlen        Length of the data to be encrypted
573  * @param [out] length          Length of the encrypted data
574  *
575  * This function computes the length of the ciphertext produced by encrypting
576  * @a inputlen bytes including padding, confounder, and checksum.
577  *
578  * @retval 0 Success; otherwise - Kerberos error codes
579  */
580 krb5_error_code KRB5_CALLCONV
581 krb5_c_encrypt_length(krb5_context context, krb5_enctype enctype,
582                       size_t inputlen, size_t *length);
583
584 /**
585  * Return cipher block size.
586  *
587  * @param [in]  context         Library context
588  * @param [in]  enctype         Encryption type
589  * @param [out] blocksize       Block size for @a enctype
590  *
591  * @retval 0 Success; otherwise - Kerberos error codes
592  */
593 krb5_error_code KRB5_CALLCONV
594 krb5_c_block_size(krb5_context context, krb5_enctype enctype,
595                   size_t *blocksize);
596
597 /**
598  * Return length of the specified key in bytes.
599  *
600  * @param [in]  context         Library context
601  * @param [in]  enctype         Encryption type
602  * @param [out] keybytes        Number of bytes required to make a key
603  * @param [out] keylength       Length of final key
604  *
605  * @retval 0 Success; otherwise - Kerberos error codes
606  */
607 krb5_error_code KRB5_CALLCONV
608 krb5_c_keylengths(krb5_context context, krb5_enctype enctype,
609                   size_t *keybytes, size_t *keylength);
610
611 /**
612  * Initialize a new cipher state.
613  *
614  * @param [in]  context         Library context
615  * @param [in]  key             Key
616  * @param [in]  usage           Key usage (see @ref KRB5_KEYUSAGE types)
617  * @param [out] new_state       New cipher state
618  *
619  * @retval 0 Success; otherwise - Kerberos error codes
620  */
621 krb5_error_code KRB5_CALLCONV
622 krb5_c_init_state(krb5_context context, const krb5_keyblock *key,
623                   krb5_keyusage usage, krb5_data *new_state);
624
625 /**
626  * Free a cipher state previously allocated by krb5_c_init_state().
627  *
628  * @param [in] context          Library context
629  * @param [in] key              Key
630  * @param [in] state            Cipher state to be freed
631  *
632  * @retval 0 Success; otherwise - Kerberos error codes
633  */
634 krb5_error_code KRB5_CALLCONV
635 krb5_c_free_state(krb5_context context, const krb5_keyblock *key,
636                   krb5_data *state);
637
638 /**
639  * Generate enctype-specific pseudo-random bytes.
640  *
641  * @param [in]  context         Library context
642  * @param [in]  keyblock        Key
643  * @param [in]  input           Input data
644  * @param [out] output          Output data
645  *
646  * This function selects a pseudo-random function based on @a keyblock and
647  * computes its value over @a input, placing the result into @a output.
648  * The caller must preinitialize @a output and allocate space for the
649  * result, using krb5_c_prf_length() to determine the required length.
650  *
651  * @retval 0 Success; otherwise - Kerberos error codes
652  */
653 krb5_error_code KRB5_CALLCONV
654 krb5_c_prf(krb5_context context, const krb5_keyblock *keyblock,
655            krb5_data *input, krb5_data *output);
656
657 /**
658  * Get the output length of pseudo-random functions for an encryption type.
659  *
660  * @param [in]  context         Library context
661  * @param [in]  enctype         Encryption type
662  * @param [out] len             Length of PRF output
663  *
664  * @retval 0 Success; otherwise - Kerberos error codes
665  */
666 krb5_error_code KRB5_CALLCONV
667 krb5_c_prf_length(krb5_context context, krb5_enctype enctype, size_t *len);
668
669 /**
670  * Compute the KRB-FX-CF2 combination of two keys and pepper strings.
671  *
672  * @param [in]  context         Library context
673  * @param [in]  k1              KDC contribution key
674  * @param [in]  pepper1         String "PKINIT"
675  * @param [in]  k2              Reply key
676  * @param [in]  pepper2         String "KeyExchange"
677  * @param [out] out             Output key
678  *
679  * This function computes the KRB-FX-CF2 function over its inputs and places
680  * the results in a newly allocated keyblock.  This function is simple in that
681  * it assumes that @a pepper1 and @a pepper2 are C strings with no internal
682  * nulls and that the enctype of the result will be the same as that of @a k1.
683  * @a k1 and @a k2 may be of different enctypes.
684  *
685  * @retval 0 Success; otherwise - Kerberos error codes
686  */
687 krb5_error_code KRB5_CALLCONV
688 krb5_c_fx_cf2_simple(krb5_context context,
689                      krb5_keyblock *k1, const char *pepper1,
690                      krb5_keyblock *k2, const char *pepper2,
691                      krb5_keyblock **out);
692
693 /**
694  * Generate an enctype-specific random encryption key.
695  *
696  * @param [in]  context         Library context
697  * @param [in]  enctype         Encryption type of the generated key
698  * @param [out] k5_random_key   An allocated and initialized keyblock
699  *
700  * Use krb5_free_keyblock_contents() to free @a k5_random_key when
701  * no longer needed.
702  *
703  * @retval 0 Success; otherwise - Kerberos error codes
704  */
705 krb5_error_code KRB5_CALLCONV
706 krb5_c_make_random_key(krb5_context context, krb5_enctype enctype,
707                        krb5_keyblock *k5_random_key);
708
709 /**
710  * Generate an enctype-specific key from random data.
711  *
712  * @param [in]  context         Library context
713  * @param [in]  enctype         Encryption type
714  * @param [in]  random_data     Random input data
715  * @param [out] k5_random_key   Resulting key
716  *
717  * This function takes random input data @a random_data and produces a valid
718  * key @a k5_random_key for a given @a enctype.
719  *
720  * @note It is assumed that @a k5_random_key has already been initialized and
721  * @a k5_random_key->contents has been allocated with the correct length.
722  *
723  * @sa krb5_c_keylengths()
724  *
725  * @retval 0 Success; otherwise - Kerberos error codes
726  */
727 krb5_error_code KRB5_CALLCONV
728 krb5_c_random_to_key(krb5_context context, krb5_enctype enctype,
729                      krb5_data *random_data, krb5_keyblock *k5_random_key);
730
731 /**
732  * Add entropy to the pseudo-random number generator.
733  *
734  * @param [in] context          Library context
735  * @param [in] randsource       Entropy source (see KRB5_RANDSOURCE types)
736  * @param [in] data             Data
737  *
738  * Contribute entropy to the PRNG used by krb5 crypto operations.  This may or
739  * may not affect the output of the next crypto operation requiring random
740  * data.
741  *
742  * @retval 0 Success; otherwise - Kerberos error codes
743  */
744 krb5_error_code KRB5_CALLCONV
745 krb5_c_random_add_entropy(krb5_context context, unsigned int randsource,
746                           const krb5_data *data);
747
748 /**
749  * Generate pseudo-random bytes.
750  *
751  * @param [in]  context         Library context
752  * @param [out] data            Random data
753  *
754  * Fills in @a data with bytes from the PRNG used by krb5 crypto operations.
755  * The caller must preinitialize @a data and allocate the desired amount of
756  * space.
757  *
758  * @retval 0 Success; otherwise - Kerberos error codes
759  */
760 krb5_error_code KRB5_CALLCONV
761 krb5_c_random_make_octets(krb5_context context, krb5_data *data);
762
763 /**
764  * Collect entropy from the OS if possible.
765  *
766  * @param [in]  context         Library context
767  * @param [in]  strong          Strongest available source of entropy
768  * @param [out] success         1 if OS provides entropy, 0 otherwise
769  *
770  * If @a strong is non-zero, this function attempts to use the strongest
771  * available source of entropy.  Setting this flag may cause the function to
772  * block on some operating systems.  Good uses include seeding the PRNG for
773  * kadmind and realm setup.
774  *
775  * @retval 0 Success; otherwise - Kerberos error codes
776  */
777 krb5_error_code KRB5_CALLCONV
778 krb5_c_random_os_entropy(krb5_context context, int strong, int *success);
779
780 /** @deprecated Replaced by krb5_c_ API family. */
781 krb5_error_code KRB5_CALLCONV
782 krb5_c_random_seed(krb5_context context, krb5_data *data);
783
784 /**
785  * Convert a string (such a password) to a key.
786  *
787  * @param [in]  context         Library context
788  * @param [in]  enctype         Encryption type
789  * @param [in]  string          String to be converted
790  * @param [in]  salt            Salt value
791  * @param [out] key             Generated key
792  *
793  * This function converts @a string to a @a key of encryption type @a enctype,
794  * using the specified @a salt.  The newly created @a key must be released by
795  * calling krb5_free_keyblock_contents() when it is no longer needed.
796  *
797  * @retval 0 Success; otherwise - Kerberos error codes
798  */
799 krb5_error_code KRB5_CALLCONV
800 krb5_c_string_to_key(krb5_context context, krb5_enctype enctype,
801                      const krb5_data *string, const krb5_data *salt,
802                      krb5_keyblock *key);
803
804 /**
805  * Convert a string (such as a password) to a key with additional parameters.
806  *
807  * @param [in]  context         Library context
808  * @param [in]  enctype         Encryption type
809  * @param [in]  string          String to be converted
810  * @param [in]  salt            Salt value
811  * @param [in]  params          Parameters
812  * @param [out] key             Generated key
813  *
814  * This function is similar to krb5_c_string_to_key(), but also takes
815  * parameters which may affect the algorithm in an enctype-dependent way.  The
816  * newly created @a key must be released by calling
817  * krb5_free_keyblock_contents() when it is no longer needed.
818  *
819  * @retval 0 Success; otherwise - Kerberos error codes
820  */
821 krb5_error_code KRB5_CALLCONV
822 krb5_c_string_to_key_with_params(krb5_context context,
823                                  krb5_enctype enctype,
824                                  const krb5_data *string,
825                                  const krb5_data *salt,
826                                  const krb5_data *params,
827                                  krb5_keyblock *key);
828
829 /**
830  * Compare two encryption types.
831  *
832  * @param [in]  context         Library context
833  * @param [in]  e1              First encryption type
834  * @param [in]  e2              Second encryption type
835  * @param [out] similar         @c TRUE if types are similar, @c FALSE if not
836  *
837  * This function determines whether two encryption types use the same kind of
838  * keys.
839  *
840  * @retval 0 Success; otherwise - Kerberos error codes
841  */
842 krb5_error_code KRB5_CALLCONV
843 krb5_c_enctype_compare(krb5_context context, krb5_enctype e1, krb5_enctype e2,
844                        krb5_boolean *similar);
845
846 /**
847  * Compute a checksum (operates on keyblock).
848  *
849  * @param [in]  context         Library context
850  * @param [in]  cksumtype       Checksum type (0 for mandatory type)
851  * @param [in]  key             Encryption key for a keyed checksum
852  * @param [in]  usage           Key usage (see @ref KRB5_KEYUSAGE types)
853  * @param [in]  input           Input data
854  * @param [out] cksum           Generated checksum
855  *
856  * This function computes a checksum of type @a cksumtype over @a input, using
857  * @a key if the checksum type is a keyed checksum.  If @a cksumtype is 0 and
858  * @a key is non-null, the checksum type will be the mandatory-to-implement
859  * checksum type for the key's encryption type.  The actual checksum key will
860  * be derived from @a key and @a usage if key derivation is specified for the
861  * checksum type.  The newly created @a cksum must be released by calling
862  * krb5_free_checksum_contents() when it is no longer needed.
863  *
864  * @note This function is similar to krb5_k_make_checksum(), but operates
865  * on keyblock @a key.
866  *
867  * @sa krb5_c_verify_checksum()
868  *
869  * @retval 0 Success; otherwise - Kerberos error codes
870  */
871 krb5_error_code KRB5_CALLCONV
872 krb5_c_make_checksum(krb5_context context, krb5_cksumtype cksumtype,
873                      const krb5_keyblock *key, krb5_keyusage usage,
874                      const krb5_data *input, krb5_checksum *cksum);
875
876 /**
877  * Verify a checksum (operates on keyblock).
878  *
879  * @param [in]  context         Library context
880  * @param [in]  key             Encryption key for a keyed checksum
881  * @param [in]  usage           @a key usage
882  * @param [in]  data            Data to be used to compute a new checksum
883  *                              using @a key to compare @a cksum against
884  * @param [in]  cksum           Checksum to be verified
885  * @param [out] valid           Non-zero for success, zero for failure
886  *
887  * This function verifies that @a cksum is a valid checksum for @a data.  If
888  * the checksum type of @a cksum is a keyed checksum, @a key is used to verify
889  * the checksum.  The actual checksum key will be derived from @a key and @a
890  * usage if key derivation is specified for the checksum type.
891  *
892  * @note This function is similar to krb5_k_verify_checksum(), but operates
893  * on keyblock @a key.
894  *
895  * @retval 0 Success; otherwise - Kerberos error codes
896  */
897 krb5_error_code KRB5_CALLCONV
898 krb5_c_verify_checksum(krb5_context context, const krb5_keyblock *key,
899                        krb5_keyusage usage, const krb5_data *data,
900                        const krb5_checksum *cksum, krb5_boolean *valid);
901
902 /**
903  * Return the length of checksums for a checksum type.
904  *
905  * @param [in]  context         Library context
906  * @param [in]  cksumtype       Checksum type
907  * @param [out] length          Checksum length
908  *
909  * @retval 0 Success; otherwise - Kerberos error codes
910  */
911 krb5_error_code KRB5_CALLCONV
912 krb5_c_checksum_length(krb5_context context, krb5_cksumtype cksumtype,
913                        size_t *length);
914
915 /**
916  * Return a list of keyed checksum types usable with an encryption type.
917  *
918  * @param [in]  context         Library context
919  * @param [in]  enctype         Encryption type
920  * @param [out] count           Count of allowable checksum types
921  * @param [out] cksumtypes      Array of allowable checksum types
922  *
923  * Use krb5_free_cksumtypes() to free @a cksumtypes when it is no longer
924  * needed.
925  *
926  * @retval 0 Success; otherwise - Kerberos error codes
927  */
928 krb5_error_code KRB5_CALLCONV
929 krb5_c_keyed_checksum_types(krb5_context context, krb5_enctype enctype,
930                             unsigned int *count, krb5_cksumtype **cksumtypes);
931
932 /** @defgroup KRB5_KEYUSAGE KRB5_KEYUSAGE
933  * @{
934  */
935 #define KRB5_KEYUSAGE_AS_REQ_PA_ENC_TS          1
936 #define KRB5_KEYUSAGE_KDC_REP_TICKET            2
937 #define KRB5_KEYUSAGE_AS_REP_ENCPART            3
938 #define KRB5_KEYUSAGE_TGS_REQ_AD_SESSKEY        4
939 #define KRB5_KEYUSAGE_TGS_REQ_AD_SUBKEY         5
940 #define KRB5_KEYUSAGE_TGS_REQ_AUTH_CKSUM        6
941 #define KRB5_KEYUSAGE_TGS_REQ_AUTH              7
942 #define KRB5_KEYUSAGE_TGS_REP_ENCPART_SESSKEY   8
943 #define KRB5_KEYUSAGE_TGS_REP_ENCPART_SUBKEY    9
944 #define KRB5_KEYUSAGE_AP_REQ_AUTH_CKSUM         10
945 #define KRB5_KEYUSAGE_AP_REQ_AUTH               11
946 #define KRB5_KEYUSAGE_AP_REP_ENCPART            12
947 #define KRB5_KEYUSAGE_KRB_PRIV_ENCPART          13
948 #define KRB5_KEYUSAGE_KRB_CRED_ENCPART          14
949 #define KRB5_KEYUSAGE_KRB_SAFE_CKSUM            15
950 #define KRB5_KEYUSAGE_APP_DATA_ENCRYPT          16
951 #define KRB5_KEYUSAGE_APP_DATA_CKSUM            17
952 #define KRB5_KEYUSAGE_KRB_ERROR_CKSUM           18
953 #define KRB5_KEYUSAGE_AD_KDCISSUED_CKSUM        19
954 #define KRB5_KEYUSAGE_AD_MTE                    20
955 #define KRB5_KEYUSAGE_AD_ITE                    21
956
957 /* XXX need to register these */
958
959 #define KRB5_KEYUSAGE_GSS_TOK_MIC               22
960 #define KRB5_KEYUSAGE_GSS_TOK_WRAP_INTEG        23
961 #define KRB5_KEYUSAGE_GSS_TOK_WRAP_PRIV         24
962
963 /* Defined in hardware preauth draft */
964
965 #define KRB5_KEYUSAGE_PA_SAM_CHALLENGE_CKSUM    25
966 #define KRB5_KEYUSAGE_PA_SAM_CHALLENGE_TRACKID  26
967 #define KRB5_KEYUSAGE_PA_SAM_RESPONSE           27
968
969 /* Defined in KDC referrals draft */
970 /*
971  * @note There is a conflict with the value of @c KRB5_KEYUSAGE_PA_REFERRAL:
972  * it is used for hardware Pre-athentication @a and KDC referrals.
973  */
974 #define KRB5_KEYUSAGE_PA_REFERRAL               26 /* XXX note conflict with above */
975
976 /* Defined in [MS-SFU] */
977 #define KRB5_KEYUSAGE_PA_S4U_X509_USER_REQUEST  26 /* XXX note conflict with above */
978 #define KRB5_KEYUSAGE_PA_S4U_X509_USER_REPLY    27 /* XXX note conflict with above */
979
980 #define KRB5_KEYUSAGE_AD_SIGNEDPATH             -21
981 #define KRB5_KEYUSAGE_IAKERB_FINISHED           42
982 #define KRB5_KEYUSAGE_PA_PKINIT_KX              44
983 /* define in draft-ietf-krb-wg-preauth-framework*/
984 #define KRB5_KEYUSAGE_FAST_REQ_CHKSUM 50
985 #define KRB5_KEYUSAGE_FAST_ENC 51
986 #define KRB5_KEYUSAGE_FAST_REP 52
987 #define KRB5_KEYUSAGE_FAST_FINISHED 53
988 #define KRB5_KEYUSAGE_ENC_CHALLENGE_CLIENT 54
989 #define KRB5_KEYUSAGE_ENC_CHALLENGE_KDC 55
990 #define KRB5_KEYUSAGE_AS_REQ 56
991 /** @} */ /* end of KRB5_KEYUSAGE group */
992
993 /**
994  * Verify that a specified encryption type is a valid Kerberos encryption type.
995  *
996  * @param [in] ktype            Encryption type
997  *
998  * @return @c TRUE if @a ktype is valid, @c FALSE if not
999  */
1000 krb5_boolean KRB5_CALLCONV
1001 krb5_c_valid_enctype(krb5_enctype ktype);
1002
1003 /**
1004  * Verify that specified checksum type is a valid Kerberos checksum type.
1005  *
1006  * @param [in] ctype            Checksum type
1007  *
1008  * @return @c TRUE if @a ctype is valid, @c FALSE if not
1009  */
1010 krb5_boolean KRB5_CALLCONV
1011 krb5_c_valid_cksumtype(krb5_cksumtype ctype);
1012
1013 /**
1014  * Test whether a checksum type is collision-proof.
1015  *
1016  * @param [in] ctype            Checksum type
1017  *
1018  * @return @c TRUE if @a ctype is collision-proof, @c FALSE if it is not
1019  * collision-proof or not a valid checksum type.
1020  */
1021 krb5_boolean KRB5_CALLCONV
1022 krb5_c_is_coll_proof_cksum(krb5_cksumtype ctype);
1023
1024 /**
1025  * Test whether a checksum type is keyed.
1026  *
1027  * @param [in] ctype            Checksum type
1028  *
1029  * @return @c TRUE if @a ctype is a keyed checksum type, @c FALSE otherwise.
1030  */
1031 krb5_boolean KRB5_CALLCONV
1032 krb5_c_is_keyed_cksum(krb5_cksumtype ctype);
1033
1034 /* AEAD APIs */
1035 /** @defgroup KRB5_CRYPTO_TYPE KRB5_CRYPTO_TYPE
1036  * @{
1037  */
1038 #define KRB5_CRYPTO_TYPE_EMPTY      0   /**< [in] ignored */
1039 #define KRB5_CRYPTO_TYPE_HEADER     1   /**< [out] header */
1040 #define KRB5_CRYPTO_TYPE_DATA       2   /**< [in, out] plaintext */
1041 #define KRB5_CRYPTO_TYPE_SIGN_ONLY  3   /**< [in] associated data */
1042 #define KRB5_CRYPTO_TYPE_PADDING    4   /**< [out] padding */
1043 #define KRB5_CRYPTO_TYPE_TRAILER    5   /**< [out] checksum for encrypt */
1044 #define KRB5_CRYPTO_TYPE_CHECKSUM   6   /**< [out] checksum for MIC */
1045 #define KRB5_CRYPTO_TYPE_STREAM     7   /**< [in] entire message without
1046                                              decomposing the structure into
1047                                              header, data and trailer buffers */
1048 /** @} */ /* end of KRB5_CRYPTO_TYPE group */
1049
1050 /**
1051  * Fill in a checksum element in IOV array (operates on keyblock)
1052  *
1053  * @param [in]     context         Library context
1054  * @param [in]     cksumtype       Checksum type (0 for mandatory type)
1055  * @param [in]     key             Encryption key for a keyed checksum
1056  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1057  * @param [in,out] data            IOV array
1058  * @param [in]     num_data        Size of @a data
1059  *
1060  * Create a checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element over
1061  * #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY chunks in @a data.
1062  * Only the #KRB5_CRYPTO_TYPE_CHECKSUM region is modified.
1063  *
1064  * @note This function is similar to krb5_k_make_checksum_iov(), but operates
1065  * on keyblock @a key.
1066  *
1067  * @sa krb5_c_verify_checksum_iov()
1068  *
1069  * @retval 0 Success; otherwise - Kerberos error codes
1070  */
1071 krb5_error_code KRB5_CALLCONV
1072 krb5_c_make_checksum_iov(krb5_context context, krb5_cksumtype cksumtype,
1073                          const krb5_keyblock *key, krb5_keyusage usage,
1074                          krb5_crypto_iov *data, size_t num_data);
1075
1076 /**
1077  * Validate a checksum element in IOV array (operates on keyblock).
1078  *
1079  * @param [in]     context         Library context
1080  * @param [in]     cksumtype       Checksum type (0 for mandatory type)
1081  * @param [in]     key             Encryption key for a keyed checksum
1082  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1083  * @param [in]     data            IOV array
1084  * @param [in]     num_data        Size of @a data
1085  * @param [out]    valid           Non-zero for success, zero for failure
1086  *
1087  * Confirm that the checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element is a
1088  * valid checksum of the #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY
1089  * regions in the iov.
1090  *
1091  * @note This function is similar to krb5_k_verify_checksum_iov(), but operates
1092  * on keyblock @a key.
1093  *
1094  * @sa krb5_c_make_checksum_iov()
1095  *
1096  * @retval 0 Success; otherwise - Kerberos error codes
1097  */
1098 krb5_error_code KRB5_CALLCONV
1099 krb5_c_verify_checksum_iov(krb5_context context, krb5_cksumtype cksumtype,
1100                            const krb5_keyblock *key, krb5_keyusage usage,
1101                            const krb5_crypto_iov *data, size_t num_data,
1102                            krb5_boolean *valid);
1103
1104 /**
1105  * Encrypt data in place supporting AEAD (operates on keyblock).
1106  *
1107  * @param [in]     context         Library context
1108  * @param [in]     keyblock        Encryption key
1109  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1110  * @param [in]     cipher_state    Cipher state; specify NULL if not needed
1111  * @param [in,out] data            IOV array. Modified in-place.
1112  * @param [in]     num_data        Size of @a data
1113  *
1114  * This function encrypts the data block @a data and stores the output in-place.
1115  * The actual encryption key will be derived from @a keyblock and @a usage
1116  * if key derivation is specified for the encryption type.  If non-null, @a
1117  * cipher_state specifies the beginning state for the encryption operation, and
1118  * is updated with the state to be passed as input to the next operation.
1119  * The caller must allocate the right number of krb5_crypto_iov
1120  * structures before calling into this API.
1121  *
1122  * @note On return from a krb5_c_encrypt_iov() call, the @a data->length in the
1123  * iov structure are adjusted to reflect actual lengths of the ciphertext used.
1124  * For example, if the padding length is too large, the length will be reduced.
1125  * Lengths are never increased.
1126  *
1127  * @note This function is similar to krb5_k_encrypt_iov(), but operates
1128  * on keyblock @a keyblock.
1129  *
1130  * @sa krb5_c_decrypt_iov()
1131  *
1132  * @retval 0 Success; otherwise - Kerberos error codes
1133  */
1134 krb5_error_code KRB5_CALLCONV
1135 krb5_c_encrypt_iov(krb5_context context, const krb5_keyblock *keyblock,
1136                    krb5_keyusage usage, const krb5_data *cipher_state,
1137                    krb5_crypto_iov *data, size_t num_data);
1138
1139 /**
1140  * Decrypt data in place supporting AEAD (operates on keyblock).
1141  *
1142  * @param [in]     context         Library context
1143  * @param [in]     keyblock        Encryption key
1144  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1145  * @param [in]     cipher_state    Cipher state; specify NULL if not needed
1146  * @param [in,out] data            IOV array. Modified in-place.
1147  * @param [in]     num_data        Size of @a data
1148  *
1149  * This function decrypts the data block @a data and stores the output in-place.
1150  * The actual decryption key will be derived from @a keyblock and @a usage
1151  * if key derivation is specified for the encryption type.  If non-null, @a
1152  * cipher_state specifies the beginning state for the decryption operation, and
1153  * is updated with the state to be passed as input to the next operation.
1154  * The caller must allocate the right number of krb5_crypto_iov
1155  * structures before calling into this API.
1156  *
1157  * @note On return from a krb5_c_decrypt_iov() call, the @a data->length in the
1158  * iov structure are adjusted to reflect actual lengths of the ciphertext used.
1159  * For example, if the padding length is too large, the length will be reduced.
1160  * Lengths are never increased.
1161  *
1162  * @note This function is similar to krb5_k_decrypt_iov(), but operates
1163  * on keyblock @a keyblock.
1164  *
1165  * @sa krb5_c_decrypt_iov()
1166  *
1167  * @retval 0 Success; otherwise - Kerberos error codes
1168  */
1169 krb5_error_code KRB5_CALLCONV
1170 krb5_c_decrypt_iov(krb5_context context, const krb5_keyblock *keyblock,
1171                    krb5_keyusage usage, const krb5_data *cipher_state,
1172                    krb5_crypto_iov *data, size_t num_data);
1173
1174 /**
1175  * Return a length of a message field specific to the encryption type.
1176  *
1177  * @param [in]  context      Library context
1178  * @param [in]  enctype      Encryption type
1179  * @param [in]  type         Type field (See @ref KRB5_CRYPTO_TYPE types)
1180  * @param [out] size         Length of the @a type specific to @a enctype
1181  *
1182  * @retval 0 Success; otherwise - Kerberos error codes
1183  */
1184 krb5_error_code KRB5_CALLCONV
1185 krb5_c_crypto_length(krb5_context context, krb5_enctype enctype,
1186                      krb5_cryptotype type, unsigned int *size);
1187
1188 /**
1189  * Fill in lengths for header, trailer and padding in a IOV array.
1190  *
1191  * @param [in]      context      Library context
1192  * @param [in]      enctype      Encryption type
1193  * @param [in,out]  data         IOV array
1194  * @param [in]      num_data     Size of @a data
1195  *
1196  * Padding is set to the actual padding required based on the provided
1197  * @a data buffers. Typically this API is used after setting up the data
1198  * buffers and #KRB5_CRYPTO_TYPE_SIGN_ONLY buffers, but before actually
1199  * allocating header, trailer and padding.
1200  *
1201  * @retval 0 Success; otherwise - Kerberos error codes
1202  */
1203 krb5_error_code KRB5_CALLCONV
1204 krb5_c_crypto_length_iov(krb5_context context, krb5_enctype enctype,
1205                          krb5_crypto_iov *data, size_t num_data);
1206
1207 /**
1208  * Return a number of padding octets.
1209  *
1210  * @param [in]  context      Library context
1211  * @param [in]  enctype      Encryption type
1212  * @param [in]  data_length  Length of the plaintext to pad
1213  * @param [out] size         Number of padding octets
1214  *
1215  * This function returns the number of the padding octets required to pad
1216  * @a data_length octets of plaintext.
1217  *
1218  * @retval 0 Success; otherwise - KRB5_BAD_ENCTYPE
1219  */
1220 krb5_error_code KRB5_CALLCONV
1221 krb5_c_padding_length(krb5_context context, krb5_enctype enctype,
1222                       size_t data_length, unsigned int *size);
1223
1224 /**
1225  * Create a krb5_key from the enctype and key data in a keyblock.
1226  *
1227  * @param [in]  context      Library context
1228  * @param [in]  key_data     Keyblock
1229  * @param [out] out          Opaque key
1230  *
1231  * The reference count on a key @a out is set to 1.
1232  * Use krb5_k_free_key() to free @a out when it is no longer needed.
1233  *
1234  * @retval 0 Success; otherwise - KRB5_BAD_ENCTYPE
1235  */
1236 krb5_error_code KRB5_CALLCONV
1237 krb5_k_create_key(krb5_context context, const krb5_keyblock *key_data,
1238                   krb5_key *out);
1239
1240 /** Increment the reference count on a key. */
1241 void KRB5_CALLCONV
1242 krb5_k_reference_key(krb5_context context, krb5_key key);
1243
1244 /** Decrement the reference count on a key and free it if it hits zero. */
1245 void KRB5_CALLCONV
1246 krb5_k_free_key(krb5_context context, krb5_key key);
1247
1248 /** Retrieve a copy of the keyblock from a krb5_key structure. */
1249 krb5_error_code KRB5_CALLCONV
1250 krb5_k_key_keyblock(krb5_context context, krb5_key key,
1251                     krb5_keyblock **key_data);
1252
1253 /** Retrieve the enctype of a krb5_key structure. */
1254 krb5_enctype KRB5_CALLCONV
1255 krb5_k_key_enctype(krb5_context context, krb5_key key);
1256
1257 /**
1258  * Encrypt data using a key (operates on opaque key).
1259  *
1260  * @param [in]     context      Library context
1261  * @param [in]     key          Encryption key
1262  * @param [in]     usage        Key usage (see @ref KRB5_KEYUSAGE types)
1263  * @param [in,out] cipher_state Cipher state; specify NULL if not needed
1264  * @param [in]     input        Data to be encrypted
1265  * @param [out]    output       Encrypted data
1266  *
1267  * This function encrypts the data block @a input and stores the output into @a
1268  * output.  The actual encryption key will be derived from @a key and @a usage
1269  * if key derivation is specified for the encryption type.  If non-null, @a
1270  * cipher_state specifies the beginning state for the encryption operation, and
1271  * is updated with the state to be passed as input to the next operation.
1272  *
1273  * @note The caller must initialize @a output and allocate at least enough
1274  * space for the result (using krb5_c_encrypt_length() to determine the amount
1275  * of space needed).  @a output->length will be set to the actual length of the
1276  * ciphertext.
1277  *
1278  * @retval 0 Success; otherwise - Kerberos error codes
1279  */
1280 krb5_error_code KRB5_CALLCONV
1281 krb5_k_encrypt(krb5_context context, krb5_key key, krb5_keyusage usage,
1282                const krb5_data *cipher_state, const krb5_data *input,
1283                krb5_enc_data *output);
1284
1285 /**
1286  * Encrypt data in place supporting AEAD (operates on opaque key).
1287  *
1288  * @param [in]     context         Library context
1289  * @param [in]     key             Encryption key
1290  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1291  * @param [in]     cipher_state    Cipher state; specify NULL if not needed
1292  * @param [in,out] data            IOV array. Modified in-place.
1293  * @param [in]     num_data        Size of @a data
1294  *
1295  * This function encrypts the data block @a data and stores the output in-place.
1296  * The actual encryption key will be derived from @a key and @a usage
1297  * if key derivation is specified for the encryption type.  If non-null, @a
1298  * cipher_state specifies the beginning state for the encryption operation, and
1299  * is updated with the state to be passed as input to the next operation.
1300  * The caller must allocate the right number of krb5_crypto_iov
1301  * structures before calling into this API.
1302  *
1303  * @note On return from a krb5_c_encrypt_iov() call, the @a data->length in the
1304  * iov structure are adjusted to reflect actual lengths of the ciphertext used.
1305  * For example, if the padding length is too large, the length will be reduced.
1306  * Lengths are never increased.
1307  *
1308  * @note This function is similar to krb5_c_encrypt_iov(), but operates
1309  * on opaque key @a key.
1310  *
1311  * @sa krb5_k_decrypt_iov()
1312  *
1313  * @retval 0 Success; otherwise - Kerberos error codes
1314  */
1315 krb5_error_code KRB5_CALLCONV
1316 krb5_k_encrypt_iov(krb5_context context, krb5_key key, krb5_keyusage usage,
1317                    const krb5_data *cipher_state, krb5_crypto_iov *data,
1318                    size_t num_data);
1319
1320 /**
1321  * Decrypt data using a key (operates on opaque key).
1322  *
1323  * @param [in]     context      Library context
1324  * @param [in]     key          Encryption key
1325  * @param [in]     usage        Key usage (see @ref KRB5_KEYUSAGE types)
1326  * @param [in,out] cipher_state Cipher state; specify NULL if not needed
1327  * @param [in]     input        Encrypted data
1328  * @param [out]    output       Decrypted data
1329  *
1330  * This function decrypts the data block @a input and stores the output into @a
1331  * output. The actual decryption key will be derived from @a key and @a usage
1332  * if key derivation is specified for the encryption type.  If non-null, @a
1333  * cipher_state specifies the beginning state for the decryption operation, and
1334  * is updated with the state to be passed as input to the next operation.
1335  *
1336  * @note The caller must initialize @a output and allocate at least enough
1337  * space for the result.  The usual practice is to allocate an output buffer as
1338  * long as the ciphertext, and let krb5_c_decrypt() trim @a output->length.
1339  * For some enctypes, the resulting @a output->length may include padding
1340  * bytes.
1341  *
1342  * @retval 0 Success; otherwise - Kerberos error codes
1343  */
1344 krb5_error_code KRB5_CALLCONV
1345 krb5_k_decrypt(krb5_context context, krb5_key key, krb5_keyusage usage,
1346                const krb5_data *cipher_state, const krb5_enc_data *input,
1347                krb5_data *output);
1348
1349 /**
1350  * Decrypt data in place supporting AEAD (operates on opaque key).
1351  *
1352  * @param [in]     context         Library context
1353  * @param [in]     key             Encryption key
1354  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1355  * @param [in]     cipher_state    Cipher state; specify NULL if not needed
1356  * @param [in,out] data            IOV array. Modified in-place.
1357  * @param [in]     num_data        Size of @a data
1358  *
1359  * This function decrypts the data block @a data and stores the output in-place.
1360  * The actual decryption key will be derived from @a key and @a usage
1361  * if key derivation is specified for the encryption type.  If non-null, @a
1362  * cipher_state specifies the beginning state for the decryption operation, and
1363  * is updated with the state to be passed as input to the next operation.
1364  * The caller must allocate the right number of krb5_crypto_iov
1365  * structures before calling into this API.
1366  *
1367  * @note On return from a krb5_c_decrypt_iov() call, the @a data->length in the
1368  * iov structure are adjusted to reflect actual lengths of the ciphertext used.
1369  * For example, if the padding length is too large, the length will be reduced.
1370  * Lengths are never increased.
1371  *
1372  * @note This function is similar to krb5_c_decrypt_iov(), but operates
1373  * on opaque key @a key.
1374  *
1375  * @sa krb5_k_encrypt_iov()
1376  *
1377  * @retval 0 Success; otherwise - Kerberos error codes
1378  */
1379 krb5_error_code KRB5_CALLCONV
1380 krb5_k_decrypt_iov(krb5_context context, krb5_key key, krb5_keyusage usage,
1381                    const krb5_data *cipher_state, krb5_crypto_iov *data,
1382                    size_t num_data);
1383 /**
1384  * Compute a checksum (operates on opaque key).
1385  *
1386  * @param [in]  context         Library context
1387  * @param [in]  cksumtype       Checksum type (0 for mandatory type)
1388  * @param [in]  key             Encryption key for a keyed checksum
1389  * @param [in]  usage           Key usage (see @ref KRB5_KEYUSAGE types)
1390  * @param [in]  input           Input data
1391  * @param [out] cksum           Generated checksum
1392  *
1393  * This function computes a checksum of type @a cksumtype over @a input, using
1394  * @a key if the checksum type is a keyed checksum.  If @a cksumtype is 0 and
1395  * @a key is non-null, the checksum type will be the mandatory-to-implement
1396  * checksum type for the key's encryption type.  The actual checksum key will
1397  * be derived from @a key and @a usage if key derivation is specified for the
1398  * checksum type.  The newly created @a cksum must be released by calling
1399  * krb5_free_checksum_contents() when it is no longer needed.
1400  *
1401  * @note This function is similar to krb5_c_make_checksum(), but operates
1402  * on opaque @a key.
1403  *
1404  * @sa krb5_c_verify_checksum()
1405  *
1406  * @retval 0 Success; otherwise - Kerberos error codes
1407  */
1408 krb5_error_code KRB5_CALLCONV
1409 krb5_k_make_checksum(krb5_context context, krb5_cksumtype cksumtype,
1410                      krb5_key key, krb5_keyusage usage, const krb5_data *input,
1411                      krb5_checksum *cksum);
1412
1413 /**
1414  * Fill in a checksum element in IOV array (operates on opaque key)
1415  *
1416  * @param [in]     context         Library context
1417  * @param [in]     cksumtype       Checksum type (0 for mandatory type)
1418  * @param [in]     key             Encryption key for a keyed checksum
1419  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1420  * @param [in,out] data            IOV array
1421  * @param [in]     num_data        Size of @a data
1422  *
1423  * Create a checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element over
1424  * #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY chunks in @a data.
1425  * Only the #KRB5_CRYPTO_TYPE_CHECKSUM region is modified.
1426  *
1427  * @note This function is similar to krb5_c_make_checksum_iov(), but operates
1428  * on opaque @a key.
1429  *
1430  * @sa krb5_k_verify_checksum_iov()
1431  *
1432  * @retval 0 Success; otherwise - Kerberos error codes
1433  */
1434 krb5_error_code KRB5_CALLCONV
1435 krb5_k_make_checksum_iov(krb5_context context, krb5_cksumtype cksumtype,
1436                          krb5_key key, krb5_keyusage usage,
1437                          krb5_crypto_iov *data, size_t num_data);
1438
1439 /**
1440  * Verify a checksum (operates on opaque key).
1441  *
1442  * @param [in]  context         Library context
1443  * @param [in]  key             Encryption key for a keyed checksum
1444  * @param [in]  usage           @a key usage
1445  * @param [in]  data            Data to be used to compute a new checksum
1446  *                              using @a key to compare @a cksum against
1447  * @param [in]  cksum           Checksum to be verified
1448  * @param [out] valid           Non-zero for success, zero for failure
1449  *
1450  * This function verifies that @a cksum is a valid checksum for @a data.  If
1451  * the checksum type of @a cksum is a keyed checksum, @a key is used to verify
1452  * the checksum.  The actual checksum key will be derived from @a key and @a
1453  * usage if key derivation is specified for the checksum type.
1454  *
1455  * @note This function is similar to krb5_c_verify_checksum(), but operates
1456  * on opaque @a key.
1457  *
1458  * @retval 0 Success; otherwise - Kerberos error codes
1459  */
1460 krb5_error_code KRB5_CALLCONV
1461 krb5_k_verify_checksum(krb5_context context, krb5_key key, krb5_keyusage usage,
1462                        const krb5_data *data, const krb5_checksum *cksum,
1463                        krb5_boolean *valid);
1464
1465 /**
1466  * Validate a checksum element in IOV array (operates on opaque key).
1467  *
1468  * @param [in]     context         Library context
1469  * @param [in]     cksumtype       Checksum type (0 for mandatory type)
1470  * @param [in]     key             Encryption key for a keyed checksum
1471  * @param [in]     usage           Key usage (see @ref KRB5_KEYUSAGE types)
1472  * @param [in]     data            IOV array
1473  * @param [in]     num_data        Size of @a data
1474  * @param [out]    valid           Non-zero for success, zero for failure
1475  *
1476  * Confirm that the checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element is a
1477  * valid checksum of the #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY
1478  * regions in the iov.
1479  *
1480  * @note This function is similar to krb5_c_verify_checksum_iov(), but operates
1481  * on opaque @a key.
1482  *
1483  * @sa krb5_k_make_checksum_iov()
1484  *
1485  * @retval 0 Success; otherwise - Kerberos error codes
1486  */
1487 krb5_error_code KRB5_CALLCONV
1488 krb5_k_verify_checksum_iov(krb5_context context, krb5_cksumtype cksumtype,
1489                            krb5_key key, krb5_keyusage usage,
1490                            const krb5_crypto_iov *data, size_t num_data,
1491                            krb5_boolean *valid);
1492
1493 /**
1494  * Generate enctype-specific pseudo-random bytes (operates on opaque key).
1495  *
1496  * @param [in]  context      Library context
1497  * @param [in]  key          Key
1498  * @param [in]  input        Input data
1499  * @param [out] output       Output data
1500  *
1501  * This function selects a pseudo-random function based on @a key and
1502  * computes its value over @a input, placing the result into @a output.
1503  * The caller must preinitialize @a output and allocate space for the
1504  * result.
1505  *
1506  * @note This function is similar to krb5_c_prf(), but operates
1507  * on opaque @a key.
1508  *
1509  * @retval 0 Success; otherwise - Kerberos error codes
1510  */
1511 krb5_error_code KRB5_CALLCONV
1512 krb5_k_prf(krb5_context context, krb5_key key, krb5_data *input, krb5_data *output);
1513
1514 #ifdef KRB5_OLD_CRYPTO
1515 /*
1516  * old cryptosystem routine prototypes.  These are now layered
1517  * on top of the functions above.
1518  */
1519 /** @deprecated Replaced by krb5_c_ API family.*/
1520 krb5_error_code KRB5_CALLCONV
1521 krb5_encrypt(krb5_context context, krb5_const_pointer inptr,
1522              krb5_pointer outptr, size_t size, krb5_encrypt_block *eblock,
1523              krb5_pointer ivec);
1524
1525 /** @deprecated Replaced by krb5_c_ API family. */
1526 krb5_error_code KRB5_CALLCONV
1527 krb5_decrypt(krb5_context context, krb5_const_pointer inptr,
1528              krb5_pointer outptr, size_t size, krb5_encrypt_block *eblock,
1529              krb5_pointer ivec);
1530
1531 /** @deprecated Replaced by krb5_c_ API family. */
1532 krb5_error_code KRB5_CALLCONV
1533 krb5_process_key(krb5_context context, krb5_encrypt_block *eblock,
1534                  const krb5_keyblock * key);
1535
1536 /** @deprecated Replaced by krb5_c_ API family. */
1537 krb5_error_code KRB5_CALLCONV
1538 krb5_finish_key(krb5_context context, krb5_encrypt_block * eblock);
1539
1540 /** @deprecated See krb5_c_string_to_key() */
1541 krb5_error_code KRB5_CALLCONV
1542 krb5_string_to_key(krb5_context context, const krb5_encrypt_block *eblock,
1543                    krb5_keyblock * keyblock, const krb5_data *data,
1544                    const krb5_data *salt);
1545
1546 /** @deprecated Replaced by krb5_c_ API family. */
1547 krb5_error_code KRB5_CALLCONV
1548 krb5_init_random_key(krb5_context context, const krb5_encrypt_block *eblock,
1549                      const krb5_keyblock *keyblock, krb5_pointer *ptr);
1550
1551 /** @deprecated Replaced by krb5_c_ API family. */
1552 krb5_error_code KRB5_CALLCONV
1553 krb5_finish_random_key(krb5_context context, const krb5_encrypt_block *eblock,
1554                        krb5_pointer *ptr);
1555
1556 /** @deprecated Replaced by krb5_c_ API family. */
1557 krb5_error_code KRB5_CALLCONV
1558 krb5_random_key(krb5_context context, const krb5_encrypt_block *eblock,
1559                 krb5_pointer ptr, krb5_keyblock **keyblock);
1560
1561 /** @deprecated Replaced by krb5_c_ API family. */
1562 krb5_enctype KRB5_CALLCONV
1563 krb5_eblock_enctype(krb5_context context, const krb5_encrypt_block *eblock);
1564
1565 /** @deprecated Replaced by krb5_c_ API family. */
1566 krb5_error_code KRB5_CALLCONV
1567 krb5_use_enctype(krb5_context context, krb5_encrypt_block *eblock,
1568                  krb5_enctype enctype);
1569
1570 /** @deprecated Replaced by krb5_c_ API family. */
1571 size_t KRB5_CALLCONV
1572 krb5_encrypt_size(size_t length, krb5_enctype crypto);
1573
1574 /** @deprecated See krb5_c_checksum_length() */
1575 size_t KRB5_CALLCONV
1576 krb5_checksum_size(krb5_context context, krb5_cksumtype ctype);
1577
1578 /** @deprecated See krb5_c_make_checksum() */
1579 krb5_error_code KRB5_CALLCONV
1580 krb5_calculate_checksum(krb5_context context, krb5_cksumtype ctype,
1581                         krb5_const_pointer in, size_t in_length,
1582                         krb5_const_pointer seed, size_t seed_length,
1583                         krb5_checksum * outcksum);
1584
1585 /** @deprecated See krb5_c_verify_checksum() */
1586 krb5_error_code KRB5_CALLCONV
1587 krb5_verify_checksum(krb5_context context, krb5_cksumtype ctype,
1588                      const krb5_checksum * cksum, krb5_const_pointer in,
1589                      size_t in_length, krb5_const_pointer seed,
1590                      size_t seed_length);
1591
1592 #endif /* KRB5_OLD_CRYPTO */
1593
1594 /*
1595  * end "encryption.h"
1596  */
1597
1598 /*
1599  * begin "fieldbits.h"
1600  */
1601
1602 /* kdc_options for kdc_request */
1603 /* options is 32 bits; each host is responsible to put the 4 bytes
1604    representing these bits into net order before transmission */
1605 /* #define      KDC_OPT_RESERVED        0x80000000 */
1606 #define KDC_OPT_FORWARDABLE             0x40000000
1607 #define KDC_OPT_FORWARDED               0x20000000
1608 #define KDC_OPT_PROXIABLE               0x10000000
1609 #define KDC_OPT_PROXY                   0x08000000
1610 #define KDC_OPT_ALLOW_POSTDATE          0x04000000
1611 #define KDC_OPT_POSTDATED               0x02000000
1612 /* #define      KDC_OPT_UNUSED          0x01000000 */
1613 #define KDC_OPT_RENEWABLE               0x00800000
1614 /* #define      KDC_OPT_UNUSED          0x00400000 */
1615 /* #define      KDC_OPT_RESERVED        0x00200000 */
1616 /* #define      KDC_OPT_RESERVED        0x00100000 */
1617 /* #define      KDC_OPT_RESERVED        0x00080000 */
1618 /* #define      KDC_OPT_RESERVED        0x00040000 */
1619 #define KDC_OPT_CNAME_IN_ADDL_TKT       0x00020000
1620 #define KDC_OPT_CANONICALIZE            0x00010000
1621 #define KDC_OPT_REQUEST_ANONYMOUS       0x00008000
1622 /* #define      KDC_OPT_RESERVED        0x00004000 */
1623 /* #define      KDC_OPT_RESERVED        0x00002000 */
1624 /* #define      KDC_OPT_RESERVED        0x00001000 */
1625 /* #define      KDC_OPT_RESERVED        0x00000800 */
1626 /* #define      KDC_OPT_RESERVED        0x00000400 */
1627 /* #define      KDC_OPT_RESERVED        0x00000200 */
1628 /* #define      KDC_OPT_RESERVED        0x00000100 */
1629 /* #define      KDC_OPT_RESERVED        0x00000080 */
1630 /* #define      KDC_OPT_RESERVED        0x00000040 */
1631 #define KDC_OPT_DISABLE_TRANSITED_CHECK 0x00000020
1632 #define KDC_OPT_RENEWABLE_OK            0x00000010
1633 #define KDC_OPT_ENC_TKT_IN_SKEY         0x00000008
1634 /* #define      KDC_OPT_UNUSED          0x00000004 */
1635 #define KDC_OPT_RENEW                   0x00000002
1636 #define KDC_OPT_VALIDATE                0x00000001
1637
1638 /*
1639  * Mask of ticket flags in the TGT which should be converted into KDC
1640  * options when using the TGT to get derivitive tickets.
1641  *
1642  *  New mask = KDC_OPT_FORWARDABLE | KDC_OPT_PROXIABLE |
1643  *             KDC_OPT_ALLOW_POSTDATE | KDC_OPT_RENEWABLE
1644  */
1645 #define KDC_TKT_COMMON_MASK             0x54800000
1646
1647 /* definitions for ap_options fields */
1648
1649 /** @defgroup AP_OPTS AP_OPTS
1650  *
1651  * ap_options are 32 bits; each host is responsible to put the 4 bytes
1652  * representing these bits into net order before transmission
1653  * @{
1654  */
1655 #define AP_OPTS_RESERVED           0x80000000
1656 #define AP_OPTS_USE_SESSION_KEY    0x40000000 /**< Use session key */
1657 #define AP_OPTS_MUTUAL_REQUIRED    0x20000000 /**< Perform a mutual
1658                                                    authentication exchange */
1659 #define AP_OPTS_ETYPE_NEGOTIATION  0x00000002
1660 #define AP_OPTS_USE_SUBKEY         0x00000001 /**< Generate a subsession key
1661                                                    from the current session key
1662                                                    obtained from the
1663                                                    credentials */
1664 /* #define      AP_OPTS_RESERVED        0x10000000 */
1665 /* #define      AP_OPTS_RESERVED        0x08000000 */
1666 /* #define      AP_OPTS_RESERVED        0x04000000 */
1667 /* #define      AP_OPTS_RESERVED        0x02000000 */
1668 /* #define      AP_OPTS_RESERVED        0x01000000 */
1669 /* #define      AP_OPTS_RESERVED        0x00800000 */
1670 /* #define      AP_OPTS_RESERVED        0x00400000 */
1671 /* #define      AP_OPTS_RESERVED        0x00200000 */
1672 /* #define      AP_OPTS_RESERVED        0x00100000 */
1673 /* #define      AP_OPTS_RESERVED        0x00080000 */
1674 /* #define      AP_OPTS_RESERVED        0x00040000 */
1675 /* #define      AP_OPTS_RESERVED        0x00020000 */
1676 /* #define      AP_OPTS_RESERVED        0x00010000 */
1677 /* #define      AP_OPTS_RESERVED        0x00008000 */
1678 /* #define      AP_OPTS_RESERVED        0x00004000 */
1679 /* #define      AP_OPTS_RESERVED        0x00002000 */
1680 /* #define      AP_OPTS_RESERVED        0x00001000 */
1681 /* #define      AP_OPTS_RESERVED        0x00000800 */
1682 /* #define      AP_OPTS_RESERVED        0x00000400 */
1683 /* #define      AP_OPTS_RESERVED        0x00000200 */
1684 /* #define      AP_OPTS_RESERVED        0x00000100 */
1685 /* #define      AP_OPTS_RESERVED        0x00000080 */
1686 /* #define      AP_OPTS_RESERVED        0x00000040 */
1687 /* #define      AP_OPTS_RESERVED        0x00000020 */
1688 /* #define      AP_OPTS_RESERVED        0x00000010 */
1689 /* #define      AP_OPTS_RESERVED        0x00000008 */
1690 /* #define      AP_OPTS_RESERVED        0x00000004 */
1691
1692
1693 #define AP_OPTS_WIRE_MASK               0xfffffff0
1694 /** @} */ /* end of AP_OPTS group */
1695
1696 /* definitions for ad_type fields. */
1697 #define AD_TYPE_RESERVED        0x8000
1698 #define AD_TYPE_EXTERNAL        0x4000
1699 #define AD_TYPE_REGISTERED      0x2000
1700
1701 #define AD_TYPE_FIELD_TYPE_MASK 0x1fff
1702
1703 /* Ticket flags */
1704 /* flags are 32 bits; each host is responsible to put the 4 bytes
1705    representing these bits into net order before transmission */
1706 /* #define      TKT_FLG_RESERVED        0x80000000 */
1707 #define TKT_FLG_FORWARDABLE             0x40000000
1708 #define TKT_FLG_FORWARDED               0x20000000
1709 #define TKT_FLG_PROXIABLE               0x10000000
1710 #define TKT_FLG_PROXY                   0x08000000
1711 #define TKT_FLG_MAY_POSTDATE            0x04000000
1712 #define TKT_FLG_POSTDATED               0x02000000
1713 #define TKT_FLG_INVALID                 0x01000000
1714 #define TKT_FLG_RENEWABLE               0x00800000
1715 #define TKT_FLG_INITIAL                 0x00400000
1716 #define TKT_FLG_PRE_AUTH                0x00200000
1717 #define TKT_FLG_HW_AUTH                 0x00100000
1718 #define TKT_FLG_TRANSIT_POLICY_CHECKED  0x00080000
1719 #define TKT_FLG_OK_AS_DELEGATE          0x00040000
1720 #define TKT_FLG_ENC_PA_REP              0x00010000
1721 #define TKT_FLG_ANONYMOUS               0x00008000
1722 /* #define      TKT_FLG_RESERVED        0x00004000 */
1723 /* #define      TKT_FLG_RESERVED        0x00002000 */
1724 /* #define      TKT_FLG_RESERVED        0x00001000 */
1725 /* #define      TKT_FLG_RESERVED        0x00000800 */
1726 /* #define      TKT_FLG_RESERVED        0x00000400 */
1727 /* #define      TKT_FLG_RESERVED        0x00000200 */
1728 /* #define      TKT_FLG_RESERVED        0x00000100 */
1729 /* #define      TKT_FLG_RESERVED        0x00000080 */
1730 /* #define      TKT_FLG_RESERVED        0x00000040 */
1731 /* #define      TKT_FLG_RESERVED        0x00000020 */
1732 /* #define      TKT_FLG_RESERVED        0x00000010 */
1733 /* #define      TKT_FLG_RESERVED        0x00000008 */
1734 /* #define      TKT_FLG_RESERVED        0x00000004 */
1735 /* #define      TKT_FLG_RESERVED        0x00000002 */
1736 /* #define      TKT_FLG_RESERVED        0x00000001 */
1737
1738 /* definitions for lr_type fields. */
1739 #define LR_TYPE_THIS_SERVER_ONLY        0x8000
1740
1741 #define LR_TYPE_INTERPRETATION_MASK     0x7fff
1742
1743 /* definitions for msec direction bit for KRB_SAFE, KRB_PRIV */
1744 #define MSEC_DIRBIT             0x8000
1745 #define MSEC_VAL_MASK           0x7fff
1746
1747 /*
1748  * end "fieldbits.h"
1749  */
1750
1751 /*
1752  * begin "proto.h"
1753  */
1754
1755 /** Protocol version number */
1756 #define KRB5_PVNO       5
1757
1758 /* Message types */
1759
1760 #define KRB5_AS_REQ   ((krb5_msgtype)10) /**< Initial authentication request */
1761 #define KRB5_AS_REP   ((krb5_msgtype)11) /**< Response to AS request */
1762 #define KRB5_TGS_REQ  ((krb5_msgtype)12) /**< Ticket granting server request */
1763 #define KRB5_TGS_REP  ((krb5_msgtype)13) /**< Response to TGS request */
1764 #define KRB5_AP_REQ   ((krb5_msgtype)14) /**< Auth req to application server */
1765 #define KRB5_AP_REP   ((krb5_msgtype)15) /**< Response to mutual AP request */
1766 #define KRB5_SAFE     ((krb5_msgtype)20) /**< Safe application message */
1767 #define KRB5_PRIV     ((krb5_msgtype)21) /**< Private application message */
1768 #define KRB5_CRED     ((krb5_msgtype)22) /**< Cred forwarding message */
1769 #define KRB5_ERROR    ((krb5_msgtype)30) /**< Error response */
1770
1771 /* LastReq types */
1772 #define KRB5_LRQ_NONE                   0
1773 #define KRB5_LRQ_ALL_LAST_TGT           1
1774 #define KRB5_LRQ_ONE_LAST_TGT           (-1)
1775 #define KRB5_LRQ_ALL_LAST_INITIAL       2
1776 #define KRB5_LRQ_ONE_LAST_INITIAL       (-2)
1777 #define KRB5_LRQ_ALL_LAST_TGT_ISSUED    3
1778 #define KRB5_LRQ_ONE_LAST_TGT_ISSUED    (-3)
1779 #define KRB5_LRQ_ALL_LAST_RENEWAL       4
1780 #define KRB5_LRQ_ONE_LAST_RENEWAL       (-4)
1781 #define KRB5_LRQ_ALL_LAST_REQ           5
1782 #define KRB5_LRQ_ONE_LAST_REQ           (-5)
1783 #define KRB5_LRQ_ALL_PW_EXPTIME         6
1784 #define KRB5_LRQ_ONE_PW_EXPTIME         (-6)
1785 #define KRB5_LRQ_ALL_ACCT_EXPTIME       7
1786 #define KRB5_LRQ_ONE_ACCT_EXPTIME       (-7)
1787
1788 /* PADATA types */
1789 #define KRB5_PADATA_NONE                0
1790 #define KRB5_PADATA_AP_REQ              1
1791 #define KRB5_PADATA_TGS_REQ             KRB5_PADATA_AP_REQ
1792 #define KRB5_PADATA_ENC_TIMESTAMP       2
1793 #define KRB5_PADATA_PW_SALT             3
1794 #if 0                           /* Not used */
1795 #define KRB5_PADATA_ENC_ENCKEY          4  /* Key encrypted within itself */
1796 #endif
1797 #define KRB5_PADATA_ENC_UNIX_TIME       5  /**< timestamp encrypted in key */
1798 #define KRB5_PADATA_ENC_SANDIA_SECURID  6  /**< SecurId passcode */
1799 #define KRB5_PADATA_SESAME              7  /**< Sesame project */
1800 #define KRB5_PADATA_OSF_DCE             8  /**< OSF DCE */
1801 #define KRB5_CYBERSAFE_SECUREID         9  /**< Cybersafe */
1802 #define KRB5_PADATA_AFS3_SALT           10 /**< Cygnus */
1803 #define KRB5_PADATA_ETYPE_INFO          11 /**< Etype info for preauth */
1804 #define KRB5_PADATA_SAM_CHALLENGE       12 /**< draft challenge system */
1805 #define KRB5_PADATA_SAM_RESPONSE        13 /**< draft challenge system response */
1806 #define KRB5_PADATA_PK_AS_REQ_OLD       14 /**< PKINIT */
1807 #define KRB5_PADATA_PK_AS_REP_OLD       15 /**< PKINIT */
1808 #define KRB5_PADATA_PK_AS_REQ           16 /**< PKINIT */
1809 #define KRB5_PADATA_PK_AS_REP           17 /**< PKINIT */
1810 #define KRB5_PADATA_ETYPE_INFO2         19
1811 #define KRB5_PADATA_USE_SPECIFIED_KVNO  20
1812 #define KRB5_PADATA_SVR_REFERRAL_INFO   20 /**< Windows 2000 referrals */
1813 #define KRB5_PADATA_SAM_REDIRECT        21
1814 #define KRB5_PADATA_GET_FROM_TYPED_DATA 22
1815 #define KRB5_PADATA_REFERRAL            25 /**< draft referral system */
1816 #define KRB5_PADATA_SAM_CHALLENGE_2     30 /**< draft challenge system, updated */
1817 #define KRB5_PADATA_SAM_RESPONSE_2      31 /**< draft challenge system, updated */
1818 #define KRB5_PADATA_PAC_REQUEST         128 /**< include Windows PAC */
1819 #define KRB5_PADATA_FOR_USER            129 /**< username protocol transition request */
1820 #define KRB5_PADATA_S4U_X509_USER       130 /**< certificate protocol transition request */
1821 #define KRB5_PADATA_FX_COOKIE           133
1822 #define KRB5_PADATA_FX_FAST             136
1823 #define KRB5_PADATA_FX_ERROR            137
1824 #define KRB5_PADATA_ENCRYPTED_CHALLENGE 138
1825 #define KRB5_PADATA_PKINIT_KX 147
1826 #define KRB5_ENCPADATA_REQ_ENC_PA_REP 149
1827
1828 #define KRB5_SAM_USE_SAD_AS_KEY         0x80000000
1829 #define KRB5_SAM_SEND_ENCRYPTED_SAD     0x40000000
1830 #define KRB5_SAM_MUST_PK_ENCRYPT_SAD    0x20000000 /* currently must be zero */
1831
1832 /** Transited encoding types */
1833 #define KRB5_DOMAIN_X500_COMPRESS               1
1834
1835 /** alternate authentication types */
1836 #define KRB5_ALTAUTH_ATT_CHALLENGE_RESPONSE     64
1837
1838 /* authorization data types. See RFC 4120 section 5.2.6 */
1839
1840 /** @defgroup KRB5_AUTHDATA KRB5_AUTHDATA
1841  * @{
1842  */
1843 #define KRB5_AUTHDATA_IF_RELEVANT   1
1844 #define KRB5_AUTHDATA_KDC_ISSUED    4
1845 #define KRB5_AUTHDATA_AND_OR        5
1846 #define KRB5_AUTHDATA_MANDATORY_FOR_KDC 8
1847 #define KRB5_AUTHDATA_INITIAL_VERIFIED_CAS      9
1848 #define KRB5_AUTHDATA_OSF_DCE   64
1849 #define KRB5_AUTHDATA_SESAME    65
1850 #define KRB5_AUTHDATA_WIN2K_PAC 128
1851 #define KRB5_AUTHDATA_ETYPE_NEGOTIATION 129     /* RFC 4537 */
1852 #define KRB5_AUTHDATA_SIGNTICKET        512     /**< formerly 142 in krb5 1.8 */
1853 #define KRB5_AUTHDATA_FX_ARMOR 71
1854 /** @} */ /* end of KRB5_AUTHDATA group */
1855
1856 /* password change constants */
1857 #define KRB5_KPASSWD_SUCCESS            0
1858 #define KRB5_KPASSWD_MALFORMED          1
1859 #define KRB5_KPASSWD_HARDERROR          2
1860 #define KRB5_KPASSWD_AUTHERROR          3
1861 #define KRB5_KPASSWD_SOFTERROR          4
1862 /* These are Microsoft's extensions in RFC 3244, and it looks like
1863    they'll become standardized, possibly with other additions.  */
1864 #define KRB5_KPASSWD_ACCESSDENIED       5       /* unused */
1865 #define KRB5_KPASSWD_BAD_VERSION        6
1866 #define KRB5_KPASSWD_INITIAL_FLAG_NEEDED 7      /* unused */
1867
1868 /*
1869  * end "proto.h"
1870  */
1871
1872 /* Time set */
1873 /** Ticket start time, end time, and renewal duration. */
1874 typedef struct _krb5_ticket_times {
1875     krb5_timestamp authtime;    /**< Time at which KDC issued the initial ticket that corresponds to this ticket */
1876                                   /* XXX ? should ktime in KDC_REP == authtime
1877                                   in ticket? otherwise client can't get this */
1878     krb5_timestamp starttime;   /**< optional in ticket, if not present, use @a authtime */
1879     krb5_timestamp endtime;     /**< Ticket expiration time */
1880     krb5_timestamp renew_till;  /**< Latest time at which renewal of ticket can be valid */
1881 } krb5_ticket_times;
1882
1883 /** Structure for auth data */
1884 typedef struct _krb5_authdata {
1885     krb5_magic magic;
1886     krb5_authdatatype ad_type; /**< ADTYPE */
1887     unsigned int length;       /**< Length of data  */
1888     krb5_octet *contents;      /**< Data */
1889 } krb5_authdata;
1890
1891 /** Structure for transited encoding */
1892 typedef struct _krb5_transited {
1893     krb5_magic magic;
1894     krb5_octet tr_type;     /**< Transited encoding type */
1895     krb5_data tr_contents;  /**< Contents */
1896 } krb5_transited;
1897
1898  /** Encrypted part of ticket. */
1899 typedef struct _krb5_enc_tkt_part {
1900     krb5_magic magic;
1901     /* to-be-encrypted portion */
1902     krb5_flags flags;                   /**< flags */
1903     krb5_keyblock *session;             /**< session key: includes enctype */
1904     krb5_principal client;              /**< client name/realm */
1905     krb5_transited transited;           /**< list of transited realms */
1906     krb5_ticket_times times;            /**< auth, start, end, renew_till */
1907     krb5_address **caddrs;              /**< array of ptrs to addresses */
1908     krb5_authdata **authorization_data; /**< auth data */
1909 } krb5_enc_tkt_part;
1910
1911 /**
1912  * Ticket structure.
1913  *
1914  * The C representation of the ticket message, with a pointer to the
1915  * C representation of the encrypted part.
1916  */
1917 typedef struct _krb5_ticket {
1918     krb5_magic magic;
1919     /* cleartext portion */
1920     krb5_principal server;              /**< server name/realm */
1921     krb5_enc_data enc_part;             /**< encryption type, kvno, encrypted encoding */
1922     krb5_enc_tkt_part *enc_part2;       /**< ptr to decrypted version, if available */
1923 } krb5_ticket;
1924
1925 /* the unencrypted version */
1926 /**
1927  * Ticket authenticator.
1928  *
1929  * The C representation of an unencrypted authenticator.
1930  */
1931 typedef struct _krb5_authenticator {
1932     krb5_magic magic;
1933     krb5_principal client;              /**< client name/realm */
1934     krb5_checksum *checksum;            /**< checksum, includes type, optional */
1935     krb5_int32 cusec;                   /**< client usec portion */
1936     krb5_timestamp ctime;               /**< client sec portion */
1937     krb5_keyblock *subkey;              /**< true session key, optional */
1938     krb5_ui_4 seq_number;               /**< sequence #, optional */
1939     krb5_authdata **authorization_data; /**< authoriazation data */
1940 } krb5_authenticator;
1941
1942 /** Ticket authentication data. */
1943 typedef struct _krb5_tkt_authent {
1944     krb5_magic magic;
1945     krb5_ticket *ticket;
1946     krb5_authenticator *authenticator;
1947     krb5_flags ap_options;
1948 } krb5_tkt_authent;
1949
1950 /** Credentials structure including ticket, session key, and lifetime info. */
1951 typedef struct _krb5_creds {
1952     krb5_magic magic;
1953     krb5_principal client;              /**< client's principal identifier */
1954     krb5_principal server;              /**< server's principal identifier */
1955     krb5_keyblock keyblock;             /**< session encryption key info */
1956     krb5_ticket_times times;            /**< lifetime info */
1957     krb5_boolean is_skey;               /**< true if ticket is encrypted in
1958                                            another ticket's skey */
1959     krb5_flags ticket_flags;            /**< flags in ticket */
1960     krb5_address **addresses;           /**< addrs in ticket */
1961     krb5_data ticket;                   /**< ticket string itself */
1962     krb5_data second_ticket;            /**< second ticket, if related to
1963                                            ticket (via DUPLICATE-SKEY or
1964                                            ENC-TKT-IN-SKEY) */
1965     krb5_authdata **authdata;           /**< authorization data */
1966 } krb5_creds;
1967
1968 /** Last request entry */
1969 typedef struct _krb5_last_req_entry {
1970     krb5_magic magic;
1971     krb5_int32 lr_type;         /**< LR type */
1972     krb5_timestamp value;       /**< Timestamp */
1973 } krb5_last_req_entry;
1974
1975 /** Pre-authentication data */
1976 typedef struct _krb5_pa_data {
1977     krb5_magic magic;
1978     krb5_preauthtype pa_type;   /**< Preauthentication data type */
1979     unsigned int length;        /**< Length of data */
1980     krb5_octet *contents;       /**< Data */
1981 } krb5_pa_data;
1982
1983 /*
1984  * The FAST error handling logic currently assumes that pointers to this
1985  * structure and krb5_pa_data can be safely cast to each other.  If this
1986  * structure changes, that code needs to be updated to copy.
1987  */
1988 /** Typed data */
1989 typedef struct _krb5_typed_data {
1990     krb5_magic magic;
1991     krb5_int32 type;
1992     unsigned int length;
1993     krb5_octet *data;
1994 } krb5_typed_data;
1995
1996 /** C representation of KDC-REQ protocol message, including KDC-REQ-BODY */
1997 typedef struct _krb5_kdc_req {
1998     krb5_magic magic;
1999     krb5_msgtype msg_type;      /**< KRB5_AS_REQ or KRB5_TGS_REQ */
2000     krb5_pa_data **padata;      /**< Preauthentication data */
2001     /* real body */
2002     krb5_flags kdc_options;     /**< Requested options */
2003     krb5_principal client;      /**< Client principal and realm */
2004     krb5_principal server;      /**< Server principal and realm */
2005     krb5_timestamp from;        /**< Requested start time */
2006     krb5_timestamp till;        /**< Requested end time */
2007     krb5_timestamp rtime;       /**< Requested renewable end time */
2008     krb5_int32 nonce;           /**< Nonce to match request andresponse */
2009     int nktypes;                /**< Number of enctypes */
2010     krb5_enctype *ktype;        /**< Requested enctypes */
2011     krb5_address **addresses;   /**< Requested addresses (optional) */
2012     krb5_enc_data authorization_data;  /**< Encrypted authz data (optional) */
2013     krb5_authdata **unenc_authdata;    /**< Unencrypted authz data */
2014     krb5_ticket **second_ticket;       /**< Second ticket array (optional) */
2015 } krb5_kdc_req;
2016
2017 /**
2018  * C representation of @c EncKDCRepPart protocol message.
2019  *
2020  * This is the cleartext message that is encrypted and inserted in @c KDC-REP.
2021  */
2022 typedef struct _krb5_enc_kdc_rep_part {
2023     krb5_magic magic;
2024     /* encrypted part: */
2025     krb5_msgtype msg_type;           /**< krb5 message type */
2026     krb5_keyblock *session;          /**< Session key */
2027     krb5_last_req_entry **last_req;  /**< Array of pointers to entries */
2028     krb5_int32 nonce;                /**< Nonce from request */
2029     krb5_timestamp key_exp;          /**< Expiration date */
2030     krb5_flags flags;                /**< Ticket flags */
2031     krb5_ticket_times times;         /**< Lifetime info */
2032     krb5_principal server;           /**< Server's principal identifier */
2033     krb5_address **caddrs;           /**< Array of ptrs to addrs, optional */
2034     krb5_pa_data **enc_padata;       /**< Encrypted preauthentication data */
2035 } krb5_enc_kdc_rep_part;
2036
2037 /** Representation of the @c KDC-REP protocol message. */
2038 typedef struct _krb5_kdc_rep {
2039     krb5_magic magic;
2040     /* cleartext part: */
2041     krb5_msgtype msg_type;            /**< KRB5_AS_REP or KRB5_KDC_REP */
2042     krb5_pa_data **padata;            /**< Preauthentication data from KDC */
2043     krb5_principal client;            /**< Client principal and realm */
2044     krb5_ticket *ticket;              /**< Ticket */
2045     krb5_enc_data enc_part;           /**< Encrypted part of reply */
2046     krb5_enc_kdc_rep_part *enc_part2; /**< Unencrypted version, if available */
2047 } krb5_kdc_rep;
2048
2049 /** Error message structure */
2050 typedef struct _krb5_error {
2051     krb5_magic magic;
2052     /* some of these may be meaningless in certain contexts */
2053     krb5_timestamp ctime;       /**< Client sec portion; optional */
2054     krb5_int32 cusec;           /**< Client usec portion; optional */
2055     krb5_int32 susec;           /**< Server usec portion */
2056     krb5_timestamp stime;       /**< Server sec portion */
2057     krb5_ui_4 error;            /**< Error code (protocol error #'s) */
2058     krb5_principal client;      /**< Client principal and realm */
2059     krb5_principal server;      /**< Server principal and realm */
2060     krb5_data text;             /**< Descriptive text */
2061     krb5_data e_data;           /**< Additional error-describing data */
2062 } krb5_error;
2063
2064 /** Authentication header. */
2065 typedef struct _krb5_ap_req {
2066     krb5_magic magic;
2067     krb5_flags ap_options;        /**< Requested options */
2068     krb5_ticket *ticket;          /**< Ticket */
2069     krb5_enc_data authenticator;  /**< Encrypted authenticator */
2070 } krb5_ap_req;
2071
2072 /**
2073  * C representaton of AP-REP message.
2074  *
2075  * The server's response to a client's request for mutual authentication.
2076  */
2077 typedef struct _krb5_ap_rep {
2078     krb5_magic magic;
2079     krb5_enc_data enc_part;     /**< Ciphertext of ApRepEncPart */
2080 } krb5_ap_rep;
2081
2082 /** Cleartext that is encrypted and put into @c _krb5_ap_rep.  */
2083 typedef struct _krb5_ap_rep_enc_part {
2084     krb5_magic magic;
2085     krb5_timestamp ctime;       /**< Client time, seconds portion */
2086     krb5_int32 cusec;           /**< Client time, microseconds portion */
2087     krb5_keyblock *subkey;      /**< Subkey (optional) */
2088     krb5_ui_4 seq_number;       /**< Sequence number */
2089 } krb5_ap_rep_enc_part;
2090
2091 /* Unused */
2092 typedef struct _krb5_response {
2093     krb5_magic magic;
2094     krb5_octet message_type;
2095     krb5_data response;
2096     krb5_int32 expected_nonce;
2097     krb5_timestamp request_time;
2098 } krb5_response;
2099
2100 /** Credentials information inserted into @c EncKrbCredPart. */
2101 typedef struct _krb5_cred_info {
2102     krb5_magic magic;
2103     krb5_keyblock *session;     /**< Session key used to encrypt ticket */
2104     krb5_principal client;      /**< Client principal and realm */
2105     krb5_principal server;      /**< Server principal and realm */
2106     krb5_flags flags;           /**< Ticket flags */
2107     krb5_ticket_times times;    /**< Auth, start, end, renew_till */
2108     krb5_address **caddrs;      /**< Array of pointers to addrs (optional) */
2109 } krb5_cred_info;
2110
2111 /** Cleartext credentials information.  */
2112 typedef struct _krb5_cred_enc_part {
2113     krb5_magic magic;
2114     krb5_int32 nonce;           /**< Nonce (optional) */
2115     krb5_timestamp timestamp;   /**< Generation time, seconds portion */
2116     krb5_int32 usec;            /**< Generation time, microseconds portion */
2117     krb5_address *s_address;    /**< Sender address (optional) */
2118     krb5_address *r_address;    /**< Recipient address (optional) */
2119     krb5_cred_info **ticket_info;
2120 } krb5_cred_enc_part;
2121
2122 /** Credentials data structure.*/
2123 typedef struct _krb5_cred {
2124     krb5_magic magic;
2125     krb5_ticket **tickets;          /**< Tickets */
2126     krb5_enc_data enc_part;         /**< Encrypted part */
2127     krb5_cred_enc_part *enc_part2;  /**< Unencrypted version, if available */
2128 } krb5_cred;
2129
2130 /*
2131  * Sandia password generation structure
2132  * Used by internal functions only
2133  */
2134 typedef struct _passwd_phrase_element {
2135     krb5_magic magic;
2136     krb5_data *passwd;
2137     krb5_data *phrase;
2138 } passwd_phrase_element;
2139
2140 /*
2141  * Password data.
2142  * Used by internal functions only
2143  */
2144 typedef struct _krb5_pwd_data {
2145     krb5_magic magic;
2146     int sequence_count;
2147     passwd_phrase_element **element;
2148 } krb5_pwd_data;
2149
2150 /* these need to be here so the typedefs are available for the prototypes */
2151 /*
2152  * Note for Windows 2000 compatibility this is encoded
2153  * in the enc_padata field of the krb5_enc_kdc_rep_part.
2154  */
2155 typedef struct _krb5_pa_svr_referral_data {
2156     /** Referred name, only realm is required */
2157     krb5_principal     principal;
2158 } krb5_pa_svr_referral_data;
2159
2160 typedef struct _krb5_pa_server_referral_data {
2161     krb5_data          *referred_realm;
2162     krb5_principal     true_principal_name;
2163     krb5_principal     requested_principal_name;
2164     krb5_timestamp     referral_valid_until;
2165     krb5_checksum      rep_cksum;
2166 } krb5_pa_server_referral_data;
2167
2168 typedef struct _krb5_pa_pac_req {
2169     /** TRUE if a PAC should be included in TGS-REP */
2170     krb5_boolean       include_pac;
2171 } krb5_pa_pac_req;
2172
2173 /*
2174  * begin "safepriv.h"
2175  */
2176
2177 /** @defgroup KRB5_AUTH_CONTEXT KRB5_AUTH_CONTEXT
2178  * @{
2179  */
2180 #define KRB5_AUTH_CONTEXT_DO_TIME       0x00000001 /**< set timestamp in the message */
2181 #define KRB5_AUTH_CONTEXT_RET_TIME      0x00000002
2182 #define KRB5_AUTH_CONTEXT_DO_SEQUENCE   0x00000004 /**< set sequence number in the message */
2183 #define KRB5_AUTH_CONTEXT_RET_SEQUENCE  0x00000008
2184 #define KRB5_AUTH_CONTEXT_PERMIT_ALL    0x00000010
2185 #define KRB5_AUTH_CONTEXT_USE_SUBKEY    0x00000020
2186 /** @} */ /* end of KRB5_AUTH_CONTEXT group */
2187
2188 /**
2189  * Replay data.
2190  *
2191  * Sequence number and timestamp information output by krb5_rd_priv() and
2192  * krb5_rd_safe().
2193  */
2194 typedef struct krb5_replay_data {
2195     krb5_timestamp      timestamp;  /**< Timestamp, seconds portion */
2196     krb5_int32          usec;       /**< Timestamp, microseconds portion */
2197     krb5_ui_4           seq;        /**< Sequence number  */
2198 } krb5_replay_data;
2199
2200 /* Flags for krb5_auth_con_genaddrs(). */
2201
2202 /** Generate the local network address. */
2203 #define KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR       0x00000001
2204 /** Generate the remote network address.  */
2205 #define KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR      0x00000002
2206 /** Generate the local network address and the local port. */
2207 #define KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR  0x00000004
2208 /** Generate the remote network address and the remote port. */
2209 #define KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR 0x00000008
2210
2211 /** Type of function used as a callback to generate checksum data for mk_req */
2212 typedef krb5_error_code
2213 (KRB5_CALLCONV * krb5_mk_req_checksum_func)(krb5_context, krb5_auth_context,
2214                                             void *, krb5_data **);
2215
2216 /*
2217  * end "safepriv.h"
2218  */
2219
2220
2221 /*
2222  * begin "ccache.h"
2223  */
2224
2225 /** Cursor for sequential lookup */
2226 typedef krb5_pointer    krb5_cc_cursor;
2227
2228 struct _krb5_ccache;
2229 typedef struct _krb5_ccache *krb5_ccache;
2230 struct _krb5_cc_ops;
2231 typedef struct _krb5_cc_ops krb5_cc_ops;
2232
2233 struct _krb5_cccol_cursor;
2234 /** Cursor for iterating over all ccaches */
2235 typedef struct _krb5_cccol_cursor *krb5_cccol_cursor;
2236
2237 /* Flags for krb5_cc_retrieve_cred. */
2238 /** The requested lifetime must be at least as great as the time specified. */
2239 #define KRB5_TC_MATCH_TIMES        0x00000001
2240 /** The is_skey field must match exactly. */
2241 #define KRB5_TC_MATCH_IS_SKEY      0x00000002
2242 /** All the flags set in the match credentials must be set. */
2243 #define KRB5_TC_MATCH_FLAGS        0x00000004
2244 /** All the time fields must match exactly. */
2245 #define KRB5_TC_MATCH_TIMES_EXACT  0x00000008
2246 /** All the flags must match exactly. */
2247 #define KRB5_TC_MATCH_FLAGS_EXACT  0x00000010
2248 /** The authorization data must match. */
2249 #define KRB5_TC_MATCH_AUTHDATA     0x00000020
2250 /** Only the name portion of the principal name must match. */
2251 #define KRB5_TC_MATCH_SRV_NAMEONLY 0x00000040
2252 /** The second ticket must match. */
2253 #define KRB5_TC_MATCH_2ND_TKT      0x00000080
2254 /** The encryption key type must match. */
2255 #define KRB5_TC_MATCH_KTYPE        0x00000100
2256 /** The supported key types must match. */
2257 #define KRB5_TC_SUPPORTED_KTYPES   0x00000200
2258
2259 /* Flags for krb5_cc_set_flags and similar. */
2260 /** Open and close the file for each cache operation. */
2261 #define KRB5_TC_OPENCLOSE          0x00000001
2262 #define KRB5_TC_NOTICKET           0x00000002
2263
2264 /**
2265  * Retrieve the name, but not type of a credential cache.
2266  *
2267  * @param [in] context          Library context
2268  * @param [in] cache            Credential cache handle
2269  *
2270  * @warning Returns the name of the credential cache.  The result is an alias
2271  * into @a cache and should not be freed or modified by the caller.  This name
2272  * does not include the cache type, so should not be used as input to
2273  * krb5_cc_resolve().
2274  *
2275  * @return
2276  * On success - the name of the credential cache.
2277  */
2278 const char * KRB5_CALLCONV
2279 krb5_cc_get_name(krb5_context context, krb5_ccache cache);
2280
2281 /**
2282  * Retrieve the full name of a credential cache.
2283  *
2284  * @param [in]  context         Library context
2285  * @param [in]  cache           Credential cache handle
2286  * @param [out] fullname_out    Full name of cache
2287  *
2288  */
2289 krb5_error_code KRB5_CALLCONV
2290 krb5_cc_get_full_name(krb5_context context, krb5_ccache cache,
2291                       char **fullname_out);
2292
2293 #if KRB5_DEPRECATED
2294 krb5_error_code KRB5_CALLCONV
2295 krb5_cc_gen_new(krb5_context context, krb5_ccache *cache);
2296 #endif /* KRB5_DEPRECATED */
2297
2298 /**
2299  * Initialize a credential cache.
2300  *
2301  * @param [in] context          Library context
2302  * @param [in] cache            Credential cache handle
2303  * @param [in] principal        Default principal name
2304  *
2305  * Destroy any existing contents of @a cache and initialize it for the default
2306  * principal @a principal.
2307  *
2308  * @retval
2309  *  0  Success
2310  * @return
2311  *  System errors; Permission errors; Kerberos error codes
2312  */
2313 krb5_error_code KRB5_CALLCONV
2314 krb5_cc_initialize(krb5_context context, krb5_ccache cache,
2315                    krb5_principal principal);
2316
2317 /**
2318  * Destroy a credential cache.
2319  *
2320  * @param [in] context          Library context
2321  * @param [in] cache            Credential cache handle
2322  *
2323  * This function destroys any existing contents of @a cache and closes the
2324  * handle to it.
2325  *
2326  * @retval
2327  * 0  Success
2328  * @return
2329  * Permission errors
2330  */
2331 krb5_error_code KRB5_CALLCONV
2332 krb5_cc_destroy(krb5_context context, krb5_ccache cache);
2333
2334 /**
2335  * Close a credential cache handle.
2336  *
2337  * @param [in] context          Library context
2338  * @param [in] cache            Credential cache handle
2339  *
2340  * This function closes a credential cache handle @a cache without affecting
2341  * the contents of the cache.
2342  *
2343  * @retval
2344  * 0  Success
2345  * @return
2346  * Kerberos error codes
2347  */
2348 krb5_error_code KRB5_CALLCONV
2349 krb5_cc_close(krb5_context context, krb5_ccache cache);
2350
2351 /**
2352  * Store credentials in a credential cache.
2353  *
2354  * @param [in]     context      Library context
2355  * @param [in,out] cache        Credential cache handle
2356  * @param [in]     creds        Credentials to be stored in cache
2357  *
2358  * This function stores @a creds into @a cache.  If @a creds->server and the
2359  * server in the decoded ticket @a creds->ticket differ, the credentials will
2360  * be stored under both server principal names.
2361  *
2362  * @retval
2363  *  0  Success
2364  * @return Permission errors; storage failure errors; Kerberos error codes
2365  */
2366 krb5_error_code KRB5_CALLCONV
2367 krb5_cc_store_cred(krb5_context context, krb5_ccache cache, krb5_creds *creds);
2368
2369 /**
2370  * Retrieve a specified credentials from a credential cache.
2371  *
2372  * @param [in]  context         Library context
2373  * @param [in]  cache           Credential cache handle
2374  * @param [in]  flags           Flags bit mask
2375  * @param [in]  mcreds          Credentials to match
2376  * @param [out] creds           Credentials matching the requested value
2377  *
2378  * This function searches a credential cache for credentials matching @a mcreds
2379  * and returns it if found.
2380  *
2381  * Valid values for @a flags are:
2382  *
2383  * @li #KRB5_TC_MATCH_TIMES        The requested lifetime must be at least as
2384  *                                 great as in @a mcreds .
2385  * @li #KRB5_TC_MATCH_IS_SKEY      The @a is_skey field much match exactly.
2386  * @li #KRB5_TC_MATCH_FLAGS        Flags set in @a mcreds must be set.
2387  * @li #KRB5_TC_MATCH_TIMES_EXACT  The requested lifetime must match exactly.
2388  * @li #KRB5_TC_MATCH_FLAGS_EXACT  Flags must match exactly.
2389  * @li #KRB5_TC_MATCH_AUTHDATA     The authorization data must match.
2390  * @li #KRB5_TC_MATCH_SRV_NAMEONLY Only the name portion of the principal
2391  *                                 name must match, not the realm.
2392  * @li #KRB5_TC_MATCH_2ND_TKT      The second tickets must match.
2393  * @li #KRB5_TC_MATCH_KTYPE        The encryption key types must match.
2394  * @li #KRB5_TC_SUPPORTED_KTYPES   Check all matching entries that have any
2395  *                                 supported encryption type and return the
2396  *                                 one with the encryption type listed earliest.
2397  *
2398  * Use krb5_free_cred_contents() to free @a creds when it is no longer needed.
2399  *
2400  * @retval 0 Success; otherwise - Kerberos error codes
2401  */
2402 krb5_error_code KRB5_CALLCONV
2403 krb5_cc_retrieve_cred(krb5_context context, krb5_ccache cache,
2404                       krb5_flags flags, krb5_creds *mcreds,
2405                       krb5_creds *creds);
2406
2407 /**
2408  * Get the default principal of a credential cache.
2409  *
2410  * @param [in]  context         Library context
2411  * @param [in]  cache           Credential cache handle
2412  * @param [out] principal       Primary principal
2413  *
2414  * Returns the default client principal of a credential cache as set by
2415  * krb5_cc_initialize().
2416  *
2417  * Use krb5_free_principal() to free @a principal when it is no longer needed.
2418  *
2419  * @retval
2420  * 0  Success
2421  * @return
2422  * Kerberos error codes
2423  */
2424 krb5_error_code KRB5_CALLCONV
2425 krb5_cc_get_principal(krb5_context context, krb5_ccache cache,
2426                       krb5_principal *principal);
2427
2428 /**
2429  * Prepare to sequentially read every credential in a credential cache.
2430  *
2431  * @param [in]  context         Library context
2432  * @param [in]  cache           Credential cache handle
2433  * @param [out] cursor          Cursor
2434  *
2435  * krb5_cc_end_seq_get() must be called to complete the retrieve operation.
2436  *
2437  * @note If @a cache is modified between the time of the call to this function
2438  * and the time of the final krb5_cc_end_seq_get(), the results are undefined.
2439  *
2440  * @retval 0  Success; otherwise - Kerberos error codes
2441  */
2442 krb5_error_code KRB5_CALLCONV
2443 krb5_cc_start_seq_get(krb5_context context, krb5_ccache cache,
2444                       krb5_cc_cursor *cursor);
2445
2446 /**
2447  * Retrieve the next entry from the credential cache.
2448  *
2449  * @param [in]     context      Library context
2450  * @param [in]     cache        Credential cache handle
2451  * @param [in,out] cursor       Cursor
2452  * @param [out]    creds        Next credential cache entry
2453  *
2454  * This function fills in @a creds with the next entry in @a cache and advances
2455  * @a cursor.
2456  *
2457  * Use krb5_free_cred_contents() to free @a creds when it is no longer needed.
2458  *
2459  * @sa krb5_cc_start_seq_get(), krb5_end_seq_get()
2460  *
2461  * @retval 0 Success; otherwise - Kerberos error codes
2462  */
2463 krb5_error_code KRB5_CALLCONV
2464 krb5_cc_next_cred(krb5_context context, krb5_ccache cache,
2465                   krb5_cc_cursor *cursor, krb5_creds *creds);
2466
2467 /**
2468  * Finish a series of sequential processing credential cache entries.
2469  *
2470  * @param [in]     context      Library context
2471  * @param [in]     cache        Credential cache handle
2472  * @param [in,out] cursor       Cursor
2473  *
2474  * This function finishes processing credential cache entries and invalidates
2475  * @a cursor.
2476  *
2477  * @sa krb5_cc_start_seq_get(), krb5_cc_next_cred()
2478  *
2479  * @retval 0 (always)
2480  */
2481 krb5_error_code KRB5_CALLCONV
2482 krb5_cc_end_seq_get(krb5_context context, krb5_ccache cache,
2483                     krb5_cc_cursor *cursor);
2484
2485 /**
2486  * Remove credentials from a credential cache.
2487  *
2488  * @param [in] context          Library context
2489  * @param [in] cache            Credential cache handle
2490  * @param [in] flags            Bitwise-ORed search flags
2491  * @param [in] creds            Credentials to be matched
2492  *
2493  * @warning This function is not implemented for some cache types.
2494  *
2495  * This function accepts the same flag values as krb5_cc_retrieve_cred().
2496  *
2497  * @retval KRB5_CC_NOSUPP Not implemented for this cache type
2498  * @return No matches found; Data cannot be deleted; Kerberos error codes
2499  */
2500 krb5_error_code KRB5_CALLCONV
2501 krb5_cc_remove_cred(krb5_context context, krb5_ccache cache, krb5_flags flags,
2502                     krb5_creds *creds);
2503
2504 /**
2505  * Set options flags on a credential cache.
2506  *
2507  * @param [in]     context      Library context
2508  * @param [in,out] cache        Credential cache handle
2509  * @param [in]     flags        Flag bit mask
2510  *
2511  * This function resets @a cache flags to @a flags.
2512  *
2513  * @retval 0 Success; otherwise - Kerberos error codes
2514  */
2515 krb5_error_code KRB5_CALLCONV
2516 krb5_cc_set_flags(krb5_context context, krb5_ccache cache, krb5_flags flags);
2517
2518 /**
2519  * Retrieve flags from a credential cache structure.
2520  *
2521  * @param [in]  context         Library context
2522  * @param [in]  cache           Credential cache handle
2523  * @param [out] flags           Flag bit mask
2524  *
2525  * @warning For memory credential cache always returns a flag mask of 0.
2526  *
2527  * @retval 0 Success; otherwise - Kerberos error codes
2528  */
2529 krb5_error_code KRB5_CALLCONV
2530 krb5_cc_get_flags(krb5_context context, krb5_ccache cache, krb5_flags *flags);
2531
2532 /**
2533  * Retrieve the type of a credential cache.
2534  *
2535  * @param [in] context          Library context
2536  * @param [in] cache            Credential cache handle
2537  *
2538  * @return The type of a credential cache as an alias that must not be modified
2539  * or freed by the caller.
2540  */
2541 const char * KRB5_CALLCONV
2542 krb5_cc_get_type(krb5_context context, krb5_ccache cache);
2543
2544 /**
2545  * Move a credential cache.
2546  *
2547  * @param [in] context          Library context
2548  * @param [in] src              The credential cache to move the content from
2549  * @param [in] dst              The credential cache to move the content to
2550  *
2551  * This function reinitializes @a dst and populates it with the credentials and
2552  * default principal of @a src; then, if successful, destroys @a src.
2553  *
2554  * @retval
2555  * 0 Success; @a src is closed.
2556  * @return
2557  * Kerberos error codes; @a src is still allocated.
2558  */
2559 krb5_error_code KRB5_CALLCONV
2560 krb5_cc_move(krb5_context context, krb5_ccache src, krb5_ccache dst);
2561
2562 /**
2563  * Return a timestamp of the last modification to a credential cache.
2564  *
2565  * @param [in]  context         Library context
2566  * @param [in]  ccache          Credential cache handle
2567  * @param [out] change_time     The last change time of @a ccache
2568  *
2569  * If an error occurs, @a change_time is set to 0.
2570  */
2571 krb5_error_code KRB5_CALLCONV
2572 krb5_cc_last_change_time(krb5_context context, krb5_ccache ccache,
2573                          krb5_timestamp *change_time);
2574
2575 /**
2576  * Lock a credential cache.
2577  *
2578  * @param [in]  context         Library context
2579  * @param [in]  ccache          Credential cache handle
2580  *
2581  * Use krb5_cc_unlock() to unlock the lock.
2582  *
2583  * @retval 0 Success; otherwise - Kerberos error codes
2584  */
2585 krb5_error_code KRB5_CALLCONV
2586 krb5_cc_lock(krb5_context context, krb5_ccache ccache);
2587
2588 /**
2589  * Unlock a credential cache.
2590  *
2591  * @param [in]  context         Library context
2592  * @param [in]  ccache          Credential cache handle
2593  *
2594  * This function unlocks the @a ccache locked by krb5_cc_lock().
2595  *
2596  * @retval 0 Success; otherwise - Kerberos error codes
2597  */
2598 krb5_error_code KRB5_CALLCONV
2599 krb5_cc_unlock(krb5_context context, krb5_ccache ccache);
2600
2601 /**
2602  * Prepare to iterate over the collection of known credential caches.
2603  *
2604  * @param [in]     context      Library context
2605  * @param [in,out] cursor       Cursor
2606  *
2607  * Get a new cache iteration @a cursor that will iterate over all known
2608  * credential caches independent of type.
2609  *
2610  * Use krb5_cccol_cursor_free() to release @a cursor when it is no longer
2611  * needed.
2612  *
2613  * @sa krb5_cccol_cursor_next()
2614  *
2615  * @retval 0 Success; otherwise - Kerberos error codes
2616  */
2617 krb5_error_code KRB5_CALLCONV
2618 krb5_cccol_cursor_new(krb5_context context, krb5_cccol_cursor *cursor);
2619
2620 /**
2621  * Get the next credential cache in the collection.
2622  *
2623  * @param [in]     context      Library context
2624  * @param [in,out] cursor       Cursor
2625  * @param [out]    ccache       Credential cache handle
2626  *
2627  * @note When all caches are iterated over and the end of the list is reached,
2628  * @a ccache is set to NULL.
2629  *
2630  * Use krb5_cc_close() to close @a ccache when it is no longer needed.
2631  *
2632  * @sa krb5_cccol_cursor_new(), krb5_cccol_cursor_free()
2633  *
2634  * @retval 0 Success; otherwise - Kerberos error codes
2635  */
2636 krb5_error_code KRB5_CALLCONV
2637 krb5_cccol_cursor_next(krb5_context context, krb5_cccol_cursor cursor,
2638                        krb5_ccache *ccache);
2639
2640 /**
2641  * Free a credential cache collection cursor.
2642  *
2643  * @param [in] context          Library context
2644  * @param [in] cursor           Cursor
2645  *
2646  * @sa krb5_cccol_cursor_new(), krb5_cccol_cursor_next()
2647  *
2648  * @retval 0 Success; otherwise - Kerberos error codes
2649  */
2650 krb5_error_code KRB5_CALLCONV
2651 krb5_cccol_cursor_free(krb5_context context, krb5_cccol_cursor *cursor);
2652
2653 /**
2654  * Return a timestamp of the last modification of any known credential cache.
2655  *
2656  * @param [in]  context         Library context
2657  * @param [out] change_time     Last modification timestamp
2658  *
2659  * This function returns the most recent modification time of any known
2660  * credential cache, ignoring any caches which cannot supply a last
2661  * modification time.
2662  *
2663  * If there are no known credential caches, @a change_time is set to 0.
2664  *
2665  * @retval 0 Success; otherwise - Kerberos error codes
2666  */
2667 krb5_error_code KRB5_CALLCONV
2668 krb5_cccol_last_change_time(krb5_context context, krb5_timestamp *change_time);
2669
2670 /**
2671  * Acquire a global lock for credential caches.
2672  *
2673  * @param [in]  context         Library context
2674  *
2675  * This function locks the global credential cache collection, ensuring
2676  * that no ccaches are added to or removed from it until the collection
2677  * lock is released.
2678  *
2679  * Use krb5_cccol_unlock() to unlock the lock.
2680  *
2681  * @retval 0 Success; otherwise - Kerberos error codes
2682  */
2683
2684 krb5_error_code KRB5_CALLCONV
2685 krb5_cccol_lock(krb5_context context);
2686
2687 /**
2688  * Release a global lock for credential caches.
2689  *
2690  * @param [in]  context         Library context
2691  *
2692  * This function unlocks the lock from krb5_cccol_lock().
2693  *
2694  * @retval 0 Success; otherwise - Kerberos error codes
2695  */
2696 krb5_error_code KRB5_CALLCONV
2697 krb5_cccol_unlock(krb5_context context);
2698
2699 /**
2700  * Create a new credential cache of the specified type with a unique name.
2701  *
2702  * @param [in]  context         Library context
2703  * @param [in]  type            Credential cache type name
2704  * @param [in]  hint            Unused
2705  * @param [out] id              Credential cache handle
2706  *
2707  * @retval
2708  * 0 Success
2709  * @return
2710  * Kerberos error codes
2711  */
2712 krb5_error_code KRB5_CALLCONV
2713 krb5_cc_new_unique(krb5_context context, const char *type, const char *hint,
2714                    krb5_ccache *id);
2715
2716 /*
2717  * end "ccache.h"
2718  */
2719
2720 /*
2721  * begin "rcache.h"
2722  */
2723
2724 struct krb5_rc_st;
2725 typedef struct krb5_rc_st *krb5_rcache;
2726
2727 /*
2728  * end "rcache.h"
2729  */
2730
2731 /*
2732  * begin "keytab.h"
2733  */
2734
2735
2736 /* XXX */
2737 #define MAX_KEYTAB_NAME_LEN 1100 /* Long enough for MAXPATHLEN + some extra */
2738
2739 typedef krb5_pointer krb5_kt_cursor;
2740
2741 /** A key table entry. */
2742 typedef struct krb5_keytab_entry_st {
2743     krb5_magic magic;
2744     krb5_principal principal;   /**< Principal of this key */
2745     krb5_timestamp timestamp;   /**< Time entry written to keytable */
2746     krb5_kvno vno;              /**< Key version number */
2747     krb5_keyblock key;          /**< The secret key */
2748 } krb5_keytab_entry;
2749
2750 struct _krb5_kt;
2751 typedef struct _krb5_kt *krb5_keytab;
2752
2753 /**
2754  * Return the type of a key table.
2755  *
2756  * @param [in] context          Library context
2757  * @param [in] keytab           Key table handle
2758  *
2759  * @return The type of a key table as an alias that must not be modified or
2760  * freed by the caller.
2761  */
2762 const char * KRB5_CALLCONV
2763 krb5_kt_get_type(krb5_context context, krb5_keytab keytab);
2764
2765 /**
2766  * Get a key table name.
2767  *
2768  * @param [in]  context         Library context
2769  * @param [in]  keytab          Key table handle
2770  * @param [out] name            Key table name
2771  * @param [in]  namelen         Maximum length to fill in name
2772  *
2773  * Fills in @a with the name of @a keytab including the type and delimiter.
2774  *
2775  * @sa MAX_KEYTAB_NAME_LEN
2776  *
2777  * @retval
2778  * 0 Success
2779  * @retval
2780  * KRB5_KT_NAME_TOOLONG  Key table name does not fit in @a namelen bytes
2781  *
2782  * @return
2783  * Kerberos error codes
2784  */
2785 krb5_error_code KRB5_CALLCONV
2786 krb5_kt_get_name(krb5_context context, krb5_keytab keytab, char *name,
2787                  unsigned int namelen);
2788
2789 /**
2790  * Close a key table handle.
2791  *
2792  * @param [in] context          Library context
2793  * @param [in] keytab           Key table handle
2794  *
2795  * @retval 0
2796  */
2797 krb5_error_code KRB5_CALLCONV
2798 krb5_kt_close(krb5_context context, krb5_keytab keytab);
2799
2800 /**
2801  * Get an entry from a key table.
2802  *
2803  * @param [in]  context         Library context
2804  * @param [in]  keytab          Key table handle
2805  * @param [in]  principal       Principal name
2806  * @param [in]  vno             Key version number (0 for highest available)
2807  * @param [in]  enctype         Encryption type (0 zero for any enctype)
2808  * @param [out] entry           Returned entry from key table
2809  *
2810  * Retrieve an entry from a key table which matches the @a keytab, @a
2811  * principal, @a vno, and @a enctype.  If @a vno is zero, retrieve the
2812  * highest-numbered kvno matching the other fields.  If @a enctype is 0, match
2813  * any enctype.
2814  *
2815  * Use krb5_free_keytab_entry_contents() to free @a entry when it is no longer
2816  * needed.
2817  *
2818  * @note If @a vno is zero, the function retrieves the highest-numbered-kvno
2819  * entry that matches the specified principal.
2820  *
2821  * @retval
2822  * 0 Success
2823  * @retval
2824  * Kerberos error codes on failure
2825  */
2826 krb5_error_code KRB5_CALLCONV
2827 krb5_kt_get_entry(krb5_context context, krb5_keytab keytab,
2828                   krb5_const_principal principal, krb5_kvno vno,
2829                   krb5_enctype enctype, krb5_keytab_entry *entry);
2830
2831 /**
2832  * Start a sequential retrieval of key table entries.
2833  *
2834  * @param [in]  context         Library context
2835  * @param [in]  keytab          Key table handle
2836  * @param [out] cursor          Cursor
2837  *
2838  * Prepare to read sequentially every key in the specified key table.  Use
2839  * krb5_kt_end_seq_get() to release the cursor when it is no longer needed.
2840  *
2841  * @sa krb5_kt_next_entry(), krb5_kt_end_seq_get()
2842  *
2843  * @retval
2844  * 0 Success
2845  * @return
2846  * Kerberos error codes
2847  */
2848 krb5_error_code KRB5_CALLCONV
2849 krb5_kt_start_seq_get(krb5_context context, krb5_keytab keytab,
2850                       krb5_kt_cursor *cursor);
2851
2852 /**
2853  * Retrieve the next entry from the key table.
2854  *
2855  * @param [in]  context         Library context
2856  * @param [in]  keytab          Key table handle
2857  * @param [out] entry           Returned key table entry
2858  * @param [in,out] cursor       Key table cursor
2859  *
2860  * Return the next sequential entry in @a keytab and advance @a cursor.
2861  *
2862  * @sa krb5_kt_start_seq_get(), krb5_kt_end_seq_get()
2863  *
2864  * @retval
2865  * 0 Success
2866  * @retval
2867  * KRB5_KT_END - if the last entry was reached
2868  * @return
2869  * Kerberos error codes
2870  */
2871 krb5_error_code KRB5_CALLCONV
2872 krb5_kt_next_entry(krb5_context context, krb5_keytab keytab,
2873                    krb5_keytab_entry *entry, krb5_kt_cursor *cursor);
2874
2875 /**
2876  * Release a keytab cursor.
2877  *
2878  * @param [in]  context         Library context
2879  * @param [in]  keytab          Key table handle
2880  * @param [out] cursor          Cursor
2881  *
2882  * This function should be called to release the cursor created by
2883  * krb5_kt_start_seq_get().
2884  *
2885  * @retval
2886  * 0 Success
2887  * @return
2888  * Kerberos error codes
2889  */
2890 krb5_error_code KRB5_CALLCONV
2891 krb5_kt_end_seq_get(krb5_context context, krb5_keytab keytab,
2892                     krb5_kt_cursor *cursor);
2893
2894 /*
2895  * end "keytab.h"
2896  */
2897
2898 /*
2899  * begin "func-proto.h"
2900  */
2901
2902 #define KRB5_INIT_CONTEXT_SECURE 0x1 /**< Use secure context configuration */
2903 #define KRB5_INIT_CONTEXT_KDC    0x2 /**< Use KDC configuration if available */
2904
2905 /**
2906  * Create a krb5 library context.
2907  *
2908  * @param [out] context         Library context
2909  *
2910  * The @a context must be released by calling krb5_free_context() when
2911  * it is no longer needed.
2912  *
2913  * @warning Any program or module that needs the Kerberos code to not trust the
2914  * environment must use krb5_init_secure_context(), or clean out the
2915  * environment.
2916  *
2917  * @retval
2918  * 0 Success
2919  * @return
2920  * Kerberos error codes
2921  */
2922 krb5_error_code KRB5_CALLCONV
2923 krb5_init_context(krb5_context *context);
2924
2925 /**
2926  * Create a krb5 library context using only configuration files.
2927  *
2928  * @param [out] context         Library context
2929  *
2930  * Create a context structure, using only system configuration files.  All
2931  * information passed through the environment variables is ignored.
2932  *
2933  * The @a context must be released by calling krb5_free_context() when
2934  * it is no longer needed.
2935  *
2936  * @retval
2937  * 0 Success
2938  * @return
2939  * Kerberos error codes
2940  */
2941 krb5_error_code KRB5_CALLCONV
2942 krb5_init_secure_context(krb5_context *context);
2943
2944 /**
2945  * Create a krb5 library context using a specified profile.
2946  *
2947  * @param [in]  profile         Profile object (NULL to create default profile)
2948  * @param [in]  flags           Context initialization flags
2949  * @param [out] context         Library context
2950  *
2951  * Create a context structure, optionally using a specified profile and
2952  * initialization flags.  If @a profile is NULL, the default profile will be
2953  * created from config files.  If @a profile is non-null, a copy of it will be
2954  * made for the new context; the caller should still clean up its copy.  Valid
2955  * flag values are:
2956  *
2957  * @li #KRB5_INIT_CONTEXT_SECURE Ignore environment variables
2958  * @li #KRB5_INIT_CONTEXT_KDC    Use KDC configuration if creating profile
2959  */
2960 krb5_error_code KRB5_CALLCONV
2961 krb5_init_context_profile(struct _profile_t *profile, krb5_flags flags,
2962                           krb5_context *context);
2963
2964 /**
2965  * Free a krb5 library context.
2966  *
2967  * @param [in] context          Library context
2968  *
2969  * This function frees a @a context that was created by krb5_init_context()
2970  * or krb5_init_secure_context().
2971  */
2972 void KRB5_CALLCONV
2973 krb5_free_context(krb5_context context);
2974
2975 /**
2976  * Copy a krb5_context structure.
2977  *
2978  * @param [in]  ctx             Library context
2979  * @param [out] nctx_out        New context structure
2980  *
2981  * The newly created context must be released by calling krb5_free_context()
2982  * when it is no longer needed.
2983  *
2984  * @retval
2985  * 0 Success
2986  * @return
2987  * Kerberos error codes
2988  */
2989 krb5_error_code KRB5_CALLCONV
2990 krb5_copy_context(krb5_context ctx, krb5_context *nctx_out);
2991
2992 /**
2993  * Set default TGS encryption types in a krb5_context structure.
2994  *
2995  * @param [in,out] context      Library context
2996  * @param [in]     etypes       Encryption type(s) to set
2997  *
2998  * This function sets the default enctype list for TGS requests
2999  * made using @a context to @a etypes.
3000  *
3001  * @note This overrides the default list (from config file or built-in).
3002  *
3003  * @retval
3004  *  0    Success
3005  * @retval
3006  *  KRB5_PROG_ETYPE_NOSUPP Program lacks support for encryption type
3007  * @return
3008  * Kerberos error codes
3009  */
3010 krb5_error_code KRB5_CALLCONV
3011 krb5_set_default_tgs_enctypes(krb5_context context, const krb5_enctype *etypes);
3012
3013 /**
3014  * Return a list of encryption types permitted for session keys.
3015  *
3016  * @param [in]  context         Library context
3017  * @param [out] ktypes          Zero-terminated list of encryption types
3018  *
3019  * This function returns the list of encryption types permitted for session
3020  * keys within @a context, as determined by configuration or by a previous call
3021  * to krb5_set_default_tgs_enctypes().
3022  *
3023  * @retval 0 Success; otherwise - Kerberos error codes
3024  */
3025 krb5_error_code KRB5_CALLCONV
3026 krb5_get_permitted_enctypes(krb5_context context, krb5_enctype **ktypes);
3027
3028 /**
3029  * Test whether the Kerberos library was built with multithread support.
3030  *
3031  * @retval
3032  * TRUE if the library is threadsafe; FALSE otherwise
3033  */
3034 krb5_boolean KRB5_CALLCONV
3035 krb5_is_thread_safe(void);
3036
3037 /* libkrb.spec */
3038
3039 /**
3040  * Decrypt a ticket using the specified key table.
3041  *
3042  * @param [in]     context      Library context
3043  * @param [in]     kt           Key table
3044  * @param [in,out] ticket       Ticket to be decrypted
3045  *
3046  * This function takes a @a ticket as input and decrypts it using
3047  * key data from @a kt.  The result is placed into @a ticket->enc_part2.
3048  *
3049  * @retval 0 Success; otherwise - Kerberos error codes
3050  */
3051 krb5_error_code KRB5_CALLCONV
3052 krb5_server_decrypt_ticket_keytab(krb5_context context, const krb5_keytab kt,
3053                                   krb5_ticket *ticket);
3054
3055 /**
3056  * Free an array of credential structures.
3057  *
3058  * @param [in] context          Library context
3059  * @param [in] tgts             Null-terminated array of credentials to free
3060  *
3061  * @note The last entry in the array @a tgts must be a NULL pointer.
3062  */
3063 void KRB5_CALLCONV
3064 krb5_free_tgt_creds(krb5_context context, krb5_creds **tgts);
3065
3066 /** @defgroup KRB5_GC  KRB5_GC
3067  * @{
3068  */
3069 #define KRB5_GC_USER_USER    1  /**< Want user-user ticket */
3070 #define KRB5_GC_CACHED       2  /**< Want cached ticket only */
3071 #define KRB5_GC_CANONICALIZE 4  /**< Set canonicalize KDC option */
3072 #define KRB5_GC_NO_STORE     8  /**< Do not store in credential cache */
3073 #define KRB5_GC_FORWARDABLE             16  /**< Acquire forwardable tickets */
3074 #define KRB5_GC_NO_TRANSIT_CHECK        32  /**< Disable transited check */
3075 #define KRB5_GC_CONSTRAINED_DELEGATION  64  /**< Constrained delegation */
3076 /** @} */ /* end of KRB5_GC group */
3077
3078 /**
3079  * Get an additional ticket.
3080  *
3081  * @param [in]     context      Library context
3082  * @param [in]     options      Options
3083  * @param [in,out] ccache       Credential cache handle
3084  * @param [in]     in_creds     Input credentials
3085  * @param [out]    out_creds    Output updated credentials
3086  *
3087  * Use @a ccache or a TGS exchange to get a service ticket matching @a
3088  * in_creds.
3089  *
3090  * Valid values for @a options are:
3091  * @li #KRB5_GC_CACHED     Search only credential cache for the ticket
3092  * @li #KRB5_GC_USER_USER  Return a user to user authentication ticket
3093  *
3094  * @a in_creds must be non-null.  @a in_creds->client and @a in_creds->server
3095  * must be filled in to specify the client and the server respectively.  If any
3096  * authorization data needs to be requested for the service ticket (such as
3097  * restrictions on how the ticket can be used), specify it in @a
3098  * in_creds->authdata; otherwise set @a in_creds->authdata to NULL.  The
3099  * session key type is specified in @a in_creds->keyblock.enctype, if it is
3100  * nonzero.
3101  *
3102  * The expiration date is specified in @a in_creds->times.endtime.
3103  * The KDC may return tickets with an earlier expiration date.
3104  * If @a in_creds->times.endtime is set to 0, the latest possible
3105  * expiration date will be requested.
3106  *
3107  * Any returned ticket and intermediate ticket-granting tickets are stored
3108  * in @a ccache.
3109  *
3110  * Use krb5_free_creds() to free @a out_creds when it is no longer needed.
3111  *
3112  * @retval
3113  *  0  Success
3114  * @return
3115  * Kerberos error codes
3116  */
3117 krb5_error_code KRB5_CALLCONV
3118 krb5_get_credentials(krb5_context context, krb5_flags options,
3119                      krb5_ccache ccache, krb5_creds *in_creds,
3120                      krb5_creds **out_creds);
3121
3122 /** @deprecated Replaced by krb5_get_validated_creds. */
3123 krb5_error_code KRB5_CALLCONV
3124 krb5_get_credentials_validate(krb5_context context, krb5_flags options,
3125                               krb5_ccache ccache, krb5_creds *in_creds,
3126                               krb5_creds **out_creds);
3127
3128 /** @deprecated Replaced by krb5_get_renewed_creds. */
3129 krb5_error_code KRB5_CALLCONV
3130 krb5_get_credentials_renew(krb5_context context, krb5_flags options,
3131                            krb5_ccache ccache, krb5_creds *in_creds,
3132                            krb5_creds **out_creds);
3133
3134 /**
3135  * Create a @c KRB_AP_REQ message.
3136  *
3137  * @param [in]     context        Library context
3138  * @param [in,out] auth_context   Pre-existing or newly created auth context
3139  * @param [in]     ap_req_options @ref AP_OPTS options
3140  * @param [in]     service        Service name, or NULL to use @c "host"
3141  * @param [in]     hostname       Host name, or NULL to use local hostname
3142  * @param [in]     in_data        Application data to be checksummed in the
3143  *                                authenticator, or NULL
3144  * @param [in]     ccache         Credential cache used to obtain credentials
3145  *                                for the desired service.
3146  * @param [out]    outbuf         @c AP-REQ message
3147  *
3148  * This function is similar to krb5_mk_req_extended() except that it uses a
3149  * given @a hostname, @a service, and @a ccache to construct a service
3150  * principal name and obtain credentials.
3151  *
3152  * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed.
3153  *
3154  * @retval 0 Success; otherwise - Kerberos error codes
3155  */
3156 krb5_error_code KRB5_CALLCONV
3157 krb5_mk_req(krb5_context context, krb5_auth_context *auth_context,
3158             krb5_flags ap_req_options, char *service, char *hostname,
3159             krb5_data *in_data, krb5_ccache ccache, krb5_data *outbuf);
3160
3161 /**
3162  * Create a @c KRB_AP_REQ message using supplied credentials.
3163  *
3164  * @param [in]     context        Library context
3165  * @param [in,out] auth_context   Pre-existing or newly created auth context
3166  * @param [in]     ap_req_options @ref AP_OPTS options
3167  * @param [in]     in_data        Application data to be checksummed in the
3168  *                                authenticator, or NULL
3169  * @param [in]     in_creds       Credentials for the service with valid ticket
3170  *                                and key
3171  * @param [out]    outbuf         @c AP-REQ message
3172  *
3173  * Valid @a ap_req_options are:
3174  * @li #AP_OPTS_USE_SESSION_KEY - Use the session key when creating the
3175  *                                request used for user to user
3176  *                                authentication.
3177  * @li #AP_OPTS_MUTUAL_REQUIRED - Request a mutual authentication packet from
3178  *                                the reciever.
3179  * @li #AP_OPTS_USE_SUBKEY      - Generate a subsession key from the current
3180  *                                session key obtained from the credentials.
3181  *
3182  * This function creates a KRB_AP_REQ message using supplied credentials @a
3183  * in_creds.  @a auth_context may point to an existing auth context or to NULL,
3184  * in which case a new one will be created.  If @a in_data is non-null, a
3185  * checksum of it will be included in the authenticator contained in the
3186  * KRB_AP_REQ message.  Use krb5_free_data_contents() to free @a outbuf when it
3187  * is no longer needed.
3188  *
3189  * On successful return, the authenticator is stored in @a auth_context with
3190  * the @a client and @a checksum fields nulled out.  (This is to prevent
3191  * pointer-sharing problems; the caller should not need these fields anyway,
3192  * since the caller supplied them.)
3193  *
3194  * @sa krb5_mk_req()
3195  *
3196  * @retval 0 Success; otherwise - Kerberos error codes
3197  */
3198 krb5_error_code KRB5_CALLCONV
3199 krb5_mk_req_extended(krb5_context context, krb5_auth_context *auth_context,
3200                      krb5_flags ap_req_options, krb5_data *in_data,
3201                      krb5_creds *in_creds, krb5_data *outbuf);
3202
3203 /**
3204  * Format and encrypt a @c KRB_AP_REP message.
3205  *
3206  * @param [in]     context      Library context
3207  * @param [in,out] auth_context Authentication context
3208  * @param [out]    outbuf       @c AP-REP message
3209  *
3210  * This function fills in @a outbuf with an AP-REP message using information
3211  * from @a auth_context.
3212  *
3213  * If the flags in @a auth_context indicate that a sequence number should be
3214  * used (either #KRB5_AUTH_CONTEXT_DO_SEQUENCE or
3215  * #KRB5_AUTH_CONTEXT_RET_SEQUENCE) and the local sequence number in @a
3216  * auth_context is 0, a new number will be generated with
3217  * krb5_generate_seq_number().
3218  *
3219  * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed.
3220  *
3221  * @retval 0 Success; otherwise - Kerberos error codes
3222  */
3223 krb5_error_code KRB5_CALLCONV
3224 krb5_mk_rep(krb5_context context, krb5_auth_context auth_context, krb5_data *outbuf);
3225
3226 /**
3227  * Format and encrypt a @c KRB_AP_REP message for DCE RPC.
3228  *
3229  * @param [in]     context           Library context
3230  * @param [in,out] auth_context      Authentication context
3231  * @param [out]    outbuf            @c AP-REP message
3232  *
3233  * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed.
3234  *
3235  * @retval 0 Success; otherwise - Kerberos error codes
3236  */
3237 krb5_error_code KRB5_CALLCONV
3238 krb5_mk_rep_dce(krb5_context context, krb5_auth_context auth_context, krb5_data *outbuf);
3239
3240 /**
3241  * Parse and decrypt a @c KRB_AP_REP message.
3242  *
3243  * @param [in]     context      Library context
3244  * @param [in,out] auth_context Authentication context
3245  * @param [in]     inbuf        AP-REP message
3246  * @param [out]    repl         Decrypted reply message
3247  *
3248  * This function parses, decrypts and verifies a message from @a inbuf and
3249  * fills in @a repl with a pointer to allocated memory containing the fields
3250  * from the encrypted response.
3251  *
3252  * Use krb5_free_ap_rep_enc_part() to free @a repl when it is no longer needed.
3253  *
3254  * @retval 0 Success; otherwise - Kerberos error codes
3255  */
3256 krb5_error_code KRB5_CALLCONV
3257 krb5_rd_rep(krb5_context context, krb5_auth_context auth_context,
3258             const krb5_data *inbuf, krb5_ap_rep_enc_part **repl);
3259
3260 /**
3261  * Parse and decrypt a @c KRB_AP_REP message for DCE RPC.
3262  *
3263  * @param [in]     context      Library context
3264  * @param [in,out] auth_context Authentication context
3265  * @param [in]     inbuf        AP-REP message
3266  * @param [out]    nonce        Sequence number from the decrypted reply
3267  *
3268  * This function parses, decrypts and verifies a message from @a inbuf and
3269  * fills in @a nonce with a decrypted reply sequence number.
3270  *
3271  * @retval 0 Success; otherwise - Kerberos error codes
3272  */
3273 krb5_error_code KRB5_CALLCONV
3274 krb5_rd_rep_dce(krb5_context context, krb5_auth_context auth_context,
3275                 const krb5_data *inbuf, krb5_ui_4 *nonce);
3276
3277 /**
3278  * Format and encode a @c KRB_ERROR message.
3279  *
3280  * @param [in]  context         Library context
3281  * @param [in]  dec_err         Error structure to be encoded
3282  * @param [out] enc_err         Encoded error structure
3283  *
3284  * This function creates a @c KRB_ERROR message in @a enc_err.  Use
3285  * krb5_free_data_contents() to free @a enc_err when it is no longer needed.
3286  *
3287  * @retval 0 Success; otherwise - Kerberos error codes
3288  */
3289 krb5_error_code KRB5_CALLCONV
3290 krb5_mk_error(krb5_context context, const krb5_error *dec_err,
3291               krb5_data *enc_err);
3292
3293 /**
3294  * Decode a @c KRB-ERROR message.
3295  *
3296  * @param [in]  context         Library context
3297  * @param [in]  enc_errbuf      Encoded error message
3298  * @param [out] dec_error       Decoded error message
3299  *
3300  * This function processes @c KRB-ERROR message @a enc_errbuf and returns
3301  * an allocated structure @a dec_error containing the error message.
3302  * Use krb5_free_error() to free @a dec_error when it is no longer needed.
3303  *
3304  * @retval 0 Success; otherwise - Kerberos error codes
3305  */
3306 krb5_error_code KRB5_CALLCONV
3307 krb5_rd_error(krb5_context context, const krb5_data *enc_errbuf,
3308               krb5_error **dec_error);
3309
3310 /**
3311  * Process @c KRB-SAFE message.
3312  *
3313  * @param [in]     context      Library context
3314  * @param [in,out] auth_context Authentication structure
3315  * @param [in]     inbuf        @c KRB-SAFE message to be parsed
3316  * @param [out]    outbuf       Data parsed from @c KRB-SAFE message
3317  * @param [out]    outdata      Replay data. Specify NULL if not needed
3318  *
3319  * This function parses a @c KRB-SAFE message, verifies its integrity, and
3320  * stores its data into @a outbuf.
3321  *
3322  * @note The @a outdata argument is required if #KRB5_AUTH_CONTEXT_RET_TIME or
3323  *       #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in the @a auth_context.
3324  *
3325  * @note @a auth_context must have a remote address set.  This address will be
3326  *       used to verify the sender address in the KRB-SAFE message.  If @a
3327  *       auth_context has a local address set, it will be used to verify the
3328  *       receiver address in the KRB-SAFE message if the message contains one.
3329  *       Both addresses must use type @c ADDRTYPE_ADDRPORT.
3330  *
3331  * If the #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag is set in @a auth_context, the
3332  * sequence number of the KRB-SAFE message is checked against the remote
3333  * sequence number field of @a auth_context.  Otherwise, the sequence number is
3334  * not used.
3335  *
3336  * If the #KRB5_AUTH_CONTEXT_DO_TIME flag is set in @a auth_context,
3337  * then two additional checks are performed:
3338  * @li The timestamp in the message must be within the permitted clock skew
3339  *     (which is usually five minutes).
3340  * @li The message must not be a replayed message field in @a auth_context.
3341  *
3342  * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed.
3343  *
3344  * @retval 0 Success; otherwise - Kerberos error codes
3345  */
3346 krb5_error_code KRB5_CALLCONV
3347 krb5_rd_safe(krb5_context context, krb5_auth_context auth_context,
3348              const krb5_data *inbuf, krb5_data *outbuf,
3349              krb5_replay_data *outdata);
3350
3351 /**
3352  * Process a @c KRB-PRIV message.
3353  *
3354  * @param [in]     context      Library context
3355  * @param [in,out] auth_context Authentication structure
3356  * @param [in]     inbuf        @c KRB-PRIV message to be parsed
3357  * @param [out]    outbuf       Data parsed from @c KRB-PRIV message
3358  * @param [out]    outdata      Replay data. Specify NULL if not needed
3359  *
3360  * This function parses a @c KRB-PRIV message, verifies its integrity, and
3361  * stores its unencrypted data into @a outbuf.
3362  *
3363  * @note If the #KRB5_AUTH_CONTEXT_RET_TIME or @c
3364  *       #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in @a auth_context, @a
3365  *       outdata is required.
3366  *
3367  * @note @a auth_context must have a remote address set.  This address will be
3368  *       used to verify the sender address in the KRB-PRIV message.  If @a
3369  *       auth_context has a local address set, it will be used to verify the
3370  *       receiver address in the KRB-PRIV message if the message contains one.
3371  *       Both addresses must use type @c ADDRTYPE_ADDRPORT.
3372  *
3373  * If the #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag is set in @a auth_context, the
3374  * sequence number of the KRB-SAFE message is checked against the remote
3375  * sequence number field of @a auth_context.  Otherwise, the sequence number is
3376  * not used.
3377  *
3378  * If the #KRB5_AUTH_CONTEXT_DO_TIME flag is set in @a auth_context,
3379  * then two additional checks are performed:
3380  * @li The timestamp in the message must be within the permitted clock skew
3381  *     (which is usually five minutes).
3382  * @li The message must not be a replayed message field in @a auth_context.
3383  *
3384  * @retval 0 Success; otherwise - Kerberos error codes
3385  */
3386 krb5_error_code KRB5_CALLCONV
3387 krb5_rd_priv(krb5_context context, krb5_auth_context auth_context,
3388              const krb5_data *inbuf, krb5_data *outbuf,
3389              krb5_replay_data *outdata);
3390
3391 /**
3392  * Convert a string principal name to a krb5_principal structure.
3393  *
3394  * @param [in]  context         Library context
3395  * @param [in]  name            String representation of a principal name
3396  * @param [out] nprincipal      Principal
3397  *
3398  * Convert a string representation of a principal name to a krb5_principal
3399  * structure.
3400  *
3401  * A string representation of a Kerberos name consists of one or more principal
3402  * name components, separated by slashes, optionally followed by the \@
3403  * character and a realm name.  If the realm name is not specified, the local
3404  * realm is used.
3405  *
3406  * To use the slash and \@ symbols as part of a component (quoted) instead of
3407  * using them as a component separator or as a realm prefix), put a backslash
3408  * (\) character in front of the symbol.  Similarly, newline, tab, backspace,
3409  * and NULL characters can be included in a component by using @c n, @c t, @c b
3410  * or @c 0, respectively.
3411  *
3412  * @note The realm in a Kerberos @a name cannot contain slash, colon,
3413  * or NULL characters.
3414  *
3415  * Use krb5_free_principal() to free @a nprincipal when it is no longer needed.
3416  *
3417  * @retval
3418  * 0 Success
3419  * @return
3420  * Kerberos error codes
3421  */
3422 krb5_error_code KRB5_CALLCONV
3423 krb5_parse_name(krb5_context context, const char *name, krb5_principal *nprincipal);
3424
3425 #define KRB5_PRINCIPAL_PARSE_NO_REALM      0x1 /**< Error if realm is present */
3426 #define KRB5_PRINCIPAL_PARSE_REQUIRE_REALM 0x2 /**< Error if realm is not present */
3427 #define KRB5_PRINCIPAL_PARSE_ENTERPRISE    0x4 /**< Create single-component
3428                                                     enterprise principle */
3429
3430 /**
3431  * Convert a string principal name to a krb5_principal with flags
3432  *
3433  * @param [in]  context         Library context
3434  * @param [in]  name            String representation of a principal name
3435  * @param [in]  flags           Flag
3436  * @param [out] nprincipal      Principal
3437  *
3438  * Similar to krb5_parse_name(), this function converts a single-string
3439  * representation of a principal name to a krb5_principal structure.
3440  *
3441  * The following flags are valid:
3442  * @li #KRB5_PRINCIPAL_PARSE_NO_REALM - no realm must be present in @a name
3443  * @li #KRB5_PRINCIPAL_PARSE_REQUIRE_REALM - realm must be present in @a name
3444  * @li #KRB5_PRINCIPAL_PARSE_ENTERPRISE - create single-component enterprise
3445  *                                        principal
3446  *
3447  * Use krb5_free_principal() to free @a nprincipal when it is no longer needed.
3448  *
3449  * @retval
3450  * 0 Success
3451  * @return
3452  * Kerberos error codes
3453  */
3454 krb5_error_code KRB5_CALLCONV
3455 krb5_parse_name_flags(krb5_context context, const char *name,
3456                       int flags, krb5_principal *nprincipal);
3457
3458 /**
3459  * Convert a krb5_principal structure to a string representation.
3460  *
3461  * @param [in]  context         Library context
3462  * @param [in]  principal       Principal
3463  * @param [out] name            String representation of principal name
3464  *
3465  * The resulting string representation uses the format and quoting conventions
3466  * described for krb5_parse_name().
3467  *
3468  * Use krb5_free_unparsed_name() to free @a name when it is no longer needed.
3469  *
3470  * @retval
3471  * 0 Success
3472  * @return
3473  * Kerberos error codes
3474  */
3475 krb5_error_code KRB5_CALLCONV
3476 krb5_unparse_name(krb5_context context, krb5_const_principal principal,
3477                   register char **name);
3478
3479 /**
3480  * Convert krb5_principal structure to string and length.
3481  *
3482  * @param [in]  context         Library context
3483  * @param [in]  principal       Principal
3484  * @param [out] name            String representation of principal name
3485  * @param [out] size            Size of unparsed name
3486  *
3487  * This function is similar to krb5_unparse_name(), but also returns the length
3488  * of the string representation.
3489  *
3490  * @retval
3491  * 0 Success
3492  * @return
3493  * Kerberos error codes. On failure @a name is set to NULL
3494  */
3495 krb5_error_code KRB5_CALLCONV
3496 krb5_unparse_name_ext(krb5_context context, krb5_const_principal principal,
3497                       char **name, unsigned int *size);
3498
3499 #define KRB5_PRINCIPAL_UNPARSE_SHORT  0x1 /**< Omit realm if it is the local realm */
3500 #define KRB5_PRINCIPAL_UNPARSE_NO_REALM 0x2 /**< Omit realm always */
3501 #define KRB5_PRINCIPAL_UNPARSE_DISPLAY  0x4 /**< Don't escape special characters */
3502
3503 /**
3504  * Convert krb5_principal structure to a string with flags.
3505  *
3506  * @param [in]  context         Library context
3507  * @param [in]  principal       Principal
3508  * @param [in]  flags           Flags
3509  * @param [out] name            String representation of principal name
3510  *
3511  * Similar to krb5_unparse_name(), this function converts a krb5_principal
3512  * structure to a string representation.
3513  *
3514  * The following flags are valid:
3515  * @li #KRB5_PRINCIPAL_UNPARSE_SHORT - omit realm if it is the local realm
3516  * @li #KRB5_PRINCIPAL_UNPARSE_NO_REALM - omit realm
3517  * @li #KRB5_PRINCIPAL_UNPARSE_DISPLAY - do not quote special characters
3518  *
3519  * Use krb5_free_unparsed_name() to free @a name when it is no longer needed.
3520  *
3521  * @retval
3522  * 0 Success
3523  * @return
3524  * Kerberos error codes. On failure @a name is set to NULL
3525  */
3526 krb5_error_code KRB5_CALLCONV
3527 krb5_unparse_name_flags(krb5_context context, krb5_const_principal principal,
3528                         int flags, char **name);
3529
3530 /**
3531  * Convert krb5_principal structure to string format with flags.
3532  *
3533  * @param [in]  context         Library context
3534  * @param [in]  principal       Principal
3535  * @param [in]  flags           Flags
3536  * @param [out] name            Single string format of principal name
3537  * @param [out] size            Size of unparsed name buffer
3538  *
3539  * @sa krb5_unparse_name() krb5_unparse_name_flags() krb5_unparse_name_ext()
3540  *
3541  * @retval
3542  * 0 Success
3543  * @return
3544  * Kerberos error codes. On failure @a name is set to NULL
3545  */
3546 krb5_error_code KRB5_CALLCONV
3547 krb5_unparse_name_flags_ext(krb5_context context, krb5_const_principal principal,
3548                             int flags, char **name, unsigned int *size);
3549
3550 /**
3551  * Set the realm field of a principal
3552  *
3553  * @param [in,out] context      Library context
3554  * @param [in]     principal    Principal name
3555  * @param [in]     realm        Realm name
3556  *
3557  * Set the realm name part of @a principal to @a realm, overwriting the
3558  * previous realm.
3559  *
3560  * @retval
3561  * 0   Success
3562  * @return
3563  * Kerberos error codes
3564  */
3565 krb5_error_code KRB5_CALLCONV
3566 krb5_set_principal_realm(krb5_context context, krb5_principal principal,
3567                          const char *realm);
3568
3569 /**
3570  * Search a list of addresses for a specified address.
3571  *
3572  * @param [in] context          Library context
3573  * @param [in] addr             Address to search for
3574  * @param [in] addrlist         Address list to be searched (or NULL)
3575  *
3576  * @note If @a addrlist contains only a NetBIOS addresses, it will be treated
3577  *       as a null list.
3578  *
3579  * @return
3580  * TRUE if @a addr is listed in @a addrlist, or @c addrlist is NULL; FALSE
3581  * otherwise
3582  */
3583 krb5_boolean KRB5_CALLCONV_WRONG
3584 krb5_address_search(krb5_context context, const krb5_address *addr,
3585                     krb5_address *const *addrlist);
3586
3587 /**
3588  * Compare two Kerberos addresses.
3589  *
3590  * @param [in] context          Library context
3591  * @param [in] addr1            First address to be compared
3592  * @param [in] addr2            Second address to be compared
3593  *
3594  * @return
3595  * TRUE if the addresses are the same, FALSE otherwise
3596  */
3597 krb5_boolean KRB5_CALLCONV
3598 krb5_address_compare(krb5_context context, const krb5_address *addr1,
3599                      const krb5_address *addr2);
3600
3601 /**
3602  * Return an ordering of the specified addresses.
3603  *
3604  * @param [in] context          Library context
3605  * @param [in] addr1            First address
3606  * @param [in] addr2            Second address
3607  *
3608  * @retval
3609  *  0 The two addresses are the same
3610  * @retval
3611  *  \< 0 First address is less than second
3612  * @retval
3613  *  \> 0 First address is greater than second
3614  */
3615 int KRB5_CALLCONV
3616 krb5_address_order(krb5_context context, const krb5_address *addr1,
3617                    const krb5_address *addr2);
3618
3619 /**
3620  * Compare the realms of two principals.
3621  *
3622  * @param [in] context          Library context
3623  * @param [in] princ1           First principal
3624  * @param [in] princ2           Second principal
3625  *
3626  * @retval
3627  * TRUE if the realm names are the same; FALSE otherwise
3628  */
3629 krb5_boolean KRB5_CALLCONV
3630 krb5_realm_compare(krb5_context context, krb5_const_principal princ1,
3631                    krb5_const_principal princ2);
3632
3633 /**
3634  * Compare two principals.
3635  *
3636  * @param [in] context          Library context
3637  * @param [in] princ1           First principal
3638  * @param [in] princ2           Second principal
3639  *
3640  * @retval
3641  * TRUE if the principals are the same; FALSE otherwise
3642  */
3643 krb5_boolean KRB5_CALLCONV
3644 krb5_principal_compare(krb5_context context,
3645                        krb5_const_principal princ1,
3646                        krb5_const_principal princ2);
3647
3648 /**
3649  * Compare two principals ignoring realm components.
3650  *
3651  * @param [in] context          Library context
3652  * @param [in] princ1           First principal
3653  * @param [in] princ2           Second principal
3654  *
3655  * Similar to krb5_principal_compare(), but do not compare the realm
3656  * components of the principals.
3657  *
3658  * @retval
3659  * TRUE if the principals are the same; FALSE otherwise
3660  */
3661 krb5_boolean KRB5_CALLCONV
3662 krb5_principal_compare_any_realm(krb5_context context,
3663                                  krb5_const_principal princ1,
3664                                  krb5_const_principal princ2);
3665
3666 #define KRB5_PRINCIPAL_COMPARE_IGNORE_REALM  1 /**< ignore realm component */
3667 #define KRB5_PRINCIPAL_COMPARE_ENTERPRISE    2 /**< UPNs as real principals */
3668 #define KRB5_PRINCIPAL_COMPARE_CASEFOLD      4 /**< case-insensitive */
3669 #define KRB5_PRINCIPAL_COMPARE_UTF8          8 /**< treat principals as UTF-8 */
3670
3671 /**
3672  * Compare two principals with additional flags.
3673  *
3674  * @param [in] context           Library context
3675  * @param [in] princ1            First principal
3676  * @param [in] princ2            Second principal
3677  * @param [in] flags             Flags
3678  *
3679  * Valid flags are:
3680  * @li #KRB5_PRINCIPAL_COMPARE_IGNORE_REALM - ignore realm component
3681  * @li #KRB5_PRINCIPAL_COMPARE_ENTERPRISE - UPNs as real principals
3682  * @li #KRB5_PRINCIPAL_COMPARE_CASEFOLD case-insensitive
3683  * @li #KRB5_PRINCIPAL_COMPARE_UTF8 - treat principals as UTF-8
3684  *
3685  * @sa krb5_principal_compare()
3686  *
3687  * @retval
3688  * TRUE if the principal names are the same; FALSE otherwise
3689  */
3690 krb5_boolean KRB5_CALLCONV
3691 krb5_principal_compare_flags(krb5_context context,
3692                              krb5_const_principal princ1,
3693                              krb5_const_principal princ2,
3694                              int flags);
3695
3696 /**
3697  * Initialize an empty @c krb5_keyblock.
3698  *
3699  * @param [in]  context         Library context
3700  * @param [in]  enctype         Encryption type
3701  * @param [in]  length          Length of keyblock (or 0)
3702  * @param [out] out             New keyblock structure
3703  *
3704  * Initialize a new keyblock and allocate storage for the contents of the key.
3705  * It is legal to pass in a length of 0, in which case contents are left
3706  * unallocated.  Use krb5_free_keyblock() to free @a out when it is no longer
3707  * needed.
3708  *
3709  * @note If @a length is set to 0, contents are left unallocated.
3710  *
3711  * @retval 0 Success; otherwise - Kerberos error codes
3712  */
3713 krb5_error_code KRB5_CALLCONV
3714 krb5_init_keyblock(krb5_context context, krb5_enctype enctype,
3715                    size_t length, krb5_keyblock **out);
3716
3717 /**
3718  * Copy a keyblock.
3719  *
3720  * @param [in]  context         Library context
3721  * @param [in]  from            Keyblock to be copied
3722  * @param [out] to              Copy of keyblock @a from
3723  *
3724  * This function creates a new keyblock with the same contents as @a from.  Use
3725  * krb5_free_keyblock() to free @a to when it is no longer needed.
3726  *
3727  * @retval 0 Success; otherwise - Kerberos error codes
3728  */
3729 krb5_error_code KRB5_CALLCONV
3730 krb5_copy_keyblock(krb5_context context, const krb5_keyblock *from,
3731                    krb5_keyblock **to);
3732
3733 /**
3734  * Copy the contents of a keyblock.
3735  *
3736  * @param [in]  context         Library context
3737  * @param [in]  from            Key to be copied
3738  * @param [out] to              Output key
3739  *
3740  * This function copies the contents of @a from to @a to.  Use
3741  * krb5_free_keyblock_contents() to free @a to when it is no longer needed.
3742  *
3743  * @retval 0 Success; otherwise - Kerberos error codes
3744  */
3745 krb5_error_code KRB5_CALLCONV
3746 krb5_copy_keyblock_contents(krb5_context context, const krb5_keyblock *from,
3747                             krb5_keyblock *to);
3748
3749 /**
3750  * Copy a krb5_creds structure.
3751  *
3752  * @param [in]  context         Library context
3753  * @param [in]  incred          Credentials structure to be copied
3754  * @param [out] outcred         Copy of @a incred
3755  *
3756  * This function creates a new credential with the contents of @a incred.  Use
3757  * krb5_free_creds() to free @a outcred when it is no longer needed.
3758  *
3759  * @retval 0 Success; otherwise - Kerberos error codes
3760  */
3761 krb5_error_code KRB5_CALLCONV
3762 krb5_copy_creds(krb5_context context, const krb5_creds *incred, krb5_creds **outcred);
3763
3764 /**
3765  * Copy a krb5_data object.
3766  *
3767  * @param [in]  context           Library context
3768  * @param [in]  indata            Data object to be copied
3769  * @param [out] outdata           Copy of @a indata
3770  *
3771  * This function creates a new krb5_data object with the contents of @a indata.
3772  * Use krb5_free_data() to free @a outdata when it is no longer needed.
3773  *
3774  * @retval 0 Success; otherwise - Kerberos error codes
3775  */
3776 krb5_error_code KRB5_CALLCONV
3777 krb5_copy_data(krb5_context context, const krb5_data *indata, krb5_data **outdata);
3778
3779 /**
3780  * Copy a principal.
3781  *
3782  * @param [in]  context         Library context
3783  * @param [in]  inprinc         Principal to be copied
3784  * @param [out] outprinc        Copy of @a inprinc
3785  *
3786  * This function creates a new principal structure with the contents of @a
3787  * inprinc.  Use krb5_free_principal() to free @a outprinc when it is no longer
3788  * needed.
3789  *
3790  * @retval 0 Success; otherwise - Kerberos error codes
3791  */
3792 krb5_error_code KRB5_CALLCONV
3793 krb5_copy_principal(krb5_context context, krb5_const_principal inprinc,
3794                     krb5_principal *outprinc);
3795
3796 /**
3797  * Copy an array of addresses.
3798  *
3799  * @param [in]  context         Library context
3800  * @param [in]  inaddr          Array of addresses to be copied
3801  * @param [out] outaddr         Copy of array of addresses
3802  *
3803  * This function creates a new address array containing a copy of @a inaddr.
3804  * Use krb5_free_addresses() to free @a outaddr when it is no longer needed.
3805  *
3806  * @retval 0 Success; otherwise - Kerberos error codes
3807  */
3808 krb5_error_code KRB5_CALLCONV
3809 krb5_copy_addresses(krb5_context context, krb5_address *const *inaddr,
3810                     krb5_address ***outaddr);
3811
3812 /**
3813  * Copy a krb5_ticket structure.
3814  *
3815  * @param [in]  context         Library context
3816  * @param [in]  from            Ticket to be copied
3817  * @param [out] pto             Copy of ticket
3818  *
3819  * This function creates a new krb5_ticket structure containing the contents of
3820  * @a from.  Use krb5_free_ticket() to free @a pto when it is no longer needed.
3821  *
3822  * @retval 0 Success; otherwise - Kerberos error codes
3823  */
3824 krb5_error_code KRB5_CALLCONV
3825 krb5_copy_ticket(krb5_context context, const krb5_ticket *from, krb5_ticket **pto);
3826
3827 /**
3828  * Copy an authorization data list.
3829  *
3830  * @param [in]  context         Library context
3831  * @param [in]  in_authdat      List of @a krb5_authdata structures
3832  * @param [out] out             New array of @a krb5_authdata structures
3833  *
3834  * This function creates a new authorization data list containing a copy of @a
3835  * in_authdat, which must be null-terminated.  Use krb5_free_authdata() to free
3836  * @a out when it is no longer needed.
3837  *
3838  * @note The last array entry in @a in_authdat must be a NULL pointer.
3839  *
3840  * @retval 0 Success; otherwise - Kerberos error codes
3841  */
3842 krb5_error_code KRB5_CALLCONV
3843 krb5_copy_authdata(krb5_context context,
3844                    krb5_authdata *const *in_authdat, krb5_authdata ***out);
3845
3846 /**
3847  * Merge two authorization data lists into a new list.
3848  *
3849  * @param [in]  context         Library context
3850  * @param [in]  inauthdat1      First list of @a krb5_authdata structures
3851  * @param [in]  inauthdat2      Second list of @a krb5_authdata structures
3852  * @param [out] outauthdat      Merged list of @a krb5_authdata structures
3853  *
3854  * Merge two authdata arrays, such as the array from a ticket
3855  * and authenticator.
3856  * Use krb5_free_authdata() to free @a outauthdat when it is no longer needed.
3857  *
3858  * @note The last array entry in @a inauthdat1 and @a inauthdat2
3859  * must be a NULL pointer.
3860  *
3861  * @retval 0 Success; otherwise - Kerberos error codes
3862  */
3863 krb5_error_code KRB5_CALLCONV
3864 krb5_merge_authdata(krb5_context context,
3865                     krb5_authdata *const *inauthdat1,
3866                     krb5_authdata * const *inauthdat2,
3867                     krb5_authdata ***outauthdat);
3868
3869 /**
3870  * Copy a krb5_authenticator structure.
3871  *
3872  * @param [in]  context         Library context
3873  * @param [in]  authfrom        krb5_authenticator structure to be copied
3874  * @param [out] authto          Copy of krb5_authenticator structure
3875  *
3876  * This function creates a new krb5_authenticator structure with the content of
3877  * @a authfrom.  Use krb5_free_authenticator() to free @a authto when it is no
3878  * longer needed.
3879  *
3880  * @retval 0 Success; otherwise - Kerberos error codes
3881  */
3882 krb5_error_code KRB5_CALLCONV
3883 krb5_copy_authenticator(krb5_context context, const krb5_authenticator *authfrom,
3884                         krb5_authenticator **authto);
3885
3886 /**
3887  * Copy a krb5_checksum structure.
3888  *
3889  * @param [in]  context         Library context
3890  * @param [in]  ckfrom          Checksum to be copied
3891  * @param [out] ckto            Copy of krb5_checksum structure
3892  *
3893  * This function creates a new krb5_checksum structure with the contents of @a
3894  * ckfrom.  Use krb5_free_checksum() to free @a ckto when it is no longer
3895  * needed.
3896  *
3897  * @retval 0 Success; otherwise - Kerberos error codes
3898  */
3899 krb5_error_code KRB5_CALLCONV
3900 krb5_copy_checksum(krb5_context context, const krb5_checksum *ckfrom,
3901                    krb5_checksum **ckto);
3902
3903 /**
3904  * Generate a replay cache object for server use and open it.
3905  *
3906  * @param [in]  context         Library context
3907  * @param [in]  piece           Unique identifier for replay cache
3908  * @param [out] rcptr           Handle to an open rcache
3909  *
3910  * This function generates a replay cache name based on @a piece and opens a
3911  * handle to it.  Typically @a piece is the first component of the service
3912  * principal name.  Use krb5_rc_close() to close @a rcptr when it is no longer
3913  * needed.
3914  *
3915  * @retval 0 Success; otherwise - Kerberos error codes
3916  */
3917 krb5_error_code KRB5_CALLCONV
3918 krb5_get_server_rcache(krb5_context context, const krb5_data *piece,
3919                        krb5_rcache *rcptr);
3920
3921 /**
3922  * Build a principal name using length-counted strings.
3923  *
3924  * @param [in]  context  Library context
3925  * @param [out] princ    Principal name
3926  * @param [in]  rlen     Realm name length
3927  * @param [in]  realm    Realm name
3928  * @param [in]  ...      List of unsigned int/char * components, followed by 0
3929  *
3930  * This function creates a principal from a length-counted string and a
3931  * variable-length list of length-counted components.  The list of components
3932  * ends with the first 0 length argument (so it is not possible to specify an
3933  * empty component with this function).  Call krb5_free_principal() to free
3934  * allocated memory for principal when it is no longer needed.
3935  *
3936  * @code
3937  * Example of how to build principal WELLKNOWN/ANONYMOUS@R
3938  *     krb5_build_principal_ext(context, &principal, strlen("R"), "R",
3939  *         (unsigned int)strlen(KRB5_WELLKNOWN_NAMESTR),
3940  *         KRB5_WELLKNOWN_NAMESTR,
3941  *         (unsigned int)strlen(KRB5_ANONYMOUS_PRINCSTR),
3942  *         KRB5_ANONYMOUS_PRINCSTR, 0);
3943  * @endcode
3944  *
3945  * @retval
3946  * 0  Success
3947  * @return
3948  * Kerberos error codes
3949  */
3950 krb5_error_code KRB5_CALLCONV_C
3951 krb5_build_principal_ext(krb5_context context,  krb5_principal * princ,
3952                          unsigned int rlen, const char * realm, ...);
3953
3954 /**
3955  * Build a principal name using null-terminated strings.
3956  *
3957  * @param [in]  context         Library context
3958  * @param [out] princ           Principal name
3959  * @param [in]  rlen            Realm name length
3960  * @param [in]  realm           Realm name
3961  * @param [in]  ...             List of char * components, ending with NULL
3962  *
3963  * Call krb5_free_principal() to free @a princ when it is no longer needed.
3964  *
3965  * @note krb5_build_principal() and krb5_build_principal_alloc_va() perform the
3966  * same task.  krb5_build_principal() takes variadic arguments.
3967  * krb5_build_principal_alloc_va() takes a pre-computed @a varargs pointer.
3968  *
3969  * @code
3970  * Example of how to build principal H/S@R
3971  *     krb5_build_principal(context, &principal,
3972  *                          strlen("R"), "R", "H", "S", (char*)NULL);
3973  * @endcode
3974  *
3975  * @retval
3976  * 0  Success
3977  * @return
3978  * Kerberos error codes
3979  */
3980 krb5_error_code KRB5_CALLCONV_C
3981 krb5_build_principal(krb5_context context,
3982                      krb5_principal * princ,
3983                      unsigned int rlen,
3984                      const char * realm, ...)
3985 #if __GNUC__ >= 4
3986     __attribute__ ((sentinel))
3987 #endif
3988     ;
3989 #if KRB5_DEPRECATED
3990 /** @deprecated Replaced by krb5_build_principal_alloc_va(). */
3991 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
3992 krb5_build_principal_va(krb5_context context,
3993                         krb5_principal princ,
3994                         unsigned int rlen,
3995                         const char *realm,
3996                         va_list ap);
3997 #endif
3998
3999 /**
4000  * Build a principal name, using a precomputed variable argument list
4001  *
4002  * @param [in]  context         Library context
4003  * @param [out] princ           Principal structure
4004  * @param [in]  rlen            Realm name length
4005  * @param [in]  realm           Realm name
4006  * @param [in]  ap              List of char * components, ending with NULL
4007  *
4008  * Similar to krb5_build_principal(), this function builds a principal name,
4009  * but its name components are specified as a va_list.
4010  *
4011  * Use krb5_free_principal() to deallocate @a princ when it is no longer
4012  * needed.
4013  *
4014  * @code
4015  * Function usage example:
4016  *   va_list ap;
4017  *   va_start(ap, realm);
4018  *   krb5_build_principal_alloc_va(context, princ, rlen, realm, ap);
4019  *   va_end(ap);
4020  * @endcode
4021  *
4022  * @retval
4023  * 0  Success
4024  * @return
4025  * Kerberos error codes
4026  */
4027 krb5_error_code KRB5_CALLCONV
4028 krb5_build_principal_alloc_va(krb5_context context,
4029                               krb5_principal *princ,
4030                               unsigned int rlen,
4031                               const char *realm,
4032                               va_list ap);
4033
4034 /**
4035  * Convert a Kerberos V4 principal to a Kerberos V5 principal.
4036  *
4037  * @param [in]  context         Library context
4038  * @param [in]  name            V4 name
4039  * @param [in]  instance        V4 instance
4040  * @param [in]  realm           Realm
4041  * @param [out] princ           V5 principal
4042  *
4043  * This function builds a @a princ from V4 specification based on given input
4044  * @a name.instance\@realm.
4045  *
4046  * Use krb5_free_principal() to free @a princ when it is no longer needed.
4047  *
4048  * @retval 0 Success; otherwise - Kerberos error codes
4049  */
4050 krb5_error_code KRB5_CALLCONV
4051 krb5_425_conv_principal(krb5_context context, const char *name,
4052                         const char *instance, const char *realm,
4053                         krb5_principal *princ);
4054
4055 /**
4056  * Convert a Kerberos V5 principal to a Kerberos V4 principal.
4057  *
4058  * @param [in]  context         Library context
4059  * @param [in]  princ           V5 Principal
4060  * @param [out] name            V4 principal's name to be filled in
4061  * @param [out] inst            V4 principal's instance name to be filled in
4062  * @param [out] realm           Principal's realm name to be filled in
4063  *
4064  * This function separates a V5 principal @a princ into @a name, @a instance,
4065  * and @a realm.
4066  *
4067  * @retval
4068  *  0  Success
4069  * @retval
4070  *  KRB5_INVALID_PRINCIPAL   Invalid principal name
4071  * @retval
4072  *  KRB5_CONFIG_CANTOPEN     Can't open or find Kerberos configuration file
4073  * @return
4074  * Kerberos error codes
4075  */
4076 krb5_error_code KRB5_CALLCONV
4077 krb5_524_conv_principal(krb5_context context, krb5_const_principal princ,
4078                         char *name, char *inst, char *realm);
4079 /**
4080  *@deprecated
4081  */
4082 struct credentials;
4083
4084 /**
4085  * Convert a Kerberos V5 credentials to a Kerberos V4 credentials
4086  *
4087  * @note Not implemented
4088  *
4089  * @retval KRB524_KRB4_DISABLED (always)
4090  */
4091 int KRB5_CALLCONV
4092 krb5_524_convert_creds(krb5_context context, krb5_creds *v5creds,
4093                        struct credentials *v4creds);
4094
4095 #if KRB5_DEPRECATED
4096 #define krb524_convert_creds_kdc krb5_524_convert_creds
4097 #define krb524_init_ets(x) (0)
4098 #endif
4099
4100 /* libkt.spec */
4101
4102 /**
4103  * Get a handle for a key table.
4104  *
4105  * @param [in]  context         Library context
4106  * @param [in]  name            Name of the key table
4107  * @param [out] ktid            Key table handle
4108  *
4109  * Resolve the key table name @a name and fill in a handle identifying the key
4110  * table.  The key table is not opened.
4111  *
4112  * @note @a name must be of the form @c type:residual, where @a type must be a
4113  * type known to the library and @a residual portion should be specific to the
4114  * particular keytab type.
4115  *
4116  * @sa krb5_kt_close()
4117  *
4118  * @code
4119  *  Example: krb5_kt_resolve(context, "FILE:/tmp/filename",&ktid);
4120  * @endcode
4121  *
4122  * @retval
4123  * 0  Success
4124  * @return
4125  * Kerberos error codes
4126  */
4127 krb5_error_code KRB5_CALLCONV
4128 krb5_kt_resolve(krb5_context context, const char *name, krb5_keytab *ktid);
4129
4130 /**
4131  * Get default key table name.
4132  *
4133  * @param [in]     context      Library context
4134  * @param [in,out] name         Key table name to be resolved
4135  * @param [in]     name_size    Size of @a name to return
4136  *
4137  * Fill @a name with the first @a name_size bytes of the name of the default
4138  * key table for the current user.
4139  *
4140  * @sa MAX_KEYTAB_NAME_LEN
4141  *
4142  * @retval
4143  * 0 Success
4144  * @retval
4145  * KRB5_CONFIG_NOTENUFSPACE Buffer is too short
4146  * @return
4147  * Kerberos error codes
4148  */
4149 krb5_error_code KRB5_CALLCONV
4150 krb5_kt_default_name(krb5_context context, char *name, int name_size);
4151
4152 /**
4153  * Resolve default key table.
4154  *
4155  * @param [in]  context         Library context
4156  * @param [in,out] id           Key table handle
4157  *
4158  * Fill @a keytab with the default key table's @a handle.
4159  *
4160  * @retval
4161  * 0  Success
4162  * @return
4163  * Kerberos error codes
4164  */
4165 krb5_error_code KRB5_CALLCONV
4166 krb5_kt_default(krb5_context context, krb5_keytab *id);
4167
4168 /**
4169  * Free the contents of a key table entry.
4170  *
4171  * @param [in] context          Library context
4172  * @param [in] entry            Key table entry whose contents are to be freed
4173  *
4174  * @note The pointer is not freed.
4175  *
4176  * @retval 0  Success; otherwise - Kerberos error codes
4177  */
4178 krb5_error_code KRB5_CALLCONV
4179 krb5_free_keytab_entry_contents(krb5_context context, krb5_keytab_entry *entry);
4180
4181 /** @deprecated Use krb5_free_keytab_entry_contents instead. */
4182 krb5_error_code KRB5_CALLCONV
4183 krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *entry);
4184
4185
4186 /* remove and add are functions, so that they can return NOWRITE
4187    if not a writable keytab */
4188
4189 /**
4190  * Remove an entry from a key table.
4191  *
4192  * @param [in] context          Library context
4193  * @param [in] id               Key table handle
4194  * @param [in] entry            Entry to remove from key table
4195  *
4196  * @retval
4197  * 0 Success
4198  * @retval
4199  *  KRB5_KT_NOWRITE     Key table is not writable
4200  * @return
4201  * Kerberos error codes
4202  */
4203 krb5_error_code KRB5_CALLCONV
4204 krb5_kt_remove_entry(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry);
4205
4206 /**
4207  * Add a new entry to a key table.
4208  *
4209  * @param [in] context          Library context
4210  * @param [in] id               Key table handle
4211  * @param [in] entry            Entry to be added
4212  *
4213  * @retval
4214  * 0  Success
4215  * @retval
4216  *  ENOMEM    Insufficient memory
4217  * @retval
4218  *  KRB5_KT_NOWRITE  Key table is not writeable
4219  * @return
4220  * Kerberos error codes
4221  */
4222 krb5_error_code KRB5_CALLCONV
4223 krb5_kt_add_entry(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry);
4224
4225 /**
4226  * Convert a principal name into the default salt for that principal.
4227  *
4228  * @param [in]  context         Library context
4229  * @param [in]  pr              Principal name
4230  * @param [out] ret             Default salt for @a pr to be filled in
4231  *
4232  * @retval 0 Success; otherwise - Kerberos error codes
4233  */
4234 krb5_error_code KRB5_CALLCONV_WRONG
4235 krb5_principal2salt(krb5_context context,
4236                     register krb5_const_principal pr, krb5_data *ret);
4237 /* librc.spec--see rcache.h */
4238
4239 /* libcc.spec */
4240
4241 /**
4242  * Resolve a credential cache name.
4243  *
4244  * @param [in]  context         Library context
4245  * @param [in]  name            Credential cache name to be resolved
4246  * @param [out] cache           Credential cache handle
4247  *
4248  * Fills in @a cache with a @a cache handle that corresponds to the name in @a
4249  * name.  @a name should be of the form @c type:residual, and @a type must be a
4250  * type known to the library.  If the @a name does not contain a colon,
4251  * interpret it as a file name.
4252  *
4253  * @code
4254  * Example: krb5_cc_resolve(context, "MEMORY:C_", &cache);
4255  * @endcode
4256  *
4257  * @retval
4258  * 0  Success
4259  * @return
4260  * Kerberos error codes
4261  */
4262 krb5_error_code KRB5_CALLCONV
4263 krb5_cc_resolve(krb5_context context, const char *name, krb5_ccache *cache);
4264
4265 /**
4266  * Duplicate ccache handle.
4267  *
4268  * @param [in]  context         Library context
4269  * @param [in]  in              Credential cache handle to be duplicated
4270  * @param [out] out             Credential cache handle
4271  *
4272  * Create a new handle referring to the same cache as @a in.
4273  * The new handle and @a in can be closed independently.
4274  */
4275 krb5_error_code KRB5_CALLCONV
4276 krb5_cc_dup(krb5_context context, krb5_ccache in, krb5_ccache *out);
4277
4278 /**
4279  * Return the name of the default credential cache.
4280  *
4281  * @param [in] context          Library context
4282  *
4283  * Try the environment variable KRB5CCNAME first then, if it is not set,
4284  * fall back on the default ccache name for the OS.
4285  *
4286  * @return
4287  * Name of default credential cache for the current user.
4288  */
4289 const char *KRB5_CALLCONV
4290 krb5_cc_default_name(krb5_context context);
4291
4292 /**
4293  * Set the default credential cache name.
4294  *
4295  * @param [in,out]  context     Library context
4296  * @param [in]      name        Default credential cache name
4297  *
4298  * This function frees the old default credential cache name and then sets it
4299  * to @a name.
4300  *
4301  * @retval
4302  *  0  Success
4303  * @retval
4304  *  KV5M_CONTEXT          Bad magic number for @c _krb5_context structure
4305  * @return
4306  * Kerberos error codes
4307  */
4308 krb5_error_code KRB5_CALLCONV
4309 krb5_cc_set_default_name(krb5_context context, const char *name);
4310
4311 /**
4312  * Resolve the default crendentials cache name.
4313  *
4314  * @param [in,out] context      Library context
4315  * @param [out]    ccache       Pointer to credential cache name
4316  *
4317  * @retval
4318  * 0  Success
4319  * @retval
4320  * KV5M_CONTEXT            Bad magic number for @c _krb5_context structure
4321  * @retval
4322  * KRB5_FCC_INTERNAL       The name of the default credential cache cannot be
4323  *                         obtained
4324  * @return
4325  * Kerberos error codes
4326  */
4327 krb5_error_code KRB5_CALLCONV
4328 krb5_cc_default(krb5_context context, krb5_ccache *ccache);
4329
4330 /**
4331  * Copy a credential cache.
4332  *
4333  * @param [in]  context         Library context
4334  * @param [in]  incc            Credential cache to be copied
4335  * @param [out] outcc           Copy of credential cache to be filled in
4336  *
4337  * @retval 0  Success; otherwise - Kerberos error codes
4338  */
4339 krb5_error_code KRB5_CALLCONV
4340 krb5_cc_copy_creds(krb5_context context, krb5_ccache incc, krb5_ccache outcc);
4341
4342 /**
4343  * Get a configuration value from a credential cache.
4344  *
4345  * @param [in]     context      Library context
4346  * @param [in]     id           Credential cache handle
4347  * @param [in]     principal    Configuration for this principal;
4348  *                              if NULL, global for the whole cache
4349  * @param [in]     key          Name of config variable
4350  * @param [out]    data         Data to be fetched
4351  *
4352  * Use krb5_free_data_contents() to free @a data when it is no longer needed.
4353  *
4354  * @retval
4355  * 0  Success
4356  * @return
4357  * Kerberos error codes
4358  */
4359 krb5_error_code KRB5_CALLCONV
4360 krb5_cc_get_config(krb5_context context, krb5_ccache id,
4361                    krb5_const_principal principal,
4362                    const char *key, krb5_data *data);
4363
4364 /**
4365  * Store a configuration value in a credential cache.
4366  *
4367  * @param [in]     context      Library context
4368  * @param [in]     id           Credential cache handle
4369  * @param [in]     principal    Configuration for a specific principal;
4370  *                              if NULL, global for the whole cache
4371  * @param [in]     key          Name of config variable
4372  * @param [in]     data         Data to store, or NULL to remove
4373  *
4374  * @note Existing configuration under the same key is over-written.
4375  *
4376  * @warning Before version 1.10 @a data was assumed to be always non-null.
4377  *
4378  * @retval
4379  * 0  Success
4380  * @return
4381  * Kerberos error codes
4382  */
4383 krb5_error_code KRB5_CALLCONV
4384 krb5_cc_set_config(krb5_context context, krb5_ccache id,
4385                    krb5_const_principal principal,
4386                    const char *key, krb5_data *data);
4387
4388 /**
4389  * Test whether a principal is a configuration principal.
4390  *
4391  * @param [in] context          Library context
4392  * @param [in] principal        Principal to check
4393  *
4394  * @return
4395  * @c TRUE if the principal is a configuration principal (generated part of
4396  * krb5_cc_set_config()); @c FALSE otherwise.
4397  */
4398 krb5_boolean KRB5_CALLCONV
4399 krb5_is_config_principal(krb5_context context, krb5_const_principal principal);
4400
4401 /**
4402  * Make a credential cache the primary cache for its collection.
4403  *
4404  * @param [in] context          Library context
4405  * @param [in] cache            Credential cache handle
4406  *
4407  * If the type of @a cache supports it, set @a cache to be the primary
4408  * credential cache for the collection it belongs to.
4409  *
4410  * @retval
4411  * 0  Success, or the type of @a cache doesn't support switching
4412  * @return
4413  * Kerberos error codes
4414  */
4415 krb5_error_code KRB5_CALLCONV
4416 krb5_cc_switch(krb5_context context, krb5_ccache cache);
4417
4418 /**
4419  * Determine whether a credential cache type supports switching.
4420  *
4421  * @param [in] context          Library context
4422  * @param [in] type             Credential cache type
4423  *
4424  * @retval TRUE if @a type supports switching
4425  * @retval FALSE if it does not or is not a valid credential cache type.
4426  */
4427 krb5_boolean KRB5_CALLCONV
4428 krb5_cc_support_switch(krb5_context context, const char *type);
4429
4430 /**
4431  * Find a credential cache with a specified client principal.
4432  *
4433  * @param [in]  context         Library context
4434  * @param [in]  client          Client principal
4435  * @param [out] cache_out       Credential cache handle
4436  *
4437  * Find a cache within the collection whose default principal is @a client.
4438  * Use @a krb5_cc_close to close @a ccache when it is no longer needed.
4439  *
4440  * @retval 0 Success
4441  * @retval KRB5_CC_NOTFOUND
4442  *
4443  * @sa krb5_cccol_cursor_new
4444  */
4445 krb5_error_code KRB5_CALLCONV
4446 krb5_cc_cache_match(krb5_context context, krb5_principal client,
4447                     krb5_ccache *cache_out);
4448
4449 /**
4450  * Select a credential cache to use with a server principal.
4451  *
4452  * @param [in]  context         Library context
4453  * @param [in]  server          Server principal
4454  * @param [out] cache_out       Credential cache handle
4455  * @param [out] princ_out       Client principal
4456  *
4457  * Select a cache within the collection containing credentials most appropriate
4458  * for use with @a server, according to configured rules and heuristics.
4459  *
4460  * Use krb5_cc_close() to release @a cache_out when it is no longer needed.
4461  * Use krb5_free_principal() to release @a princ_out when it is no longer
4462  * needed.  Note that @a princ_out is set in some error conditions.
4463  *
4464  * @return
4465  * If an appropriate cache is found, 0 is returned, @a cache_out is set to the
4466  * selected cache, and @a princ_out is set to the default principal of that
4467  * cache.
4468  *
4469  * If the appropriate client principal can be authoritatively determined but
4470  * the cache collection contains no credentials for that principal, then
4471  * KRB5_CC_NOTFOUND is returned, @a cache_out is set to NULL, and @a princ_out
4472  * is set to the appropriate client principal.
4473  *
4474  * If no configured mechanism can determine the appropriate cache or principal,
4475  * KRB5_CC_NOTFOUND is returned and @a cache_out and @a princ_out are set to
4476  * NULL.
4477  *
4478  * Any other error code indicates a fatal error in the processing of a cache
4479  * selection mechanism.
4480  */
4481 krb5_error_code KRB5_CALLCONV
4482 krb5_cc_select(krb5_context context, krb5_principal server,
4483                krb5_ccache *cache_out, krb5_principal *princ_out);
4484
4485 /* krb5_free.c */
4486 /**
4487  * Free the storage assigned to a principal.
4488  *
4489  * @param [in] context          Library context
4490  * @param [in] val              Principal to be freed
4491  */
4492 void KRB5_CALLCONV
4493 krb5_free_principal(krb5_context context, krb5_principal val);
4494
4495 /**
4496  * Free a krb5_authenticator structure.
4497  *
4498  * @param [in] context          Library context
4499  * @param [in] val              Authenticator structure to be freed
4500  *
4501  * This function frees the contents of @a val and the structure itself.
4502  */
4503 void KRB5_CALLCONV
4504 krb5_free_authenticator(krb5_context context, krb5_authenticator *val);
4505
4506 /**
4507  * Free the data stored in array of addresses.
4508  *
4509  * @param [in] context          Library context
4510  * @param [in] val              Array of addresses to be freed
4511  *
4512  * This function frees the contents of @a val and the array itself.
4513  *
4514  * @note The last entry in the array must be a NULL pointer.
4515  */
4516 void KRB5_CALLCONV
4517 krb5_free_addresses(krb5_context context, krb5_address **val);
4518
4519 /**
4520  * Free the storage assigned to array of authentication data.
4521  *
4522  * @param [in] context          Library context
4523  * @param [in] val              Array of authentication data to be freed
4524  *
4525  * This function frees the contents of @a val and the array itself.
4526  *
4527  * @note The last entry in the array must be a NULL pointer.
4528  */
4529 void KRB5_CALLCONV
4530 krb5_free_authdata(krb5_context context, krb5_authdata **val);
4531
4532 /**
4533  * Free a ticket.
4534  *
4535  * @param [in] context          Library context
4536  * @param [in] val              Ticket to be freed
4537  *
4538  * This function frees the contents of @a val and the structure itself.
4539  */
4540 void KRB5_CALLCONV
4541 krb5_free_ticket(krb5_context context, krb5_ticket *val);
4542
4543 /**
4544  * Free an error allocated by krb5_read_error() or krb5_sendauth().
4545  *
4546  * @param [in] context          Library context
4547  * @param [in] val              Error data structure to be freed
4548  *
4549  * This function frees the contents of @a val and the structure itself.
4550  */
4551 void KRB5_CALLCONV
4552 krb5_free_error(krb5_context context, register krb5_error *val);
4553
4554 /**
4555  * Free a krb5_creds structure.
4556  *
4557  * @param [in] context          Library context
4558  * @param [in] val              Credential structure to be freed.
4559  *
4560  * This function frees the contents of @a val and the structure itself.
4561  */
4562 void KRB5_CALLCONV
4563 krb5_free_creds(krb5_context context, krb5_creds *val);
4564
4565 /**
4566  * Free the contents of a krb5_creds structure.
4567  *
4568  * @param [in] context          Library context
4569  * @param [in] val              Credential structure to free contents of
4570  *
4571  * This function frees the contents of @a val, but not the structure itself.
4572  */
4573 void KRB5_CALLCONV
4574 krb5_free_cred_contents(krb5_context context, krb5_creds *val);
4575
4576 /**
4577  * Free a krb5_checksum structure.
4578  *
4579  * @param [in] context          Library context
4580  * @param [in] val              Checksum structure to be freed
4581  *
4582  * This function frees the contents of @a val and the structure itself.
4583  */
4584 void KRB5_CALLCONV
4585 krb5_free_checksum(krb5_context context, register krb5_checksum *val);
4586
4587 /**
4588  * Free the contents of a krb5_checksum structure.
4589  *
4590  * @param [in] context          Library context
4591  * @param [in] val              Checksum structure to free contents of
4592  *
4593  * This function frees the contents of @a val, but not the structure itself.
4594  */
4595 void KRB5_CALLCONV
4596 krb5_free_checksum_contents(krb5_context context, register krb5_checksum *val);
4597
4598 /**
4599  * Free a krb5_keyblock structure.
4600  *
4601  * @param [in] context          Library context
4602  * @param [in] val              Keyblock to be freed
4603  *
4604  * This function frees the contents of @a val and the structure itself.
4605  */
4606 void KRB5_CALLCONV
4607 krb5_free_keyblock(krb5_context context, register krb5_keyblock *val);
4608
4609 /**
4610  * Free the contents of a krb5_keyblock structure.
4611  *
4612  * @param [in] context          Library context
4613  * @param [in] key              Keyblock to be freed
4614  *
4615  * This function frees the contents of @a key, but not the structure itself.
4616  */
4617 void KRB5_CALLCONV
4618 krb5_free_keyblock_contents(krb5_context context, register krb5_keyblock *key);
4619
4620 /**
4621  * Free a krb5_ap_rep_enc_part structure.
4622  *
4623  * @param [in] context          Library context
4624  * @param [in] val              AP-REP enc part to be freed
4625  *
4626  * This function frees the contents of @a val and the structure itself.
4627  */
4628 void KRB5_CALLCONV
4629 krb5_free_ap_rep_enc_part(krb5_context context, krb5_ap_rep_enc_part *val);
4630
4631 /**
4632  * Free a krb5_data structure.
4633  *
4634  * @param [in] context          Library context
4635  * @param [in] val              Data structure to be freed
4636  *
4637  * This function frees the contents of @a val and the structure itself.
4638  */
4639 void KRB5_CALLCONV
4640 krb5_free_data(krb5_context context, krb5_data *val);
4641
4642 /**
4643  * Free storage associated with a @c krb5_octet_data structure and its pointer.
4644  *
4645  * @param [in] context          Context structure
4646  * @param [in] val              Data structure to be freed
4647  *
4648  * @return
4649  * None
4650  */
4651 void KRB5_CALLCONV
4652 krb5_free_octet_data(krb5_context context, krb5_octet_data *val);
4653
4654 /**
4655  * Free the contents of a krb5_data structure and zero the data field.
4656  *
4657  * @param [in] context          Library context
4658  * @param [in] val              Data structure to free contents of
4659  *
4660  * This function frees the contents of @a val, but not the structure itself.
4661  */
4662 void KRB5_CALLCONV
4663 krb5_free_data_contents(krb5_context context, krb5_data *val);
4664
4665 /**
4666  * Free a string representation of a principal.
4667  *
4668  * @param [in] context          Library context
4669  * @param [in] val              Name string to be freed
4670  */
4671 void KRB5_CALLCONV
4672 krb5_free_unparsed_name(krb5_context context, char *val);
4673
4674 /**
4675  * Free a string allocated by a krb5 function.
4676  *
4677  * @param [in] context          Library context
4678  * @param [in] val              String to be freed
4679  */
4680 void KRB5_CALLCONV
4681 krb5_free_string(krb5_context context, char *val);
4682
4683 /**
4684  * Free an array of checksum types.
4685  *
4686  * @param [in] context          Library context
4687  * @param [in] val              Array of checksum types to be freed
4688  */
4689 void KRB5_CALLCONV
4690 krb5_free_cksumtypes(krb5_context context, krb5_cksumtype *val);
4691
4692 /* From krb5/os, but needed by the outside world */
4693 /**
4694  * Retrieve the system time of day, in sec and ms, since the epoch.
4695  *
4696  * @param [in]  context         Library context
4697  * @param [out] seconds         System timeofday, seconds portion
4698  * @param [out] microseconds    System timeofday, microseconds portion
4699  *
4700  * This function retrieves the system time of day with the context
4701  * specific time offset adjustment.
4702  *
4703  * @sa krb5_crypto_us_timeofday()
4704  *
4705  * @retval
4706  * 0  Success
4707  * @return
4708  * Kerberos error codes
4709  */
4710 krb5_error_code KRB5_CALLCONV
4711 krb5_us_timeofday(krb5_context context,
4712                   krb5_timestamp *seconds, krb5_int32 *microseconds);
4713
4714 /**
4715  * Retrieve the current time with context specific time offset adjustment.
4716  *
4717  * @param [in]     context      Library context
4718  * @param [in,out] timeret      Timestamp to fill in
4719  *
4720  * This function retrieves the system time of day with the context specific
4721  * time offset adjustment.
4722  *
4723  * @retval
4724  * 0  Success
4725  * @return
4726  * Kerberos error codes
4727  */
4728 krb5_error_code KRB5_CALLCONV
4729 krb5_timeofday(krb5_context context, register krb5_timestamp *timeret);
4730
4731 /**
4732  * Return all interface addresses for this host.
4733  *
4734  * @param [in]  context         Library context
4735  * @param [out] addr            Array of krb5_address pointers, ending with
4736  *                              NULL
4737  *
4738  * Use krb5_free_addresses() to free @a addr when it is no longer needed.
4739  *
4740  * @retval 0 Success; otherwise - Kerberos error codes
4741  */
4742 krb5_error_code KRB5_CALLCONV
4743 krb5_os_localaddr(krb5_context context, krb5_address ***addr);
4744
4745 /**
4746  * Retrieve the default realm.
4747  *
4748  * @param [in]  context         Library context
4749  * @param [out] lrealm          Default realm name
4750  *
4751  * Retrieves the default realm to be used if no user-specified realm is
4752  * available.
4753  *
4754  * Use krb5_free_default_realm() to free @a lrealm when it is no longer needed.
4755  *
4756  * @retval
4757  * 0  Success
4758  * @return
4759  * Kerberos error codes
4760  */
4761 krb5_error_code KRB5_CALLCONV
4762 krb5_get_default_realm(krb5_context context, char **lrealm);
4763
4764 /**
4765  * Override the default realm for the specified context.
4766  *
4767  * @param [in]     context      Library context
4768  * @param [in]     lrealm       Realm name for the default realm
4769  *
4770  * If @a lrealm is NULL, clear the default realm setting.
4771  *
4772  * @retval
4773  * 0  Success
4774  * @return
4775  * Kerberos error codes
4776  */
4777 krb5_error_code KRB5_CALLCONV
4778 krb5_set_default_realm(krb5_context context, const char *lrealm);
4779
4780 /**
4781  * Free a default realm string returned by krb5_get_default_realm().
4782  *
4783  * @param [in] context          Library context
4784  * @param [in] lrealm           Realm to be freed
4785  */
4786 void KRB5_CALLCONV
4787 krb5_free_default_realm(krb5_context context, char *lrealm);
4788
4789 /**
4790  * Generate a full principal name from a service name.
4791  *
4792  * @param [in]  context         Library context
4793  * @param [in]  hostname        Host name, or NULL to use local host
4794  * @param [in]  sname           Service name, or NULL to use @c "host"
4795  * @param [in]  type            Principal type
4796  * @param [out] ret_princ       Generated principal
4797  *
4798  * This function converts a @a hostname and @a sname into @a krb5_principal
4799  * structure @a ret_princ.  The returned principal will be of the form @a
4800  * sname\/hostname\@REALM where REALM is determined by krb5_get_host_realm().
4801  * In some cases this may be the referral (empty) realm.
4802  *
4803  * The @a type can be one of the following:
4804  *
4805  * @li #KRB5_NT_SRV_HOST canonicalizes the host name before looking up the
4806  * realm and generating the principal.
4807  *
4808  * @li #KRB5_NT_UNKNOWN accepts the hostname as given, and does not
4809  * canonicalize it.
4810  *
4811  * Use krb5_free_principal to free @a ret_princ when it is no longer needed.
4812  *
4813  * @retval
4814  * 0  Success
4815  * @return
4816  * Kerberos error codes
4817  */
4818 krb5_error_code KRB5_CALLCONV
4819 krb5_sname_to_principal(krb5_context context, const char *hostname, const char *sname,
4820                         krb5_int32 type, krb5_principal *ret_princ);
4821
4822 /**
4823  * Test whether a principal matches a matching principal.
4824  *
4825  * @param [in]  context         Library context
4826  * @param [in]  matching        Matching principal
4827  * @param [in]  princ           Principal to test
4828  *
4829  * @note A matching principal is a host-based principal with an empty realm
4830  * and/or second data component (hostname).  Profile configuration may cause
4831  * the hostname to be ignored even if it is present.  A principal matches a
4832  * matching principal if the former has the same non-empty (and non-ignored)
4833  * components of the latter.
4834  *
4835  * If @a matching is NULL, return TRUE.  If @a matching is not a matching
4836  * principal, return the value of krb5_principal_compare(context, matching,
4837  * princ).
4838  *
4839  * @return
4840  * TRUE if @a princ matches @a matching, FALSE otherwise.
4841  */
4842 krb5_boolean KRB5_CALLCONV
4843 krb5_sname_match(krb5_context context, krb5_const_principal matching,
4844                  krb5_const_principal princ);
4845
4846 /**
4847  * Change a password for an existing Kerberos account.
4848  *
4849  * @param [in]  context             Library context
4850  * @param [in]  creds               Credentials for kadmin/changepw service
4851  * @param [in]  newpw               New password
4852  * @param [out] result_code         Numeric error code from server
4853  * @param [out] result_code_string  String equivalent to @a result_code
4854  * @param [out] result_string       Change password response from the KDC
4855  *
4856  * Change the password for the existing principal identified by @a creds.
4857  *
4858  * The possible values of the output @a result_code are:
4859  *
4860  * @li #KRB5_KPASSWD_SUCCESS   (0) - success
4861  * @li #KRB5_KPASSWD_MALFORMED (1) - Malformed request error
4862  * @li #KRB5_KPASSWD_HARDERROR (2) - Server error
4863  * @li #KRB5_KPASSWD_AUTHERROR (3) - Authentication error
4864  * @li #KRB5_KPASSWD_SOFTERROR (4) - Password change rejected
4865  *
4866  * @retval 0 Success; otherwise - Kerberos error codes
4867  */
4868 krb5_error_code KRB5_CALLCONV
4869 krb5_change_password(krb5_context context, krb5_creds *creds, char *newpw,
4870                      int *result_code, krb5_data *result_code_string,
4871                      krb5_data *result_string);
4872
4873 /**
4874  * Set a password for a principal using specified credentials.
4875  *
4876  * @param [in]  context              Library context
4877  * @param [in]  creds                Credentials for kadmin/changepw service
4878  * @param [in]  newpw                New password
4879  * @param [in]  change_password_for  Change the password for this principal
4880  * @param [out] result_code          Numeric error code from server
4881  * @param [out] result_code_string   String equivalent to @a result_code
4882  * @param [out] result_string        Data returned from the remote system
4883  *
4884  * This function uses the credentials @a creds to set the password @a newpw for
4885  * the principal @a change_password_for.  It implements the set password
4886  * operation of RFC 3244, for interoperability with Microsoft Windows
4887  * implementations.
4888  *
4889  * @note If @a change_password_for is NULL, the change is performed on the
4890  * current principal. If @a change_password_for is non-null, the change is
4891  * performed on the principal name passed in @a change_password_for.
4892  *
4893  * The error code and strings are returned in @a result_code,
4894  * @a result_code_string and @a result_string.
4895  *
4896  * @sa krb5_set_password_using_ccache()
4897  *
4898  * @retval
4899  * 0  Success and result_code is set to #KRB5_KPASSWD_SUCCESS.
4900  * @return
4901  * Kerberos error codes.
4902  */
4903 krb5_error_code KRB5_CALLCONV
4904 krb5_set_password(krb5_context context, krb5_creds *creds, char *newpw,
4905                   krb5_principal change_password_for, int *result_code,
4906                   krb5_data *result_code_string, krb5_data *result_string);
4907
4908 /**
4909  * Set a password for a principal using cached credentials.
4910  *
4911  * @param [in]  context              Library context
4912  * @param [in]  ccache               Credential cache
4913  * @param [in]  newpw                New password
4914  * @param [in]  change_password_for  Change the password for this principal
4915  * @param [out] result_code          Numeric error code from server
4916  * @param [out] result_code_string   String equivalent to @a result_code
4917  * @param [out] result_string        Data returned from the remote system
4918  *
4919  * This function uses the cached credentials from @a ccache to set the password
4920  * @a newpw for the principal @a change_password_for.  It implements RFC 3244
4921  * set password operation (interoperable with MS Windows implementations) using
4922  * the credential cache.
4923  *
4924  * The error code and strings are returned in @a result_code,
4925  * @a result_code_string and @a result_string.
4926  *
4927  * @note If @a change_password_for is set to NULL, the change is performed on
4928  * the default principal in @a ccache. If @a change_password_for is non null,
4929  * the change is performed on the specified principal.
4930  *
4931  * @sa krb5_set_password()
4932  *
4933  * @retval
4934  * 0  Success
4935  * @return
4936  * Kerberos error codes
4937  */
4938 krb5_error_code KRB5_CALLCONV
4939 krb5_set_password_using_ccache(krb5_context context, krb5_ccache ccache,
4940                                char *newpw, krb5_principal change_password_for,
4941                                int *result_code, krb5_data *result_code_string,
4942                                krb5_data *result_string);
4943
4944 /**
4945  * Retrieve configuration profile from the context.
4946  *
4947  * @param [in]  context         Library context
4948  * @param [out] profile         Pointer to data read from a configuration file
4949  *
4950  * This function creates a new @a profile object that reflects profile
4951  * in the supplied @a context.
4952  *
4953  * The @a profile object may be freed with profile_release() function.
4954  * See profile.h and profile API for more details.
4955  *
4956  * @retval
4957  * 0 Success
4958  * @return
4959  * Kerberos error codes
4960  */
4961 krb5_error_code KRB5_CALLCONV
4962 krb5_get_profile(krb5_context context, struct _profile_t ** profile);
4963
4964 #if KRB5_DEPRECATED
4965 /** @deprecated Replaced by krb5_get_init_creds_password().*/
4966 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
4967 krb5_get_in_tkt_with_password(krb5_context context, krb5_flags options,
4968                               krb5_address *const *addrs, krb5_enctype *ktypes,
4969                               krb5_preauthtype *pre_auth_types,
4970                               const char *password, krb5_ccache ccache,
4971                               krb5_creds *creds, krb5_kdc_rep **ret_as_reply);
4972
4973 /** @deprecated Replaced by krb5_get_init_creds(). */
4974 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
4975 krb5_get_in_tkt_with_skey(krb5_context context, krb5_flags options,
4976                           krb5_address *const *addrs, krb5_enctype *ktypes,
4977                           krb5_preauthtype *pre_auth_types,
4978                           const krb5_keyblock *key, krb5_ccache ccache,
4979                           krb5_creds *creds, krb5_kdc_rep **ret_as_reply);
4980
4981 /** @deprecated Replaced by krb5_get_init_creds_keytab(). */
4982 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
4983 krb5_get_in_tkt_with_keytab(krb5_context context, krb5_flags options,
4984                             krb5_address *const *addrs, krb5_enctype *ktypes,
4985                             krb5_preauthtype *pre_auth_types,
4986                             krb5_keytab arg_keytab, krb5_ccache ccache,
4987                             krb5_creds *creds, krb5_kdc_rep **ret_as_reply);
4988
4989 #endif /* KRB5_DEPRECATED */
4990
4991 /**
4992  * Parse and decrypt a @c KRB_AP_REQ message.
4993  *
4994  * @param [in]     context        Library context
4995  * @param [in,out] auth_context   Pre-existing or newly created auth context
4996  * @param [in]     inbuf          AP-REQ message to be parsed
4997  * @param [in]     server         Matching principal for server, or NULL to
4998  *                                allow any principal in keytab
4999  * @param [in]     keytab         Key table, or NULL to use the default
5000  * @param [out]    ap_req_options If non-null, the AP-REQ flags on output
5001  * @param [out]    ticket         If non-null, ticket from the AP-REQ message
5002  *
5003  * This function parses, decrypts and verifies a AP-REQ message from @a inbuf
5004  * and stores the authenticator in @a auth_context.
5005  *
5006  * If a keyblock is present in the @a auth_context, it is used to decrypt the
5007  * ticket in AP-REQ message. (This is useful for user-to-user authentication.)
5008  * Otherwise, the decryption key is obtained from the @a keytab.  If @a keytab
5009  * is iterable, all of its key entries it will be tried against the ticket;
5010  * otherwise, the server principal in the ticket will be looked up in the
5011  * keytab and that key will be tried.
5012  *
5013  * The client specified in the decrypted authenticator must match the client
5014  * specified in the decrypted ticket.  If @a server is non-null, the key in
5015  * which the ticket is encrypted must correspond to a principal in @a keytab
5016  * matching @a server according to the rules of krb5_sname_match().
5017  *
5018  * If the @a remote_addr field of @a auth_context is set, the request must come
5019  * from that address.
5020  *
5021  * If a replay cache handle is provided in the @a auth_context, the
5022  * authenticator and ticket are verified against it.  If no conflict is found,
5023  * the new authenticator is then stored in the replay cash of @a auth_context.
5024  *
5025  * Various other checks are performed on the decoded data, including
5026  * cross-realm policy, clockskew, and ticket validation times.
5027  *
5028  * On success the authenticator, subkey, and remote sequence number of the
5029  * request are stored in @a auth_context. If the #AP_OPTS_MUTUAL_REQUIRED
5030  * bit is set, the local sequence number is XORed with the remote sequence
5031  * number in the request.
5032  *
5033  * Use krb5_free_ticket() to free @a ticket when it is no longer needed.
5034  *
5035  * @retval 0 Success; otherwise - Kerberos error codes
5036  */
5037 krb5_error_code KRB5_CALLCONV
5038 krb5_rd_req(krb5_context context, krb5_auth_context *auth_context,
5039             const krb5_data *inbuf, krb5_const_principal server,
5040             krb5_keytab keytab, krb5_flags *ap_req_options,
5041             krb5_ticket **ticket);
5042
5043 /**
5044  * Retrieve a service key from a key table.
5045  *
5046  * @param [in]  context     Library context
5047  * @param [in]  keyprocarg  Name of a key table (NULL to use default name)
5048  * @param [in]  principal   Service principal
5049  * @param [in]  vno         Key version number (0 for highest available)
5050  * @param [in]  enctype     Encryption type (0 for any type)
5051  * @param [out] key         Service key from key table
5052  *
5053  * Open and search the specified key table for the entry identified by @a
5054  * principal, @a enctype, and @a vno. If no key is found, return an error code.
5055  *
5056  * The default key table is used, unless @a keyprocarg is non-null.
5057  * @a keyprocarg designates a specific key table.
5058  *
5059  * Use krb5_free_keyblock() to free @a key when it is no longer needed.
5060  *
5061  * @retval
5062  * 0 Success
5063  * @return Kerberos error code if not found or @a keyprocarg is invalid.
5064  */
5065 krb5_error_code KRB5_CALLCONV
5066 krb5_kt_read_service_key(krb5_context context, krb5_pointer keyprocarg,
5067                          krb5_principal principal, krb5_kvno vno,
5068                          krb5_enctype enctype, krb5_keyblock **key);
5069
5070 /**
5071  * Format a @c KRB-SAFE message.
5072  *
5073  * @param [in]     context      Library context
5074  * @param [in,out] auth_context Authentication context
5075  * @param [in]     userdata     User data in the message
5076  * @param [out]    outbuf       Formatted @c KRB-SAFE buffer
5077  * @param [out]    outdata      Replay data. Specify NULL if not needed
5078  *
5079  * This function creates an integrity protected @c KRB-SAFE message
5080  * using data supplied by the application.
5081  *
5082  * Fields in @a auth_context specify the checksum type, the keyblock that
5083  * can be used to seed the checksum, full addresses (host and port) for
5084  * the sender and receiver, and @ref KRB5_AUTH_CONTEXT flags.
5085  *
5086  * The local address in @a auth_context must be set, and is used to form the
5087  * sender address used in the KRB-SAFE message.  The remote address is
5088  * optional; if specified, it will be used to form the receiver address used in
5089  * the message.
5090  *
5091  * If #KRB5_AUTH_CONTEXT_DO_TIME flag is set in the @a auth_context, an entry
5092  * describing the message is entered in the replay cache @a
5093  * auth_context->rcache which enables the caller to detect if this message is
5094  * reflected by an attacker.  If #KRB5_AUTH_CONTEXT_DO_TIME is not set, the
5095  * replay cache is not used.
5096  *
5097  * If either #KRB5_AUTH_CONTEXT_DO_SEQUENCE or
5098  * #KRB5_AUTH_CONTEXT_RET_SEQUENCE is set, the @a auth_context local sequence
5099  * number will be placed in @a outdata as its sequence number.
5100  *
5101  * @note The @a outdata argument is required if #KRB5_AUTH_CONTEXT_RET_TIME or
5102  *       #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in the @a auth_context.
5103  *
5104  * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed.
5105  *
5106  * @retval 0 Success; otherwise - Kerberos error codes
5107  */
5108 krb5_error_code KRB5_CALLCONV
5109 krb5_mk_safe(krb5_context context, krb5_auth_context auth_context,
5110              const krb5_data *userdata, krb5_data *outbuf,
5111              krb5_replay_data *outdata);
5112
5113 /**
5114  * Format a @c KRB-PRIV message.
5115  *
5116  * @param [in]     context      Library context
5117  * @param [in,out] auth_context Authentication context
5118  * @param [in]     userdata     User data for @c KRB-PRIV message
5119  * @param [out]    outbuf       Formatted @c KRB-PRIV message
5120  * @param [out]    outdata      Replay cache handle (NULL if not needed)
5121  *
5122  * This function is similar to krb5_mk_safe(), but the message is encrypted and
5123  * integrity-protected, not just integrity-protected.
5124  *
5125  * The local address in @a auth_context must be set, and is used to form the
5126  * sender address used in the KRB-SAFE message.  The remote address is
5127  * optional; if specified, it will be used to form the receiver address used in
5128  * the message.
5129  *
5130  * @note If the #KRB5_AUTH_CONTEXT_RET_TIME or
5131  * #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in @a auth_context, the @a
5132  * outdata is required.
5133  *
5134  * @note The flags from @a auth_context specify whether sequence numbers or
5135  * timestamps will be used to identify the message.  Valid values are:
5136  *
5137  * @li #KRB5_AUTH_CONTEXT_DO_TIME      - Use timestamps in @a outdata
5138  * @li #KRB5_AUTH_CONTEXT_RET_TIME     - Copy timestamp to @a outdata.
5139  * @li #KRB5_AUTH_CONTEXT_DO_SEQUENCE  - Use local sequence numbers from
5140  *                                       @a auth_context in replay cache.
5141  * @li #KRB5_AUTH_CONTEXT_RET_SEQUENCE - Use local sequence numbers from
5142  *                                       @a auth_context as a sequence number
5143  *                                       in the encrypted message @a outbuf.
5144  *
5145  * @retval 0 Success; otherwise - Kerberos error codes
5146  */
5147 krb5_error_code KRB5_CALLCONV
5148 krb5_mk_priv(krb5_context context, krb5_auth_context auth_context,
5149              const krb5_data *userdata, krb5_data *outbuf,
5150              krb5_replay_data *outdata);
5151
5152 /**
5153  * Client function for @c sendauth protocol.
5154  *
5155  * @param [in]     context        Library context
5156  * @param [in,out] auth_context   Authentication context
5157  * @param [in]     fd             File descriptor that describes network socket
5158  * @param [in]     appl_version   Application protocol version to be matched
5159  *                                with the receiver's application version
5160  * @param [in]     client         Client principal
5161  * @param [in]     server         Server principal
5162  * @param [in]     ap_req_options @ref AP_OPTS options
5163  * @param [in]     in_data        Data to be sent to the server
5164  * @param [in]     in_creds       Input credentials, or NULL to use @a ccache
5165  * @param [in]     ccache         Credential cache
5166  * @param [out]    error          If non-null, contains KRB_ERROR message
5167  *                                returned from server
5168  * @param [out]    rep_result     If non-null and @a ap_req_options is
5169  *                                #AP_OPTS_MUTUAL_REQUIRED, contains the result
5170  *                                of mutual authentication exchange
5171  * @param [out]    out_creds      If non-null, the retrieved credentials
5172  *
5173  * This function performs the client side of a sendauth/recvauth exchange by
5174  * sending and receiving messages over @a fd.
5175  *
5176  * Credentials may be specified in three ways:
5177  *
5178  * @li If @a in_creds is NULL, credentials are obtained with
5179  * krb5_get_credentials() using the principals @a client and @a server.  @a
5180  * server must be non-null; @a client may NULL to use the default principal of
5181  * @a ccache.
5182  *
5183  * @li If @a in_creds is non-null, but does not contain a ticket, credentials
5184  * for the exchange are obtained with krb5_get_credentials() using @a in_creds.
5185  * In this case, the values of @a client and @a server are unused.
5186  *
5187  * @li If @a in_creds is a complete credentials structure, it used directly.
5188  * In this case, the values of @a client, @a server, and @a ccache are unused.
5189  *
5190  * If the server is using a different application protocol than that specified
5191  * in @a appl_version, an error will be returned.
5192  *
5193  * Use krb5_free_creds() to free @a out_creds, krb5_free_ap_rep_enc_part() to
5194  * free @a rep_result, and krb5_free_error() to free @a error when they are no
5195  * longer needed.
5196  *
5197  * @sa krb5_recvauth()
5198  *
5199  * @retval 0 Success; otherwise - Kerberos error codes
5200  */
5201 krb5_error_code KRB5_CALLCONV
5202 krb5_sendauth(krb5_context context, krb5_auth_context *auth_context,
5203               krb5_pointer fd, char *appl_version, krb5_principal client,
5204               krb5_principal server, krb5_flags ap_req_options,
5205               krb5_data *in_data, krb5_creds *in_creds, krb5_ccache ccache,
5206               krb5_error **error, krb5_ap_rep_enc_part **rep_result,
5207               krb5_creds **out_creds);
5208
5209 /**
5210  * Server function for @a sendauth protocol.
5211  *
5212  * @param [in]     context      Library context
5213  * @param [in,out] auth_context Authentication context
5214  * @param [in]     fd           File descriptor
5215  * @param [in]     appl_version Application protocol version to be matched
5216  *                              against the client's application version
5217  * @param [in]     server       Server principal (NULL for any in @a keytab)
5218  * @param [in]     flags        Additional specifications
5219  * @param [in]     keytab       Key table containing service keys
5220  * @param [out]    ticket       Ticket (NULL if not needed)
5221  *
5222  * This function performs the srever side of a sendauth/recvauth exchange by
5223  * sending and receiving messages over @a fd.
5224  *
5225  * Use krb5_free_ticket() to free @a ticket when it is no longer needed.
5226  *
5227  * @sa krb5_sendauth()
5228  *
5229  * @retval 0 Success; otherwise - Kerberos error codes
5230  */
5231 krb5_error_code KRB5_CALLCONV
5232 krb5_recvauth(krb5_context context, krb5_auth_context *auth_context,
5233               krb5_pointer fd, char *appl_version, krb5_principal server,
5234               krb5_int32 flags, krb5_keytab keytab, krb5_ticket **ticket);
5235
5236 /**
5237  * Server function for @a sendauth protocol with version parameter.
5238  *
5239  * @param [in]     context      Library context
5240  * @param [in,out] auth_context Authentication context
5241  * @param [in]     fd           File descriptor
5242  * @param [in]     server       Server principal (NULL for any in @a keytab)
5243  * @param [in]     flags        Additional specifications
5244  * @param [in]     keytab       Decryption key
5245  * @param [out]    ticket       Ticket (NULL if not needed)
5246  * @param [out]    version      sendauth protocol version (NULL if not needed)
5247  *
5248  * This function is similar to krb5_recvauth() with the additional output
5249  * information place into @a version.
5250  *
5251  * @retval 0 Success; otherwise - Kerberos error codes
5252  */
5253 krb5_error_code KRB5_CALLCONV
5254 krb5_recvauth_version(krb5_context context,
5255                       krb5_auth_context *auth_context,
5256                       krb5_pointer fd,
5257                       krb5_principal server,
5258                       krb5_int32 flags,
5259                       krb5_keytab keytab,
5260                       krb5_ticket **ticket,
5261                       krb5_data *version);
5262
5263 /**
5264  * Format a @c KRB-CRED message for an array of credentials.
5265  *
5266  * @param [in]     context      Library context
5267  * @param [in,out] auth_context Authentication context
5268  * @param [in]     ppcreds      Null-terminated array of credentials
5269  * @param [out]    ppdata       Encoded credentials
5270  * @param [out]    outdata      Replay cache information (NULL if not needed)
5271  *
5272  * This function takes an array of credentials @a ppcreds and formats
5273  * a @c KRB-CRED message @a ppdata to pass to krb5_rd_cred().
5274  *
5275  * @note If the #KRB5_AUTH_CONTEXT_RET_TIME or #KRB5_AUTH_CONTEXT_RET_SEQUENCE
5276  *       flag is set in @a auth_context, @a outdata is required.
5277  *
5278  * The message will be encrypted using the send subkey of @a auth_context if it
5279  * is present, or the session key otherwise.
5280  *
5281  * @retval
5282  *  0 Success
5283  * @retval
5284  *  ENOMEM Insufficient memory
5285  * @retval
5286  *   KRB5_RC_REQUIRED Message replay detection requires @a rcache parameter
5287  * @return
5288  * Kerberos error codes
5289  */
5290 krb5_error_code KRB5_CALLCONV
5291 krb5_mk_ncred(krb5_context context, krb5_auth_context auth_context,
5292               krb5_creds **ppcreds, krb5_data **ppdata,
5293               krb5_replay_data *outdata);
5294
5295 /**
5296  * Format a @c KRB-CRED message for a single set of credentials.
5297  *
5298  * @param [in]     context      Library context
5299  * @param [in,out] auth_context Authentication context
5300  * @param [in]     pcreds       Pointer to credentials
5301  * @param [out]    ppdata       Encoded credentials
5302  * @param [out]    outdata      Replay cache data (NULL if not needed)
5303  *
5304  * This is a convenience function that calls krb5_mk_ncred() with a single set
5305  * of credentials.
5306  *
5307  * @retval
5308  * 0 Success
5309  * @retval
5310  *  ENOMEM Insufficient memory
5311  * @retval
5312  *  KRB5_RC_REQUIRED   Message replay detection requires @a rcache parameter
5313  * @return
5314  * Kerberos error codes
5315  */
5316 krb5_error_code KRB5_CALLCONV
5317 krb5_mk_1cred(krb5_context context, krb5_auth_context auth_context,
5318               krb5_creds *pcreds, krb5_data **ppdata,
5319               krb5_replay_data *outdata);
5320
5321 /**
5322  * Read and validate a @c KRB-CRED message.
5323  *
5324  * @param [in]     context      Library context
5325  * @param [in,out] auth_context Authentication context
5326  * @param [in]     pcreddata    @c KRB-CRED message
5327  * @param [out]    pppcreds     Null-terminated array of forwarded credentials
5328  * @param [out]    outdata      Replay data (NULL if not needed)
5329  *
5330  * @note The @a outdata argument is required if #KRB5_AUTH_CONTEXT_RET_TIME or
5331  *       #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in the @a auth_context.`
5332  *
5333  * @a pcreddata will be decrypted using the receiving subkey if it is present
5334  * in @a auth_context, or the session key if the receiving subkey is not
5335  * present or fails to decrypt the message.
5336  *
5337  * Use krb5_free_tgt_creds() to free @a pppcreds when it is no longer needed.
5338  *
5339  * @retval 0 Success; otherwise - Kerberos error codes
5340  */
5341 krb5_error_code KRB5_CALLCONV
5342 krb5_rd_cred(krb5_context context, krb5_auth_context auth_context,
5343              krb5_data *pcreddata, krb5_creds ***pppcreds,
5344              krb5_replay_data *outdata);
5345
5346 /**
5347  * Get a forwarded TGT and format a @c KRB-CRED message.
5348  *
5349  * @param [in] context          Library context
5350  * @param [in] auth_context     Authentication context
5351  * @param [in] rhost            Remote host
5352  * @param [in] client           Client principal of TGT
5353  * @param [in] server           Principal of server to receive TGT
5354  * @param [in] cc               Credential cache handle (NULL to use default)
5355  * @param [in] forwardable      Whether TGT should be forwardable
5356  * @param [out] outbuf          KRB-CRED message
5357  *
5358  * Get a TGT for use at the remote host @a rhost and format it into a KRB-CRED
5359  * message.  If @a rhost is NULL and @a server is of type #KRB5_NT_SRV_HST,
5360  * the second component of @a server will be used.
5361  *
5362  * @retval
5363  *  0 Success
5364  * @retval
5365  *   ENOMEM Insufficient memory
5366  * @retval
5367  *   KRB5_PRINC_NOMATCH Requested principal and ticket do not match
5368  * @retval
5369  *   KRB5_NO_TKT_SUPPLIED Request did not supply a ticket
5370  * @retval
5371  *   KRB5_CC_BADNAME Credential cache name or principal name malformed
5372  * @return
5373  * Kerberos error codes
5374  */
5375 krb5_error_code KRB5_CALLCONV
5376 krb5_fwd_tgt_creds(krb5_context context, krb5_auth_context auth_context,
5377                    char *rhost, krb5_principal client, krb5_principal server,
5378                    krb5_ccache cc, int forwardable, krb5_data *outbuf);
5379
5380 /**
5381  * Create and initialize an authentication context.
5382  *
5383  * @param [in]  context         Library context
5384  * @param [out] auth_context    Authentication context
5385  *
5386  * This function creates an authentication context to hold configuration and
5387  * state relevant to krb5 functions for authenticating principals and
5388  * protecting messages once authentication has occurred.
5389  *
5390  * By default, flags for the context are set to enable the use of the replay
5391  * cache (#KRB5_AUTH_CONTEXT_DO_TIME), but not sequence numbers.  Use
5392  * krb5_auth_con_setflags() to change the flags.
5393  *
5394  * The allocated @a auth_context must be freed with krb5_auth_con_free() when
5395  * it is no longer needed.
5396  *
5397  * @retval 0 Success; otherwise - Kerberos error codes
5398  */
5399 krb5_error_code KRB5_CALLCONV
5400 krb5_auth_con_init(krb5_context context, krb5_auth_context *auth_context);
5401
5402 /**
5403  * Free a krb5_auth_context structure.
5404  *
5405  * @param [in] context          Library context
5406  * @param [in] auth_context     Authentication context to be freed
5407  *
5408  * This function frees an auth context allocated by krb5_auth_con_init().
5409  *
5410  * @retval 0  (always)
5411  */
5412 krb5_error_code KRB5_CALLCONV
5413 krb5_auth_con_free(krb5_context context, krb5_auth_context auth_context);
5414
5415 /**
5416  * Set a flags field in a krb5_auth_context structure.
5417  *
5418  * @param [in]     context      Library context
5419  * @param [in,out] auth_context Authentication context
5420  * @param [in]     flags        Flags bit mask
5421  *
5422  * Valid values for @a flags are:
5423  * @li #KRB5_AUTH_CONTEXT_DO_TIME Use timestamps
5424  * @li #KRB5_AUTH_CONTEXT_RET_TIME Save timestamps
5425  * @li #KRB5_AUTH_CONTEXT_DO_SEQUENCE Use sequence numbers
5426  * @li #KRB5_AUTH_CONTEXT_RET_SEQUENCE Save sequence numbers
5427  *
5428  * @retval 0 (always)
5429  */
5430 krb5_error_code KRB5_CALLCONV
5431 krb5_auth_con_setflags(krb5_context context, krb5_auth_context auth_context, krb5_int32 flags);
5432
5433 /**
5434  * Retrieve flags from a krb5_auth_context structure.
5435  *
5436  * @param [in]  context         Library context
5437  * @param [in]  auth_context    Authentication context
5438  * @param [out] flags           Flags bit mask
5439  *
5440  * Valid values for @a flags are:
5441  * @li #KRB5_AUTH_CONTEXT_DO_TIME Use timestamps
5442  * @li #KRB5_AUTH_CONTEXT_RET_TIME Save timestamps
5443  * @li #KRB5_AUTH_CONTEXT_DO_SEQUENCE Use sequence numbers
5444  * @li #KRB5_AUTH_CONTEXT_RET_SEQUENCE Save sequence numbers
5445  *
5446  * @retval 0 (always)
5447  */
5448 krb5_error_code KRB5_CALLCONV
5449 krb5_auth_con_getflags(krb5_context context, krb5_auth_context auth_context,
5450                        krb5_int32 *flags);
5451
5452 /**
5453  * Set a checksum callback in an auth context.
5454  *
5455  * @param [in] context          Library context
5456  * @param [in] auth_context     Authentication context
5457  * @param [in] func             Checksum callback
5458  * @param [in] data             Callback argument
5459  *
5460  * Set a callback to obtain checksum data in krb5_mk_req().  The callback will
5461  * be invoked after the subkey and local sequence number are stored in @a
5462  * auth_context.
5463  *
5464  * @retval 0 (always)
5465  */
5466 krb5_error_code KRB5_CALLCONV
5467 krb5_auth_con_set_checksum_func( krb5_context context,
5468                                  krb5_auth_context  auth_context,
5469                                  krb5_mk_req_checksum_func func,
5470                                  void *data);
5471
5472 /**
5473  * Get the checksum callback from an auth context.
5474  *
5475  * @param [in]  context         Library context
5476  * @param [in]  auth_context    Authentication context
5477  * @param [out] func            Checksum callback
5478  * @param [out] data            Callback argument
5479  *
5480  * @retval 0 (always)
5481  */
5482 krb5_error_code KRB5_CALLCONV
5483 krb5_auth_con_get_checksum_func( krb5_context context,
5484                                  krb5_auth_context auth_context,
5485                                  krb5_mk_req_checksum_func *func,
5486                                  void **data);
5487
5488 /**
5489  * Set the local and remote addresses in an auth context.
5490  *
5491  * @param [in] context          Library context
5492  * @param [in] auth_context     Authentication context
5493  * @param [in] local_addr       Local address
5494  * @param [in] remote_addr      Remote address
5495  *
5496  * This function releases the storage assigned to the contents of the local and
5497  * remote addresses of @a auth_context and then sets them to @a local_addr and
5498  * @a remote_addr respectively.
5499  *
5500  * @sa krb5_auth_con_genaddrs()
5501  *
5502  * @retval 0 Success; otherwise - Kerberos error codes
5503  */
5504 krb5_error_code KRB5_CALLCONV_WRONG
5505 krb5_auth_con_setaddrs(krb5_context context, krb5_auth_context auth_context,
5506                        krb5_address *local_addr, krb5_address *remote_addr);
5507
5508 /**
5509  * Retrieve address fields from an auth context.
5510  *
5511  * @param [in]  context         Library context
5512  * @param [in]  auth_context    Authentication context
5513  * @param [out] local_addr      Local address (NULL if not needed)
5514  * @param [out] remote_addr     Remote address (NULL if not needed)
5515  *
5516  * @retval 0 Success; otherwise - Kerberos error codes
5517  */
5518 krb5_error_code KRB5_CALLCONV
5519 krb5_auth_con_getaddrs(krb5_context context, krb5_auth_context auth_context,
5520                        krb5_address **local_addr, krb5_address **remote_addr);
5521
5522 /**
5523  * Set local and remote port fields in an auth context.
5524  *
5525  * @param [in] context          Library context
5526  * @param [in] auth_context     Authentication context
5527  * @param [in] local_port       Local port
5528  * @param [in] remote_port      Remote port
5529  *
5530  * This function releases the storage assigned to the contents of the local and
5531  * remote ports of @a auth_context and then sets them to @a local_port and @a
5532  * remote_port respectively.
5533  *
5534  * @sa krb5_auth_con_genaddrs()
5535  *
5536  * @retval 0 Success; otherwise - Kerberos error codes
5537  */
5538 krb5_error_code KRB5_CALLCONV
5539 krb5_auth_con_setports(krb5_context context, krb5_auth_context auth_context,
5540                        krb5_address *local_port, krb5_address *remote_port);
5541
5542 /**
5543  * Set the session key in an auth context.
5544  *
5545  * @param [in] context          Library context
5546  * @param [in] auth_context     Authentication context
5547  * @param [in] keyblock         User key
5548  *
5549  * @retval 0 Success; otherwise - Kerberos error codes
5550  */
5551 krb5_error_code KRB5_CALLCONV
5552 krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context,
5553                              krb5_keyblock *keyblock);
5554
5555 /**
5556  * Retrieve the session key from an auth context as a keyblock.
5557  *
5558  * @param [in]  context         Library context
5559  * @param [in]  auth_context    Authentication context
5560  * @param [out] keyblock        Session key
5561  *
5562  * This function creates a keyblock containing the session key from @a
5563  * auth_context.  Use krb5_free_keyblock() to free @a keyblock when it is no
5564  * longer needed
5565  *
5566  * @retval 0 Success. Otherwise - Kerberos error codes
5567  */
5568 krb5_error_code KRB5_CALLCONV
5569 krb5_auth_con_getkey(krb5_context context, krb5_auth_context auth_context,
5570                      krb5_keyblock **keyblock);
5571
5572 /**
5573  * Retrieve the session key from an auth context.
5574  *
5575  * @param [in]  context         Library context
5576  * @param [in]  auth_context    Authentication context
5577  * @param [out] key             Session key
5578  *
5579  * This function sets @a key to the session key from @a auth_context.  Use
5580  * krb5_k_free_key() to release @a key when it is no longer needed.
5581  *
5582  * @retval 0 (always)
5583  */
5584 krb5_error_code KRB5_CALLCONV
5585 krb5_auth_con_getkey_k(krb5_context context, krb5_auth_context auth_context,
5586                        krb5_key *key);
5587
5588 /**
5589  * Retrieve the send subkey from an auth context as a keyblock.
5590  *
5591  * @param [in]  ctx             Library context
5592  * @param [in]  ac              Authentication context
5593  * @param [out] keyblock        Send subkey
5594  *
5595  * This function creates a keyblock containing the send subkey from @a
5596  * auth_context.  Use krb5_free_keyblock() to free @a keyblock when it is no
5597  * longer needed.
5598  *
5599  * @retval 0 Success; otherwise - Kerberos error codes
5600  */
5601 krb5_error_code KRB5_CALLCONV
5602 krb5_auth_con_getsendsubkey(krb5_context ctx, krb5_auth_context ac, krb5_keyblock **keyblock);
5603
5604 /**
5605  * Retrieve the send subkey from an auth context.
5606  *
5607  * @param [in]  ctx             Library context
5608  * @param [in]  ac              Authentication context
5609  * @param [out] key             Send subkey
5610  *
5611  * This function sets @a key to the send subkey from @a auth_context.  Use
5612  * krb5_k_free_key() to release @a key when it is no longer needed.
5613  *
5614  * @retval 0 Success; otherwise - Kerberos error codes
5615  */
5616 krb5_error_code KRB5_CALLCONV
5617 krb5_auth_con_getsendsubkey_k(krb5_context ctx, krb5_auth_context ac,
5618                               krb5_key *key);
5619
5620 /**
5621  * Retrieve the receiving subkey from an auth context as a keyblock.
5622  *
5623  * @param [in]  ctx             Library context
5624  * @param [in]  ac              Authentication context
5625  * @param [out] keyblock        Receiving subkey
5626  *
5627  * This function creates a keyblock containing the receiving subkey from @a
5628  * auth_context.  Use krb5_free_keyblock() to free @a keyblock when it is no
5629  * longer needed.
5630  *
5631  * @retval 0 Success; otherwise - Kerberos error codes
5632  */
5633 krb5_error_code KRB5_CALLCONV
5634 krb5_auth_con_getrecvsubkey(krb5_context ctx, krb5_auth_context ac, krb5_keyblock **keyblock);
5635
5636 /**
5637  * Retrieve the receiving subkey from an auth context as a keyblock.
5638  *
5639  * @param [in]  ctx             Library context
5640  * @param [in]  ac              Authentication context
5641  * @param [out] key             Receiving subkey
5642  *
5643  * This function sets @a key to the receiving subkey from @a auth_context.  Use
5644  * krb5_k_free_key() to release @a key when it is no longer needed.
5645  *
5646  * @retval 0 Success; otherwise - Kerberos error codes
5647  */
5648 krb5_error_code KRB5_CALLCONV
5649 krb5_auth_con_getrecvsubkey_k(krb5_context ctx, krb5_auth_context ac, krb5_key *key);
5650
5651 /**
5652  * Set the send subkey in an auth context with a keyblock.
5653  *
5654  * @param [in] ctx              Library context
5655  * @param [in] ac               Authentication context
5656  * @param [in] keyblock         Send subkey
5657  *
5658  * This function sets the send subkey in @a ac to a copy of @a keyblock.
5659  *
5660  * @retval 0 Success. Otherwise - Kerberos error codes
5661  */
5662 krb5_error_code KRB5_CALLCONV
5663 krb5_auth_con_setsendsubkey(krb5_context ctx, krb5_auth_context ac,
5664                             krb5_keyblock *keyblock);
5665
5666 /**
5667  * Set the send subkey in an auth context.
5668  *
5669  * @param [in]  ctx             Library context
5670  * @param [in]  ac              Authentication context
5671  * @param [out] key             Send subkey
5672  *
5673  * This function sets the send subkey in @a ac to @a key, incrementing its
5674  * reference count.
5675  *
5676  * @retval 0 Success; otherwise - Kerberos error codes
5677  */
5678 krb5_error_code KRB5_CALLCONV
5679 krb5_auth_con_setsendsubkey_k(krb5_context ctx, krb5_auth_context ac, krb5_key key);
5680
5681 /**
5682  * Set the receiving subkey in an auth context with a keyblock.
5683  *
5684  * @param [in] ctx              Library context
5685  * @param [in] ac               Authentication context
5686  * @param [in] keyblock         Receiving subkey
5687  *
5688  * This function sets the receiving subkey in @a ac to a copy of @a keyblock.
5689  *
5690  * @retval 0 Success; otherwise - Kerberos error codes
5691  */
5692 krb5_error_code KRB5_CALLCONV
5693 krb5_auth_con_setrecvsubkey(krb5_context ctx, krb5_auth_context ac,
5694                             krb5_keyblock *keyblock);
5695
5696 /**
5697  * Set the receiving subkey in an auth context.
5698  *
5699  * @param [in] ctx              Library context
5700  * @param [in] ac               Authentication context
5701  * @param [in] key              Receiving subkey
5702  *
5703  * This function sets the receiving subkey in @a ac to @a key, incrementing its
5704  * reference count.
5705  *
5706  * @retval 0 Success; otherwise - Kerberos error codes
5707  */
5708 krb5_error_code KRB5_CALLCONV
5709 krb5_auth_con_setrecvsubkey_k(krb5_context ctx, krb5_auth_context ac,
5710                               krb5_key key);
5711
5712 #if KRB5_DEPRECATED
5713 /** @deprecated Replaced by krb5_auth_con_getsendsubkey(). */
5714 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
5715 krb5_auth_con_getlocalsubkey(krb5_context context, krb5_auth_context auth_context,
5716                              krb5_keyblock **keyblock);
5717
5718 /** @deprecated Replaced by krb5_auth_con_getrecvsubkey(). */
5719 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
5720 krb5_auth_con_getremotesubkey(krb5_context context, krb5_auth_context auth_context,
5721                               krb5_keyblock **keyblock);
5722 #endif
5723
5724 /**
5725  * Retrieve the local sequence number from an auth context.
5726  *
5727  * @param [in]  context         Library context
5728  * @param [in]  auth_context    Authentication context
5729  * @param [out] seqnumber       Local sequence number
5730  *
5731  * Retrieve the local sequence number from @a auth_context and return it in @a
5732  * seqnumber.  The #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag must be set in @a
5733  * auth_context for this function to be useful.
5734  *
5735  * @retval 0 Success; otherwise - Kerberos error codes
5736  */
5737 krb5_error_code KRB5_CALLCONV
5738 krb5_auth_con_getlocalseqnumber(krb5_context context, krb5_auth_context auth_context,
5739                                 krb5_int32 *seqnumber);
5740
5741 /**
5742  * Retrieve the remote sequence number from an auth context.
5743  *
5744  * @param [in]  context         Library context
5745  * @param [in]  auth_context    Authentication context
5746  * @param [out] seqnumber       Remote sequence number
5747  *
5748  * Retrieve the remote sequence number from @a auth_context and return it in @a
5749  * seqnumber.  The #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag must be set in @a
5750  * auth_context for this function to be useful.
5751  *
5752  * @retval 0 Success; otherwise - Kerberos error codes
5753  */
5754 krb5_error_code KRB5_CALLCONV
5755 krb5_auth_con_getremoteseqnumber(krb5_context context, krb5_auth_context auth_context,
5756                                  krb5_int32 *seqnumber);
5757
5758 #if KRB5_DEPRECATED
5759 /** @deprecated Not replaced.
5760  *
5761  * RFC 4120 doesn't have anything like the initvector concept;
5762  * only really old protocols may need this API.
5763  */
5764 KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV
5765 krb5_auth_con_initivector(krb5_context context, krb5_auth_context auth_context);
5766 #endif
5767
5768 /**
5769  * Set the replay cache in an auth context.
5770  *
5771  * @param [in] context          Library context
5772  * @param [in] auth_context     Authentication context
5773  * @param [in] rcache           Replay cache haddle
5774  *
5775  * This function sets the replay cache in @a auth_context to @a rcache.  @a
5776  * rcache will be closed when @a auth_context is freed, so the caller should
5777  * relinguish that responsibility.
5778  *
5779  * @retval 0 Success; otherwise - Kerberos error codes
5780  */
5781 krb5_error_code KRB5_CALLCONV
5782 krb5_auth_con_setrcache(krb5_context context, krb5_auth_context auth_context,
5783                         krb5_rcache rcache);
5784
5785 /**
5786  * Retrieve the replay cache from an auth context.
5787  *
5788  * @param [in]  context         Library context
5789  * @param [in]  auth_context    Authentication context
5790  * @param [out] rcache          Replay cache handle
5791  *
5792  * This function fetches the replay cache from @a auth_context.  The caller
5793  * should not close @a rcache.
5794  *
5795  * @retval 0 (always)
5796  */
5797 krb5_error_code KRB5_CALLCONV_WRONG
5798 krb5_auth_con_getrcache(krb5_context context, krb5_auth_context auth_context,
5799                         krb5_rcache *rcache);
5800
5801 /**
5802  * Retrieve the authenticator from an auth context.
5803  *
5804  * @param [in]  context         Library context
5805  * @param [in]  auth_context    Authentication context
5806  * @param [out] authenticator   Authenticator
5807  *
5808  * Use krb5_free_authenticator() to free @a authenticator when it is no longer
5809  * needed.
5810  *
5811  * @retval 0 Success. Otherwise - Kerberos error codes
5812  */
5813 krb5_error_code KRB5_CALLCONV
5814 krb5_auth_con_getauthenticator(krb5_context context, krb5_auth_context auth_context,
5815                                krb5_authenticator **authenticator);
5816
5817 /**
5818  * Set checksum type in an an auth context.
5819  *
5820  * @param [in] context          Library context
5821  * @param [in] auth_context     Authentication context
5822  * @param [in] cksumtype        Checksum type
5823  *
5824  * This function sets the checksum type in @a auth_context to be used by
5825  * krb5_mk_req() for the authenticator checksum.
5826  *
5827  * @retval 0 Success. Otherwise - Kerberos error codes
5828  */
5829 krb5_error_code KRB5_CALLCONV
5830 krb5_auth_con_set_req_cksumtype(krb5_context context, krb5_auth_context auth_context,
5831                                 krb5_cksumtype cksumtype);
5832
5833 #define KRB5_REALM_BRANCH_CHAR '.'
5834
5835 /*
5836  * end "func-proto.h"
5837  */
5838
5839 /*
5840  * begin stuff from libos.h
5841  */
5842
5843 /**
5844  * @brief Read a password from keyboard input.
5845  *
5846  * @param [in]     context      Library context
5847  * @param [in]     prompt       First user prompt when reading password
5848  * @param [in]     prompt2      Second user prompt (NULL to prompt only once)
5849  * @param [out]    return_pwd   Returned password
5850  * @param [in,out] size_return  On input, maximum size of password; on output,
5851  *                              size of password read
5852  *
5853  * This function reads a password from keyboard input and stores it in @a
5854  * return_pwd.  @a size_return should be set by the caller to the amount of
5855  * storage space available in @a return_pwd; on successful return, it will be
5856  * set to the length of the password read.
5857  *
5858  * @a prompt is printed to the terminal, followed by ": ", and then a password
5859  * is read from the keyboard.
5860  *
5861  * If @a prompt2 is NULL, the password is read only once.  Otherwise, @a
5862  * prompt2 is printed to the terminal and a second password is read.  If the
5863  * two passwords entered are not identical, KRB5_LIBOS_BADPWDMATCH is returned.
5864  *
5865  * Echoing is turned off when the password is read.
5866  *
5867  * @retval
5868  *  0   Success
5869  * @return
5870  * Error in reading or verifying the password
5871  * @return
5872  * Kerberos error codes
5873  */
5874 krb5_error_code KRB5_CALLCONV
5875 krb5_read_password(krb5_context context,
5876                    const char *prompt, const char *prompt2,
5877                    char *return_pwd, unsigned int *size_return);
5878
5879 /**
5880  * Convert a principal name to a local name.
5881  *
5882  * @param [in]  context         Library context
5883  * @param [in]  aname           Principal name
5884  * @param [in]  lnsize_in       Space available in @a lname
5885  * @param [out] lname           Local name buffer to be filled in
5886  *
5887  * If @a aname does not correspond to any local account, KRB5_LNAME_NOTRANS is
5888  * returned.  If @a lnsize_in is too small for the local name,
5889  * KRB5_CONFIG_NOTENUFSPACE is returned.
5890  *
5891  * Local names, rather than principal names, can be used by programs that
5892  * translate to an environment-specific name (for example, a user account
5893  * name).
5894  *
5895  * @retval
5896  * 0  Success
5897  * @retval
5898  *  System errors
5899  * @return
5900  * Kerberos error codes
5901  */
5902 krb5_error_code KRB5_CALLCONV
5903 krb5_aname_to_localname(krb5_context context, krb5_const_principal aname,
5904                         int lnsize_in, char *lname);
5905
5906 /**
5907  * Get the Kerberos realm names for a host.
5908  *
5909  * @param [in]  context         Library context
5910  * @param [in]  host            Host name (or NULL)
5911  * @param [out] realmsp         Null-terminated list of realm names
5912  *
5913  * Fill in @a realmsp with a pointer to a null-terminated list of realm names.
5914  * If there are no known realms for the host, a list containing the referral
5915  * (empty) realm is returned.
5916  *
5917  * If @a host is NULL, the local host's realms are determined.
5918  *
5919  * Use krb5_free_host_realm() to release @a realmsp when it is no longer
5920  * needed.
5921  *
5922  * @retval
5923  *  0   Success
5924  * @retval
5925  *  ENOMEM  Insufficient memory
5926  * @return
5927  * Kerberos error codes
5928  */
5929 krb5_error_code KRB5_CALLCONV
5930 krb5_get_host_realm(krb5_context context, const char *host, char ***realmsp);
5931
5932 /**
5933  *
5934  * @param [in] context           Library context
5935  * @param [in] hdata             Host name (or NULL)
5936  * @param [out] realmsp          Null-terminated list of realm names
5937  *
5938  * Fill in @a realmsp with a pointer to a null-terminated list of realm names
5939  * obtained through heuristics or insecure resolution methods which have lower
5940  * priority than KDC referrals.
5941  *
5942  * If @a host is NULL, the local host's realms are determined.
5943  *
5944  * Use krb5_free_host_realm() to release @a realmsp when it is no longer
5945  * needed.
5946  */
5947 krb5_error_code KRB5_CALLCONV
5948 krb5_get_fallback_host_realm(krb5_context context,
5949                              krb5_data *hdata, char ***realmsp);
5950
5951 /**
5952  * Free the memory allocated by krb5_get_host_realm().
5953  *
5954  * @param [in] context          Library context
5955  * @param [in] realmlist        List of realm names to be released
5956  *
5957  * @retval
5958  * 0  Success
5959  * @return
5960  * Kerberos error codes
5961  */
5962 krb5_error_code KRB5_CALLCONV
5963 krb5_free_host_realm(krb5_context context, char *const *realmlist);
5964
5965 /**
5966  * Determine if a principal is authorized to log in as a local user.
5967  *
5968  * @param [in] context          Library context
5969  * @param [in] principal        Principal name
5970  * @param [in] luser            Local username
5971  *
5972  * Determine whether @a principal is authorized to log in as a local user @a
5973  * luser.
5974  *
5975  * @retval
5976  * TRUE Principal is authorized to log in as user; FALSE otherwise.
5977  */
5978 krb5_boolean KRB5_CALLCONV
5979 krb5_kuserok(krb5_context context, krb5_principal principal, const char *luser);
5980
5981 /**
5982  * Generate auth context addresses from a connected socket.
5983  *
5984  * @param [in] context          Library context
5985  * @param [in] auth_context     Authentication context
5986  * @param [in] infd             Connected socket descriptor
5987  * @param [in] flags            Flags
5988  *
5989  * This function sets the local and/or remote addresses in @a auth_context
5990  * based on the local and remote endpoints of the socket @a infd.  The
5991  * following flags determine the operations performed:
5992  *
5993  * @li #KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR   Generate local address.
5994  * @li #KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR  Generate remote address.
5995  * @li #KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR  Generate local address and port.
5996  * @li #KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR Generate remote address and port.
5997  *
5998  * @retval 0 Success; otherwise - Kerberos error codes
5999  */
6000 krb5_error_code KRB5_CALLCONV
6001 krb5_auth_con_genaddrs(krb5_context context, krb5_auth_context auth_context,
6002                        int infd, int flags);
6003
6004 /**
6005  * Set time offset field in a krb5_context structure.
6006  *
6007  * @param [in] context          Library context
6008  * @param [in] seconds          Real time, seconds portion
6009  * @param [in] microseconds     Real time, microseconds portion
6010  *
6011  * This function sets the time offset in @a context to the difference between
6012  * the system time and the real time as determined by @a seconds and @a
6013  * microseconds.
6014  *
6015  * @retval 0 Success; otherwise - Kerberos error codes
6016  */
6017 krb5_error_code KRB5_CALLCONV
6018 krb5_set_real_time(krb5_context context, krb5_timestamp seconds,
6019                    krb5_int32 microseconds);
6020
6021 /**
6022  * Return the time offsets from the os context.
6023  *
6024  * @param [in]  context         Library context
6025  * @param [out] seconds         Time offset, seconds portion
6026  * @param [out] microseconds    Time offset, microseconds portion
6027  *
6028  * This function returns the time offsets in @a context.
6029  *
6030  * @retval 0  Success; otherwise - Kerberos error codes
6031  */
6032 krb5_error_code KRB5_CALLCONV
6033 krb5_get_time_offsets(krb5_context context, krb5_timestamp *seconds, krb5_int32 *microseconds);
6034
6035 /* str_conv.c */
6036 /**
6037  * Convert a string to an encryption type.
6038  *
6039  * @param [in]  string          String to convert to an encryption type
6040  * @param [out] enctypep        Encryption type
6041  *
6042  * @retval 0  Success; otherwise - EINVAL
6043  */
6044 krb5_error_code KRB5_CALLCONV
6045 krb5_string_to_enctype(char *string, krb5_enctype *enctypep);
6046
6047 /**
6048  * Convert a string to a salt type.
6049  *
6050  * @param [in]  string          String to convert to an encryption type
6051  * @param [out] salttypep       Salt type to be filled in
6052  *
6053  * @retval 0  Success; otherwise - EINVAL
6054  */
6055 krb5_error_code KRB5_CALLCONV
6056 krb5_string_to_salttype(char *string, krb5_int32 *salttypep);
6057
6058 /**
6059  * Convert a string to a checksum type.
6060  *
6061  * @param [in]  string          String to be converted
6062  * @param [out] cksumtypep      Checksum type to be filled in
6063  *
6064  * @retval 0  Success; otherwise - EINVAL
6065  */
6066 krb5_error_code KRB5_CALLCONV
6067 krb5_string_to_cksumtype(char *string, krb5_cksumtype *cksumtypep);
6068
6069 /**
6070  * Convert a string to a timestamp.
6071  *
6072  * @param [in]  string          String to be converted
6073  * @param [out] timestampp      Pointer to timestamp
6074  *
6075  * @retval 0  Success; otherwise - EINVAL
6076  */
6077 krb5_error_code KRB5_CALLCONV
6078 krb5_string_to_timestamp(char *string, krb5_timestamp *timestampp);
6079
6080 /**
6081  * Convert a string to a delta time value.
6082  *
6083  * @param [in]  string          String to be converted
6084  * @param [out] deltatp         Delta time to be filled in
6085  *
6086  * @retval 0  Success; otherwise - KRB5_DELTAT_BADFORMAT
6087  */
6088 krb5_error_code KRB5_CALLCONV
6089 krb5_string_to_deltat(char *string, krb5_deltat *deltatp);
6090
6091 /**
6092  * Convert an encryption type to a string.
6093  *
6094  * @param [in]  enctype         Encryption type
6095  * @param [out] buffer          Buffer to hold encryption type string
6096  * @param [in]  buflen          Storage available in @a buffer
6097  *
6098  * @retval 0  Success; otherwise - Kerberos error codes
6099  */
6100 krb5_error_code KRB5_CALLCONV
6101 krb5_enctype_to_string(krb5_enctype enctype, char *buffer, size_t buflen);
6102
6103 /**
6104  * Convert an encryption type to a name or alias.
6105  *
6106  * @param [in]  enctype         Encryption type
6107  * @param [in]  shortest        Flag
6108  * @param [out] buffer          Buffer to hold encryption type string
6109  * @param [in]  buflen          Storage available in @a buffer
6110  *
6111  * If @a shortest is FALSE, this function returns the enctype's canonical name
6112  * (like "aes128-cts-hmac-sha1-96").  If @a shortest is TRUE, it return the
6113  * enctype's shortest alias (like "aes128-cts").
6114  *
6115  * @retval 0  Success; otherwise - Kerberos error codes
6116  */
6117 krb5_error_code KRB5_CALLCONV
6118 krb5_enctype_to_name(krb5_enctype enctype, krb5_boolean shortest,
6119                      char *buffer, size_t buflen);
6120
6121 /**
6122  * Convert a salt type to a string.
6123  *
6124  * @param [in]  salttype        Salttype to convert
6125  * @param [out] buffer          Buffer to receive the converted string
6126  * @param [in]  buflen          Storage available in @a buffer
6127  *
6128  * @retval 0  Success; otherwise - Kerberos error codes
6129  */
6130 krb5_error_code KRB5_CALLCONV
6131 krb5_salttype_to_string(krb5_int32 salttype, char *buffer, size_t buflen);
6132
6133 /**
6134  * Convert a checksum type to a string.
6135  *
6136  * @param [in]  cksumtype       Checksum type
6137  * @param [out] buffer          Buffer to hold converted checksum type
6138  * @param [in]  buflen          Storage available in @a buffer
6139  *
6140  * @retval 0  Success; otherwise - Kerberos error codes
6141  */
6142 krb5_error_code KRB5_CALLCONV
6143 krb5_cksumtype_to_string(krb5_cksumtype cksumtype, char *buffer, size_t buflen);
6144
6145 /**
6146  * Convert a timestamp to a string.
6147  *
6148  * @param [in]  timestamp       Timestamp to convert
6149  * @param [out] buffer          Buffer to hold converted timestamp
6150  * @param [in]  buflen          Storage available in @a buffer
6151  *
6152  * The string is returned in the locale's appropriate date and time
6153  * representation.
6154  *
6155  * @retval 0  Success; otherwise - Kerberos error codes
6156  */
6157 krb5_error_code KRB5_CALLCONV
6158 krb5_timestamp_to_string(krb5_timestamp timestamp, char *buffer, size_t buflen);
6159
6160 /**
6161  * Convert a timestamp to a string, with optional output padding
6162  *
6163  * @param [in]  timestamp       Timestamp to convert
6164  * @param [out] buffer          Buffer to hold the converted timestamp
6165  * @param [in]  buflen          Length of buffer
6166  * @param [in]  pad             Optional value to pad @a buffer if converted
6167  *                              timestamp does not fill it
6168  *
6169  * If @a pad is not NULL, @a buffer is padded out to @a buflen - 1 characters
6170  * with the value of *@a pad.
6171  *
6172  * @retval 0  Success; otherwise - Kerberos error codes
6173  */
6174 krb5_error_code KRB5_CALLCONV
6175 krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer,
6176                            size_t buflen, char *pad);
6177
6178 /**
6179  * Convert a relative time value to a string.
6180  *
6181  * @param [in]  deltat          Relative time value to convert
6182  * @param [out] buffer          Buffer to hold time string
6183  * @param [in]  buflen          Storage available in @a buffer
6184  *
6185  * @retval 0  Success; otherwise - Kerberos error codes
6186  */
6187 krb5_error_code KRB5_CALLCONV
6188 krb5_deltat_to_string(krb5_deltat deltat, char *buffer, size_t buflen);
6189
6190 /* The name of the Kerberos ticket granting service... and its size */
6191 #define KRB5_TGS_NAME           "krbtgt"
6192 #define KRB5_TGS_NAME_SIZE      6
6193
6194 /* flags for recvauth */
6195 #define KRB5_RECVAUTH_SKIP_VERSION      0x0001
6196 #define KRB5_RECVAUTH_BADAUTHVERS       0x0002
6197 /* initial ticket api functions */
6198
6199 /** Text for prompt used in prompter callback function.  */
6200 typedef struct _krb5_prompt {
6201     char *prompt;      /**< The prompt to show to the user */
6202     int hidden;        /**< Boolean; informative prompt or hidden (e.g. PIN) */
6203     krb5_data *reply;  /**< Must be allocated before call to  prompt routine */
6204 } krb5_prompt;
6205
6206 /** Pointer to a prompter callback function. */
6207 typedef krb5_error_code
6208 (KRB5_CALLCONV *krb5_prompter_fct)(krb5_context context, void *data,
6209                                    const char *name, const char *banner,
6210                                    int num_prompts, krb5_prompt prompts[]);
6211
6212 /**
6213  * Prompt user for password.
6214  *
6215  * @param [in]     context      Library context
6216  * @param          data         Unused (callback argument)
6217  * @param [in]     name         Name to output during prompt
6218  * @param [in]     banner       Banner to output during prompt
6219  * @param [in]     num_prompts  Number of prompts in @a prompts
6220  * @param [in,out] prompts      Array of output prompts and replies
6221  *
6222  * This function is intended to be used as a prompter callback for
6223  * krb5_get_init_creds_password() or krb5_init_creds_init().
6224  *
6225  * Writes @a name and @a banner to stdout, each followed by a newline, then
6226  * writes each prompt field in the @a prompts array, followed by ": ", and sets
6227  * the reply field of the entry to a line of input read from stdin.  If the
6228  * hidden flag is set for a prompt, then terminal echoing is turned off when
6229  * input is read.
6230  *
6231  * @retval
6232  *  0   Success
6233  * @return
6234  * Kerberos error codes
6235  *
6236  */
6237 krb5_error_code KRB5_CALLCONV
6238 krb5_prompter_posix(krb5_context context, void *data, const char *name,
6239                     const char *banner, int num_prompts,
6240                     krb5_prompt prompts[]);
6241
6242 /** Store options for @c _krb5_get_init_creds */
6243 typedef struct _krb5_get_init_creds_opt {
6244     krb5_flags flags;
6245     krb5_deltat tkt_life;
6246     krb5_deltat renew_life;
6247     int forwardable;
6248     int proxiable;
6249     krb5_enctype *etype_list;
6250     int etype_list_length;
6251     krb5_address **address_list;
6252     krb5_preauthtype *preauth_list;
6253     int preauth_list_length;
6254     krb5_data *salt;
6255 } krb5_get_init_creds_opt;
6256
6257 #define KRB5_GET_INIT_CREDS_OPT_TKT_LIFE        0x0001
6258 #define KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE      0x0002
6259 #define KRB5_GET_INIT_CREDS_OPT_FORWARDABLE     0x0004
6260 #define KRB5_GET_INIT_CREDS_OPT_PROXIABLE       0x0008
6261 #define KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST      0x0010
6262 #define KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST    0x0020
6263 #define KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST    0x0040
6264 #define KRB5_GET_INIT_CREDS_OPT_SALT            0x0080
6265 #define KRB5_GET_INIT_CREDS_OPT_CHG_PWD_PRMPT   0x0100
6266 #define KRB5_GET_INIT_CREDS_OPT_CANONICALIZE    0x0200
6267 #define KRB5_GET_INIT_CREDS_OPT_ANONYMOUS       0x0400
6268
6269
6270 /**
6271  * Allocate a new initial credential options structure.
6272  *
6273  * @param [in]  context         Library context
6274  * @param [out] opt             New options structure
6275  *
6276  * This function is the preferred way to create an options structure for
6277  * getting initial credentials, and is required to make use of certain options.
6278  * Use krb5_get_init_creds_opt_free() to free @a opt when it is no longer
6279  * needed.
6280  *
6281  * @retval 0 - Success; Kerberos errors otherwise.
6282  */
6283 krb5_error_code KRB5_CALLCONV
6284 krb5_get_init_creds_opt_alloc(krb5_context context,
6285                               krb5_get_init_creds_opt **opt);
6286
6287 /**
6288  * Free initial credential options.
6289  *
6290  * @param [in] context          Library context
6291  * @param [in] opt              Options structure to free
6292  *
6293  * @sa krb5_get_init_creds_opt_alloc()
6294  */
6295 void KRB5_CALLCONV
6296 krb5_get_init_creds_opt_free(krb5_context context,
6297                              krb5_get_init_creds_opt *opt);
6298
6299 /** @deprecated Use krb5_get_init_creds_opt_alloc() instead. */
6300 void KRB5_CALLCONV
6301 krb5_get_init_creds_opt_init(krb5_get_init_creds_opt *opt);
6302
6303 /**
6304  * Set the ticket lifetime in initial credential options.
6305  *
6306  * @param [in] opt              Options structure
6307  * @param [in] tkt_life         Ticket lifetime
6308  */
6309 void KRB5_CALLCONV
6310 krb5_get_init_creds_opt_set_tkt_life(krb5_get_init_creds_opt *opt,
6311                                      krb5_deltat tkt_life);
6312
6313 /**
6314  * Set the ticket renewal lifetime in initial credential options.
6315  *
6316  * @param [in] opt              Pointer to @a options field
6317  * @param [in] renew_life       Ticket renewal lifetime
6318  */
6319 void KRB5_CALLCONV
6320 krb5_get_init_creds_opt_set_renew_life(krb5_get_init_creds_opt *opt,
6321                                        krb5_deltat renew_life);
6322
6323 /**
6324  * Set or unset the forwardable flag in initial credential options.
6325  *
6326  * @param [in] opt              Options structure
6327  * @param [in] forwardable      Whether credentials should be forwardable
6328  */
6329 void KRB5_CALLCONV
6330 krb5_get_init_creds_opt_set_forwardable(krb5_get_init_creds_opt *opt,
6331                                         int forwardable);
6332
6333 /**
6334  * Set or unset the proxiable flag in initial credential options.
6335  *
6336  * @param [in] opt              Options structure
6337  * @param [in] proxiable        Whether credentials should be proxiable
6338  */
6339 void KRB5_CALLCONV
6340 krb5_get_init_creds_opt_set_proxiable(krb5_get_init_creds_opt *opt,
6341                                       int proxiable);
6342
6343 /**
6344  * Set or unset the canonicalize flag in initial credential options.
6345  *
6346  * @param [in] opt              Options structure
6347  * @param [in] canonicalize     Whether to canonicalize client principal
6348  */
6349 void KRB5_CALLCONV
6350 krb5_get_init_creds_opt_set_canonicalize(krb5_get_init_creds_opt *opt,
6351                                          int canonicalize);
6352
6353 /**
6354  * Set or unset the anonymous flag in initial credential options.
6355  *
6356  * @param [in] opt              Options structure
6357  * @param [in] anonymous        Whether to make an anonymous request
6358  *
6359  * This function may be used to request anonymous credentials from the KDC by
6360  * setting @a anonymous to non-zero.  Note that anonymous credentials are only
6361  * a request; clients must verify that credentials are anonymous if that is a
6362  * requirement.
6363  */
6364 void KRB5_CALLCONV
6365 krb5_get_init_creds_opt_set_anonymous(krb5_get_init_creds_opt *opt,
6366                                       int anonymous);
6367
6368 /**
6369  * Set allowable encryption types in initial credential options.
6370  *
6371  * @param [in] opt               Options structure
6372  * @param [in] etype_list        Array of encryption types
6373  * @param [in] etype_list_length Length of @a etype_list
6374  */
6375 void KRB5_CALLCONV
6376 krb5_get_init_creds_opt_set_etype_list(krb5_get_init_creds_opt *opt,
6377                                        krb5_enctype *etype_list,
6378                                        int etype_list_length);
6379
6380 /**
6381  * Set address restrictions in initial credential options.
6382  *
6383  * @param [in] opt              Options structure
6384  * @param [in] addresses        Null-terminated array of addresses
6385  */
6386 void KRB5_CALLCONV
6387 krb5_get_init_creds_opt_set_address_list(krb5_get_init_creds_opt *opt,
6388                                          krb5_address **addresses);
6389
6390 /**
6391  * Set preauthentication types in initial credential options.
6392  *
6393  * @param [in] opt                 Options structure
6394  * @param [in] preauth_list        Array of preauthentication types
6395  * @param [in] preauth_list_length Length of @a preauth_list
6396  *
6397  * This function can be used to perform optimistic preauthentication when
6398  * getting initial credentials, in combination with
6399  * krb5_get_init_creds_opt_set_salt() and krb5_get_init_creds_opt_set_pa().
6400  */
6401 void KRB5_CALLCONV
6402 krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt *opt,
6403                                          krb5_preauthtype *preauth_list,
6404                                          int preauth_list_length);
6405
6406 /**
6407  * Set salt for optimistic preauthentication in initial credential options.
6408  *
6409  * @param [in] opt              Options structure
6410  * @param [in] salt             Salt data
6411  *
6412  * When getting initial credentials with a password, a salt string it used to
6413  * convert the password to a key.  Normally this salt is obtained from the
6414  * first KDC reply, but when performing optimistic preauthentication, the
6415  * client may need to supply the salt string with this function.
6416  */
6417 void KRB5_CALLCONV
6418 krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt *opt,
6419                                  krb5_data *salt);
6420
6421 /**
6422  * Set or unset change-password-prompt flag in initial credential options.
6423  *
6424  * @param [in] opt              Options structure
6425  * @param [in] prompt           Whether to prompt to change password
6426  *
6427  * This flag is on by default.  It controls whether
6428  * krb5_get_init_creds_password() will react to an expired-password error by
6429  * prompting for a new password and attempting to change the old one.
6430  */
6431 void KRB5_CALLCONV
6432 krb5_get_init_creds_opt_set_change_password_prompt(krb5_get_init_creds_opt *opt,
6433                                                    int prompt);
6434
6435 /** Generic preauth option attribute/value pairs */
6436 typedef struct _krb5_gic_opt_pa_data {
6437     char *attr;
6438     char *value;
6439 } krb5_gic_opt_pa_data;
6440
6441 /**
6442  * Supply options for preauthentication in initial credential options.
6443  *
6444  * @param [in] context          Library context
6445  * @param [in] opt              Options structure
6446  * @param [in] attr             Preauthentication option name
6447  * @param [in] value            Preauthentication option value
6448  *
6449  * This function allows the caller to supply options for preauthentication.
6450  * The values of @a attr and @a value are supplied to each preauthentication
6451  * module available within @a context.
6452  */
6453 krb5_error_code KRB5_CALLCONV
6454 krb5_get_init_creds_opt_set_pa(krb5_context context,
6455                                krb5_get_init_creds_opt *opt, const char *attr,
6456                                const char *value);
6457
6458 /**
6459  * Set location of FAST armor ccache in initial credential options.
6460  *
6461  * @param [in] context          Library context
6462  * @param [in] opt              Options
6463  * @param [in] fast_ccache_name Credential cache name
6464  *
6465  * Sets the location of a credential cache containing an armor ticket to
6466  * protect an initial credential exchange using the FAST protocol extension.
6467  *
6468  * In version 1.7, setting an armor ccache requires that FAST be used for the
6469  * exchange.  In version 1.8 or later, setting the armor ccache causes FAST to
6470  * be used if the KDC supports it; krb5_get_init_creds_opt_set_fast_flags()
6471  * must be used to require that FAST be used.
6472  */
6473 krb5_error_code KRB5_CALLCONV
6474 krb5_get_init_creds_opt_set_fast_ccache_name(krb5_context context,
6475                                              krb5_get_init_creds_opt *opt,
6476                                              const char *fast_ccache_name);
6477
6478 /**
6479  * Set FAST armor cache in initial credential options.
6480  *
6481  * @param [in] context           Library context
6482  * @param [in] opt               Options
6483  * @param [in] ccache            Credential cache handle
6484  *
6485  * This function is similar to krb5_get_init_creds_opt_set_fast_ccache_name(),
6486  * but uses a credential cache handle instead of a name.
6487  */
6488 krb5_error_code KRB5_CALLCONV
6489 krb5_get_init_creds_opt_set_fast_ccache(krb5_context context,
6490                                         krb5_get_init_creds_opt *opt,
6491                                         krb5_ccache ccache);
6492
6493 /**
6494  * Set an output credential cache in initial credential options.
6495  *
6496  * @param [in] context          Library context
6497  * @param [in] opt              Options
6498  * @param [in] ccache           Credential cache handle
6499  *
6500  * If an output credential cache is set, then the krb5_get_init_creds family of
6501  * APIs will write credentials to it.  Setting an output ccache is desirable
6502  * both because it simplifies calling code and because it permits the
6503  * krb5_get_init_creds APIs to write out configuration information about the
6504  * realm to the ccache.
6505  */
6506 krb5_error_code KRB5_CALLCONV
6507 krb5_get_init_creds_opt_set_out_ccache(krb5_context context,
6508                                        krb5_get_init_creds_opt *opt,
6509                                        krb5_ccache ccache);
6510
6511 /**
6512  * Set FAST flags in initial credential options.
6513  *
6514  * @param [in] context          Library context
6515  * @param [in] opt              Options
6516  * @param [in] flags            FAST flags
6517  *
6518  * The following flag values are valid:
6519  * @li #KRB5_FAST_REQUIRED - Require FAST to be used
6520  *
6521  * @retval
6522  * 0 - Success; Kerberos errors otherwise.
6523  */
6524 krb5_error_code KRB5_CALLCONV
6525 krb5_get_init_creds_opt_set_fast_flags(krb5_context context,
6526                                        krb5_get_init_creds_opt *opt,
6527                                        krb5_flags flags);
6528
6529 /**
6530  * Retrieve FAST flags from initial credential options.
6531  *
6532  * @param [in]  context         Library context
6533  * @param [in]  opt             Options
6534  * @param [out] out_flags       FAST flags
6535  *
6536  * @retval
6537  * 0 - Success; Kerberos errors otherwise.
6538  */
6539 krb5_error_code KRB5_CALLCONV
6540 krb5_get_init_creds_opt_get_fast_flags(krb5_context context,
6541                                        krb5_get_init_creds_opt *opt,
6542                                        krb5_flags *out_flags);
6543
6544 /* Fast flags*/
6545 #define KRB5_FAST_REQUIRED 1l<<0 /**< Require KDC to support FAST*/
6546
6547 typedef void
6548 (KRB5_CALLCONV *krb5_expire_callback_func)(krb5_context context, void *data,
6549                                            krb5_timestamp password_expiration,
6550                                            krb5_timestamp account_expiration,
6551                                            krb5_boolean is_last_req);
6552
6553 /**
6554  * Set an expiration callback in initial credential options.
6555  *
6556  * @param [in] context          Library context
6557  * @param [in] opt              Options structure
6558  * @param [in] cb               Callback function
6559  * @param [in] data             Callback argument
6560  *
6561  * Set a callback to receive password and account expiration times.
6562  *
6563  * This option only applies to krb5_get_init_creds_password().  @a cb will be
6564  * invoked if and only if credentials are successfully acquired.  The callback
6565  * will receive the @a context from the krb5_get_init_creds_password() call and
6566  * the @a data argument supplied with this API.  The remaining arguments should
6567  * be interpreted as follows:
6568  *
6569  * If @a is_last_req is true, then the KDC reply contained last-req entries
6570  * which unambiguously indicated the password expiration, account expiration,
6571  * or both.  (If either value was not present, the corresponding argument will
6572  * be 0.)  Furthermore, a non-zero @a password_expiration should be taken as a
6573  * suggestion from the KDC that a warning be displayed.
6574  *
6575  * If @a is_last_req is false, then @a account_expiration will be 0 and @a
6576  * password_expiration will contain the expiration time of either the password
6577  * or account, or 0 if no expiration time was indicated in the KDC reply.  The
6578  * callback should independently decide whether to display a password
6579  * expiration warning.
6580  *
6581  * Note that @a cb may be invoked even if credentials are being acquired for
6582  * the kadmin/changepw service in order to change the password.  It is the
6583  * caller's responsibility to avoid displaying a password expiry warning in
6584  * this case.
6585  *
6586  * @warning Setting an expire callback with this API will cause
6587  * krb5_get_init_creds_password() not to send password expiry warnings to the
6588  * prompter, as it ordinarily may.
6589  */
6590 krb5_error_code KRB5_CALLCONV
6591 krb5_get_init_creds_opt_set_expire_callback(krb5_context context,
6592                                             krb5_get_init_creds_opt *opt,
6593                                             krb5_expire_callback_func cb,
6594                                             void *data);
6595
6596 /**
6597  * Get initial credentials using a password.
6598  *
6599  * @param [in]  context         Library context
6600  * @param [out] creds           New credentials
6601  * @param [in]  client          Client principal
6602  * @param [in]  password        Password (or NULL)
6603  * @param [in]  prompter        Prompter function
6604  * @param [in]  data            Prompter callback data
6605  * @param [in]  start_time      Time when ticket becomes valid (0 for now)
6606  * @param [in]  in_tkt_service  Service name of initial credentials (or NULL)
6607  * @param [in]  k5_gic_options  Initial credential options
6608  *
6609  * This function requests KDC for an initial credentials for @a client using @a
6610  * password.  If @a password is NULL, a password will be prompted for using @a
6611  * prompter if necessary.  If @a in_tkt_service is specified, it is parsed as a
6612  * principal name (with the realm ignored) and used as the service principal
6613  * for the request; otherwise the ticket-granting service is used.
6614  *
6615  * @sa krb5_verify_init_creds()
6616  *
6617  * @retval
6618  *  0    Success
6619  * @retval
6620  *  EINVAL Invalid argument
6621  * @retval
6622  *  KRB5_KDC_UNREACH Cannot contact any KDC for requested realm
6623  * @retval
6624  *  KRB5_PREAUTH_FAILED Generic Pre-athentication failure
6625  * @retval
6626  *  KRB5_LIBOS_PWDINTR Password read interrupted
6627  * @retval
6628  *  KRB5_REALM_CANT_RESOLVE Cannot resolve network address for KDC in requested realm
6629  * @retval
6630  *  KRB5KDC_ERR_KEY_EXP Password has expired
6631  * @retval
6632  *  KRB5_LIBOS_BADPWDMATCH Password mismatch
6633  * @retval
6634  *  KRB5_CHPW_PWDNULL New password cannot be zero length
6635  * @retval
6636  *  KRB5_CHPW_FAIL Password change failed
6637  * @return
6638  * Kerberos error codes
6639  */
6640 krb5_error_code KRB5_CALLCONV
6641 krb5_get_init_creds_password(krb5_context context, krb5_creds *creds,
6642                              krb5_principal client, char *password,
6643                              krb5_prompter_fct prompter, void *data,
6644                              krb5_deltat start_time, char *in_tkt_service,
6645                              krb5_get_init_creds_opt *k5_gic_options);
6646
6647 struct _krb5_init_creds_context;
6648 typedef struct _krb5_init_creds_context *krb5_init_creds_context;
6649
6650 #define KRB5_INIT_CREDS_STEP_FLAG_CONTINUE 0x1  /* More responses needed */
6651
6652 /**
6653  * Free an initial credentials context.
6654  *
6655  * @param [in] context          Library context
6656  * @param [in] ctx              Initial credentials context
6657  */
6658 void KRB5_CALLCONV
6659 krb5_init_creds_free(krb5_context context, krb5_init_creds_context ctx);
6660
6661 /**
6662  * Acquire credentials using an initial credentials context.
6663  *
6664  * @param [in] context          Library context
6665  * @param [in] ctx              Initial credentials context
6666  *
6667  * This function synchronously obtains credentials using a context created by
6668  * krb5_init_creds_init().  On successful return, the credentials can be
6669  * retrieved with krb5_init_creds_get_creds().
6670  *
6671  * @retval 0 Success; otherwise - Kerberos error codes
6672  */
6673 krb5_error_code KRB5_CALLCONV
6674 krb5_init_creds_get(krb5_context context, krb5_init_creds_context ctx);
6675
6676 /**
6677  * Retrieve acquired credentials from an initial credentials context.
6678  *
6679  * @param [in]  context         Library context
6680  * @param [in]  ctx             Initial credentials context
6681  * @param [out] creds           Acquired credentials
6682  *
6683  * This function copies the acquired initial credentials from @a ctx into @a
6684  * creds, after the successful completion of krb5_init_creds_get() or
6685  * krb5_init_creds_step().  Use krb5_free_cred_contents() to free @a creds when
6686  * it is no longer needed.
6687  *
6688  * @retval 0 Success; otherwise - Kerberos error codes
6689  */
6690 krb5_error_code KRB5_CALLCONV
6691 krb5_init_creds_get_creds(krb5_context context, krb5_init_creds_context ctx,
6692                           krb5_creds *creds);
6693
6694 /**
6695  * Get the last error from KDC from an initial credentials context.
6696  *
6697  * @param [in]  context         Library context
6698  * @param [in]  ctx             Initial credentials context
6699  * @param [out] error           Error from KDC, or NULL if none was received
6700  *
6701  * @retval 0 Success; otherwise - Kerberos error codes
6702  */
6703 krb5_error_code KRB5_CALLCONV
6704 krb5_init_creds_get_error(krb5_context context, krb5_init_creds_context ctx,
6705                           krb5_error **error);
6706
6707 /**
6708  * Create a context for acquiring initial credentials.
6709  *
6710  * @param [in]  context         Library context
6711  * @param [in]  client          Client principal to get initial creds for
6712  * @param [in]  prompter        Prompter callback
6713  * @param [in]  data            Prompter callback argument
6714  * @param [in]  start_time      Time when credentials become valid (0 for now)
6715  * @param [in]  options         Options structure (NULL for default)
6716  * @param [out] ctx             New initial credentials context
6717  *
6718  * This function creates a new context for acquiring initial credentials.  Use
6719  * krb5_init_creds_free() to free @a ctx when it is no longer needed.
6720  *
6721  * @retval 0 Success; otherwise - Kerberos error codes
6722  */
6723 krb5_error_code KRB5_CALLCONV
6724 krb5_init_creds_init(krb5_context context, krb5_principal client,
6725                      krb5_prompter_fct prompter, void *data,
6726                      krb5_deltat start_time, krb5_get_init_creds_opt *options,
6727                      krb5_init_creds_context *ctx);
6728
6729 /**
6730  * Specify a keytab to use for acquiring initial credentials.
6731  *
6732  * @param [in] context          Library context
6733  * @param [in] ctx              Initial credentials context
6734  * @param [in] keytab           Key table handle
6735  *
6736  * This function supplies a keytab containing the client key for an initial
6737  * credentials request.
6738  *
6739  * @retval 0 Success; otherwise - Kerberos error codes
6740  */
6741 krb5_error_code KRB5_CALLCONV
6742 krb5_init_creds_set_keytab(krb5_context context, krb5_init_creds_context ctx,
6743                            krb5_keytab keytab);
6744
6745 /**
6746  * Get the next KDC request for acquiring initial credentials.
6747  *
6748  * @param [in]  context         Library context
6749  * @param [in]  ctx             Initial credentials context
6750  * @param [in]  in              KDC response (empty on the first call)
6751  * @param [out] out             Next KDC request
6752  * @param [out] realm           Realm for next KDC request
6753  * @param [out] flags           Output flags
6754  *
6755  * This function constructs the next KDC request in an initial credential
6756  * exchange, allowing the caller to control the transport of KDC requests and
6757  * replies.  On the first call, @a in should be set to an empty buffer; on
6758  * subsequent calls, it should be set to the KDC's reply to the previous
6759  * request.
6760  *
6761  * If more requests are needed, @a flags will be set to
6762  * #KRB5_INIT_CREDS_STEP_FLAG_CONTINUE and the next request will be placed in
6763  * @a out.  If no more requests are needed, @a flags will not contain
6764  * #KRB5_INIT_CREDS_STEP_FLAG_CONTINUE and @a out will be empty.
6765  *
6766  * If this function returns @c KRB5KRB_ERR_RESPONSE_TOO_BIG, the caller should
6767  * transmit the next request using TCP rather than UDP.  If this function
6768  * returns any other error, the initial credential exchange has failed.
6769  *
6770  * @retval 0 Success; otherwise - Kerberos error codes
6771  */
6772 krb5_error_code KRB5_CALLCONV
6773 krb5_init_creds_step(krb5_context context, krb5_init_creds_context ctx,
6774                      krb5_data *in, krb5_data *out, krb5_data *realm,
6775                      unsigned int *flags);
6776
6777 /**
6778  * Set a password for acquiring initial credentials.
6779  *
6780  * @param [in] context          Library context
6781  * @param [in] ctx              Initial credentials context
6782  * @param [in] password         Password
6783  *
6784  * This function supplies a password to be used to construct the client key for
6785  * an initial credentials request.
6786  *
6787  * @retval 0 Success; otherwise - Kerberos error codes
6788  */
6789 krb5_error_code KRB5_CALLCONV
6790 krb5_init_creds_set_password(krb5_context context, krb5_init_creds_context ctx,
6791                              const char *password);
6792
6793 /**
6794  * Specify a service principal for acquiring initial credentials.
6795  *
6796  * @param [in] context          Library context
6797  * @param [in] ctx              Initial credentials context
6798  * @param [in] service          Service principal string
6799  *
6800  * This function supplies a service principal string to acquire initial
6801  * credentials for instead of the default krbtgt service.  @a service is parsed
6802  * as a principal name; any realm part is ignored.
6803  *
6804  * @retval 0 Success; otherwise - Kerberos error codes
6805  */
6806 krb5_error_code KRB5_CALLCONV
6807 krb5_init_creds_set_service(krb5_context context, krb5_init_creds_context ctx,
6808                             const char *service);
6809
6810 /**
6811  * Retrieve ticket times from an initial credentials context.
6812  *
6813  * @param [in]  context         Library context
6814  * @param [in]  ctx             Initial credentials context
6815  * @param [out] times           Ticket times for acquired credentials
6816  *
6817  * The initial credentials context must have completed obtaining credentials
6818  * via either krb5_init_creds_get() or krb5_init_creds_step().
6819  *
6820  * @retval 0 Success; otherwise - Kerberos error codes
6821  */
6822 krb5_error_code KRB5_CALLCONV
6823 krb5_init_creds_get_times(krb5_context context, krb5_init_creds_context ctx,
6824                           krb5_ticket_times *times);
6825
6826 struct _krb5_tkt_creds_context;
6827 typedef struct _krb5_tkt_creds_context *krb5_tkt_creds_context;
6828
6829 /**
6830  * Create a context to get credentials from a KDC's Ticket Granting Service.
6831  *
6832  * @param[in]  context          Library context
6833  * @param[in]  ccache           Credential cache handle
6834  * @param[in]  creds            Input credentials
6835  * @param[in]  options          @ref KRB5_GC options for this request.
6836  * @param[out] ctx              New TGS request context
6837  *
6838  * This function prepares to obtain credentials matching @a creds, either by
6839  * retrieving them from @a ccache or by making requests to ticket-granting
6840  * services beginning with a ticket-granting ticket for the client principal's
6841  * realm.
6842  *
6843  * The resulting TGS acquisition context can be used asynchronously with
6844  * krb5_tkt_creds_step() or synchronously with krb5_tkt_creds_get().  See also
6845  * krb5_get_credentials() for synchronous use.
6846  *
6847  * Use krb5_tkt_creds_free() to free @a ctx when it is no longer needed.
6848  *
6849  * @retval 0  Success; otherwise - Kerberos error codes
6850  */
6851 krb5_error_code KRB5_CALLCONV
6852 krb5_tkt_creds_init(krb5_context context, krb5_ccache ccache,
6853                     krb5_creds *creds, krb5_flags options,
6854                     krb5_tkt_creds_context *ctx);
6855
6856 /**
6857  * Synchronously obtain credentials using a TGS request context.
6858  *
6859  * @param[in] context           Library context
6860  * @param[in] ctx               TGS request context
6861  *
6862  * This function synchronously obtains credentials using a context created by
6863  * krb5_tkt_creds_init().  On successful return, the credentials can be
6864  * retrieved with krb5_tkt_creds_get_creds().
6865  *
6866  * @retval 0  Success; otherwise - Kerberos error codes
6867  */
6868 krb5_error_code KRB5_CALLCONV
6869 krb5_tkt_creds_get(krb5_context context, krb5_tkt_creds_context ctx);
6870
6871 /**
6872  * Retrieve acquired credentials from a TGS request context.
6873  *
6874  * @param[in]  context          Library context
6875  * @param[in]  ctx              TGS request context
6876  * @param[out] creds            Acquired credentials
6877  *
6878  * This function copies the acquired initial credentials from @a ctx into @a
6879  * creds, after the successful completion of krb5_tkt_creds_get() or
6880  * krb5_tkt_creds_step().  Use krb5_free_cred_contents() to free @a creds when
6881  * it is no longer needed.
6882  *
6883  * @retval 0  Success; otherwise - Kerberos error codes
6884  */
6885 krb5_error_code KRB5_CALLCONV
6886 krb5_tkt_creds_get_creds(krb5_context context, krb5_tkt_creds_context ctx,
6887                          krb5_creds *creds);
6888
6889 /**
6890  * Free a TGS request context.
6891  *
6892  * @param[in]  context  Library context
6893  * @param[in]  ctx      TGS request context
6894  */
6895 void KRB5_CALLCONV
6896 krb5_tkt_creds_free(krb5_context context, krb5_tkt_creds_context ctx);
6897
6898 #define KRB5_TKT_CREDS_STEP_FLAG_CONTINUE 0x1  /* More responses needed. */
6899
6900 /**
6901  * Get the next KDC request in a TGS exchange.
6902  *
6903  * @param[in]  context          Library context
6904  * @param[in]  ctx              TGS request context
6905  * @param[in]  in               KDC response (empty on the first call)
6906  * @param[out] out              Next KDC request
6907  * @param[out] realm            Realm for next KDC request
6908  * @param[out] flags            Output flags
6909  *
6910  * This function constructs the next KDC request for a TGS exchange, allowing
6911  * the caller to control the transport of KDC requests and replies.  On the
6912  * first call, @a in should be set to an empty buffer; on subsequent calls, it
6913  * should be set to the KDC's reply to the previous request.
6914  *
6915  * If more requests are needed, @a flags will be set to
6916  * #KRB5_TKT_CREDS_STEP_FLAG_CONTINUE and the next request will be placed in @a
6917  * out.  If no more requests are needed, @a flags will not contain
6918  * #KRB5_TKT_CREDS_STEP_FLAG_CONTINUE and @a out will be empty.
6919  *
6920  * If this function returns @c KRB5KRB_ERR_RESPONSE_TOO_BIG, the caller should
6921  * transmit the next request using TCP rather than UDP.  If this function
6922  * returns any other error, the TGS exchange has failed.
6923  *
6924  * @retval 0  Success; otherwise - Kerberos error codes
6925  */
6926 krb5_error_code KRB5_CALLCONV
6927 krb5_tkt_creds_step(krb5_context context, krb5_tkt_creds_context ctx,
6928                     krb5_data *in, krb5_data *out, krb5_data *realm,
6929                     unsigned int *flags);
6930
6931 /**
6932  * Retrieve ticket times from a TGS request context.
6933  *
6934  * @param[in]  context          Library context
6935  * @param[in]  ctx              TGS request context
6936  * @param[out] times            Ticket times for acquired credentials
6937  *
6938  * The TGS request context must have completed obtaining credentials via either
6939  * krb5_tkt_creds_get() or krb5_tkt_creds_step().
6940  *
6941  * @retval 0  Success; otherwise - Kerberos error codes
6942  */
6943 krb5_error_code KRB5_CALLCONV
6944 krb5_tkt_creds_get_times(krb5_context context, krb5_tkt_creds_context ctx,
6945                          krb5_ticket_times *times);
6946
6947 /**
6948  * Get initial credentials using a key table.
6949  *
6950  * @param [in]  context         Library context
6951  * @param [out] creds           New credentials
6952  * @param [in]  client          Client principal
6953  * @param [in]  arg_keytab      Key table handle
6954  * @param [in]  start_time      Time when ticket becomes valid (0 for now)
6955  * @param [in]  in_tkt_service  Service name of initial credentials (or NLUL)
6956  * @param [in]  k5_gic_options  Initial credential options
6957  *
6958  * This function requests KDC for an initial credentials for @a client using a
6959  * client key stored in @a arg_keytab.  If @a in_tkt_service is specified, it
6960  * is parsed as a principal name (with the realm ignored) and used as the
6961  * service principal for the request; otherwise the ticket-granting service is
6962  * used.
6963  *
6964  * @sa krb5_verify_init_creds()
6965  *
6966  * @retval
6967  * 0 Success
6968  * @return
6969  * Kerberos error codes
6970  */
6971 krb5_error_code KRB5_CALLCONV
6972 krb5_get_init_creds_keytab(krb5_context context, krb5_creds *creds,
6973                            krb5_principal client, krb5_keytab arg_keytab,
6974                            krb5_deltat start_time, char *in_tkt_service,
6975                            krb5_get_init_creds_opt *k5_gic_options);
6976
6977 typedef struct _krb5_verify_init_creds_opt {
6978     krb5_flags flags;
6979     int ap_req_nofail; /**< boolean */
6980 } krb5_verify_init_creds_opt;
6981
6982 #define KRB5_VERIFY_INIT_CREDS_OPT_AP_REQ_NOFAIL        0x0001
6983
6984 /**
6985  * Initialize a credential verification options structure.
6986  *
6987  * @param [in] k5_vic_options   Verification options structure
6988  */
6989 void KRB5_CALLCONV
6990 krb5_verify_init_creds_opt_init(krb5_verify_init_creds_opt *k5_vic_options);
6991
6992 /**
6993  * Set whether credential verification is required.
6994  *
6995  * @param [in] k5_vic_options   Verification options structure
6996  * @param [in] ap_req_nofail    Whether to require successful verification
6997  *
6998  * This function determines how krb5_verify_init_creds() behaves if no keytab
6999  * information is available.  If @a ap_req_nofail is @c FALSE, verification
7000  * will be skipped in this case and krb5_verify_init_creds() will return
7001  * successfully.  If @a ap_req_nofail is @c TRUE, krb5_verify_init_creds() will
7002  * not return successfully unless verification can be performed.
7003  *
7004  * If this function is not used, the behavior of krb5_verify_init_creds() is
7005  * determined through configuration.
7006  */
7007 void KRB5_CALLCONV
7008 krb5_verify_init_creds_opt_set_ap_req_nofail(krb5_verify_init_creds_opt * k5_vic_options,
7009                                              int ap_req_nofail);
7010
7011 /**
7012  * Verify initial credentials against a keytab.
7013  *
7014  * @param [in]     context      Library context
7015  * @param [in]     creds        Initial credentials to be verified
7016  * @param [in]     server_arg   Server principal (or NULL)
7017  * @param [in]     keytab_arg   Key table (NULL to use default keytab)
7018  * @param [in,out] ccache_arg   Credential cache for fetched creds (or NULL)
7019  * @param [in]     options      Verification options (NULL for default options)
7020  *
7021  * This function attempts to verify that @a creds were obtained from a KDC with
7022  * knowledge of a key in @a keytab_arg.  If @a server_arg is provided, the
7023  * highest-kvno key entry for that principal name is used to verify the
7024  * credentials; otherwise, the highest-kvno key entry for the first principal
7025  * listed in @a keytab_arg is used.
7026  *
7027  * If the specified keytab does not exist, or is empty, or cannot be read, or
7028  * does not contain an entry for @a server_arg, then credential verification
7029  * may be skipped unless configuration demands that it succeed.  The caller can
7030  * control this behavior by providing a verification options structure; see
7031  * krb5_verify_init_creds_opt_init() and
7032  * krb5_verify_init_creds_opt_set_ap_req_nofail().
7033  *
7034  * If @a ccache_arg is NULL, any additional credentials fetched during the
7035  * verification process will be destroyed.  If @a ccache_arg points to NULL, a
7036  * memory ccache will be created for the additional credentials and returned in
7037  * @a ccache_arg.  If @a ccache_arg points to a valid credential cache handle,
7038  * the additional credentials will be stored in that cache.
7039  *
7040  * @retval 0  Success; otherwise - Kerberos error codes
7041  */
7042 krb5_error_code KRB5_CALLCONV
7043 krb5_verify_init_creds(krb5_context context, krb5_creds *creds,
7044                        krb5_principal server_arg, krb5_keytab keytab_arg,
7045                        krb5_ccache *ccache_arg, krb5_verify_init_creds_opt *options);
7046
7047 /**
7048  * Get validated credentials from the KDC.
7049  *
7050  * @param [in]  context         Library context
7051  * @param [out] creds           Validated credentials
7052  * @param [in]  client          Client principal name
7053  * @param [in]  ccache          Credential cache
7054  * @param [in]  in_tkt_service  Server principal string (or NULL)
7055  *
7056  * This function gets a validated credential using a postdated credential from
7057  * @a ccache.  If @a in_tkt_service is specified, it is parsed (with the realm
7058  * part ignored) and used as the server principal of the credential;
7059  * otherwise, the ticket-granting service is used.
7060  *
7061  * If successful, the validated credential is placed in @a creds.
7062  *
7063  * @sa krb5_get_renewed_creds()
7064  *
7065  * @retval
7066  * 0 Success
7067  * @retval
7068  * KRB5_NO_2ND_TKT Request missing second ticket
7069  * @retval
7070  * KRB5_NO_TKT_SUPPLIED Request did not supply a ticket
7071  * @retval
7072  * KRB5_PRINC_NOMATCH Requested principal and ticket do not match
7073  * @retval
7074  * KRB5_KDCREP_MODIFIED KDC reply did not match expectations
7075  * @retval
7076  * KRB5_KDCREP_SKEW Clock skew too great in KDC reply
7077  * @return
7078  * Kerberos error codes
7079  */
7080 krb5_error_code KRB5_CALLCONV
7081 krb5_get_validated_creds(krb5_context context, krb5_creds *creds,
7082                          krb5_principal client, krb5_ccache ccache,
7083                          char *in_tkt_service);
7084
7085 /**
7086  * Get renewed credential from KDC using an existing credential.
7087  *
7088  * @param [in]  context         Library context
7089  * @param [out] creds           Renewed credentials
7090  * @param [in]  client          Client principal name
7091  * @param [in]  ccache          Credential cache
7092  * @param [in]  in_tkt_service  Server principal string (or NULL)
7093  *
7094  * This function gets a renewed credential using an existing one from @a
7095  * ccache.  If @a in_tkt_service is specified, it is parsed (with the realm
7096  * part ignored) and used as the server principal of the credential; otherwise,
7097  * the ticket-granting service is used.
7098  *
7099  * If successful, the renewed credential is placed in @a creds.
7100  *
7101  * @retval
7102  * 0 Success
7103  * @return
7104  * Kerberos error codes
7105  */
7106 krb5_error_code KRB5_CALLCONV
7107 krb5_get_renewed_creds(krb5_context context, krb5_creds *creds,
7108                        krb5_principal client, krb5_ccache ccache,
7109                        char *in_tkt_service);
7110
7111 /**
7112  * Decode an ASN.1-formatted ticket.
7113  *
7114  * @param [in]  code            ASN.1-formatted ticket
7115  * @param [out] rep             Decoded ticket information
7116  *
7117  * @retval 0  Success; otherwise - Kerberos error codes
7118  */
7119 krb5_error_code KRB5_CALLCONV
7120 krb5_decode_ticket(const krb5_data *code, krb5_ticket **rep);
7121
7122 /**
7123  * Retrieve a string value from the appdefaults section of krb5.conf.
7124  *
7125  * @param [in]  context         Library context
7126  * @param [in]  appname         Application name
7127  * @param [in]  realm           Realm name
7128  * @param [in]  option          Option to be checked
7129  * @param [in]  default_value   Default value to return if no match is found
7130  * @param [out] ret_value       String value of @a option
7131  *
7132  * This function gets the application defaults for @a option based on the given
7133  * @a appname and/or @a realm.
7134  *
7135  * @sa krb5_appdefault_boolean()
7136  */
7137 void KRB5_CALLCONV
7138 krb5_appdefault_string(krb5_context context, const char *appname,
7139                        const krb5_data *realm, const char *option,
7140                        const char *default_value, char ** ret_value);
7141
7142 /**
7143  * Retrieve a boolean value from the appdefaults section of krb5.conf.
7144  *
7145  * @param [in]  context         Library context
7146  * @param [in]  appname         Application name
7147  * @param [in]  realm           Realm name
7148  * @param [in]  option          Option to be checked
7149  * @param [in]  default_value   Default value to return if no match is found
7150  * @param [out] ret_value       Boolean value of @a option
7151  *
7152  * This function gets the application defaults for @a option based on the given
7153  * @a appname and/or @a realm.
7154  *
7155  * @sa krb5_appdefault_string()
7156  */
7157 void KRB5_CALLCONV
7158 krb5_appdefault_boolean(krb5_context context, const char *appname,
7159                         const krb5_data *realm, const char *option,
7160                         int default_value, int *ret_value);
7161
7162 /*
7163  * Prompter enhancements
7164  */
7165 #define KRB5_PROMPT_TYPE_PASSWORD            0x1
7166 #define KRB5_PROMPT_TYPE_NEW_PASSWORD        0x2
7167 #define KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN  0x3
7168 #define KRB5_PROMPT_TYPE_PREAUTH             0x4
7169
7170 typedef krb5_int32 krb5_prompt_type;
7171
7172 /**
7173  * Get prompt types array from a context.
7174  *
7175  * @param [in] context          Library context
7176  *
7177  * @return
7178  * Pointer to an array of prompt types corresponding to the prompter's @a
7179  * prompts arguments.  Each type has one of the following values:
7180  *  @li #KRB5_PROMPT_TYPE_PASSWORD
7181  *  @li #KRB5_PROMPT_TYPE_NEW_PASSWORD
7182  *  @li #KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN
7183  *  @li #KRB5_PROMPT_TYPE_PREAUTH
7184  */
7185 krb5_prompt_type* KRB5_CALLCONV
7186 krb5_get_prompt_types(krb5_context context);
7187
7188 /* Error reporting */
7189 /**
7190  * Set an extended error message for an error code.
7191  *
7192  * @param [in] ctx              Library context
7193  * @param [in] code             Error code
7194  * @param [in] fmt              Error string for the error code
7195  * @param [in] ...              printf(3) style parameters
7196  */
7197 void KRB5_CALLCONV_C
7198 krb5_set_error_message(krb5_context ctx, krb5_error_code code, const char *fmt, ...)
7199 #if !defined(__cplusplus) && (__GNUC__ > 2)
7200     __attribute__((__format__(__printf__, 3, 4)))
7201 #endif
7202     ;
7203
7204 /**
7205  * Set an extended error message for an error code using a va_list.
7206  *
7207  * @param [in] ctx              Library context
7208  * @param [in] code             Error code
7209  * @param [in] fmt              Error string for the error code
7210  * @param [in] args             List of vprintf(3) style arguments
7211  */
7212 void KRB5_CALLCONV
7213 krb5_vset_error_message(krb5_context  ctx, krb5_error_code code,
7214                          const char *fmt, va_list args)
7215 #if !defined(__cplusplus) && (__GNUC__ > 2)
7216     __attribute__((__format__(__printf__, 3, 0)))
7217 #endif
7218     ;
7219
7220 /**
7221  * Copy the most recent extended error message from one context to another.
7222  *
7223  * @param [in] dest_ctx         Library context to copy message to
7224  * @param [in] src_ctx          Library context with current message
7225  */
7226 void KRB5_CALLCONV
7227 krb5_copy_error_message(krb5_context dest_ctx, krb5_context src_ctx);
7228
7229 /**
7230  * Get the (possibly extended) error message for a code.
7231  *
7232  * @param [in] ctx              Library context
7233  * @param [in] code             Error code
7234  *
7235  * The behavior of krb5_get_error_message() is only defined the first time it
7236  * is called after a failed call to a krb5 function using the same context, and
7237  * only when the error code passed in is the same as that returned by the krb5
7238  * function.
7239  *
7240  * This function never returns NULL, so its result may be used unconditionally
7241  * as a C string.
7242  *
7243  * The string returned by this function must be freed using
7244  * krb5_free_error_message()
7245  *
7246  * @note Future versions may return the same string for the second
7247  * and following calls.
7248  */
7249 const char * KRB5_CALLCONV
7250 krb5_get_error_message(krb5_context ctx, krb5_error_code code);
7251
7252 /**
7253  * Free an error message generated by krb5_get_error_message().
7254  *
7255  * @param [in] ctx              Library context
7256  * @param [in] msg              Pointer to error message
7257  */
7258 void KRB5_CALLCONV
7259 krb5_free_error_message(krb5_context ctx, const char *msg);
7260
7261 /**
7262  * Clear the extended error message in a context.
7263  *
7264  * @param [in] ctx              Library context
7265  *
7266  * This function unsets the extended error message in a context, to ensure that
7267  * it is not mistakenly applied to another occurrence of the same error code.
7268  */
7269 void KRB5_CALLCONV
7270 krb5_clear_error_message(krb5_context ctx);
7271
7272 /**
7273  * Unwrap authorization data.
7274  *
7275  * @param [in]  context         Library context
7276  * @param [in]  type            @ref KRB5_AUTHDATA type of @a container
7277  * @param [in]  container       Authorization data to be decoded
7278  * @param [out] authdata        List of decoded authorization data
7279  *
7280  * @sa krb5_encode_authdata_container()
7281  *
7282  * @retval 0 Success; otherwise - Kerberos error codes
7283  */
7284 krb5_error_code KRB5_CALLCONV
7285 krb5_decode_authdata_container(krb5_context context,
7286                                krb5_authdatatype type,
7287                                const krb5_authdata *container,
7288                                krb5_authdata ***authdata);
7289 /**
7290  * Wrap authorization data in a container.
7291  *
7292  * @param [in]  context         Library context
7293  * @param [in]  type            @ref KRB5_AUTHDATA type of @a container
7294  * @param [in]  authdata        List of authorization data to be encoded
7295  * @param [out] container       List of encoded authorization data
7296  *
7297  * The result is returned in @a container as a single-element list.
7298  *
7299  * @sa krb5_decode_authdata_container()
7300  *
7301  * @retval 0 Success; otherwise - Kerberos error codes
7302  */
7303 krb5_error_code KRB5_CALLCONV
7304 krb5_encode_authdata_container(krb5_context context,
7305                                krb5_authdatatype type,
7306                                krb5_authdata * const*authdata,
7307                                krb5_authdata ***container);
7308
7309 /*
7310  * AD-KDCIssued
7311  */
7312 /**
7313  * Encode and sign AD-KDCIssued authorization data.
7314  *
7315  * @param [in]  context         Library context
7316  * @param [in]  key             Session key
7317  * @param [in]  issuer          The name of the issuing principal
7318  * @param [in]  authdata        List of authorization data to be signed
7319  * @param [out] ad_kdcissued    List containing AD-KDCIssued authdata
7320  *
7321  * This function wraps a list of authorization data entries @a authdata in an
7322  * AD-KDCIssued container (see RFC 4120 section 5.2.6.2) signed with @a key.
7323  * The result is returned in @a ad_kdcissued as a single-element list.
7324  */
7325 krb5_error_code KRB5_CALLCONV
7326 krb5_make_authdata_kdc_issued(krb5_context context,
7327                               const krb5_keyblock *key,
7328                               krb5_const_principal issuer,
7329                               krb5_authdata *const *authdata,
7330                               krb5_authdata ***ad_kdcissued);
7331
7332 /**
7333  * Unwrap and verify AD-KDCIssued authorization data.
7334  *
7335  * @param [in] context          Library context
7336  * @param [in] key              Session key
7337  * @param [in] ad_kdcissued     AD-KDCIssued authorization data to be unwrapped
7338  * @param [out] issuer          Name of issuing principal (or NULL)
7339  * @param [out] authdata        Unwrapped list of authorization data
7340  *
7341  * This function unwraps an AD-KDCIssued authdatum (see RFC 4120 section
7342  * 5.2.6.2) and verifies its signature against @a key.  The issuer field of the
7343  * authdatum element is returned in @a issuer, and the unwrapped list of
7344  * authdata is returned in @a authdata.
7345  */
7346 krb5_error_code KRB5_CALLCONV
7347 krb5_verify_authdata_kdc_issued(krb5_context context,
7348                                 const krb5_keyblock *key,
7349                                 const krb5_authdata *ad_kdcissued,
7350                                 krb5_principal *issuer,
7351                                 krb5_authdata ***authdata);
7352
7353 /*
7354  * Windows PAC
7355  */
7356
7357 /* Microsoft defined types of data */
7358 #define KRB5_PAC_LOGON_INFO        1  /**< Logon information */
7359 #define KRB5_PAC_CREDENTIALS_INFO  2  /**< Credentials information */
7360 #define KRB5_PAC_SERVER_CHECKSUM   6  /**< Server checksum */
7361 #define KRB5_PAC_PRIVSVR_CHECKSUM  7  /**< KDC checksum */
7362 #define KRB5_PAC_CLIENT_INFO       10 /**< Client name and ticket info */
7363 #define KRB5_PAC_DELEGATION_INFO   11 /**< Constrained delegation info */
7364 #define KRB5_PAC_UPN_DNS_INFO      12 /**< User principal name and DNS info */
7365
7366 struct krb5_pac_data;
7367 /** PAC data structure to convey authorization information */
7368 typedef struct krb5_pac_data *krb5_pac;
7369
7370 /**
7371  * Add a buffer to a PAC handle.
7372  *
7373  * @param [in] context          Library context
7374  * @param [in] pac              PAC handle
7375  * @param [in] type             Buffer type
7376  * @param [in] data             contents
7377  *
7378  * This function adds a buffer of type @a type and contents @a data to @a pac
7379  * if there isn't already a buffer of this type present.
7380  *
7381  * The valid values of @a type is one of the following:
7382  * @li #PAC_LOGON_INFO         -  Logon information
7383  * @li #PAC_CREDENTIALS_INFO   -  Credentials information
7384  * @li #PAC_SERVER_CHECKSUM    -  Server checksum
7385  * @li #PAC_PRIVSVR_CHECKSUM   -  KDC checksum
7386  * @li #PAC_CLIENT_INFO        -  Client name and ticket information
7387  * @li #PAC_DELEGATION_INFO    -  Constrained delegation information
7388  * @li #PAC_UPN_DNS_INFO       -  User principal name and DNS information
7389  *
7390  * @retval 0 Success; otherwise - Kerberos error codes
7391  */
7392 krb5_error_code KRB5_CALLCONV
7393 krb5_pac_add_buffer(krb5_context context, krb5_pac pac, krb5_ui_4 type,
7394                     const krb5_data *data);
7395
7396 /**
7397  * Free a PAC handle.
7398  *
7399  * @param [in] context         Library context
7400  * @param [in] pac             PAC to be freed
7401  *
7402  * This function frees the contents of @a pac and the structure itself.
7403  */
7404 void KRB5_CALLCONV
7405 krb5_pac_free(krb5_context context, krb5_pac pac);
7406
7407 /**
7408  * Retrieve a buffer value from a PAC.
7409  *
7410  * @param [in]  context         Library context
7411  * @param [in]  pac             PAC handle
7412  * @param [in]  type            Type of buffer to retrieve
7413  * @param [out] data            Buffer value
7414  *
7415  * Use krb5_free_data_contents() to free @a data when it is no longer needed.
7416  *
7417  * @retval 0 Success; otherwise - Kerberos error codes
7418  */
7419 krb5_error_code KRB5_CALLCONV
7420 krb5_pac_get_buffer(krb5_context context, krb5_pac pac, krb5_ui_4 type,
7421                     krb5_data *data);
7422
7423 /**
7424  * Return an array of buffer types in a PAC handle.
7425  *
7426  * @param [in]  context         Library context
7427  * @param [in]  pac             PAC handle
7428  * @param [out] len             Number of entries in @a types
7429  * @param [out] types           Array of buffer types
7430  *
7431  * @retval 0 Success; otherwise - Kerberos error codes
7432  */
7433 krb5_error_code KRB5_CALLCONV
7434 krb5_pac_get_types(krb5_context context, krb5_pac pac, size_t *len,
7435                    krb5_ui_4 **types);
7436
7437 /**
7438  * Create an empty Privilege Attribute Certificate (PAC) handle.
7439  *
7440  * @param [in]  context         Library context
7441  * @param [out] pac             New PAC handle
7442  *
7443  * Use krb5_pac_free() to free @a pac when it is no longer needed.
7444  *
7445  * @retval 0 Success; otherwise - Kerberos error codes
7446  */
7447 krb5_error_code KRB5_CALLCONV
7448 krb5_pac_init(krb5_context context, krb5_pac *pac);
7449
7450 /**
7451  * Unparse an encoded PAC into a new handle.
7452  *
7453  * @param [in]  context         Library context
7454  * @param [in]  ptr             PAC buffer
7455  * @param [in]  len             Length of @a ptr
7456  * @param [out] pac             PAC handle
7457  *
7458  * Use krb5_pac_free() to free @a pac when it is no longer needed.
7459  *
7460  * @retval 0 Success; otherwise - Kerberos error codes
7461  */
7462 krb5_error_code KRB5_CALLCONV
7463 krb5_pac_parse(krb5_context context, const void *ptr, size_t len,
7464                krb5_pac *pac);
7465
7466 /**
7467  * Verify a PAC.
7468  *
7469  * @param [in] context          Library context
7470  * @param [in] pac              PAC handle
7471  * @param [in] authtime         Expected timestamp
7472  * @param [in] principal        Expected principal name (or NULL)
7473  * @param [in] server           Key to validate server checksum
7474  * @param [in] privsvr          Key to validate KDC checksum (or NULL)
7475  *
7476  * This function validates @a pac against the supplied @a server, @a privsvr,
7477  * @a principal and @a authtime.  If @a principal is NULL, the principal and
7478  * authtime are not verified.  If @a privsvr is NULL, the KDC checksum is not
7479  * verified.
7480  *
7481  * If successful, @a pac is marked as verified.
7482  *
7483  * @note A checksum mismatch can occur if the PAC was copied from a cross-realm
7484  * TGT by an ignorant KDC; also Apple Mac OS X Server Open Directory (as of
7485  * 10.6) generates PACs with no server checksum at all.  One should consider
7486  * not failing the whole authentication because of this reason, but, instead,
7487  * treating the ticket as if it did not contain a PAC or marking the PAC
7488  * information as non-verified.
7489  *
7490  * @retval 0 Success; otherwise - Kerberos error codes
7491  */
7492 krb5_error_code KRB5_CALLCONV
7493 krb5_pac_verify(krb5_context context, const krb5_pac pac,
7494                 krb5_timestamp authtime, krb5_const_principal principal,
7495                 const krb5_keyblock *server, const krb5_keyblock *privsvr);
7496
7497 /**
7498  * Sign a PAC.
7499  *
7500  * @param [in]  context         Library context
7501  * @param [in]  pac             PAC handle
7502  * @param [in]  authtime        Expected timestamp
7503  * @param [in]  principal       Expected principal name (or NULL)
7504  * @param [in]  server_key      Key for server checksum
7505  * @param [in]  privsvr_key     Key for KDC checksum
7506  * @param [out] data            Signed PAC encoding
7507  *
7508  * This function signs @a pac using the keys @a server_key and @a privsvr_key
7509  * and returns the signed encoding in @a data.  @a pac is modified to include
7510  * the server and KDC checksum buffers.  Use krb5_free_data_contents() to free
7511  * @a data when it is no longer needed.
7512  */
7513 krb5_error_code KRB5_CALLCONV
7514 krb5_pac_sign(krb5_context context, krb5_pac pac, krb5_timestamp authtime,
7515               krb5_const_principal principal, const krb5_keyblock *server_key,
7516               const krb5_keyblock *privsvr_key, krb5_data *data);
7517
7518 /**
7519  * Allow the appplication to override the profile's allow_weak_crypto setting.
7520  *
7521  * @param [in] context          Library context
7522  * @param [in] enable           Boolean flag
7523  *
7524  * This function allows an application to override the allow_weak_crypto
7525  * setting.  It is primarily for use by aklog.
7526  *
7527  * @retval 0  (always)
7528  */
7529 krb5_error_code KRB5_CALLCONV
7530 krb5_allow_weak_crypto(krb5_context context, krb5_boolean enable);
7531
7532 /* This structure may be extended to contain more fields in the future. */
7533 struct krb5_trace_info {
7534     const char *message;
7535 };
7536
7537 typedef void
7538 (KRB5_CALLCONV *krb5_trace_callback)(krb5_context context,
7539                                      const struct krb5_trace_info *info,
7540                                      void *cb_data);
7541
7542 /**
7543  * Specify a callback function for trace events.
7544  *
7545  * @param [in] context          Library context
7546  * @param [in] fn               Callback function
7547  * @param [in] cb_data          Callback data
7548  *
7549  * Specify a callback for trace events occurring in krb5 operations performed
7550  * within @a context.  @a fn will be invoked with @a context as the first
7551  * argument, @a cb_data as the last argument, and a pointer to a struct
7552  * krb5_trace_info as the second argument.  If the trace callback is reset via
7553  * this function or @a context is destroyed, @a fn will be invoked with a NULL
7554  * second argument so it can clean up @a cb_data.  Supply a NULL value for @a
7555  * fn to disable trace callbacks within @a context.
7556  *
7557  * @return Returns KRB5_TRACE_NOSUPP if tracing is not supported in the library
7558  * (unless @a fn is NULL).
7559  */
7560 krb5_error_code KRB5_CALLCONV
7561 krb5_set_trace_callback(krb5_context context, krb5_trace_callback fn,
7562                         void *cb_data);
7563
7564 /**
7565  * Specify a file name for directing trace events.
7566  *
7567  * @param [in] context          Library context
7568  * @param [in] filename         File name
7569  *
7570  * Open @a filename for appending (creating it, if necessary) and set up a
7571  * callback to write trace events to it.
7572  *
7573  * @retval KRB5_TRACE_NOSUPP Tracing is not supported in the library.
7574  */
7575 krb5_error_code KRB5_CALLCONV
7576 krb5_set_trace_filename(krb5_context context, const char *filename);
7577
7578 #if TARGET_OS_MAC
7579 #    pragma pack(pop)
7580 #endif
7581
7582 KRB5INT_END_DECLS
7583
7584 /* Don't use this!  We're going to phase it out.  It's just here to keep
7585    applications from breaking right away.  */
7586 #define krb5_const const
7587
7588 #undef KRB5_ATTR_DEPRECATED
7589
7590 #endif /* KRB5_GENERAL__ */
7591