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