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 "librpc/gen_ndr/auth.h"
26 #include "../auth/common_auth.h"
28 extern const char *krbtgt_attrs[];
29 extern const char *server_attrs[];
30 extern const char *user_attrs[];
32 union netr_Validation;
33 struct netr_SamBaseInfo;
35 struct loadparm_context;
37 /* modules can use the following to determine if the interface has changed
38 * please increment the version number after each interface change
39 * with a comment and maybe update struct auth_critical_sizes.
41 /* version 1 - version from samba 3.0 - metze */
42 /* version 2 - initial samba4 version - metze */
43 /* version 3 - subsequent samba4 version - abartlet */
44 /* version 4 - subsequent samba4 version - metze */
45 /* version 0 - till samba4 is stable - metze */
46 #define AUTH_INTERFACE_VERSION 0
48 #define AUTH_SESSION_INFO_DEFAULT_GROUPS 0x01 /* Add the user to the default world and network groups */
49 #define AUTH_SESSION_INFO_AUTHENTICATED 0x02 /* Add the user to the 'authenticated users' group */
50 #define AUTH_SESSION_INFO_SIMPLE_PRIVILEGES 0x04 /* Use a trivial map between users and privilages, rather than a DB */
52 struct auth_serversupplied_info
57 DATA_BLOB user_session_key;
58 DATA_BLOB lm_session_key;
60 const char *account_name;
61 const char *domain_name;
63 const char *full_name;
64 const char *logon_script;
65 const char *profile_path;
66 const char *home_directory;
67 const char *home_drive;
68 const char *logon_server;
73 NTTIME last_password_change;
74 NTTIME allow_password_change;
75 NTTIME force_password_change;
78 uint16_t bad_password_count;
84 struct PAC_SIGNATURE_DATA pac_srv_sig, pac_kdc_sig;
87 struct auth_method_context;
88 struct auth_check_password_request;
90 struct auth_session_info;
93 struct auth_operations {
96 /* If you are using this interface, then you are probably
97 * getting something wrong. This interface is only for
98 * security=server, and makes a number of compromises to allow
99 * that. It is not compatible with being a PDC. */
101 NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8]);
103 /* Given the user supplied info, check if this backend want to handle the password checking */
105 NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
106 const struct auth_usersupplied_info *user_info);
108 /* Given the user supplied info, check a password */
110 NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
111 const struct auth_usersupplied_info *user_info,
112 struct auth_serversupplied_info **server_info);
114 /* Lookup a 'server info' return based only on the principal */
115 NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
116 struct auth_context *auth_context,
117 const char *principal,
118 struct ldb_dn *user_dn,
119 struct auth_serversupplied_info **server_info);
122 struct auth_method_context {
123 struct auth_method_context *prev, *next;
124 struct auth_context *auth_ctx;
125 const struct auth_operations *ops;
130 struct auth_context {
132 /* Who set this up in the first place? */
135 bool may_be_modified;
140 /* methods, in the order they should be called */
141 struct auth_method_context *methods;
143 /* the event context to use for calls that can block */
144 struct tevent_context *event_ctx;
146 /* the messaging context which can be used by backends */
147 struct messaging_context *msg_ctx;
149 /* loadparm context */
150 struct loadparm_context *lp_ctx;
152 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
153 struct ldb_context *sam_ctx;
155 NTSTATUS (*check_password)(struct auth_context *auth_ctx,
157 const struct auth_usersupplied_info *user_info,
158 struct auth_serversupplied_info **server_info);
160 NTSTATUS (*get_challenge)(struct auth_context *auth_ctx, uint8_t chal[8]);
162 bool (*challenge_may_be_modified)(struct auth_context *auth_ctx);
164 NTSTATUS (*set_challenge)(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
166 NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
167 struct auth_context *auth_ctx,
168 const char *principal,
169 struct ldb_dn *user_dn,
170 struct auth_serversupplied_info **server_info);
172 NTSTATUS (*generate_session_info)(TALLOC_CTX *mem_ctx,
173 struct auth_context *auth_context,
174 struct auth_serversupplied_info *server_info,
175 uint32_t session_info_flags,
176 struct auth_session_info **session_info);
179 /* this structure is used by backends to determine the size of some critical types */
180 struct auth_critical_sizes {
181 int interface_version;
182 int sizeof_auth_operations;
183 int sizeof_auth_methods;
184 int sizeof_auth_context;
185 int sizeof_auth_usersupplied_info;
186 int sizeof_auth_serversupplied_info;
189 NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context,
190 enum auth_password_state to_state,
191 const struct auth_usersupplied_info *user_info_in,
192 const struct auth_usersupplied_info **user_info_encrypted);
194 #include "auth/session.h"
195 #include "auth/system_session_proto.h"
199 struct gensec_security;
201 NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, uint8_t chal[8]);
202 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
203 struct ldb_context *sam_ctx,
204 uint32_t logon_parameters,
205 struct ldb_dn *domain_dn,
206 struct ldb_message *msg,
207 const char *logon_workstation,
208 const char *name_for_logs,
209 bool allow_domain_trust,
210 bool password_change);
211 NTSTATUS authsam_expand_nested_groups(struct ldb_context *sam_ctx,
212 struct ldb_val *dn_val, const bool only_childs, const char *filter,
213 TALLOC_CTX *res_sids_ctx, struct dom_sid ***res_sids,
214 unsigned int *num_res_sids);
215 struct auth_session_info *system_session(struct loadparm_context *lp_ctx);
216 NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
217 const char *netbios_name,
218 const char *domain_name,
219 struct ldb_dn *domain_dn,
220 struct ldb_message *msg,
221 DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
222 struct auth_serversupplied_info **_server_info);
223 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx,
224 struct loadparm_context *lp_ctx,
225 struct auth_session_info **_session_info) ;
226 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
228 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods,
229 struct tevent_context *ev,
230 struct messaging_context *msg,
231 struct loadparm_context *lp_ctx,
232 struct ldb_context *sam_ctx,
233 struct auth_context **auth_ctx);
234 const char **auth_methods_from_lp(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
236 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx,
237 struct tevent_context *ev,
238 struct messaging_context *msg,
239 struct loadparm_context *lp_ctx,
240 struct auth_context **auth_ctx);
241 NTSTATUS auth_context_create_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct auth_context **auth_ctx);
243 NTSTATUS auth_check_password(struct auth_context *auth_ctx,
245 const struct auth_usersupplied_info *user_info,
246 struct auth_serversupplied_info **server_info);
247 NTSTATUS auth_init(void);
248 NTSTATUS auth_register(const struct auth_operations *ops);
249 NTSTATUS server_service_auth_init(void);
250 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
251 struct tevent_context *ev,
252 struct messaging_context *msg,
253 struct loadparm_context *lp_ctx,
254 const char *nt4_domain,
255 const char *nt4_username,
256 const char *password,
257 const uint32_t logon_parameters,
258 struct auth_session_info **session_info);
260 struct tevent_req *auth_check_password_send(TALLOC_CTX *mem_ctx,
261 struct tevent_context *ev,
262 struct auth_context *auth_ctx,
263 const struct auth_usersupplied_info *user_info);
264 NTSTATUS auth_check_password_recv(struct tevent_req *req,
266 struct auth_serversupplied_info **server_info);
268 bool auth_challenge_may_be_modified(struct auth_context *auth_ctx);
269 NTSTATUS auth_context_set_challenge(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
271 NTSTATUS auth_get_server_info_principal(TALLOC_CTX *mem_ctx,
272 struct auth_context *auth_ctx,
273 const char *principal,
274 struct ldb_dn *user_dn,
275 struct auth_serversupplied_info **server_info);
277 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
278 struct tevent_context *event_ctx,
279 struct messaging_context *msg_ctx,
280 struct loadparm_context *lp_ctx,
281 struct cli_credentials *server_credentials,
282 const char *target_service,
283 struct gensec_security **gensec_context);
285 #endif /* _SMBAUTH_H_ */