2 Unix SMB/CIFS implementation.
3 Standardised Authentication types
4 Copyright (C) Andrew Bartlett 2001
5 Copyright (C) Stefan Metzmacher 2005
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.
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.
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/>.
24 #include "librpc/gen_ndr/ndr_krb5pac.h"
26 extern const char *krbtgt_attrs
[];
27 extern const char *server_attrs
[];
28 extern const char *user_attrs
[];
30 union netr_Validation
;
31 struct netr_SamBaseInfo
;
33 struct loadparm_context
;
35 /* modules can use the following to determine if the interface has changed
36 * please increment the version number after each interface change
37 * with a comment and maybe update struct auth_critical_sizes.
39 /* version 1 - version from samba 3.0 - metze */
40 /* version 2 - initial samba4 version - metze */
41 /* version 3 - subsequent samba4 version - abartlet */
42 /* version 4 - subsequent samba4 version - metze */
43 /* version 0 - till samba4 is stable - metze */
44 #define AUTH_INTERFACE_VERSION 0
46 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
47 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
48 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT 0x04 /* don't check unix account status */
49 #define USER_INFO_INTERACTIVE_LOGON 0x08 /* don't check unix account status */
51 enum auth_password_state
{
52 AUTH_PASSWORD_RESPONSE
,
57 struct auth_usersupplied_info
59 const char *workstation_name
;
60 const struct tsocket_address
*remote_host
;
62 uint32_t logon_parameters
;
65 /* the values the client gives us */
67 const char *account_name
;
68 const char *domain_name
;
71 enum auth_password_state password_state
;
79 struct samr_Password
*lanman
;
80 struct samr_Password
*nt
;
88 struct auth_serversupplied_info
90 struct dom_sid
*account_sid
;
91 struct dom_sid
*primary_group_sid
;
93 size_t n_domain_groups
;
94 struct dom_sid
**domain_groups
;
96 DATA_BLOB user_session_key
;
97 DATA_BLOB lm_session_key
;
99 const char *account_name
;
100 const char *domain_name
;
102 const char *full_name
;
103 const char *logon_script
;
104 const char *profile_path
;
105 const char *home_directory
;
106 const char *home_drive
;
107 const char *logon_server
;
112 NTTIME last_password_change
;
113 NTTIME allow_password_change
;
114 NTTIME force_password_change
;
116 uint16_t logon_count
;
117 uint16_t bad_password_count
;
123 struct PAC_SIGNATURE_DATA pac_srv_sig
, pac_kdc_sig
;
126 struct auth_method_context
;
127 struct auth_check_password_request
;
130 struct auth_operations
{
133 /* If you are using this interface, then you are probably
134 * getting something wrong. This interface is only for
135 * security=server, and makes a number of compromises to allow
136 * that. It is not compatible with being a PDC. */
138 NTSTATUS (*get_challenge
)(struct auth_method_context
*ctx
, TALLOC_CTX
*mem_ctx
, uint8_t chal
[8]);
140 /* Given the user supplied info, check if this backend want to handle the password checking */
142 NTSTATUS (*want_check
)(struct auth_method_context
*ctx
, TALLOC_CTX
*mem_ctx
,
143 const struct auth_usersupplied_info
*user_info
);
145 /* Given the user supplied info, check a password */
147 NTSTATUS (*check_password
)(struct auth_method_context
*ctx
, TALLOC_CTX
*mem_ctx
,
148 const struct auth_usersupplied_info
*user_info
,
149 struct auth_serversupplied_info
**server_info
);
151 /* Lookup a 'server info' return based only on the principal */
152 NTSTATUS (*get_server_info_principal
)(TALLOC_CTX
*mem_ctx
,
153 struct auth_context
*auth_context
,
154 const char *principal
,
155 struct auth_serversupplied_info
**server_info
);
158 struct auth_method_context
{
159 struct auth_method_context
*prev
, *next
;
160 struct auth_context
*auth_ctx
;
161 const struct auth_operations
*ops
;
166 struct auth_context
{
168 /* Who set this up in the first place? */
171 bool may_be_modified
;
176 /* methods, in the order they should be called */
177 struct auth_method_context
*methods
;
179 /* the event context to use for calls that can block */
180 struct tevent_context
*event_ctx
;
182 /* the messaging context which can be used by backends */
183 struct messaging_context
*msg_ctx
;
185 /* loadparm context */
186 struct loadparm_context
*lp_ctx
;
188 NTSTATUS (*check_password
)(struct auth_context
*auth_ctx
,
190 const struct auth_usersupplied_info
*user_info
,
191 struct auth_serversupplied_info
**server_info
);
193 NTSTATUS (*get_challenge
)(struct auth_context
*auth_ctx
, uint8_t chal
[8]);
195 bool (*challenge_may_be_modified
)(struct auth_context
*auth_ctx
);
197 NTSTATUS (*set_challenge
)(struct auth_context
*auth_ctx
, const uint8_t chal
[8], const char *set_by
);
199 NTSTATUS (*get_server_info_principal
)(TALLOC_CTX
*mem_ctx
,
200 struct auth_context
*auth_context
,
201 const char *principal
,
202 struct auth_serversupplied_info
**server_info
);
206 /* this structure is used by backends to determine the size of some critical types */
207 struct auth_critical_sizes
{
208 int interface_version
;
209 int sizeof_auth_operations
;
210 int sizeof_auth_methods
;
211 int sizeof_auth_context
;
212 int sizeof_auth_usersupplied_info
;
213 int sizeof_auth_serversupplied_info
;
216 NTSTATUS
encrypt_user_info(TALLOC_CTX
*mem_ctx
, struct auth_context
*auth_context
,
217 enum auth_password_state to_state
,
218 const struct auth_usersupplied_info
*user_info_in
,
219 const struct auth_usersupplied_info
**user_info_encrypted
);
221 #include "auth/session.h"
222 #include "auth/system_session_proto.h"
227 struct gensec_security
;
229 NTSTATUS
auth_get_challenge(struct auth_context
*auth_ctx
, uint8_t chal
[8]);
230 NTSTATUS
authsam_account_ok(TALLOC_CTX
*mem_ctx
,
231 struct ldb_context
*sam_ctx
,
232 uint32_t logon_parameters
,
233 struct ldb_dn
*domain_dn
,
234 struct ldb_message
*msg
,
235 const char *logon_workstation
,
236 const char *name_for_logs
,
237 bool allow_domain_trust
,
238 bool password_change
);
239 struct auth_session_info
*system_session(struct loadparm_context
*lp_ctx
);
240 NTSTATUS
authsam_expand_nested_groups(struct ldb_context
*sam_ctx
,
241 const struct dom_sid
*sid
,
242 const bool only_childs
,
243 TALLOC_CTX
*res_sids_ctx
,
244 struct dom_sid
***res_sids
,
245 unsigned int *num_res_sids
);
246 NTSTATUS
authsam_make_server_info(TALLOC_CTX
*mem_ctx
, struct ldb_context
*sam_ctx
,
247 const char *netbios_name
,
248 const char *domain_name
,
249 struct ldb_dn
*domain_dn
,
250 struct ldb_message
*msg
,
251 DATA_BLOB user_sess_key
, DATA_BLOB lm_sess_key
,
252 struct auth_serversupplied_info
**_server_info
);
253 NTSTATUS
auth_system_session_info(TALLOC_CTX
*parent_ctx
,
254 struct loadparm_context
*lp_ctx
,
255 struct auth_session_info
**_session_info
) ;
256 NTSTATUS
auth_nt_status_squash(NTSTATUS nt_status
);
258 NTSTATUS
auth_context_create_methods(TALLOC_CTX
*mem_ctx
, const char **methods
,
259 struct tevent_context
*ev
,
260 struct messaging_context
*msg
,
261 struct loadparm_context
*lp_ctx
,
262 struct auth_context
**auth_ctx
);
264 NTSTATUS
auth_context_create(TALLOC_CTX
*mem_ctx
,
265 struct tevent_context
*ev
,
266 struct messaging_context
*msg
,
267 struct loadparm_context
*lp_ctx
,
268 struct auth_context
**auth_ctx
);
270 NTSTATUS
auth_check_password(struct auth_context
*auth_ctx
,
272 const struct auth_usersupplied_info
*user_info
,
273 struct auth_serversupplied_info
**server_info
);
274 NTSTATUS
auth_init(void);
275 NTSTATUS
auth_register(const struct auth_operations
*ops
);
276 NTSTATUS
authenticate_username_pw(TALLOC_CTX
*mem_ctx
,
277 struct tevent_context
*ev
,
278 struct messaging_context
*msg
,
279 struct loadparm_context
*lp_ctx
,
280 const char *nt4_domain
,
281 const char *nt4_username
,
282 const char *password
,
283 struct auth_session_info
**session_info
);
285 struct tevent_req
*auth_check_password_send(TALLOC_CTX
*mem_ctx
,
286 struct tevent_context
*ev
,
287 struct auth_context
*auth_ctx
,
288 const struct auth_usersupplied_info
*user_info
);
289 NTSTATUS
auth_check_password_recv(struct tevent_req
*req
,
291 struct auth_serversupplied_info
**server_info
);
293 bool auth_challenge_may_be_modified(struct auth_context
*auth_ctx
);
294 NTSTATUS
auth_context_set_challenge(struct auth_context
*auth_ctx
, const uint8_t chal
[8], const char *set_by
);
296 NTSTATUS
auth_get_server_info_principal(TALLOC_CTX
*mem_ctx
,
297 struct auth_context
*auth_ctx
,
298 const char *principal
,
299 struct auth_serversupplied_info
**server_info
);
301 NTSTATUS
samba_server_gensec_start(TALLOC_CTX
*mem_ctx
,
302 struct tevent_context
*event_ctx
,
303 struct messaging_context
*msg_ctx
,
304 struct loadparm_context
*lp_ctx
,
305 struct cli_credentials
*server_credentials
,
306 const char *target_service
,
307 struct gensec_security
**gensec_context
);
309 #endif /* _SMBAUTH_H_ */