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
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.
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.
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.
22 #if defined(HAVE_KRB5)
24 #include "auth/kerberos/krb5_init_context.h"
26 struct ccache_container {
27 struct smb_krb5_context *smb_krb5_context;
32 struct keytab_container {
33 struct smb_krb5_context *smb_krb5_context;
37 /* not really ASN.1, but RFC 1964 */
38 #define TOK_ID_KRB_AP_REQ ((const uint8_t *)"\x01\x00")
39 #define TOK_ID_KRB_AP_REP ((const uint8_t *)"\x02\x00")
40 #define TOK_ID_KRB_ERROR ((const uint8_t *)"\x03\x00")
41 #define TOK_ID_GSS_GETMIC ((const uint8_t *)"\x01\x01")
42 #define TOK_ID_GSS_WRAP ((const uint8_t *)"\x02\x01")
44 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE
45 #define KRB5_KEY_TYPE(k) ((k)->keytype)
46 #define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length)
47 #define KRB5_KEY_DATA(k) ((k)->keyvalue.data)
49 #define KRB5_KEY_TYPE(k) ((k)->enctype)
50 #define KRB5_KEY_LENGTH(k) ((k)->length)
51 #define KRB5_KEY_DATA(k) ((k)->contents)
52 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
54 #ifndef HAVE_KRB5_SET_REAL_TIME
55 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
58 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
59 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
62 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
63 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
66 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
67 void krb5_free_unparsed_name(krb5_context ctx, char *val);
70 #if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT)
71 const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i );
74 /* Samba wrapper function for krb5 functionality. */
75 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
76 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
77 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
78 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
79 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
80 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
81 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
82 krb5_error_code ads_krb5_mk_req(krb5_context context,
83 krb5_auth_context *auth_context,
84 const krb5_flags ap_req_options,
85 const char *principal,
88 BOOL get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, krb5_ticket *tkt);
89 NTSTATUS ads_verify_ticket(TALLOC_CTX *mem_ctx,
90 struct smb_krb5_context *smb_krb5_context,
91 krb5_auth_context *auth_context,
92 struct cli_credentials *machine_account,
94 const DATA_BLOB *enc_ticket,
97 krb5_keyblock **keyblock);
98 int kerberos_kinit_password_cc(krb5_context ctx, krb5_ccache cc,
99 krb5_principal principal, const char *password,
100 time_t *expire_time, time_t *kdc_time);
101 int kerberos_kinit_keyblock_cc(krb5_context ctx, krb5_ccache cc,
102 krb5_principal principal, krb5_keyblock *keyblock,
103 time_t *expire_time, time_t *kdc_time);
104 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context,
105 krb5_principal host_princ,
107 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
108 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
109 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
110 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
111 char *smb_get_krb5_error_message(krb5_context context, krb5_error_code code, TALLOC_CTX *mem_ctx);
112 krb5_error_code kinit_to_ccache(TALLOC_CTX *parent_ctx,
113 struct cli_credentials *credentials,
114 struct smb_krb5_context *smb_krb5_context,
116 krb5_error_code salt_principal_from_credentials(TALLOC_CTX *parent_ctx,
117 struct cli_credentials *machine_account,
118 struct smb_krb5_context *smb_krb5_context,
119 krb5_principal *salt_princ);
120 krb5_error_code principal_from_credentials(TALLOC_CTX *parent_ctx,
121 struct cli_credentials *credentials,
122 struct smb_krb5_context *smb_krb5_context,
123 krb5_principal *princ);
124 int create_memory_keytab(TALLOC_CTX *parent_ctx,
125 struct cli_credentials *machine_account,
126 struct smb_krb5_context *smb_krb5_context,
127 struct keytab_container **keytab_container);
128 NTSTATUS kerberos_decode_pac(TALLOC_CTX *mem_ctx,
129 struct PAC_DATA **pac_data_out,
131 krb5_context context,
132 krb5_keyblock *krbtgt_keyblock,
133 krb5_keyblock *service_keyblock,
134 krb5_const_principal client_principal,
135 time_t tgs_authtime);
136 NTSTATUS kerberos_pac_logon_info(TALLOC_CTX *mem_ctx,
137 struct PAC_LOGON_INFO **logon_info,
139 krb5_context context,
140 krb5_keyblock *krbtgt_keyblock,
141 krb5_keyblock *service_keyblock,
142 krb5_const_principal client_principal,
143 time_t tgs_authtime);
144 krb5_error_code kerberos_encode_pac(TALLOC_CTX *mem_ctx,
145 struct PAC_DATA *pac_data,
146 krb5_context context,
147 krb5_keyblock *krbtgt_keyblock,
148 krb5_keyblock *service_keyblock,
150 krb5_error_code kerberos_create_pac(TALLOC_CTX *mem_ctx,
151 struct auth_serversupplied_info *server_info,
152 krb5_context context,
153 krb5_keyblock *krbtgt_keyblock,
154 krb5_keyblock *service_keyblock,
155 krb5_principal client_principal,
158 #endif /* HAVE_KRB5 */