r3571: rough guesses at what abartlet really wanted to do in his last commit
[metze/samba/wip.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 #include "libcli/auth/ntlmssp.h"
25 #include "libcli/auth/credentials.h"
26 #include "libcli/auth/gensec.h"
27 #include "libcli/auth/spnego.h"
28
29 /* modules can use the following to determine if the interface has changed
30  * please increment the version number after each interface change
31  * with a comment and maybe update struct auth_critical_sizes.
32  */
33 /* version 1 - version from samba 3.0 - metze */
34 /* version 2 - initial samba4 version - metze */
35 /* version 3 - subsequent samba4 version - abartlet */
36 #define AUTH_INTERFACE_VERSION 3
37
38 /* AUTH_STR - string */
39 typedef struct auth_str
40 {
41         int len;
42         char *str;
43 } AUTH_STR;
44
45 struct auth_usersupplied_info
46 {
47         
48         DATA_BLOB lm_resp;
49         DATA_BLOB nt_resp;
50         DATA_BLOB lm_interactive_password;
51         DATA_BLOB nt_interactive_password;
52         DATA_BLOB plaintext_password;
53         
54         BOOL encrypted;
55         
56         AUTH_STR           client_domain;          /* domain name string */
57         AUTH_STR           domain;               /* domain name after mapping */
58         AUTH_STR           internal_username;    /* username after mapping */
59         AUTH_STR           smb_name;        /* username before mapping */
60         AUTH_STR           wksta_name;           /* workstation name (netbios calling name) unicode string */
61         
62 };
63
64 struct auth_serversupplied_info 
65 {
66         BOOL guest;
67         
68         struct dom_sid *user_sid;
69         struct dom_sid *primary_group_sid;
70
71         size_t n_domain_groups;
72         struct dom_sid **domain_groups;
73         
74         DATA_BLOB user_session_key;
75         DATA_BLOB lm_session_key;
76
77         const char *account_name;
78         const char *domain;
79         const char *realm;
80
81         const char *full_name;
82         const char *logon_script;
83         const char *profile_path;
84         const char *home_directory;
85         const char *home_drive;
86         
87         NTTIME last_logon;
88         NTTIME last_logoff;
89         NTTIME acct_expiry;
90         NTTIME last_password_change;
91         NTTIME allow_password_change;
92         NTTIME force_password_change;
93         
94         uint16 logon_count;
95         uint16 bad_password_count;
96         
97         uint32 acct_flags;
98 };
99
100 struct auth_session_info 
101 {
102         int refcount;
103         /* NT group information taken from the info3 structure */
104         
105         NT_USER_TOKEN *nt_user_token;
106
107         struct auth_serversupplied_info *server_info;
108
109         DATA_BLOB session_key;
110
111         /* needed to key the schannel credentials */
112         const char *workstation;
113 };
114
115 struct auth_context {
116         DATA_BLOB challenge; 
117
118         /* Who set this up in the first place? */ 
119         const char *challenge_set_by; 
120
121         BOOL challenge_may_be_modified;
122
123         struct auth_methods *challenge_set_method; 
124
125         /* methods, in the order they should be called */
126         struct auth_methods *auth_method_list;  
127
128         const uint8_t *(*get_ntlm_challenge)(struct auth_context *auth_context);
129         NTSTATUS (*check_ntlm_password)(struct auth_context *auth_context,
130                                         const struct auth_usersupplied_info *user_info, 
131                                         TALLOC_CTX *out_mem_ctx, 
132                                         struct auth_serversupplied_info **server_info);
133         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
134 };
135
136 struct auth_methods
137 {
138         struct auth_methods *prev, *next;
139         const char *name; /* What name got this module */
140
141         NTSTATUS (*auth)(const struct auth_context *auth_context,
142                          void *my_private_data, 
143                          TALLOC_CTX *mem_ctx,
144                          const struct auth_usersupplied_info *user_info, 
145                          struct auth_serversupplied_info **server_info);
146
147         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
148                               void **my_private_data, 
149                               TALLOC_CTX *mem_ctx);
150         
151         /* Used to keep tabs on things like the cli for SMB server authentication */
152         void *private_data;
153         
154         /* Function to clean up the above arbitary structure */
155         void (*free_private_data)(void **private_data);
156
157         /* Function to send a keepalive message on the above structure */
158         void (*send_keepalive)(void **private_data);
159
160 };
161
162 struct auth_operations {
163         /* the name of the backend */
164         const char *name;
165
166         /* Function to create a member of the authmethods list */
167         NTSTATUS (*init)(struct auth_context *, const char *, struct auth_methods **);
168 };
169
170 /* this structure is used by backends to determine the size of some critical types */
171 struct auth_critical_sizes {
172         int interface_version;
173         int sizeof_auth_operations;
174         int sizeof_auth_methods;
175         int sizeof_auth_context;
176         int sizeof_auth_usersupplied_info;
177         int sizeof_auth_serversupplied_info;
178         int sizeof_auth_str;
179 };
180
181 #endif /* _SMBAUTH_H_ */