s3:smbd/smb2_read improve debug message
[Samba/gebeck_regimport.git] / lib / krb5_wrap / krb5_samba.h
blob8d55a32f154f51e864fd455979947a12c6cd4a35
1 /*
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/>.
23 #ifndef _KRB5_SAMBA_H
24 #define _KRB5_SAMBA_H
26 #ifdef HAVE_KRB5
28 #define KRB5_PRIVATE 1 /* this file uses PRIVATE interfaces! */
29 /* this file uses DEPRECATED interfaces! */
31 #ifdef KRB5_DEPRECATED
32 #undef KRB5_DEPRECATED
33 #endif
35 #if defined(HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER)
36 #define KRB5_DEPRECATED 1
37 #else
38 #define KRB5_DEPRECATED
39 #endif
41 #include "system/kerberos.h"
42 #include "system/network.h"
44 #ifndef KRB5_ADDR_NETBIOS
45 #define KRB5_ADDR_NETBIOS 0x14
46 #endif
48 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
49 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
50 #endif
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
55 #endif
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
58 #endif
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
65 #endif
67 #ifndef krb5_princ_size
68 #if defined(HAVE_KRB5_KRB5_PRINCIPAL_GET_NUM_COMP)
69 #define krb5_princ_size krb5_principal_get_num_comp
70 #else
71 #error krb5_princ_size unavailable
72 #endif
73 #endif
75 typedef struct {
76 #if defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) /* MIT */
77 krb5_address **addrs;
78 #elif defined(HAVE_KRB5_ADDRESSES) /* Heimdal */
79 krb5_addresses *addrs;
80 #else
81 #error UNKNOWN_KRB5_ADDRESS_TYPE
82 #endif /* defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) */
83 } smb_krb5_addresses;
85 #ifdef HAVE_KRB5_KEYTAB_ENTRY_KEY /* MIT */
86 #define KRB5_KT_KEY(k) (&(k)->key)
87 #elif HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK /* Heimdal */
88 #define KRB5_KT_KEY(k) (&(k)->keyblock)
89 #else
90 #error krb5_keytab_entry has no key or keyblock member
91 #endif /* HAVE_KRB5_KEYTAB_ENTRY_KEY */
93 /* work around broken krb5.h on sles9 */
94 #ifdef SIZEOF_LONG
95 #undef SIZEOF_LONG
96 #endif
98 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE /* Heimdal */
99 #define KRB5_KEY_TYPE(k) ((k)->keytype)
100 #define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length)
101 #define KRB5_KEY_DATA(k) ((k)->keyvalue.data)
102 #define KRB5_KEY_DATA_CAST void
103 #else /* MIT */
104 #define KRB5_KEY_TYPE(k) ((k)->enctype)
105 #define KRB5_KEY_LENGTH(k) ((k)->length)
106 #define KRB5_KEY_DATA(k) ((k)->contents)
107 #define KRB5_KEY_DATA_CAST krb5_octet
108 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
110 krb5_error_code smb_krb5_parse_name(krb5_context context,
111 const char *name, /* in unix charset */
112 krb5_principal *principal);
114 krb5_error_code smb_krb5_unparse_name(TALLOC_CTX *mem_ctx,
115 krb5_context context,
116 krb5_const_principal principal,
117 char **unix_name);
119 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
121 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
122 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
123 #endif
125 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
126 void krb5_free_unparsed_name(krb5_context ctx, char *val);
127 #endif
129 /* Stub out initialize_krb5_error_table since it is not present in all
130 * Kerberos implementations. If it's not present, it's not necessary to
131 * call it.
133 #ifndef HAVE_INITIALIZE_KRB5_ERROR_TABLE
134 #define initialize_krb5_error_table()
135 #endif
137 /* Samba wrapper functions for krb5 functionality. */
138 bool setup_kaddr( krb5_address *pkaddr, struct sockaddr_storage *paddr);
139 int create_kerberos_key_from_string(krb5_context context,
140 krb5_principal host_princ,
141 krb5_data *password,
142 krb5_keyblock *key,
143 krb5_enctype enctype,
144 bool no_salt);
145 int create_kerberos_key_from_string_direct(krb5_context context,
146 krb5_principal host_princ,
147 krb5_data *password,
148 krb5_keyblock *key,
149 krb5_enctype enctype);
151 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
152 bool get_krb5_smb_session_key(TALLOC_CTX *mem_ctx,
153 krb5_context context,
154 krb5_auth_context auth_context,
155 DATA_BLOB *session_key, bool remote);
156 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
157 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
158 bool kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
159 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
160 krb5_error_code smb_krb5_parse_name_norealm(krb5_context context,
161 const char *name,
162 krb5_principal *principal);
163 bool smb_krb5_principal_compare_any_realm(krb5_context context,
164 krb5_const_principal princ1,
165 krb5_const_principal princ2);
166 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *expire_time);
167 krb5_error_code kpasswd_err_to_krb5_err(krb5_error_code res_code);
168 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr,
169 const char *netbios_name);
170 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
171 NTSTATUS krb5_to_nt_status(krb5_error_code kerberos_error);
172 krb5_error_code nt_status_to_krb5(NTSTATUS nt_status);
173 void smb_krb5_free_error(krb5_context context, krb5_error *krberror);
174 krb5_error_code handle_krberror_packet(krb5_context context,
175 krb5_data *packet);
177 void smb_krb5_get_init_creds_opt_free(krb5_context context,
178 krb5_get_init_creds_opt *opt);
179 krb5_error_code smb_krb5_get_init_creds_opt_alloc(krb5_context context,
180 krb5_get_init_creds_opt **opt);
181 krb5_enctype smb_get_enctype_from_kt_entry(krb5_keytab_entry *kt_entry);
182 krb5_error_code smb_krb5_enctype_to_string(krb5_context context,
183 krb5_enctype enctype,
184 char **etype_s);
185 krb5_error_code smb_krb5_open_keytab(krb5_context context,
186 const char *keytab_name,
187 bool write_access,
188 krb5_keytab *keytab);
189 krb5_error_code smb_krb5_keytab_name(TALLOC_CTX *mem_ctx,
190 krb5_context context,
191 krb5_keytab keytab,
192 const char **keytab_name);
193 krb5_error_code smb_krb5_get_credentials(krb5_context context,
194 krb5_ccache ccache,
195 krb5_principal me,
196 krb5_principal server,
197 krb5_principal impersonate_princ,
198 krb5_creds **out_creds);
199 krb5_error_code smb_krb5_get_creds(const char *server_s,
200 time_t time_offset,
201 const char *cc,
202 const char *impersonate_princ_s,
203 krb5_creds **creds_p);
204 krb5_error_code smb_krb5_keyblock_init_contents(krb5_context context,
205 krb5_enctype enctype,
206 const void *data,
207 size_t length,
208 krb5_keyblock *key);
209 krb5_error_code kerberos_kinit_keyblock_cc(krb5_context ctx, krb5_ccache cc,
210 krb5_principal principal,
211 krb5_keyblock *keyblock,
212 const char *target_service,
213 krb5_get_init_creds_opt *krb_options,
214 time_t *expire_time,
215 time_t *kdc_time);
216 krb5_error_code kerberos_kinit_password_cc(krb5_context ctx,
217 krb5_ccache cc,
218 krb5_principal principal,
219 const char *password,
220 const char *target_service,
221 krb5_get_init_creds_opt *krb_options,
222 time_t *expire_time,
223 time_t *kdc_time);
224 #ifdef SAMBA4_USES_HEIMDAL
225 krb5_error_code kerberos_kinit_s4u2_cc(krb5_context ctx,
226 krb5_ccache store_cc,
227 krb5_principal init_principal,
228 const char *init_password,
229 krb5_principal impersonate_principal,
230 const char *self_service,
231 const char *target_service,
232 krb5_get_init_creds_opt *krb_options,
233 time_t *expire_time,
234 time_t *kdc_time);
235 #endif
237 #if defined(HAVE_KRB5_MAKE_PRINCIPAL)
238 #define smb_krb5_make_principal krb5_make_principal
239 #elif defined(HAVE_KRB5_BUILD_PRINCIPAL_ALLOC_VA)
240 krb5_error_code smb_krb5_make_principal(krb5_context context,
241 krb5_principal *principal,
242 const char *realm, ...);
243 #else
244 #error krb5_make_principal not available
245 #endif
247 #if defined(HAVE_KRB5_CC_GET_LIFETIME)
248 #define smb_krb5_cc_get_lifetime krb5_cc_get_lifetime
249 #elif defined(HAVE_KRB5_CC_RETRIEVE_CRED)
250 krb5_error_code smb_krb5_cc_get_lifetime(krb5_context context,
251 krb5_ccache id,
252 time_t *t);
253 #else
254 #error krb5_cc_get_lifetime not available
255 #endif
257 #if defined(HAVE_KRB5_FREE_CHECKSUM_CONTENTS)
258 #define smb_krb5_free_checksum_contents krb5_free_checksum_contents
259 #elif defined (HAVE_FREE_CHECKSUM)
260 void smb_krb5_free_checksum_contents(krb5_context ctx, krb5_checksum *cksum);
261 #else
262 #error krb5_free_checksum_contents/free_Checksum is not vailable
263 #endif
265 krb5_error_code smb_krb5_make_pac_checksum(TALLOC_CTX *mem_ctx,
266 DATA_BLOB *pac_data,
267 krb5_context context,
268 const krb5_keyblock *keyblock,
269 uint32_t *sig_type,
270 DATA_BLOB *sig_blob);
272 char *smb_krb5_principal_get_realm(krb5_context context,
273 krb5_principal principal);
275 char *kerberos_get_principal_from_service_hostname(TALLOC_CTX *mem_ctx,
276 const char *service,
277 const char *remote_name,
278 const char *default_realm);
280 char *smb_get_krb5_error_message(krb5_context context,
281 krb5_error_code code,
282 TALLOC_CTX *mem_ctx);
284 bool unwrap_edata_ntstatus(TALLOC_CTX *mem_ctx,
285 DATA_BLOB *edata,
286 DATA_BLOB *edata_out);
289 krb5_error_code kt_copy(krb5_context context,
290 const char *from,
291 const char *to);
292 krb5_error_code kt_copy_one_principal(krb5_context context,
293 const char *from,
294 const char *to,
295 const char *principal,
296 krb5_kvno kvno,
297 krb5_enctype *enctypes);
299 #if defined(HAVE_KRB5_KT_COMPARE)
300 #define smb_krb5_kt_compare krb5_kt_compare
301 #else
302 krb5_boolean smb_krb5_kt_compare(krb5_context context,
303 krb5_keytab_entry *entry,
304 krb5_const_principal principal,
305 krb5_kvno vno,
306 krb5_enctype enctype);
307 #endif
309 #endif /* HAVE_KRB5 */
311 int cli_krb5_get_ticket(TALLOC_CTX *mem_ctx,
312 const char *principal, time_t time_offset,
313 DATA_BLOB *ticket, DATA_BLOB *session_key_krb5,
314 uint32_t extra_ap_opts, const char *ccname,
315 time_t *tgs_expire,
316 const char *impersonate_princ_s);
318 #endif /* _KRB5_SAMBA_H */