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