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