Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into openchange
[amitay/samba.git] / source4 / auth / auth.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Standardised Authentication types
4    Copyright (C) Andrew Bartlett   2001
5    Copyright (C) Stefan Metzmacher 2005
6    
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.
11    
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.
16    
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/>.
19 */
20
21 #ifndef _SAMBA_AUTH_H
22 #define _SAMBA_AUTH_H
23
24 extern const char *user_attrs[];
25
26 union netr_Validation;
27 struct netr_SamBaseInfo;
28 struct netr_SamInfo3;
29 struct loadparm_context;
30
31 /* modules can use the following to determine if the interface has changed
32  * please increment the version number after each interface change
33  * with a comment and maybe update struct auth_critical_sizes.
34  */
35 /* version 1 - version from samba 3.0 - metze */
36 /* version 2 - initial samba4 version - metze */
37 /* version 3 - subsequent samba4 version - abartlet */
38 /* version 4 - subsequent samba4 version - metze */
39 /* version 0 - till samba4 is stable - metze */
40 #define AUTH_INTERFACE_VERSION 0
41
42 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
43 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
44 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT   0x04 /* dont check unix account status */
45 #define USER_INFO_INTERACTIVE_LOGON         0x08 /* dont check unix account status */
46
47 enum auth_password_state {
48         AUTH_PASSWORD_RESPONSE,
49         AUTH_PASSWORD_HASH,
50         AUTH_PASSWORD_PLAIN
51 };
52
53 struct auth_usersupplied_info
54 {
55         const char *workstation_name;
56         struct socket_address *remote_host;
57
58         uint32_t logon_parameters;
59
60         bool mapped_state;
61         /* the values the client gives us */
62         struct {
63                 const char *account_name;
64                 const char *domain_name;
65         } client, mapped;
66
67         enum auth_password_state password_state;
68
69         union {
70                 struct {
71                         DATA_BLOB lanman;
72                         DATA_BLOB nt;
73                 } response;
74                 struct {
75                         struct samr_Password *lanman;
76                         struct samr_Password *nt;
77                 } hash;
78                 
79                 char *plaintext;
80         } password;
81         uint32_t flags;
82 };
83
84 struct auth_serversupplied_info 
85 {
86         struct dom_sid *account_sid;
87         struct dom_sid *primary_group_sid;
88
89         size_t n_domain_groups;
90         struct dom_sid **domain_groups;
91
92         DATA_BLOB user_session_key;
93         DATA_BLOB lm_session_key;
94
95         const char *account_name;
96         const char *domain_name;
97
98         const char *full_name;
99         const char *logon_script;
100         const char *profile_path;
101         const char *home_directory;
102         const char *home_drive;
103         const char *logon_server;
104         
105         NTTIME last_logon;
106         NTTIME last_logoff;
107         NTTIME acct_expiry;
108         NTTIME last_password_change;
109         NTTIME allow_password_change;
110         NTTIME force_password_change;
111
112         uint16_t logon_count;
113         uint16_t bad_password_count;
114
115         uint32_t acct_flags;
116
117         bool authenticated;
118 };
119
120 struct auth_method_context;
121 struct auth_check_password_request;
122
123 struct auth_operations {
124         const char *name;
125
126         /* If you are using this interface, then you are probably
127          * getting something wrong.  This interface is only for
128          * security=server, and makes a number of compromises to allow
129          * that.  It is not compatible with being a PDC.  */
130
131         NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, DATA_BLOB *challenge);
132
133         /* Given the user supplied info, check if this backend want to handle the password checking */
134
135         NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
136                                const struct auth_usersupplied_info *user_info);
137
138         /* Given the user supplied info, check a password */
139
140         NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
141                                    const struct auth_usersupplied_info *user_info,
142                                    struct auth_serversupplied_info **server_info);
143 };
144
145 struct auth_method_context {
146         struct auth_method_context *prev, *next;
147         struct auth_context *auth_ctx;
148         const struct auth_operations *ops;
149         int depth;
150         void *private_data;
151 };
152
153 struct auth_context {
154         struct {
155                 /* Who set this up in the first place? */ 
156                 const char *set_by;
157
158                 bool may_be_modified;
159
160                 DATA_BLOB data; 
161         } challenge;
162
163         /* methods, in the order they should be called */
164         struct auth_method_context *methods;
165
166         /* the event context to use for calls that can block */
167         struct event_context *event_ctx;
168
169         /* the messaging context which can be used by backends */
170         struct messaging_context *msg_ctx;
171
172         /* loadparm context */
173         struct loadparm_context *lp_ctx;
174 };
175
176 /* this structure is used by backends to determine the size of some critical types */
177 struct auth_critical_sizes {
178         int interface_version;
179         int sizeof_auth_operations;
180         int sizeof_auth_methods;
181         int sizeof_auth_context;
182         int sizeof_auth_usersupplied_info;
183         int sizeof_auth_serversupplied_info;
184 };
185
186  NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context, 
187                            enum auth_password_state to_state,
188                            const struct auth_usersupplied_info *user_info_in,
189                            const struct auth_usersupplied_info **user_info_encrypted);
190
191 #include "auth/session.h"
192 #include "auth/system_session_proto.h"
193
194 struct ldb_message;
195 struct ldb_context;
196 NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, const uint8_t **_chal);
197 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
198                             struct ldb_context *sam_ctx,
199                             uint32_t logon_parameters,
200                             struct ldb_message *msg,
201                             struct ldb_message *msg_domain_ref,
202                             const char *logon_workstation,
203                             const char *name_for_logs);
204 struct auth_session_info *system_session(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
205 NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
206                                            const char *netbios_name,
207                                            struct ldb_message *msg,
208                                            struct ldb_message *msg_domain_ref,
209                                            DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
210                                            struct auth_serversupplied_info **_server_info);
211 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx, 
212                                            struct loadparm_context *lp_ctx,
213                                            struct auth_session_info **_session_info) ;
214 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
215
216 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods, 
217                                      struct event_context *ev,
218                                      struct messaging_context *msg,
219                                      struct loadparm_context *lp_ctx,
220                                      struct auth_context **auth_ctx);
221
222 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx, 
223                              struct event_context *ev,
224                              struct messaging_context *msg,
225                              struct loadparm_context *lp_ctx,
226                              struct auth_context **auth_ctx);
227
228 NTSTATUS auth_check_password(struct auth_context *auth_ctx,
229                              TALLOC_CTX *mem_ctx,
230                              const struct auth_usersupplied_info *user_info, 
231                              struct auth_serversupplied_info **server_info);
232 NTSTATUS auth_init(void);
233 NTSTATUS auth_register(const struct auth_operations *ops);
234 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
235                                            struct event_context *ev,
236                                            struct messaging_context *msg,
237                                            struct loadparm_context *lp_ctx,
238                                            const char *nt4_domain,
239                                            const char *nt4_username,
240                                            const char *password,
241                                            struct auth_session_info **session_info);
242 NTSTATUS auth_check_password_recv(struct auth_check_password_request *req,
243                                   TALLOC_CTX *mem_ctx,
244                                   struct auth_serversupplied_info **server_info);
245
246 void auth_check_password_send(struct auth_context *auth_ctx,
247                               const struct auth_usersupplied_info *user_info,
248                               void (*callback)(struct auth_check_password_request *req, void *private_data),
249                               void *private_data);
250 NTSTATUS auth_context_set_challenge(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
251
252 #endif /* _SMBAUTH_H_ */