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 AUTH4_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 */
51 #define AUTH_SESSION_INFO_UNIX_TOKEN 0x08 /* The returned token must have the unix_token and unix_info elements provided */
53 struct auth_method_context;
54 struct auth_check_password_request;
56 struct auth_session_info;
58 struct smb_krb5_context;
60 struct auth_operations {
63 /* If you are using this interface, then you are probably
64 * getting something wrong. This interface is only for
65 * security=server, and makes a number of compromises to allow
66 * that. It is not compatible with being a PDC. */
68 NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8]);
70 /* Given the user supplied info, check if this backend want to handle the password checking */
72 NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
73 const struct auth_usersupplied_info *user_info);
75 /* Given the user supplied info, check a password */
77 NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
78 const struct auth_usersupplied_info *user_info,
79 struct auth_user_info_dc **interim_info);
81 /* Lookup a 'session info interim' return based only on the principal or DN */
82 NTSTATUS (*get_user_info_dc_principal)(TALLOC_CTX *mem_ctx,
83 struct auth4_context *auth_context,
84 const char *principal,
85 struct ldb_dn *user_dn,
86 struct auth_user_info_dc **interim_info);
89 struct auth_method_context {
90 struct auth_method_context *prev, *next;
91 struct auth4_context *auth_ctx;
92 const struct auth_operations *ops;
97 struct auth4_context {
99 /* Who set this up in the first place? */
102 bool may_be_modified;
107 /* methods, in the order they should be called */
108 struct auth_method_context *methods;
110 /* the event context to use for calls that can block */
111 struct tevent_context *event_ctx;
113 /* the messaging context which can be used by backends */
114 struct imessaging_context *msg_ctx;
116 /* loadparm context */
117 struct loadparm_context *lp_ctx;
119 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
120 struct ldb_context *sam_ctx;
122 NTSTATUS (*check_password)(struct auth4_context *auth_ctx,
124 const struct auth_usersupplied_info *user_info,
125 struct auth_user_info_dc **user_info_dc);
127 NTSTATUS (*get_challenge)(struct auth4_context *auth_ctx, uint8_t chal[8]);
129 bool (*challenge_may_be_modified)(struct auth4_context *auth_ctx);
131 NTSTATUS (*set_challenge)(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
133 NTSTATUS (*generate_session_info)(TALLOC_CTX *mem_ctx,
134 struct auth4_context *auth_context,
135 struct auth_user_info_dc *user_info_dc,
136 uint32_t session_info_flags,
137 struct auth_session_info **session_info);
139 NTSTATUS (*generate_session_info_pac)(struct auth4_context *auth_ctx,
140 TALLOC_CTX *mem_ctx_out,
141 struct smb_krb5_context *smb_krb5_context,
143 const char *principal_name,
144 const struct tsocket_address *remote_address,
145 uint32_t session_info_flags,
146 struct auth_session_info **session_info);
149 /* this structure is used by backends to determine the size of some critical types */
150 struct auth_critical_sizes {
151 int interface_version;
152 int sizeof_auth_operations;
153 int sizeof_auth_methods;
154 int sizeof_auth_context;
155 int sizeof_auth_usersupplied_info;
156 int sizeof_auth_user_info_dc;
159 NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth4_context *auth_context,
160 enum auth_password_state to_state,
161 const struct auth_usersupplied_info *user_info_in,
162 const struct auth_usersupplied_info **user_info_encrypted);
165 #include "auth/session.h"
166 #include "auth/unix_token_proto.h"
167 #include "auth/system_session_proto.h"
168 #include "libcli/security/security.h"
172 struct gensec_security;
173 struct cli_credentials;
175 NTSTATUS auth_get_challenge(struct auth4_context *auth_ctx, uint8_t chal[8]);
176 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
177 struct ldb_context *sam_ctx,
178 uint32_t logon_parameters,
179 struct ldb_dn *domain_dn,
180 struct ldb_message *msg,
181 const char *logon_workstation,
182 const char *name_for_logs,
183 bool allow_domain_trust,
184 bool password_change);
186 struct auth_session_info *system_session(struct loadparm_context *lp_ctx);
187 NTSTATUS authsam_make_user_info_dc(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
188 const char *netbios_name,
189 const char *domain_name,
190 struct ldb_dn *domain_dn,
191 struct ldb_message *msg,
192 DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
193 struct auth_user_info_dc **_user_info_dc);
194 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx,
195 struct loadparm_context *lp_ctx,
196 struct auth_session_info **_session_info) ;
198 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods,
199 struct tevent_context *ev,
200 struct imessaging_context *msg,
201 struct loadparm_context *lp_ctx,
202 struct ldb_context *sam_ctx,
203 struct auth4_context **auth_ctx);
204 const char **auth_methods_from_lp(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
206 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx,
207 struct tevent_context *ev,
208 struct imessaging_context *msg,
209 struct loadparm_context *lp_ctx,
210 struct auth4_context **auth_ctx);
212 NTSTATUS auth_check_password(struct auth4_context *auth_ctx,
214 const struct auth_usersupplied_info *user_info,
215 struct auth_user_info_dc **user_info_dc);
216 NTSTATUS auth4_init(void);
217 NTSTATUS auth_register(const struct auth_operations *ops);
218 NTSTATUS server_service_auth_init(void);
219 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
220 struct tevent_context *ev,
221 struct imessaging_context *msg,
222 struct loadparm_context *lp_ctx,
223 const char *nt4_domain,
224 const char *nt4_username,
225 const char *password,
226 const uint32_t logon_parameters,
227 struct auth_session_info **session_info);
229 struct tevent_req *auth_check_password_send(TALLOC_CTX *mem_ctx,
230 struct tevent_context *ev,
231 struct auth4_context *auth_ctx,
232 const struct auth_usersupplied_info *user_info);
233 NTSTATUS auth_check_password_recv(struct tevent_req *req,
235 struct auth_user_info_dc **user_info_dc);
237 bool auth_challenge_may_be_modified(struct auth4_context *auth_ctx);
238 NTSTATUS auth_context_set_challenge(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
240 NTSTATUS auth_get_user_info_dc_principal(TALLOC_CTX *mem_ctx,
241 struct auth4_context *auth_ctx,
242 const char *principal,
243 struct ldb_dn *user_dn,
244 struct auth_user_info_dc **user_info_dc);
246 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
247 struct tevent_context *event_ctx,
248 struct imessaging_context *msg_ctx,
249 struct loadparm_context *lp_ctx,
250 struct cli_credentials *server_credentials,
251 const char *target_service,
252 struct gensec_security **gensec_context);
254 #endif /* _SMBAUTH_H_ */