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"
25 #include "../auth/common_auth.h"
27 extern const char *krbtgt_attrs
[];
28 extern const char *server_attrs
[];
29 extern const char *user_attrs
[];
31 union netr_Validation
;
32 struct netr_SamBaseInfo
;
34 struct loadparm_context
;
36 /* modules can use the following to determine if the interface has changed
37 * please increment the version number after each interface change
38 * with a comment and maybe update struct auth_critical_sizes.
40 /* version 1 - version from samba 3.0 - metze */
41 /* version 2 - initial samba4 version - metze */
42 /* version 3 - subsequent samba4 version - abartlet */
43 /* version 4 - subsequent samba4 version - metze */
44 /* version 0 - till samba4 is stable - metze */
45 #define AUTH_INTERFACE_VERSION 0
47 #define AUTH_SESSION_INFO_DEFAULT_GROUPS 0x01 /* Add the user to the default world and network groups */
48 #define AUTH_SESSION_INFO_AUTHENTICATED 0x02 /* Add the user to the 'authenticated users' group */
49 #define AUTH_SESSION_INFO_SIMPLE_PRIVILEGES 0x04 /* Use a trivial map between users and privilages, rather than a DB */
51 struct auth_serversupplied_info
53 struct dom_sid
*account_sid
;
54 struct dom_sid
*primary_group_sid
;
56 size_t n_domain_groups
;
57 struct dom_sid
**domain_groups
;
59 DATA_BLOB user_session_key
;
60 DATA_BLOB lm_session_key
;
62 const char *account_name
;
63 const char *domain_name
;
65 const char *full_name
;
66 const char *logon_script
;
67 const char *profile_path
;
68 const char *home_directory
;
69 const char *home_drive
;
70 const char *logon_server
;
75 NTTIME last_password_change
;
76 NTTIME allow_password_change
;
77 NTTIME force_password_change
;
80 uint16_t bad_password_count
;
86 struct PAC_SIGNATURE_DATA pac_srv_sig
, pac_kdc_sig
;
89 struct auth_method_context
;
90 struct auth_check_password_request
;
92 struct auth_session_info
;
95 struct auth_operations
{
98 /* If you are using this interface, then you are probably
99 * getting something wrong. This interface is only for
100 * security=server, and makes a number of compromises to allow
101 * that. It is not compatible with being a PDC. */
103 NTSTATUS (*get_challenge
)(struct auth_method_context
*ctx
, TALLOC_CTX
*mem_ctx
, uint8_t chal
[8]);
105 /* Given the user supplied info, check if this backend want to handle the password checking */
107 NTSTATUS (*want_check
)(struct auth_method_context
*ctx
, TALLOC_CTX
*mem_ctx
,
108 const struct auth_usersupplied_info
*user_info
);
110 /* Given the user supplied info, check a password */
112 NTSTATUS (*check_password
)(struct auth_method_context
*ctx
, TALLOC_CTX
*mem_ctx
,
113 const struct auth_usersupplied_info
*user_info
,
114 struct auth_serversupplied_info
**server_info
);
116 /* Lookup a 'server info' return based only on the principal */
117 NTSTATUS (*get_server_info_principal
)(TALLOC_CTX
*mem_ctx
,
118 struct auth_context
*auth_context
,
119 const char *principal
,
120 struct ldb_dn
*user_dn
,
121 struct auth_serversupplied_info
**server_info
);
124 struct auth_method_context
{
125 struct auth_method_context
*prev
, *next
;
126 struct auth_context
*auth_ctx
;
127 const struct auth_operations
*ops
;
132 struct auth_context
{
134 /* Who set this up in the first place? */
137 bool may_be_modified
;
142 /* methods, in the order they should be called */
143 struct auth_method_context
*methods
;
145 /* the event context to use for calls that can block */
146 struct tevent_context
*event_ctx
;
148 /* the messaging context which can be used by backends */
149 struct messaging_context
*msg_ctx
;
151 /* loadparm context */
152 struct loadparm_context
*lp_ctx
;
154 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
155 struct ldb_context
*sam_ctx
;
157 NTSTATUS (*check_password
)(struct auth_context
*auth_ctx
,
159 const struct auth_usersupplied_info
*user_info
,
160 struct auth_serversupplied_info
**server_info
);
162 NTSTATUS (*get_challenge
)(struct auth_context
*auth_ctx
, uint8_t chal
[8]);
164 bool (*challenge_may_be_modified
)(struct auth_context
*auth_ctx
);
166 NTSTATUS (*set_challenge
)(struct auth_context
*auth_ctx
, const uint8_t chal
[8], const char *set_by
);
168 NTSTATUS (*get_server_info_principal
)(TALLOC_CTX
*mem_ctx
,
169 struct auth_context
*auth_ctx
,
170 const char *principal
,
171 struct ldb_dn
*user_dn
,
172 struct auth_serversupplied_info
**server_info
);
174 NTSTATUS (*generate_session_info
)(TALLOC_CTX
*mem_ctx
,
175 struct auth_context
*auth_context
,
176 struct auth_serversupplied_info
*server_info
,
177 uint32_t session_info_flags
,
178 struct auth_session_info
**session_info
);
181 /* this structure is used by backends to determine the size of some critical types */
182 struct auth_critical_sizes
{
183 int interface_version
;
184 int sizeof_auth_operations
;
185 int sizeof_auth_methods
;
186 int sizeof_auth_context
;
187 int sizeof_auth_usersupplied_info
;
188 int sizeof_auth_serversupplied_info
;
191 NTSTATUS
encrypt_user_info(TALLOC_CTX
*mem_ctx
, struct auth_context
*auth_context
,
192 enum auth_password_state to_state
,
193 const struct auth_usersupplied_info
*user_info_in
,
194 const struct auth_usersupplied_info
**user_info_encrypted
);
196 #include "auth/session.h"
197 #include "auth/system_session_proto.h"
201 struct gensec_security
;
203 NTSTATUS
auth_get_challenge(struct auth_context
*auth_ctx
, uint8_t chal
[8]);
204 NTSTATUS
authsam_account_ok(TALLOC_CTX
*mem_ctx
,
205 struct ldb_context
*sam_ctx
,
206 uint32_t logon_parameters
,
207 struct ldb_dn
*domain_dn
,
208 struct ldb_message
*msg
,
209 const char *logon_workstation
,
210 const char *name_for_logs
,
211 bool allow_domain_trust
,
212 bool password_change
);
213 NTSTATUS
authsam_expand_nested_groups(struct ldb_context
*sam_ctx
,
214 struct ldb_val
*dn_val
, const bool only_childs
, const char *filter
,
215 TALLOC_CTX
*res_sids_ctx
, struct dom_sid
***res_sids
,
216 unsigned int *num_res_sids
);
217 struct auth_session_info
*system_session(struct loadparm_context
*lp_ctx
);
218 NTSTATUS
authsam_make_server_info(TALLOC_CTX
*mem_ctx
, struct ldb_context
*sam_ctx
,
219 const char *netbios_name
,
220 const char *domain_name
,
221 struct ldb_dn
*domain_dn
,
222 struct ldb_message
*msg
,
223 DATA_BLOB user_sess_key
, DATA_BLOB lm_sess_key
,
224 struct auth_serversupplied_info
**_server_info
);
225 NTSTATUS
auth_system_session_info(TALLOC_CTX
*parent_ctx
,
226 struct loadparm_context
*lp_ctx
,
227 struct auth_session_info
**_session_info
) ;
228 NTSTATUS
auth_nt_status_squash(NTSTATUS nt_status
);
230 NTSTATUS
auth_context_create_methods(TALLOC_CTX
*mem_ctx
, const char **methods
,
231 struct tevent_context
*ev
,
232 struct messaging_context
*msg
,
233 struct loadparm_context
*lp_ctx
,
234 struct ldb_context
*sam_ctx
,
235 struct auth_context
**auth_ctx
);
237 NTSTATUS
auth_context_create(TALLOC_CTX
*mem_ctx
,
238 struct tevent_context
*ev
,
239 struct messaging_context
*msg
,
240 struct loadparm_context
*lp_ctx
,
241 struct auth_context
**auth_ctx
);
242 NTSTATUS
auth_context_create_from_ldb(TALLOC_CTX
*mem_ctx
, struct ldb_context
*ldb
, struct auth_context
**auth_ctx
);
244 NTSTATUS
auth_check_password(struct auth_context
*auth_ctx
,
246 const struct auth_usersupplied_info
*user_info
,
247 struct auth_serversupplied_info
**server_info
);
248 NTSTATUS
auth_init(void);
249 NTSTATUS
auth_register(const struct auth_operations
*ops
);
250 NTSTATUS
server_service_auth_init(void);
251 NTSTATUS
authenticate_username_pw(TALLOC_CTX
*mem_ctx
,
252 struct tevent_context
*ev
,
253 struct messaging_context
*msg
,
254 struct loadparm_context
*lp_ctx
,
255 const char *nt4_domain
,
256 const char *nt4_username
,
257 const char *password
,
258 const uint32_t logon_parameters
,
259 struct auth_session_info
**session_info
);
261 struct tevent_req
*auth_check_password_send(TALLOC_CTX
*mem_ctx
,
262 struct tevent_context
*ev
,
263 struct auth_context
*auth_ctx
,
264 const struct auth_usersupplied_info
*user_info
);
265 NTSTATUS
auth_check_password_recv(struct tevent_req
*req
,
267 struct auth_serversupplied_info
**server_info
);
269 bool auth_challenge_may_be_modified(struct auth_context
*auth_ctx
);
270 NTSTATUS
auth_context_set_challenge(struct auth_context
*auth_ctx
, const uint8_t chal
[8], const char *set_by
);
272 NTSTATUS
auth_get_server_info_principal(TALLOC_CTX
*mem_ctx
,
273 struct auth_context
*auth_ctx
,
274 const char *principal
,
275 struct ldb_dn
*user_dn
,
276 struct auth_serversupplied_info
**server_info
);
278 NTSTATUS
samba_server_gensec_start(TALLOC_CTX
*mem_ctx
,
279 struct tevent_context
*event_ctx
,
280 struct messaging_context
*msg_ctx
,
281 struct loadparm_context
*lp_ctx
,
282 struct cli_credentials
*server_credentials
,
283 const char *target_service
,
284 struct gensec_security
**gensec_context
);
286 #endif /* _SMBAUTH_H_ */