s3: smbd - open logic fix.
[Samba.git] / auth / credentials / credentials.h
blobfdd35bbd42506480032ec066d5fac6fa1f988c65
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/data_blob.h"
26 #include "librpc/gen_ndr/misc.h"
28 struct cli_credentials;
29 struct ccache_container;
30 struct tevent_context;
31 struct netlogon_creds_CredentialState;
32 struct ldb_context;
33 struct ldb_message;
34 struct loadparm_context;
35 struct ccache_container;
36 struct gssapi_creds_container;
37 struct smb_krb5_context;
38 struct keytab_container;
40 /* In order of priority */
41 enum credentials_obtained {
42 CRED_UNINITIALISED = 0, /* We don't even have a guess yet */
43 CRED_CALLBACK, /* Callback should be used to obtain value */
44 CRED_GUESS_ENV, /* Current value should be used, which was guessed */
45 CRED_GUESS_FILE, /* A guess from a file (or file pointed at in env variable) */
46 CRED_CALLBACK_RESULT, /* Value was obtained from a callback */
47 CRED_SPECIFIED /* Was explicitly specified on the command-line */
50 enum credentials_use_kerberos {
51 CRED_AUTO_USE_KERBEROS = 0, /* Default, we try kerberos if available */
52 CRED_DONT_USE_KERBEROS, /* Sometimes trying kerberos just does 'bad things', so don't */
53 CRED_MUST_USE_KERBEROS /* Sometimes administrators are parinoid, so always do kerberos */
56 enum credentials_krb_forwardable {
57 CRED_AUTO_KRB_FORWARDABLE = 0, /* Default, follow library defaults */
58 CRED_NO_KRB_FORWARDABLE, /* not forwardable */
59 CRED_FORCE_KRB_FORWARDABLE /* forwardable */
62 #define CLI_CRED_NTLM2 0x01
63 #define CLI_CRED_NTLMv2_AUTH 0x02
64 #define CLI_CRED_LANMAN_AUTH 0x04
65 #define CLI_CRED_NTLM_AUTH 0x08
66 #define CLI_CRED_CLEAR_AUTH 0x10 /* TODO: Push cleartext auth with this flag */
68 const char *cli_credentials_get_workstation(struct cli_credentials *cred);
69 bool cli_credentials_set_workstation(struct cli_credentials *cred,
70 const char *val,
71 enum credentials_obtained obtained);
72 bool cli_credentials_is_anonymous(struct cli_credentials *cred);
73 struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx);
74 void cli_credentials_set_anonymous(struct cli_credentials *cred);
75 bool cli_credentials_wrong_password(struct cli_credentials *cred);
76 const char *cli_credentials_get_password(struct cli_credentials *cred);
77 void cli_credentials_get_ntlm_username_domain(struct cli_credentials *cred, TALLOC_CTX *mem_ctx,
78 const char **username,
79 const char **domain);
80 NTSTATUS cli_credentials_get_ntlm_response(struct cli_credentials *cred, TALLOC_CTX *mem_ctx,
81 int *flags,
82 DATA_BLOB challenge, DATA_BLOB target_info,
83 DATA_BLOB *_lm_response, DATA_BLOB *_nt_response,
84 DATA_BLOB *_lm_session_key, DATA_BLOB *_session_key);
85 const char *cli_credentials_get_realm(struct cli_credentials *cred);
86 const char *cli_credentials_get_username(struct cli_credentials *cred);
87 int cli_credentials_get_krb5_context(struct cli_credentials *cred,
88 struct loadparm_context *lp_ctx,
89 struct smb_krb5_context **smb_krb5_context);
90 int cli_credentials_get_ccache(struct cli_credentials *cred,
91 struct tevent_context *event_ctx,
92 struct loadparm_context *lp_ctx,
93 struct ccache_container **ccc,
94 const char **error_string);
95 int cli_credentials_get_named_ccache(struct cli_credentials *cred,
96 struct tevent_context *event_ctx,
97 struct loadparm_context *lp_ctx,
98 char *ccache_name,
99 struct ccache_container **ccc, const char **error_string);
100 bool cli_credentials_failed_kerberos_login(struct cli_credentials *cred,
101 const char *principal,
102 unsigned int *count);
103 int cli_credentials_get_keytab(struct cli_credentials *cred,
104 struct loadparm_context *lp_ctx,
105 struct keytab_container **_ktc);
106 const char *cli_credentials_get_domain(struct cli_credentials *cred);
107 struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
108 void cli_credentials_set_machine_account_pending(struct cli_credentials *cred,
109 struct loadparm_context *lp_ctx);
110 void cli_credentials_set_conf(struct cli_credentials *cred,
111 struct loadparm_context *lp_ctx);
112 const char *cli_credentials_get_principal(struct cli_credentials *cred, TALLOC_CTX *mem_ctx);
113 int cli_credentials_get_server_gss_creds(struct cli_credentials *cred,
114 struct loadparm_context *lp_ctx,
115 struct gssapi_creds_container **_gcc);
116 int cli_credentials_get_client_gss_creds(struct cli_credentials *cred,
117 struct tevent_context *event_ctx,
118 struct loadparm_context *lp_ctx,
119 struct gssapi_creds_container **_gcc,
120 const char **error_string);
121 void cli_credentials_set_forced_sasl_mech(struct cli_credentials *creds,
122 const char *sasl_mech);
123 void cli_credentials_set_kerberos_state(struct cli_credentials *creds,
124 enum credentials_use_kerberos use_kerberos);
125 void cli_credentials_set_krb_forwardable(struct cli_credentials *creds,
126 enum credentials_krb_forwardable krb_forwardable);
127 bool cli_credentials_set_domain(struct cli_credentials *cred,
128 const char *val,
129 enum credentials_obtained obtained);
130 bool cli_credentials_set_domain_callback(struct cli_credentials *cred,
131 const char *(*domain_cb) (struct cli_credentials *));
132 bool cli_credentials_set_username(struct cli_credentials *cred,
133 const char *val, enum credentials_obtained obtained);
134 bool cli_credentials_set_username_callback(struct cli_credentials *cred,
135 const char *(*username_cb) (struct cli_credentials *));
136 bool cli_credentials_set_principal(struct cli_credentials *cred,
137 const char *val,
138 enum credentials_obtained obtained);
139 bool cli_credentials_set_principal_callback(struct cli_credentials *cred,
140 const char *(*principal_cb) (struct cli_credentials *));
141 bool cli_credentials_set_password(struct cli_credentials *cred,
142 const char *val,
143 enum credentials_obtained obtained);
144 struct cli_credentials *cli_credentials_init_anon(TALLOC_CTX *mem_ctx);
145 void cli_credentials_parse_string(struct cli_credentials *credentials, const char *data, enum credentials_obtained obtained);
146 struct samr_Password *cli_credentials_get_nt_hash(struct cli_credentials *cred,
147 TALLOC_CTX *mem_ctx);
148 bool cli_credentials_set_realm(struct cli_credentials *cred,
149 const char *val,
150 enum credentials_obtained obtained);
151 void cli_credentials_set_secure_channel_type(struct cli_credentials *cred,
152 enum netr_SchannelType secure_channel_type);
153 void cli_credentials_set_password_last_changed_time(struct cli_credentials *cred,
154 time_t last_change_time);
155 void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
156 struct netlogon_creds_CredentialState *netlogon_creds);
157 NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred,
158 struct smb_krb5_context *smb_krb5_context);
159 NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
160 struct loadparm_context *lp_ctx,
161 const char *serviceprincipal);
162 NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred,
163 struct loadparm_context *lp_ctx);
164 bool cli_credentials_authentication_requested(struct cli_credentials *cred);
165 void cli_credentials_guess(struct cli_credentials *cred,
166 struct loadparm_context *lp_ctx);
167 bool cli_credentials_set_bind_dn(struct cli_credentials *cred,
168 const char *bind_dn);
169 const char *cli_credentials_get_bind_dn(struct cli_credentials *cred);
170 bool cli_credentials_parse_file(struct cli_credentials *cred, const char *file, enum credentials_obtained obtained);
171 const char *cli_credentials_get_unparsed_name(struct cli_credentials *credentials, TALLOC_CTX *mem_ctx);
172 bool cli_credentials_set_password_callback(struct cli_credentials *cred,
173 const char *(*password_cb) (struct cli_credentials *));
174 enum netr_SchannelType cli_credentials_get_secure_channel_type(struct cli_credentials *cred);
175 time_t cli_credentials_get_password_last_changed_time(struct cli_credentials *cred);
176 void cli_credentials_set_kvno(struct cli_credentials *cred,
177 int kvno);
178 bool cli_credentials_set_nt_hash(struct cli_credentials *cred,
179 const struct samr_Password *nt_hash,
180 enum credentials_obtained obtained);
181 bool cli_credentials_set_ntlm_response(struct cli_credentials *cred,
182 const DATA_BLOB *lm_response,
183 const DATA_BLOB *nt_response,
184 enum credentials_obtained obtained);
185 int cli_credentials_set_keytab_name(struct cli_credentials *cred,
186 struct loadparm_context *lp_ctx,
187 const char *keytab_name,
188 enum credentials_obtained obtained);
189 void cli_credentials_set_gensec_features(struct cli_credentials *creds, uint32_t gensec_features);
190 uint32_t cli_credentials_get_gensec_features(struct cli_credentials *creds);
191 int cli_credentials_set_ccache(struct cli_credentials *cred,
192 struct loadparm_context *lp_ctx,
193 const char *name,
194 enum credentials_obtained obtained,
195 const char **error_string);
196 bool cli_credentials_parse_password_file(struct cli_credentials *credentials, const char *file, enum credentials_obtained obtained);
197 bool cli_credentials_parse_password_fd(struct cli_credentials *credentials,
198 int fd, enum credentials_obtained obtained);
199 void cli_credentials_invalidate_ccache(struct cli_credentials *cred,
200 enum credentials_obtained obtained);
201 void cli_credentials_set_salt_principal(struct cli_credentials *cred, const char *principal);
202 void cli_credentials_set_impersonate_principal(struct cli_credentials *cred,
203 const char *principal,
204 const char *self_service);
205 void cli_credentials_set_target_service(struct cli_credentials *cred, const char *principal);
206 const char *cli_credentials_get_salt_principal(struct cli_credentials *cred);
207 const char *cli_credentials_get_impersonate_principal(struct cli_credentials *cred);
208 const char *cli_credentials_get_self_service(struct cli_credentials *cred);
209 const char *cli_credentials_get_target_service(struct cli_credentials *cred);
210 enum credentials_use_kerberos cli_credentials_get_kerberos_state(struct cli_credentials *creds);
211 const char *cli_credentials_get_forced_sasl_mech(struct cli_credentials *cred);
212 enum credentials_krb_forwardable cli_credentials_get_krb_forwardable(struct cli_credentials *creds);
213 NTSTATUS cli_credentials_set_secrets(struct cli_credentials *cred,
214 struct loadparm_context *lp_ctx,
215 struct ldb_context *ldb,
216 const char *base,
217 const char *filter,
218 char **error_string);
219 int cli_credentials_get_kvno(struct cli_credentials *cred);
221 bool cli_credentials_set_username_callback(struct cli_credentials *cred,
222 const char *(*username_cb) (struct cli_credentials *));
225 * Obtain the client principal for this credentials context.
226 * @param cred credentials context
227 * @retval The username set on this context.
228 * @note Return value will never be NULL except by programmer error.
230 const char *cli_credentials_get_principal_and_obtained(struct cli_credentials *cred, TALLOC_CTX *mem_ctx, enum credentials_obtained *obtained);
231 bool cli_credentials_set_principal(struct cli_credentials *cred,
232 const char *val,
233 enum credentials_obtained obtained);
234 bool cli_credentials_set_principal_callback(struct cli_credentials *cred,
235 const char *(*principal_cb) (struct cli_credentials *));
238 * Obtain the 'old' password for this credentials context (used for join accounts).
239 * @param cred credentials context
240 * @retval If set, the cleartext password, otherwise NULL
242 const char *cli_credentials_get_old_password(struct cli_credentials *cred);
243 bool cli_credentials_set_old_password(struct cli_credentials *cred,
244 const char *val,
245 enum credentials_obtained obtained);
246 bool cli_credentials_set_domain_callback(struct cli_credentials *cred,
247 const char *(*domain_cb) (struct cli_credentials *));
248 bool cli_credentials_set_realm_callback(struct cli_credentials *cred,
249 const char *(*realm_cb) (struct cli_credentials *));
250 bool cli_credentials_set_workstation_callback(struct cli_credentials *cred,
251 const char *(*workstation_cb) (struct cli_credentials *));
253 void cli_credentials_set_callback_data(struct cli_credentials *cred,
254 void *callback_data);
255 void *_cli_credentials_callback_data(struct cli_credentials *cred);
256 #define cli_credentials_callback_data(_cred, _type) \
257 talloc_get_type_abort(_cli_credentials_callback_data(_cred), _type)
258 #define cli_credentials_callback_data_void(_cred) \
259 _cli_credentials_callback_data(_cred)
261 struct cli_credentials *cli_credentials_shallow_copy(TALLOC_CTX *mem_ctx,
262 struct cli_credentials *src);
265 * Return attached NETLOGON credentials
267 struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
269 #endif /* __CREDENTIALS_H__ */