2 Unix SMB/CIFS implementation.
3 simple kerberos5 routines for active directory
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Luke Howard 2002-2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
7 Copyright (C) Guenther Deschner 2005-2009
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #define KRB5_PRIVATE 1 /* this file uses PRIVATE interfaces! */
29 /* this file uses DEPRECATED interfaces! */
31 #ifdef KRB5_DEPRECATED
32 #undef KRB5_DEPRECATED
35 #if defined(HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER)
36 #define KRB5_DEPRECATED 1
38 #define KRB5_DEPRECATED
41 #include "system/kerberos.h"
42 #include "system/network.h"
44 #ifndef KRB5_ADDR_NETBIOS
45 #define KRB5_ADDR_NETBIOS 0x14
48 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
49 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
52 /* Heimdal uses a slightly different name */
53 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5) && !defined(HAVE_ENCTYPE_ARCFOUR_HMAC)
54 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
56 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5_56) && !defined(HAVE_ENCTYPE_ARCFOUR_HMAC_EXP)
57 #define ENCTYPE_ARCFOUR_HMAC_EXP ENCTYPE_ARCFOUR_HMAC_MD5_56
60 /* The older versions of heimdal that don't have this
61 define don't seem to use it anyway. I'm told they
62 always use a subkey */
63 #ifndef HAVE_AP_OPTS_USE_SUBKEY
64 #define AP_OPTS_USE_SUBKEY 0
68 #define KRB5_PW_SALT 3
71 /* CKSUMTYPE_HMAC_MD5 in Heimdal
72 CKSUMTYPE_HMAC_MD5_ARCFOUR in MIT */
73 #if defined(CKSUMTYPE_HMAC_MD5_ARCFOUR) && !defined(CKSUMTYPE_HMAC_MD5)
74 #define CKSUMTYPE_HMAC_MD5 CKSUMTYPE_HMAC_MD5_ARCFOUR
78 * CKSUMTYPE_HMAC_SHA1_96_AES_* in Heimdal
79 * CKSUMTYPE_HMAC_SHA1_96_AES* in MIT
81 #if defined(CKSUMTYPE_HMAC_SHA1_96_AES128) && !defined(CKSUMTYPE_HMAC_SHA1_96_AES_128)
82 #define CKSUMTYPE_HMAC_SHA1_96_AES_128 CKSUMTYPE_HMAC_SHA1_96_AES128
84 #if defined(CKSUMTYPE_HMAC_SHA1_96_AES256) && !defined(CKSUMTYPE_HMAC_SHA1_96_AES_256)
85 #define CKSUMTYPE_HMAC_SHA1_96_AES_256 CKSUMTYPE_HMAC_SHA1_96_AES256
89 * KRB5_KU_OTHER_ENCRYPTED in Heimdal
90 * KRB5_KEYUSAGE_APP_DATA_ENCRYPT in MIT
92 #if defined(KRB5_KEYUSAGE_APP_DATA_ENCRYPT) && !defined(KRB5_KU_OTHER_ENCRYPTED)
93 #define KRB5_KU_OTHER_ENCRYPTED KRB5_KEYUSAGE_APP_DATA_ENCRYPT
97 #if defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) /* MIT */
99 #elif defined(HAVE_KRB5_ADDRESSES) /* Heimdal */
100 krb5_addresses *addrs;
102 #error UNKNOWN_KRB5_ADDRESS_TYPE
103 #endif /* defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) */
104 } smb_krb5_addresses;
106 #ifdef HAVE_KRB5_KEYTAB_ENTRY_KEY /* MIT */
107 #define KRB5_KT_KEY(k) (&(k)->key)
108 #elif defined(HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK) /* Heimdal */
109 #define KRB5_KT_KEY(k) (&(k)->keyblock)
111 #error krb5_keytab_entry has no key or keyblock member
112 #endif /* HAVE_KRB5_KEYTAB_ENTRY_KEY */
114 /* work around broken krb5.h on sles9 */
119 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE /* Heimdal */
120 #define KRB5_KEY_TYPE(k) ((k)->keytype)
121 #define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length)
122 #define KRB5_KEY_DATA(k) ((k)->keyvalue.data)
123 #define KRB5_KEY_DATA_CAST void
125 #define KRB5_KEY_TYPE(k) ((k)->enctype)
126 #define KRB5_KEY_LENGTH(k) ((k)->length)
127 #define KRB5_KEY_DATA(k) ((k)->contents)
128 #define KRB5_KEY_DATA_CAST krb5_octet
129 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
131 #ifdef HAVE_E_DATA_POINTER_IN_KRB5_ERROR /* Heimdal */
132 #define KRB5_ERROR_CODE(k) ((k)->error_code)
134 #define KRB5_ERROR_CODE(k) ((k)->error)
135 #endif /* HAVE_E_DATA_POINTER_IN_KRB5_ERROR */
137 krb5_error_code smb_krb5_parse_name(krb5_context context,
138 const char *name, /* in unix charset */
139 krb5_principal *principal);
141 krb5_error_code smb_krb5_unparse_name(TALLOC_CTX *mem_ctx,
142 krb5_context context,
143 krb5_const_principal principal,
146 krb5_error_code smb_krb5_init_context_common(krb5_context *_krb5_context);
148 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
150 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
151 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
154 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
155 void krb5_free_unparsed_name(krb5_context ctx, char *val);
158 /* Stub out initialize_krb5_error_table since it is not present in all
159 * Kerberos implementations. If it's not present, it's not necessary to
162 #ifndef HAVE_INITIALIZE_KRB5_ERROR_TABLE
163 #define initialize_krb5_error_table()
166 #ifndef HAVE_KRB5_FREE_STRING
167 #ifdef HAVE_KRB5_XFREE
168 #define krb5_free_string(context, ptr) krb5_xfree(ptr)
170 #error krb5_xfree not available
172 #endif /* HAVE_KRB5_FREE_STRING */
174 /* Samba wrapper functions for krb5 functionality. */
175 bool smb_krb5_sockaddr_to_kaddr(struct sockaddr_storage *paddr,
176 krb5_address *pkaddr);
178 krb5_error_code smb_krb5_mk_error(krb5_context context,
179 krb5_error_code error_code,
182 const krb5_principal client,
183 const krb5_principal server,
186 krb5_error_code smb_krb5_get_allowed_etypes(krb5_context context,
187 krb5_enctype **enctypes);
189 bool smb_krb5_get_smb_session_key(TALLOC_CTX *mem_ctx,
190 krb5_context context,
191 krb5_auth_context auth_context,
192 DATA_BLOB *session_key,
195 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
196 void smb_krb5_free_data_contents(krb5_context context, krb5_data *pdata);
197 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *expire_time);
198 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr,
199 const char *netbios_name);
200 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
201 krb5_enctype smb_krb5_kt_get_enctype_from_entry(krb5_keytab_entry *kt_entry);
203 krb5_error_code smb_krb5_enctype_to_string(krb5_context context,
204 krb5_enctype enctype,
206 krb5_error_code smb_krb5_kt_open_relative(krb5_context context,
207 const char *keytab_name_req,
209 krb5_keytab *keytab);
210 krb5_error_code smb_krb5_kt_open(krb5_context context,
211 const char *keytab_name,
213 krb5_keytab *keytab);
214 krb5_error_code smb_krb5_kt_get_name(TALLOC_CTX *mem_ctx,
215 krb5_context context,
217 const char **keytab_name);
218 krb5_error_code smb_krb5_kt_seek_and_delete_old_entries(krb5_context context,
221 krb5_enctype enctype,
223 krb5_principal princ,
225 bool keep_old_entries);
226 krb5_error_code smb_krb5_kt_add_entry(krb5_context context,
230 const char *salt_principal,
231 krb5_enctype enctype,
234 bool keep_old_entries);
236 krb5_error_code smb_krb5_get_credentials(krb5_context context,
239 krb5_principal server,
240 krb5_principal impersonate_princ,
241 krb5_creds **out_creds);
242 krb5_error_code smb_krb5_keyblock_init_contents(krb5_context context,
243 krb5_enctype enctype,
247 krb5_error_code smb_krb5_kinit_keyblock_ccache(krb5_context ctx,
249 krb5_principal principal,
250 krb5_keyblock *keyblock,
251 const char *target_service,
252 krb5_get_init_creds_opt *krb_options,
255 krb5_error_code smb_krb5_kinit_password_ccache(krb5_context ctx,
257 krb5_principal principal,
258 const char *password,
259 const char *target_service,
260 krb5_get_init_creds_opt *krb_options,
263 #ifdef SAMBA4_USES_HEIMDAL
264 krb5_error_code smb_krb5_kinit_s4u2_ccache(krb5_context ctx,
265 krb5_ccache store_cc,
266 krb5_principal init_principal,
267 const char *init_password,
268 krb5_principal impersonate_principal,
269 const char *self_service,
270 const char *target_service,
271 krb5_get_init_creds_opt *krb_options,
276 #if defined(HAVE_KRB5_MAKE_PRINCIPAL)
277 #define smb_krb5_make_principal krb5_make_principal
278 #elif defined(HAVE_KRB5_BUILD_PRINCIPAL_ALLOC_VA)
279 krb5_error_code smb_krb5_make_principal(krb5_context context,
280 krb5_principal *principal,
281 const char *realm, ...);
283 #error krb5_make_principal not available
286 #if defined(HAVE_KRB5_CC_GET_LIFETIME)
287 #define smb_krb5_cc_get_lifetime krb5_cc_get_lifetime
288 #elif defined(HAVE_KRB5_CC_RETRIEVE_CRED)
289 krb5_error_code smb_krb5_cc_get_lifetime(krb5_context context,
293 #error krb5_cc_get_lifetime not available
296 #if defined(HAVE_KRB5_FREE_CHECKSUM_CONTENTS)
297 #define smb_krb5_free_checksum_contents krb5_free_checksum_contents
298 #elif defined (HAVE_FREE_CHECKSUM)
299 void smb_krb5_free_checksum_contents(krb5_context ctx, krb5_checksum *cksum);
301 #error krb5_free_checksum_contents/free_Checksum is not vailable
304 krb5_error_code smb_krb5_make_pac_checksum(TALLOC_CTX *mem_ctx,
306 krb5_context context,
307 const krb5_keyblock *keyblock,
309 DATA_BLOB *sig_blob);
311 char *smb_krb5_principal_get_realm(TALLOC_CTX *mem_ctx,
312 krb5_context context,
313 krb5_const_principal principal);
315 void smb_krb5_principal_set_type(krb5_context context,
316 krb5_principal principal,
319 krb5_error_code smb_krb5_principal_set_realm(krb5_context context,
320 krb5_principal principal,
323 char *smb_krb5_get_realm_from_hostname(TALLOC_CTX *mem_ctx,
324 const char *hostname,
325 const char *client_realm);
327 char *smb_get_krb5_error_message(krb5_context context,
328 krb5_error_code code,
329 TALLOC_CTX *mem_ctx);
331 krb5_error_code kt_copy(krb5_context context,
334 krb5_error_code kt_copy_one_principal(krb5_context context,
337 const char *principal,
339 const krb5_enctype *enctypes);
341 #if defined(HAVE_KRB5_KT_COMPARE)
342 #define smb_krb5_kt_compare krb5_kt_compare
344 krb5_boolean smb_krb5_kt_compare(krb5_context context,
345 krb5_keytab_entry *entry,
346 krb5_const_principal principal,
348 krb5_enctype enctype);
351 const krb5_enctype *samba_all_enctypes(void);
353 uint32_t kerberos_enctype_to_bitmap(krb5_enctype enc_type_enum);
354 krb5_enctype ms_suptype_to_ietf_enctype(uint32_t enctype_bitmap);
355 krb5_error_code ms_suptypes_to_ietf_enctypes(TALLOC_CTX *mem_ctx,
356 uint32_t enctype_bitmap,
357 krb5_enctype **enctypes);
358 int smb_krb5_get_pw_salt(krb5_context context,
359 krb5_const_principal host_princ,
361 int smb_krb5_salt_principal(const char *realm,
362 const char *sAMAccountName,
363 const char *userPrincipalName,
366 char **_salt_principal);
367 int smb_krb5_salt_principal2data(krb5_context context,
368 const char *salt_principal,
372 int smb_krb5_create_key_from_string(krb5_context context,
373 krb5_const_principal host_princ,
376 krb5_enctype enctype,
379 krb5_boolean smb_krb5_get_allowed_weak_crypto(krb5_context context);
381 #ifndef krb5_princ_size
382 #if defined(HAVE_KRB5_PRINCIPAL_GET_NUM_COMP)
383 #define krb5_princ_size krb5_principal_get_num_comp
385 #error krb5_princ_size unavailable
389 char *smb_krb5_principal_get_comp_string(TALLOC_CTX *mem_ctx,
390 krb5_context context,
391 krb5_const_principal principal,
392 unsigned int component);
394 krb5_error_code smb_krb5_copy_data_contents(krb5_data *p,
398 int smb_krb5_principal_get_type(krb5_context context,
399 krb5_const_principal principal);
401 #if !defined(HAVE_KRB5_WARNX)
402 krb5_error_code krb5_warnx(krb5_context context, const char *fmt, ...);
405 krb5_error_code smb_krb5_cc_copy_creds(krb5_context context,
406 krb5_ccache incc, krb5_ccache outcc);
408 #endif /* HAVE_KRB5 */
410 int ads_krb5_cli_get_ticket(TALLOC_CTX *mem_ctx,
411 const char *principal,
414 DATA_BLOB *session_key_krb5,
415 uint32_t extra_ap_opts, const char *ccname,
417 const char *impersonate_princ_s);
419 #endif /* _KRB5_SAMBA_H */
420 void smb_krb5_dump_creds(int level, krb5_context context, const krb5_creds *creds);
421 void smb_krb5_dump_ccache(int level, krb5_context context, krb5_ccache ccache);
422 void smb_krb5_dump_all_ccaches(int level, const char *location, const char *func);