r9728: A *major* update to the credentials system, to incorporate the
[samba.git] / source4 / auth / kerberos / kerberos.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    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #if defined(HAVE_KRB5)
23
24 #if defined(HAVE_KRB5_INITLOG) && defined(HAVE_KRB5_ADDLOG_FUNC) && defined (HAVE_KRB5_SET_WARN_DEST) && defined(HAVE_KRB5_LOG_FACILITY)
25 #define HAVE_KRB5_LOG_CONTROL
26 #else
27 #undef HAVE_KRB5_LOG_CONTROL
28 #endif
29
30 struct smb_krb5_context {
31         krb5_context krb5_context;
32 #ifdef HAVE_KRB5_LOG_CONTROL
33         krb5_log_facility *logf;
34 #endif
35 };
36         
37 struct ccache_container {
38         struct smb_krb5_context *smb_krb5_context;
39         krb5_ccache ccache;
40 };
41
42 /* not really ASN.1, but RFC 1964 */
43 #define TOK_ID_KRB_AP_REQ       "\x01\x00"
44 #define TOK_ID_KRB_AP_REP       "\x02\x00"
45 #define TOK_ID_KRB_ERROR        "\x03\x00"
46 #define TOK_ID_GSS_GETMIC       "\x01\x01"
47 #define TOK_ID_GSS_WRAP         "\x02\x01"
48
49 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE
50 #define KRB5_KEY_TYPE(k)        ((k)->keytype)
51 #define KRB5_KEY_LENGTH(k)      ((k)->keyvalue.length)
52 #define KRB5_KEY_DATA(k)        ((k)->keyvalue.data)
53 #else
54 #define KRB5_KEY_TYPE(k)        ((k)->enctype)
55 #define KRB5_KEY_LENGTH(k)      ((k)->length)
56 #define KRB5_KEY_DATA(k)        ((k)->contents)
57 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
58
59 #ifndef HAVE_KRB5_SET_REAL_TIME
60 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
61 #endif
62
63 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
64 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
65 #endif
66
67 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
68 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
69 #endif
70
71 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
72 void krb5_free_unparsed_name(krb5_context ctx, char *val);
73 #endif
74
75 #if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT)
76 const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i );
77 #endif
78
79 /* Samba wrapper function for krb5 functionality. */
80 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
81 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
82 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
83 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
84 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
85 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
86 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
87 krb5_error_code ads_krb5_mk_req(krb5_context context, 
88                                 krb5_auth_context *auth_context, 
89                                 const krb5_flags ap_req_options,
90                                 const char *principal,
91                                 krb5_ccache ccache, 
92                                 krb5_data *outbuf);
93 DATA_BLOB get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, 
94                                  krb5_ticket *tkt);
95
96 NTSTATUS ads_verify_ticket(TALLOC_CTX *mem_ctx, 
97                            struct smb_krb5_context *smb_krb5_context,
98                            krb5_auth_context auth_context,
99                            const char *realm, const char *service, 
100                            const DATA_BLOB *ticket, 
101                            char **principal, DATA_BLOB *auth_data,
102                            DATA_BLOB *ap_rep,
103                            krb5_keyblock **keyblock);
104 int kerberos_kinit_password_cc(krb5_context ctx, krb5_ccache cc, 
105                                const char *principal, const char *password, 
106                                time_t *expire_time, time_t *kdc_time);
107 int kerberos_kinit_keyblock_cc(krb5_context ctx, krb5_ccache cc, 
108                                const char *principal, krb5_keyblock *keyblock,
109                                time_t *expire_time, time_t *kdc_time);
110 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context,
111                                                         krb5_principal host_princ,
112                                                         int enctype);
113 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
114 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
115 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
116 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
117 char *smb_get_krb5_error_message(krb5_context context, krb5_error_code code, TALLOC_CTX *mem_ctx);
118  krb5_error_code kinit_to_ccache(TALLOC_CTX *parent_ctx,
119                           struct cli_credentials *credentials,
120                           struct smb_krb5_context *smb_krb5_context,
121                                  krb5_ccache ccache);
122 krb5_error_code smb_krb5_init_context(TALLOC_CTX *parent_ctx, 
123                                       struct smb_krb5_context **smb_krb5_context); 
124 krb5_error_code salt_principal_from_credentials(TALLOC_CTX *parent_ctx, 
125                                                 struct cli_credentials *machine_account, 
126                                                 struct smb_krb5_context *smb_krb5_context,
127                                                 krb5_principal *salt_princ);
128 NTSTATUS create_memory_keytab(TALLOC_CTX *parent_ctx,
129                               struct cli_credentials *machine_account,
130                               struct smb_krb5_context *smb_krb5_context,
131                               krb5_keytab *keytab);
132 NTSTATUS kerberos_decode_pac(TALLOC_CTX *mem_ctx,
133                              struct PAC_DATA **pac_data_out,
134                              DATA_BLOB blob,
135                              krb5_context context,
136                              krb5_keyblock *krbtgt_keyblock,
137                              krb5_keyblock *service_keyblock);
138 NTSTATUS kerberos_pac_logon_info(TALLOC_CTX *mem_ctx,
139                                  struct PAC_LOGON_INFO **logon_info,
140                                  DATA_BLOB blob,
141                                  krb5_context context,
142                                  krb5_keyblock *krbtgt_keyblock,
143                                  krb5_keyblock *service_keyblock);
144 krb5_error_code kerberos_create_pac(TALLOC_CTX *mem_ctx,
145                                     struct auth_serversupplied_info *server_info,
146                                     krb5_context context,
147                                     krb5_keyblock *krbtgt_keyblock,
148                                     krb5_keyblock *server_keyblock,
149                                     time_t tgs_authtime,
150                                     DATA_BLOB *pac);
151
152 krb5_error_code kerberos_encode_pac(TALLOC_CTX *mem_ctx,
153                                     struct PAC_DATA *pac_data,
154                                     krb5_context context,
155                                     krb5_keyblock *krbtgt_keyblock,
156                                     krb5_keyblock *service_keyblock,
157                                     DATA_BLOB *pac);
158 #endif /* HAVE_KRB5 */
159