r443: Update Samba4 to the auth and NTLMSSP code from Samba3.
[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 typedef struct auth_usersupplied_info
41 {
42         
43         DATA_BLOB lm_resp;
44         DATA_BLOB nt_resp;
45         DATA_BLOB lm_interactive_pwd;
46         DATA_BLOB nt_interactive_pwd;
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 } auth_usersupplied_info;
58
59 #define SAM_FILL_NAME  0x01
60 #define SAM_FILL_INFO3 0x02
61 #define SAM_FILL_SAM   0x04
62 #define SAM_FILL_UNIX  0x08
63 #define SAM_FILL_ALL (SAM_FILL_NAME | SAM_FILL_INFO3 | SAM_FILL_SAM | SAM_FILL_UNIX)
64
65 typedef struct auth_serversupplied_info 
66 {
67         BOOL guest;
68         
69         /* This groups info is needed for when we become_user() for this uid */
70         int n_groups;
71         gid_t *groups;
72         
73         /* NT group information taken from the info3 structure */
74         
75         NT_USER_TOKEN *ptok;
76         
77         DATA_BLOB user_session_key;
78         DATA_BLOB lm_session_key;
79         
80         uint32 sam_fill_level;  /* How far is this structure filled? */
81         
82         SAM_ACCOUNT *sam_account;
83         
84         void *pam_handle;
85 } auth_serversupplied_info;
86
87 struct auth_context {
88         DATA_BLOB challenge; 
89
90         /* Who set this up in the first place? */ 
91         const char *challenge_set_by; 
92
93         BOOL challenge_may_be_modified;
94
95         struct auth_methods *challenge_set_method; 
96         /* What order are the various methods in?   Try to stop it changing under us */ 
97         struct auth_methods *auth_method_list;  
98
99         TALLOC_CTX *mem_ctx;
100         const uint8 *(*get_ntlm_challenge)(struct auth_context *auth_context);
101         NTSTATUS (*check_ntlm_password)(const struct auth_context *auth_context,
102                                         const struct auth_usersupplied_info *user_info, 
103                                         struct auth_serversupplied_info **server_info);
104         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
105         void (*free)(struct auth_context **auth_context);
106 };
107
108 typedef struct auth_methods
109 {
110         struct auth_methods *prev, *next;
111         const char *name; /* What name got this module */
112
113         NTSTATUS (*auth)(const struct auth_context *auth_context,
114                          void *my_private_data, 
115                          TALLOC_CTX *mem_ctx,
116                          const struct auth_usersupplied_info *user_info, 
117                          auth_serversupplied_info **server_info);
118
119         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
120                               void **my_private_data, 
121                               TALLOC_CTX *mem_ctx);
122         
123         /* Used to keep tabs on things like the cli for SMB server authentication */
124         void *private_data;
125         
126         /* Function to clean up the above arbitary structure */
127         void (*free_private_data)(void **private_data);
128
129         /* Function to send a keepalive message on the above structure */
130         void (*send_keepalive)(void **private_data);
131
132 } auth_methods;
133
134 typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **);
135
136 struct auth_init_function_entry {
137         const char *name;
138         /* Function to create a member of the authmethods list */
139
140         auth_init_function init;
141
142         struct auth_init_function_entry *prev, *next;
143 };
144
145 typedef struct auth_ntlmssp_state
146 {
147         TALLOC_CTX *mem_ctx;
148         struct auth_context *auth_context;
149         struct auth_serversupplied_info *server_info;
150         struct ntlmssp_state *ntlmssp_state;
151 } AUTH_NTLMSSP_STATE;
152
153 #define auth_ops __XXX_ERROR_BLA
154 struct auth_operations {
155         /* the name of the backend */
156         const char *name;
157
158         /* Function to create a member of the authmethods list */
159         NTSTATUS (*init)(struct auth_context *, const char *, struct auth_methods **);
160 };
161
162 /* this structure is used by backends to determine the size of some critical types */
163 struct auth_critical_sizes {
164         int interface_version;
165         int sizeof_auth_operations;
166         int sizeof_auth_methods;
167         int sizeof_auth_context;
168         int sizeof_auth_ntlmssp_state;
169         int sizeof_auth_usersupplied_info;
170         int sizeof_auth_serversupplied_info;
171         int sizeof_auth_str;
172         int sizeof_auth_unistr;
173 };
174
175 #endif /* _SMBAUTH_H_ */