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
56 DATA_BLOB user_session_key;
57 DATA_BLOB lm_session_key;
59 const char *account_name;
60 const char *domain_name;
62 const char *full_name;
63 const char *logon_script;
64 const char *profile_path;
65 const char *home_directory;
66 const char *home_drive;
67 const char *logon_server;
72 NTTIME last_password_change;
73 NTTIME allow_password_change;
74 NTTIME force_password_change;
77 uint16_t bad_password_count;
83 struct PAC_SIGNATURE_DATA pac_srv_sig, pac_kdc_sig;
86 struct auth_method_context;
87 struct auth_check_password_request;
89 struct auth_session_info;
92 struct auth_operations {
95 /* If you are using this interface, then you are probably
96 * getting something wrong. This interface is only for
97 * security=server, and makes a number of compromises to allow
98 * that. It is not compatible with being a PDC. */
100 NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8]);
102 /* Given the user supplied info, check if this backend want to handle the password checking */
104 NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
105 const struct auth_usersupplied_info *user_info);
107 /* Given the user supplied info, check a password */
109 NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
110 const struct auth_usersupplied_info *user_info,
111 struct auth_serversupplied_info **server_info);
113 /* Lookup a 'server info' return based only on the principal */
114 NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
115 struct auth_context *auth_context,
116 const char *principal,
117 struct ldb_dn *user_dn,
118 struct auth_serversupplied_info **server_info);
121 struct auth_method_context {
122 struct auth_method_context *prev, *next;
123 struct auth_context *auth_ctx;
124 const struct auth_operations *ops;
129 struct auth_context {
131 /* Who set this up in the first place? */
134 bool may_be_modified;
139 /* methods, in the order they should be called */
140 struct auth_method_context *methods;
142 /* the event context to use for calls that can block */
143 struct tevent_context *event_ctx;
145 /* the messaging context which can be used by backends */
146 struct messaging_context *msg_ctx;
148 /* loadparm context */
149 struct loadparm_context *lp_ctx;
151 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
152 struct ldb_context *sam_ctx;
154 NTSTATUS (*check_password)(struct auth_context *auth_ctx,
156 const struct auth_usersupplied_info *user_info,
157 struct auth_serversupplied_info **server_info);
159 NTSTATUS (*get_challenge)(struct auth_context *auth_ctx, uint8_t chal[8]);
161 bool (*challenge_may_be_modified)(struct auth_context *auth_ctx);
163 NTSTATUS (*set_challenge)(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
165 NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
166 struct auth_context *auth_ctx,
167 const char *principal,
168 struct ldb_dn *user_dn,
169 struct auth_serversupplied_info **server_info);
171 NTSTATUS (*generate_session_info)(TALLOC_CTX *mem_ctx,
172 struct auth_context *auth_context,
173 struct auth_serversupplied_info *server_info,
174 uint32_t session_info_flags,
175 struct auth_session_info **session_info);
178 /* this structure is used by backends to determine the size of some critical types */
179 struct auth_critical_sizes {
180 int interface_version;
181 int sizeof_auth_operations;
182 int sizeof_auth_methods;
183 int sizeof_auth_context;
184 int sizeof_auth_usersupplied_info;
185 int sizeof_auth_serversupplied_info;
188 NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context,
189 enum auth_password_state to_state,
190 const struct auth_usersupplied_info *user_info_in,
191 const struct auth_usersupplied_info **user_info_encrypted);
193 #include "auth/session.h"
194 #include "auth/system_session_proto.h"
198 struct gensec_security;
200 NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, uint8_t chal[8]);
201 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
202 struct ldb_context *sam_ctx,
203 uint32_t logon_parameters,
204 struct ldb_dn *domain_dn,
205 struct ldb_message *msg,
206 const char *logon_workstation,
207 const char *name_for_logs,
208 bool allow_domain_trust,
209 bool password_change);
210 NTSTATUS authsam_expand_nested_groups(struct ldb_context *sam_ctx,
211 struct ldb_val *dn_val, const bool only_childs, const char *filter,
212 TALLOC_CTX *res_sids_ctx, struct dom_sid ***res_sids,
213 unsigned int *num_res_sids);
214 struct auth_session_info *system_session(struct loadparm_context *lp_ctx);
215 NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
216 const char *netbios_name,
217 const char *domain_name,
218 struct ldb_dn *domain_dn,
219 struct ldb_message *msg,
220 DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
221 struct auth_serversupplied_info **_server_info);
222 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx,
223 struct loadparm_context *lp_ctx,
224 struct auth_session_info **_session_info) ;
225 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
227 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods,
228 struct tevent_context *ev,
229 struct messaging_context *msg,
230 struct loadparm_context *lp_ctx,
231 struct ldb_context *sam_ctx,
232 struct auth_context **auth_ctx);
233 const char **auth_methods_from_lp(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
235 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx,
236 struct tevent_context *ev,
237 struct messaging_context *msg,
238 struct loadparm_context *lp_ctx,
239 struct auth_context **auth_ctx);
240 NTSTATUS auth_context_create_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct auth_context **auth_ctx);
242 NTSTATUS auth_check_password(struct auth_context *auth_ctx,
244 const struct auth_usersupplied_info *user_info,
245 struct auth_serversupplied_info **server_info);
246 NTSTATUS auth_init(void);
247 NTSTATUS auth_register(const struct auth_operations *ops);
248 NTSTATUS server_service_auth_init(void);
249 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
250 struct tevent_context *ev,
251 struct messaging_context *msg,
252 struct loadparm_context *lp_ctx,
253 const char *nt4_domain,
254 const char *nt4_username,
255 const char *password,
256 const uint32_t logon_parameters,
257 struct auth_session_info **session_info);
259 struct tevent_req *auth_check_password_send(TALLOC_CTX *mem_ctx,
260 struct tevent_context *ev,
261 struct auth_context *auth_ctx,
262 const struct auth_usersupplied_info *user_info);
263 NTSTATUS auth_check_password_recv(struct tevent_req *req,
265 struct auth_serversupplied_info **server_info);
267 bool auth_challenge_may_be_modified(struct auth_context *auth_ctx);
268 NTSTATUS auth_context_set_challenge(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
270 NTSTATUS auth_get_server_info_principal(TALLOC_CTX *mem_ctx,
271 struct auth_context *auth_ctx,
272 const char *principal,
273 struct ldb_dn *user_dn,
274 struct auth_serversupplied_info **server_info);
276 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
277 struct tevent_context *event_ctx,
278 struct messaging_context *msg_ctx,
279 struct loadparm_context *lp_ctx,
280 struct cli_credentials *server_credentials,
281 const char *target_service,
282 struct gensec_security **gensec_context);
284 #endif /* _SMBAUTH_H_ */