3e724c29a5d4a2e34e937934122ef17d1f3136b3
[jelmer/samba4-debian.git] / source / 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 #include "auth/credentials/credentials.h"
25 #include "auth/kerberos/krb5_init_context.h"
26 #include "librpc/gen_ndr/krb5pac.h"
27
28 struct auth_serversupplied_info;
29
30 struct ccache_container {
31         struct smb_krb5_context *smb_krb5_context;
32         krb5_ccache ccache;
33 };
34
35
36 struct gssapi_creds_container {
37         gss_cred_id_t creds;
38 };
39
40
41 struct keytab_container {
42         struct smb_krb5_context *smb_krb5_context;
43         krb5_keytab keytab;
44 };
45
46 /* not really ASN.1, but RFC 1964 */
47 #define TOK_ID_KRB_AP_REQ       ((const uint8_t *)"\x01\x00")
48 #define TOK_ID_KRB_AP_REP       ((const uint8_t *)"\x02\x00")
49 #define TOK_ID_KRB_ERROR        ((const uint8_t *)"\x03\x00")
50 #define TOK_ID_GSS_GETMIC       ((const uint8_t *)"\x01\x01")
51 #define TOK_ID_GSS_WRAP         ((const uint8_t *)"\x02\x01")
52
53 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE
54 #define KRB5_KEY_TYPE(k)        ((k)->keytype)
55 #define KRB5_KEY_LENGTH(k)      ((k)->keyvalue.length)
56 #define KRB5_KEY_DATA(k)        ((k)->keyvalue.data)
57 #else
58 #define KRB5_KEY_TYPE(k)        ((k)->enctype)
59 #define KRB5_KEY_LENGTH(k)      ((k)->length)
60 #define KRB5_KEY_DATA(k)        ((k)->contents)
61 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
62
63 #ifndef HAVE_KRB5_SET_REAL_TIME
64 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
65 #endif
66
67 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
68 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
69 #endif
70
71 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
72 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
73 #endif
74
75 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
76 void krb5_free_unparsed_name(krb5_context ctx, char *val);
77 #endif
78
79 #if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT)
80 const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i );
81 #endif
82
83 /* Samba wrapper function for krb5 functionality. */
84 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
85 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
86 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
87 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
88 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
89 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
90 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
91 krb5_error_code ads_krb5_mk_req(krb5_context context, 
92                                 krb5_auth_context *auth_context, 
93                                 const krb5_flags ap_req_options,
94                                 const char *principal,
95                                 krb5_ccache ccache, 
96                                 krb5_data *outbuf);
97 BOOL get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, krb5_ticket *tkt);
98  NTSTATUS ads_verify_ticket(TALLOC_CTX *mem_ctx, 
99                             struct smb_krb5_context *smb_krb5_context,
100                             krb5_auth_context *auth_context,
101                             struct cli_credentials *machine_account,
102                             const char *service, 
103                             const DATA_BLOB *enc_ticket, 
104                             krb5_ticket **tkt,
105                             DATA_BLOB *ap_rep,
106                             krb5_keyblock **keyblock);
107 int kerberos_kinit_password_cc(krb5_context ctx, krb5_ccache cc, 
108                                krb5_principal principal, const char *password, 
109                                time_t *expire_time, time_t *kdc_time);
110 int kerberos_kinit_keyblock_cc(krb5_context ctx, krb5_ccache cc, 
111                                krb5_principal principal, krb5_keyblock *keyblock,
112                                time_t *expire_time, time_t *kdc_time);
113 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context,
114                                                         krb5_principal host_princ,
115                                                         int enctype);
116 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
117 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
118 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
119 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
120 char *smb_get_krb5_error_message(krb5_context context, krb5_error_code code, TALLOC_CTX *mem_ctx);
121  krb5_error_code kinit_to_ccache(TALLOC_CTX *parent_ctx,
122                           struct cli_credentials *credentials,
123                           struct smb_krb5_context *smb_krb5_context,
124                                  krb5_ccache ccache);
125 krb5_error_code principal_from_credentials(TALLOC_CTX *parent_ctx, 
126                                            struct cli_credentials *credentials, 
127                                            struct smb_krb5_context *smb_krb5_context,
128                                            krb5_principal *princ);
129 NTSTATUS kerberos_decode_pac(TALLOC_CTX *mem_ctx,
130                              struct PAC_DATA **pac_data_out,
131                              DATA_BLOB blob,
132                              krb5_context context,
133                              krb5_keyblock *krbtgt_keyblock,
134                              krb5_keyblock *service_keyblock,
135                              krb5_const_principal client_principal,
136                              time_t tgs_authtime,
137                              krb5_error_code *k5ret);
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_const_principal client_principal,
145                                   time_t tgs_authtime, 
146                                   krb5_error_code *k5ret);
147  krb5_error_code kerberos_encode_pac(TALLOC_CTX *mem_ctx,
148                                     struct PAC_DATA *pac_data,
149                                     krb5_context context,
150                                     krb5_keyblock *krbtgt_keyblock,
151                                     krb5_keyblock *service_keyblock,
152                                      DATA_BLOB *pac) ;
153  krb5_error_code kerberos_create_pac(TALLOC_CTX *mem_ctx,
154                                      struct auth_serversupplied_info *server_info,
155                                      krb5_context context,
156                                      krb5_keyblock *krbtgt_keyblock,
157                                      krb5_keyblock *service_keyblock,
158                                      krb5_principal client_principal,
159                                      time_t tgs_authtime,
160                                      DATA_BLOB *pac);
161
162  int cli_credentials_set_client_gss_creds(struct cli_credentials *cred, 
163                                           gss_cred_id_t gssapi_cred,
164                                           enum credentials_obtained obtained); 
165
166 #include "auth/kerberos/proto.h"
167
168 #endif /* HAVE_KRB5 */