s4-auth-krb: Move keytab functions in a separate file.
[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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _AUTH_KERBEROS_H_
22 #define _AUTH_KERBEROS_H_
23
24 #if defined(HAVE_KRB5)
25
26 #include "auth/kerberos/krb5_init_context.h"
27 #include "librpc/gen_ndr/krb5pac.h"
28 #include "libcli/auth/krb5_wrap.h"
29
30 struct auth_user_info_dc;
31 struct cli_credentials;
32
33 struct ccache_container {
34         struct smb_krb5_context *smb_krb5_context;
35         krb5_ccache ccache;
36 };
37
38 struct keytab_container {
39         struct smb_krb5_context *smb_krb5_context;
40         krb5_keytab keytab;
41 };
42
43 struct principal_container {
44         struct smb_krb5_context *smb_krb5_context;
45         krb5_principal principal;
46         const char *string_form; /* Optional */
47 };
48
49 /* not really ASN.1, but RFC 1964 */
50 #define TOK_ID_KRB_AP_REQ       ((const uint8_t *)"\x01\x00")
51 #define TOK_ID_KRB_AP_REP       ((const uint8_t *)"\x02\x00")
52 #define TOK_ID_KRB_ERROR        ((const uint8_t *)"\x03\x00")
53 #define TOK_ID_GSS_GETMIC       ((const uint8_t *)"\x01\x01")
54 #define TOK_ID_GSS_WRAP         ((const uint8_t *)"\x02\x01")
55
56 #ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE
57 #define KRB5_KEY_TYPE(k)        ((k)->keytype)
58 #define KRB5_KEY_LENGTH(k)      ((k)->keyvalue.length)
59 #define KRB5_KEY_DATA(k)        ((k)->keyvalue.data)
60 #else
61 #define KRB5_KEY_TYPE(k)        ((k)->enctype)
62 #define KRB5_KEY_LENGTH(k)      ((k)->length)
63 #define KRB5_KEY_DATA(k)        ((k)->contents)
64 #endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
65
66 #define ENC_ALL_TYPES (ENC_CRC32 | ENC_RSA_MD5 | ENC_RC4_HMAC_MD5 |     \
67                        ENC_HMAC_SHA1_96_AES128 | ENC_HMAC_SHA1_96_AES256)
68
69 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
70 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
71 #endif
72
73 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
74 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
75 #endif
76
77 #if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT)
78 const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i );
79 #endif
80
81 /* Samba wrapper function for krb5 functionality. */
82 krb5_error_code kerberos_kinit_password_cc(krb5_context ctx, krb5_ccache cc,
83                                            krb5_principal principal, const char *password,
84                                            krb5_principal impersonate_principal,
85                                            const char *self_service,
86                                            const char *target_service,
87                                            krb5_get_init_creds_opt *krb_options,
88                                            time_t *expire_time, time_t *kdc_time);
89 krb5_error_code kerberos_kinit_keyblock_cc(krb5_context ctx, krb5_ccache cc,
90                                            krb5_principal principal, krb5_keyblock *keyblock,
91                                            const char *target_service,
92                                            krb5_get_init_creds_opt *krb_options,
93                                            time_t *expire_time, time_t *kdc_time);
94 NTSTATUS kerberos_pac_logon_info(TALLOC_CTX *mem_ctx,
95                                  DATA_BLOB blob,
96                                  krb5_context context,
97                                  const krb5_keyblock *krbtgt_keyblock,
98                                  const krb5_keyblock *service_keyblock,
99                                  krb5_const_principal client_principal,
100                                  time_t tgs_authtime,
101                                  struct PAC_LOGON_INFO **logon_info);
102  krb5_error_code kerberos_encode_pac(TALLOC_CTX *mem_ctx,
103                                     struct PAC_DATA *pac_data,
104                                     krb5_context context,
105                                     const krb5_keyblock *krbtgt_keyblock,
106                                     const krb5_keyblock *service_keyblock,
107                                     DATA_BLOB *pac);
108  krb5_error_code kerberos_create_pac(TALLOC_CTX *mem_ctx,
109                                      struct auth_user_info_dc *user_info_dc,
110                                      krb5_context context,
111                                      const krb5_keyblock *krbtgt_keyblock,
112                                      const krb5_keyblock *service_keyblock,
113                                      krb5_principal client_principal,
114                                      time_t tgs_authtime,
115                                      DATA_BLOB *pac);
116 struct loadparm_context;
117 struct ldb_message;
118 struct ldb_context;
119 uint32_t kerberos_enctype_to_bitmap(krb5_enctype enc_type_enum);
120 krb5_error_code smb_krb5_update_keytab(TALLOC_CTX *parent_ctx,
121                                        struct smb_krb5_context *smb_krb5_context,
122                                        struct ldb_context *ldb, 
123                                        struct ldb_message *msg,
124                                        bool delete_all_kvno,
125                                        const char **error_string);
126
127 #include "auth/kerberos/proto.h"
128
129 #endif /* HAVE_KRB5 */
130
131 #endif /* _AUTH_KERBEROS_H_ */