Bump the accessor version number since we made changes.
[krb5.git] / src / include / k5-int.h
1 /*
2  * Copyright (C) 1989,1990,1991,1992,1993,1994,1995,2000,2001, 2003,2006,2007,2008,2009 by the Massachusetts Institute of Technology,
3  * Cambridge, MA, USA.  All Rights Reserved.
4  * 
5  * This software is being provided to you, the LICENSEE, by the 
6  * Massachusetts Institute of Technology (M.I.T.) under the following 
7  * license.  By obtaining, using and/or copying this software, you agree 
8  * that you have read, understood, and will comply with these terms and 
9  * conditions:  
10  * 
11  * Export of this software from the United States of America may
12  * require a specific license from the United States Government.
13  * It is the responsibility of any person or organization contemplating
14  * export to obtain such a license before exporting.
15  * 
16  * WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute 
17  * this software and its documentation for any purpose and without fee or 
18  * royalty is hereby granted, provided that you agree to comply with the 
19  * following copyright notice and statements, including the disclaimer, and 
20  * that the same appear on ALL copies of the software and documentation, 
21  * including modifications that you make for internal use or for 
22  * distribution:
23  * 
24  * THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS 
25  * OR WARRANTIES, EXPRESS OR IMPLIED.  By way of example, but not 
26  * limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF 
27  * MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF 
28  * THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY 
29  * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.   
30  * 
31  * The name of the Massachusetts Institute of Technology or M.I.T. may NOT 
32  * be used in advertising or publicity pertaining to distribution of the 
33  * software.  Title to copyright in this software and any associated 
34  * documentation shall at all times remain with M.I.T., and USER agrees to 
35  * preserve same.
36  *
37  * Furthermore if you modify this software you must label
38  * your software as modified software and not distribute it in such a
39  * fashion that it might be confused with the original M.I.T. software.  
40  */
41
42 /*
43  * Copyright (C) 1998 by the FundsXpress, INC.
44  * 
45  * All rights reserved.
46  * 
47  * Export of this software from the United States of America may require
48  * a specific license from the United States Government.  It is the
49  * responsibility of any person or organization contemplating export to
50  * obtain such a license before exporting.
51  * 
52  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
53  * distribute this software and its documentation for any purpose and
54  * without fee is hereby granted, provided that the above copyright
55  * notice appear in all copies and that both that copyright notice and
56  * this permission notice appear in supporting documentation, and that
57  * the name of FundsXpress. not be used in advertising or publicity pertaining
58  * to distribution of the software without specific, written prior
59  * permission.  FundsXpress makes no representations about the suitability of
60  * this software for any purpose.  It is provided "as is" without express
61  * or implied warranty.
62  * 
63  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
64  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
65  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
66  */
67
68 /*
69  * This prototype for k5-int.h (Krb5 internals include file)
70  * includes the user-visible definitions from krb5.h and then
71  * includes other definitions that are not user-visible but are
72  * required for compiling Kerberos internal routines.
73  *
74  * John Gilmore, Cygnus Support, Sat Jan 21 22:45:52 PST 1995
75  */
76
77 #ifndef _KRB5_INT_H
78 #define _KRB5_INT_H
79
80 #ifdef KRB5_GENERAL__
81 #error krb5.h included before k5-int.h
82 #endif /* KRB5_GENERAL__ */
83
84 #include "osconf.h"
85
86 #if defined(__MACH__) && defined(__APPLE__)
87 #       include <TargetConditionals.h>
88 #    if TARGET_RT_MAC_CFM
89 #       error "Use KfM 4.0 SDK headers for CFM compilation."
90 #    endif
91 #endif
92
93 /*
94  * Begin "k5-config.h"
95  */
96 #ifndef KRB5_CONFIG__
97 #define KRB5_CONFIG__
98
99 /* 
100  * Machine-type definitions: PC Clone 386 running Microloss Windows
101  */
102
103 #if defined(_MSDOS) || defined(_WIN32)
104 #include "win-mac.h"
105
106 /* Kerberos Windows initialization file */
107 #define KERBEROS_INI    "kerberos.ini"
108 #define INI_FILES       "Files"
109 #define INI_KRB_CCACHE  "krb5cc"        /* Location of the ccache */
110 #define INI_KRB5_CONF   "krb5.ini"      /* Location of krb5.conf file */
111 #define ANSI_STDIO
112 #endif
113
114 #include "autoconf.h"
115
116 #ifndef KRB5_SYSTYPES__
117 #define KRB5_SYSTYPES__
118
119 #ifdef HAVE_SYS_TYPES_H         /* From autoconf.h */
120 #include <sys/types.h>
121 #else /* HAVE_SYS_TYPES_H */
122 typedef unsigned long   u_long;
123 typedef unsigned int    u_int;
124 typedef unsigned short  u_short;
125 typedef unsigned char   u_char;
126 #endif /* HAVE_SYS_TYPES_H */
127 #endif /* KRB5_SYSTYPES__ */
128
129
130 #include "k5-platform.h"
131 /* not used in krb5.h (yet) */
132 typedef UINT64_TYPE krb5_ui_8;
133 typedef INT64_TYPE krb5_int64;
134
135
136 #define DEFAULT_PWD_STRING1 "Enter password"
137 #define DEFAULT_PWD_STRING2 "Re-enter password for verification"
138
139 #define KRB5_KDB_MAX_LIFE       (60*60*24) /* one day */
140 #define KRB5_KDB_MAX_RLIFE      (60*60*24*7) /* one week */
141 #define KRB5_KDB_EXPIRATION     2145830400 /* Thu Jan  1 00:00:00 2038 UTC */
142
143 /* 
144  * Windows requires a different api interface to each function. Here
145  * just define it as NULL.
146  */
147 #ifndef KRB5_CALLCONV
148 #define KRB5_CALLCONV
149 #define KRB5_CALLCONV_C
150 #endif
151 #ifndef O_BINARY
152 #define O_BINARY 0
153 #endif
154
155 /* #define KRB5_OLD_CRYPTO is done in krb5.h */
156
157 #endif /* KRB5_CONFIG__ */
158
159 /*
160  * End "k5-config.h"
161  */
162
163 /*
164  * After loading the configuration definitions, load the Kerberos definitions.
165  */
166 #include <errno.h>
167 #include "krb5.h"
168 #include "profile.h"
169
170 #include "port-sockets.h"
171 #include "socket-utils.h"
172
173 /* Get mutex support; currently used only for the replay cache.  */
174 #include "k5-thread.h"
175
176 /* Get error info support.  */
177 #include "k5-err.h"
178
179 /* Get string buffer support. */
180 #include "k5-buf.h"
181
182 /* cofiguration variables */
183 #define KRB5_CONF_ACL_FILE                       "acl_file"
184 #define KRB5_CONF_ADMIN_KEYTAB                   "admin_keytab"
185 #define KRB5_CONF_ADMIN_SERVER                   "admin_server"
186 #define KRB5_CONF_ALLOW_WEAK_CRYPTO              "allow_weak_crypto"
187 #define KRB5_CONF_AP_REQ_CHECKSUM_TYPE           "ap_req_checksum_type"
188 #define KRB5_CONF_AUTH_TO_LOCAL                  "auth_to_local"
189 #define KRB5_CONF_AUTH_TO_LOCAL_NAMES            "auth_to_local_names"
190 #define KRB5_CONF_CANONICALIZE                   "canonicalize"
191 #define KRB5_CONF_CCACHE_TYPE                    "ccache_type"
192 #define KRB5_CONF_CLOCKSKEW                      "clockskew"
193 #define KRB5_CONF_DATABASE_NAME                  "database_name"
194 #define KRB5_CONF_DB_MODULE_DIR                  "db_module_dir"
195 #define KRB5_CONF_DB_MODULES                     "db_modules"
196 #define KRB5_CONF_DOMAIN_REALM                   "domain_realm"
197 #define KRB5_CONF_DEFAULT_REALM                  "default_realm"
198 #define KRB5_CONF_DEFAULT_DOMAIN                 "default_domain"
199 #define KRB5_CONF_DEFAULT_TKT_ENCTYPES           "default_tkt_enctypes"
200 #define KRB5_CONF_DEFAULT_TGS_ENCTYPES           "default_tgs_enctypes"
201 #define KRB5_CONF_DEFAULT_KEYTAB_NAME            "default_keytab_name"
202 #define KRB5_CONF_DEFAULT_PRINCIPAL_EXPIRATION   "default_principal_expiration"
203 #define KRB5_CONF_DEFAULT_PRINCIPAL_FLAGS        "default_principal_flags"
204 #define KRB5_CONF_DICT_FILE                   "dict_file"
205 #define KRB5_CONF_DNS_LOOKUP_KDC              "dns_lookup_kdc"
206 #define KRB5_CONF_DNS_LOOKUP_REALM            "dns_lookup_realm"
207 #define KRB5_CONF_DNS_FALLBACK                "dns_fallback"
208 #define KRB5_CONF_EXTRA_ADDRESSES             "extra_addresses"
209 #define KRB5_CONF_FORWARDABLE                 "forwardable"
210 #define KRB5_CONF_HOST_BASED_SERVICES         "host_based_services"
211 #define KRB5_CONF_IPROP_ENABLE                "iprop_enable"
212 #define KRB5_CONF_IPROP_MASTER_ULOGSIZE       "iprop_master_ulogsize"
213 #define KRB5_CONF_IPROP_PORT                  "iprop_port"
214 #define KRB5_CONF_IPROP_SLAVE_POLL            "iprop_slave_poll"
215 #define KRB5_CONF_IPROP_LOGFILE               "iprop_logfile"
216 #define KRB5_CONF_KADMIND_PORT                "kadmind_port"
217 #define KRB5_CONF_KRB524_SERVER               "krb524_server"
218 #define KRB5_CONF_KDC                         "kdc"
219 #define KRB5_CONF_KDCDEFAULTS                 "kdcdefaults"
220 #define KRB5_CONF_KDC_PORTS                   "kdc_ports"
221 #define KRB5_CONF_KDC_TCP_PORTS               "kdc_tcp_ports"
222 #define KRB5_CONF_MAX_DGRAM_REPLY_SIZE        "kdc_max_dgram_reply_size"
223 #define KRB5_CONF_KDC_DEFAULT_OPTIONS         "kdc_default_options"
224 #define KRB5_CONF_KDC_TIMESYNC                "kdc_timesync"
225 #define KRB5_CONF_KDC_REQ_CHECKSUM_TYPE       "kdc_req_checksum_type"
226 #define KRB5_CONF_KEY_STASH_FILE              "key_stash_file"
227 #define KRB5_CONF_KPASSWD_PORT                "kpasswd_port"
228 #define KRB5_CONF_KPASSWD_SERVER              "kpasswd_server"
229 #define KRB5_CONF_LIBDEFAULTS                 "libdefaults"
230 #define KRB5_CONF_LDAP_KDC_DN                 "ldap_kdc_dn"
231 #define KRB5_CONF_LDAP_KADMIN_DN              "ldap_kadmind_dn"
232 #define KRB5_CONF_LDAP_SERVICE_PASSWORD_FILE  "ldap_service_password_file"
233 #define KRB5_CONF_LDAP_ROOT_CERTIFICATE_FILE  "ldap_root_certificate_file"
234 #define KRB5_CONF_LDAP_SERVERS                "ldap_servers"
235 #define KRB5_CONF_LDAP_CONNS_PER_SERVER       "ldap_conns_per_server"
236 #define KRB5_CONF_NO_HOST_REFERRAL            "no_host_referral"
237 #define KRB5_CONF_MASTER_KEY_NAME             "master_key_name"
238 #define KRB5_CONF_MASTER_KEY_TYPE             "master_key_type"
239 #define KRB5_CONF_MASTER_KDC                  "master_kdc"
240 #define KRB5_CONF_MAX_LIFE                    "max_life"
241 #define KRB5_CONF_MAX_RENEWABLE_LIFE          "max_renewable_life"
242 #define KRB5_CONF_NOADDRESSES                 "noaddresses"
243 #define KRB5_CONF_PERMITTED_ENCTYPES          "permitted_enctypes"
244 #define KRB5_CONF_PREFERRED_PREAUTH_TYPES     "preferred_preauth_types"
245 #define KRB5_CONF_PROXIABLE                   "proxiable"
246 #define KRB5_CONF_RDNS                        "rdns"
247 #define KRB5_CONF_REALMS                      "realms"
248 #define KRB5_CONF_REALM_TRY_DOMAINS           "realm_try_domains"
249 #define KRB5_CONF_REJECT_BAD_TRANSIT          "reject_bad_transit"
250 #define KRB5_CONF_RENEW_LIFETIME              "renew_lifetime"
251 #define KRB5_CONF_SAFE_CHECKSUM_TYPE          "safe_checksum_type"
252 #define KRB5_CONF_SUPPORTED_ENCTYPES          "supported_enctypes"
253 #define KRB5_CONF_TICKET_LIFETIME             "ticket_lifetime"
254 #define KRB5_CONF_UDP_PREFERENCE_LIMIT        "udp_preference_limit"
255 #define KRB5_CONF_VERIFY_AP_REQ_NOFAIL        "verify_ap_req_nofail"
256 #define KRB5_CONF_V4_INSTANCE_CONVERT         "v4_instance_convert"
257 #define KRB5_CONF_V4_REALM                    "v4_realm"
258 #define KRB5_CONF_ASTERISK                    "*"
259
260 /* Error codes used in KRB_ERROR protocol messages.
261    Return values of library routines are based on a different error table
262    (which allows non-ambiguous error codes between subsystems) */
263
264 /* KDC errors */
265 #define KDC_ERR_NONE                    0 /* No error */
266 #define KDC_ERR_NAME_EXP                1 /* Client's entry in DB expired */
267 #define KDC_ERR_SERVICE_EXP             2 /* Server's entry in DB expired */
268 #define KDC_ERR_BAD_PVNO                3 /* Requested pvno not supported */
269 #define KDC_ERR_C_OLD_MAST_KVNO         4 /* C's key encrypted in old master */
270 #define KDC_ERR_S_OLD_MAST_KVNO         5 /* S's key encrypted in old master */
271 #define KDC_ERR_C_PRINCIPAL_UNKNOWN     6 /* Client not found in Kerberos DB */
272 #define KDC_ERR_S_PRINCIPAL_UNKNOWN     7 /* Server not found in Kerberos DB */
273 #define KDC_ERR_PRINCIPAL_NOT_UNIQUE    8 /* Multiple entries in Kerberos DB */
274 #define KDC_ERR_NULL_KEY                9 /* The C or S has a null key */
275 #define KDC_ERR_CANNOT_POSTDATE         10 /* Tkt ineligible for postdating */
276 #define KDC_ERR_NEVER_VALID             11 /* Requested starttime > endtime */
277 #define KDC_ERR_POLICY                  12 /* KDC policy rejects request */
278 #define KDC_ERR_BADOPTION               13 /* KDC can't do requested opt. */
279 #define KDC_ERR_ENCTYPE_NOSUPP          14 /* No support for encryption type */
280 #define KDC_ERR_SUMTYPE_NOSUPP          15 /* No support for checksum type */
281 #define KDC_ERR_PADATA_TYPE_NOSUPP      16 /* No support for padata type */
282 #define KDC_ERR_TRTYPE_NOSUPP           17 /* No support for transited type */
283 #define KDC_ERR_CLIENT_REVOKED          18 /* C's creds have been revoked */
284 #define KDC_ERR_SERVICE_REVOKED         19 /* S's creds have been revoked */
285 #define KDC_ERR_TGT_REVOKED             20 /* TGT has been revoked */
286 #define KDC_ERR_CLIENT_NOTYET           21 /* C not yet valid */
287 #define KDC_ERR_SERVICE_NOTYET          22 /* S not yet valid */
288 #define KDC_ERR_KEY_EXP                 23 /* Password has expired */
289 #define KDC_ERR_PREAUTH_FAILED          24 /* Preauthentication failed */
290 #define KDC_ERR_PREAUTH_REQUIRED        25 /* Additional preauthentication */
291                                            /* required */
292 #define KDC_ERR_SERVER_NOMATCH          26 /* Requested server and */
293                                            /* ticket don't match*/
294 #define KDC_ERR_MUST_USE_USER2USER      27 /* Server principal valid for */
295                                            /*   user2user only */
296 #define KDC_ERR_PATH_NOT_ACCEPTED       28 /* KDC policy rejected transited */
297                                            /*   path */
298 #define KDC_ERR_SVC_UNAVAILABLE         29 /* A service is not
299                                             * available that is
300                                             * required to process the
301                                             * request */
302 /* Application errors */
303 #define KRB_AP_ERR_BAD_INTEGRITY 31     /* Decrypt integrity check failed */
304 #define KRB_AP_ERR_TKT_EXPIRED  32      /* Ticket expired */
305 #define KRB_AP_ERR_TKT_NYV      33      /* Ticket not yet valid */
306 #define KRB_AP_ERR_REPEAT       34      /* Request is a replay */
307 #define KRB_AP_ERR_NOT_US       35      /* The ticket isn't for us */
308 #define KRB_AP_ERR_BADMATCH     36      /* Ticket/authenticator don't match */
309 #define KRB_AP_ERR_SKEW         37      /* Clock skew too great */
310 #define KRB_AP_ERR_BADADDR      38      /* Incorrect net address */
311 #define KRB_AP_ERR_BADVERSION   39      /* Protocol version mismatch */
312 #define KRB_AP_ERR_MSG_TYPE     40      /* Invalid message type */
313 #define KRB_AP_ERR_MODIFIED     41      /* Message stream modified */
314 #define KRB_AP_ERR_BADORDER     42      /* Message out of order */
315 #define KRB_AP_ERR_BADKEYVER    44      /* Key version is not available */
316 #define KRB_AP_ERR_NOKEY        45      /* Service key not available */
317 #define KRB_AP_ERR_MUT_FAIL     46      /* Mutual authentication failed */
318 #define KRB_AP_ERR_BADDIRECTION 47      /* Incorrect message direction */
319 #define KRB_AP_ERR_METHOD       48      /* Alternative authentication */
320                                         /* method required */
321 #define KRB_AP_ERR_BADSEQ       49      /* Incorrect sequence numnber */
322                                         /* in message */
323 #define KRB_AP_ERR_INAPP_CKSUM  50      /* Inappropriate type of */
324                                         /* checksum in message */
325 #define KRB_AP_PATH_NOT_ACCEPTED 51     /* Policy rejects transited path */
326 #define KRB_ERR_RESPONSE_TOO_BIG 52     /* Response too big for UDP, */
327                                         /*   retry with TCP */
328
329 /* other errors */
330 #define KRB_ERR_GENERIC         60      /* Generic error (description */
331                                         /* in e-text) */
332 #define KRB_ERR_FIELD_TOOLONG   61      /* Field is too long for impl. */
333
334 /* PKINIT server-reported errors */
335 #define KDC_ERR_CLIENT_NOT_TRUSTED              62 /* client cert not trusted */
336 #define KDC_ERR_KDC_NOT_TRUSTED                 63
337 #define KDC_ERR_INVALID_SIG                     64 /* client signature verify failed */
338 #define KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED  65 /* invalid Diffie-Hellman parameters */
339 #define KDC_ERR_CERTIFICATE_MISMATCH            66
340 #define KRB_AP_ERR_NO_TGT                       67
341 #define KDC_ERR_WRONG_REALM                     68
342 #define KRB_AP_ERR_USER_TO_USER_REQUIRED        69
343 #define KDC_ERR_CANT_VERIFY_CERTIFICATE         70 /* client cert not verifiable to */
344                                                    /* trusted root cert */
345 #define KDC_ERR_INVALID_CERTIFICATE             71 /* client cert had invalid signature */
346 #define KDC_ERR_REVOKED_CERTIFICATE             72 /* client cert was revoked */
347 #define KDC_ERR_REVOCATION_STATUS_UNKNOWN       73 /* client cert revoked, reason unknown */
348 #define KDC_ERR_REVOCATION_STATUS_UNAVAILABLE   74
349 #define KDC_ERR_CLIENT_NAME_MISMATCH            75 /* mismatch between client cert and */
350                                                    /* principal name */
351 #define KDC_ERR_INCONSISTENT_KEY_PURPOSE        77 /* bad extended key use */
352 #define KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED     78 /* bad digest algorithm in client cert */
353 #define KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED    79 /* missing paChecksum in PA-PK-AS-REQ */
354 #define KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED 80 /* bad digest algorithm in SignedData */
355 #define KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED 81
356
357 /*
358  * This structure is returned in the e-data field of the KRB-ERROR
359  * message when the error calling for an alternative form of
360  * authentication is returned, KRB_AP_METHOD.
361  */
362 typedef struct _krb5_alt_method {
363         krb5_magic      magic;
364         krb5_int32      method;
365         unsigned int    length;
366         krb5_octet      *data;
367 } krb5_alt_method;
368
369 /*
370  * A null-terminated array of this structure is returned by the KDC as
371  * the data part of the ETYPE_INFO preauth type.  It informs the
372  * client which encryption types are supported.
373  * The  same data structure is used by both etype-info and etype-info2
374  * but s2kparams must be null when encoding etype-info.
375  */
376 typedef struct _krb5_etype_info_entry {
377         krb5_magic      magic;
378         krb5_enctype    etype;
379         unsigned int    length;
380         krb5_octet      *salt;
381     krb5_data s2kparams;
382 } krb5_etype_info_entry;
383
384 /* 
385  *  This is essentially -1 without sign extension which can screw up
386  *  comparisons on 64 bit machines. If the length is this value, then
387  *  the salt data is not present. This is to distinguish between not
388  *  being set and being of 0 length. 
389  */
390 #define KRB5_ETYPE_NO_SALT VALID_UINT_BITS
391
392 typedef krb5_etype_info_entry ** krb5_etype_info;
393
394 /* RFC 4537 */
395 typedef struct _krb5_etype_list {
396         int             length;
397         krb5_enctype    *etypes;
398 } krb5_etype_list;
399
400 /*
401  * a sam_challenge is returned for alternate preauth 
402  */
403 /*
404           SAMFlags ::= BIT STRING {
405               use-sad-as-key[0],
406               send-encrypted-sad[1],
407               must-pk-encrypt-sad[2]
408           }
409  */
410 /*
411           PA-SAM-CHALLENGE ::= SEQUENCE {
412               sam-type[0]                 INTEGER,
413               sam-flags[1]                SAMFlags,
414               sam-type-name[2]            GeneralString OPTIONAL,
415               sam-track-id[3]             GeneralString OPTIONAL,
416               sam-challenge-label[4]      GeneralString OPTIONAL,
417               sam-challenge[5]            GeneralString OPTIONAL,
418               sam-response-prompt[6]      GeneralString OPTIONAL,
419               sam-pk-for-sad[7]           EncryptionKey OPTIONAL,
420               sam-nonce[8]                INTEGER OPTIONAL,
421               sam-cksum[9]                Checksum OPTIONAL
422           }
423 */
424 /* sam_type values -- informational only */
425 #define PA_SAM_TYPE_ENIGMA     1   /*  Enigma Logic */
426 #define PA_SAM_TYPE_DIGI_PATH  2   /*  Digital Pathways */
427 #define PA_SAM_TYPE_SKEY_K0    3   /*  S/key where  KDC has key 0 */
428 #define PA_SAM_TYPE_SKEY       4   /*  Traditional S/Key */
429 #define PA_SAM_TYPE_SECURID    5   /*  Security Dynamics */
430 #define PA_SAM_TYPE_CRYPTOCARD 6   /*  CRYPTOCard */
431 #if 1 /* XXX need to figure out who has which numbers assigned */
432 #define PA_SAM_TYPE_ACTIVCARD_DEC  6   /*  ActivCard decimal mode */
433 #define PA_SAM_TYPE_ACTIVCARD_HEX  7   /*  ActivCard hex mode */
434 #define PA_SAM_TYPE_DIGI_PATH_HEX  8   /*  Digital Pathways hex mode */
435 #endif
436 #define PA_SAM_TYPE_EXP_BASE    128 /* experimental */
437 #define PA_SAM_TYPE_GRAIL               (PA_SAM_TYPE_EXP_BASE+0) /* testing */
438 #define PA_SAM_TYPE_SECURID_PREDICT     (PA_SAM_TYPE_EXP_BASE+1) /* special */
439
440 typedef struct _krb5_predicted_sam_response {
441         krb5_magic      magic;
442         krb5_keyblock   sam_key;
443         krb5_flags      sam_flags; /* Makes key munging easier */
444         krb5_timestamp  stime;  /* time on server, for replay detection */
445         krb5_int32      susec;
446         krb5_principal  client;
447         krb5_data       msd;    /* mechanism specific data */
448 } krb5_predicted_sam_response;
449
450 typedef struct _krb5_sam_challenge {
451         krb5_magic      magic;
452         krb5_int32      sam_type; /* information */
453         krb5_flags      sam_flags; /* KRB5_SAM_* values */
454         krb5_data       sam_type_name;
455         krb5_data       sam_track_id;
456         krb5_data       sam_challenge_label;
457         krb5_data       sam_challenge;
458         krb5_data       sam_response_prompt;
459         krb5_data       sam_pk_for_sad;
460         krb5_int32      sam_nonce;
461         krb5_checksum   sam_cksum;
462 } krb5_sam_challenge;
463
464 typedef struct _krb5_sam_key {  /* reserved for future use */
465         krb5_magic      magic;
466         krb5_keyblock   sam_key;
467 } krb5_sam_key;
468
469 typedef struct _krb5_enc_sam_response_enc {
470         krb5_magic      magic;
471         krb5_int32      sam_nonce;
472         krb5_timestamp  sam_timestamp;
473         krb5_int32      sam_usec;
474         krb5_data       sam_sad;
475 } krb5_enc_sam_response_enc;
476
477 typedef struct _krb5_sam_response {
478         krb5_magic      magic;
479         krb5_int32      sam_type; /* informational */
480         krb5_flags      sam_flags; /* KRB5_SAM_* values */
481         krb5_data       sam_track_id; /* copied */
482         krb5_enc_data   sam_enc_key; /* krb5_sam_key - future use */
483         krb5_enc_data   sam_enc_nonce_or_ts; /* krb5_enc_sam_response_enc */
484         krb5_int32      sam_nonce;
485         krb5_timestamp  sam_patimestamp;
486 } krb5_sam_response;
487
488 typedef struct _krb5_sam_challenge_2 {
489         krb5_data       sam_challenge_2_body;
490         krb5_checksum   **sam_cksum;            /* Array of checksums */
491 } krb5_sam_challenge_2;
492
493 typedef struct _krb5_sam_challenge_2_body {
494         krb5_magic      magic;
495         krb5_int32      sam_type; /* information */
496         krb5_flags      sam_flags; /* KRB5_SAM_* values */
497         krb5_data       sam_type_name;
498         krb5_data       sam_track_id;
499         krb5_data       sam_challenge_label;
500         krb5_data       sam_challenge;
501         krb5_data       sam_response_prompt;
502         krb5_data       sam_pk_for_sad;
503         krb5_int32      sam_nonce;
504         krb5_enctype    sam_etype;
505 } krb5_sam_challenge_2_body;
506
507 typedef struct _krb5_sam_response_2 {
508         krb5_magic      magic;
509         krb5_int32      sam_type; /* informational */
510         krb5_flags      sam_flags; /* KRB5_SAM_* values */
511         krb5_data       sam_track_id; /* copied */
512         krb5_enc_data   sam_enc_nonce_or_sad; /* krb5_enc_sam_response_enc */
513         krb5_int32      sam_nonce;
514 } krb5_sam_response_2;
515
516 typedef struct _krb5_enc_sam_response_enc_2 {
517         krb5_magic      magic;
518         krb5_int32      sam_nonce;
519         krb5_data       sam_sad;
520 } krb5_enc_sam_response_enc_2;
521
522 /*
523  * Keep the pkinit definitions in a separate file so that the plugin
524  * only has to include k5-int-pkinit.h rather than k5-int.h
525  */
526
527 #include "k5-int-pkinit.h"
528
529 #include <stdlib.h>
530 #include <string.h>
531
532 #ifndef HAVE_STRDUP
533 extern char *strdup (const char *);
534 #endif
535
536 #ifdef HAVE_UNISTD_H
537 #include <unistd.h>
538 #endif
539
540 #ifdef HAVE_SYS_TIME_H
541 #include <sys/time.h>
542 #ifdef TIME_WITH_SYS_TIME
543 #include <time.h>
544 #endif
545 #else
546 #include <time.h>
547 #endif
548
549 #ifdef HAVE_SYS_STAT_H
550 #include <sys/stat.h>                   /* struct stat, stat() */
551 #endif
552
553 #ifdef HAVE_SYS_PARAM_H
554 #include <sys/param.h>                  /* MAXPATHLEN */
555 #endif
556
557 #ifdef HAVE_SYS_FILE_H
558 #include <sys/file.h>                   /* prototypes for file-related
559                                            syscalls; flags for open &
560                                            friends */
561 #endif
562
563 #ifdef HAVE_FCNTL_H
564 #include <fcntl.h>
565 #endif
566
567 #include <stdio.h>
568
569 #include "k5-gmt_mktime.h"
570
571 struct addrlist;
572 struct sendto_callback_info;
573
574 /* libos.spec */
575 krb5_error_code krb5_lock_file (krb5_context, int, int);
576 krb5_error_code krb5_unlock_file (krb5_context, int);
577 krb5_error_code krb5_sendto_kdc (krb5_context, const krb5_data *,
578                                  const krb5_data *, krb5_data *, int *, int);
579
580 krb5_error_code krb5int_sendto (krb5_context context, const krb5_data *message,
581                 const struct addrlist *addrs, struct sendto_callback_info* callback_info,
582                                 krb5_data *reply, struct sockaddr *localaddr, socklen_t *localaddrlen,
583                 struct sockaddr *remoteaddr, socklen_t *remoteaddrlen, int *addr_used,
584                 int (*msg_handler)(krb5_context, const krb5_data *, void *),
585                 void *msg_handler_data);
586
587 krb5_error_code krb5_get_krbhst (krb5_context, const krb5_data *, char *** );
588 krb5_error_code krb5_free_krbhst (krb5_context, char * const * );
589 krb5_error_code krb5_create_secure_file (krb5_context, const char * pathname);
590 krb5_error_code krb5_sync_disk_file (krb5_context, FILE *fp);
591
592 krb5_error_code krb5int_get_fq_local_hostname (char *, size_t);
593
594 krb5_error_code krb5int_init_context_kdc(krb5_context *);
595
596 krb5_error_code krb5_os_init_context (krb5_context, krb5_boolean);
597
598 void krb5_os_free_context (krb5_context);
599
600 /* This function is needed by KfM's KerberosPreferences API 
601  * because it needs to be able to specify "secure" */
602 krb5_error_code os_get_default_config_files 
603     (profile_filespec_t **pfiles, krb5_boolean secure);
604
605 krb5_error_code krb5_os_hostaddr
606         (krb5_context, const char *, krb5_address ***);
607
608 krb5_error_code krb5int_get_domain_realm_mapping
609         (krb5_context , const char *, char ***);
610
611 /* N.B.: You need to include fake-addrinfo.h *before* k5-int.h if you're
612    going to use this structure.  */
613 struct addrlist {
614     struct {
615 #ifdef FAI_DEFINED
616         struct addrinfo *ai;
617 #else
618         struct undefined_addrinfo *ai;
619 #endif
620         void (*freefn)(void *);
621         void *data;
622     } *addrs;
623     int naddrs;
624     int space;
625 };
626 #define ADDRLIST_INIT { 0, 0, 0 }
627 extern void krb5int_free_addrlist (struct addrlist *);
628 extern int krb5int_grow_addrlist (struct addrlist *, int);
629 extern int krb5int_add_host_to_list (struct addrlist *, const char *,
630                                      int, int, int, int);
631
632 #include <krb5/locate_plugin.h>
633 krb5_error_code
634 krb5int_locate_server (krb5_context, const krb5_data *realm,
635                        struct addrlist *, enum locate_service_type svc,
636                        int sockettype, int family);
637
638 struct derived_key {
639     krb5_data constant;
640     krb5_key dkey;
641     struct derived_key *next;
642 };
643
644 /* Internal structure of an opaque key identifier */
645 struct krb5_key_st {
646     krb5_keyblock keyblock;
647     int refcount;
648     struct derived_key *derived;
649 };
650
651 /* new encryption provider api */
652
653 struct krb5_enc_provider {
654     /* keybytes is the input size to make_key; 
655        keylength is the output size */
656     size_t block_size, keybytes, keylength;
657
658     /* cipher-state == 0 fresh state thrown away at end */
659     krb5_error_code (*encrypt) (krb5_key key,
660                                 const krb5_data *cipher_state,
661                                 const krb5_data *input,
662                                 krb5_data *output);
663
664     krb5_error_code (*decrypt) (krb5_key key,
665                                 const krb5_data *ivec,
666                                 const krb5_data *input,
667                                 krb5_data *output);
668
669     krb5_error_code (*make_key) (const krb5_data *randombits,
670                                  krb5_keyblock *key);
671
672   krb5_error_code (*init_state) (const krb5_keyblock *key,
673                                  krb5_keyusage keyusage, krb5_data *out_state);
674   krb5_error_code (*free_state) (krb5_data *state);
675
676     /* In-place encryption/decryption of multiple buffers */
677     krb5_error_code (*encrypt_iov) (krb5_key key,
678                                     const krb5_data *cipher_state,
679                                     krb5_crypto_iov *data,
680                                     size_t num_data);
681
682
683     krb5_error_code (*decrypt_iov) (krb5_key key,
684                                     const krb5_data *cipher_state,
685                                     krb5_crypto_iov *data,
686                                     size_t num_data);
687
688 };
689
690 struct krb5_hash_provider {
691     char hash_name[8];
692     size_t hashsize, blocksize;
693
694     /* this takes multiple inputs to avoid lots of copying. */
695     krb5_error_code (*hash) (unsigned int icount, const krb5_data *input,
696                              krb5_data *output);
697 };
698
699 struct krb5_keyhash_provider {
700     size_t hashsize;
701
702     krb5_error_code (*hash) (krb5_key key,
703                              krb5_keyusage keyusage,
704                              const krb5_data *ivec,
705                              const krb5_data *input,
706                              krb5_data *output);
707
708     krb5_error_code (*verify) (krb5_key key,
709                                krb5_keyusage keyusage,
710                                const krb5_data *ivec,
711                                const krb5_data *input,
712                                const krb5_data *hash,
713                                krb5_boolean *valid);
714
715     krb5_error_code (*hash_iov) (krb5_key key,
716                                  krb5_keyusage keyusage,
717                                  const krb5_data *ivec,
718                                  const krb5_crypto_iov *data,
719                                  size_t num_data,
720                                  krb5_data *output);
721
722     krb5_error_code (*verify_iov) (krb5_key key,
723                                   krb5_keyusage keyusage,
724                                   const krb5_data *ivec,
725                                   const krb5_crypto_iov *data,
726                                   size_t num_data,
727                                   const krb5_data *hash,
728                                   krb5_boolean *valid);
729 };
730
731 struct krb5_aead_provider {
732     krb5_error_code (*crypto_length) (const struct krb5_aead_provider *aead,
733                                       const struct krb5_enc_provider *enc,
734                                       const struct krb5_hash_provider *hash,
735                                       krb5_cryptotype type,
736                                       unsigned int *length);
737     krb5_error_code (*encrypt_iov) (const struct krb5_aead_provider *aead,
738                                     const struct krb5_enc_provider *enc,
739                                     const struct krb5_hash_provider *hash,
740                                     krb5_key key,
741                                     krb5_keyusage keyusage,
742                                     const krb5_data *ivec,
743                                     krb5_crypto_iov *data,
744                                     size_t num_data);
745     krb5_error_code (*decrypt_iov) (const struct krb5_aead_provider *aead,
746                                     const struct krb5_enc_provider *enc,
747                                     const struct krb5_hash_provider *hash,
748                                     krb5_key key,
749                                     krb5_keyusage keyusage,
750                                     const krb5_data *ivec,
751                                     krb5_crypto_iov *data,
752                                     size_t num_data);
753 };
754
755 /*
756  * in here to deal with stuff from lib/crypto
757  */
758
759 void krb5int_nfold
760 (unsigned int inbits, const unsigned char *in,
761                 unsigned int outbits, unsigned char *out);
762
763 krb5_error_code krb5int_hmac
764 (const struct krb5_hash_provider *hash,
765                 krb5_key key, unsigned int icount,
766                 const krb5_data *input, krb5_data *output);
767
768 krb5_error_code krb5int_hmac_iov
769 (const struct krb5_hash_provider *hash,
770                 krb5_key key,
771                 const krb5_crypto_iov *data, size_t num_data,
772                 krb5_data *output);
773
774 krb5_error_code krb5int_hmac_keyblock
775 (const struct krb5_hash_provider *hash,
776                 const krb5_keyblock *key, unsigned int icount,
777                 const krb5_data *input, krb5_data *output);
778
779 krb5_error_code krb5int_hmac_iov_keyblock
780 (const struct krb5_hash_provider *hash,
781                 const krb5_keyblock *key,
782                 const krb5_crypto_iov *data, size_t num_data,
783                 krb5_data *output);
784
785 krb5_error_code krb5int_pbkdf2_hmac_sha1 (const krb5_data *, unsigned long,
786                                           const krb5_data *,
787                                           const krb5_data *);
788
789 /* Make this a function eventually?  */
790 #ifdef _WIN32
791 # define krb5int_zap_data(ptr, len) SecureZeroMemory(ptr, len)
792 #elif defined(__GNUC__)
793 static inline void krb5int_zap_data(void *ptr, size_t len)
794 {
795     memset(ptr, 0, len);
796     asm volatile ("" : : "g" (ptr), "g" (len));
797 }
798 #else
799 # define krb5int_zap_data(ptr, len) memset((volatile void *)ptr, 0, len)
800 #endif /* WIN32 */
801 #define zap(p,l) krb5int_zap_data(p,l)
802
803 /* Convenience function: zap and free ptr if it is non-NULL. */
804 static inline void
805 zapfree(void *ptr, size_t len)
806 {
807     if (ptr != NULL) {
808         zap(ptr, len);
809         free(ptr);
810     }
811 }
812
813 /* A definition of init_state for DES based encryption systems.
814  * sets up an 8-byte IV of all zeros
815  */
816
817 krb5_error_code krb5int_des_init_state
818 (const krb5_keyblock *key, krb5_keyusage keyusage, krb5_data *new_state);
819
820 /* 
821  * normally to free a cipher_state you can just memset the length to zero and
822  * free it.
823  */
824 krb5_error_code krb5int_default_free_state
825 (krb5_data *state);
826
827
828 /*
829  * Combine two keys (normally used by the hardware preauth mechanism)
830  */
831 krb5_error_code krb5int_c_combine_keys
832 (krb5_context context, krb5_keyblock *key1, krb5_keyblock *key2,
833                 krb5_keyblock *outkey);
834
835
836 void  krb5int_c_free_keyblock
837 (krb5_context, krb5_keyblock *key);
838 void  krb5int_c_free_keyblock_contents
839         (krb5_context, krb5_keyblock *);
840 krb5_error_code krb5int_c_init_keyblock
841                 (krb5_context, krb5_enctype enctype,
842                 size_t length, krb5_keyblock **out); 
843 krb5_error_code krb5int_c_copy_keyblock
844 (krb5_context context, const krb5_keyblock *from, krb5_keyblock **to);
845 krb5_error_code krb5int_c_copy_keyblock_contents
846 (krb5_context context, const krb5_keyblock *from, krb5_keyblock *to);
847
848 /*
849  * Internal - for cleanup.
850  */
851 extern void krb5int_prng_cleanup (void);
852
853
854 /* 
855  * These declarations are here, so both krb5 and k5crypto
856  * can get to them.
857  * krb5 needs to get to them so it can  make them available to libgssapi.
858  */
859 extern const struct krb5_enc_provider krb5int_enc_arcfour;
860 extern const struct krb5_hash_provider krb5int_hash_md5;
861
862
863 #ifdef KRB5_OLD_CRYPTO
864 /* old provider api */
865
866 krb5_error_code krb5_crypto_os_localaddr
867         (krb5_address ***);
868
869 krb5_error_code krb5_crypto_us_timeofday
870         (krb5_int32 *,
871                 krb5_int32 *);
872
873 #endif /* KRB5_OLD_CRYPTO */
874
875 /* this helper fct is in libkrb5, but it makes sense declared here. */
876
877 krb5_error_code krb5_encrypt_helper
878 (krb5_context context, const krb5_keyblock *key,
879                 krb5_keyusage keyusage, const krb5_data *plain,
880                 krb5_enc_data *cipher);
881
882 krb5_error_code krb5_encrypt_keyhelper
883 (krb5_context context, krb5_key key,
884                 krb5_keyusage keyusage, const krb5_data *plain,
885                 krb5_enc_data *cipher);
886
887 /*
888  * End "los-proto.h"
889  */
890
891 typedef struct _krb5_os_context {
892         krb5_magic              magic;
893         krb5_int32              time_offset;
894         krb5_int32              usec_offset;
895         krb5_int32              os_flags;
896         char *                  default_ccname;
897 } *krb5_os_context;
898
899 /*
900  * Flags for the os_flags field
901  *
902  * KRB5_OS_TOFFSET_VALID means that the time offset fields are valid.
903  * The intention is that this facility to correct the system clocks so
904  * that they reflect the "real" time, for systems where for some
905  * reason we can't set the system clock.  Instead we calculate the
906  * offset between the system time and real time, and store the offset
907  * in the os context so that we can correct the system clock as necessary.
908  *
909  * KRB5_OS_TOFFSET_TIME means that the time offset fields should be
910  * returned as the time by the krb5 time routines.  This should only
911  * be used for testing purposes (obviously!)
912  */
913 #define KRB5_OS_TOFFSET_VALID   1
914 #define KRB5_OS_TOFFSET_TIME    2
915
916 /* lock mode flags */
917 #define KRB5_LOCKMODE_SHARED    0x0001
918 #define KRB5_LOCKMODE_EXCLUSIVE 0x0002
919 #define KRB5_LOCKMODE_DONTBLOCK 0x0004
920 #define KRB5_LOCKMODE_UNLOCK    0x0008
921
922 /*
923  * Define our view of the size of a DES key.
924  */
925 #define KRB5_MIT_DES_KEYSIZE            8
926 #define KRB5_MIT_DES3_KEYSIZE           24
927 #define KRB5_MIT_DES3_KEY_BYTES         21
928
929 /*
930  * Check if des_int.h has been included before us.  If so, then check to see
931  * that our view of the DES key size is the same as des_int.h's.
932  */
933 #ifdef  MIT_DES_KEYSIZE
934 #if     MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE
935 error(MIT_DES_KEYSIZE does not equal KRB5_MIT_DES_KEYSIZE)
936 #endif  /* MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE */
937 #endif  /* MIT_DES_KEYSIZE */
938
939 /*
940  * Begin "preauth.h"
941  *
942  * (Originally written by Glen Machin at Sandia Labs.)
943  */
944 /*
945  * Sandia National Laboratories also makes no representations about the 
946  * suitability of the modifications, or additions to this software for 
947  * any purpose.  It is provided "as is" without express or implied warranty.
948  * 
949  */
950 #ifndef KRB5_PREAUTH__
951 #define KRB5_PREAUTH__
952
953 #include <krb5/preauth_plugin.h>
954
955 #define CLIENT_ROCK_MAGIC 0x4352434b
956 /* This structure is passed into the client preauth functions and passed
957  * back to the "get_data_proc" function so that it can locate the
958  * requested information.  It is opaque to the plugin code and can be
959  * expanded in the future as new types of requests are defined which
960  * may require other things to be passed through. */
961     struct krb5int_fast_request_state;
962 typedef struct _krb5_preauth_client_rock {
963         krb5_magic      magic;
964     krb5_enctype *etype;
965     struct krb5int_fast_request_state *fast_state;
966 } krb5_preauth_client_rock;
967
968 /* This structure lets us keep track of all of the modules which are loaded,
969  * turning the list of modules and their lists of implemented preauth types
970  * into a single list which we can walk easily. */
971 typedef struct _krb5_preauth_context {
972     int n_modules;
973     struct _krb5_preauth_context_module {
974         /* Which of the possibly more than one preauth types which the
975          * module supports we're using at this point in the list. */
976         krb5_preauthtype pa_type;
977         /* Encryption types which the client claims to support -- we
978          * copy them directly into the krb5_kdc_req structure during
979          * krb5_preauth_prepare_request(). */
980         krb5_enctype *enctypes;
981         /* The plugin's per-plugin context and a function to clear it. */
982         void *plugin_context;
983         preauth_client_plugin_fini_proc client_fini;
984         /* The module's table, and some of its members, copied here for
985          * convenience when we populated the list. */
986         struct krb5plugin_preauth_client_ftable_v1 *ftable;
987         const char *name;
988         int flags, use_count;
989         preauth_client_process_proc client_process;
990         preauth_client_tryagain_proc client_tryagain;
991         preauth_client_supply_gic_opts_proc client_supply_gic_opts;
992         preauth_client_request_init_proc client_req_init;
993         preauth_client_request_fini_proc client_req_fini;
994         /* The per-request context which the client_req_init() function
995          * might allocate, which we'll need to clean up later by
996          * calling the client_req_fini() function. */
997         void *request_context;
998         /* A pointer to the request_context pointer.  All modules within
999          * a plugin will point at the request_context of the first
1000          * module within the plugin. */
1001         void **request_context_pp;
1002     } *modules;
1003 } krb5_preauth_context;
1004
1005 typedef struct _krb5_pa_enc_ts {
1006     krb5_timestamp      patimestamp;
1007     krb5_int32          pausec;
1008 } krb5_pa_enc_ts;
1009
1010 typedef struct _krb5_pa_for_user {
1011     krb5_principal      user;
1012     krb5_checksum       cksum;
1013     krb5_data           auth_package;
1014 } krb5_pa_for_user;
1015
1016 typedef struct _krb5_s4u_userid {
1017     krb5_int32          nonce;
1018     krb5_principal      user;
1019     krb5_data           subject_cert;
1020     krb5_flags          options;
1021 } krb5_s4u_userid;
1022
1023 #define KRB5_S4U_OPTS_CHECK_LOGON_HOURS         0x40000000 /* check logon hour restrictions */
1024 #define KRB5_S4U_OPTS_USE_REPLY_KEY_USAGE       0x20000000 /* sign with usage 27 instead of 26 */
1025
1026 typedef struct _krb5_pa_s4u_x509_user {
1027     krb5_s4u_userid     user_id;
1028     krb5_checksum       cksum;
1029 } krb5_pa_s4u_x509_user;
1030
1031 enum {
1032   KRB5_FAST_ARMOR_AP_REQUEST = 0x1
1033 };
1034
1035 typedef struct _krb5_fast_armor {
1036     krb5_int32 armor_type;
1037     krb5_data armor_value;
1038 } krb5_fast_armor;
1039 typedef struct _krb5_fast_armored_req {
1040     krb5_magic magic;
1041     krb5_fast_armor *armor;
1042     krb5_checksum req_checksum;
1043     krb5_enc_data enc_part;
1044 } krb5_fast_armored_req;
1045
1046 typedef struct _krb5_fast_req {
1047     krb5_magic magic;
1048     krb5_flags fast_options;
1049     /* padata from req_body is used*/
1050    krb5_kdc_req *req_body;
1051 } krb5_fast_req;
1052
1053 /* Bits 0-15 are critical in fast options.*/
1054 #define UNSUPPORTED_CRITICAL_FAST_OPTIONS 0x00ff
1055 #define KRB5_FAST_OPTION_HIDE_CLIENT_NAMES 0x01
1056
1057 typedef struct _krb5_fast_finished {
1058     krb5_timestamp timestamp;
1059     krb5_int32 usec;
1060     krb5_principal client;
1061     krb5_checksum ticket_checksum;
1062 } krb5_fast_finished;
1063
1064 typedef struct _krb5_fast_response {
1065     krb5_magic magic;
1066     krb5_pa_data **padata;
1067     krb5_keyblock *strengthen_key;
1068     krb5_fast_finished *finished;
1069     krb5_int32 nonce;
1070 } krb5_fast_response;
1071
1072 typedef struct _krb5_ad_kdcissued {
1073     krb5_checksum ad_checksum;
1074     krb5_principal i_principal;
1075     krb5_authdata **elements;
1076 } krb5_ad_kdcissued;
1077
1078 typedef krb5_error_code (*krb5_preauth_obtain_proc)
1079     (krb5_context,
1080                     krb5_pa_data *,
1081                     krb5_etype_info,
1082                     krb5_keyblock *, 
1083                     krb5_error_code ( * )(krb5_context,
1084                                           const krb5_enctype,
1085                                           krb5_data *,
1086                                           krb5_const_pointer,
1087                                           krb5_keyblock **),
1088                     krb5_const_pointer,
1089                     krb5_creds *,
1090                     krb5_kdc_req *,
1091                     krb5_pa_data **);
1092
1093 typedef krb5_error_code (*krb5_preauth_process_proc)
1094     (krb5_context,
1095                     krb5_pa_data *,
1096                     krb5_kdc_req *,
1097                     krb5_kdc_rep *,
1098                     krb5_error_code ( * )(krb5_context,
1099                                           const krb5_enctype,
1100                                           krb5_data *,
1101                                           krb5_const_pointer,
1102                                           krb5_keyblock **),
1103                     krb5_const_pointer,
1104                     krb5_error_code ( * )(krb5_context,
1105                                           const krb5_keyblock *,
1106                                           krb5_const_pointer,
1107                                           krb5_kdc_rep * ),
1108                     krb5_keyblock **,
1109                     krb5_creds *, 
1110                     krb5_int32 *,
1111                     krb5_int32 *);
1112
1113 typedef struct _krb5_preauth_ops {
1114     krb5_magic magic;
1115     int     type;
1116     int flags;
1117     krb5_preauth_obtain_proc    obtain;
1118     krb5_preauth_process_proc   process;
1119 } krb5_preauth_ops;
1120
1121 krb5_error_code krb5_obtain_padata
1122         (krb5_context,
1123                 krb5_pa_data **,
1124                 krb5_error_code ( * )(krb5_context,
1125                                                       const krb5_enctype,
1126                                                       krb5_data *,
1127                                                       krb5_const_pointer,
1128                                                       krb5_keyblock **),
1129                 krb5_const_pointer, 
1130                 krb5_creds *,
1131                 krb5_kdc_req *);
1132
1133 krb5_error_code krb5_process_padata
1134         (krb5_context,
1135                 krb5_kdc_req *,
1136                 krb5_kdc_rep *,
1137                 krb5_error_code ( * )(krb5_context,
1138                                                       const krb5_enctype,
1139                                                       krb5_data *,
1140                                                       krb5_const_pointer,
1141                                                       krb5_keyblock **),
1142                 krb5_const_pointer,
1143                 krb5_error_code ( * )(krb5_context,
1144                                                       const krb5_keyblock *,
1145                                                       krb5_const_pointer,
1146                                                       krb5_kdc_rep * ),
1147                 krb5_keyblock **,       
1148                 krb5_creds *, 
1149                 krb5_int32 *);          
1150
1151 krb5_pa_data * krb5int_find_pa_data
1152 (krb5_context,  krb5_pa_data * const *, krb5_preauthtype);
1153 /* Does not return a copy; original padata sequence responsible for freeing*/
1154
1155 void krb5_free_etype_info
1156     (krb5_context, krb5_etype_info);
1157
1158 /*
1159  * Preauthentication property flags
1160  */
1161 #define KRB5_PREAUTH_FLAGS_ENCRYPT      0x00000001
1162 #define KRB5_PREAUTH_FLAGS_HARDWARE     0x00000002
1163
1164 #endif /* KRB5_PREAUTH__ */
1165 /*
1166  * End "preauth.h"
1167  */
1168
1169 /*
1170  * Extending the krb5_get_init_creds_opt structure.  The original
1171  * krb5_get_init_creds_opt structure is defined publicly.  The
1172  * new extended version is private.  The original interface
1173  * assumed a pre-allocated structure which was passed to
1174  * krb5_get_init_creds_init().  The new interface assumes that
1175  * the caller will call krb5_get_init_creds_alloc() and
1176  * krb5_get_init_creds_free().
1177  *
1178  * Callers MUST NOT call krb5_get_init_creds_init() after allocating an
1179  * opts structure using krb5_get_init_creds_alloc().  To do so will
1180  * introduce memory leaks.  Unfortunately, there is no way to enforce
1181  * this behavior.
1182  *
1183  * Two private flags are added for backward compatibility.
1184  * KRB5_GET_INIT_CREDS_OPT_EXTENDED says that the structure was allocated
1185  * with the new krb5_get_init_creds_opt_alloc() function.
1186  * KRB5_GET_INIT_CREDS_OPT_SHADOWED is set to indicate that the extended
1187  * structure is a shadow copy of an original krb5_get_init_creds_opt
1188  * structure.  
1189  * If KRB5_GET_INIT_CREDS_OPT_SHADOWED is set after a call to
1190  * krb5int_gic_opt_to_opte(), the resulting extended structure should be
1191  * freed (using krb5_get_init_creds_free).  Otherwise, the original
1192  * structure was already extended and there is no need to free it.
1193  */
1194
1195 #define KRB5_GET_INIT_CREDS_OPT_EXTENDED 0x80000000
1196 #define KRB5_GET_INIT_CREDS_OPT_SHADOWED 0x40000000
1197
1198 #define krb5_gic_opt_is_extended(s) \
1199     ((s) && ((s)->flags & KRB5_GET_INIT_CREDS_OPT_EXTENDED) ? 1 : 0)
1200 #define krb5_gic_opt_is_shadowed(s) \
1201     ((s) && ((s)->flags & KRB5_GET_INIT_CREDS_OPT_SHADOWED) ? 1 : 0)
1202
1203
1204 typedef struct _krb5_gic_opt_private {
1205     int num_preauth_data;
1206     krb5_gic_opt_pa_data *preauth_data;
1207   char * fast_ccache_name;
1208 } krb5_gic_opt_private;
1209
1210 /*
1211  * On the Mac, ensure that the layout of krb5_gic_opt_ext matches that
1212  * of krb5_get_init_creds_opt.
1213  */
1214 #if TARGET_OS_MAC
1215 #    pragma pack(push,2)
1216 #endif
1217
1218 typedef struct _krb5_gic_opt_ext {
1219     krb5_flags flags;
1220     krb5_deltat tkt_life;
1221     krb5_deltat renew_life;
1222     int forwardable;
1223     int proxiable;
1224     krb5_enctype *etype_list;
1225     int etype_list_length;
1226     krb5_address **address_list;
1227     krb5_preauthtype *preauth_list;
1228     int preauth_list_length;
1229     krb5_data *salt;
1230     /*
1231      * Do not change anything above this point in this structure.
1232      * It is identical to the public krb5_get_init_creds_opt structure.
1233      * New members must be added below.
1234      */
1235     krb5_gic_opt_private *opt_private;
1236 } krb5_gic_opt_ext;
1237
1238 #if TARGET_OS_MAC
1239 #    pragma pack(pop)
1240 #endif
1241
1242 krb5_error_code
1243 krb5int_gic_opt_to_opte(krb5_context context,
1244                         krb5_get_init_creds_opt *opt,
1245                         krb5_gic_opt_ext **opte,
1246                         unsigned int force,
1247                         const char *where);
1248
1249 krb5_error_code
1250 krb5int_copy_data_contents (krb5_context, const krb5_data *, krb5_data *);
1251
1252 krb5_error_code
1253 krb5int_copy_data_contents_add0 (krb5_context, const krb5_data *, krb5_data *);
1254
1255 krb5_error_code
1256 krb5int_copy_creds_contents (krb5_context, const krb5_creds *, krb5_creds *);
1257
1258 typedef krb5_error_code (*krb5_gic_get_as_key_fct)
1259     (krb5_context,
1260                      krb5_principal,
1261                      krb5_enctype,
1262                      krb5_prompter_fct,
1263                      void *prompter_data,
1264                      krb5_data *salt,
1265      krb5_data *s2kparams,
1266                      krb5_keyblock *as_key,
1267                      void *gak_data);
1268
1269 krb5_error_code KRB5_CALLCONV
1270 krb5_get_init_creds
1271 (krb5_context context,
1272                 krb5_creds *creds,
1273                 krb5_principal client,
1274                 krb5_prompter_fct prompter,
1275                 void *prompter_data,
1276                 krb5_deltat start_time,
1277                 char *in_tkt_service,
1278                 krb5_gic_opt_ext *gic_options,
1279                 krb5_gic_get_as_key_fct gak,
1280                 void *gak_data,
1281                 int *master,
1282                 krb5_kdc_rep **as_reply);
1283
1284 krb5_error_code krb5int_populate_gic_opt (
1285     krb5_context, krb5_gic_opt_ext **,
1286     krb5_flags options, krb5_address * const *addrs, krb5_enctype *ktypes,
1287     krb5_preauthtype *pre_auth_types, krb5_creds *creds);
1288
1289
1290 krb5_error_code KRB5_CALLCONV krb5_do_preauth
1291         (krb5_context context,
1292          krb5_kdc_req *request,
1293          krb5_data *encoded_request_body,
1294          krb5_data *encoded_previous_request,
1295          krb5_pa_data **in_padata, krb5_pa_data ***out_padata,
1296          krb5_data *salt, krb5_data *s2kparams,
1297          krb5_enctype *etype, krb5_keyblock *as_key,
1298          krb5_prompter_fct prompter, void *prompter_data,
1299          krb5_gic_get_as_key_fct gak_fct, void *gak_data,
1300          krb5_preauth_client_rock *get_data_rock,
1301          krb5_gic_opt_ext *opte);
1302 krb5_error_code KRB5_CALLCONV krb5_do_preauth_tryagain
1303         (krb5_context context,
1304          krb5_kdc_req *request,
1305          krb5_data *encoded_request_body,
1306          krb5_data *encoded_previous_request,
1307          krb5_pa_data **in_padata, krb5_pa_data ***out_padata,
1308          krb5_error *err_reply,
1309          krb5_data *salt, krb5_data *s2kparams,
1310          krb5_enctype *etype, krb5_keyblock *as_key,
1311          krb5_prompter_fct prompter, void *prompter_data,
1312          krb5_gic_get_as_key_fct gak_fct, void *gak_data,
1313          krb5_preauth_client_rock *get_data_rock,
1314          krb5_gic_opt_ext *opte);
1315 void KRB5_CALLCONV krb5_init_preauth_context
1316         (krb5_context);
1317 void KRB5_CALLCONV krb5_free_preauth_context
1318         (krb5_context);
1319 void KRB5_CALLCONV krb5_clear_preauth_context_use_counts
1320         (krb5_context);
1321 void KRB5_CALLCONV krb5_preauth_prepare_request
1322         (krb5_context, krb5_gic_opt_ext *, krb5_kdc_req *);
1323 void KRB5_CALLCONV krb5_preauth_request_context_init
1324         (krb5_context);
1325 void KRB5_CALLCONV krb5_preauth_request_context_fini
1326         (krb5_context);
1327
1328 void KRB5_CALLCONV krb5_free_sam_challenge
1329         (krb5_context, krb5_sam_challenge * );
1330 void KRB5_CALLCONV krb5_free_sam_challenge_2
1331         (krb5_context, krb5_sam_challenge_2 * );
1332 void KRB5_CALLCONV krb5_free_sam_challenge_2_body
1333         (krb5_context, krb5_sam_challenge_2_body *);
1334 void KRB5_CALLCONV krb5_free_sam_response
1335         (krb5_context, krb5_sam_response * );
1336 void KRB5_CALLCONV krb5_free_sam_response_2
1337         (krb5_context, krb5_sam_response_2 * );
1338 void KRB5_CALLCONV krb5_free_predicted_sam_response
1339         (krb5_context, krb5_predicted_sam_response * );
1340 void KRB5_CALLCONV krb5_free_enc_sam_response_enc
1341         (krb5_context, krb5_enc_sam_response_enc * );
1342 void KRB5_CALLCONV krb5_free_enc_sam_response_enc_2
1343         (krb5_context, krb5_enc_sam_response_enc_2 * );
1344 void KRB5_CALLCONV krb5_free_sam_challenge_contents
1345         (krb5_context, krb5_sam_challenge * );
1346 void KRB5_CALLCONV krb5_free_sam_challenge_2_contents
1347         (krb5_context, krb5_sam_challenge_2 * );
1348 void KRB5_CALLCONV krb5_free_sam_challenge_2_body_contents
1349         (krb5_context, krb5_sam_challenge_2_body * );
1350 void KRB5_CALLCONV krb5_free_sam_response_contents
1351         (krb5_context, krb5_sam_response * );
1352 void KRB5_CALLCONV krb5_free_sam_response_2_contents
1353         (krb5_context, krb5_sam_response_2 *);
1354 void KRB5_CALLCONV krb5_free_predicted_sam_response_contents
1355         (krb5_context, krb5_predicted_sam_response * );
1356 void KRB5_CALLCONV krb5_free_enc_sam_response_enc_contents
1357         (krb5_context, krb5_enc_sam_response_enc * );
1358 void KRB5_CALLCONV krb5_free_enc_sam_response_enc_2_contents
1359         (krb5_context, krb5_enc_sam_response_enc_2 * );
1360  
1361 void KRB5_CALLCONV krb5_free_pa_enc_ts
1362         (krb5_context, krb5_pa_enc_ts *);
1363 void KRB5_CALLCONV krb5_free_pa_for_user
1364         (krb5_context, krb5_pa_for_user * );
1365 void KRB5_CALLCONV krb5_free_s4u_userid_contents
1366         (krb5_context, krb5_s4u_userid * );
1367 void KRB5_CALLCONV krb5_free_pa_s4u_x509_user
1368         (krb5_context, krb5_pa_s4u_x509_user * );
1369 void KRB5_CALLCONV krb5_free_pa_svr_referral_data
1370         (krb5_context, krb5_pa_svr_referral_data * );
1371 void KRB5_CALLCONV krb5_free_pa_server_referral_data
1372         (krb5_context, krb5_pa_server_referral_data * );
1373 void KRB5_CALLCONV krb5_free_pa_pac_req
1374         (krb5_context, krb5_pa_pac_req * );
1375 void KRB5_CALLCONV krb5_free_etype_list
1376         (krb5_context, krb5_etype_list * );
1377
1378 void KRB5_CALLCONV krb5_free_fast_armor
1379 (krb5_context, krb5_fast_armor *);
1380 void KRB5_CALLCONV krb5_free_fast_armored_req
1381 (krb5_context, krb5_fast_armored_req *);
1382 void KRB5_CALLCONV krb5_free_fast_req(krb5_context, krb5_fast_req *);
1383 void KRB5_CALLCONV krb5_free_fast_finished
1384 (krb5_context, krb5_fast_finished *);
1385 void KRB5_CALLCONV krb5_free_fast_response
1386 (krb5_context, krb5_fast_response *);
1387 void KRB5_CALLCONV krb5_free_ad_kdcissued
1388 (krb5_context, krb5_ad_kdcissued *);
1389
1390 /* #include "krb5/wordsize.h" -- comes in through base-defs.h. */
1391 #include "com_err.h"
1392 #include "k5-plugin.h"
1393
1394 #include <krb5/authdata_plugin.h>
1395
1396 struct _krb5_authdata_context {
1397     krb5_magic magic;
1398     int n_modules;
1399     struct _krb5_authdata_context_module {
1400         krb5_authdatatype ad_type;
1401         void *plugin_context;
1402         authdata_client_plugin_fini_proc client_fini;
1403         krb5_flags flags;
1404         krb5plugin_authdata_client_ftable_v0 *ftable;
1405         authdata_client_request_init_proc client_req_init;
1406         authdata_client_request_fini_proc client_req_fini;
1407         const char *name;
1408         void *request_context;
1409         void **request_context_pp;
1410     } *modules;
1411     struct plugin_dir_handle plugins;
1412 };
1413
1414 typedef struct _krb5_authdata_context *krb5_authdata_context;
1415
1416 void KRB5_CALLCONV krb5int_free_data_list
1417 (krb5_context context, krb5_data *data);
1418
1419 krb5_error_code KRB5_CALLCONV krb5_authdata_context_init
1420 (krb5_context kcontext, krb5_authdata_context *pcontext);
1421
1422 void KRB5_CALLCONV
1423 krb5_authdata_context_free
1424 (krb5_context kcontext, krb5_authdata_context context);
1425
1426 krb5_error_code KRB5_CALLCONV krb5_authdata_export_authdata
1427 (krb5_context kcontext,
1428  krb5_authdata_context context,
1429  krb5_flags usage,
1430  krb5_authdata ***pauthdata);
1431
1432 krb5_error_code KRB5_CALLCONV
1433 krb5_authdata_get_attribute_types
1434 (krb5_context kcontext,
1435  krb5_authdata_context context,
1436  krb5_data **attrs);
1437
1438 krb5_error_code KRB5_CALLCONV krb5_authdata_get_attribute
1439 (krb5_context kcontext,
1440  krb5_authdata_context context,
1441  const krb5_data *attribute,
1442  krb5_boolean *authenticated,
1443  krb5_boolean *complete,
1444  krb5_data *value,
1445  krb5_data *display_value,
1446  int *more);
1447
1448 krb5_error_code KRB5_CALLCONV krb5_authdata_set_attribute
1449 (krb5_context kcontext,
1450  krb5_authdata_context context,
1451  krb5_boolean complete,
1452  const krb5_data *attribute,
1453  const krb5_data *value);
1454
1455 krb5_error_code KRB5_CALLCONV
1456 krb5_authdata_delete_attribute
1457 (krb5_context kcontext,
1458  krb5_authdata_context context,
1459  const krb5_data *attribute);
1460
1461 krb5_error_code KRB5_CALLCONV krb5_authdata_import_attributes
1462 (krb5_context kcontext,
1463  krb5_authdata_context context,
1464  krb5_flags usage,
1465  const krb5_data *attributes);
1466
1467 krb5_error_code KRB5_CALLCONV krb5_authdata_export_attributes
1468 (krb5_context kcontext,
1469  krb5_authdata_context context,
1470  krb5_flags usage,
1471  krb5_data **pattributes);
1472
1473 krb5_error_code KRB5_CALLCONV krb5_authdata_export_internal
1474 (krb5_context kcontext,
1475  krb5_authdata_context context,
1476  krb5_boolean restrict_authenticated,
1477  const char *module,
1478  void **ptr);
1479
1480 krb5_error_code KRB5_CALLCONV krb5_authdata_context_copy
1481 (krb5_context kcontext,
1482  krb5_authdata_context src,
1483  krb5_authdata_context *dst);
1484
1485 krb5_error_code KRB5_CALLCONV krb5_authdata_free_internal
1486 (krb5_context kcontext,
1487  krb5_authdata_context context,
1488  const char *module,
1489  void *ptr);
1490
1491
1492 struct _kdb5_dal_handle;        /* private, in kdb5.h */
1493 typedef struct _kdb5_dal_handle kdb5_dal_handle;
1494 struct _kdb_log_context;
1495 struct _krb5_context {
1496         krb5_magic      magic;
1497         krb5_enctype    *in_tkt_etypes;
1498         krb5_enctype    *tgs_etypes;
1499         struct _krb5_os_context os_context;
1500         char            *default_realm;
1501         profile_t       profile;
1502         kdb5_dal_handle *dal_handle;
1503         int             ser_ctx_count;
1504         void            *ser_ctx;
1505         /* allowable clock skew */
1506         krb5_deltat     clockskew;
1507         krb5_cksumtype  kdc_req_sumtype;
1508         krb5_cksumtype  default_ap_req_sumtype;
1509         krb5_cksumtype  default_safe_sumtype;
1510         krb5_flags      kdc_default_options;
1511         krb5_flags      library_options;
1512         krb5_boolean    profile_secure;
1513         int             fcc_default_format;
1514         krb5_prompt_type *prompt_types;
1515         /* Message size above which we'll try TCP first in send-to-kdc
1516            type code.  Aside from the 2**16 size limit, we put no
1517            absolute limit on the UDP packet size.  */
1518         int             udp_pref_limit;
1519
1520         /* Use the config-file ktypes instead of app-specified?  */
1521         krb5_boolean    use_conf_ktypes;
1522
1523 #ifdef KRB5_DNS_LOOKUP
1524         krb5_boolean    profile_in_memory;
1525 #endif /* KRB5_DNS_LOOKUP */
1526
1527     /* locate_kdc module stuff */
1528     struct plugin_dir_handle libkrb5_plugins;
1529     struct krb5plugin_service_locate_ftable *vtbl;
1530     void (**locate_fptrs)(void);
1531
1532     /* preauth module stuff */
1533     struct plugin_dir_handle preauth_plugins;
1534     krb5_preauth_context *preauth_context;
1535
1536     /* error detail info */
1537     struct errinfo err;
1538
1539     /* For Sun iprop code; does this really have to be here?  */
1540     struct _kdb_log_context *kdblog_context;
1541
1542     krb5_boolean allow_weak_crypto;
1543 };
1544
1545 /* could be used in a table to find an etype and initialize a block */
1546
1547
1548 #define KRB5_LIBOPT_SYNC_KDCTIME        0x0001
1549
1550 /* internal message representations */
1551
1552 typedef struct _krb5_safe {
1553     krb5_magic magic;
1554     krb5_data user_data;                /* user data */
1555     krb5_timestamp timestamp;           /* client time, optional */
1556     krb5_int32 usec;                    /* microsecond portion of time,
1557                                            optional */
1558     krb5_ui_4 seq_number;               /* sequence #, optional */
1559     krb5_address *s_address;    /* sender address */
1560     krb5_address *r_address;    /* recipient address, optional */
1561     krb5_checksum *checksum;    /* data integrity checksum */
1562 } krb5_safe;
1563
1564 typedef struct _krb5_priv {
1565     krb5_magic magic;
1566     krb5_enc_data enc_part;             /* encrypted part */
1567 } krb5_priv;
1568
1569 typedef struct _krb5_priv_enc_part {
1570     krb5_magic magic;
1571     krb5_data user_data;                /* user data */
1572     krb5_timestamp timestamp;           /* client time, optional */
1573     krb5_int32 usec;                    /* microsecond portion of time, opt. */
1574     krb5_ui_4 seq_number;               /* sequence #, optional */
1575     krb5_address *s_address;    /* sender address */
1576     krb5_address *r_address;    /* recipient address, optional */
1577 } krb5_priv_enc_part;
1578
1579 void KRB5_CALLCONV krb5_free_safe
1580         (krb5_context, krb5_safe * );
1581 void KRB5_CALLCONV krb5_free_priv
1582         (krb5_context, krb5_priv * );
1583 void KRB5_CALLCONV krb5_free_priv_enc_part
1584         (krb5_context, krb5_priv_enc_part * );
1585
1586 /*
1587  * Begin "asn1.h"
1588  */
1589 #ifndef KRB5_ASN1__
1590 #define KRB5_ASN1__
1591
1592 /* ASN.1 encoding knowledge; KEEP IN SYNC WITH ASN.1 defs! */
1593 /* here we use some knowledge of ASN.1 encodings */
1594 /* 
1595   Ticket is APPLICATION 1.
1596   Authenticator is APPLICATION 2.
1597   AS_REQ is APPLICATION 10.
1598   AS_REP is APPLICATION 11.
1599   TGS_REQ is APPLICATION 12.
1600   TGS_REP is APPLICATION 13.
1601   AP_REQ is APPLICATION 14.
1602   AP_REP is APPLICATION 15.
1603   KRB_SAFE is APPLICATION 20.
1604   KRB_PRIV is APPLICATION 21.
1605   KRB_CRED is APPLICATION 22.
1606   EncASRepPart is APPLICATION 25.
1607   EncTGSRepPart is APPLICATION 26.
1608   EncAPRepPart is APPLICATION 27.
1609   EncKrbPrivPart is APPLICATION 28.
1610   EncKrbCredPart is APPLICATION 29.
1611   KRB_ERROR is APPLICATION 30.
1612  */
1613 /* allow either constructed or primitive encoding, so check for bit 6
1614    set or reset */
1615 #define krb5int_is_app_tag(dat,tag)\
1616     ((dat) && (dat)->length && \
1617      ((((dat)->data[0] & ~0x20) == ((tag) | 0x40))))
1618 #define krb5_is_krb_ticket(dat)               krb5int_is_app_tag(dat, 1)
1619 #define krb5_is_krb_authenticator(dat)        krb5int_is_app_tag(dat, 2)
1620 #define krb5_is_as_req(dat)                   krb5int_is_app_tag(dat, 10)
1621 #define krb5_is_as_rep(dat)                   krb5int_is_app_tag(dat, 11)
1622 #define krb5_is_tgs_req(dat)                  krb5int_is_app_tag(dat, 12)
1623 #define krb5_is_tgs_rep(dat)                  krb5int_is_app_tag(dat, 13)
1624 #define krb5_is_ap_req(dat)                   krb5int_is_app_tag(dat, 14)
1625 #define krb5_is_ap_rep(dat)                   krb5int_is_app_tag(dat, 15)
1626 #define krb5_is_krb_safe(dat)                 krb5int_is_app_tag(dat, 20)
1627 #define krb5_is_krb_priv(dat)                 krb5int_is_app_tag(dat, 21)
1628 #define krb5_is_krb_cred(dat)                 krb5int_is_app_tag(dat, 22)
1629 #define krb5_is_krb_enc_as_rep_part(dat)      krb5int_is_app_tag(dat, 25)
1630 #define krb5_is_krb_enc_tgs_rep_part(dat)     krb5int_is_app_tag(dat, 26)
1631 #define krb5_is_krb_enc_ap_rep_part(dat)      krb5int_is_app_tag(dat, 27)
1632 #define krb5_is_krb_enc_krb_priv_part(dat)    krb5int_is_app_tag(dat, 28)
1633 #define krb5_is_krb_enc_krb_cred_part(dat)    krb5int_is_app_tag(dat, 29)
1634 #define krb5_is_krb_error(dat)                krb5int_is_app_tag(dat, 30)
1635
1636 /*************************************************************************
1637  * Prototypes for krb5_encode.c
1638  *************************************************************************/
1639
1640 /*
1641    krb5_error_code encode_krb5_structure(const krb5_structure *rep,
1642                                          krb5_data **code);
1643    modifies  *code
1644    effects   Returns the ASN.1 encoding of *rep in **code.
1645              Returns ASN1_MISSING_FIELD if a required field is emtpy in *rep.
1646              Returns ENOMEM if memory runs out.
1647 */
1648
1649 krb5_error_code encode_krb5_authenticator
1650         (const krb5_authenticator *rep, krb5_data **code);
1651
1652 krb5_error_code encode_krb5_ticket
1653         (const krb5_ticket *rep, krb5_data **code);
1654
1655 krb5_error_code encode_krb5_encryption_key
1656         (const krb5_keyblock *rep, krb5_data **code);
1657
1658 krb5_error_code encode_krb5_enc_tkt_part
1659         (const krb5_enc_tkt_part *rep, krb5_data **code);
1660
1661 krb5_error_code encode_krb5_enc_kdc_rep_part
1662         (const krb5_enc_kdc_rep_part *rep, krb5_data **code);
1663
1664 /* yes, the translation is identical to that used for KDC__REP */ 
1665 krb5_error_code encode_krb5_as_rep
1666         (const krb5_kdc_rep *rep, krb5_data **code);
1667
1668 /* yes, the translation is identical to that used for KDC__REP */ 
1669 krb5_error_code encode_krb5_tgs_rep
1670         (const krb5_kdc_rep *rep, krb5_data **code);
1671
1672 krb5_error_code encode_krb5_ap_req
1673         (const krb5_ap_req *rep, krb5_data **code);
1674
1675 krb5_error_code encode_krb5_ap_rep
1676         (const krb5_ap_rep *rep, krb5_data **code);
1677
1678 krb5_error_code encode_krb5_ap_rep_enc_part
1679         (const krb5_ap_rep_enc_part *rep, krb5_data **code);
1680
1681 krb5_error_code encode_krb5_as_req
1682         (const krb5_kdc_req *rep, krb5_data **code);
1683
1684 krb5_error_code encode_krb5_tgs_req
1685         (const krb5_kdc_req *rep, krb5_data **code);
1686
1687 krb5_error_code encode_krb5_kdc_req_body
1688         (const krb5_kdc_req *rep, krb5_data **code);
1689
1690 krb5_error_code encode_krb5_safe
1691         (const krb5_safe *rep, krb5_data **code);
1692
1693 struct krb5_safe_with_body {
1694     krb5_safe *safe;
1695     krb5_data *body;
1696 };
1697 krb5_error_code encode_krb5_safe_with_body
1698         (const struct krb5_safe_with_body *rep, krb5_data **code);
1699
1700 krb5_error_code encode_krb5_priv
1701         (const krb5_priv *rep, krb5_data **code);
1702
1703 krb5_error_code encode_krb5_enc_priv_part
1704         (const krb5_priv_enc_part *rep, krb5_data **code);
1705
1706 krb5_error_code encode_krb5_cred
1707         (const krb5_cred *rep, krb5_data **code);
1708
1709 krb5_error_code encode_krb5_enc_cred_part
1710         (const krb5_cred_enc_part *rep, krb5_data **code);
1711
1712 krb5_error_code encode_krb5_error
1713         (const krb5_error *rep, krb5_data **code);
1714
1715 krb5_error_code encode_krb5_authdata
1716         (krb5_authdata *const *rep, krb5_data **code);
1717
1718 krb5_error_code encode_krb5_authdata_elt
1719         (const krb5_authdata *rep, krb5_data **code);
1720
1721 krb5_error_code encode_krb5_pwd_sequence
1722         (const passwd_phrase_element *rep, krb5_data **code);
1723
1724 krb5_error_code encode_krb5_pwd_data
1725         (const krb5_pwd_data *rep, krb5_data **code);
1726
1727 krb5_error_code encode_krb5_padata_sequence
1728         (krb5_pa_data *const *rep, krb5_data **code);
1729
1730 krb5_error_code encode_krb5_alt_method
1731         (const krb5_alt_method *, krb5_data **code);
1732
1733 krb5_error_code encode_krb5_etype_info
1734         (krb5_etype_info_entry *const *, krb5_data **code);
1735 krb5_error_code encode_krb5_etype_info2
1736         (krb5_etype_info_entry *const *, krb5_data **code);
1737
1738 krb5_error_code encode_krb5_enc_data
1739         (const krb5_enc_data *, krb5_data **);
1740
1741 krb5_error_code encode_krb5_pa_enc_ts
1742         (const krb5_pa_enc_ts *, krb5_data **);
1743
1744 krb5_error_code encode_krb5_sam_challenge
1745         (const krb5_sam_challenge * , krb5_data **);
1746
1747 krb5_error_code encode_krb5_sam_key
1748         (const krb5_sam_key * , krb5_data **);
1749
1750 krb5_error_code encode_krb5_enc_sam_response_enc
1751         (const krb5_enc_sam_response_enc * , krb5_data **);
1752
1753 krb5_error_code encode_krb5_sam_response
1754         (const krb5_sam_response * , krb5_data **);
1755
1756 #if 0 /* currently not compiled because we never use them */
1757 krb5_error_code encode_krb5_sam_challenge_2
1758         (const krb5_sam_challenge_2 * , krb5_data **);
1759
1760 krb5_error_code encode_krb5_sam_challenge_2_body
1761         (const krb5_sam_challenge_2_body * , krb5_data **);
1762 #endif
1763
1764 krb5_error_code encode_krb5_enc_sam_response_enc_2
1765         (const krb5_enc_sam_response_enc_2 * , krb5_data **);
1766
1767 krb5_error_code encode_krb5_sam_response_2
1768         (const krb5_sam_response_2 * , krb5_data **);
1769
1770 krb5_error_code encode_krb5_predicted_sam_response
1771         (const krb5_predicted_sam_response * , krb5_data **);
1772
1773 struct krb5_setpw_req {
1774     krb5_principal target;
1775     krb5_data password;
1776 };
1777 krb5_error_code encode_krb5_setpw_req
1778         (const struct krb5_setpw_req *rep, krb5_data **code);
1779
1780 krb5_error_code encode_krb5_pa_for_user
1781         (const krb5_pa_for_user * , krb5_data **);
1782
1783 krb5_error_code encode_krb5_s4u_userid
1784         (const krb5_s4u_userid * , krb5_data **);
1785
1786 krb5_error_code encode_krb5_pa_s4u_x509_user
1787         (const krb5_pa_s4u_x509_user * , krb5_data **);
1788
1789 krb5_error_code encode_krb5_pa_svr_referral_data
1790         (const krb5_pa_svr_referral_data * , krb5_data **);
1791
1792 krb5_error_code encode_krb5_pa_server_referral_data
1793         (const krb5_pa_server_referral_data * , krb5_data **);
1794
1795 krb5_error_code encode_krb5_pa_pac_req
1796         (const krb5_pa_pac_req * , krb5_data **);
1797
1798 krb5_error_code encode_krb5_etype_list
1799         (const krb5_etype_list * , krb5_data **);
1800
1801 krb5_error_code encode_krb5_pa_fx_fast_request
1802 (const krb5_fast_armored_req *, krb5_data **);
1803 krb5_error_code encode_krb5_fast_req
1804 (const krb5_fast_req *, krb5_data **);
1805 krb5_error_code encode_krb5_pa_fx_fast_reply
1806 (const krb5_enc_data *, krb5_data **);
1807
1808 krb5_error_code encode_krb5_fast_response
1809 (const krb5_fast_response *, krb5_data **);
1810
1811 krb5_error_code encode_krb5_ad_kdcissued
1812 (const krb5_ad_kdcissued *, krb5_data **);
1813
1814 /*************************************************************************
1815  * End of prototypes for krb5_encode.c
1816  *************************************************************************/
1817
1818 krb5_error_code decode_krb5_sam_challenge
1819        (const krb5_data *, krb5_sam_challenge **);
1820
1821 krb5_error_code decode_krb5_enc_sam_key
1822        (const krb5_data *, krb5_sam_key **);
1823
1824 krb5_error_code decode_krb5_enc_sam_response_enc
1825        (const krb5_data *, krb5_enc_sam_response_enc **);
1826
1827 krb5_error_code decode_krb5_sam_response
1828        (const krb5_data *, krb5_sam_response **);
1829
1830 krb5_error_code decode_krb5_predicted_sam_response
1831        (const krb5_data *, krb5_predicted_sam_response **);
1832
1833 krb5_error_code decode_krb5_sam_challenge_2
1834         (const krb5_data *, krb5_sam_challenge_2 **);
1835
1836 krb5_error_code decode_krb5_sam_challenge_2_body
1837         (const krb5_data *, krb5_sam_challenge_2_body **);
1838
1839 krb5_error_code decode_krb5_enc_sam_response_enc_2
1840         (const krb5_data *, krb5_enc_sam_response_enc_2 **);
1841
1842 krb5_error_code decode_krb5_sam_response_2
1843         (const krb5_data *, krb5_sam_response_2 **);
1844
1845
1846 /*************************************************************************
1847  * Prototypes for krb5_decode.c
1848  *************************************************************************/
1849
1850 krb5_error_code krb5_validate_times
1851        (krb5_context, 
1852                        krb5_ticket_times *);
1853
1854 /*
1855    krb5_error_code decode_krb5_structure(const krb5_data *code,
1856                                          krb5_structure **rep);
1857                                          
1858    requires  Expects **rep to not have been allocated;
1859               a new *rep is allocated regardless of the old value.
1860    effects   Decodes *code into **rep.
1861              Returns ENOMEM if memory is exhausted.
1862              Returns asn1 and krb5 errors.
1863 */
1864
1865 krb5_error_code decode_krb5_authenticator
1866         (const krb5_data *code, krb5_authenticator **rep);
1867
1868 krb5_error_code decode_krb5_ticket
1869         (const krb5_data *code, krb5_ticket **rep);
1870
1871 krb5_error_code decode_krb5_encryption_key
1872         (const krb5_data *output, krb5_keyblock **rep);
1873
1874 krb5_error_code decode_krb5_enc_tkt_part
1875         (const krb5_data *output, krb5_enc_tkt_part **rep);
1876
1877 krb5_error_code decode_krb5_enc_kdc_rep_part
1878         (const krb5_data *output, krb5_enc_kdc_rep_part **rep);
1879
1880 krb5_error_code decode_krb5_as_rep
1881         (const krb5_data *output, krb5_kdc_rep **rep);
1882
1883 krb5_error_code decode_krb5_tgs_rep
1884         (const krb5_data *output, krb5_kdc_rep **rep);
1885
1886 krb5_error_code decode_krb5_ap_req
1887         (const krb5_data *output, krb5_ap_req **rep);
1888
1889 krb5_error_code decode_krb5_ap_rep
1890         (const krb5_data *output, krb5_ap_rep **rep);
1891
1892 krb5_error_code decode_krb5_ap_rep_enc_part
1893         (const krb5_data *output, krb5_ap_rep_enc_part **rep);
1894
1895 krb5_error_code decode_krb5_as_req
1896         (const krb5_data *output, krb5_kdc_req **rep);
1897
1898 krb5_error_code decode_krb5_tgs_req
1899         (const krb5_data *output, krb5_kdc_req **rep);
1900
1901 krb5_error_code decode_krb5_kdc_req_body
1902         (const krb5_data *output, krb5_kdc_req **rep);
1903
1904 krb5_error_code decode_krb5_safe
1905         (const krb5_data *output, krb5_safe **rep);
1906
1907 krb5_error_code decode_krb5_safe_with_body
1908         (const krb5_data *output, krb5_safe **rep, krb5_data *body);
1909
1910 krb5_error_code decode_krb5_priv
1911         (const krb5_data *output, krb5_priv **rep);
1912
1913 krb5_error_code decode_krb5_enc_priv_part
1914         (const krb5_data *output, krb5_priv_enc_part **rep);
1915
1916 krb5_error_code decode_krb5_cred
1917         (const krb5_data *output, krb5_cred **rep);
1918
1919 krb5_error_code decode_krb5_enc_cred_part
1920         (const krb5_data *output, krb5_cred_enc_part **rep);
1921
1922 krb5_error_code decode_krb5_error
1923         (const krb5_data *output, krb5_error **rep);
1924
1925 krb5_error_code decode_krb5_authdata
1926         (const krb5_data *output, krb5_authdata ***rep);
1927
1928 krb5_error_code decode_krb5_pwd_sequence
1929         (const krb5_data *output, passwd_phrase_element **rep);
1930
1931 krb5_error_code decode_krb5_pwd_data
1932         (const krb5_data *output, krb5_pwd_data **rep);
1933
1934 krb5_error_code decode_krb5_padata_sequence
1935         (const krb5_data *output, krb5_pa_data ***rep);
1936
1937 krb5_error_code decode_krb5_alt_method
1938         (const krb5_data *output, krb5_alt_method **rep);
1939
1940 krb5_error_code decode_krb5_etype_info
1941         (const krb5_data *output, krb5_etype_info_entry ***rep);
1942
1943 krb5_error_code decode_krb5_etype_info2
1944         (const krb5_data *output, krb5_etype_info_entry ***rep);
1945
1946 krb5_error_code decode_krb5_enc_data
1947         (const krb5_data *output, krb5_enc_data **rep);
1948
1949 krb5_error_code decode_krb5_pa_enc_ts
1950         (const krb5_data *output, krb5_pa_enc_ts **rep);
1951
1952 krb5_error_code decode_krb5_sam_key
1953         (const krb5_data *, krb5_sam_key **);
1954
1955 krb5_error_code decode_krb5_setpw_req
1956         (const krb5_data *, krb5_data **, krb5_principal *);
1957
1958 krb5_error_code decode_krb5_pa_for_user
1959         (const krb5_data *, krb5_pa_for_user **);
1960
1961 krb5_error_code decode_krb5_pa_s4u_x509_user
1962         (const krb5_data *, krb5_pa_s4u_x509_user **);
1963
1964 krb5_error_code decode_krb5_pa_svr_referral_data
1965         (const krb5_data *, krb5_pa_svr_referral_data **);
1966
1967 krb5_error_code decode_krb5_pa_server_referral_data
1968         (const krb5_data *, krb5_pa_server_referral_data **);
1969
1970 krb5_error_code decode_krb5_pa_pac_req
1971         (const krb5_data *, krb5_pa_pac_req **);
1972
1973 krb5_error_code decode_krb5_etype_list
1974         (const krb5_data *, krb5_etype_list **);
1975
1976 krb5_error_code decode_krb5_pa_fx_fast_request
1977 (const krb5_data *, krb5_fast_armored_req **);
1978
1979 krb5_error_code decode_krb5_fast_req
1980 (const krb5_data *, krb5_fast_req **);
1981
1982
1983 krb5_error_code decode_krb5_pa_fx_fast_reply
1984 (const krb5_data *, krb5_enc_data **);
1985
1986 krb5_error_code decode_krb5_fast_response
1987 (const krb5_data *, krb5_fast_response **);
1988
1989 krb5_error_code decode_krb5_ad_kdcissued
1990 (const krb5_data *, krb5_ad_kdcissued **);
1991
1992 struct _krb5_key_data;          /* kdb.h */
1993
1994 struct ldap_seqof_key_data {
1995     krb5_int32 mkvno;           /* Master key version number */
1996     struct _krb5_key_data *key_data;
1997     krb5_int16 n_key_data;
1998 };
1999 typedef struct ldap_seqof_key_data ldap_seqof_key_data;
2000
2001 krb5_error_code
2002 krb5int_ldap_encode_sequence_of_keys (const ldap_seqof_key_data *val,
2003                                       krb5_data **code);
2004
2005 krb5_error_code
2006 krb5int_ldap_decode_sequence_of_keys (krb5_data *in,
2007                                       ldap_seqof_key_data **rep);
2008
2009 /*************************************************************************
2010  * End of prototypes for krb5_decode.c
2011  *************************************************************************/
2012
2013 #endif /* KRB5_ASN1__ */
2014 /*
2015  * End "asn1.h"
2016  */
2017
2018
2019 /*
2020  * Internal krb5 library routines
2021  */
2022 krb5_error_code krb5_encrypt_tkt_part
2023         (krb5_context,
2024                 const krb5_keyblock *,
2025                 krb5_ticket * );
2026
2027
2028 krb5_error_code krb5_encode_kdc_rep
2029         (krb5_context,
2030                 krb5_msgtype,
2031                 const krb5_enc_kdc_rep_part *,
2032                 int using_subkey,
2033                 const krb5_keyblock *,
2034                 krb5_kdc_rep *,
2035                 krb5_data ** );
2036
2037 krb5_boolean krb5int_auth_con_chkseqnum
2038         (krb5_context ctx, krb5_auth_context ac, krb5_ui_4 in_seq);
2039 /*
2040  * [De]Serialization Handle and operations.
2041  */
2042 struct __krb5_serializer {
2043     krb5_magic          odtype;
2044     krb5_error_code     (*sizer) (krb5_context,
2045                                                   krb5_pointer,
2046                                                   size_t *);
2047     krb5_error_code     (*externalizer) (krb5_context,
2048                                                          krb5_pointer,
2049                                                          krb5_octet **,
2050                                                          size_t *);
2051     krb5_error_code     (*internalizer) (krb5_context,
2052                                                          krb5_pointer *,
2053                                                          krb5_octet **,
2054                                                          size_t *);
2055 };
2056 typedef const struct __krb5_serializer * krb5_ser_handle;
2057 typedef struct __krb5_serializer krb5_ser_entry;
2058
2059 krb5_ser_handle krb5_find_serializer
2060         (krb5_context,
2061                 krb5_magic);
2062 krb5_error_code krb5_register_serializer
2063         (krb5_context,
2064                         const krb5_ser_entry *);
2065
2066 /* Determine the external size of a particular opaque structure */
2067 krb5_error_code KRB5_CALLCONV krb5_size_opaque
2068         (krb5_context,
2069                 krb5_magic,
2070                 krb5_pointer,
2071                 size_t *);
2072
2073 /* Serialize the structure into a buffer */
2074 krb5_error_code KRB5_CALLCONV krb5_externalize_opaque
2075         (krb5_context,
2076                 krb5_magic,
2077                 krb5_pointer,
2078                 krb5_octet **,
2079                 size_t *);
2080
2081 /* Deserialize the structure from a buffer */
2082 krb5_error_code KRB5_CALLCONV krb5_internalize_opaque
2083         (krb5_context,
2084                 krb5_magic,
2085                 krb5_pointer *,
2086                 krb5_octet **,
2087                 size_t *);
2088
2089 /* Serialize data into a buffer */
2090 krb5_error_code krb5_externalize_data
2091         (krb5_context,
2092                 krb5_pointer,
2093                 krb5_octet **,
2094                 size_t *);
2095 /*
2096  * Initialization routines.
2097  */
2098
2099 /* Initialize serialization for krb5_[os_]context */
2100 krb5_error_code KRB5_CALLCONV krb5_ser_context_init
2101         (krb5_context);
2102
2103 /* Initialize serialization for krb5_auth_context */
2104 krb5_error_code KRB5_CALLCONV krb5_ser_auth_context_init
2105         (krb5_context);
2106
2107 /* Initialize serialization for krb5_keytab */
2108 krb5_error_code KRB5_CALLCONV krb5_ser_keytab_init
2109         (krb5_context);
2110
2111 /* Initialize serialization for krb5_ccache */
2112 krb5_error_code KRB5_CALLCONV krb5_ser_ccache_init
2113         (krb5_context);
2114
2115 /* Initialize serialization for krb5_rcache */
2116 krb5_error_code KRB5_CALLCONV krb5_ser_rcache_init
2117         (krb5_context);
2118
2119 /* [De]serialize 4-byte integer */
2120 krb5_error_code KRB5_CALLCONV krb5_ser_pack_int32
2121         (krb5_int32,
2122                 krb5_octet **,
2123                 size_t *);
2124 krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int32
2125         (krb5_int32 *,
2126                 krb5_octet **,
2127                 size_t *);
2128 /* [De]serialize 8-byte integer */
2129 krb5_error_code KRB5_CALLCONV krb5_ser_pack_int64
2130         (krb5_int64, krb5_octet **, size_t *);
2131 krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int64
2132         (krb5_int64 *, krb5_octet **, size_t *);
2133 /* [De]serialize byte string */
2134 krb5_error_code KRB5_CALLCONV krb5_ser_pack_bytes
2135         (krb5_octet *,
2136                 size_t,
2137                 krb5_octet **,
2138                 size_t *);
2139 krb5_error_code KRB5_CALLCONV krb5_ser_unpack_bytes
2140         (krb5_octet *,
2141                 size_t,
2142                 krb5_octet **,
2143                 size_t *);
2144
2145 krb5_error_code KRB5_CALLCONV krb5int_cc_default
2146         (krb5_context, krb5_ccache *);
2147
2148 krb5_error_code KRB5_CALLCONV krb5_cc_retrieve_cred_default
2149         (krb5_context, krb5_ccache, krb5_flags,
2150                         krb5_creds *, krb5_creds *);
2151
2152 krb5_boolean KRB5_CALLCONV
2153 krb5_creds_compare (krb5_context in_context,
2154                     krb5_creds *in_creds,
2155                     krb5_creds *in_compare_creds);
2156
2157 void krb5int_set_prompt_types
2158         (krb5_context, krb5_prompt_type *);
2159
2160 krb5_error_code
2161 krb5int_generate_and_save_subkey (krb5_context, krb5_auth_context,
2162                                   krb5_keyblock * /* Old keyblock, not new!  */,
2163                                   krb5_enctype);
2164
2165 /* set and change password helpers */
2166
2167 krb5_error_code krb5int_mk_chpw_req
2168         (krb5_context context, krb5_auth_context auth_context, 
2169                         krb5_data *ap_req, char *passwd, krb5_data *packet);
2170 krb5_error_code krb5int_rd_chpw_rep
2171         (krb5_context context, krb5_auth_context auth_context,
2172                        krb5_data *packet, int *result_code,
2173                        krb5_data *result_data);
2174 krb5_error_code KRB5_CALLCONV krb5_chpw_result_code_string
2175         (krb5_context context, int result_code,
2176                         char **result_codestr);
2177 krb5_error_code  krb5int_mk_setpw_req
2178         (krb5_context context, krb5_auth_context auth_context,
2179                         krb5_data *ap_req, krb5_principal targetprinc, char *passwd, krb5_data *packet);
2180 krb5_error_code krb5int_rd_setpw_rep
2181         (krb5_context context, krb5_auth_context auth_context,
2182                        krb5_data *packet, int *result_code,
2183                        krb5_data *result_data);
2184 krb5_error_code krb5int_setpw_result_code_string
2185         (krb5_context context, int result_code,
2186                         const char **result_codestr);
2187
2188 struct srv_dns_entry {
2189     struct srv_dns_entry *next;
2190     int priority;
2191     int weight;
2192     unsigned short port;
2193     char *host;
2194 };
2195 #ifdef KRB5_DNS_LOOKUP
2196 krb5_error_code
2197 krb5int_make_srv_query_realm(const krb5_data *realm,
2198                              const char *service,
2199                              const char *protocol,
2200                              struct srv_dns_entry **answers);
2201 void krb5int_free_srv_dns_data(struct srv_dns_entry *);
2202 #endif
2203
2204 /* value to use when requesting a keytab entry and KVNO doesn't matter */
2205 #define IGNORE_VNO 0
2206 /* value to use when requesting a keytab entry and enctype doesn't matter */
2207 #define IGNORE_ENCTYPE 0
2208
2209 /*
2210  * Convenience function for structure magic number
2211  */
2212 #define KRB5_VERIFY_MAGIC(structure,magic_number) \
2213     if ((structure)->magic != (magic_number)) return (magic_number);
2214
2215 /* to keep lint happy */
2216 #define krb5_xfree(val) free((char *)(val))
2217
2218 /* To keep happy libraries which are (for now) accessing internal stuff */
2219
2220 /* Make sure to increment by one when changing the struct */
2221 #define KRB5INT_ACCESS_STRUCT_VERSION 15
2222
2223 #ifndef ANAME_SZ
2224 struct ktext;                   /* from krb.h, for krb524 support */
2225 #endif
2226 typedef struct _krb5int_access {
2227     /* crypto stuff */
2228     const struct krb5_hash_provider *md5_hash_provider;
2229     const struct krb5_enc_provider *arcfour_enc_provider;
2230     krb5_error_code (*hmac)(const struct krb5_hash_provider *hash,
2231                             const krb5_keyblock *key,
2232                             unsigned int icount, const krb5_data *input,
2233                             krb5_data *output);
2234     krb5_error_code (*auth_con_get_subkey_enctype)(krb5_context,
2235                                                    krb5_auth_context,
2236                                                    krb5_enctype *);
2237     /* service location and communication */
2238     krb5_error_code (*sendto_udp) (krb5_context, const krb5_data *msg,
2239                                    const struct addrlist *, struct sendto_callback_info*, krb5_data *reply,
2240                                    struct sockaddr *, socklen_t *,struct sockaddr *,
2241                                    socklen_t *, int *,
2242                                    int (*msg_handler)(krb5_context, const krb5_data *, void *),
2243                                    void *msg_handler_data);
2244     krb5_error_code (*add_host_to_list)(struct addrlist *lp,
2245                                         const char *hostname,
2246                                         int port, int secport,
2247                                         int socktype, int family);
2248     void (*free_addrlist) (struct addrlist *);
2249
2250     krb5_error_code (*make_srv_query_realm)(const krb5_data *realm,
2251                                             const char *service,
2252                                             const char *protocol,
2253                                             struct srv_dns_entry **answers);
2254     void (*free_srv_dns_data)(struct srv_dns_entry *);
2255     int (*use_dns_kdc)(krb5_context);
2256     krb5_error_code (*clean_hostname)(krb5_context, const char *, char *, size_t);
2257
2258     krb5_error_code (*mandatory_cksumtype)(krb5_context, krb5_enctype,
2259                                            krb5_cksumtype *);
2260     krb5_error_code (KRB5_CALLCONV *ser_pack_int64)(krb5_int64, krb5_octet **,
2261                                                     size_t *);
2262     krb5_error_code (KRB5_CALLCONV *ser_unpack_int64)(krb5_int64 *,
2263                                                       krb5_octet **, size_t *);
2264
2265     /* Used for KDB LDAP back end.  */
2266     krb5_error_code
2267     (*asn1_ldap_encode_sequence_of_keys) (const ldap_seqof_key_data *val,
2268                                           krb5_data **code);
2269
2270     krb5_error_code
2271     (*asn1_ldap_decode_sequence_of_keys) (krb5_data *in,
2272                                           ldap_seqof_key_data **);
2273   /* Used for encrypted challenge fast factor*/
2274     krb5_error_code (*encode_enc_data)(const krb5_enc_data *, krb5_data **);
2275     krb5_error_code (*decode_enc_data)(const krb5_data *, krb5_enc_data **);
2276     void (*free_enc_data)(krb5_context, krb5_enc_data *);
2277     krb5_error_code (*encode_enc_ts)(const krb5_pa_enc_ts *, krb5_data **);
2278     krb5_error_code (*decode_enc_ts)(const krb5_data *, krb5_pa_enc_ts **);
2279     void (*free_enc_ts)(krb5_context, krb5_pa_enc_ts *);
2280     krb5_error_code (*encrypt_helper)
2281         (krb5_context, const krb5_keyblock *, krb5_keyusage, const krb5_data *,
2282          krb5_enc_data *);
2283
2284     /*
2285      * pkinit asn.1 encode/decode functions
2286      */
2287     krb5_error_code (*encode_krb5_auth_pack)
2288         (const krb5_auth_pack *rep, krb5_data **code);
2289     krb5_error_code (*encode_krb5_auth_pack_draft9)
2290         (const krb5_auth_pack_draft9 *rep, krb5_data **code);
2291     krb5_error_code (*encode_krb5_kdc_dh_key_info)
2292         (const krb5_kdc_dh_key_info *rep, krb5_data **code);
2293     krb5_error_code (*encode_krb5_pa_pk_as_rep)
2294         (const krb5_pa_pk_as_rep *rep, krb5_data **code);
2295     krb5_error_code (*encode_krb5_pa_pk_as_rep_draft9)
2296         (const krb5_pa_pk_as_rep_draft9 *rep, krb5_data **code);
2297     krb5_error_code (*encode_krb5_pa_pk_as_req)
2298         (const krb5_pa_pk_as_req *rep, krb5_data **code);
2299     krb5_error_code (*encode_krb5_pa_pk_as_req_draft9)
2300         (const krb5_pa_pk_as_req_draft9 *rep, krb5_data **code);
2301     krb5_error_code (*encode_krb5_reply_key_pack)
2302         (const krb5_reply_key_pack *, krb5_data **code);
2303     krb5_error_code (*encode_krb5_reply_key_pack_draft9)
2304         (const krb5_reply_key_pack_draft9 *, krb5_data **code);
2305     krb5_error_code (*encode_krb5_td_dh_parameters)
2306         (const krb5_algorithm_identifier **, krb5_data **code);
2307     krb5_error_code (*encode_krb5_td_trusted_certifiers)
2308         (const krb5_external_principal_identifier **, krb5_data **code);
2309     krb5_error_code (*encode_krb5_typed_data)
2310         (const krb5_typed_data **, krb5_data **code);
2311
2312     krb5_error_code (*decode_krb5_auth_pack)
2313         (const krb5_data *, krb5_auth_pack **);
2314     krb5_error_code (*decode_krb5_auth_pack_draft9)
2315         (const krb5_data *, krb5_auth_pack_draft9 **);
2316     krb5_error_code (*decode_krb5_pa_pk_as_req)
2317         (const krb5_data *, krb5_pa_pk_as_req **);
2318     krb5_error_code (*decode_krb5_pa_pk_as_req_draft9)
2319         (const krb5_data *, krb5_pa_pk_as_req_draft9 **);
2320     krb5_error_code (*decode_krb5_pa_pk_as_rep)
2321         (const krb5_data *, krb5_pa_pk_as_rep **);
2322     krb5_error_code (*decode_krb5_pa_pk_as_rep_draft9)
2323         (const krb5_data *, krb5_pa_pk_as_rep_draft9 **);
2324     krb5_error_code (*decode_krb5_kdc_dh_key_info)
2325         (const krb5_data *, krb5_kdc_dh_key_info **);
2326     krb5_error_code (*decode_krb5_principal_name)
2327         (const krb5_data *, krb5_principal_data **);
2328     krb5_error_code (*decode_krb5_reply_key_pack)
2329         (const krb5_data *, krb5_reply_key_pack **);
2330     krb5_error_code (*decode_krb5_reply_key_pack_draft9)
2331         (const krb5_data *, krb5_reply_key_pack_draft9 **);
2332     krb5_error_code (*decode_krb5_td_dh_parameters)
2333         (const krb5_data *, krb5_algorithm_identifier ***);
2334     krb5_error_code (*decode_krb5_td_trusted_certifiers)
2335         (const krb5_data *, krb5_external_principal_identifier ***);
2336     krb5_error_code (*decode_krb5_typed_data)
2337         (const krb5_data *, krb5_typed_data ***);
2338
2339     krb5_error_code (*decode_krb5_as_req)
2340         (const krb5_data *output, krb5_kdc_req **rep);
2341     krb5_error_code (*encode_krb5_kdc_req_body)
2342         (const krb5_kdc_req *rep, krb5_data **code);
2343     void (KRB5_CALLCONV *free_kdc_req)
2344         (krb5_context, krb5_kdc_req * );
2345     void (*set_prompt_types)
2346         (krb5_context, krb5_prompt_type *);
2347     krb5_error_code (*encode_krb5_authdata_elt)
2348         (const krb5_authdata *rep, krb5_data **code);
2349
2350     /* Exported for testing only!  */
2351     krb5_error_code (*encode_krb5_sam_response_2)
2352         (const krb5_sam_response_2 *rep, krb5_data **code);
2353     krb5_error_code (*encode_krb5_enc_sam_response_enc_2)
2354         (const krb5_enc_sam_response_enc_2 *rep, krb5_data **code);
2355
2356 } krb5int_access;
2357
2358 #define KRB5INT_ACCESS_VERSION \
2359     (((krb5_int32)((sizeof(krb5int_access) & 0xFFFF) | \
2360                    (KRB5INT_ACCESS_STRUCT_VERSION << 16))) & 0xFFFFFFFF)
2361
2362 krb5_error_code KRB5_CALLCONV krb5int_accessor
2363         (krb5int_access*, krb5_int32);
2364
2365 /* Ick -- some krb524 and krb4 support placed in the krb5 library,
2366    because AFS (and potentially other applications?) use the krb4
2367    object as an opaque token, which (in some implementations) is not
2368    in fact a krb4 ticket, so we don't want to drag in the krb4 support
2369    just to enable this.  */
2370
2371 #define KRB524_SERVICE "krb524"
2372 #define KRB524_PORT 4444
2373
2374 /* temporary -- this should be under lib/krb5/ccache somewhere */
2375
2376 struct _krb5_ccache {
2377     krb5_magic magic;
2378     const struct _krb5_cc_ops *ops;
2379     krb5_pointer data;
2380 };
2381
2382 /*
2383  * Per-type ccache cursor.
2384  */
2385 struct krb5_cc_ptcursor_s {
2386     const struct _krb5_cc_ops *ops;
2387     krb5_pointer data;
2388 };
2389 typedef struct krb5_cc_ptcursor_s *krb5_cc_ptcursor;
2390
2391 struct _krb5_cc_ops {
2392     krb5_magic magic;
2393     char *prefix;
2394     const char * (KRB5_CALLCONV *get_name) (krb5_context, krb5_ccache);
2395     krb5_error_code (KRB5_CALLCONV *resolve) (krb5_context, krb5_ccache *,
2396                                             const char *);
2397     krb5_error_code (KRB5_CALLCONV *gen_new) (krb5_context, krb5_ccache *);
2398     krb5_error_code (KRB5_CALLCONV *init) (krb5_context, krb5_ccache,
2399                                             krb5_principal);
2400     krb5_error_code (KRB5_CALLCONV *destroy) (krb5_context, krb5_ccache);
2401     krb5_error_code (KRB5_CALLCONV *close) (krb5_context, krb5_ccache);
2402     krb5_error_code (KRB5_CALLCONV *store) (krb5_context, krb5_ccache,
2403                                             krb5_creds *);
2404     krb5_error_code (KRB5_CALLCONV *retrieve) (krb5_context, krb5_ccache,
2405                                             krb5_flags, krb5_creds *,
2406                                             krb5_creds *);
2407     krb5_error_code (KRB5_CALLCONV *get_princ) (krb5_context, krb5_ccache,
2408                                             krb5_principal *);
2409     krb5_error_code (KRB5_CALLCONV *get_first) (krb5_context, krb5_ccache,
2410                                             krb5_cc_cursor *);
2411     krb5_error_code (KRB5_CALLCONV *get_next) (krb5_context, krb5_ccache,
2412                                             krb5_cc_cursor *, krb5_creds *);
2413     krb5_error_code (KRB5_CALLCONV *end_get) (krb5_context, krb5_ccache,
2414                                             krb5_cc_cursor *);
2415     krb5_error_code (KRB5_CALLCONV *remove_cred) (krb5_context, krb5_ccache,
2416                                             krb5_flags, krb5_creds *);
2417     krb5_error_code (KRB5_CALLCONV *set_flags) (krb5_context, krb5_ccache,
2418                                             krb5_flags);
2419     krb5_error_code (KRB5_CALLCONV *get_flags) (krb5_context, krb5_ccache,
2420                                                 krb5_flags *);
2421     krb5_error_code (KRB5_CALLCONV *ptcursor_new)(krb5_context,
2422                                                   krb5_cc_ptcursor *);
2423     krb5_error_code (KRB5_CALLCONV *ptcursor_next)(krb5_context,
2424                                                    krb5_cc_ptcursor,
2425                                                    krb5_ccache *);
2426     krb5_error_code (KRB5_CALLCONV *ptcursor_free)(krb5_context,
2427                                                    krb5_cc_ptcursor *);
2428     krb5_error_code (KRB5_CALLCONV *move)(krb5_context, krb5_ccache, 
2429                                                 krb5_ccache);
2430     krb5_error_code (KRB5_CALLCONV *lastchange)(krb5_context,
2431                                                 krb5_ccache, krb5_timestamp *);
2432     krb5_error_code (KRB5_CALLCONV *wasdefault)(krb5_context, krb5_ccache,
2433                                                 krb5_timestamp *);
2434     krb5_error_code (KRB5_CALLCONV *lock)(krb5_context, krb5_ccache);
2435     krb5_error_code (KRB5_CALLCONV *unlock)(krb5_context, krb5_ccache);
2436 };
2437
2438 extern const krb5_cc_ops *krb5_cc_dfl_ops;
2439
2440 krb5_error_code
2441 krb5int_cc_os_default_name(krb5_context context, char **name);
2442
2443 typedef struct _krb5_donot_replay {
2444     krb5_magic magic;
2445     krb5_ui_4 hash;
2446     char *server;                       /* null-terminated */
2447     char *client;                       /* null-terminated */
2448     char *msghash;                      /* null-terminated */
2449     krb5_int32 cusec;
2450     krb5_timestamp ctime;
2451 } krb5_donot_replay;
2452
2453 krb5_error_code krb5_rc_default 
2454         (krb5_context,
2455                 krb5_rcache *);
2456 krb5_error_code krb5_rc_resolve_type 
2457         (krb5_context,
2458                 krb5_rcache *,char *);
2459 krb5_error_code krb5_rc_resolve_full 
2460         (krb5_context,
2461                 krb5_rcache *,char *);
2462 char * krb5_rc_get_type 
2463         (krb5_context,
2464                 krb5_rcache);
2465 char * krb5_rc_default_type 
2466         (krb5_context);
2467 char * krb5_rc_default_name 
2468         (krb5_context);
2469 krb5_error_code krb5_auth_to_rep 
2470         (krb5_context,
2471                 krb5_tkt_authent *,
2472                 krb5_donot_replay *);
2473 krb5_error_code krb5_rc_hash_message
2474         (krb5_context context,
2475                 const krb5_data *message, char **out);
2476
2477
2478 krb5_error_code KRB5_CALLCONV krb5_rc_initialize
2479         (krb5_context, krb5_rcache,krb5_deltat);
2480 krb5_error_code KRB5_CALLCONV krb5_rc_recover_or_initialize
2481         (krb5_context, krb5_rcache,krb5_deltat);
2482 krb5_error_code KRB5_CALLCONV krb5_rc_recover
2483         (krb5_context, krb5_rcache);
2484 krb5_error_code KRB5_CALLCONV krb5_rc_destroy
2485         (krb5_context, krb5_rcache);
2486 krb5_error_code KRB5_CALLCONV krb5_rc_close
2487         (krb5_context, krb5_rcache);
2488 krb5_error_code KRB5_CALLCONV krb5_rc_store
2489         (krb5_context, krb5_rcache,krb5_donot_replay *);
2490 krb5_error_code KRB5_CALLCONV krb5_rc_expunge
2491         (krb5_context, krb5_rcache);
2492 krb5_error_code KRB5_CALLCONV krb5_rc_get_lifespan
2493         (krb5_context, krb5_rcache,krb5_deltat *);
2494 char *KRB5_CALLCONV krb5_rc_get_name
2495         (krb5_context, krb5_rcache);
2496 krb5_error_code KRB5_CALLCONV krb5_rc_resolve
2497         (krb5_context, krb5_rcache, char *);
2498
2499 typedef struct _krb5_kt_ops {
2500     krb5_magic magic;
2501     char *prefix;
2502     /* routines always present */
2503     krb5_error_code (KRB5_CALLCONV *resolve) 
2504         (krb5_context,
2505                  const char *,
2506                  krb5_keytab *);
2507     krb5_error_code (KRB5_CALLCONV *get_name) 
2508         (krb5_context,
2509                  krb5_keytab,
2510                  char *,
2511                  unsigned int);
2512     krb5_error_code (KRB5_CALLCONV *close) 
2513         (krb5_context,
2514                  krb5_keytab);
2515     krb5_error_code (KRB5_CALLCONV *get) 
2516         (krb5_context,
2517                  krb5_keytab,
2518                  krb5_const_principal,
2519                  krb5_kvno,
2520                  krb5_enctype,
2521                  krb5_keytab_entry *);
2522     krb5_error_code (KRB5_CALLCONV *start_seq_get) 
2523         (krb5_context,
2524                  krb5_keytab,
2525                  krb5_kt_cursor *);     
2526     krb5_error_code (KRB5_CALLCONV *get_next) 
2527         (krb5_context,
2528                  krb5_keytab,
2529                  krb5_keytab_entry *,
2530                  krb5_kt_cursor *);
2531     krb5_error_code (KRB5_CALLCONV *end_get) 
2532         (krb5_context,
2533                  krb5_keytab,
2534                  krb5_kt_cursor *);
2535     /* routines to be included on extended version (write routines) */
2536     krb5_error_code (KRB5_CALLCONV *add) 
2537         (krb5_context,
2538                  krb5_keytab,
2539                  krb5_keytab_entry *);
2540     krb5_error_code (KRB5_CALLCONV *remove) 
2541         (krb5_context,
2542                  krb5_keytab,
2543                   krb5_keytab_entry *);
2544
2545     /* Handle for serializer */
2546     const krb5_ser_entry *serializer;
2547 } krb5_kt_ops;
2548
2549 extern const krb5_kt_ops krb5_kt_dfl_ops;
2550
2551 extern krb5_error_code krb5int_translate_gai_error (int);
2552
2553 /* Not sure it's ready for exposure just yet.  */
2554 extern krb5_error_code
2555 krb5int_c_mandatory_cksumtype (krb5_context, krb5_enctype, krb5_cksumtype *);
2556
2557 extern int krb5int_crypto_init (void);
2558 extern int krb5int_prng_init(void);
2559
2560 /*
2561  * Referral definitions, debugging hooks, and subfunctions.
2562  */
2563 #define        KRB5_REFERRAL_MAXHOPS    10
2564 /* #define DEBUG_REFERRALS */
2565
2566 #ifdef DEBUG_REFERRALS
2567 void krb5int_dbgref_dump_principal(char *, krb5_principal);
2568 #endif
2569
2570 /* Common hostname-parsing code. */
2571 krb5_error_code KRB5_CALLCONV krb5int_clean_hostname
2572         (krb5_context,
2573                 const char *,
2574                 char *,
2575                 size_t);
2576
2577 /* Use the above four instead.  */
2578 krb5_boolean KRB5_CALLCONV valid_enctype
2579         (krb5_enctype ktype);
2580 krb5_boolean KRB5_CALLCONV valid_cksumtype
2581         (krb5_cksumtype ctype);
2582 krb5_boolean KRB5_CALLCONV is_coll_proof_cksum
2583         (krb5_cksumtype ctype);
2584 krb5_boolean KRB5_CALLCONV is_keyed_cksum
2585         (krb5_cksumtype ctype);
2586
2587 krb5_error_code KRB5_CALLCONV krb5_random_confounder
2588         (size_t, krb5_pointer);
2589
2590 krb5_error_code krb5_encrypt_data
2591         (krb5_context context, krb5_keyblock *key, 
2592                 krb5_pointer ivec, krb5_data *data, 
2593                 krb5_enc_data *enc_data);
2594
2595 krb5_error_code krb5_decrypt_data
2596         (krb5_context context, krb5_keyblock *key, 
2597                 krb5_pointer ivec, krb5_enc_data *data, 
2598                 krb5_data *enc_data);
2599
2600 krb5_error_code
2601 krb5int_aes_encrypt(krb5_key key, const krb5_data *ivec,
2602                     const krb5_data *input, krb5_data *output);
2603 krb5_error_code
2604 krb5int_aes_decrypt(krb5_key key, const krb5_data *ivec,
2605                     const krb5_data *input, krb5_data *output);
2606
2607 struct _krb5_kt {       /* should move into k5-int.h */
2608     krb5_magic magic;
2609     const struct _krb5_kt_ops *ops;
2610     krb5_pointer data;
2611 };
2612
2613 krb5_error_code krb5_set_default_in_tkt_ktypes
2614         (krb5_context,
2615                 const krb5_enctype *);
2616 krb5_error_code krb5_get_default_in_tkt_ktypes
2617         (krb5_context,
2618                 krb5_enctype **);
2619
2620 krb5_error_code krb5_set_default_tgs_ktypes
2621         (krb5_context,
2622                 const krb5_enctype *);
2623
2624 krb5_error_code KRB5_CALLCONV krb5_get_tgs_ktypes
2625         (krb5_context,
2626                 krb5_const_principal,
2627                 krb5_enctype **);
2628
2629 void KRB5_CALLCONV krb5_free_ktypes
2630         (krb5_context, krb5_enctype *);
2631
2632 krb5_boolean krb5_is_permitted_enctype
2633         (krb5_context, krb5_enctype);
2634
2635 typedef struct
2636 {
2637         krb5_enctype *etype;
2638         krb5_boolean *etype_ok;
2639         krb5_int32 etype_count;
2640 } krb5_etypes_permitted;
2641
2642 krb5_boolean krb5_is_permitted_enctype_ext 
2643          ( krb5_context, krb5_etypes_permitted *);
2644
2645 krb5_boolean KRB5_CALLCONV krb5int_c_weak_enctype(krb5_enctype);
2646
2647 krb5_error_code krb5_kdc_rep_decrypt_proc
2648         (krb5_context,
2649                 const krb5_keyblock *,
2650                 krb5_const_pointer,
2651                 krb5_kdc_rep * );
2652 krb5_error_code KRB5_CALLCONV krb5_decrypt_tkt_part
2653         (krb5_context,
2654                 const krb5_keyblock *,
2655                 krb5_ticket * );
2656 krb5_error_code krb5_get_cred_from_kdc
2657         (krb5_context,
2658                 krb5_ccache,            /* not const, as reading may save
2659                                            state */
2660                 krb5_creds *,
2661                 krb5_creds **,
2662                 krb5_creds *** );
2663 krb5_error_code krb5_get_cred_from_kdc_validate
2664         (krb5_context,
2665                 krb5_ccache,            /* not const, as reading may save
2666                                            state */
2667                 krb5_creds *,
2668                 krb5_creds **,
2669                 krb5_creds *** );
2670 krb5_error_code krb5_get_cred_from_kdc_renew
2671         (krb5_context,
2672                 krb5_ccache,            /* not const, as reading may save
2673                                            state */
2674                 krb5_creds *,
2675                 krb5_creds **,
2676                 krb5_creds *** );
2677
2678 krb5_error_code krb5_get_cred_via_tkt
2679         (krb5_context,
2680                    krb5_creds *,
2681                    krb5_flags,
2682                    krb5_address * const *,
2683                    krb5_creds *,
2684                    krb5_creds **);
2685
2686 krb5_error_code KRB5_CALLCONV krb5_copy_addr
2687         (krb5_context,
2688                 const krb5_address *,
2689                 krb5_address **);
2690
2691 void krb5_init_ets
2692         (krb5_context);
2693 void krb5_free_ets
2694         (krb5_context);
2695 krb5_error_code krb5_generate_subkey
2696         (krb5_context,
2697                 const krb5_keyblock *, krb5_keyblock **);
2698 krb5_error_code krb5_generate_subkey_extended
2699         (krb5_context,
2700                 const krb5_keyblock *,
2701                 krb5_enctype,
2702                 krb5_keyblock **);
2703 krb5_error_code krb5_generate_seq_number
2704         (krb5_context,
2705                 const krb5_keyblock *, krb5_ui_4 *);
2706
2707 krb5_error_code KRB5_CALLCONV krb5_kt_register
2708         (krb5_context,
2709                 const struct _krb5_kt_ops * );
2710
2711 /* use krb5_free_keytab_entry_contents instead */
2712 krb5_error_code KRB5_CALLCONV krb5_kt_free_entry
2713         (krb5_context,
2714                 krb5_keytab_entry * );
2715
2716 krb5_error_code krb5_principal2salt_norealm
2717         (krb5_context,
2718                 krb5_const_principal, krb5_data *);
2719
2720 unsigned int KRB5_CALLCONV krb5_get_notification_message
2721         (void);
2722
2723 /* chk_trans.c */
2724 krb5_error_code krb5_check_transited_list
2725         (krb5_context, const krb5_data *trans,
2726          const krb5_data *realm1, const krb5_data *realm2);
2727
2728 /* free_rtree.c */
2729 void krb5_free_realm_tree
2730         (krb5_context,
2731                 krb5_principal *);
2732
2733 void KRB5_CALLCONV krb5_free_authenticator_contents
2734         (krb5_context, krb5_authenticator * );
2735
2736 void KRB5_CALLCONV krb5_free_address
2737         (krb5_context, krb5_address * );
2738
2739 void KRB5_CALLCONV krb5_free_enc_tkt_part
2740         (krb5_context, krb5_enc_tkt_part * );
2741
2742 void KRB5_CALLCONV krb5_free_tickets
2743         (krb5_context, krb5_ticket ** );
2744 void KRB5_CALLCONV krb5_free_kdc_req
2745         (krb5_context, krb5_kdc_req * );
2746 void KRB5_CALLCONV krb5_free_kdc_rep
2747         (krb5_context, krb5_kdc_rep * );
2748 void KRB5_CALLCONV krb5_free_last_req
2749         (krb5_context, krb5_last_req_entry ** );
2750 void KRB5_CALLCONV krb5_free_enc_kdc_rep_part
2751         (krb5_context, krb5_enc_kdc_rep_part * );
2752 void KRB5_CALLCONV krb5_free_ap_req
2753         (krb5_context, krb5_ap_req * );
2754 void KRB5_CALLCONV krb5_free_ap_rep
2755         (krb5_context, krb5_ap_rep * );
2756 void KRB5_CALLCONV krb5_free_cred
2757         (krb5_context, krb5_cred *);
2758 void KRB5_CALLCONV krb5_free_cred_enc_part
2759         (krb5_context, krb5_cred_enc_part *);
2760 void KRB5_CALLCONV krb5_free_pa_data
2761         (krb5_context, krb5_pa_data **);
2762 void KRB5_CALLCONV krb5_free_tkt_authent
2763         (krb5_context, krb5_tkt_authent *);
2764 void KRB5_CALLCONV krb5_free_pwd_data
2765         (krb5_context, krb5_pwd_data *);
2766 void KRB5_CALLCONV krb5_free_pwd_sequences
2767         (krb5_context, passwd_phrase_element **);
2768 void KRB5_CALLCONV krb5_free_passwd_phrase_element
2769         (krb5_context, passwd_phrase_element *);
2770 void KRB5_CALLCONV krb5_free_alt_method
2771         (krb5_context, krb5_alt_method *);
2772 void KRB5_CALLCONV krb5_free_enc_data
2773         (krb5_context, krb5_enc_data *);
2774 krb5_error_code krb5_set_config_files
2775         (krb5_context, const char **);
2776
2777 krb5_error_code KRB5_CALLCONV krb5_get_default_config_files
2778         (char ***filenames);
2779
2780 void KRB5_CALLCONV krb5_free_config_files
2781         (char **filenames);
2782 krb5_error_code krb5int_send_tgs
2783         (krb5_context,
2784                 krb5_flags,
2785                 const krb5_ticket_times *,
2786                 const krb5_enctype *,
2787                 krb5_const_principal,
2788                 krb5_address * const *,
2789                 krb5_authdata * const *,
2790                 krb5_pa_data * const *,
2791                 const krb5_data *,
2792                 krb5_creds *,
2793                 krb5_error_code (*gcvt_fct)(krb5_context,
2794                                             krb5_keyblock *,
2795                                             krb5_kdc_req *,
2796                                             void *),
2797                 void *gcvt_data,
2798                 krb5_response * , krb5_keyblock **subkey);
2799                 /* The subkey field is an output parameter; if a
2800                  * tgs-rep is received then the subkey will be filled
2801                  * in with the subkey needed to decrypt the TGS
2802                  * response. Otherwise it will be set to null.
2803                  */
2804 krb5_error_code krb5int_decode_tgs_rep
2805         (krb5_context,
2806                 krb5_data *,
2807          const krb5_keyblock *, krb5_keyusage,
2808                 krb5_kdc_rep ** );
2809 krb5_error_code krb5int_find_authdata
2810 (krb5_context context, krb5_authdata *const * ticket_authdata,
2811  krb5_authdata * const *ap_req_authdata,
2812  krb5_authdatatype ad_type,
2813  krb5_authdata ***results);
2814
2815 krb5_error_code krb5_rd_req_decoded
2816         (krb5_context,
2817                 krb5_auth_context *,
2818                 const krb5_ap_req *,
2819                 krb5_const_principal,
2820                 krb5_keytab,
2821                 krb5_flags *,
2822                 krb5_ticket **);
2823
2824 krb5_error_code krb5_rd_req_decoded_anyflag
2825         (krb5_context,
2826                 krb5_auth_context *,
2827                 const krb5_ap_req *,
2828                 krb5_const_principal,
2829                 krb5_keytab,
2830                 krb5_flags *,
2831                 krb5_ticket **);
2832
2833 krb5_error_code KRB5_CALLCONV krb5_cc_register
2834         (krb5_context,
2835                 const krb5_cc_ops *,
2836                 krb5_boolean );
2837 krb5_error_code krb5_walk_realm_tree
2838         (krb5_context,
2839                 const krb5_data *,
2840                 const krb5_data *,
2841                 krb5_principal **,
2842                 int);
2843 krb5_error_code KRB5_CALLCONV krb5_auth_con_set_req_cksumtype
2844         (krb5_context,
2845                 krb5_auth_context,
2846                 krb5_cksumtype);
2847
2848 krb5_error_code krb5_auth_con_set_safe_cksumtype
2849         (krb5_context,
2850                 krb5_auth_context,
2851                 krb5_cksumtype);
2852 krb5_error_code krb5_auth_con_setivector
2853         (krb5_context,
2854                 krb5_auth_context,
2855                 krb5_pointer);
2856
2857 krb5_error_code krb5_auth_con_getivector
2858         (krb5_context,
2859                 krb5_auth_context,
2860                 krb5_pointer *);
2861
2862 krb5_error_code krb5_auth_con_setpermetypes
2863         (krb5_context,
2864             krb5_auth_context,
2865             const krb5_enctype *);
2866
2867 krb5_error_code krb5_auth_con_getpermetypes
2868         (krb5_context,
2869             krb5_auth_context,
2870             krb5_enctype **);
2871
2872 krb5_error_code krb5_auth_con_get_subkey_enctype
2873         (krb5_context context,
2874             krb5_auth_context,
2875             krb5_enctype *);
2876
2877 krb5_error_code
2878 krb5_auth_con_get_authdata_context
2879         (krb5_context context,
2880             krb5_auth_context auth_context,
2881             krb5_authdata_context *ad_context);
2882
2883 krb5_error_code
2884 krb5_auth_con_set_authdata_context
2885         (krb5_context context,
2886             krb5_auth_context auth_context,
2887             krb5_authdata_context ad_context);
2888
2889 krb5_error_code KRB5_CALLCONV
2890 krb5int_server_decrypt_ticket_keyblock
2891         (krb5_context context,
2892                 const krb5_keyblock *key,
2893                 krb5_ticket  *ticket);
2894
2895 krb5_error_code krb5_read_message (krb5_context, krb5_pointer, krb5_data *);
2896 krb5_error_code krb5_write_message (krb5_context, krb5_pointer, krb5_data *);
2897 krb5_error_code krb5int_write_messages (krb5_context, krb5_pointer, krb5_data *, int);
2898 int krb5_net_read (krb5_context, int , char *, int);
2899 int krb5_net_write (krb5_context, int , const char *, int);
2900
2901 krb5_error_code KRB5_CALLCONV krb5_get_realm_domain
2902         (krb5_context,
2903                 const char *,
2904                 char ** );
2905
2906 krb5_error_code krb5_gen_portaddr
2907         (krb5_context,
2908                 const krb5_address *,
2909                 krb5_const_pointer,
2910                 krb5_address **);
2911 krb5_error_code krb5_gen_replay_name
2912         (krb5_context,
2913                 const krb5_address *,
2914                 const char *,
2915                 char **);
2916 krb5_error_code krb5_make_fulladdr
2917         (krb5_context,
2918                 krb5_address *,
2919                 krb5_address *,
2920                 krb5_address *);
2921
2922 krb5_error_code krb5_set_debugging_time
2923         (krb5_context, krb5_timestamp, krb5_int32);
2924 krb5_error_code krb5_use_natural_time
2925         (krb5_context);
2926 krb5_error_code krb5_set_time_offsets
2927         (krb5_context, krb5_timestamp, krb5_int32);
2928 krb5_error_code krb5int_check_clockskew(krb5_context, krb5_timestamp);
2929 /*
2930  * The realm iterator functions
2931  */
2932
2933 krb5_error_code KRB5_CALLCONV krb5_realm_iterator_create
2934         (krb5_context context, void **iter_p);
2935
2936 krb5_error_code KRB5_CALLCONV krb5_realm_iterator
2937         (krb5_context context, void **iter_p, char **ret_realm);
2938
2939 void KRB5_CALLCONV krb5_realm_iterator_free
2940         (krb5_context context, void **iter_p);
2941
2942 void KRB5_CALLCONV krb5_free_realm_string
2943         (krb5_context context, char *str);
2944
2945 /* Internal principal function used by KIM to avoid code duplication */
2946 krb5_error_code KRB5_CALLCONV
2947 krb5int_build_principal_alloc_va(krb5_context context, 
2948                                  krb5_principal *princ, 
2949                                  unsigned int rlen, 
2950                                  const char *realm, 
2951                                  const char *first,
2952                                  va_list ap);
2953
2954 /* Some data comparison and conversion functions.  */
2955 #if 0
2956 static inline int data_cmp(krb5_data d1, krb5_data d2)
2957 {
2958     if (d1.length < d2.length) return -1;
2959     if (d1.length > d2.length) return 1;
2960     return memcmp(d1.data, d2.data, d1.length);
2961 }
2962 static inline int data_eq (krb5_data d1, krb5_data d2)
2963 {
2964     return data_cmp(d1, d2) == 0;
2965 }
2966 #else
2967 static inline int data_eq (krb5_data d1, krb5_data d2)
2968 {
2969     return (d1.length == d2.length
2970             && !memcmp(d1.data, d2.data, d1.length));
2971 }
2972 #endif
2973 static inline krb5_data string2data (char *str)
2974 {
2975     krb5_data d;
2976     d.magic = KV5M_DATA;
2977     d.length = strlen(str);
2978     d.data = str;
2979     return d;
2980 }
2981 static inline int data_eq_string (krb5_data d, char *s)
2982 {
2983     return data_eq(d, string2data(s));
2984 }
2985 static inline int authdata_eq (krb5_authdata a1, krb5_authdata a2)
2986 {
2987     return (a1.ad_type == a2.ad_type
2988             && a1.length == a2.length
2989             && !memcmp(a1.contents, a2.contents, a1.length));
2990 }
2991
2992 /* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */
2993 static inline void *
2994 k5alloc(size_t size, krb5_error_code *code)
2995 {
2996     void *ptr;
2997
2998     ptr = calloc(size, 1);
2999     *code = (ptr == NULL) ? ENOMEM : 0;
3000     return ptr;
3001 }
3002
3003 krb5_error_code KRB5_CALLCONV
3004 krb5int_pac_sign(krb5_context context,
3005                  krb5_pac pac,
3006                  krb5_timestamp authtime,
3007                  krb5_const_principal principal,
3008                  const krb5_keyblock *server_key,
3009                  const krb5_keyblock *privsvr_key,
3010                  krb5_data *data);
3011
3012 krb5_error_code KRB5_CALLCONV
3013 krb5_get_credentials_for_user(krb5_context context, krb5_flags options,
3014                               krb5_ccache ccache,
3015                               krb5_creds *in_creds,
3016                               krb5_data *cert,
3017                               krb5_creds **out_creds);
3018
3019 krb5_error_code KRB5_CALLCONV
3020 krb5_get_credentials_for_proxy(krb5_context context,
3021                                krb5_flags options,
3022                                krb5_ccache ccache,
3023                                krb5_creds *in_creds,
3024                                krb5_ticket *evidence_tkt,
3025                                krb5_creds **out_creds);
3026
3027 krb5_error_code krb5int_parse_enctype_list(krb5_context context, char *profstr,
3028                                            krb5_enctype *default_list,
3029                                            krb5_enctype **result);
3030
3031 #ifdef DEBUG_ERROR_LOCATIONS
3032 #define krb5_set_error_message(ctx, code, ...) \
3033     krb5_set_error_message_fl(ctx, code, __FILE__, __LINE__, __VA_ARGS__)
3034 #endif
3035
3036 #endif /* _KRB5_INT_H */