Don't use sigev_value.sival_int to just store the mid, use sigev_value.sival_ptr...
[Samba/ekacnet.git] / source4 / auth / auth.h
blob9ce338c8aefda56d3f9dca93c95a90e7070235cc
1 /*
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/>.
21 #ifndef _SAMBA_AUTH_H
22 #define _SAMBA_AUTH_H
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;
32 struct netr_SamInfo3;
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 #define AUTH_SESSION_INFO_DEFAULT_GROUPS 0x01 /* Add the user to the default world and network groups */
52 #define AUTH_SESSION_INFO_AUTHENTICATED 0x02 /* Add the user to the 'authenticated users' group */
53 #define AUTH_SESSION_INFO_ENTERPRISE_DC 0x04 /* Add the user to the 'enterprise DC' group */
55 enum auth_password_state {
56 AUTH_PASSWORD_RESPONSE,
57 AUTH_PASSWORD_HASH,
58 AUTH_PASSWORD_PLAIN
61 struct auth_usersupplied_info
63 const char *workstation_name;
64 const struct tsocket_address *remote_host;
66 uint32_t logon_parameters;
68 bool mapped_state;
69 /* the values the client gives us */
70 struct {
71 const char *account_name;
72 const char *domain_name;
73 } client, mapped;
75 enum auth_password_state password_state;
77 union {
78 struct {
79 DATA_BLOB lanman;
80 DATA_BLOB nt;
81 } response;
82 struct {
83 struct samr_Password *lanman;
84 struct samr_Password *nt;
85 } hash;
87 char *plaintext;
88 } password;
89 uint32_t flags;
92 struct auth_serversupplied_info
94 struct dom_sid *account_sid;
95 struct dom_sid *primary_group_sid;
97 size_t n_domain_groups;
98 struct dom_sid **domain_groups;
100 DATA_BLOB user_session_key;
101 DATA_BLOB lm_session_key;
103 const char *account_name;
104 const char *domain_name;
106 const char *full_name;
107 const char *logon_script;
108 const char *profile_path;
109 const char *home_directory;
110 const char *home_drive;
111 const char *logon_server;
113 NTTIME last_logon;
114 NTTIME last_logoff;
115 NTTIME acct_expiry;
116 NTTIME last_password_change;
117 NTTIME allow_password_change;
118 NTTIME force_password_change;
120 uint16_t logon_count;
121 uint16_t bad_password_count;
123 uint32_t acct_flags;
125 bool authenticated;
127 struct PAC_SIGNATURE_DATA pac_srv_sig, pac_kdc_sig;
130 struct auth_method_context;
131 struct auth_check_password_request;
132 struct auth_context;
133 struct auth_session_info;
134 struct ldb_dn;
136 struct auth_operations {
137 const char *name;
139 /* If you are using this interface, then you are probably
140 * getting something wrong. This interface is only for
141 * security=server, and makes a number of compromises to allow
142 * that. It is not compatible with being a PDC. */
144 NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8]);
146 /* Given the user supplied info, check if this backend want to handle the password checking */
148 NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
149 const struct auth_usersupplied_info *user_info);
151 /* Given the user supplied info, check a password */
153 NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
154 const struct auth_usersupplied_info *user_info,
155 struct auth_serversupplied_info **server_info);
157 /* Lookup a 'server info' return based only on the principal */
158 NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
159 struct auth_context *auth_context,
160 const char *principal,
161 struct ldb_dn *user_dn,
162 struct auth_serversupplied_info **server_info);
165 struct auth_method_context {
166 struct auth_method_context *prev, *next;
167 struct auth_context *auth_ctx;
168 const struct auth_operations *ops;
169 int depth;
170 void *private_data;
173 struct auth_context {
174 struct {
175 /* Who set this up in the first place? */
176 const char *set_by;
178 bool may_be_modified;
180 DATA_BLOB data;
181 } challenge;
183 /* methods, in the order they should be called */
184 struct auth_method_context *methods;
186 /* the event context to use for calls that can block */
187 struct tevent_context *event_ctx;
189 /* the messaging context which can be used by backends */
190 struct messaging_context *msg_ctx;
192 /* loadparm context */
193 struct loadparm_context *lp_ctx;
195 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
196 struct ldb_context *sam_ctx;
198 NTSTATUS (*check_password)(struct auth_context *auth_ctx,
199 TALLOC_CTX *mem_ctx,
200 const struct auth_usersupplied_info *user_info,
201 struct auth_serversupplied_info **server_info);
203 NTSTATUS (*get_challenge)(struct auth_context *auth_ctx, uint8_t chal[8]);
205 bool (*challenge_may_be_modified)(struct auth_context *auth_ctx);
207 NTSTATUS (*set_challenge)(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
209 NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
210 struct auth_context *auth_ctx,
211 const char *principal,
212 struct ldb_dn *user_dn,
213 struct auth_serversupplied_info **server_info);
215 NTSTATUS (*generate_session_info)(TALLOC_CTX *mem_ctx,
216 struct auth_context *auth_context,
217 struct auth_serversupplied_info *server_info,
218 uint32_t session_info_flags,
219 struct auth_session_info **session_info);
222 /* this structure is used by backends to determine the size of some critical types */
223 struct auth_critical_sizes {
224 int interface_version;
225 int sizeof_auth_operations;
226 int sizeof_auth_methods;
227 int sizeof_auth_context;
228 int sizeof_auth_usersupplied_info;
229 int sizeof_auth_serversupplied_info;
232 NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context,
233 enum auth_password_state to_state,
234 const struct auth_usersupplied_info *user_info_in,
235 const struct auth_usersupplied_info **user_info_encrypted);
237 #include "auth/session.h"
238 #include "auth/system_session_proto.h"
240 struct ldb_message;
241 struct ldb_context;
242 struct gensec_security;
244 NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, uint8_t chal[8]);
245 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
246 struct ldb_context *sam_ctx,
247 uint32_t logon_parameters,
248 struct ldb_dn *domain_dn,
249 struct ldb_message *msg,
250 const char *logon_workstation,
251 const char *name_for_logs,
252 bool allow_domain_trust,
253 bool password_change);
254 NTSTATUS authsam_expand_nested_groups(struct ldb_context *sam_ctx,
255 struct ldb_val *dn_val, const bool only_childs, const char *filter,
256 TALLOC_CTX *res_sids_ctx, struct dom_sid ***res_sids,
257 unsigned int *num_res_sids);
258 struct auth_session_info *system_session(struct loadparm_context *lp_ctx);
259 NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
260 const char *netbios_name,
261 const char *domain_name,
262 struct ldb_dn *domain_dn,
263 struct ldb_message *msg,
264 DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
265 struct auth_serversupplied_info **_server_info);
266 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx,
267 struct loadparm_context *lp_ctx,
268 struct auth_session_info **_session_info) ;
269 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
271 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods,
272 struct tevent_context *ev,
273 struct messaging_context *msg,
274 struct loadparm_context *lp_ctx,
275 struct ldb_context *sam_ctx,
276 struct auth_context **auth_ctx);
278 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx,
279 struct tevent_context *ev,
280 struct messaging_context *msg,
281 struct loadparm_context *lp_ctx,
282 struct auth_context **auth_ctx);
283 NTSTATUS auth_context_create_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct auth_context **auth_ctx);
285 NTSTATUS auth_check_password(struct auth_context *auth_ctx,
286 TALLOC_CTX *mem_ctx,
287 const struct auth_usersupplied_info *user_info,
288 struct auth_serversupplied_info **server_info);
289 NTSTATUS auth_init(void);
290 NTSTATUS auth_register(const struct auth_operations *ops);
291 NTSTATUS server_service_auth_init(void);
292 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
293 struct tevent_context *ev,
294 struct messaging_context *msg,
295 struct loadparm_context *lp_ctx,
296 const char *nt4_domain,
297 const char *nt4_username,
298 const char *password,
299 struct auth_session_info **session_info);
301 struct tevent_req *auth_check_password_send(TALLOC_CTX *mem_ctx,
302 struct tevent_context *ev,
303 struct auth_context *auth_ctx,
304 const struct auth_usersupplied_info *user_info);
305 NTSTATUS auth_check_password_recv(struct tevent_req *req,
306 TALLOC_CTX *mem_ctx,
307 struct auth_serversupplied_info **server_info);
309 bool auth_challenge_may_be_modified(struct auth_context *auth_ctx);
310 NTSTATUS auth_context_set_challenge(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
312 NTSTATUS auth_get_server_info_principal(TALLOC_CTX *mem_ctx,
313 struct auth_context *auth_ctx,
314 const char *principal,
315 struct ldb_dn *user_dn,
316 struct auth_serversupplied_info **server_info);
318 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
319 struct tevent_context *event_ctx,
320 struct messaging_context *msg_ctx,
321 struct loadparm_context *lp_ctx,
322 struct cli_credentials *server_credentials,
323 const char *target_service,
324 struct gensec_security **gensec_context);
326 #endif /* _SMBAUTH_H_ */