1 /* $NetBSD: krb5_locl.h,v 1.1.1.2 2011/04/14 14:09:23 elric Exp $ */ 2 3 /* 4 * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan 5 * (Royal Institute of Technology, Stockholm, Sweden). 6 * All rights reserved. 7 * 8 * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * 3. Neither the name of the Institute nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38 /* Id */ 39 40 #ifndef __KRB5_LOCL_H__ 41 #define __KRB5_LOCL_H__ 42 43 #include <config.h> 44 45 #include <errno.h> 46 #include <ctype.h> 47 #include <string.h> 48 #include <stdio.h> 49 #include <stdlib.h> 50 #include <limits.h> 51 52 #include <krb5/krb5-types.h> 53 54 #ifdef HAVE_SYS_TYPES_H 55 #include <sys/types.h> 56 #endif 57 #ifdef HAVE_SYS_MMAN_H 58 #include <sys/mman.h> 59 #endif 60 #ifdef HAVE_UNISTD_H 61 #include <unistd.h> 62 #endif 63 #ifdef HAVE_FCNTL_H 64 #include <fcntl.h> 65 #endif 66 67 #if defined(HAVE_SYS_IOCTL_H) && SunOS != 40 68 #include <sys/ioctl.h> 69 #endif 70 #ifdef HAVE_PWD_H 71 #undef _POSIX_PTHREAD_SEMANTICS 72 /* This gets us the 5-arg getpwnam_r on Solaris 9. */ 73 #define _POSIX_PTHREAD_SEMANTICS 74 #include <pwd.h> 75 #endif 76 77 #ifdef HAVE_SYS_PARAM_H 78 #include <sys/param.h> 79 #endif 80 #include <time.h> 81 #ifdef HAVE_SYS_TIME_H 82 #include <sys/time.h> 83 #endif 84 #ifdef HAVE_SYS_SELECT_H 85 #include <sys/select.h> 86 #endif 87 #ifdef HAVE_SYS_SOCKET_H 88 #include <sys/socket.h> 89 #endif 90 #ifdef HAVE_NETINET_IN_H 91 #include <netinet/in.h> 92 #endif 93 #ifdef HAVE_NETINET_IN6_H 94 #include <netinet/in6.h> 95 #endif 96 #ifdef HAVE_NETINET6_IN6_H 97 #include <netinet6/in6.h> 98 #endif 99 #ifdef HAVE_NETDB_H 100 #include <netdb.h> 101 #endif 102 #ifdef _AIX 103 struct ether_addr; 104 struct mbuf; 105 struct sockaddr_dl; 106 #endif 107 #ifdef HAVE_ARPA_INET_H 108 #include <arpa/inet.h> 109 #endif 110 #ifdef HAVE_ARPA_NAMESER_H 111 #include <arpa/nameser.h> 112 #endif 113 #ifdef HAVE_SYS_UIO_H 114 #include <sys/uio.h> 115 #endif 116 #ifdef HAVE_SYS_FILIO_H 117 #include <sys/filio.h> 118 #endif 119 #ifdef HAVE_SYS_FILE_H 120 #include <sys/file.h> 121 #endif 122 123 #include <krb5/com_err.h> 124 125 #include <krb5/heimbase.h> 126 127 #define HEIMDAL_TEXTDOMAIN "heimdal_krb5" 128 129 #ifdef LIBINTL 130 #include <libintl.h> 131 #define N_(x,y) dgettext(HEIMDAL_TEXTDOMAIN, x) 132 #else 133 #define N_(x,y) (x) 134 #define bindtextdomain(package, localedir) 135 #endif 136 137 138 #ifdef HAVE_CRYPT_H 139 #undef des_encrypt 140 #define des_encrypt wingless_pigs_mostly_fail_to_fly 141 #include <crypt.h> 142 #undef des_encrypt 143 #endif 144 145 #ifdef HAVE_DOOR_CREATE 146 #include <door.h> 147 #endif 148 149 #include <krb5/roken.h> 150 #include <krb5/parse_time.h> 151 #include <krb5/base64.h> 152 153 #include <krb5/wind.h> 154 155 #define HC_DEPRECATED_CRYPTO 156 #include "crypto-headers.h" 157 158 159 #include <krb5/krb5_asn1.h> 160 161 struct send_to_kdc; 162 163 /* XXX glue for pkinit */ 164 struct hx509_certs_data; 165 struct krb5_pk_identity; 166 struct krb5_pk_cert; 167 struct ContentInfo; 168 struct AlgorithmIdentifier; 169 typedef struct krb5_pk_init_ctx_data *krb5_pk_init_ctx; 170 struct krb5_dh_moduli; 171 172 /* v4 glue */ 173 struct _krb5_krb_auth_data; 174 175 #include <krb5/der.h> 176 177 #include <krb5/krb5.h> 178 #include <krb5/krb5_err.h> 179 #include <krb5/asn1_err.h> 180 #ifdef PKINIT 181 #include <krb5/hx509.h> 182 #endif 183 184 #include "crypto.h" 185 186 #include <krb5/krb5-private.h> 187 188 #include "heim_threads.h" 189 190 #define ALLOC(X, N) (X) = calloc((N), sizeof(*(X))) 191 #define ALLOC_SEQ(X, N) do { (X)->len = (N); ALLOC((X)->val, (N)); } while(0) 192 193 #ifndef PATH_SEP 194 #define PATH_SEP ":" 195 #endif 196 197 /* should this be public? */ 198 #define KEYTAB_DEFAULT "FILE:" SYSCONFDIR "/krb5.keytab" 199 #define KEYTAB_DEFAULT_MODIFY "FILE:" SYSCONFDIR "/krb5.keytab" 200 201 202 #define MODULI_FILE SYSCONFDIR "/krb5.moduli" 203 204 #ifndef O_BINARY 205 #define O_BINARY 0 206 #endif 207 208 #ifndef O_CLOEXEC 209 #define O_CLOEXEC 0 210 #endif 211 212 #ifndef SOCK_CLOEXEC 213 #define SOCK_CLOEXEC 0 214 #endif 215 216 217 #define KRB5_BUFSIZ 2048 218 219 typedef enum { 220 KRB5_INIT_CREDS_TRISTATE_UNSET = 0, 221 KRB5_INIT_CREDS_TRISTATE_TRUE, 222 KRB5_INIT_CREDS_TRISTATE_FALSE 223 } krb5_get_init_creds_tristate; 224 225 struct _krb5_get_init_creds_opt_private { 226 int refcount; 227 /* ENC_TIMESTAMP */ 228 const char *password; 229 krb5_s2k_proc key_proc; 230 /* PA_PAC_REQUEST */ 231 krb5_get_init_creds_tristate req_pac; 232 /* PKINIT */ 233 krb5_pk_init_ctx pk_init_ctx; 234 krb5_get_init_creds_tristate addressless; 235 int flags; 236 #define KRB5_INIT_CREDS_CANONICALIZE 1 237 #define KRB5_INIT_CREDS_NO_C_CANON_CHECK 2 238 #define KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK 4 239 struct { 240 krb5_gic_process_last_req func; 241 void *ctx; 242 } lr; 243 }; 244 245 typedef struct krb5_context_data { 246 krb5_enctype *etypes; 247 krb5_enctype *etypes_des; 248 char **default_realms; 249 time_t max_skew; 250 time_t kdc_timeout; 251 unsigned max_retries; 252 int32_t kdc_sec_offset; 253 int32_t kdc_usec_offset; 254 krb5_config_section *cf; 255 struct et_list *et_list; 256 struct krb5_log_facility *warn_dest; 257 struct krb5_log_facility *debug_dest; 258 const krb5_cc_ops **cc_ops; 259 int num_cc_ops; 260 const char *http_proxy; 261 const char *time_fmt; 262 krb5_boolean log_utc; 263 const char *default_keytab; 264 const char *default_keytab_modify; 265 krb5_boolean use_admin_kdc; 266 krb5_addresses *extra_addresses; 267 krb5_boolean scan_interfaces; /* `ifconfig -a' */ 268 krb5_boolean srv_lookup; /* do SRV lookups */ 269 krb5_boolean srv_try_txt; /* try TXT records also */ 270 int32_t fcache_vno; /* create cache files w/ this 271 version */ 272 int num_kt_types; /* # of registered keytab types */ 273 struct krb5_keytab_data *kt_types; /* registered keytab types */ 274 const char *date_fmt; 275 char *error_string; 276 krb5_error_code error_code; 277 krb5_addresses *ignore_addresses; 278 char *default_cc_name; 279 char *default_cc_name_env; 280 int default_cc_name_set; 281 void *mutex; /* protects error_string/error_buf */ 282 int large_msg_size; 283 int flags; 284 #define KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME 1 285 #define KRB5_CTX_F_CHECK_PAC 2 286 #define KRB5_CTX_F_HOMEDIR_ACCESS 4 287 #define KRB5_CTX_F_SOCKETS_INITIALIZED 8 288 #define KRB5_CTX_F_RD_REQ_IGNORE 16 289 struct send_to_kdc *send_to_kdc; 290 #ifdef PKINIT 291 hx509_context hx509ctx; 292 #endif 293 } krb5_context_data; 294 295 #ifndef KRB5_USE_PATH_TOKENS 296 #define KRB5_DEFAULT_CCNAME_FILE "FILE:/tmp/krb5cc_%{uid}" 297 #else 298 #define KRB5_DEFAULT_CCNAME_FILE "FILE:%{TEMP}/krb5cc_%{uid}" 299 #endif 300 #define KRB5_DEFAULT_CCNAME_API "API:" 301 #define KRB5_DEFAULT_CCNAME_KCM_KCM "KCM:%{uid}" 302 #define KRB5_DEFAULT_CCNAME_KCM_API "API:%{uid}" 303 304 #define EXTRACT_TICKET_ALLOW_CNAME_MISMATCH 1 305 #define EXTRACT_TICKET_ALLOW_SERVER_MISMATCH 2 306 #define EXTRACT_TICKET_MATCH_REALM 4 307 #define EXTRACT_TICKET_AS_REQ 8 308 #define EXTRACT_TICKET_TIMESYNC 16 309 310 /* 311 * Configurable options 312 */ 313 314 #ifndef KRB5_DEFAULT_CCTYPE 315 #ifdef __APPLE__ 316 #define KRB5_DEFAULT_CCTYPE (&krb5_acc_ops) 317 #else 318 #define KRB5_DEFAULT_CCTYPE (&krb5_fcc_ops) 319 #endif 320 #endif 321 322 #ifndef KRB5_ADDRESSLESS_DEFAULT 323 #define KRB5_ADDRESSLESS_DEFAULT TRUE 324 #endif 325 326 #ifndef KRB5_FORWARDABLE_DEFAULT 327 #define KRB5_FORWARDABLE_DEFAULT TRUE 328 #endif 329 330 #ifdef PKINIT 331 332 struct krb5_pk_identity { 333 hx509_verify_ctx verify_ctx; 334 hx509_certs certs; 335 hx509_cert cert; 336 hx509_certs anchors; 337 hx509_certs certpool; 338 hx509_revoke_ctx revokectx; 339 int flags; 340 #define PKINIT_BTMM 1 341 }; 342 343 enum krb5_pk_type { 344 PKINIT_WIN2K = 1, 345 PKINIT_27 = 2 346 }; 347 348 #endif /* PKINIT */ 349 350 #endif /* __KRB5_LOCL_H__ */ 351