r14511: Install more headers
[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 "libcli/raw/request.h"
24 #include "smbd/process_model.h"
25 #include "libcli/raw/interfaces.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         /* the share name */
107         const char *share_name;
108
109         /* the NTVFS context - see source/ntvfs/ for details */
110         struct ntvfs_context *ntvfs;
111
112         /* some stuff to support share level security */
113         struct {
114                 /* in share level security we need to fake up a session */
115                 struct smbsrv_session *session;
116         } sec_share;
117
118         /* some stuff to support share level security */
119         struct {
120                 /* in SMB2 a tcon always belongs to one session */
121                 struct smbsrv_session *session;
122         } smb2;
123
124         /* some statictics for the management tools */
125         struct {
126                 struct timeval connect_time;
127         } statistics;
128 };
129
130 /* a set of flags to control handling of request structures */
131 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
132
133 /* the context for a single SMB request. This is passed to any request-context 
134    functions */
135 struct smbsrv_request {
136         /* the smbsrv_connection needs a list of requests queued for send */
137         struct smbsrv_request *next, *prev;
138
139         /* the server_context contains all context specific to this SMB socket */
140         struct smbsrv_connection *smb_conn;
141
142         /* conn is only set for operations that have a valid TID */
143         struct smbsrv_tcon *tcon;
144
145         /* the session context is derived from the vuid */
146         struct smbsrv_session *session;
147
148         /* a set of flags to control usage of the request. See REQ_CONTROL_* */
149         unsigned control_flags;
150
151         /* the flags from the SMB request, in raw form (host byte order) */
152         uint16_t flags2;
153
154         /* the system time when the request arrived */
155         struct timeval request_time;
156
157         /* this can contain a fnum from an earlier part of a chained
158          * message (such as an SMBOpenX), or -1 */
159         int chained_fnum;
160
161         /* how far through the chain of SMB commands have we gone? */
162         unsigned chain_count;
163
164         /* the sequence number for signing */
165         uint64_t seq_num;
166
167         struct request_buffer in;
168         struct request_buffer out;
169
170         /*
171          * the following elemets will be part of a future ntvfs_request struct
172          */
173
174         /* the ntvfs_context this requests belongs to */
175         struct ntvfs_context *ctx;
176
177         /* ntvfs per request async states */
178         struct ntvfs_async_state *async_states;
179
180         /* the session_info, with security_token and maybe delegated credentials */
181         struct auth_session_info *session_info;
182
183         /* the smb pid is needed for locking contexts */
184         uint16_t smbpid;
185
186 uint16_t smbmid;
187
188         /* some statictics for the management tools */
189         struct {
190                 /* the system time when the request arrived */
191                 struct timeval request_time;
192         } statistics;
193 };
194
195 /* this contains variables that should be used in % substitutions for
196  * smb.conf parameters */
197 struct substitute_context {
198         char *remote_arch;
199
200         /* our local netbios name, as give to us by the client */
201         char *local_machine;
202
203         /* the remote netbios name, as give to us by the client */
204         char *remote_machine;
205
206         /* the select remote protocol */
207         char *remote_proto;     
208
209         /* the name of the client as should be displayed in
210          * smbstatus. Can be an IP or a netbios name */
211         char *client_name; 
212
213         /* the username for %U */
214         char *user_name;
215 };
216
217 /* Remote architectures we know about. */
218 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_WINXP, RA_SAMBA};
219
220 enum security_types {SEC_SHARE,SEC_USER} security;
221
222 /* smb server context structure. This should contain all the state
223  * information associated with a SMB server connection 
224  */
225 struct smbsrv_connection {
226         /* context that has been negotiated between the client and server */
227         struct {
228                 /* have we already done the NBT session establishment? */
229                 BOOL done_nbt_session;
230         
231                 /* only one negprot per connection is allowed */
232                 BOOL done_negprot;
233         
234                 /* multiple session setups are allowed, but some parameters are
235                    ignored in any but the first */
236                 BOOL done_sesssetup;
237                 
238                 /* 
239                  * Size of data we can send to client. Set
240                  *  by the client for all protocols above CORE.
241                  *  Set by us for CORE protocol.
242                  */
243                 unsigned max_send; /* init to BUFFER_SIZE */
244         
245                 /*
246                  * Size of the data we can receive. Set by us.
247                  * Can be modified by the max xmit parameter.
248                  */
249                 unsigned max_recv; /* init to BUFFER_SIZE */
250         
251                 /* a guess at the remote architecture. Try not to rely on this - in almost
252                    all cases using these values is the wrong thing to do */
253                 enum remote_arch_types ra_type;
254         
255                 /* the negotiatiated protocol */
256                 enum protocol_types protocol;
257         
258                 /* authentication context for multi-part negprot */
259                 struct auth_context *auth_context;
260         
261                 /* reference to the kerberos keytab, or machine trust account */
262                 struct cli_credentials *server_credentials;
263         
264                 /* did we tell the client we support encrypted passwords? */
265                 BOOL encrypted_passwords;
266         
267                 /* Did we choose SPNEGO, or perhaps raw NTLMSSP, or even no extended security at all? */
268                 const char *oid;
269         
270                 /* client capabilities */
271                 uint32_t client_caps;
272         
273                 /* the timezone we sent to the client */
274                 int zone_offset;
275
276                 /* NBT names only set when done_nbt_session is true */
277                 struct nbt_name *called_name;
278                 struct nbt_name *calling_name;
279         } negotiate;
280
281         /* the context associated with open tree connects on a smb socket */
282         struct smbsrv_tcons_context smb_tcons;
283
284         /* context associated with currently valid session setups */
285         struct smbsrv_sessions_context sessions;
286
287         /* the server_context holds a linked list of pending requests,
288          * this is used for blocking locks and requests blocked due to oplock
289          * break requests */
290         struct _smbsrv_pending_request {
291                 struct _smbsrv_pending_request *next, *prev;
292         
293                 /* the request itself - needs to be freed */
294                 struct smbsrv_request *request;
295         } *requests;
296
297         struct smb_signing_context signing;
298         
299         struct stream_connection *connection;
300
301         /* this holds a partially received request */
302         struct packet_context *packet;
303
304         /* a list of partially received transaction requests */
305         struct smbsrv_trans_partial {
306                 struct smbsrv_trans_partial *next, *prev;
307                 struct smbsrv_request *req;
308                 struct smb_trans2 *trans;
309                 uint8_t command;
310         } *trans_partial;
311
312         /* configuration parameters */
313         struct {
314                 enum security_types security;
315                 BOOL nt_status_support;
316         } config;
317 };
318
319 #include "smb_server/smb_server_proto.h"
320 #include "smb_server/smb/smb_proto.h"