s3:libsmb: Plumb cli_smb2_dskattr() inside cli_dskattr().
[Samba.git] / auth / credentials / credentials.h
blob766a513cca939c77a7e3072dd4290280c6ce5c58
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_kerberos_state(struct cli_credentials *creds,
122 enum credentials_use_kerberos use_kerberos);
123 void cli_credentials_set_krb_forwardable(struct cli_credentials *creds,
124 enum credentials_krb_forwardable krb_forwardable);
125 bool cli_credentials_set_domain(struct cli_credentials *cred,
126 const char *val,
127 enum credentials_obtained obtained);
128 bool cli_credentials_set_domain_callback(struct cli_credentials *cred,
129 const char *(*domain_cb) (struct cli_credentials *));
130 bool cli_credentials_set_username(struct cli_credentials *cred,
131 const char *val, enum credentials_obtained obtained);
132 bool cli_credentials_set_username_callback(struct cli_credentials *cred,
133 const char *(*username_cb) (struct cli_credentials *));
134 bool cli_credentials_set_principal(struct cli_credentials *cred,
135 const char *val,
136 enum credentials_obtained obtained);
137 bool cli_credentials_set_principal_callback(struct cli_credentials *cred,
138 const char *(*principal_cb) (struct cli_credentials *));
139 bool cli_credentials_set_password(struct cli_credentials *cred,
140 const char *val,
141 enum credentials_obtained obtained);
142 struct cli_credentials *cli_credentials_init_anon(TALLOC_CTX *mem_ctx);
143 void cli_credentials_parse_string(struct cli_credentials *credentials, const char *data, enum credentials_obtained obtained);
144 struct samr_Password *cli_credentials_get_nt_hash(struct cli_credentials *cred,
145 TALLOC_CTX *mem_ctx);
146 bool cli_credentials_set_realm(struct cli_credentials *cred,
147 const char *val,
148 enum credentials_obtained obtained);
149 void cli_credentials_set_secure_channel_type(struct cli_credentials *cred,
150 enum netr_SchannelType secure_channel_type);
151 void cli_credentials_set_password_last_changed_time(struct cli_credentials *cred,
152 time_t last_change_time);
153 void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
154 struct netlogon_creds_CredentialState *netlogon_creds);
155 NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred,
156 struct smb_krb5_context *smb_krb5_context);
157 NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
158 struct loadparm_context *lp_ctx,
159 const char *serviceprincipal);
160 NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred,
161 struct loadparm_context *lp_ctx);
162 bool cli_credentials_authentication_requested(struct cli_credentials *cred);
163 void cli_credentials_guess(struct cli_credentials *cred,
164 struct loadparm_context *lp_ctx);
165 bool cli_credentials_set_bind_dn(struct cli_credentials *cred,
166 const char *bind_dn);
167 const char *cli_credentials_get_bind_dn(struct cli_credentials *cred);
168 bool cli_credentials_parse_file(struct cli_credentials *cred, const char *file, enum credentials_obtained obtained);
169 const char *cli_credentials_get_unparsed_name(struct cli_credentials *credentials, TALLOC_CTX *mem_ctx);
170 bool cli_credentials_set_password_callback(struct cli_credentials *cred,
171 const char *(*password_cb) (struct cli_credentials *));
172 enum netr_SchannelType cli_credentials_get_secure_channel_type(struct cli_credentials *cred);
173 time_t cli_credentials_get_password_last_changed_time(struct cli_credentials *cred);
174 void cli_credentials_set_kvno(struct cli_credentials *cred,
175 int kvno);
176 bool cli_credentials_set_nt_hash(struct cli_credentials *cred,
177 const struct samr_Password *nt_hash,
178 enum credentials_obtained obtained);
179 bool cli_credentials_set_ntlm_response(struct cli_credentials *cred,
180 const DATA_BLOB *lm_response,
181 const DATA_BLOB *nt_response,
182 enum credentials_obtained obtained);
183 int cli_credentials_set_keytab_name(struct cli_credentials *cred,
184 struct loadparm_context *lp_ctx,
185 const char *keytab_name,
186 enum credentials_obtained obtained);
187 void cli_credentials_set_gensec_features(struct cli_credentials *creds, uint32_t gensec_features);
188 uint32_t cli_credentials_get_gensec_features(struct cli_credentials *creds);
189 int cli_credentials_set_ccache(struct cli_credentials *cred,
190 struct loadparm_context *lp_ctx,
191 const char *name,
192 enum credentials_obtained obtained,
193 const char **error_string);
194 bool cli_credentials_parse_password_file(struct cli_credentials *credentials, const char *file, enum credentials_obtained obtained);
195 bool cli_credentials_parse_password_fd(struct cli_credentials *credentials,
196 int fd, enum credentials_obtained obtained);
197 void cli_credentials_invalidate_ccache(struct cli_credentials *cred,
198 enum credentials_obtained obtained);
199 void cli_credentials_set_salt_principal(struct cli_credentials *cred, const char *principal);
200 void cli_credentials_set_impersonate_principal(struct cli_credentials *cred,
201 const char *principal,
202 const char *self_service);
203 void cli_credentials_set_target_service(struct cli_credentials *cred, const char *principal);
204 const char *cli_credentials_get_salt_principal(struct cli_credentials *cred);
205 const char *cli_credentials_get_impersonate_principal(struct cli_credentials *cred);
206 const char *cli_credentials_get_self_service(struct cli_credentials *cred);
207 const char *cli_credentials_get_target_service(struct cli_credentials *cred);
208 enum credentials_use_kerberos cli_credentials_get_kerberos_state(struct cli_credentials *creds);
209 enum credentials_krb_forwardable cli_credentials_get_krb_forwardable(struct cli_credentials *creds);
210 NTSTATUS cli_credentials_set_secrets(struct cli_credentials *cred,
211 struct loadparm_context *lp_ctx,
212 struct ldb_context *ldb,
213 const char *base,
214 const char *filter,
215 char **error_string);
216 int cli_credentials_get_kvno(struct cli_credentials *cred);
218 bool cli_credentials_set_username_callback(struct cli_credentials *cred,
219 const char *(*username_cb) (struct cli_credentials *));
222 * Obtain the client principal for this credentials context.
223 * @param cred credentials context
224 * @retval The username set on this context.
225 * @note Return value will never be NULL except by programmer error.
227 const char *cli_credentials_get_principal_and_obtained(struct cli_credentials *cred, TALLOC_CTX *mem_ctx, enum credentials_obtained *obtained);
228 bool cli_credentials_set_principal(struct cli_credentials *cred,
229 const char *val,
230 enum credentials_obtained obtained);
231 bool cli_credentials_set_principal_callback(struct cli_credentials *cred,
232 const char *(*principal_cb) (struct cli_credentials *));
235 * Obtain the 'old' password for this credentials context (used for join accounts).
236 * @param cred credentials context
237 * @retval If set, the cleartext password, otherwise NULL
239 const char *cli_credentials_get_old_password(struct cli_credentials *cred);
240 bool cli_credentials_set_old_password(struct cli_credentials *cred,
241 const char *val,
242 enum credentials_obtained obtained);
243 bool cli_credentials_set_domain_callback(struct cli_credentials *cred,
244 const char *(*domain_cb) (struct cli_credentials *));
245 bool cli_credentials_set_realm_callback(struct cli_credentials *cred,
246 const char *(*realm_cb) (struct cli_credentials *));
247 bool cli_credentials_set_workstation_callback(struct cli_credentials *cred,
248 const char *(*workstation_cb) (struct cli_credentials *));
250 void cli_credentials_set_callback_data(struct cli_credentials *cred,
251 void *callback_data);
252 void *_cli_credentials_callback_data(struct cli_credentials *cred);
253 #define cli_credentials_callback_data(_cred, _type) \
254 talloc_get_type_abort(_cli_credentials_callback_data(_cred), _type)
255 #define cli_credentials_callback_data_void(_cred) \
256 _cli_credentials_callback_data(_cred)
258 struct cli_credentials *cli_credentials_shallow_copy(TALLOC_CTX *mem_ctx,
259 struct cli_credentials *src);
262 * Return attached NETLOGON credentials
264 struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
266 #endif /* __CREDENTIALS_H__ */