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