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