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