r11782: - make the TID 32bit in the smbsrv_tcon structure, as SMB2 uses
[obnox/samba/samba-obnox.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 "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 state 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         /* Distinguish between a VUID allocated for the multi-pass
52          * extended secrity session setup and one that is finished */
53         BOOL finished_sesssetup;
54
55         struct timeval connect_time;
56 };
57
58 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
59    include recursion */
60 struct ntvfs_context;
61
62 struct smbsrv_tcon {
63         struct smbsrv_tcon *next, *prev;
64
65         /* the server context that this was created on */
66         struct smbsrv_connection *smb_conn;
67
68         /* 
69          * an index passed over the wire:
70          * - 16 bit for smb
71          * - 32 bit for smb2
72          */
73         uint32_t tid; /* an index passed over the wire (the TID) */
74
75         int service;
76         BOOL read_only;
77         BOOL admin_user;
78
79         /* the NTVFS context - see source/ntvfs/ for details */
80         struct ntvfs_context *ntvfs_ctx;
81
82         /* the reported filesystem type */
83         char *fs_type;
84
85         /* the reported device type */
86         char *dev_type;
87
88         /* some stuff to support share level security */
89         struct {
90                 /* in share level security we need to fake up a session */
91                 struct smbsrv_session *session;
92         } sec_share;
93
94         /* some statictics for the management tools */
95         struct {
96                 struct timeval connect_time;
97         } statistics;
98 };
99
100 /* a set of flags to control handling of request structures */
101 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
102
103 /* the context for a single SMB request. This is passed to any request-context 
104    functions */
105 struct smbsrv_request {
106         /* the smbsrv_connection needs a list of requests queued for send */
107         struct smbsrv_request *next, *prev;
108
109         /* the server_context contains all context specific to this SMB socket */
110         struct smbsrv_connection *smb_conn;
111
112         /* conn is only set for operations that have a valid TID */
113         struct smbsrv_tcon *tcon;
114
115         /* the session context is derived from the vuid */
116         struct smbsrv_session *session;
117
118         /* a set of flags to control usage of the request. See REQ_CONTROL_* */
119         unsigned control_flags;
120
121         /* the smb pid is needed for locking contexts */
122         uint16_t smbpid;
123
124         /* the flags from the SMB request, in raw form (host byte order) */
125         uint16_t flags, flags2;
126
127         /* the system time when the request arrived */
128         struct timeval request_time;
129
130         /* this can contain a fnum from an earlier part of a chained
131          * message (such as an SMBOpenX), or -1 */
132         int chained_fnum;
133
134         /* how far through the chain of SMB commands have we gone? */
135         unsigned chain_count;
136
137         /* the sequence number for signing */
138         uint64_t seq_num;
139
140         /* ntvfs per request async states */
141         struct ntvfs_async_state *async_states;
142
143         struct request_buffer in;
144         struct request_buffer out;
145 };
146
147 /* this contains variables that should be used in % substitutions for
148  * smb.conf parameters */
149 struct substitute_context {
150         char *remote_arch;
151
152         /* our local netbios name, as give to us by the client */
153         char *local_machine;
154
155         /* the remote netbios name, as give to us by the client */
156         char *remote_machine;
157
158         /* the select remote protocol */
159         char *remote_proto;     
160
161         /* the name of the client as should be displayed in
162          * smbstatus. Can be an IP or a netbios name */
163         char *client_name; 
164
165         /* the username for %U */
166         char *user_name;
167 };
168
169 /* Remote architectures we know about. */
170 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_WINXP, RA_SAMBA};
171
172 /* smb server context structure. This should contain all the state
173  * information associated with a SMB server connection 
174  */
175 struct smbsrv_connection {
176         /* context that has been negotiated between the client and server */
177         struct {
178                 /* have we already done the NBT session establishment? */
179                 BOOL done_nbt_session;
180         
181                 /* only one negprot per connection is allowed */
182                 BOOL done_negprot;
183         
184                 /* multiple session setups are allowed, but some parameters are
185                    ignored in any but the first */
186                 BOOL done_sesssetup;
187                 
188                 /* 
189                  * Size of data we can send to client. Set
190                  *  by the client for all protocols above CORE.
191                  *  Set by us for CORE protocol.
192                  */
193                 unsigned max_send; /* init to BUFFER_SIZE */
194         
195                 /*
196                  * Size of the data we can receive. Set by us.
197                  * Can be modified by the max xmit parameter.
198                  */
199                 unsigned max_recv; /* init to BUFFER_SIZE */
200         
201                 /* a guess at the remote architecture. Try not to rely on this - in almost
202                    all cases using these values is the wrong thing to do */
203                 enum remote_arch_types ra_type;
204         
205                 /* the negotiatiated protocol */
206                 enum protocol_types protocol;
207         
208                 /* authentication context for multi-part negprot */
209                 struct auth_context *auth_context;
210         
211                 /* reference to the kerberos keytab, or machine trust account */
212                 struct cli_credentials *server_credentials;
213         
214                 /* did we tell the client we support encrypted passwords? */
215                 BOOL encrypted_passwords;
216         
217                 /* did we send an extended security negprot reply? */
218                 BOOL spnego_negotiated;
219         
220                 /* client capabilities */
221                 uint32_t client_caps;
222         
223                 /* the timezone we sent to the client */
224                 int zone_offset;
225
226                 /* NBT names only set when done_nbt_session is true */
227                 struct nbt_name *called_name;
228                 struct nbt_name *calling_name;
229         } negotiate;
230
231         /* the context associated with open tree connects on a smb socket */
232         struct {
233                 /* an id tree used to allocate tids */
234                 struct idr_context *idtree_tid;
235
236                 /* this is the limit of vuid values for this connection */
237                 uint32_t idtree_limit;
238
239                 /* list of open tree connects */
240                 struct smbsrv_tcon *list;
241         } tcons;
242
243         /* context associated with currently valid session setups */
244         struct {
245                 int num_validated_vuids;
246
247                 /* an id tree used to allocate vuids */
248                 /* this holds info on session vuids that are already
249                  * validated for this VC */
250                 struct idr_context *idtree_vuid;
251
252                 /* also kept as a link list so it can be enumerated by
253                    the management code */
254                 struct smbsrv_session *list;
255         } sessions;
256
257         /* the server_context holds a linked list of pending requests,
258          * this is used for blocking locks and requests blocked due to oplock
259          * break requests */
260         struct _smbsrv_pending_request {
261                 struct _smbsrv_pending_request *next, *prev;
262         
263                 /* the request itself - needs to be freed */
264                 struct smbsrv_request *request;
265         } *requests;
266
267         struct smb_signing_context signing;
268         
269         struct stream_connection *connection;
270
271         /* this holds a partially received request */
272         struct packet_context *packet;
273
274         /* a list of partially received transaction requests */
275         struct smbsrv_trans_partial {
276                 struct smbsrv_trans_partial *next, *prev;
277                 struct smbsrv_request *req;
278                 struct smb_trans2 *trans;
279                 uint8_t command;
280         } *trans_partial;
281
282         /* mark a connection for termination */
283         const char *terminate;
284
285         /* configuration parameters */
286         struct {
287                 enum security_types security;
288                 BOOL nt_status_support;
289         } config;
290 };