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