r1067: fix compiler warnings
[samba.git] / source4 / auth / auth.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Standardised Authentication types
4    Copyright (C) Andrew Bartlett 2001
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef _SAMBA_AUTH_H
22 #define _SAMBA_AUTH_H
23
24 /* modules can use the following to determine if the interface has changed
25  * please increment the version number after each interface change
26  * with a comment and maybe update struct auth_critical_sizes.
27  */
28 /* version 1 - version from samba 3.0 - metze */
29 /* version 2 - initial samba4 version - metze */
30 /* version 3 - subsequent samba4 version - abartlet */
31 #define AUTH_INTERFACE_VERSION 3
32
33 /* AUTH_STR - string */
34 typedef struct auth_str
35 {
36         int len;
37         char *str;
38 } AUTH_STR;
39
40 struct auth_usersupplied_info
41 {
42         
43         DATA_BLOB lm_resp;
44         DATA_BLOB nt_resp;
45         DATA_BLOB lm_interactive_password;
46         DATA_BLOB nt_interactive_password;
47         DATA_BLOB plaintext_password;
48         
49         BOOL encrypted;
50         
51         AUTH_STR           client_domain;          /* domain name string */
52         AUTH_STR           domain;               /* domain name after mapping */
53         AUTH_STR           internal_username;    /* username after mapping */
54         AUTH_STR           smb_name;        /* username before mapping */
55         AUTH_STR           wksta_name;           /* workstation name (netbios calling name) unicode string */
56         
57 };
58
59 struct auth_serversupplied_info 
60 {
61         TALLOC_CTX *mem_ctx;
62
63         BOOL guest;
64         
65         struct dom_sid *user_sid;
66         struct dom_sid *primary_group_sid;
67
68         size_t n_domain_groups;
69         struct dom_sid **domain_groups;
70         
71         DATA_BLOB user_session_key;
72         DATA_BLOB lm_session_key;
73
74         const char *account_name;
75         const char *domain;
76
77         const char *full_name;
78         const char *logon_script;
79         const char *profile_path;
80         const char *home_directory;
81         const char *home_drive;
82         
83         NTTIME last_logon;
84         NTTIME last_logoff;
85         NTTIME acct_expiry;
86         NTTIME last_password_change;
87         NTTIME allow_password_change;
88         NTTIME force_password_change;
89         
90         uint16 logon_count;
91         uint16 bad_password_count;
92         
93         uint32 acct_flags;
94 };
95
96 struct auth_session_info 
97 {
98         TALLOC_CTX *mem_ctx;
99         /* NT group information taken from the info3 structure */
100         
101         NT_USER_TOKEN *nt_user_token;
102
103         struct auth_serversupplied_info *server_info;
104
105         DATA_BLOB session_key;
106 };
107
108 struct auth_context {
109         DATA_BLOB challenge; 
110
111         /* Who set this up in the first place? */ 
112         const char *challenge_set_by; 
113
114         BOOL challenge_may_be_modified;
115
116         struct auth_methods *challenge_set_method; 
117         /* What order are the various methods in?   Try to stop it changing under us */ 
118         struct auth_methods *auth_method_list;  
119
120         TALLOC_CTX *mem_ctx;
121         const uint8_t *(*get_ntlm_challenge)(struct auth_context *auth_context);
122         NTSTATUS (*check_ntlm_password)(struct auth_context *auth_context,
123                                         const struct auth_usersupplied_info *user_info, 
124                                         struct auth_serversupplied_info **server_info);
125         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
126 };
127
128 struct auth_methods
129 {
130         struct auth_methods *prev, *next;
131         const char *name; /* What name got this module */
132
133         NTSTATUS (*auth)(const struct auth_context *auth_context,
134                          void *my_private_data, 
135                          TALLOC_CTX *mem_ctx,
136                          const struct auth_usersupplied_info *user_info, 
137                          struct auth_serversupplied_info **server_info);
138
139         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
140                               void **my_private_data, 
141                               TALLOC_CTX *mem_ctx);
142         
143         /* Used to keep tabs on things like the cli for SMB server authentication */
144         void *private_data;
145         
146         /* Function to clean up the above arbitary structure */
147         void (*free_private_data)(void **private_data);
148
149         /* Function to send a keepalive message on the above structure */
150         void (*send_keepalive)(void **private_data);
151
152 };
153
154 typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **);
155
156 struct auth_init_function_entry {
157         const char *name;
158         /* Function to create a member of the authmethods list */
159
160         auth_init_function init;
161
162         struct auth_init_function_entry *prev, *next;
163 };
164
165 struct auth_ntlmssp_state
166 {
167         TALLOC_CTX *mem_ctx;
168         struct auth_context *auth_context;
169         struct auth_serversupplied_info *server_info;
170         struct ntlmssp_state *ntlmssp_state;
171 };
172
173 #define auth_ops __XXX_ERROR_BLA
174 struct auth_operations {
175         /* the name of the backend */
176         const char *name;
177
178         /* Function to create a member of the authmethods list */
179         NTSTATUS (*init)(struct auth_context *, const char *, struct auth_methods **);
180 };
181
182 /* this structure is used by backends to determine the size of some critical types */
183 struct auth_critical_sizes {
184         int interface_version;
185         int sizeof_auth_operations;
186         int sizeof_auth_methods;
187         int sizeof_auth_context;
188         int sizeof_auth_ntlmssp_state;
189         int sizeof_auth_usersupplied_info;
190         int sizeof_auth_serversupplied_info;
191         int sizeof_auth_str;
192         int sizeof_auth_unistr;
193 };
194
195 #endif /* _SMBAUTH_H_ */