4f221fbeee6232ea14cc19544a4e0e2fa9b6bcd6
[asn/mit-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,
4  * 2003,2006,2007,2008,2009 by the Massachusetts Institute of Technology,
5  * Cambridge, MA, USA.  All Rights Reserved.
6  *
7  * This software is being provided to you, the LICENSEE, by the
8  * Massachusetts Institute of Technology (M.I.T.) under the following
9  * license.  By obtaining, using and/or copying this software, you agree
10  * that you have read, understood, and will comply with these terms and
11  * conditions:
12  *
13  * Export of this software from the United States of America may
14  * require a specific license from the United States Government.
15  * It is the responsibility of any person or organization contemplating
16  * export to obtain such a license before exporting.
17  *
18  * WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute
19  * this software and its documentation for any purpose and without fee or
20  * royalty is hereby granted, provided that you agree to comply with the
21  * following copyright notice and statements, including the disclaimer, and
22  * that the same appear on ALL copies of the software and documentation,
23  * including modifications that you make for internal use or for
24  * distribution:
25  *
26  * THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
27  * OR WARRANTIES, EXPRESS OR IMPLIED.  By way of example, but not
28  * limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
29  * MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
30  * THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
31  * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
32  *
33  * The name of the Massachusetts Institute of Technology or M.I.T. may NOT
34  * be used in advertising or publicity pertaining to distribution of the
35  * software.  Title to copyright in this software and any associated
36  * documentation shall at all times remain with M.I.T., and USER agrees to
37  * preserve same.
38  *
39  * Furthermore if you modify this software you must label
40  * your software as modified software and not distribute it in such a
41  * fashion that it might be confused with the original M.I.T. software.
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 #endif
114
115 #include "autoconf.h"
116
117 #ifndef KRB5_SYSTYPES__
118 #define KRB5_SYSTYPES__
119
120 #ifdef HAVE_SYS_TYPES_H         /* From autoconf.h */
121 #include <sys/types.h>
122 #else /* HAVE_SYS_TYPES_H */
123 typedef unsigned long   u_long;
124 typedef unsigned int    u_int;
125 typedef unsigned short  u_short;
126 typedef unsigned char   u_char;
127 #endif /* HAVE_SYS_TYPES_H */
128 #endif /* KRB5_SYSTYPES__ */
129
130
131 #include "k5-platform.h"
132 /* not used in krb5.h (yet) */
133 typedef UINT64_TYPE krb5_ui_8;
134 typedef INT64_TYPE krb5_int64;
135
136
137 #define KRB5_KDB_MAX_LIFE       (60*60*24) /* one day */
138 #define KRB5_KDB_MAX_RLIFE      (60*60*24*7) /* one week */
139 #define KRB5_KDB_EXPIRATION     2145830400 /* Thu Jan  1 00:00:00 2038 UTC */
140
141 /*
142  * Windows requires a different api interface to each function. Here
143  * just define it as NULL.
144  */
145 #ifndef KRB5_CALLCONV
146 #define KRB5_CALLCONV
147 #define KRB5_CALLCONV_C
148 #endif
149 #ifndef O_BINARY
150 #define O_BINARY 0
151 #endif
152
153 /* #define KRB5_OLD_CRYPTO is done in krb5.h */
154
155 #endif /* KRB5_CONFIG__ */
156
157 /*
158  * End "k5-config.h"
159  */
160
161 /*
162  * After loading the configuration definitions, load the Kerberos definitions.
163  */
164 #include <errno.h>
165 #include "krb5.h"
166 #include <krb5/plugin.h>
167 #include "profile.h"
168
169 #include "port-sockets.h"
170 #include "socket-utils.h"
171
172 /* Get mutex support; currently used only for the replay cache.  */
173 #include "k5-thread.h"
174
175 /* Get error info support.  */
176 #include "k5-err.h"
177
178 /* Get string buffer support. */
179 #include "k5-buf.h"
180
181 /* Define tracing macros. */
182 #include "k5-trace.h"
183
184 /* cofiguration variables */
185 #define KRB5_CONF_ACL_FILE                       "acl_file"
186 #define KRB5_CONF_ADMIN_SERVER                   "admin_server"
187 #define KRB5_CONF_ALLOW_WEAK_CRYPTO              "allow_weak_crypto"
188 #define KRB5_CONF_AP_REQ_CHECKSUM_TYPE           "ap_req_checksum_type"
189 #define KRB5_CONF_AUTH_TO_LOCAL                  "auth_to_local"
190 #define KRB5_CONF_AUTH_TO_LOCAL_NAMES            "auth_to_local_names"
191 #define KRB5_CONF_CANONICALIZE                   "canonicalize"
192 #define KRB5_CONF_CCACHE_TYPE                    "ccache_type"
193 #define KRB5_CONF_CLOCKSKEW                      "clockskew"
194 #define KRB5_CONF_DATABASE_NAME                  "database_name"
195 #define KRB5_CONF_DB_MODULE_DIR                  "db_module_dir"
196 #define KRB5_CONF_DEFAULT                        "default"
197 #define KRB5_CONF_DEFAULT_REALM                  "default_realm"
198 #define KRB5_CONF_DEFAULT_CCACHE_NAME            "default_ccache_name"
199 #define KRB5_CONF_DEFAULT_CLIENT_KEYTAB_NAME     "default_client_keytab_name"
200 #define KRB5_CONF_DEFAULT_DOMAIN                 "default_domain"
201 #define KRB5_CONF_DEFAULT_TKT_ENCTYPES           "default_tkt_enctypes"
202 #define KRB5_CONF_DEFAULT_TGS_ENCTYPES           "default_tgs_enctypes"
203 #define KRB5_CONF_DEFAULT_KEYTAB_NAME            "default_keytab_name"
204 #define KRB5_CONF_DEFAULT_PRINCIPAL_EXPIRATION   "default_principal_expiration"
205 #define KRB5_CONF_DEFAULT_PRINCIPAL_FLAGS        "default_principal_flags"
206 #define KRB5_CONF_DICT_FILE                   "dict_file"
207 #define KRB5_CONF_DISABLE                     "disable"
208 #define KRB5_CONF_DISABLE_LAST_SUCCESS        "disable_last_success"
209 #define KRB5_CONF_DISABLE_LOCKOUT             "disable_lockout"
210 #define KRB5_CONF_DNS_CANONICALIZE_HOSTNAME   "dns_canonicalize_hostname"
211 #define KRB5_CONF_DNS_LOOKUP_KDC              "dns_lookup_kdc"
212 #define KRB5_CONF_DNS_LOOKUP_REALM            "dns_lookup_realm"
213 #define KRB5_CONF_DNS_FALLBACK                "dns_fallback"
214 #define KRB5_CONF_DOMAIN_REALM                "domain_realm"
215 #define KRB5_CONF_ENABLE_ONLY                 "enable_only"
216 #define KRB5_CONF_EXTRA_ADDRESSES             "extra_addresses"
217 #define KRB5_CONF_FORWARDABLE                 "forwardable"
218 #define KRB5_CONF_HOST_BASED_SERVICES         "host_based_services"
219 #define KRB5_CONF_IGNORE_ACCEPTOR_HOSTNAME    "ignore_acceptor_hostname"
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_IPROP_RESYNC_TIMEOUT        "iprop_resync_timeout"
226 #define KRB5_CONF_K5LOGIN_AUTHORITATIVE       "k5login_authoritative"
227 #define KRB5_CONF_K5LOGIN_DIRECTORY           "k5login_directory"
228 #define KRB5_CONF_KADMIND_PORT                "kadmind_port"
229 #define KRB5_CONF_KRB524_SERVER               "krb524_server"
230 #define KRB5_CONF_KDC                         "kdc"
231 #define KRB5_CONF_KDCDEFAULTS                 "kdcdefaults"
232 #define KRB5_CONF_KDC_PORTS                   "kdc_ports"
233 #define KRB5_CONF_KDC_TCP_PORTS               "kdc_tcp_ports"
234 #define KRB5_CONF_MAX_DGRAM_REPLY_SIZE        "kdc_max_dgram_reply_size"
235 #define KRB5_CONF_KDC_DEFAULT_OPTIONS         "kdc_default_options"
236 #define KRB5_CONF_KDC_TIMESYNC                "kdc_timesync"
237 #define KRB5_CONF_KDC_REQ_CHECKSUM_TYPE       "kdc_req_checksum_type"
238 #define KRB5_CONF_KEY_STASH_FILE              "key_stash_file"
239 #define KRB5_CONF_KPASSWD_PORT                "kpasswd_port"
240 #define KRB5_CONF_KPASSWD_SERVER              "kpasswd_server"
241 #define KRB5_CONF_LDAP_CONNS_PER_SERVER       "ldap_conns_per_server"
242 #define KRB5_CONF_LDAP_KADMIN_DN              "ldap_kadmind_dn"
243 #define KRB5_CONF_LDAP_KDC_DN                 "ldap_kdc_dn"
244 #define KRB5_CONF_LDAP_KERBEROS_CONTAINER_DN  "ldap_kerberos_container_dn"
245 #define KRB5_CONF_LDAP_SERVERS                "ldap_servers"
246 #define KRB5_CONF_LDAP_SERVICE_PASSWORD_FILE  "ldap_service_password_file"
247 #define KRB5_CONF_LIBDEFAULTS                 "libdefaults"
248 #define KRB5_CONF_LOGGING                     "logging"
249 #define KRB5_CONF_MASTER_KEY_NAME             "master_key_name"
250 #define KRB5_CONF_MASTER_KEY_TYPE             "master_key_type"
251 #define KRB5_CONF_MASTER_KDC                  "master_kdc"
252 #define KRB5_CONF_MAX_LIFE                    "max_life"
253 #define KRB5_CONF_MAX_RENEWABLE_LIFE          "max_renewable_life"
254 #define KRB5_CONF_MODULE                      "module"
255 #define KRB5_CONF_NOADDRESSES                 "noaddresses"
256 #define KRB5_CONF_NO_HOST_REFERRAL            "no_host_referral"
257 #define KRB5_CONF_PERMITTED_ENCTYPES          "permitted_enctypes"
258 #define KRB5_CONF_PLUGINS                     "plugins"
259 #define KRB5_CONF_PLUGIN_BASE_DIR             "plugin_base_dir"
260 #define KRB5_CONF_PREFERRED_PREAUTH_TYPES     "preferred_preauth_types"
261 #define KRB5_CONF_PROXIABLE                   "proxiable"
262 #define KRB5_CONF_RDNS                        "rdns"
263 #define KRB5_CONF_REALMS                      "realms"
264 #define KRB5_CONF_REALM_TRY_DOMAINS           "realm_try_domains"
265 #define KRB5_CONF_REJECT_BAD_TRANSIT          "reject_bad_transit"
266 #define KRB5_CONF_RENEW_LIFETIME              "renew_lifetime"
267 #define KRB5_CONF_RESTRICT_ANONYMOUS_TO_TGT   "restrict_anonymous_to_tgt"
268 #define KRB5_CONF_ASSUME_DES_CRC_SESSION      "des_crc_session_supported"
269 #define KRB5_CONF_SAFE_CHECKSUM_TYPE          "safe_checksum_type"
270 #define KRB5_CONF_SUPPORTED_ENCTYPES          "supported_enctypes"
271 #define KRB5_CONF_TICKET_LIFETIME             "ticket_lifetime"
272 #define KRB5_CONF_UDP_PREFERENCE_LIMIT        "udp_preference_limit"
273 #define KRB5_CONF_VERIFY_AP_REQ_NOFAIL        "verify_ap_req_nofail"
274 #define KRB5_CONF_V4_INSTANCE_CONVERT         "v4_instance_convert"
275 #define KRB5_CONF_V4_REALM                    "v4_realm"
276
277 /* Cache configuration variables */
278 #define KRB5_CC_CONF_FAST_AVAIL                  "fast_avail"
279 #define KRB5_CC_CONF_PROXY_IMPERSONATOR          "proxy_impersonator"
280 #define KRB5_CC_CONF_REFRESH_TIME                "refresh_time"
281 #define KRB5_CC_CONF_PA_TYPE                     "pa_type"
282 #define KRB5_CC_CONF_PA_CONFIG_DATA              "pa_config_data"
283
284 /* Error codes used in KRB_ERROR protocol messages.
285    Return values of library routines are based on a different error table
286    (which allows non-ambiguous error codes between subsystems) */
287
288 /* KDC errors */
289 #define KDC_ERR_NONE                    0 /* No error */
290 #define KDC_ERR_NAME_EXP                1 /* Client's entry in DB expired */
291 #define KDC_ERR_SERVICE_EXP             2 /* Server's entry in DB expired */
292 #define KDC_ERR_BAD_PVNO                3 /* Requested pvno not supported */
293 #define KDC_ERR_C_OLD_MAST_KVNO         4 /* C's key encrypted in old master */
294 #define KDC_ERR_S_OLD_MAST_KVNO         5 /* S's key encrypted in old master */
295 #define KDC_ERR_C_PRINCIPAL_UNKNOWN     6 /* Client not found in Kerberos DB */
296 #define KDC_ERR_S_PRINCIPAL_UNKNOWN     7 /* Server not found in Kerberos DB */
297 #define KDC_ERR_PRINCIPAL_NOT_UNIQUE    8 /* Multiple entries in Kerberos DB */
298 #define KDC_ERR_NULL_KEY                9 /* The C or S has a null key */
299 #define KDC_ERR_CANNOT_POSTDATE         10 /* Tkt ineligible for postdating */
300 #define KDC_ERR_NEVER_VALID             11 /* Requested starttime > endtime */
301 #define KDC_ERR_POLICY                  12 /* KDC policy rejects request */
302 #define KDC_ERR_BADOPTION               13 /* KDC can't do requested opt. */
303 #define KDC_ERR_ENCTYPE_NOSUPP          14 /* No support for encryption type */
304 #define KDC_ERR_SUMTYPE_NOSUPP          15 /* No support for checksum type */
305 #define KDC_ERR_PADATA_TYPE_NOSUPP      16 /* No support for padata type */
306 #define KDC_ERR_TRTYPE_NOSUPP           17 /* No support for transited type */
307 #define KDC_ERR_CLIENT_REVOKED          18 /* C's creds have been revoked */
308 #define KDC_ERR_SERVICE_REVOKED         19 /* S's creds have been revoked */
309 #define KDC_ERR_TGT_REVOKED             20 /* TGT has been revoked */
310 #define KDC_ERR_CLIENT_NOTYET           21 /* C not yet valid */
311 #define KDC_ERR_SERVICE_NOTYET          22 /* S not yet valid */
312 #define KDC_ERR_KEY_EXP                 23 /* Password has expired */
313 #define KDC_ERR_PREAUTH_FAILED          24 /* Preauthentication failed */
314 #define KDC_ERR_PREAUTH_REQUIRED        25 /* Additional preauthentication */
315                                            /* required */
316 #define KDC_ERR_SERVER_NOMATCH          26 /* Requested server and */
317                                            /* ticket don't match*/
318 #define KDC_ERR_MUST_USE_USER2USER      27 /* Server principal valid for */
319                                            /*   user2user only */
320 #define KDC_ERR_PATH_NOT_ACCEPTED       28 /* KDC policy rejected transited */
321                                            /*   path */
322 #define KDC_ERR_SVC_UNAVAILABLE         29 /* A service is not
323                                             * available that is
324                                             * required to process the
325                                             * request */
326 /* Application errors */
327 #define KRB_AP_ERR_BAD_INTEGRITY 31     /* Decrypt integrity check failed */
328 #define KRB_AP_ERR_TKT_EXPIRED  32      /* Ticket expired */
329 #define KRB_AP_ERR_TKT_NYV      33      /* Ticket not yet valid */
330 #define KRB_AP_ERR_REPEAT       34      /* Request is a replay */
331 #define KRB_AP_ERR_NOT_US       35      /* The ticket isn't for us */
332 #define KRB_AP_ERR_BADMATCH     36      /* Ticket/authenticator don't match */
333 #define KRB_AP_ERR_SKEW         37      /* Clock skew too great */
334 #define KRB_AP_ERR_BADADDR      38      /* Incorrect net address */
335 #define KRB_AP_ERR_BADVERSION   39      /* Protocol version mismatch */
336 #define KRB_AP_ERR_MSG_TYPE     40      /* Invalid message type */
337 #define KRB_AP_ERR_MODIFIED     41      /* Message stream modified */
338 #define KRB_AP_ERR_BADORDER     42      /* Message out of order */
339 #define KRB_AP_ERR_BADKEYVER    44      /* Key version is not available */
340 #define KRB_AP_ERR_NOKEY        45      /* Service key not available */
341 #define KRB_AP_ERR_MUT_FAIL     46      /* Mutual authentication failed */
342 #define KRB_AP_ERR_BADDIRECTION 47      /* Incorrect message direction */
343 #define KRB_AP_ERR_METHOD       48      /* Alternative authentication */
344                                         /* method required */
345 #define KRB_AP_ERR_BADSEQ       49      /* Incorrect sequence numnber */
346                                         /* in message */
347 #define KRB_AP_ERR_INAPP_CKSUM  50      /* Inappropriate type of */
348                                         /* checksum in message */
349 #define KRB_AP_PATH_NOT_ACCEPTED 51     /* Policy rejects transited path */
350 #define KRB_ERR_RESPONSE_TOO_BIG 52     /* Response too big for UDP, */
351                                         /*   retry with TCP */
352
353 /* other errors */
354 #define KRB_ERR_GENERIC         60      /* Generic error (description */
355                                         /* in e-text) */
356 #define KRB_ERR_FIELD_TOOLONG   61      /* Field is too long for impl. */
357
358 /* PKINIT server-reported errors */
359 #define KDC_ERR_CLIENT_NOT_TRUSTED              62 /* client cert not trusted */
360 #define KDC_ERR_KDC_NOT_TRUSTED                 63
361 #define KDC_ERR_INVALID_SIG                     64 /* client signature verify failed */
362 #define KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED  65 /* invalid Diffie-Hellman parameters */
363 #define KDC_ERR_CERTIFICATE_MISMATCH            66
364 #define KRB_AP_ERR_NO_TGT                       67
365 #define KDC_ERR_WRONG_REALM                     68
366 #define KRB_AP_ERR_USER_TO_USER_REQUIRED        69
367 #define KDC_ERR_CANT_VERIFY_CERTIFICATE         70 /* client cert not verifiable to */
368                                                    /* trusted root cert */
369 #define KDC_ERR_INVALID_CERTIFICATE             71 /* client cert had invalid signature */
370 #define KDC_ERR_REVOKED_CERTIFICATE             72 /* client cert was revoked */
371 #define KDC_ERR_REVOCATION_STATUS_UNKNOWN       73 /* client cert revoked, reason unknown */
372 #define KDC_ERR_REVOCATION_STATUS_UNAVAILABLE   74
373 #define KDC_ERR_CLIENT_NAME_MISMATCH            75 /* mismatch between client cert and */
374                                                    /* principal name */
375 #define KDC_ERR_INCONSISTENT_KEY_PURPOSE        77 /* bad extended key use */
376 #define KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED     78 /* bad digest algorithm in client cert */
377 #define KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED    79 /* missing paChecksum in PA-PK-AS-REQ */
378 #define KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED 80 /* bad digest algorithm in SignedData */
379 #define KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED 81
380 #define KRB_AP_ERR_IAKERB_KDC_NOT_FOUND         85 /* The IAKERB proxy could
381                                                       not find a KDC */
382 #define KRB_AP_ERR_IAKERB_KDC_NO_RESPONSE       86 /* The KDC did not respond
383                                                       to the IAKERB proxy */
384 #define KRB_ERR_MAX 127 /* err table base max offset for protocol err codes */
385
386 /*
387  * A null-terminated array of this structure is returned by the KDC as
388  * the data part of the ETYPE_INFO preauth type.  It informs the
389  * client which encryption types are supported.
390  * The  same data structure is used by both etype-info and etype-info2
391  * but s2kparams must be null when encoding etype-info.
392  */
393 typedef struct _krb5_etype_info_entry {
394     krb5_magic      magic;
395     krb5_enctype    etype;
396     unsigned int    length;
397     krb5_octet      *salt;
398     krb5_data s2kparams;
399 } krb5_etype_info_entry;
400
401 /*
402  *  This is essentially -1 without sign extension which can screw up
403  *  comparisons on 64 bit machines. If the length is this value, then
404  *  the salt data is not present. This is to distinguish between not
405  *  being set and being of 0 length.
406  */
407 #define KRB5_ETYPE_NO_SALT VALID_UINT_BITS
408
409 typedef krb5_etype_info_entry ** krb5_etype_info;
410
411 /* RFC 4537 */
412 typedef struct _krb5_etype_list {
413     int             length;
414     krb5_enctype    *etypes;
415 } krb5_etype_list;
416
417 /* sam_type values -- informational only */
418 #define PA_SAM_TYPE_ENIGMA     1   /*  Enigma Logic */
419 #define PA_SAM_TYPE_DIGI_PATH  2   /*  Digital Pathways */
420 #define PA_SAM_TYPE_SKEY_K0    3   /*  S/key where  KDC has key 0 */
421 #define PA_SAM_TYPE_SKEY       4   /*  Traditional S/Key */
422 #define PA_SAM_TYPE_SECURID    5   /*  Security Dynamics */
423 #define PA_SAM_TYPE_CRYPTOCARD 6   /*  CRYPTOCard */
424 #if 1 /* XXX need to figure out who has which numbers assigned */
425 #define PA_SAM_TYPE_ACTIVCARD_DEC  6   /*  ActivCard decimal mode */
426 #define PA_SAM_TYPE_ACTIVCARD_HEX  7   /*  ActivCard hex mode */
427 #define PA_SAM_TYPE_DIGI_PATH_HEX  8   /*  Digital Pathways hex mode */
428 #endif
429 #define PA_SAM_TYPE_EXP_BASE    128 /* experimental */
430 #define PA_SAM_TYPE_GRAIL               (PA_SAM_TYPE_EXP_BASE+0) /* testing */
431 #define PA_SAM_TYPE_SECURID_PREDICT     (PA_SAM_TYPE_EXP_BASE+1) /* special */
432
433 typedef struct _krb5_sam_challenge_2 {
434     krb5_data       sam_challenge_2_body;
435     krb5_checksum   **sam_cksum;            /* Array of checksums */
436 } krb5_sam_challenge_2;
437
438 typedef struct _krb5_sam_challenge_2_body {
439     krb5_magic      magic;
440     krb5_int32      sam_type; /* information */
441     krb5_flags      sam_flags; /* KRB5_SAM_* values */
442     krb5_data       sam_type_name;
443     krb5_data       sam_track_id;
444     krb5_data       sam_challenge_label;
445     krb5_data       sam_challenge;
446     krb5_data       sam_response_prompt;
447     krb5_data       sam_pk_for_sad;
448     krb5_int32      sam_nonce;
449     krb5_enctype    sam_etype;
450 } krb5_sam_challenge_2_body;
451
452 typedef struct _krb5_sam_response_2 {
453     krb5_magic      magic;
454     krb5_int32      sam_type; /* informational */
455     krb5_flags      sam_flags; /* KRB5_SAM_* values */
456     krb5_data       sam_track_id; /* copied */
457     krb5_enc_data   sam_enc_nonce_or_sad; /* krb5_enc_sam_response_enc */
458     krb5_int32      sam_nonce;
459 } krb5_sam_response_2;
460
461 typedef struct _krb5_enc_sam_response_enc_2 {
462     krb5_magic      magic;
463     krb5_int32      sam_nonce;
464     krb5_data       sam_sad;
465 } krb5_enc_sam_response_enc_2;
466
467 /*
468  * Keep the pkinit definitions in a separate file so that the plugin
469  * only has to include k5-int-pkinit.h rather than k5-int.h
470  */
471
472 #include "k5-int-pkinit.h"
473
474 #define KRB5_OTP_FLAG_NEXTOTP        0x40000000
475 #define KRB5_OTP_FLAG_COMBINE        0x20000000
476 #define KRB5_OTP_FLAG_COLLECT_PIN    0x10000000
477 #define KRB5_OTP_FLAG_NO_COLLECT_PIN 0x08000000
478 #define KRB5_OTP_FLAG_ENCRYPT_NONCE  0x04000000
479 #define KRB5_OTP_FLAG_SEPARATE_PIN   0x02000000
480 #define KRB5_OTP_FLAG_CHECK_DIGIT    0x01000000
481
482 #define KRB5_OTP_FORMAT_DECIMAL      0x00000000
483 #define KRB5_OTP_FORMAT_HEXADECIMAL  0x00000001
484 #define KRB5_OTP_FORMAT_ALPHANUMERIC 0x00000002
485 #define KRB5_OTP_FORMAT_BINARY       0x00000003
486 #define KRB5_OTP_FORMAT_BASE64       0x00000004
487
488 typedef struct _krb5_otp_tokeninfo {
489     krb5_flags flags;
490     krb5_data vendor;
491     krb5_data challenge;
492     krb5_int32 length;          /* -1 for unspecified */
493     krb5_int32 format;          /* -1 for unspecified */
494     krb5_data token_id;
495     krb5_data alg_id;
496     krb5_algorithm_identifier **supported_hash_alg;
497     krb5_int32 iteration_count; /* -1 for unspecified */
498 } krb5_otp_tokeninfo;
499
500 typedef struct _krb5_pa_otp_challenge {
501     krb5_data nonce;
502     krb5_data service;
503     krb5_otp_tokeninfo **tokeninfo;
504     krb5_data salt;
505     krb5_data s2kparams;
506 } krb5_pa_otp_challenge;
507
508 typedef struct _krb5_pa_otp_req {
509     krb5_int32 flags;
510     krb5_data nonce;
511     krb5_enc_data enc_data;
512     krb5_algorithm_identifier *hash_alg;
513     krb5_int32 iteration_count; /* -1 for unspecified */
514     krb5_data otp_value;
515     krb5_data pin;
516     krb5_data challenge;
517     krb5_timestamp time;
518     krb5_data counter;
519     krb5_int32 format;          /* -1 for unspecified */
520     krb5_data token_id;
521     krb5_data alg_id;
522     krb5_data vendor;
523 } krb5_pa_otp_req;
524
525 #include <stdlib.h>
526 #include <string.h>
527
528 #ifndef HAVE_STRDUP
529 extern char *strdup (const char *);
530 #endif
531
532 #ifdef HAVE_UNISTD_H
533 #include <unistd.h>
534 #endif
535
536 #ifdef HAVE_SYS_TIME_H
537 #include <sys/time.h>
538 #ifdef TIME_WITH_SYS_TIME
539 #include <time.h>
540 #endif
541 #else
542 #include <time.h>
543 #endif
544
545 #ifdef HAVE_SYS_STAT_H
546 #include <sys/stat.h>                   /* struct stat, stat() */
547 #endif
548
549 #ifdef HAVE_SYS_PARAM_H
550 #include <sys/param.h>                  /* MAXPATHLEN */
551 #endif
552
553 #ifdef HAVE_SYS_FILE_H
554 #include <sys/file.h>                   /* prototypes for file-related
555                                            syscalls; flags for open &
556                                            friends */
557 #endif
558
559 #ifdef HAVE_FCNTL_H
560 #include <fcntl.h>
561 #endif
562
563 #include <stdio.h>
564
565 #include "k5-gmt_mktime.h"
566
567 /* libos.spec */
568 krb5_error_code krb5_lock_file(krb5_context, int, int);
569 krb5_error_code krb5_unlock_file(krb5_context, int);
570 krb5_error_code krb5_sendto_kdc(krb5_context, const krb5_data *,
571                                 const krb5_data *, krb5_data *, int *, int);
572
573 krb5_error_code krb5int_init_context_kdc(krb5_context *);
574
575 struct derived_key {
576     krb5_data constant;
577     krb5_key dkey;
578     struct derived_key *next;
579 };
580
581 /* Internal structure of an opaque key identifier */
582 struct krb5_key_st {
583     krb5_keyblock keyblock;
584     int refcount;
585     struct derived_key *derived;
586     /*
587      * Cache of data private to the cipher implementation, which we
588      * don't want to have to recompute for every operation.  This may
589      * include key schedules, iteration counts, etc.
590      *
591      * The cipher implementation is responsible for setting this up
592      * whenever needed, and the enc_provider key_cleanup method must
593      * then be provided to dispose of it.
594      */
595     void *cache;
596 };
597
598 krb5_error_code
599 krb5int_arcfour_gsscrypt(const krb5_keyblock *keyblock, krb5_keyusage usage,
600                          const krb5_data *kd_data, krb5_crypto_iov *data,
601                          size_t num_data);
602
603 /*
604  * Attempt to zero memory in a way that compilers won't optimize out.
605  *
606  * This mechanism should work even for heap storage about to be freed,
607  * or automatic storage right before we return from a function.
608  *
609  * Then, even if we leak uninitialized memory someplace, or UNIX
610  * "core" files get created with world-read access, some of the most
611  * sensitive data in the process memory will already be safely wiped.
612  *
613  * We're not going so far -- yet -- as to try to protect key data that
614  * may have been written into swap space....
615  */
616 #ifdef _WIN32
617 # define zap(ptr, len) SecureZeroMemory(ptr, len)
618 #elif defined(__GNUC__)
619 static inline void zap(void *ptr, size_t len)
620 {
621     memset(ptr, 0, len);
622     /*
623      * Some versions of gcc have gotten clever enough to eliminate a
624      * memset call right before the block in question is released.
625      * This (empty) asm requires it to assume that we're doing
626      * something interesting with the stored (zero) value, so the
627      * memset can't be eliminated.
628      *
629      * An optimizer that looks at assembly or object code may not be
630      * fooled, and may still cause the memset to go away.  Address
631      * that problem if and when we encounter it.
632      *
633      * This also may not be enough if free() does something
634      * interesting like purge memory locations from a write-back cache
635      * that hasn't written back the zero bytes yet.  A memory barrier
636      * instruction would help in that case.
637      */
638     asm volatile ("" : : "g" (ptr), "g" (len));
639 }
640 #else
641 /* Use a function from libkrb5support to defeat inlining. */
642 # define zap(ptr, len) krb5int_zap(ptr, len)
643 #endif
644
645 /* Convenience function: zap and free ptr if it is non-NULL. */
646 static inline void
647 zapfree(void *ptr, size_t len)
648 {
649     if (ptr != NULL) {
650         zap(ptr, len);
651         free(ptr);
652     }
653 }
654
655 /* Convenience function: zap and free zero-terminated str if it is non-NULL. */
656 static inline void
657 zapfreestr(void *str)
658 {
659     if (str != NULL) {
660         zap(str, strlen((char *)str));
661         free(str);
662     }
663 }
664
665 /*
666  * Combine two keys (normally used by the hardware preauth mechanism)
667  */
668 krb5_error_code
669 krb5int_c_combine_keys(krb5_context context, krb5_keyblock *key1,
670                        krb5_keyblock *key2, krb5_keyblock *outkey);
671
672 void krb5int_c_free_keyblock(krb5_context, krb5_keyblock *key);
673 void krb5int_c_free_keyblock_contents(krb5_context, krb5_keyblock *);
674 krb5_error_code krb5int_c_init_keyblock(krb5_context, krb5_enctype enctype,
675                                         size_t length, krb5_keyblock **out);
676 krb5_error_code krb5int_c_copy_keyblock(krb5_context context,
677                                         const krb5_keyblock *from,
678                                         krb5_keyblock **to);
679 krb5_error_code krb5int_c_copy_keyblock_contents(krb5_context context,
680                                                  const krb5_keyblock *from,
681                                                  krb5_keyblock *to);
682
683 krb5_error_code krb5_crypto_us_timeofday(krb5_int32 *, krb5_int32 *);
684
685 /*
686  * End "los-proto.h"
687  */
688
689 typedef struct _krb5_os_context {
690     krb5_magic              magic;
691     krb5_int32              time_offset;
692     krb5_int32              usec_offset;
693     krb5_int32              os_flags;
694     char *                  default_ccname;
695 } *krb5_os_context;
696
697 /*
698  * Flags for the os_flags field
699  *
700  * KRB5_OS_TOFFSET_VALID means that the time offset fields are valid.
701  * The intention is that this facility to correct the system clocks so
702  * that they reflect the "real" time, for systems where for some
703  * reason we can't set the system clock.  Instead we calculate the
704  * offset between the system time and real time, and store the offset
705  * in the os context so that we can correct the system clock as necessary.
706  *
707  * KRB5_OS_TOFFSET_TIME means that the time offset fields should be
708  * returned as the time by the krb5 time routines.  This should only
709  * be used for testing purposes (obviously!)
710  */
711 #define KRB5_OS_TOFFSET_VALID   1
712 #define KRB5_OS_TOFFSET_TIME    2
713
714 /* lock mode flags */
715 #define KRB5_LOCKMODE_SHARED    0x0001
716 #define KRB5_LOCKMODE_EXCLUSIVE 0x0002
717 #define KRB5_LOCKMODE_DONTBLOCK 0x0004
718 #define KRB5_LOCKMODE_UNLOCK    0x0008
719
720 /*
721  * Begin "preauth.h"
722  *
723  * (Originally written by Glen Machin at Sandia Labs.)
724  */
725 /*
726  * Sandia National Laboratories also makes no representations about the
727  * suitability of the modifications, or additions to this software for
728  * any purpose.  It is provided "as is" without express or implied warranty.
729  */
730 #ifndef KRB5_PREAUTH__
731 #define KRB5_PREAUTH__
732
733 typedef struct _krb5_pa_enc_ts {
734     krb5_timestamp      patimestamp;
735     krb5_int32          pausec;
736 } krb5_pa_enc_ts;
737
738 typedef struct _krb5_pa_for_user {
739     krb5_principal      user;
740     krb5_checksum       cksum;
741     krb5_data           auth_package;
742 } krb5_pa_for_user;
743
744 typedef struct _krb5_s4u_userid {
745     krb5_int32          nonce;
746     krb5_principal      user;
747     krb5_data           subject_cert;
748     krb5_flags          options;
749 } krb5_s4u_userid;
750
751 #define KRB5_S4U_OPTS_CHECK_LOGON_HOURS         0x40000000 /* check logon hour restrictions */
752 #define KRB5_S4U_OPTS_USE_REPLY_KEY_USAGE       0x20000000 /* sign with usage 27 instead of 26 */
753
754 typedef struct _krb5_pa_s4u_x509_user {
755     krb5_s4u_userid     user_id;
756     krb5_checksum       cksum;
757 } krb5_pa_s4u_x509_user;
758
759 enum {
760     KRB5_FAST_ARMOR_AP_REQUEST = 0x1
761 };
762
763 typedef struct _krb5_fast_armor {
764     krb5_int32 armor_type;
765     krb5_data armor_value;
766 } krb5_fast_armor;
767 typedef struct _krb5_fast_armored_req {
768     krb5_magic magic;
769     krb5_fast_armor *armor;
770     krb5_checksum req_checksum;
771     krb5_enc_data enc_part;
772 } krb5_fast_armored_req;
773
774 typedef struct _krb5_fast_req {
775     krb5_magic magic;
776     krb5_flags fast_options;
777     /* padata from req_body is used*/
778     krb5_kdc_req *req_body;
779 } krb5_fast_req;
780
781 /* Bits 0-15 are critical in FAST options (RFC 6113 section 7.3). */
782 #define UNSUPPORTED_CRITICAL_FAST_OPTIONS   0xbfff0000
783 #define KRB5_FAST_OPTION_HIDE_CLIENT_NAMES  0x40000000
784
785 typedef struct _krb5_fast_finished {
786     krb5_timestamp timestamp;
787     krb5_int32 usec;
788     krb5_principal client;
789     krb5_checksum ticket_checksum;
790 } krb5_fast_finished;
791
792 typedef struct _krb5_fast_response {
793     krb5_magic magic;
794     krb5_pa_data **padata;
795     krb5_keyblock *strengthen_key;
796     krb5_fast_finished *finished;
797     krb5_int32 nonce;
798 } krb5_fast_response;
799
800 typedef struct _krb5_ad_kdcissued {
801     krb5_checksum ad_checksum;
802     krb5_principal i_principal;
803     krb5_authdata **elements;
804 } krb5_ad_kdcissued;
805
806 typedef struct _krb5_ad_signedpath_data {
807     krb5_principal client;
808     krb5_timestamp authtime;
809     krb5_principal *delegated;
810     krb5_pa_data **method_data;
811     krb5_authdata **authorization_data;
812 } krb5_ad_signedpath_data;
813
814 typedef struct _krb5_ad_signedpath {
815     krb5_enctype enctype;
816     krb5_checksum checksum;
817     krb5_principal *delegated;
818     krb5_pa_data **method_data;
819 } krb5_ad_signedpath;
820
821 typedef struct _krb5_iakerb_header {
822     krb5_data target_realm;
823     krb5_data *cookie;
824 } krb5_iakerb_header;
825
826 typedef struct _krb5_iakerb_finished {
827     krb5_checksum checksum;
828 } krb5_iakerb_finished;
829
830 krb5_pa_data *
831 krb5int_find_pa_data(krb5_context, krb5_pa_data *const *, krb5_preauthtype);
832 /* Does not return a copy; original padata sequence responsible for freeing*/
833
834 void krb5_free_etype_info(krb5_context, krb5_etype_info);
835
836 #endif /* KRB5_PREAUTH__ */
837 /*
838  * End "preauth.h"
839  */
840
841 krb5_error_code
842 krb5int_copy_data_contents(krb5_context, const krb5_data *, krb5_data *);
843
844 krb5_error_code
845 krb5int_copy_data_contents_add0(krb5_context, const krb5_data *, krb5_data *);
846
847 void KRB5_CALLCONV
848 krb5_free_sam_challenge_2(krb5_context, krb5_sam_challenge_2 *);
849
850 void KRB5_CALLCONV
851 krb5_free_sam_challenge_2_body(krb5_context, krb5_sam_challenge_2_body *);
852
853 void KRB5_CALLCONV
854 krb5_free_sam_response_2(krb5_context, krb5_sam_response_2 *);
855
856 void KRB5_CALLCONV
857 krb5_free_enc_sam_response_enc_2(krb5_context, krb5_enc_sam_response_enc_2 *);
858
859 void KRB5_CALLCONV
860 krb5_free_sam_challenge_2_contents(krb5_context, krb5_sam_challenge_2 *);
861
862 void KRB5_CALLCONV
863 krb5_free_sam_challenge_2_body_contents(krb5_context,
864                                         krb5_sam_challenge_2_body *);
865
866 void KRB5_CALLCONV
867 krb5_free_sam_response_2_contents(krb5_context, krb5_sam_response_2 *);
868
869 void KRB5_CALLCONV
870 krb5_free_enc_sam_response_enc_2_contents(krb5_context,
871                                           krb5_enc_sam_response_enc_2 * );
872
873 void KRB5_CALLCONV
874 krb5_free_pa_enc_ts(krb5_context, krb5_pa_enc_ts *);
875
876 void KRB5_CALLCONV
877 krb5_free_pa_for_user(krb5_context, krb5_pa_for_user *);
878
879 void KRB5_CALLCONV
880 krb5_free_s4u_userid_contents(krb5_context, krb5_s4u_userid *);
881
882 void KRB5_CALLCONV
883 krb5_free_pa_s4u_x509_user(krb5_context, krb5_pa_s4u_x509_user *);
884
885 void KRB5_CALLCONV
886 krb5_free_pa_pac_req(krb5_context, krb5_pa_pac_req * );
887
888 void KRB5_CALLCONV krb5_free_fast_armor(krb5_context, krb5_fast_armor *);
889 void KRB5_CALLCONV krb5_free_fast_armored_req(krb5_context,
890                                               krb5_fast_armored_req *);
891 void KRB5_CALLCONV krb5_free_fast_req(krb5_context, krb5_fast_req *);
892 void KRB5_CALLCONV krb5_free_fast_finished(krb5_context, krb5_fast_finished *);
893 void KRB5_CALLCONV krb5_free_fast_response(krb5_context, krb5_fast_response *);
894 void KRB5_CALLCONV krb5_free_ad_kdcissued(krb5_context, krb5_ad_kdcissued *);
895 void KRB5_CALLCONV krb5_free_ad_signedpath(krb5_context, krb5_ad_signedpath *);
896 void KRB5_CALLCONV krb5_free_iakerb_header(krb5_context, krb5_iakerb_header *);
897 void KRB5_CALLCONV krb5_free_iakerb_finished(krb5_context,
898                                              krb5_iakerb_finished *);
899 void k5_free_algorithm_identifier(krb5_context context,
900                                   krb5_algorithm_identifier *val);
901 void k5_free_otp_tokeninfo(krb5_context context, krb5_otp_tokeninfo *val);
902 void k5_free_pa_otp_challenge(krb5_context context,
903                               krb5_pa_otp_challenge *val);
904 void k5_free_pa_otp_req(krb5_context context, krb5_pa_otp_req *val);
905
906 /* #include "krb5/wordsize.h" -- comes in through base-defs.h. */
907 #include "com_err.h"
908 #include "k5-plugin.h"
909
910 #include <krb5/authdata_plugin.h>
911
912 struct _krb5_authdata_context {
913     krb5_magic magic;
914     int n_modules;
915     struct _krb5_authdata_context_module {
916         krb5_authdatatype ad_type;
917         void *plugin_context;
918         authdata_client_plugin_fini_proc client_fini;
919         krb5_flags flags;
920         krb5plugin_authdata_client_ftable_v0 *ftable;
921         authdata_client_request_init_proc client_req_init;
922         authdata_client_request_fini_proc client_req_fini;
923         const char *name;
924         void *request_context;
925         void **request_context_pp;
926     } *modules;
927     struct plugin_dir_handle plugins;
928 };
929
930 typedef struct _krb5_authdata_context *krb5_authdata_context;
931
932 void KRB5_CALLCONV
933 krb5int_free_data_list(krb5_context context, krb5_data *data);
934
935 krb5_error_code KRB5_CALLCONV
936 krb5_authdata_context_init(krb5_context kcontext,
937                            krb5_authdata_context *pcontext);
938
939 void KRB5_CALLCONV
940 krb5_authdata_context_free(krb5_context kcontext,
941                            krb5_authdata_context context);
942
943 krb5_error_code KRB5_CALLCONV
944 krb5_authdata_export_authdata(krb5_context kcontext,
945                               krb5_authdata_context context, krb5_flags usage,
946                               krb5_authdata ***pauthdata);
947
948 krb5_error_code KRB5_CALLCONV
949 krb5_authdata_get_attribute_types(krb5_context kcontext,
950                                   krb5_authdata_context context,
951                                   krb5_data **attrs);
952
953 krb5_error_code KRB5_CALLCONV
954 krb5_authdata_get_attribute(krb5_context kcontext,
955                             krb5_authdata_context context,
956                             const krb5_data *attribute,
957                             krb5_boolean *authenticated,
958                             krb5_boolean *complete, krb5_data *value,
959                             krb5_data *display_value, int *more);
960
961 krb5_error_code KRB5_CALLCONV
962 krb5_authdata_set_attribute(krb5_context kcontext,
963                             krb5_authdata_context context,
964                             krb5_boolean complete, const krb5_data *attribute,
965                             const krb5_data *value);
966
967 krb5_error_code KRB5_CALLCONV
968 krb5_authdata_delete_attribute(krb5_context kcontext,
969                                krb5_authdata_context context,
970                                const krb5_data *attribute);
971
972 krb5_error_code KRB5_CALLCONV
973 krb5_authdata_import_attributes(krb5_context kcontext,
974                                 krb5_authdata_context context,
975                                 krb5_flags usage, const krb5_data *attributes);
976
977 krb5_error_code KRB5_CALLCONV
978 krb5_authdata_export_attributes(krb5_context kcontext,
979                                 krb5_authdata_context context,
980                                 krb5_flags usage, krb5_data **pattributes);
981
982 krb5_error_code KRB5_CALLCONV
983 krb5_authdata_export_internal(krb5_context kcontext,
984                               krb5_authdata_context context,
985                               krb5_boolean restrict_authenticated,
986                               const char *module, void **ptr);
987
988 krb5_error_code KRB5_CALLCONV
989 krb5_authdata_context_copy(krb5_context kcontext, krb5_authdata_context src,
990                            krb5_authdata_context *dst);
991
992 krb5_error_code KRB5_CALLCONV
993 krb5_authdata_free_internal(krb5_context kcontext,
994                             krb5_authdata_context context, const char *module,
995                             void *ptr);
996
997 /*** Plugin framework ***/
998
999 /*
1000  * This framework can be used to create pluggable interfaces.  Not all existing
1001  * pluggable interface use this framework, but new ones should.  A new
1002  * pluggable interface entails:
1003  *
1004  * - An interface ID definition in the list of #defines below.
1005  *
1006  * - A name in the interface_names array in lib/krb5/krb/plugins.c.
1007  *
1008  * - An installed public header file in include/krb5.  The public header should
1009  *   include <krb5/plugin.h> and should declare a vtable structure for each
1010  *   supported major version of the interface.
1011  *
1012  * - A consumer API implementation, located within the code unit which makes
1013  *   use of the pluggable interface.  The consumer API should consist of:
1014  *
1015  *   . An interface-specific handle type which contains a vtable structure for
1016  *     the module (or a union of several such structures, if there are multiple
1017  *     supported major versions) and, optionally, resource data bound to the
1018  *     handle.
1019  *
1020  *   . An interface-specific loader function which creates a handle or list of
1021  *     handles.  A list of handles would be created if the interface is a
1022  *     one-to-many interface where the consumer wants to consult all available
1023  *     modules; a single handle would be created for an interface where the
1024  *     consumer wants to consult a specific module.  The loader function should
1025  *     use k5_plugin_load or k5_plugin_load_all to produce one or a list of
1026  *     vtable initializer functions, and should use those functions to fill in
1027  *     the vtable structure for the module (if necessary, trying each supported
1028  *     major version starting from the most recent).  The loader function can
1029  *     also bind resource data into the handle based on caller arguments, if
1030  *     appropriate.
1031  *
1032  *   . For each plugin method, a wrapper function which accepts a krb5_context,
1033  *     a plugin handle, and the method arguments.  Wrapper functions should
1034  *     invoke the method function contained in the handle's vtable.
1035  *
1036  * - Possibly, built-in implementations of the interface, also located within
1037  *   the code unit which makes use of the interface.  Built-in implementations
1038  *   must be registered with k5_plugin_register before the first call to
1039  *   k5_plugin_load or k5_plugin_load_all.
1040  *
1041  * A pluggable interface should have one or more currently supported major
1042  * versions, starting at 1.  Each major version should have a current minor
1043  * version, also starting at 1.  If new methods are added to a vtable, the
1044  * minor version should be incremented and the vtable stucture should document
1045  * where each minor vtable version ends.  If method signatures for a vtable are
1046  * changed, the major version should be incremented.
1047  *
1048  * Plugin module implementations (either built-in or dynamically loaded) should
1049  * define a function named <interfacename>_<modulename>_initvt, matching the
1050  * signature of krb5_plugin_initvt_fn as declared in include/krb5/plugin.h.
1051  * The initvt function should check the given maj_ver argument against its own
1052  * supported major versions, cast the vtable pointer to the appropriate
1053  * interface-specific vtable type, and fill in the vtable methods, stopping as
1054  * appropriate for the given min_ver.  Memory for the vtable structure is
1055  * allocated by the caller, not by the module.
1056  *
1057  * Dynamic plugin modules are registered with the framework through the
1058  * [plugins] section of the profile, as described in the admin documentation
1059  * and krb5.conf man page.
1060  */
1061
1062 struct plugin_mapping;
1063
1064 /* Holds krb5_context information about each pluggable interface. */
1065 struct plugin_interface {
1066     struct plugin_mapping **modules;
1067     krb5_boolean configured;
1068 };
1069
1070 /* A list of plugin interface IDs.  Make sure to increment
1071  * PLUGIN_NUM_INTERFACES when a new interface is added, and add an entry to the
1072  * interface_names table in lib/krb5/krb/plugin.c. */
1073 #define PLUGIN_INTERFACE_PWQUAL      0
1074 #define PLUGIN_INTERFACE_KADM5_HOOK  1
1075 #define PLUGIN_INTERFACE_CLPREAUTH   2
1076 #define PLUGIN_INTERFACE_KDCPREAUTH  3
1077 #define PLUGIN_INTERFACE_CCSELECT    4
1078 #define PLUGIN_INTERFACE_LOCALAUTH   5
1079 #define PLUGIN_INTERFACE_HOSTREALM   6
1080 #define PLUGIN_INTERFACE_AUDIT       7
1081 #define PLUGIN_NUM_INTERFACES        8
1082
1083 /* Retrieve the plugin module of type interface_id and name modname,
1084  * storing the result into module. */
1085 krb5_error_code
1086 k5_plugin_load(krb5_context context, int interface_id, const char *modname,
1087                krb5_plugin_initvt_fn *module);
1088
1089 /* Retrieve all plugin modules of type interface_id, storing the result
1090  * into modules.  Free the result with k5_plugin_free_handles. */
1091 krb5_error_code
1092 k5_plugin_load_all(krb5_context context, int interface_id,
1093                    krb5_plugin_initvt_fn **modules);
1094
1095 /* Release a module list allocated by k5_plugin_load_all. */
1096 void
1097 k5_plugin_free_modules(krb5_context context, krb5_plugin_initvt_fn *modules);
1098
1099 /* Register a plugin module of type interface_id and name modname. */
1100 krb5_error_code
1101 k5_plugin_register(krb5_context context, int interface_id, const char *modname,
1102                    krb5_plugin_initvt_fn module);
1103
1104 /*
1105  * Register a plugin module which is part of the krb5 tree but is built as a
1106  * dynamic plugin.  Look for the module in modsubdir relative to the
1107  * context->base_plugin_dir.
1108  */
1109 krb5_error_code
1110 k5_plugin_register_dyn(krb5_context context, int interface_id,
1111                        const char *modname, const char *modsubdir);
1112
1113 /* Destroy the module state within context; used by krb5_free_context. */
1114 void
1115 k5_plugin_free_context(krb5_context context);
1116
1117 struct _kdb5_dal_handle;        /* private, in kdb5.h */
1118 typedef struct _kdb5_dal_handle kdb5_dal_handle;
1119 struct _kdb_log_context;
1120 typedef struct krb5_preauth_context_st krb5_preauth_context;
1121 struct ccselect_module_handle;
1122 struct localauth_module_handle;
1123 struct hostrealm_module_handle;
1124 struct _krb5_context {
1125     krb5_magic      magic;
1126     krb5_enctype    *in_tkt_etypes;
1127     krb5_enctype    *tgs_etypes;
1128     struct _krb5_os_context os_context;
1129     char            *default_realm;
1130     profile_t       profile;
1131     kdb5_dal_handle *dal_handle;
1132     int             ser_ctx_count;
1133     void            *ser_ctx;
1134     /* allowable clock skew */
1135     krb5_deltat     clockskew;
1136     krb5_cksumtype  kdc_req_sumtype;
1137     krb5_cksumtype  default_ap_req_sumtype;
1138     krb5_cksumtype  default_safe_sumtype;
1139     krb5_flags      kdc_default_options;
1140     krb5_flags      library_options;
1141     krb5_boolean    profile_secure;
1142     int             fcc_default_format;
1143     krb5_prompt_type *prompt_types;
1144     /* Message size above which we'll try TCP first in send-to-kdc
1145        type code.  Aside from the 2**16 size limit, we put no
1146        absolute limit on the UDP packet size.  */
1147     int             udp_pref_limit;
1148
1149     /* Use the config-file ktypes instead of app-specified?  */
1150     krb5_boolean    use_conf_ktypes;
1151
1152     /* locate_kdc module stuff */
1153     struct plugin_dir_handle libkrb5_plugins;
1154     struct krb5plugin_service_locate_ftable *vtbl;
1155     void (**locate_fptrs)(void);
1156
1157     /* preauth module stuff */
1158     krb5_preauth_context *preauth_context;
1159
1160     /* cache module stuff */
1161     struct ccselect_module_handle **ccselect_handles;
1162
1163     /* localauth module stuff */
1164     struct localauth_module_handle **localauth_handles;
1165
1166     /* hostrealm module stuff */
1167     struct hostrealm_module_handle **hostrealm_handles;
1168
1169     /* error detail info */
1170     struct errinfo err;
1171
1172     /* For Sun iprop code; does this really have to be here?  */
1173     struct _kdb_log_context *kdblog_context;
1174
1175     krb5_boolean allow_weak_crypto;
1176     krb5_boolean ignore_acceptor_hostname;
1177     krb5_boolean dns_canonicalize_hostname;
1178
1179     krb5_trace_callback trace_callback;
1180     void *trace_callback_data;
1181
1182     struct plugin_interface plugins[PLUGIN_NUM_INTERFACES];
1183     char *plugin_base_dir;
1184 };
1185
1186 /* could be used in a table to find an etype and initialize a block */
1187
1188
1189 #define KRB5_LIBOPT_SYNC_KDCTIME        0x0001
1190
1191 /* internal message representations */
1192
1193 typedef struct _krb5_safe {
1194     krb5_magic magic;
1195     krb5_data user_data;                /* user data */
1196     krb5_timestamp timestamp;           /* client time, optional */
1197     krb5_int32 usec;                    /* microsecond portion of time,
1198                                            optional */
1199     krb5_ui_4 seq_number;               /* sequence #, optional */
1200     krb5_address *s_address;    /* sender address */
1201     krb5_address *r_address;    /* recipient address, optional */
1202     krb5_checksum *checksum;    /* data integrity checksum */
1203 } krb5_safe;
1204
1205 typedef struct _krb5_priv {
1206     krb5_magic magic;
1207     krb5_enc_data enc_part;             /* encrypted part */
1208 } krb5_priv;
1209
1210 typedef struct _krb5_priv_enc_part {
1211     krb5_magic magic;
1212     krb5_data user_data;                /* user data */
1213     krb5_timestamp timestamp;           /* client time, optional */
1214     krb5_int32 usec;                    /* microsecond portion of time, opt. */
1215     krb5_ui_4 seq_number;               /* sequence #, optional */
1216     krb5_address *s_address;    /* sender address */
1217     krb5_address *r_address;    /* recipient address, optional */
1218 } krb5_priv_enc_part;
1219
1220 void KRB5_CALLCONV krb5_free_safe(krb5_context, krb5_safe *);
1221 void KRB5_CALLCONV krb5_free_priv(krb5_context, krb5_priv *);
1222 void KRB5_CALLCONV krb5_free_priv_enc_part(krb5_context, krb5_priv_enc_part *);
1223
1224 /*
1225  * Begin "asn1.h"
1226  */
1227 #ifndef KRB5_ASN1__
1228 #define KRB5_ASN1__
1229
1230 /* ASN.1 encoding knowledge; KEEP IN SYNC WITH ASN.1 defs! */
1231 /* here we use some knowledge of ASN.1 encodings */
1232 /*
1233   Ticket is APPLICATION 1.
1234   Authenticator is APPLICATION 2.
1235   AS_REQ is APPLICATION 10.
1236   AS_REP is APPLICATION 11.
1237   TGS_REQ is APPLICATION 12.
1238   TGS_REP is APPLICATION 13.
1239   AP_REQ is APPLICATION 14.
1240   AP_REP is APPLICATION 15.
1241   KRB_SAFE is APPLICATION 20.
1242   KRB_PRIV is APPLICATION 21.
1243   KRB_CRED is APPLICATION 22.
1244   EncASRepPart is APPLICATION 25.
1245   EncTGSRepPart is APPLICATION 26.
1246   EncAPRepPart is APPLICATION 27.
1247   EncKrbPrivPart is APPLICATION 28.
1248   EncKrbCredPart is APPLICATION 29.
1249   KRB_ERROR is APPLICATION 30.
1250 */
1251 /* allow either constructed or primitive encoding, so check for bit 6
1252    set or reset */
1253 #define krb5int_is_app_tag(dat,tag)                     \
1254     ((dat != NULL) && (dat)->length &&                  \
1255      ((((dat)->data[0] & ~0x20) == ((tag) | 0x40))))
1256 #define krb5_is_krb_ticket(dat)               krb5int_is_app_tag(dat, 1)
1257 #define krb5_is_krb_authenticator(dat)        krb5int_is_app_tag(dat, 2)
1258 #define krb5_is_as_req(dat)                   krb5int_is_app_tag(dat, 10)
1259 #define krb5_is_as_rep(dat)                   krb5int_is_app_tag(dat, 11)
1260 #define krb5_is_tgs_req(dat)                  krb5int_is_app_tag(dat, 12)
1261 #define krb5_is_tgs_rep(dat)                  krb5int_is_app_tag(dat, 13)
1262 #define krb5_is_ap_req(dat)                   krb5int_is_app_tag(dat, 14)
1263 #define krb5_is_ap_rep(dat)                   krb5int_is_app_tag(dat, 15)
1264 #define krb5_is_krb_safe(dat)                 krb5int_is_app_tag(dat, 20)
1265 #define krb5_is_krb_priv(dat)                 krb5int_is_app_tag(dat, 21)
1266 #define krb5_is_krb_cred(dat)                 krb5int_is_app_tag(dat, 22)
1267 #define krb5_is_krb_enc_as_rep_part(dat)      krb5int_is_app_tag(dat, 25)
1268 #define krb5_is_krb_enc_tgs_rep_part(dat)     krb5int_is_app_tag(dat, 26)
1269 #define krb5_is_krb_enc_ap_rep_part(dat)      krb5int_is_app_tag(dat, 27)
1270 #define krb5_is_krb_enc_krb_priv_part(dat)    krb5int_is_app_tag(dat, 28)
1271 #define krb5_is_krb_enc_krb_cred_part(dat)    krb5int_is_app_tag(dat, 29)
1272 #define krb5_is_krb_error(dat)                krb5int_is_app_tag(dat, 30)
1273
1274 /*************************************************************************
1275  * Prototypes for krb5_encode.c
1276  *************************************************************************/
1277
1278 /*
1279   krb5_error_code encode_krb5_structure(const krb5_structure *rep,
1280   krb5_data **code);
1281   modifies  *code
1282   effects   Returns the ASN.1 encoding of *rep in **code.
1283   Returns ASN1_MISSING_FIELD if a required field is emtpy in *rep.
1284   Returns ENOMEM if memory runs out.
1285 */
1286
1287 krb5_error_code
1288 encode_krb5_authenticator(const krb5_authenticator *rep, krb5_data **code);
1289
1290 krb5_error_code
1291 encode_krb5_ticket(const krb5_ticket *rep, krb5_data **code);
1292
1293 krb5_error_code
1294 encode_krb5_enc_tkt_part(const krb5_enc_tkt_part *rep, krb5_data **code);
1295
1296 krb5_error_code
1297 encode_krb5_enc_kdc_rep_part(const krb5_enc_kdc_rep_part *rep,
1298                              krb5_data **code);
1299
1300 /* yes, the translation is identical to that used for KDC__REP */
1301 krb5_error_code
1302 encode_krb5_as_rep(const krb5_kdc_rep *rep, krb5_data **code);
1303
1304 /* yes, the translation is identical to that used for KDC__REP */
1305 krb5_error_code
1306 encode_krb5_tgs_rep(const krb5_kdc_rep *rep, krb5_data **code);
1307
1308 krb5_error_code
1309 encode_krb5_ap_req(const krb5_ap_req *rep, krb5_data **code);
1310
1311 krb5_error_code
1312 encode_krb5_ap_rep(const krb5_ap_rep *rep, krb5_data **code);
1313
1314 krb5_error_code
1315 encode_krb5_ap_rep_enc_part(const krb5_ap_rep_enc_part *rep, krb5_data **code);
1316
1317 krb5_error_code
1318 encode_krb5_as_req(const krb5_kdc_req *rep, krb5_data **code);
1319
1320 krb5_error_code
1321 encode_krb5_tgs_req(const krb5_kdc_req *rep, krb5_data **code);
1322
1323 krb5_error_code
1324 encode_krb5_kdc_req_body(const krb5_kdc_req *rep, krb5_data **code);
1325
1326 krb5_error_code
1327 encode_krb5_safe(const krb5_safe *rep, krb5_data **code);
1328
1329 struct krb5_safe_with_body {
1330     krb5_safe *safe;
1331     krb5_data *body;
1332 };
1333 krb5_error_code
1334 encode_krb5_safe_with_body(const struct krb5_safe_with_body *rep,
1335                            krb5_data **code);
1336
1337 krb5_error_code
1338 encode_krb5_priv(const krb5_priv *rep, krb5_data **code);
1339
1340 krb5_error_code
1341 encode_krb5_enc_priv_part(const krb5_priv_enc_part *rep, krb5_data **code);
1342
1343 krb5_error_code
1344 encode_krb5_cred(const krb5_cred *rep, krb5_data **code);
1345 krb5_error_code
1346 encode_krb5_checksum(const krb5_checksum *, krb5_data **);
1347
1348 krb5_error_code
1349 encode_krb5_enc_cred_part(const krb5_cred_enc_part *rep, krb5_data **code);
1350
1351 krb5_error_code
1352 encode_krb5_error(const krb5_error *rep, krb5_data **code);
1353
1354 krb5_error_code
1355 encode_krb5_authdata(krb5_authdata *const *rep, krb5_data **code);
1356
1357 krb5_error_code
1358 encode_krb5_padata_sequence(krb5_pa_data *const *rep, krb5_data **code);
1359
1360 krb5_error_code
1361 encode_krb5_typed_data(krb5_pa_data *const *rep, krb5_data **code);
1362
1363 krb5_error_code
1364 encode_krb5_etype_info(krb5_etype_info_entry *const *, krb5_data **code);
1365
1366 krb5_error_code
1367 encode_krb5_etype_info2(krb5_etype_info_entry *const *, krb5_data **code);
1368
1369 krb5_error_code
1370 encode_krb5_pa_enc_ts(const krb5_pa_enc_ts *, krb5_data **);
1371
1372 krb5_error_code
1373 encode_krb5_sam_challenge_2(const krb5_sam_challenge_2 * , krb5_data **);
1374
1375 krb5_error_code
1376 encode_krb5_sam_challenge_2_body(const krb5_sam_challenge_2_body *,
1377                                  krb5_data **);
1378
1379 krb5_error_code
1380 encode_krb5_enc_sam_response_enc_2(const krb5_enc_sam_response_enc_2 *,
1381                                    krb5_data **);
1382
1383 krb5_error_code
1384 encode_krb5_sam_response_2(const krb5_sam_response_2 * , krb5_data **);
1385
1386 struct krb5_setpw_req {
1387     krb5_principal target;
1388     krb5_data password;
1389 };
1390 krb5_error_code
1391 encode_krb5_setpw_req(const struct krb5_setpw_req *rep, krb5_data **code);
1392
1393 krb5_error_code
1394 encode_krb5_pa_for_user(const krb5_pa_for_user *, krb5_data **);
1395
1396 krb5_error_code
1397 encode_krb5_s4u_userid(const krb5_s4u_userid *, krb5_data **);
1398
1399 krb5_error_code
1400 encode_krb5_pa_s4u_x509_user(const krb5_pa_s4u_x509_user *, krb5_data **);
1401
1402 krb5_error_code
1403 encode_krb5_pa_pac_req(const krb5_pa_pac_req *, krb5_data **);
1404
1405 krb5_error_code
1406 encode_krb5_etype_list(const krb5_etype_list * , krb5_data **);
1407
1408 krb5_error_code
1409 encode_krb5_pa_fx_fast_request(const krb5_fast_armored_req *, krb5_data **);
1410
1411 krb5_error_code
1412 encode_krb5_fast_req(const krb5_fast_req *, krb5_data **);
1413
1414 krb5_error_code
1415 encode_krb5_pa_fx_fast_reply(const krb5_enc_data *, krb5_data **);
1416
1417 krb5_error_code
1418 encode_krb5_iakerb_header(const krb5_iakerb_header *, krb5_data **);
1419
1420 krb5_error_code
1421 encode_krb5_iakerb_finished(const krb5_iakerb_finished *, krb5_data **);
1422
1423 krb5_error_code
1424 encode_krb5_fast_response(const krb5_fast_response *, krb5_data **);
1425
1426 krb5_error_code
1427 encode_krb5_ad_kdcissued(const krb5_ad_kdcissued *, krb5_data **);
1428
1429 krb5_error_code
1430 encode_krb5_ad_signedpath(const krb5_ad_signedpath *, krb5_data **);
1431
1432 krb5_error_code
1433 encode_krb5_ad_signedpath_data(const krb5_ad_signedpath_data *, krb5_data **);
1434
1435 krb5_error_code
1436 encode_krb5_otp_tokeninfo(const krb5_otp_tokeninfo *, krb5_data **);
1437
1438 krb5_error_code
1439 encode_krb5_pa_otp_challenge(const krb5_pa_otp_challenge *, krb5_data **);
1440
1441 krb5_error_code
1442 encode_krb5_pa_otp_req(const krb5_pa_otp_req *, krb5_data **);
1443
1444 krb5_error_code
1445 encode_krb5_pa_otp_enc_req(const krb5_data *, krb5_data **);
1446
1447 /*************************************************************************
1448  * End of prototypes for krb5_encode.c
1449  *************************************************************************/
1450
1451 krb5_error_code
1452 decode_krb5_sam_challenge_2(const krb5_data *, krb5_sam_challenge_2 **);
1453
1454 krb5_error_code
1455 decode_krb5_sam_challenge_2_body(const krb5_data *,
1456                                  krb5_sam_challenge_2_body **);
1457
1458 krb5_error_code
1459 decode_krb5_enc_sam_response_enc_2(const krb5_data *,
1460                                    krb5_enc_sam_response_enc_2 **);
1461
1462 krb5_error_code
1463 decode_krb5_sam_response_2(const krb5_data *, krb5_sam_response_2 **);
1464
1465
1466 /*************************************************************************
1467  * Prototypes for krb5_decode.c
1468  *************************************************************************/
1469 /*
1470   krb5_error_code decode_krb5_structure(const krb5_data *code,
1471   krb5_structure **rep);
1472
1473   requires  Expects **rep to not have been allocated;
1474   a new *rep is allocated regardless of the old value.
1475   effects   Decodes *code into **rep.
1476   Returns ENOMEM if memory is exhausted.
1477   Returns asn1 and krb5 errors.
1478 */
1479
1480 krb5_error_code
1481 decode_krb5_authenticator(const krb5_data *code, krb5_authenticator **rep);
1482
1483 krb5_error_code
1484 decode_krb5_ticket(const krb5_data *code, krb5_ticket **rep);
1485
1486 krb5_error_code
1487 decode_krb5_encryption_key(const krb5_data *output, krb5_keyblock **rep);
1488
1489 krb5_error_code
1490 decode_krb5_enc_tkt_part(const krb5_data *output, krb5_enc_tkt_part **rep);
1491
1492 krb5_error_code
1493 decode_krb5_enc_kdc_rep_part(const krb5_data *output,
1494                              krb5_enc_kdc_rep_part **rep);
1495
1496 krb5_error_code
1497 decode_krb5_as_rep(const krb5_data *output, krb5_kdc_rep **rep);
1498
1499 krb5_error_code
1500 decode_krb5_tgs_rep(const krb5_data *output, krb5_kdc_rep **rep);
1501
1502 krb5_error_code
1503 decode_krb5_ap_req(const krb5_data *output, krb5_ap_req **rep);
1504
1505 krb5_error_code
1506 decode_krb5_ap_rep(const krb5_data *output, krb5_ap_rep **rep);
1507
1508 krb5_error_code
1509 decode_krb5_ap_rep_enc_part(const krb5_data *output,
1510                             krb5_ap_rep_enc_part **rep);
1511
1512 krb5_error_code
1513 decode_krb5_as_req(const krb5_data *output, krb5_kdc_req **rep);
1514
1515 krb5_error_code
1516 decode_krb5_tgs_req(const krb5_data *output, krb5_kdc_req **rep);
1517
1518 krb5_error_code
1519 decode_krb5_kdc_req_body(const krb5_data *output, krb5_kdc_req **rep);
1520
1521 krb5_error_code
1522 decode_krb5_safe(const krb5_data *output, krb5_safe **rep);
1523
1524 krb5_error_code
1525 decode_krb5_safe_with_body(const krb5_data *output, krb5_safe **rep,
1526                            krb5_data **body);
1527
1528 krb5_error_code
1529 decode_krb5_priv(const krb5_data *output, krb5_priv **rep);
1530
1531 krb5_error_code
1532 decode_krb5_enc_priv_part(const krb5_data *output, krb5_priv_enc_part **rep);
1533 krb5_error_code
1534 decode_krb5_checksum(const krb5_data *, krb5_checksum **);
1535
1536 krb5_error_code
1537 decode_krb5_cred(const krb5_data *output, krb5_cred **rep);
1538
1539 krb5_error_code
1540 decode_krb5_enc_cred_part(const krb5_data *output, krb5_cred_enc_part **rep);
1541
1542 krb5_error_code
1543 decode_krb5_error(const krb5_data *output, krb5_error **rep);
1544
1545 krb5_error_code
1546 decode_krb5_authdata(const krb5_data *output, krb5_authdata ***rep);
1547
1548 krb5_error_code
1549 decode_krb5_padata_sequence(const krb5_data *output, krb5_pa_data ***rep);
1550
1551 krb5_error_code
1552 decode_krb5_typed_data(const krb5_data *, krb5_pa_data ***);
1553
1554 krb5_error_code
1555 decode_krb5_etype_info(const krb5_data *output, krb5_etype_info_entry ***rep);
1556
1557 krb5_error_code
1558 decode_krb5_etype_info2(const krb5_data *output, krb5_etype_info_entry ***rep);
1559
1560 krb5_error_code
1561 decode_krb5_enc_data(const krb5_data *output, krb5_enc_data **rep);
1562
1563 krb5_error_code
1564 decode_krb5_pa_enc_ts(const krb5_data *output, krb5_pa_enc_ts **rep);
1565
1566 krb5_error_code
1567 decode_krb5_setpw_req(const krb5_data *, krb5_data **, krb5_principal *);
1568
1569 krb5_error_code
1570 decode_krb5_pa_for_user(const krb5_data *, krb5_pa_for_user **);
1571
1572 krb5_error_code
1573 decode_krb5_pa_s4u_x509_user(const krb5_data *, krb5_pa_s4u_x509_user **);
1574
1575 krb5_error_code
1576 decode_krb5_pa_pac_req(const krb5_data *, krb5_pa_pac_req **);
1577
1578 krb5_error_code
1579 decode_krb5_etype_list(const krb5_data *, krb5_etype_list **);
1580
1581 krb5_error_code
1582 decode_krb5_pa_fx_fast_request(const krb5_data *, krb5_fast_armored_req **);
1583
1584 krb5_error_code
1585 decode_krb5_fast_req(const krb5_data *, krb5_fast_req **);
1586
1587 krb5_error_code
1588 decode_krb5_pa_fx_fast_reply(const krb5_data *, krb5_enc_data **);
1589
1590 krb5_error_code
1591 decode_krb5_fast_response(const krb5_data *, krb5_fast_response **);
1592
1593 krb5_error_code
1594 decode_krb5_ad_kdcissued(const krb5_data *, krb5_ad_kdcissued **);
1595
1596 krb5_error_code
1597 decode_krb5_ad_signedpath(const krb5_data *, krb5_ad_signedpath **);
1598
1599 krb5_error_code
1600 decode_krb5_iakerb_header(const krb5_data *, krb5_iakerb_header **);
1601
1602 krb5_error_code
1603 decode_krb5_iakerb_finished(const krb5_data *, krb5_iakerb_finished **);
1604
1605 krb5_error_code
1606 decode_krb5_otp_tokeninfo(const krb5_data *, krb5_otp_tokeninfo **);
1607
1608 krb5_error_code
1609 decode_krb5_pa_otp_challenge(const krb5_data *, krb5_pa_otp_challenge **);
1610
1611 krb5_error_code
1612 decode_krb5_pa_otp_req(const krb5_data *, krb5_pa_otp_req **);
1613
1614 krb5_error_code
1615 decode_krb5_pa_otp_enc_req(const krb5_data *, krb5_data **);
1616
1617 struct _krb5_key_data;          /* kdb.h */
1618
1619 struct ldap_seqof_key_data {
1620     krb5_int32 mkvno;           /* Master key version number */
1621     krb5_int16 kvno;            /* kvno of key_data elements (all the same) */
1622     struct _krb5_key_data *key_data;
1623     krb5_int16 n_key_data;
1624 };
1625 typedef struct ldap_seqof_key_data ldap_seqof_key_data;
1626
1627 krb5_error_code
1628 krb5int_ldap_encode_sequence_of_keys(const ldap_seqof_key_data *val,
1629                                      krb5_data **code);
1630
1631 krb5_error_code
1632 krb5int_ldap_decode_sequence_of_keys(const krb5_data *in,
1633                                      ldap_seqof_key_data **rep);
1634
1635 /*************************************************************************
1636  * End of prototypes for krb5_decode.c
1637  *************************************************************************/
1638
1639 #endif /* KRB5_ASN1__ */
1640 /*
1641  * End "asn1.h"
1642  */
1643
1644
1645 /*
1646  * Internal krb5 library routines
1647  */
1648 krb5_error_code
1649 krb5_encrypt_tkt_part(krb5_context, const krb5_keyblock *, krb5_ticket *);
1650
1651 krb5_error_code
1652 krb5_encode_kdc_rep(krb5_context, krb5_msgtype, const krb5_enc_kdc_rep_part *,
1653                     int using_subkey, const krb5_keyblock *, krb5_kdc_rep *,
1654                     krb5_data ** );
1655
1656 /*
1657  * [De]Serialization Handle and operations.
1658  */
1659 struct __krb5_serializer {
1660     krb5_magic          odtype;
1661     krb5_error_code     (*sizer) (krb5_context,
1662                                   krb5_pointer,
1663                                   size_t *);
1664     krb5_error_code     (*externalizer) (krb5_context,
1665                                          krb5_pointer,
1666                                          krb5_octet **,
1667                                          size_t *);
1668     krb5_error_code     (*internalizer) (krb5_context,
1669                                          krb5_pointer *,
1670                                          krb5_octet **,
1671                                          size_t *);
1672 };
1673 typedef const struct __krb5_serializer * krb5_ser_handle;
1674 typedef struct __krb5_serializer krb5_ser_entry;
1675
1676 krb5_ser_handle krb5_find_serializer(krb5_context, krb5_magic);
1677 krb5_error_code krb5_register_serializer(krb5_context, const krb5_ser_entry *);
1678
1679 /* Determine the external size of a particular opaque structure */
1680 krb5_error_code KRB5_CALLCONV
1681 krb5_size_opaque(krb5_context, krb5_magic, krb5_pointer, size_t *);
1682
1683 /* Serialize the structure into a buffer */
1684 krb5_error_code KRB5_CALLCONV
1685 krb5_externalize_opaque(krb5_context, krb5_magic, krb5_pointer, krb5_octet **,
1686                         size_t *);
1687
1688 /* Deserialize the structure from a buffer */
1689 krb5_error_code KRB5_CALLCONV
1690 krb5_internalize_opaque(krb5_context, krb5_magic, krb5_pointer *,
1691                         krb5_octet **, size_t *);
1692
1693 /* Serialize data into a buffer */
1694 krb5_error_code
1695 krb5_externalize_data(krb5_context, krb5_pointer, krb5_octet **, size_t *);
1696 /*
1697  * Initialization routines.
1698  */
1699
1700 /* Initialize serialization for krb5_[os_]context */
1701 krb5_error_code KRB5_CALLCONV krb5_ser_context_init(krb5_context);
1702
1703 /* Initialize serialization for krb5_auth_context */
1704 krb5_error_code KRB5_CALLCONV krb5_ser_auth_context_init(krb5_context);
1705
1706 /* Initialize serialization for krb5_keytab */
1707 krb5_error_code KRB5_CALLCONV krb5_ser_keytab_init(krb5_context);
1708
1709 /* Initialize serialization for krb5_ccache */
1710 krb5_error_code KRB5_CALLCONV krb5_ser_ccache_init(krb5_context);
1711
1712 /* Initialize serialization for krb5_rcache */
1713 krb5_error_code KRB5_CALLCONV krb5_ser_rcache_init(krb5_context);
1714
1715 /* [De]serialize 4-byte integer */
1716 krb5_error_code KRB5_CALLCONV
1717 krb5_ser_pack_int32(krb5_int32, krb5_octet **, size_t *);
1718
1719 krb5_error_code KRB5_CALLCONV
1720 krb5_ser_unpack_int32(krb5_int32 *, krb5_octet **, size_t *);
1721
1722 /* [De]serialize 8-byte integer */
1723 krb5_error_code KRB5_CALLCONV
1724 krb5_ser_pack_int64(krb5_int64, krb5_octet **, size_t *);
1725
1726 krb5_error_code KRB5_CALLCONV
1727 krb5_ser_unpack_int64(krb5_int64 *, krb5_octet **, size_t *);
1728
1729 /* [De]serialize byte string */
1730 krb5_error_code KRB5_CALLCONV
1731 krb5_ser_pack_bytes(krb5_octet *, size_t, krb5_octet **, size_t *);
1732
1733 krb5_error_code KRB5_CALLCONV
1734 krb5_ser_unpack_bytes(krb5_octet *, size_t, krb5_octet **, size_t *);
1735
1736 krb5_error_code KRB5_CALLCONV
1737 krb5int_cc_default(krb5_context, krb5_ccache *);
1738
1739 /* Fill in the buffer with random alpha-numeric data. */
1740 krb5_error_code
1741 krb5int_random_string(krb5_context, char *string, unsigned int length);
1742
1743 /* value to use when requesting a keytab entry and KVNO doesn't matter */
1744 #define IGNORE_VNO 0
1745 /* value to use when requesting a keytab entry and enctype doesn't matter */
1746 #define IGNORE_ENCTYPE 0
1747
1748 /* To keep happy libraries which are (for now) accessing internal stuff */
1749
1750 /* Make sure to increment by one when changing the struct */
1751 #define KRB5INT_ACCESS_STRUCT_VERSION 21
1752
1753 typedef struct _krb5int_access {
1754     krb5_error_code (*auth_con_get_subkey_enctype)(krb5_context,
1755                                                    krb5_auth_context,
1756                                                    krb5_enctype *);
1757
1758     krb5_error_code (*clean_hostname)(krb5_context, const char *, char *,
1759                                       size_t);
1760
1761     krb5_error_code (*mandatory_cksumtype)(krb5_context, krb5_enctype,
1762                                            krb5_cksumtype *);
1763     krb5_error_code (KRB5_CALLCONV *ser_pack_int64)(krb5_int64, krb5_octet **,
1764                                                     size_t *);
1765     krb5_error_code (KRB5_CALLCONV *ser_unpack_int64)(krb5_int64 *,
1766                                                       krb5_octet **, size_t *);
1767
1768     /* Used for KDB LDAP back end.  */
1769     krb5_error_code
1770     (*asn1_ldap_encode_sequence_of_keys)(const ldap_seqof_key_data *val,
1771                                          krb5_data **code);
1772
1773     krb5_error_code
1774     (*asn1_ldap_decode_sequence_of_keys)(const krb5_data *in,
1775                                          ldap_seqof_key_data **);
1776
1777     /*
1778      * pkinit asn.1 encode/decode functions
1779      */
1780     krb5_error_code
1781     (*encode_krb5_auth_pack)(const krb5_auth_pack *rep, krb5_data **code);
1782
1783     krb5_error_code
1784     (*encode_krb5_auth_pack_draft9)(const krb5_auth_pack_draft9 *rep,
1785                                     krb5_data **code);
1786
1787     krb5_error_code
1788     (*encode_krb5_kdc_dh_key_info)(const krb5_kdc_dh_key_info *rep,
1789                                    krb5_data **code);
1790
1791     krb5_error_code
1792     (*encode_krb5_pa_pk_as_rep)(const krb5_pa_pk_as_rep *rep,
1793                                 krb5_data **code);
1794
1795     krb5_error_code
1796     (*encode_krb5_pa_pk_as_rep_draft9)(const krb5_pa_pk_as_rep_draft9 *rep,
1797                                        krb5_data **code);
1798
1799     krb5_error_code
1800     (*encode_krb5_pa_pk_as_req)(const krb5_pa_pk_as_req *rep,
1801                                 krb5_data **code);
1802
1803     krb5_error_code
1804     (*encode_krb5_pa_pk_as_req_draft9)(const krb5_pa_pk_as_req_draft9 *rep,
1805                                        krb5_data **code);
1806
1807     krb5_error_code
1808     (*encode_krb5_reply_key_pack)(const krb5_reply_key_pack *,
1809                                   krb5_data **code);
1810
1811     krb5_error_code
1812     (*encode_krb5_reply_key_pack_draft9)(const krb5_reply_key_pack_draft9 *,
1813                                          krb5_data **code);
1814
1815     krb5_error_code
1816     (*encode_krb5_td_dh_parameters)(krb5_algorithm_identifier *const *,
1817                                     krb5_data **code);
1818
1819     krb5_error_code
1820     (*encode_krb5_td_trusted_certifiers)(krb5_external_principal_identifier *
1821                                          const *, krb5_data **code);
1822
1823     krb5_error_code
1824     (*decode_krb5_auth_pack)(const krb5_data *, krb5_auth_pack **);
1825
1826     krb5_error_code
1827     (*decode_krb5_auth_pack_draft9)(const krb5_data *,
1828                                     krb5_auth_pack_draft9 **);
1829
1830     krb5_error_code
1831     (*decode_krb5_pa_pk_as_req)(const krb5_data *, krb5_pa_pk_as_req **);
1832
1833     krb5_error_code
1834     (*decode_krb5_pa_pk_as_req_draft9)(const krb5_data *,
1835                                        krb5_pa_pk_as_req_draft9 **);
1836
1837     krb5_error_code
1838     (*decode_krb5_pa_pk_as_rep)(const krb5_data *, krb5_pa_pk_as_rep **);
1839
1840     krb5_error_code
1841     (*decode_krb5_kdc_dh_key_info)(const krb5_data *, krb5_kdc_dh_key_info **);
1842
1843     krb5_error_code
1844     (*decode_krb5_principal_name)(const krb5_data *, krb5_principal_data **);
1845
1846     krb5_error_code
1847     (*decode_krb5_reply_key_pack)(const krb5_data *, krb5_reply_key_pack **);
1848
1849     krb5_error_code
1850     (*decode_krb5_reply_key_pack_draft9)(const krb5_data *,
1851                                          krb5_reply_key_pack_draft9 **);
1852
1853     krb5_error_code
1854     (*decode_krb5_td_dh_parameters)(const krb5_data *,
1855                                     krb5_algorithm_identifier ***);
1856
1857     krb5_error_code
1858     (*decode_krb5_td_trusted_certifiers)(const krb5_data *,
1859                                          krb5_external_principal_identifier
1860                                          ***);
1861
1862     krb5_error_code
1863     (*encode_krb5_kdc_req_body)(const krb5_kdc_req *rep, krb5_data **code);
1864
1865     void
1866     (KRB5_CALLCONV *free_kdc_req)(krb5_context, krb5_kdc_req * );
1867     void
1868     (*set_prompt_types)(krb5_context, krb5_prompt_type *);
1869 } krb5int_access;
1870
1871 #define KRB5INT_ACCESS_VERSION                                          \
1872     (((krb5_int32)((sizeof(krb5int_access) & 0xFFFF) |                  \
1873                    (KRB5INT_ACCESS_STRUCT_VERSION << 16))) & 0xFFFFFFFF)
1874
1875 krb5_error_code KRB5_CALLCONV
1876 krb5int_accessor(krb5int_access*, krb5_int32);
1877
1878 typedef struct _krb5_donot_replay {
1879     krb5_magic magic;
1880     krb5_ui_4 hash;
1881     char *server;                       /* null-terminated */
1882     char *client;                       /* null-terminated */
1883     char *msghash;                      /* null-terminated */
1884     krb5_int32 cusec;
1885     krb5_timestamp ctime;
1886 } krb5_donot_replay;
1887
1888 krb5_error_code KRB5_CALLCONV
1889 krb5int_cc_user_set_default_name(krb5_context context, const char *name);
1890
1891 krb5_error_code krb5_rc_default(krb5_context, krb5_rcache *);
1892 krb5_error_code krb5_rc_resolve_type(krb5_context, krb5_rcache *,char *);
1893 krb5_error_code krb5_rc_resolve_full(krb5_context, krb5_rcache *,char *);
1894 char *krb5_rc_get_type(krb5_context, krb5_rcache);
1895 char *krb5_rc_default_type(krb5_context);
1896 char *krb5_rc_default_name(krb5_context);
1897 krb5_error_code krb5_auth_to_rep(krb5_context, krb5_tkt_authent *,
1898                                  krb5_donot_replay *);
1899 krb5_error_code krb5_rc_hash_message(krb5_context context,
1900                                      const krb5_data *message, char **out);
1901
1902 krb5_error_code KRB5_CALLCONV
1903 krb5_rc_initialize(krb5_context, krb5_rcache, krb5_deltat);
1904
1905 krb5_error_code KRB5_CALLCONV
1906 krb5_rc_recover_or_initialize(krb5_context, krb5_rcache,krb5_deltat);
1907
1908 krb5_error_code KRB5_CALLCONV
1909 krb5_rc_recover(krb5_context, krb5_rcache);
1910
1911 krb5_error_code KRB5_CALLCONV
1912 krb5_rc_destroy(krb5_context, krb5_rcache);
1913
1914 krb5_error_code KRB5_CALLCONV
1915 krb5_rc_close(krb5_context, krb5_rcache);
1916
1917 krb5_error_code KRB5_CALLCONV
1918 krb5_rc_store(krb5_context, krb5_rcache, krb5_donot_replay *);
1919
1920 krb5_error_code KRB5_CALLCONV
1921 krb5_rc_expunge(krb5_context, krb5_rcache);
1922
1923 krb5_error_code KRB5_CALLCONV
1924 krb5_rc_get_lifespan(krb5_context, krb5_rcache,krb5_deltat *);
1925
1926 char *KRB5_CALLCONV
1927 krb5_rc_get_name(krb5_context, krb5_rcache);
1928
1929 krb5_error_code KRB5_CALLCONV
1930 krb5_rc_resolve(krb5_context, krb5_rcache, char *);
1931
1932 /*
1933  * This structure was exposed and used in macros in krb5 1.2, so do not
1934  * change its ABI.
1935  */
1936 typedef struct _krb5_kt_ops {
1937     krb5_magic magic;
1938     char *prefix;
1939
1940     /* routines always present */
1941     krb5_error_code (KRB5_CALLCONV *resolve)(krb5_context, const char *,
1942                                              krb5_keytab *);
1943     krb5_error_code (KRB5_CALLCONV *get_name)(krb5_context, krb5_keytab,
1944                                               char *, unsigned int);
1945     krb5_error_code (KRB5_CALLCONV *close)(krb5_context, krb5_keytab);
1946     krb5_error_code (KRB5_CALLCONV *get)(krb5_context, krb5_keytab,
1947                                          krb5_const_principal, krb5_kvno,
1948                                          krb5_enctype, krb5_keytab_entry *);
1949     krb5_error_code (KRB5_CALLCONV *start_seq_get)(krb5_context, krb5_keytab,
1950                                                    krb5_kt_cursor *);
1951     krb5_error_code (KRB5_CALLCONV *get_next)(krb5_context, krb5_keytab,
1952                                               krb5_keytab_entry *,
1953                                               krb5_kt_cursor *);
1954     krb5_error_code (KRB5_CALLCONV *end_get)(krb5_context, krb5_keytab,
1955                                              krb5_kt_cursor *);
1956     /* routines to be included on extended version (write routines) */
1957     krb5_error_code (KRB5_CALLCONV *add)(krb5_context, krb5_keytab,
1958                                          krb5_keytab_entry *);
1959     krb5_error_code (KRB5_CALLCONV *remove)(krb5_context, krb5_keytab,
1960                                             krb5_keytab_entry *);
1961
1962     /* Handle for serializer */
1963     const krb5_ser_entry *serializer;
1964 } krb5_kt_ops;
1965
1966 /* Not sure it's ready for exposure just yet.  */
1967 extern krb5_error_code
1968 krb5int_c_mandatory_cksumtype(krb5_context, krb5_enctype, krb5_cksumtype *);
1969
1970 /*
1971  * Referral definitions and subfunctions.
1972  */
1973 #define        KRB5_REFERRAL_MAXHOPS    10
1974
1975 struct _krb5_kt {       /* should move into k5-int.h */
1976     krb5_magic magic;
1977     const struct _krb5_kt_ops *ops;
1978     krb5_pointer data;
1979 };
1980
1981 krb5_error_code krb5_set_default_in_tkt_ktypes(krb5_context,
1982                                                const krb5_enctype *);
1983
1984 krb5_error_code krb5_get_default_in_tkt_ktypes(krb5_context, krb5_enctype **);
1985
1986 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context,
1987                                             const krb5_enctype *);
1988
1989 krb5_error_code KRB5_CALLCONV
1990 krb5_get_tgs_ktypes(krb5_context, krb5_const_principal, krb5_enctype **);
1991
1992 krb5_boolean krb5_is_permitted_enctype(krb5_context, krb5_enctype);
1993
1994 krb5_boolean KRB5_CALLCONV krb5int_c_weak_enctype(krb5_enctype);
1995
1996 krb5_error_code krb5_kdc_rep_decrypt_proc(krb5_context, const krb5_keyblock *,
1997                                           krb5_const_pointer, krb5_kdc_rep *);
1998 krb5_error_code KRB5_CALLCONV krb5_decrypt_tkt_part(krb5_context,
1999                                                     const krb5_keyblock *,
2000                                                     krb5_ticket * );
2001
2002 krb5_error_code krb5_get_cred_via_tkt(krb5_context, krb5_creds *, krb5_flags,
2003                                       krb5_address *const *, krb5_creds *,
2004                                       krb5_creds **);
2005
2006 krb5_error_code KRB5_CALLCONV krb5_copy_addr(krb5_context,
2007                                              const krb5_address *,
2008                                              krb5_address **);
2009
2010 void krb5_init_ets(krb5_context);
2011 void krb5_free_ets(krb5_context);
2012 krb5_error_code krb5_generate_subkey(krb5_context, const krb5_keyblock *,
2013                                      krb5_keyblock **);
2014 krb5_error_code krb5_generate_subkey_extended(krb5_context,
2015                                               const krb5_keyblock *,
2016                                               krb5_enctype, krb5_keyblock **);
2017 krb5_error_code krb5_generate_seq_number(krb5_context, const krb5_keyblock *,
2018                                          krb5_ui_4 *);
2019
2020 krb5_error_code KRB5_CALLCONV krb5_kt_register(krb5_context,
2021                                                const struct _krb5_kt_ops *);
2022
2023 krb5_error_code k5_kt_get_principal(krb5_context context, krb5_keytab keytab,
2024                                     krb5_principal *princ_out);
2025
2026 krb5_error_code krb5_principal2salt_norealm(krb5_context, krb5_const_principal,
2027                                             krb5_data *);
2028
2029 unsigned int KRB5_CALLCONV krb5_get_notification_message(void);
2030
2031 /* chk_trans.c */
2032 krb5_error_code krb5_check_transited_list(krb5_context, const krb5_data *trans,
2033                                           const krb5_data *realm1,
2034                                           const krb5_data *realm2);
2035
2036 /* free_rtree.c */
2037 void krb5_free_realm_tree(krb5_context, krb5_principal *);
2038
2039 void KRB5_CALLCONV krb5_free_authenticator_contents(krb5_context,
2040                                                     krb5_authenticator *);
2041
2042 void KRB5_CALLCONV krb5_free_address(krb5_context, krb5_address *);
2043
2044 void KRB5_CALLCONV krb5_free_enc_tkt_part(krb5_context, krb5_enc_tkt_part *);
2045
2046 void KRB5_CALLCONV krb5_free_tickets(krb5_context, krb5_ticket **);
2047 void KRB5_CALLCONV krb5_free_kdc_req(krb5_context, krb5_kdc_req *);
2048 void KRB5_CALLCONV krb5_free_kdc_rep(krb5_context, krb5_kdc_rep *);
2049 void KRB5_CALLCONV krb5_free_last_req(krb5_context, krb5_last_req_entry **);
2050 void KRB5_CALLCONV krb5_free_enc_kdc_rep_part(krb5_context,
2051                                               krb5_enc_kdc_rep_part *);
2052 void KRB5_CALLCONV krb5_free_ap_req(krb5_context, krb5_ap_req *);
2053 void KRB5_CALLCONV krb5_free_ap_rep(krb5_context, krb5_ap_rep *);
2054 void KRB5_CALLCONV krb5_free_cred(krb5_context, krb5_cred *);
2055 void KRB5_CALLCONV krb5_free_cred_enc_part(krb5_context, krb5_cred_enc_part *);
2056 void KRB5_CALLCONV krb5_free_pa_data(krb5_context, krb5_pa_data **);
2057 void KRB5_CALLCONV krb5_free_tkt_authent(krb5_context, krb5_tkt_authent *);
2058 void KRB5_CALLCONV krb5_free_enc_data(krb5_context, krb5_enc_data *);
2059 krb5_error_code krb5_set_config_files(krb5_context, const char **);
2060
2061 krb5_error_code KRB5_CALLCONV krb5_get_default_config_files(char ***filenames);
2062
2063 void KRB5_CALLCONV krb5_free_config_files(char **filenames);
2064
2065 krb5_error_code krb5_rd_req_decoded(krb5_context, krb5_auth_context *,
2066                                     const krb5_ap_req *, krb5_const_principal,
2067                                     krb5_keytab, krb5_flags *, krb5_ticket **);
2068
2069 krb5_error_code krb5_rd_req_decoded_anyflag(krb5_context, krb5_auth_context *,
2070                                             const krb5_ap_req *,
2071                                             krb5_const_principal, krb5_keytab,
2072                                             krb5_flags *, krb5_ticket **);
2073
2074 krb5_error_code KRB5_CALLCONV
2075 krb5_cc_register(krb5_context, const krb5_cc_ops *, krb5_boolean );
2076
2077 krb5_error_code krb5_walk_realm_tree(krb5_context, const krb5_data *,
2078                                      const krb5_data *, krb5_principal **,
2079                                      int);
2080
2081 krb5_error_code
2082 krb5_auth_con_set_safe_cksumtype(krb5_context, krb5_auth_context,
2083                                  krb5_cksumtype);
2084
2085 krb5_error_code krb5_auth_con_setivector(krb5_context, krb5_auth_context,
2086                                          krb5_pointer);
2087
2088 krb5_error_code krb5_auth_con_getivector(krb5_context, krb5_auth_context,
2089                                          krb5_pointer *);
2090
2091 krb5_error_code krb5_auth_con_setpermetypes(krb5_context, krb5_auth_context,
2092                                             const krb5_enctype *);
2093
2094 krb5_error_code krb5_auth_con_getpermetypes(krb5_context, krb5_auth_context,
2095                                             krb5_enctype **);
2096
2097 krb5_error_code krb5_auth_con_get_subkey_enctype(krb5_context context,
2098                                                  krb5_auth_context,
2099                                                  krb5_enctype *);
2100
2101 krb5_error_code
2102 krb5_auth_con_get_authdata_context(krb5_context context,
2103                                    krb5_auth_context auth_context,
2104                                    krb5_authdata_context *ad_context);
2105
2106 krb5_error_code
2107 krb5_auth_con_set_authdata_context(krb5_context context,
2108                                    krb5_auth_context auth_context,
2109                                    krb5_authdata_context ad_context);
2110
2111 krb5_error_code krb5_read_message(krb5_context, krb5_pointer, krb5_data *);
2112 krb5_error_code krb5_write_message(krb5_context, krb5_pointer, krb5_data *);
2113 int krb5_net_read(krb5_context, int , char *, int);
2114 int krb5_net_write(krb5_context, int , const char *, int);
2115
2116 krb5_error_code KRB5_CALLCONV krb5_get_realm_domain(krb5_context,
2117                                                     const char *, char ** );
2118
2119 krb5_error_code krb5_gen_portaddr(krb5_context, const krb5_address *,
2120                                   krb5_const_pointer, krb5_address **);
2121
2122 krb5_error_code krb5_gen_replay_name(krb5_context, const krb5_address *,
2123                                      const char *, char **);
2124 krb5_error_code krb5_make_fulladdr(krb5_context, krb5_address *,
2125                                    krb5_address *, krb5_address *);
2126
2127 krb5_error_code krb5_set_debugging_time(krb5_context, krb5_timestamp,
2128                                         krb5_int32);
2129 krb5_error_code krb5_use_natural_time(krb5_context);
2130 krb5_error_code krb5_set_time_offsets(krb5_context, krb5_timestamp,
2131                                       krb5_int32);
2132
2133 /* Some data comparison and conversion functions.  */
2134 static inline int
2135 data_eq(krb5_data d1, krb5_data d2)
2136 {
2137     return (d1.length == d2.length && (d1.length == 0 ||
2138                                        !memcmp(d1.data, d2.data, d1.length)));
2139 }
2140
2141 static inline int
2142 data_eq_string (krb5_data d, const char *s)
2143 {
2144     return (d.length == strlen(s) && (d.length == 0 ||
2145                                       !memcmp(d.data, s, d.length)));
2146 }
2147
2148 static inline krb5_data
2149 make_data(void *data, unsigned int len)
2150 {
2151     krb5_data d;
2152
2153     d.magic = KV5M_DATA;
2154     d.data = (char *) data;
2155     d.length = len;
2156     return d;
2157 }
2158
2159 static inline krb5_data
2160 empty_data()
2161 {
2162     return make_data(NULL, 0);
2163 }
2164
2165 static inline krb5_data
2166 string2data(char *str)
2167 {
2168     return make_data(str, strlen(str));
2169 }
2170
2171 static inline krb5_error_code
2172 alloc_data(krb5_data *data, unsigned int len)
2173 {
2174     /* Allocate at least one byte since zero-byte allocs may return NULL. */
2175     char *ptr = (char *) calloc((len > 0) ? len : 1, 1);
2176
2177     if (ptr == NULL)
2178         return ENOMEM;
2179     data->magic = KV5M_DATA;
2180     data->data = ptr;
2181     data->length = len;
2182     return 0;
2183 }
2184
2185 static inline int
2186 authdata_eq(krb5_authdata a1, krb5_authdata a2)
2187 {
2188     return (a1.ad_type == a2.ad_type && a1.length == a2.length &&
2189             (a1.length == 0 || !memcmp(a1.contents, a2.contents, a1.length)));
2190 }
2191
2192 /* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */
2193 static inline void *
2194 k5calloc(size_t nmemb, size_t size, krb5_error_code *code)
2195 {
2196     void *ptr;
2197
2198     /* Allocate at least one byte since zero-byte allocs may return NULL. */
2199     ptr = calloc(nmemb ? nmemb : 1, size ? size : 1);
2200     *code = (ptr == NULL) ? ENOMEM : 0;
2201     return ptr;
2202 }
2203
2204 /* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */
2205 static inline void *
2206 k5alloc(size_t size, krb5_error_code *code)
2207 {
2208     return k5calloc(1, size, code);
2209 }
2210
2211 /* Return a copy of the len bytes of memory at in; set *code to 0 or ENOMEM. */
2212 static inline void *
2213 k5memdup(const void *in, size_t len, krb5_error_code *code)
2214 {
2215     void *ptr = k5alloc(len, code);
2216
2217     if (ptr != NULL && len > 0)
2218         memcpy(ptr, in, len);
2219     return ptr;
2220 }
2221
2222 /* Like k5memdup, but add a final null byte. */
2223 static inline void *
2224 k5memdup0(const void *in, size_t len, krb5_error_code *code)
2225 {
2226     void *ptr = k5alloc(len + 1, code);
2227
2228     if (ptr != NULL && len > 0)
2229         memcpy(ptr, in, len);
2230     return ptr;
2231 }
2232
2233 krb5_error_code KRB5_CALLCONV
2234 krb5_get_credentials_for_user(krb5_context context, krb5_flags options,
2235                               krb5_ccache ccache,
2236                               krb5_creds *in_creds,
2237                               krb5_data *cert,
2238                               krb5_creds **out_creds);
2239
2240 krb5_error_code KRB5_CALLCONV
2241 krb5_get_credentials_for_proxy(krb5_context context,
2242                                krb5_flags options,
2243                                krb5_ccache ccache,
2244                                krb5_creds *in_creds,
2245                                krb5_ticket *evidence_tkt,
2246                                krb5_creds **out_creds);
2247
2248 krb5_error_code KRB5_CALLCONV
2249 krb5int_get_authdata_containee_types(krb5_context context,
2250                                      const krb5_authdata *container,
2251                                      unsigned int *nad_types,
2252                                      krb5_authdatatype **ad_types);
2253
2254 krb5_error_code krb5int_parse_enctype_list(krb5_context context,
2255                                            const char *profkey, char *profstr,
2256                                            krb5_enctype *default_list,
2257                                            krb5_enctype **result);
2258
2259 krb5_boolean k5_etypes_contains(const krb5_enctype *list, krb5_enctype etype);
2260
2261 #ifdef DEBUG_ERROR_LOCATIONS
2262 #define krb5_set_error_message(ctx, code, ...)                          \
2263     krb5_set_error_message_fl(ctx, code, __FILE__, __LINE__, __VA_ARGS__)
2264 #endif
2265 void KRB5_CALLCONV_C
2266 krb5_set_error_message_fl(krb5_context ctx, krb5_error_code code,
2267                           const char *file, int line, const char *fmt, ...)
2268 #ifdef __GNUC__
2269     __attribute__((__format__(printf,5,6)))
2270 #endif
2271     ;
2272
2273 #endif /* _KRB5_INT_H */