r19598: Ahead of a merge to current lorikeet-heimdal:
[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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef _SAMBA_AUTH_H
23 #define _SAMBA_AUTH_H
24
25 union netr_Validation;
26
27 /* modules can use the following to determine if the interface has changed
28  * please increment the version number after each interface change
29  * with a comment and maybe update struct auth_critical_sizes.
30  */
31 /* version 1 - version from samba 3.0 - metze */
32 /* version 2 - initial samba4 version - metze */
33 /* version 3 - subsequent samba4 version - abartlet */
34 /* version 4 - subsequent samba4 version - metze */
35 /* version 0 - till samba4 is stable - metze */
36 #define AUTH_INTERFACE_VERSION 0
37
38 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
39 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
40 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT   0x04 /* dont check unix account status */
41 #define USER_INFO_INTERACTIVE_LOGON         0x08 /* dont check unix account status */
42
43 enum auth_password_state {
44         AUTH_PASSWORD_RESPONSE,
45         AUTH_PASSWORD_HASH,
46         AUTH_PASSWORD_PLAIN
47 };
48
49 struct auth_usersupplied_info
50 {
51         const char *workstation_name;
52         struct socket_address *remote_host;
53
54         uint32_t logon_parameters;
55
56         BOOL mapped_state;
57         /* the values the client gives us */
58         struct {
59                 const char *account_name;
60                 const char *domain_name;
61         } client, mapped;
62
63         enum auth_password_state password_state;
64
65         union {
66                 struct {
67                         DATA_BLOB lanman;
68                         DATA_BLOB nt;
69                 } response;
70                 struct {
71                         struct samr_Password *lanman;
72                         struct samr_Password *nt;
73                 } hash;
74                 
75                 char *plaintext;
76         } password;
77         uint32_t flags;
78 };
79
80 struct auth_serversupplied_info 
81 {
82         struct dom_sid *account_sid;
83         struct dom_sid *primary_group_sid;
84
85         size_t n_domain_groups;
86         struct dom_sid **domain_groups;
87
88         DATA_BLOB user_session_key;
89         DATA_BLOB lm_session_key;
90
91         const char *account_name;
92         const char *domain_name;
93
94         const char *full_name;
95         const char *logon_script;
96         const char *profile_path;
97         const char *home_directory;
98         const char *home_drive;
99         const char *logon_server;
100         
101         NTTIME last_logon;
102         NTTIME last_logoff;
103         NTTIME acct_expiry;
104         NTTIME last_password_change;
105         NTTIME allow_password_change;
106         NTTIME force_password_change;
107
108         uint16_t logon_count;
109         uint16_t bad_password_count;
110
111         uint32_t acct_flags;
112
113         BOOL authenticated;
114 };
115
116 struct auth_session_info {
117         struct security_token *security_token;
118         struct auth_serversupplied_info *server_info;
119         DATA_BLOB session_key;
120         struct cli_credentials *credentials;
121 };
122
123 struct auth_method_context;
124 struct auth_check_password_request;
125
126 struct auth_operations {
127         const char *name;
128
129         /* If you are using this interface, then you are probably
130          * getting something wrong.  This interface is only for
131          * security=server, and makes a number of compromises to allow
132          * that.  It is not compatible with being a PDC.  */
133
134         NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, DATA_BLOB *challenge);
135
136         /* Given the user supplied info, check if this backend want to handle the password checking */
137
138         NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
139                                const struct auth_usersupplied_info *user_info);
140
141         /* Given the user supplied info, check a password */
142
143         NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
144                                    const struct auth_usersupplied_info *user_info,
145                                    struct auth_serversupplied_info **server_info);
146 };
147
148 struct auth_method_context {
149         struct auth_method_context *prev, *next;
150         struct auth_context *auth_ctx;
151         const struct auth_operations *ops;
152         int depth;
153         void *private_data;
154 };
155
156 struct auth_context {
157         struct {
158                 /* Who set this up in the first place? */ 
159                 const char *set_by;
160
161                 BOOL may_be_modified;
162
163                 DATA_BLOB data; 
164         } challenge;
165
166         /* methods, in the order they should be called */
167         struct auth_method_context *methods;
168
169         /* the event context to use for calls that can block */
170         struct event_context *event_ctx;
171
172         /* the messaging context which can be used by backends */
173         struct messaging_context *msg_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/auth_proto.h"
192
193 #endif /* _SMBAUTH_H_ */