2 samba -- Unix SMB/CIFS implementation.
4 Client credentials structure
6 Copyright (C) Jelmer Vernooij 2004-2006
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
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.
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.
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/>.
22 #ifndef __CREDENTIALS_H__
23 #define __CREDENTIALS_H__
25 #include "util/data_blob.h"
26 #include "librpc/gen_ndr/misc.h"
28 struct ccache_container;
30 /* In order of priority */
31 enum credentials_obtained {
32 CRED_UNINITIALISED = 0, /* We don't even have a guess yet */
33 CRED_CALLBACK, /* Callback should be used to obtain value */
34 CRED_GUESS_ENV, /* Current value should be used, which was guessed */
35 CRED_GUESS_FILE, /* A guess from a file (or file pointed at in env variable) */
36 CRED_CALLBACK_RESULT, /* Value was obtained from a callback */
37 CRED_SPECIFIED /* Was explicitly specified on the command-line */
40 enum credentials_use_kerberos {
41 CRED_AUTO_USE_KERBEROS = 0, /* Default, we try kerberos if available */
42 CRED_DONT_USE_KERBEROS, /* Sometimes trying kerberos just does 'bad things', so don't */
43 CRED_MUST_USE_KERBEROS /* Sometimes administrators are parinoid, so always do kerberos */
46 #define CLI_CRED_NTLM2 0x01
47 #define CLI_CRED_NTLMv2_AUTH 0x02
48 #define CLI_CRED_LANMAN_AUTH 0x04
49 #define CLI_CRED_NTLM_AUTH 0x08
50 #define CLI_CRED_CLEAR_AUTH 0x10 /* TODO: Push cleartext auth with this flag */
52 struct cli_credentials {
53 enum credentials_obtained workstation_obtained;
54 enum credentials_obtained username_obtained;
55 enum credentials_obtained password_obtained;
56 enum credentials_obtained domain_obtained;
57 enum credentials_obtained realm_obtained;
58 enum credentials_obtained ccache_obtained;
59 enum credentials_obtained client_gss_creds_obtained;
60 enum credentials_obtained principal_obtained;
61 enum credentials_obtained keytab_obtained;
62 enum credentials_obtained server_gss_creds_obtained;
64 /* Threshold values (essentially a MAX() over a number of the
65 * above) for the ccache and GSS credentials, to ensure we
66 * regenerate/pick correctly */
68 enum credentials_obtained ccache_threshold;
69 enum credentials_obtained client_gss_creds_threshold;
71 const char *workstation;
74 const char *old_password;
77 const char *principal;
78 const char *salt_principal;
82 struct samr_Password *nt_hash;
84 struct ccache_container *ccache;
85 struct gssapi_creds_container *client_gss_creds;
86 struct keytab_container *keytab;
87 struct gssapi_creds_container *server_gss_creds;
89 const char *(*workstation_cb) (struct cli_credentials *);
90 const char *(*password_cb) (struct cli_credentials *);
91 const char *(*username_cb) (struct cli_credentials *);
92 const char *(*domain_cb) (struct cli_credentials *);
93 const char *(*realm_cb) (struct cli_credentials *);
94 const char *(*principal_cb) (struct cli_credentials *);
96 /* Private handle for the callback routines to use */
99 struct creds_CredentialState *netlogon_creds;
100 enum netr_SchannelType secure_channel_type;
103 struct smb_krb5_context *smb_krb5_context;
105 /* We are flagged to get machine account details from the
106 * secrets.ldb when we are asked for a username or password */
107 bool machine_account_pending;
108 struct loadparm_context *machine_account_pending_lp_ctx;
110 /* Is this a machine account? */
111 bool machine_account;
113 /* Should we be trying to use kerberos? */
114 enum credentials_use_kerberos use_kerberos;
116 /* gensec features which should be used for connections */
117 uint32_t gensec_features;
119 /* Number of retries left before bailing out */
122 /* Whether any callback is currently running */
123 bool callback_running;
125 /* an event context for anyone wanting to use the credentials */
126 struct event_context *ev;
130 struct loadparm_context;
131 struct ccache_container;
133 struct gssapi_creds_container;
135 const char *cli_credentials_get_workstation(struct cli_credentials *cred);
136 bool cli_credentials_set_workstation(struct cli_credentials *cred,
138 enum credentials_obtained obtained);
139 bool cli_credentials_is_anonymous(struct cli_credentials *cred);
140 struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx);
141 void cli_credentials_set_anonymous(struct cli_credentials *cred);
142 bool cli_credentials_wrong_password(struct cli_credentials *cred);
143 const char *cli_credentials_get_password(struct cli_credentials *cred);
144 void cli_credentials_get_ntlm_username_domain(struct cli_credentials *cred, TALLOC_CTX *mem_ctx,
145 const char **username,
146 const char **domain);
147 NTSTATUS cli_credentials_get_ntlm_response(struct cli_credentials *cred, TALLOC_CTX *mem_ctx,
149 DATA_BLOB challenge, DATA_BLOB target_info,
150 DATA_BLOB *_lm_response, DATA_BLOB *_nt_response,
151 DATA_BLOB *_lm_session_key, DATA_BLOB *_session_key);
152 const char *cli_credentials_get_realm(struct cli_credentials *cred);
153 const char *cli_credentials_get_username(struct cli_credentials *cred);
154 int cli_credentials_get_krb5_context(struct cli_credentials *cred,
155 struct loadparm_context *lp_ctx,
156 struct smb_krb5_context **smb_krb5_context);
157 int cli_credentials_get_ccache(struct cli_credentials *cred,
158 struct loadparm_context *lp_ctx,
159 struct ccache_container **ccc);
160 int cli_credentials_get_keytab(struct cli_credentials *cred,
161 struct loadparm_context *lp_ctx,
162 struct keytab_container **_ktc);
163 const char *cli_credentials_get_domain(struct cli_credentials *cred);
164 struct creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
165 void cli_credentials_set_machine_account_pending(struct cli_credentials *cred,
166 struct loadparm_context *lp_ctx);
167 void cli_credentials_set_conf(struct cli_credentials *cred,
168 struct loadparm_context *lp_ctx);
169 const char *cli_credentials_get_principal(struct cli_credentials *cred, TALLOC_CTX *mem_ctx);
170 int cli_credentials_get_server_gss_creds(struct cli_credentials *cred,
171 struct loadparm_context *lp_ctx,
172 struct gssapi_creds_container **_gcc);
173 int cli_credentials_get_client_gss_creds(struct cli_credentials *cred,
174 struct loadparm_context *lp_ctx,
175 struct gssapi_creds_container **_gcc);
176 void cli_credentials_set_event_context(struct cli_credentials *cred, struct event_context *ev);
177 void cli_credentials_set_kerberos_state(struct cli_credentials *creds,
178 enum credentials_use_kerberos use_kerberos);
179 struct event_context *cli_credentials_get_event_context(struct cli_credentials *cred);
180 bool cli_credentials_set_domain(struct cli_credentials *cred,
182 enum credentials_obtained obtained);
183 bool cli_credentials_set_username(struct cli_credentials *cred,
184 const char *val, enum credentials_obtained obtained);
185 bool cli_credentials_set_password(struct cli_credentials *cred,
187 enum credentials_obtained obtained);
188 struct cli_credentials *cli_credentials_init_anon(TALLOC_CTX *mem_ctx);
189 void cli_credentials_parse_string(struct cli_credentials *credentials, const char *data, enum credentials_obtained obtained);
190 const struct samr_Password *cli_credentials_get_nt_hash(struct cli_credentials *cred,
191 TALLOC_CTX *mem_ctx);
192 bool cli_credentials_set_realm(struct cli_credentials *cred,
194 enum credentials_obtained obtained);
195 void cli_credentials_set_secure_channel_type(struct cli_credentials *cred,
196 enum netr_SchannelType secure_channel_type);
197 void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
198 struct creds_CredentialState *netlogon_creds);
199 NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred,
200 struct smb_krb5_context *smb_krb5_context);
201 NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
202 struct loadparm_context *lp_ctx,
203 const char *serviceprincipal);
204 NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred,
205 struct loadparm_context *lp_ctx);
206 bool cli_credentials_authentication_requested(struct cli_credentials *cred);
207 void cli_credentials_guess(struct cli_credentials *cred,
208 struct loadparm_context *lp_ctx);
209 bool cli_credentials_set_bind_dn(struct cli_credentials *cred,
210 const char *bind_dn);
211 const char *cli_credentials_get_bind_dn(struct cli_credentials *cred);
212 bool cli_credentials_parse_file(struct cli_credentials *cred, const char *file, enum credentials_obtained obtained);
213 const char *cli_credentials_get_unparsed_name(struct cli_credentials *credentials, TALLOC_CTX *mem_ctx);
214 bool cli_credentials_set_password_callback(struct cli_credentials *cred,
215 const char *(*password_cb) (struct cli_credentials *));
216 enum netr_SchannelType cli_credentials_get_secure_channel_type(struct cli_credentials *cred);
217 void cli_credentials_set_kvno(struct cli_credentials *cred,
219 bool cli_credentials_set_nt_hash(struct cli_credentials *cred,
220 const struct samr_Password *nt_hash,
221 enum credentials_obtained obtained);
222 int cli_credentials_set_keytab_name(struct cli_credentials *cred,
223 struct loadparm_context *lp_ctx,
224 const char *keytab_name,
225 enum credentials_obtained obtained);
226 int cli_credentials_update_keytab(struct cli_credentials *cred,
227 struct loadparm_context *lp_ctx);
228 void cli_credentials_set_gensec_features(struct cli_credentials *creds, uint32_t gensec_features);
229 uint32_t cli_credentials_get_gensec_features(struct cli_credentials *creds);
230 int cli_credentials_set_ccache(struct cli_credentials *cred,
231 struct loadparm_context *lp_ctx,
233 enum credentials_obtained obtained);
234 bool cli_credentials_parse_password_file(struct cli_credentials *credentials, const char *file, enum credentials_obtained obtained);
235 bool cli_credentials_parse_password_fd(struct cli_credentials *credentials,
236 int fd, enum credentials_obtained obtained);
237 void cli_credentials_invalidate_ccache(struct cli_credentials *cred,
238 enum credentials_obtained obtained);
239 void cli_credentials_set_salt_principal(struct cli_credentials *cred, const char *principal);
240 enum credentials_use_kerberos cli_credentials_get_kerberos_state(struct cli_credentials *creds);
241 NTSTATUS cli_credentials_set_secrets(struct cli_credentials *cred,
242 struct loadparm_context *lp_ctx,
243 struct ldb_context *ldb,
246 int cli_credentials_get_kvno(struct cli_credentials *cred);
248 #endif /* __CREDENTIALS_H__ */