r4232: added server support for multi-part SMBtrans requests, while
[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
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 "request.h"
24 #include "smbd/process_model.h"
25
26 /*
27   this header declares the core context structures associated with smb
28   sockets, tree connects, requests etc
29
30   the idea is that we will eventually get rid of all our global
31   variables and instead store our stang from structures hanging off
32   these basic elements
33 */
34
35 /* the current user context for a request */
36 struct smbsrv_session {
37         struct smbsrv_session *prev, *next;
38
39         struct smbsrv_connection *smb_conn;
40
41         /* the vuid is used to specify the security context for this
42            request. Note that this may not be the same vuid as we
43            received on the wire (for example, for share mode or guest
44            access) */
45         uint16_t vuid;
46
47         struct gensec_security *gensec_ctx;
48
49         struct auth_session_info *session_info;
50 };
51
52 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
53    include recursion */
54 struct ntvfs_context;
55
56 struct smbsrv_tcon {
57         struct smbsrv_tcon *next, *prev;
58
59         /* the server context that this was created on */
60         struct smbsrv_connection *smb_conn;
61
62         uint16_t cnum; /* an index passed over the wire (the TID) */
63         int service;
64         BOOL read_only;
65         BOOL admin_user;
66
67         /* the NTVFS context - see source/ntvfs/ for details */
68         struct ntvfs_context *ntvfs_ctx;
69
70         /* the reported filesystem type */
71         char *fs_type;
72
73         /* the reported device type */
74         char *dev_type;
75 };
76
77 /* a set of flags to control handling of request structures */
78 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
79
80 /* the context for a single SMB request. This is passed to any request-context 
81    functions */
82 struct smbsrv_request {
83         /* the smbsrv_connection needs a list of requests queued for send */
84         struct smbsrv_request *next, *prev;
85
86         /* the server_context contains all context specific to this SMB socket */
87         struct smbsrv_connection *smb_conn;
88
89         /* conn is only set for operations that have a valid TID */
90         struct smbsrv_tcon *tcon;
91
92         /* the session context is derived from the vuid */
93         struct smbsrv_session *session;
94
95         /* a set of flags to control usage of the request. See REQ_CONTROL_* */
96         unsigned control_flags;
97
98         /* the smb pid is needed for locking contexts */
99         uint16_t smbpid;
100
101         /* the flags from the SMB request, in raw form (host byte order) */
102         uint16_t flags, flags2;
103
104         /* the system time when the request arrived */
105         struct timeval request_time;
106
107         /* this can contain a fnum from an earlier part of a chained
108          * message (such as an SMBOpenX), or -1 */
109         int chained_fnum;
110
111         /* how far through the chain of SMB commands have we gone? */
112         unsigned chain_count;
113
114         /* the sequence number for signing */
115         uint64_t seq_num;
116
117         /* ntvfs per request async states */
118         struct ntvfs_async_state *async_states;
119
120         struct request_buffer in;
121         struct request_buffer out;
122 };
123
124 /* this contains variables that should be used in % substitutions for
125  * smb.conf parameters */
126 struct substitute_context {
127         char *remote_arch;
128
129         /* our local netbios name, as give to us by the client */
130         char *local_machine;
131
132         /* the remote netbios name, as give to us by the client */
133         char *remote_machine;
134
135         /* the select remote protocol */
136         char *remote_proto;     
137
138         /* the name of the client as should be displayed in
139          * smbstatus. Can be an IP or a netbios name */
140         char *client_name; 
141
142         /* the username for %U */
143         char *user_name;
144 };
145
146 /* smb server context structure. This should contain all the state
147  * information associated with a SMB server connection 
148  */
149 struct smbsrv_connection {
150         /* a count of the number of packets we have received. We
151          * actually only care about zero/non-zero at this stage */
152         unsigned pkt_count;
153
154         /* context that has been negotiated between the client and server */
155         struct {
156                 /* have we already done the NBT session establishment? */
157                 BOOL done_nbt_session;
158         
159                 /* only one negprot per connection is allowed */
160                 BOOL done_negprot;
161         
162                 /* multiple session setups are allowed, but some parameters are
163                    ignored in any but the first */
164                 BOOL done_sesssetup;
165                 
166                 /* 
167                  * Size of data we can send to client. Set
168                  *  by the client for all protocols above CORE.
169                  *  Set by us for CORE protocol.
170                  */
171                 unsigned max_send; /* init to BUFFER_SIZE */
172         
173                 /*
174                  * Size of the data we can receive. Set by us.
175                  * Can be modified by the max xmit parameter.
176                  */
177                 unsigned max_recv; /* init to BUFFER_SIZE */
178         
179                 /* a guess at the remote architecture. Try not to rely on this - in almost
180                    all cases using these values is the wrong thing to do */
181                 enum remote_arch_types ra_type;
182         
183                 /* the negotiatiated protocol */
184                 enum protocol_types protocol;
185         
186                 /* authentication context for multi-part negprot */
187                 struct auth_context *auth_context;
188         
189                 /* state of NTLMSSP auth */
190                 struct auth_ntlmssp_state *ntlmssp_state;
191         
192                 /* did we tell the client we support encrypted passwords? */
193                 BOOL encrypted_passwords;
194         
195                 /* did we send an extended security negprot reply? */
196                 BOOL spnego_negotiated;
197         
198                 /* client capabilities */
199                 uint32_t client_caps;
200         
201                 /* the timezone we sent to the client */
202                 int zone_offset;
203         } negotiate;
204
205         /* the context associated with open tree connects on a smb socket */
206         struct {
207                 /* list of open tree connects */
208                 struct smbsrv_tcon *tcons;
209
210                 /* an id tree used to allocate tids */
211                 struct idr_context *idtree_tid;
212         } tree;
213
214         /* the context associated with open files on an smb socket */
215         struct {
216                 struct files_struct *files; /* open files */
217         
218                 /* a fsp to use when chaining */
219                 struct files_struct *chain_fsp;
220         
221                 /* a fsp to use to save when breaking an oplock. */
222                 struct files_struct *oplock_save_chain_fsp;
223         
224                 /* how many files are open */
225                 int files_used;
226         
227                 /* limit for maximum open files */
228                 int real_max_open_files;
229         } file;
230
231         /* context associated with currently valid session setups */
232         struct {
233                 /* this holds info on session vuids that are already validated for this VC */
234                 struct smbsrv_session *session_list;
235                 uint16_t next_vuid; /* initialise to VUID_OFFSET */
236                 int num_validated_vuids;
237         } sessions;
238
239         /* this holds long term state specific to the printing subsystem */
240         struct {
241                 struct notify_queue *notify_queue_head;
242         } print;
243
244         /* the server_context holds a linked list of pending requests,
245          * this is used for blocking locks and requests blocked due to oplock
246          * break requests */
247         struct _smbsrv_pending_request {
248                 struct _smbsrv_pending_request *next, *prev;
249         
250                 /* the request itself - needs to be freed */
251                 struct smbsrv_request *request;
252         } *requests;
253
254         /* the timers context contains info on when we last did various
255          * functions */
256         struct {
257                 /* when did we last do timeout processing? */
258                 time_t last_timeout_processing;
259         
260                 /* when did we last sent a keepalive */
261                 time_t last_keepalive_sent;
262                 
263                 /* when we last checked the smb.conf for auto-reload */
264                 time_t last_smb_conf_reload;
265         } timers;
266
267         struct smb_signing_context signing;
268
269         struct substitute_context substitute;
270
271         struct dcesrv_context *dcesrv;
272
273         /* the pid of the process handling this session */
274         pid_t pid;
275         
276         struct server_connection *connection;
277
278         /* this holds a partially received request */
279         struct smbsrv_request *partial_req;
280
281         /* this holds list of replies that are waiting to be sent
282            to the client */
283         struct smbsrv_request *pending_send;
284
285         /* a list of partially received transaction requests */
286         struct smbsrv_trans_partial {
287                 struct smbsrv_trans_partial *next, *prev;
288                 struct smbsrv_request *req;
289                 struct smb_trans2 *trans;
290                 uint8_t command;
291         } *trans_partial;
292 };