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