3800b024adb5cb14482264205380d9816e7270ea
[kai/samba.git] / lib / krb5_wrap / krb5_samba.h
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
8
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.
13
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.
18
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/>.
21 */
22
23 #ifndef _KRB5_SAMBA_H
24 #define _KRB5_SAMBA_H
25
26 #ifdef HAVE_KRB5
27
28 #define KRB5_PRIVATE    1       /* this file uses PRIVATE interfaces! */
29 /* this file uses DEPRECATED interfaces! */
30
31 #if defined(HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER)
32 #define KRB5_DEPRECATED 1
33 #else
34 #define KRB5_DEPRECATED
35 #endif
36
37 #include "system/kerberos.h"
38 #include "system/network.h"
39
40 #ifndef KRB5_ADDR_NETBIOS
41 #define KRB5_ADDR_NETBIOS 0x14
42 #endif
43
44 #ifndef KRB5KRB_ERR_RESPONSE_TOO_BIG
45 #define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
46 #endif
47
48 /* Heimdal uses a slightly different name */
49 #if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5) && !defined(HAVE_ENCTYPE_ARCFOUR_HMAC)
50 #define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5
51 #endif
52
53 /* The older versions of heimdal that don't have this
54    define don't seem to use it anyway.  I'm told they
55    always use a subkey */
56 #ifndef HAVE_AP_OPTS_USE_SUBKEY
57 #define AP_OPTS_USE_SUBKEY 0
58 #endif
59
60 typedef struct {
61 #if defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) /* MIT */
62         krb5_address **addrs;
63 #elif defined(HAVE_KRB5_ADDRESSES) /* Heimdal */
64         krb5_addresses *addrs;
65 #else
66 #error UNKNOWN_KRB5_ADDRESS_TYPE
67 #endif /* defined(HAVE_MAGIC_IN_KRB5_ADDRESS) && defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) */
68 } smb_krb5_addresses;
69
70 #ifdef HAVE_KRB5_KEYTAB_ENTRY_KEY               /* MIT */
71 #define KRB5_KT_KEY(k)          (&(k)->key)
72 #elif HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK          /* Heimdal */
73 #define KRB5_KT_KEY(k)          (&(k)->keyblock)
74 #else
75 #error krb5_keytab_entry has no key or keyblock member
76 #endif /* HAVE_KRB5_KEYTAB_ENTRY_KEY */
77
78 /* work around broken krb5.h on sles9 */
79 #ifdef SIZEOF_LONG
80 #undef SIZEOF_LONG
81 #endif
82
83 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE /* Heimdal */
84 #define KRB5_KEY_TYPE(k)        ((k)->keytype)
85 #define KRB5_KEY_LENGTH(k)      ((k)->keyvalue.length)
86 #define KRB5_KEY_DATA(k)        ((k)->keyvalue.data)
87 #define KRB5_KEY_DATA_CAST      void
88 #else /* MIT */
89 #define KRB5_KEY_TYPE(k)        ((k)->enctype)
90 #define KRB5_KEY_LENGTH(k)      ((k)->length)
91 #define KRB5_KEY_DATA(k)        ((k)->contents)
92 #define KRB5_KEY_DATA_CAST      krb5_octet
93 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
94
95 krb5_error_code smb_krb5_parse_name(krb5_context context,
96                                 const char *name, /* in unix charset */
97                                 krb5_principal *principal);
98
99 krb5_error_code smb_krb5_unparse_name(TALLOC_CTX *mem_ctx,
100                                       krb5_context context,
101                                       krb5_const_principal principal,
102                                       char **unix_name);
103
104 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
105
106 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
107 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
108 #endif
109
110 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
111 void krb5_free_unparsed_name(krb5_context ctx, char *val);
112 #endif
113
114 /* Stub out initialize_krb5_error_table since it is not present in all
115  * Kerberos implementations. If it's not present, it's not necessary to
116  * call it.
117  */
118 #ifndef HAVE_INITIALIZE_KRB5_ERROR_TABLE
119 #define initialize_krb5_error_table()
120 #endif
121
122 /* Samba wrapper functions for krb5 functionality. */
123 bool setup_kaddr( krb5_address *pkaddr, struct sockaddr_storage *paddr);
124 int create_kerberos_key_from_string(krb5_context context,
125                                     krb5_principal host_princ,
126                                     krb5_data *password,
127                                     krb5_keyblock *key,
128                                     krb5_enctype enctype,
129                                     bool no_salt);
130 int create_kerberos_key_from_string_direct(krb5_context context,
131                                            krb5_principal host_princ,
132                                            krb5_data *password,
133                                            krb5_keyblock *key,
134                                            krb5_enctype enctype);
135
136 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
137 bool get_krb5_smb_session_key(TALLOC_CTX *mem_ctx,
138                               krb5_context context,
139                               krb5_auth_context auth_context,
140                               DATA_BLOB *session_key, bool remote);
141 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
142 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
143 bool kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
144 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
145 krb5_error_code smb_krb5_parse_name_norealm(krb5_context context,
146                                             const char *name,
147                                             krb5_principal *principal);
148 bool smb_krb5_principal_compare_any_realm(krb5_context context,
149                                           krb5_const_principal princ1,
150                                           krb5_const_principal princ2);
151 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *expire_time);
152 krb5_error_code kpasswd_err_to_krb5_err(krb5_error_code res_code);
153 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr,
154                                                   const char *netbios_name);
155 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
156 NTSTATUS krb5_to_nt_status(krb5_error_code kerberos_error);
157 krb5_error_code nt_status_to_krb5(NTSTATUS nt_status);
158 void smb_krb5_free_error(krb5_context context, krb5_error *krberror);
159 krb5_error_code handle_krberror_packet(krb5_context context,
160                                          krb5_data *packet);
161
162 void smb_krb5_get_init_creds_opt_free(krb5_context context,
163                                     krb5_get_init_creds_opt *opt);
164 krb5_error_code smb_krb5_get_init_creds_opt_alloc(krb5_context context,
165                                     krb5_get_init_creds_opt **opt);
166 krb5_enctype smb_get_enctype_from_kt_entry(krb5_keytab_entry *kt_entry);
167 krb5_error_code smb_krb5_enctype_to_string(krb5_context context,
168                                             krb5_enctype enctype,
169                                             char **etype_s);
170 krb5_error_code smb_krb5_open_keytab(krb5_context context,
171                                       const char *keytab_name,
172                                       bool write_access,
173                                       krb5_keytab *keytab);
174 krb5_error_code smb_krb5_keytab_name(TALLOC_CTX *mem_ctx,
175                                      krb5_context context,
176                                      krb5_keytab keytab,
177                                      const char **keytab_name);
178 krb5_error_code smb_krb5_get_credentials(krb5_context context,
179                                          krb5_ccache ccache,
180                                          krb5_principal me,
181                                          krb5_principal server,
182                                          krb5_principal impersonate_princ,
183                                          krb5_creds **out_creds);
184 krb5_error_code smb_krb5_get_creds(const char *server_s,
185                                    time_t time_offset,
186                                    const char *cc,
187                                    const char *impersonate_princ_s,
188                                    krb5_creds **creds_p);
189 char *smb_krb5_principal_get_realm(krb5_context context,
190                                    krb5_principal principal);
191
192 char *kerberos_get_principal_from_service_hostname(TALLOC_CTX *mem_ctx,
193                                                    const char *service,
194                                                    const char *remote_name,
195                                                    const char *default_realm);
196
197 char *smb_get_krb5_error_message(krb5_context context,
198                                  krb5_error_code code,
199                                  TALLOC_CTX *mem_ctx);
200
201 int cli_krb5_get_ticket(TALLOC_CTX *mem_ctx,
202                         const char *principal, time_t time_offset,
203                         DATA_BLOB *ticket, DATA_BLOB *session_key_krb5,
204                         uint32_t extra_ap_opts, const char *ccname,
205                         time_t *tgs_expire,
206                         const char *impersonate_princ_s);
207
208 bool unwrap_edata_ntstatus(TALLOC_CTX *mem_ctx,
209                            DATA_BLOB *edata,
210                            DATA_BLOB *edata_out);
211
212 #endif /* HAVE_KRB5 */
213
214
215 #endif /* _KRB5_SAMBA_H */