r12694: Move some headers to the directory of the subsystem they belong to.
[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 "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 *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 /* smb server context structure. This should contain all the state
210  * information associated with a SMB server connection 
211  */
212 struct smbsrv_connection {
213         /* context that has been negotiated between the client and server */
214         struct {
215                 /* have we already done the NBT session establishment? */
216                 BOOL done_nbt_session;
217         
218                 /* only one negprot per connection is allowed */
219                 BOOL done_negprot;
220         
221                 /* multiple session setups are allowed, but some parameters are
222                    ignored in any but the first */
223                 BOOL done_sesssetup;
224                 
225                 /* 
226                  * Size of data we can send to client. Set
227                  *  by the client for all protocols above CORE.
228                  *  Set by us for CORE protocol.
229                  */
230                 unsigned max_send; /* init to BUFFER_SIZE */
231         
232                 /*
233                  * Size of the data we can receive. Set by us.
234                  * Can be modified by the max xmit parameter.
235                  */
236                 unsigned max_recv; /* init to BUFFER_SIZE */
237         
238                 /* a guess at the remote architecture. Try not to rely on this - in almost
239                    all cases using these values is the wrong thing to do */
240                 enum remote_arch_types ra_type;
241         
242                 /* the negotiatiated protocol */
243                 enum protocol_types protocol;
244         
245                 /* authentication context for multi-part negprot */
246                 struct auth_context *auth_context;
247         
248                 /* reference to the kerberos keytab, or machine trust account */
249                 struct cli_credentials *server_credentials;
250         
251                 /* did we tell the client we support encrypted passwords? */
252                 BOOL encrypted_passwords;
253         
254                 /* did we send an extended security negprot reply? */
255                 BOOL spnego_negotiated;
256         
257                 /* client capabilities */
258                 uint32_t client_caps;
259         
260                 /* the timezone we sent to the client */
261                 int zone_offset;
262
263                 /* NBT names only set when done_nbt_session is true */
264                 struct nbt_name *called_name;
265                 struct nbt_name *calling_name;
266         } negotiate;
267
268         /* the context associated with open tree connects on a smb socket */
269         struct smbsrv_tcons_context smb_tcons;
270
271         /* context associated with currently valid session setups */
272         struct smbsrv_sessions_context sessions;
273
274         /* the server_context holds a linked list of pending requests,
275          * this is used for blocking locks and requests blocked due to oplock
276          * break requests */
277         struct _smbsrv_pending_request {
278                 struct _smbsrv_pending_request *next, *prev;
279         
280                 /* the request itself - needs to be freed */
281                 struct smbsrv_request *request;
282         } *requests;
283
284         struct smb_signing_context signing;
285         
286         struct stream_connection *connection;
287
288         /* this holds a partially received request */
289         struct packet_context *packet;
290
291         /* a list of partially received transaction requests */
292         struct smbsrv_trans_partial {
293                 struct smbsrv_trans_partial *next, *prev;
294                 struct smbsrv_request *req;
295                 struct smb_trans2 *trans;
296                 uint8_t command;
297         } *trans_partial;
298
299         /* configuration parameters */
300         struct {
301                 enum security_types security;
302                 BOOL nt_status_support;
303         } config;
304 };
305
306 #include "smb_server/smb_server_proto.h"
307 #include "smb_server/smb/smb_proto.h"