r14157: - pass a struct ntvfs_request to the ntvfs layer
[kai/samba.git] / source4 / smb_server / smb_server.h
1 /* 
2    Unix SMB/CIFS implementation.
3    
4    Copyright (C) Andrew Tridgell              2003
5    Copyright (C) James J Myers                2003 <myersjj@samba.org>
6    Copyright (C) Stefan Metzmacher            2004-2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "smb.h"
24 #include "libcli/raw/request.h"
25 #include "smbd/process_model.h"
26
27 /*
28   this header declares the core context structures associated with smb
29   sockets, tree connects, requests etc
30
31   the idea is that we will eventually get rid of all our global
32   variables and instead store our state from structures hanging off
33   these basic elements
34 */
35
36 struct smbsrv_tcons_context {
37         /* an id tree used to allocate tids */
38         struct idr_context *idtree_tid;
39
40         /* this is the limit of vuid values for this connection */
41         uint32_t idtree_limit;
42
43         /* list of open tree connects */
44         struct smbsrv_tcon *list;
45 };
46
47 struct smbsrv_sessions_context {
48         /* an id tree used to allocate vuids */
49         /* this holds info on session vuids that are already
50          * validated for this VC */
51         struct idr_context *idtree_vuid;
52
53         /* this is the limit of vuid values for this connection */
54         uint64_t idtree_limit;
55
56         /* also kept as a link list so it can be enumerated by
57            the management code */
58         struct smbsrv_session *list;
59 } sessions;
60
61 /* the current user context for a request */
62 struct smbsrv_session {
63         struct smbsrv_session *prev, *next;
64
65         struct smbsrv_connection *smb_conn;
66
67         struct smbsrv_tcons_context smb2_tcons;
68
69         /* 
70          * an index passed over the wire:
71          * - 16 bit for smb
72          * - 64 bit for smb2
73          */
74         uint64_t vuid;
75
76         struct gensec_security *gensec_ctx;
77
78         struct auth_session_info *session_info;
79
80         /* some statictics for the management tools */
81         struct {
82                 /* the time when the session setup started */
83                 struct timeval connect_time;
84                 /* the time when the session setup was finished */
85                 struct timeval auth_time;
86         } statistics;
87 };
88
89 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
90    include recursion */
91 struct ntvfs_context;
92
93 struct smbsrv_tcon {
94         struct smbsrv_tcon *next, *prev;
95
96         /* the server context that this was created on */
97         struct smbsrv_connection *smb_conn;
98
99         /* 
100          * an index passed over the wire:
101          * - 16 bit for smb
102          * - 32 bit for smb2
103          */
104         uint32_t tid; /* an index passed over the wire (the TID) */
105
106         int service;
107         BOOL read_only;
108         BOOL admin_user;
109
110         /* the NTVFS context - see source/ntvfs/ for details */
111         struct ntvfs_context *ntvfs_ctx;
112
113         /* the reported filesystem type */
114         char *fs_type;
115
116         /* the reported device type */
117         char *dev_type;
118
119         /* some stuff to support share level security */
120         struct {
121                 /* in share level security we need to fake up a session */
122                 struct smbsrv_session *session;
123         } sec_share;
124
125         /* some stuff to support share level security */
126         struct {
127                 /* in SMB2 a tcon always belongs to one session */
128                 struct smbsrv_session *session;
129         } smb2;
130
131         /* some statictics for the management tools */
132         struct {
133                 struct timeval connect_time;
134         } statistics;
135 };
136
137 /* a set of flags to control handling of request structures */
138 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
139
140 /* the context for a single SMB request. This is passed to any request-context 
141    functions */
142 struct smbsrv_request {
143         /* the smbsrv_connection needs a list of requests queued for send */
144         struct smbsrv_request_foo *next, *prev;
145
146         /* the server_context contains all context specific to this SMB socket */
147         struct smbsrv_connection *smb_conn;
148
149         /* conn is only set for operations that have a valid TID */
150         struct smbsrv_tcon *tcon;
151
152         /* the session context is derived from the vuid */
153         struct smbsrv_session *session;
154
155         /* a set of flags to control usage of the request. See REQ_CONTROL_* */
156         unsigned control_flags;
157
158         /* the smb pid is needed for locking contexts */
159         uint16_t smbpid;
160
161         /* the flags from the SMB request, in raw form (host byte order) */
162         uint16_t flags, flags2;
163
164         /* the system time when the request arrived */
165         struct timeval request_time;
166
167         /* this can contain a fnum from an earlier part of a chained
168          * message (such as an SMBOpenX), or -1 */
169         int chained_fnum;
170
171         /* how far through the chain of SMB commands have we gone? */
172         unsigned chain_count;
173
174         /* the sequence number for signing */
175         uint64_t seq_num;
176
177         /* ntvfs per request async states */
178         struct ntvfs_async_state *async_states;
179
180         struct request_buffer in;
181         struct request_buffer out;
182 };
183
184 /* this contains variables that should be used in % substitutions for
185  * smb.conf parameters */
186 struct substitute_context {
187         char *remote_arch;
188
189         /* our local netbios name, as give to us by the client */
190         char *local_machine;
191
192         /* the remote netbios name, as give to us by the client */
193         char *remote_machine;
194
195         /* the select remote protocol */
196         char *remote_proto;     
197
198         /* the name of the client as should be displayed in
199          * smbstatus. Can be an IP or a netbios name */
200         char *client_name; 
201
202         /* the username for %U */
203         char *user_name;
204 };
205
206 /* Remote architectures we know about. */
207 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_WINXP, RA_SAMBA};
208
209 enum security_types {SEC_SHARE,SEC_USER} security;
210
211 /* smb server context structure. This should contain all the state
212  * information associated with a SMB server connection 
213  */
214 struct smbsrv_connection {
215         /* context that has been negotiated between the client and server */
216         struct {
217                 /* have we already done the NBT session establishment? */
218                 BOOL done_nbt_session;
219         
220                 /* only one negprot per connection is allowed */
221                 BOOL done_negprot;
222         
223                 /* multiple session setups are allowed, but some parameters are
224                    ignored in any but the first */
225                 BOOL done_sesssetup;
226                 
227                 /* 
228                  * Size of data we can send to client. Set
229                  *  by the client for all protocols above CORE.
230                  *  Set by us for CORE protocol.
231                  */
232                 unsigned max_send; /* init to BUFFER_SIZE */
233         
234                 /*
235                  * Size of the data we can receive. Set by us.
236                  * Can be modified by the max xmit parameter.
237                  */
238                 unsigned max_recv; /* init to BUFFER_SIZE */
239         
240                 /* a guess at the remote architecture. Try not to rely on this - in almost
241                    all cases using these values is the wrong thing to do */
242                 enum remote_arch_types ra_type;
243         
244                 /* the negotiatiated protocol */
245                 enum protocol_types protocol;
246         
247                 /* authentication context for multi-part negprot */
248                 struct auth_context *auth_context;
249         
250                 /* reference to the kerberos keytab, or machine trust account */
251                 struct cli_credentials *server_credentials;
252         
253                 /* did we tell the client we support encrypted passwords? */
254                 BOOL encrypted_passwords;
255         
256                 /* Did we choose SPNEGO, or perhaps raw NTLMSSP, or even no extended security at all? */
257                 const char *oid;
258         
259                 /* client capabilities */
260                 uint32_t client_caps;
261         
262                 /* the timezone we sent to the client */
263                 int zone_offset;
264
265                 /* NBT names only set when done_nbt_session is true */
266                 struct nbt_name *called_name;
267                 struct nbt_name *calling_name;
268         } negotiate;
269
270         /* the context associated with open tree connects on a smb socket */
271         struct smbsrv_tcons_context smb_tcons;
272
273         /* context associated with currently valid session setups */
274         struct smbsrv_sessions_context sessions;
275
276         /* the server_context holds a linked list of pending requests,
277          * this is used for blocking locks and requests blocked due to oplock
278          * break requests */
279         struct _smbsrv_pending_request {
280                 struct _smbsrv_pending_request *next, *prev;
281         
282                 /* the request itself - needs to be freed */
283                 struct smbsrv_request *request;
284         } *requests;
285
286         struct smb_signing_context signing;
287         
288         struct stream_connection *connection;
289
290         /* this holds a partially received request */
291         struct packet_context *packet;
292
293         /* a list of partially received transaction requests */
294         struct smbsrv_trans_partial {
295                 struct smbsrv_trans_partial *next, *prev;
296                 struct smbsrv_request *req;
297                 struct smb_trans2 *trans;
298                 uint8_t command;
299         } *trans_partial;
300
301         /* configuration parameters */
302         struct {
303                 enum security_types security;
304                 BOOL nt_status_support;
305         } config;
306 };
307
308 #include "smb_server/smb_server_proto.h"
309 #include "smb_server/smb/smb_proto.h"