smbd: Correct PATH_ vs NAME_NOT_FOUND for not following lcomp
[Samba.git] / auth / credentials / credentials.h
blobc3a048ecc8de932f3060d4679482c03707bc349f
1 /*
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 "../lib/util/time.h"
26 #include "../lib/util/data_blob.h"
27 #include "librpc/gen_ndr/misc.h"
29 struct cli_credentials;
30 struct ccache_container;
31 struct tevent_context;
32 struct netlogon_creds_CredentialState;
33 struct ldb_context;
34 struct ldb_message;
35 struct loadparm_context;
36 struct ccache_container;
37 struct gssapi_creds_container;
38 struct smb_krb5_context;
39 struct keytab_container;
40 struct db_context;
41 enum smb_signing_setting;
42 enum smb_encryption_setting;
44 /* In order of priority */
45 enum credentials_obtained {
46 CRED_UNINITIALISED = 0, /* We don't even have a guess yet */
47 CRED_SMB_CONF, /* Current value should be used, which comes from smb.conf */
48 CRED_CALLBACK, /* Callback should be used to obtain value */
49 CRED_GUESS_ENV, /* Current value should be used, which was guessed */
50 CRED_GUESS_FILE, /* A guess from a file (or file pointed at in env variable) */
51 CRED_CALLBACK_RESULT, /* Value was obtained from a callback */
52 CRED_SPECIFIED /* Was explicitly specified on the command-line */
55 enum credentials_use_kerberos {
56 /** Sometimes trying kerberos just does 'bad things', so don't */
57 CRED_USE_KERBEROS_DISABLED = 0,
58 /** Default, we try kerberos if available */
59 CRED_USE_KERBEROS_DESIRED,
60 /** Sometimes administrators are paranoid, so always do kerberos */
61 CRED_USE_KERBEROS_REQUIRED,
64 enum credentials_client_protection {
65 CRED_CLIENT_PROTECTION_DEFAULT = -1,
66 CRED_CLIENT_PROTECTION_PLAIN = 0,
67 CRED_CLIENT_PROTECTION_SIGN,
68 CRED_CLIENT_PROTECTION_ENCRYPT,
71 enum credentials_krb_forwardable {
72 CRED_AUTO_KRB_FORWARDABLE = 0, /* Default, follow library defaults */
73 CRED_NO_KRB_FORWARDABLE, /* not forwardable */
74 CRED_FORCE_KRB_FORWARDABLE /* forwardable */
77 #define CLI_CRED_NTLM2 0x01
78 #define CLI_CRED_NTLMv2_AUTH 0x02
79 #define CLI_CRED_LANMAN_AUTH 0x04
80 #define CLI_CRED_NTLM_AUTH 0x08
81 #define CLI_CRED_CLEAR_AUTH 0x10 /* TODO: Push cleartext auth with this flag */
83 const char *cli_credentials_get_workstation(struct cli_credentials *cred);
84 bool cli_credentials_set_workstation(struct cli_credentials *cred,
85 const char *val,
86 enum credentials_obtained obtained);
87 bool cli_credentials_is_anonymous(struct cli_credentials *cred);
88 struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx);
89 struct cli_credentials *cli_credentials_init_server(TALLOC_CTX *mem_ctx,
90 struct loadparm_context *lp_ctx);
91 void cli_credentials_set_anonymous(struct cli_credentials *cred);
92 bool cli_credentials_wrong_password(struct cli_credentials *cred);
93 const char *cli_credentials_get_password(struct cli_credentials *cred);
94 const char *cli_credentials_get_password_and_obtained(struct cli_credentials *cred,
95 enum credentials_obtained *obtained);
96 void cli_credentials_get_ntlm_username_domain(struct cli_credentials *cred, TALLOC_CTX *mem_ctx,
97 const char **username,
98 const char **domain);
99 NTSTATUS cli_credentials_get_ntlm_response(struct cli_credentials *cred, TALLOC_CTX *mem_ctx,
100 int *flags,
101 DATA_BLOB challenge,
102 const NTTIME *server_timestamp,
103 DATA_BLOB target_info,
104 DATA_BLOB *_lm_response, DATA_BLOB *_nt_response,
105 DATA_BLOB *_lm_session_key, DATA_BLOB *_session_key);
106 const char *cli_credentials_get_realm(struct cli_credentials *cred);
107 const char *cli_credentials_get_username(struct cli_credentials *cred);
108 const char *cli_credentials_get_username_and_obtained(struct cli_credentials *cred,
109 enum credentials_obtained *obtained);
110 int cli_credentials_get_krb5_context(struct cli_credentials *cred,
111 struct loadparm_context *lp_ctx,
112 struct smb_krb5_context **smb_krb5_context);
113 int cli_credentials_get_ccache(struct cli_credentials *cred,
114 struct tevent_context *event_ctx,
115 struct loadparm_context *lp_ctx,
116 struct ccache_container **ccc,
117 const char **error_string);
118 int cli_credentials_get_named_ccache(struct cli_credentials *cred,
119 struct tevent_context *event_ctx,
120 struct loadparm_context *lp_ctx,
121 char *ccache_name,
122 struct ccache_container **ccc, const char **error_string);
123 bool cli_credentials_failed_kerberos_login(struct cli_credentials *cred,
124 const char *principal,
125 unsigned int *count);
126 int cli_credentials_get_keytab(struct cli_credentials *cred,
127 struct loadparm_context *lp_ctx,
128 struct keytab_container **_ktc);
129 const char *cli_credentials_get_domain(struct cli_credentials *cred);
130 struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
131 void cli_credentials_set_machine_account_pending(struct cli_credentials *cred,
132 struct loadparm_context *lp_ctx);
133 bool cli_credentials_set_conf(struct cli_credentials *cred,
134 struct loadparm_context *lp_ctx);
135 char *cli_credentials_get_principal(struct cli_credentials *cred, TALLOC_CTX *mem_ctx);
136 int cli_credentials_get_server_gss_creds(struct cli_credentials *cred,
137 struct loadparm_context *lp_ctx,
138 struct gssapi_creds_container **_gcc);
139 int cli_credentials_get_client_gss_creds(struct cli_credentials *cred,
140 struct tevent_context *event_ctx,
141 struct loadparm_context *lp_ctx,
142 struct gssapi_creds_container **_gcc,
143 const char **error_string);
144 void cli_credentials_set_forced_sasl_mech(struct cli_credentials *creds,
145 const char *sasl_mech);
146 bool cli_credentials_set_kerberos_state(struct cli_credentials *creds,
147 enum credentials_use_kerberos kerberos_state,
148 enum credentials_obtained obtained);
149 void cli_credentials_set_krb_forwardable(struct cli_credentials *creds,
150 enum credentials_krb_forwardable krb_forwardable);
151 bool cli_credentials_set_domain(struct cli_credentials *cred,
152 const char *val,
153 enum credentials_obtained obtained);
154 bool cli_credentials_set_domain_callback(struct cli_credentials *cred,
155 const char *(*domain_cb) (struct cli_credentials *));
156 bool cli_credentials_set_username(struct cli_credentials *cred,
157 const char *val, enum credentials_obtained obtained);
158 bool cli_credentials_set_username_callback(struct cli_credentials *cred,
159 const char *(*username_cb) (struct cli_credentials *));
160 bool cli_credentials_set_principal(struct cli_credentials *cred,
161 const char *val,
162 enum credentials_obtained obtained);
163 bool cli_credentials_set_principal_callback(struct cli_credentials *cred,
164 const char *(*principal_cb) (struct cli_credentials *));
165 bool cli_credentials_set_password(struct cli_credentials *cred,
166 const char *val,
167 enum credentials_obtained obtained);
168 struct cli_credentials *cli_credentials_init_anon(TALLOC_CTX *mem_ctx);
169 void cli_credentials_parse_string(struct cli_credentials *credentials, const char *data, enum credentials_obtained obtained);
170 struct samr_Password *cli_credentials_get_nt_hash(struct cli_credentials *cred,
171 TALLOC_CTX *mem_ctx);
172 struct samr_Password *cli_credentials_get_old_nt_hash(struct cli_credentials *cred,
173 TALLOC_CTX *mem_ctx);
174 bool cli_credentials_set_realm(struct cli_credentials *cred,
175 const char *val,
176 enum credentials_obtained obtained);
177 void cli_credentials_set_secure_channel_type(struct cli_credentials *cred,
178 enum netr_SchannelType secure_channel_type);
179 void cli_credentials_set_password_last_changed_time(struct cli_credentials *cred,
180 time_t last_change_time);
181 void cli_credentials_set_netlogon_creds(
182 struct cli_credentials *cred,
183 const struct netlogon_creds_CredentialState *netlogon_creds);
184 NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred,
185 struct smb_krb5_context *smb_krb5_context);
186 NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
187 struct loadparm_context *lp_ctx,
188 const char *serviceprincipal);
189 NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred,
190 struct loadparm_context *lp_ctx);
192 * Fill in credentials for the machine trust account, from the
193 * secrets.ldb or passed in handle to secrets.tdb (perhaps in CTDB).
195 * This version is used in parts of the code that can link in the
196 * CTDB dbwrap backend, by passing down the already open handle.
198 * @param cred Credentials structure to fill in
199 * @param db_ctx dbwrap context for secrets.tdb
200 * @retval NTSTATUS error detailing any failure
202 NTSTATUS cli_credentials_set_machine_account_db_ctx(struct cli_credentials *cred,
203 struct loadparm_context *lp_ctx,
204 struct db_context *db_ctx);
206 bool cli_credentials_authentication_requested(struct cli_credentials *cred);
207 bool 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 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 time_t cli_credentials_get_password_last_changed_time(struct cli_credentials *cred);
218 void cli_credentials_set_kvno(struct cli_credentials *cred,
219 int kvno);
220 bool cli_credentials_set_utf16_password(struct cli_credentials *cred,
221 const DATA_BLOB *password_utf16,
222 enum credentials_obtained obtained);
223 bool cli_credentials_set_old_utf16_password(struct cli_credentials *cred,
224 const DATA_BLOB *password_utf16);
225 void cli_credentials_set_password_will_be_nt_hash(struct cli_credentials *cred,
226 bool val);
227 bool cli_credentials_is_password_nt_hash(struct cli_credentials *cred);
228 bool cli_credentials_set_nt_hash(struct cli_credentials *cred,
229 const struct samr_Password *nt_hash,
230 enum credentials_obtained obtained);
231 bool cli_credentials_set_old_nt_hash(struct cli_credentials *cred,
232 const struct samr_Password *nt_hash);
233 bool cli_credentials_set_ntlm_response(struct cli_credentials *cred,
234 const DATA_BLOB *lm_response,
235 const DATA_BLOB *lm_session_key,
236 const DATA_BLOB *nt_response,
237 const DATA_BLOB *nt_session_key,
238 enum credentials_obtained obtained);
239 int cli_credentials_set_keytab_name(struct cli_credentials *cred,
240 struct loadparm_context *lp_ctx,
241 const char *keytab_name,
242 enum credentials_obtained obtained);
243 bool cli_credentials_set_gensec_features(struct cli_credentials *creds,
244 uint32_t gensec_features,
245 enum credentials_obtained obtained);
246 uint32_t cli_credentials_get_gensec_features(struct cli_credentials *creds);
247 int cli_credentials_set_ccache(struct cli_credentials *cred,
248 struct loadparm_context *lp_ctx,
249 const char *name,
250 enum credentials_obtained obtained,
251 const char **error_string);
252 bool cli_credentials_parse_password_file(struct cli_credentials *credentials, const char *file, enum credentials_obtained obtained);
253 bool cli_credentials_parse_password_fd(struct cli_credentials *credentials,
254 int fd, enum credentials_obtained obtained);
255 void cli_credentials_invalidate_ccache(struct cli_credentials *cred,
256 enum credentials_obtained obtained);
257 void cli_credentials_set_salt_principal(struct cli_credentials *cred, const char *principal);
258 void cli_credentials_set_impersonate_principal(struct cli_credentials *cred,
259 const char *principal,
260 const char *self_service);
261 void cli_credentials_set_target_service(struct cli_credentials *cred, const char *principal);
262 const char *cli_credentials_get_salt_principal(struct cli_credentials *cred);
263 const char *cli_credentials_get_impersonate_principal(struct cli_credentials *cred);
264 const char *cli_credentials_get_self_service(struct cli_credentials *cred);
265 const char *cli_credentials_get_target_service(struct cli_credentials *cred);
266 enum credentials_use_kerberos cli_credentials_get_kerberos_state(struct cli_credentials *creds);
267 const char *cli_credentials_get_forced_sasl_mech(struct cli_credentials *cred);
268 enum credentials_krb_forwardable cli_credentials_get_krb_forwardable(struct cli_credentials *creds);
269 NTSTATUS cli_credentials_set_secrets(struct cli_credentials *cred,
270 struct loadparm_context *lp_ctx,
271 struct ldb_context *ldb,
272 const char *base,
273 const char *filter,
274 char **error_string);
275 int cli_credentials_get_kvno(struct cli_credentials *cred);
277 bool cli_credentials_set_username_callback(struct cli_credentials *cred,
278 const char *(*username_cb) (struct cli_credentials *));
281 * Obtain the client principal for this credentials context.
282 * @param cred credentials context
283 * @retval The username set on this context.
284 * @note Return value will never be NULL except by programmer error.
286 char *cli_credentials_get_principal_and_obtained(struct cli_credentials *cred, TALLOC_CTX *mem_ctx, enum credentials_obtained *obtained);
287 bool cli_credentials_set_principal(struct cli_credentials *cred,
288 const char *val,
289 enum credentials_obtained obtained);
290 bool cli_credentials_set_principal_callback(struct cli_credentials *cred,
291 const char *(*principal_cb) (struct cli_credentials *));
294 * Obtain the 'old' password for this credentials context (used for join accounts).
295 * @param cred credentials context
296 * @retval If set, the cleartext password, otherwise NULL
298 const char *cli_credentials_get_old_password(struct cli_credentials *cred);
299 bool cli_credentials_set_old_password(struct cli_credentials *cred,
300 const char *val,
301 enum credentials_obtained obtained);
302 bool cli_credentials_set_domain_callback(struct cli_credentials *cred,
303 const char *(*domain_cb) (struct cli_credentials *));
304 bool cli_credentials_set_realm_callback(struct cli_credentials *cred,
305 const char *(*realm_cb) (struct cli_credentials *));
306 bool cli_credentials_set_workstation_callback(struct cli_credentials *cred,
307 const char *(*workstation_cb) (struct cli_credentials *));
309 void cli_credentials_set_callback_data(struct cli_credentials *cred,
310 void *callback_data);
311 void *_cli_credentials_callback_data(struct cli_credentials *cred);
312 #define cli_credentials_callback_data(_cred, _type) \
313 talloc_get_type_abort(_cli_credentials_callback_data(_cred), _type)
314 #define cli_credentials_callback_data_void(_cred) \
315 _cli_credentials_callback_data(_cred)
317 bool cli_credentials_set_smb_signing(struct cli_credentials *cred,
318 enum smb_signing_setting signing_state,
319 enum credentials_obtained obtained);
320 enum smb_signing_setting
321 cli_credentials_get_smb_signing(struct cli_credentials *cred);
323 bool cli_credentials_set_smb_ipc_signing(struct cli_credentials *cred,
324 enum smb_signing_setting ipc_signing_state,
325 enum credentials_obtained obtained);
326 enum smb_signing_setting
327 cli_credentials_get_smb_ipc_signing(struct cli_credentials *cred);
329 bool cli_credentials_set_smb_encryption(struct cli_credentials *cred,
330 enum smb_encryption_setting encryption_state,
331 enum credentials_obtained obtained);
332 enum smb_encryption_setting
333 cli_credentials_get_smb_encryption(struct cli_credentials *cred);
335 bool cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred);
337 void cli_credentials_dump(struct cli_credentials *creds);
340 * Return attached NETLOGON credentials
342 struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
344 NTSTATUS netlogon_creds_session_encrypt(
345 struct netlogon_creds_CredentialState *state,
346 DATA_BLOB data);
348 int cli_credentials_get_aes256_key(struct cli_credentials *cred,
349 TALLOC_CTX *mem_ctx,
350 struct loadparm_context *lp_ctx,
351 const char *salt,
352 DATA_BLOB *aes_256);
354 #endif /* __CREDENTIALS_H__ */