r3425: got rid of a bunch of cruft from rewrite.h
[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 /*
24   this header declares the core context structures associated with smb
25   sockets, tree connects, requests etc
26
27   the idea is that we will eventually get rid of all our global
28   variables and instead store our stang from structures hanging off
29   these basic elements
30 */
31
32 /* the current user context for a request */
33 struct smbsrv_session {
34         struct smbsrv_session *prev, *next;
35
36         struct smbsrv_connection *smb_conn;
37
38         /* the vuid is used to specify the security context for this
39            request. Note that this may not be the same vuid as we
40            received on the wire (for example, for share mode or guest
41            access) */
42         uint16_t vuid;
43
44         struct gensec_security *gensec_ctx;
45
46         struct auth_session_info *session_info;
47 };
48
49 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
50    include recursion */
51 struct ntvfs_context;
52
53 struct smbsrv_tcon {
54         struct smbsrv_tcon *next, *prev;
55
56         /* the server context that this was created on */
57         struct smbsrv_connection *smb_conn;
58
59         uint16_t cnum; /* an index passed over the wire (the TID) */
60         int service;
61         BOOL read_only;
62         BOOL admin_user;
63
64         /* the NTVFS context - see source/ntvfs/ for details */
65         struct ntvfs_context *ntvfs_ctx;
66
67         /* the reported filesystem type */
68         char *fs_type;
69
70         /* the reported device type */
71         char *dev_type;
72 };
73
74 /* a set of flags to control handling of request structures */
75 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
76
77 /* the context for a single SMB request. This is passed to any request-context 
78    functions */
79 struct smbsrv_request {
80         /* the smbsrv_connection needs a list of requests queued for send */
81         struct smbsrv_request *next, *prev;
82
83         /* the server_context contains all context specific to this SMB socket */
84         struct smbsrv_connection *smb_conn;
85
86         /* conn is only set for operations that have a valid TID */
87         struct smbsrv_tcon *tcon;
88
89         /* the session context is derived from the vuid */
90         struct smbsrv_session *session;
91
92         /* a set of flags to control usage of the request. See REQ_CONTROL_* */
93         unsigned control_flags;
94
95         /* the smb pid is needed for locking contexts */
96         uint16_t smbpid;
97
98         /* the flags from the SMB request, in raw form (host byte order) */
99         uint16_t flags, flags2;
100
101         /* the system time when the request arrived */
102         struct timeval request_time;
103
104         /* this can contain a fnum from an earlier part of a chained
105          * message (such as an SMBOpenX), or -1 */
106         int chained_fnum;
107
108         /* how far through the chain of SMB commands have we gone? */
109         unsigned chain_count;
110
111         /* the sequence number for signing */
112         uint64_t seq_num;
113
114         /* ntvfs per request async states */
115         struct ntvfs_async_state *async_states;
116
117         struct request_buffer in;
118         struct request_buffer out;
119 };
120
121 /* this contains variables that should be used in % substitutions for
122  * smb.conf parameters */
123 struct substitute_context {
124         char *remote_arch;
125
126         /* our local netbios name, as give to us by the client */
127         char *local_machine;
128
129         /* the remote netbios name, as give to us by the client */
130         char *remote_machine;
131
132         /* the select remote protocol */
133         char *remote_proto;     
134
135         /* the name of the client as should be displayed in
136          * smbstatus. Can be an IP or a netbios name */
137         char *client_name; 
138
139         /* the username for %U */
140         char *user_name;
141 };
142
143 #include "smbd/process_model.h"
144
145 /* smb server context structure. This should contain all the state
146  * information associated with a SMB server connection 
147  */
148 struct smbsrv_connection {
149         /* a count of the number of packets we have received. We
150          * actually only care about zero/non-zero at this stage */
151         unsigned pkt_count;
152
153         /* context that has been negotiated between the client and server */
154         struct {
155                 /* have we already done the NBT session establishment? */
156                 BOOL done_nbt_session;
157         
158                 /* only one negprot per connection is allowed */
159                 BOOL done_negprot;
160         
161                 /* multiple session setups are allowed, but some parameters are
162                    ignored in any but the first */
163                 BOOL done_sesssetup;
164                 
165                 /* 
166                  * Size of data we can send to client. Set
167                  *  by the client for all protocols above CORE.
168                  *  Set by us for CORE protocol.
169                  */
170                 unsigned max_send; /* init to BUFFER_SIZE */
171         
172                 /*
173                  * Size of the data we can receive. Set by us.
174                  * Can be modified by the max xmit parameter.
175                  */
176                 unsigned max_recv; /* init to BUFFER_SIZE */
177         
178                 /* a guess at the remote architecture. Try not to rely on this - in almost
179                    all cases using these values is the wrong thing to do */
180                 enum remote_arch_types ra_type;
181         
182                 /* the negotiatiated protocol */
183                 enum protocol_types protocol;
184         
185                 /* authentication context for multi-part negprot */
186                 struct auth_context *auth_context;
187         
188                 /* state of NTLMSSP auth */
189                 struct auth_ntlmssp_state *ntlmssp_state;
190         
191                 /* did we tell the client we support encrypted passwords? */
192                 BOOL encrypted_passwords;
193         
194                 /* did we send an extended security negprot reply? */
195                 BOOL spnego_negotiated;
196         
197                 /* client capabilities */
198                 uint32_t client_caps;
199         
200                 /* the timezone we sent to the client */
201                 int zone_offset;
202         } negotiate;
203
204         /* the context associated with open tree connects on a smb socket */
205         struct {
206                 /* list of open tree connects */
207                 struct smbsrv_tcon *tcons;
208
209                 /* an id tree used to allocate tids */
210                 struct idr_context *idtree_tid;
211         } tree;
212
213         /* the context associated with open files on an smb socket */
214         struct {
215                 struct files_struct *files; /* open files */
216         
217                 /* a fsp to use when chaining */
218                 struct files_struct *chain_fsp;
219         
220                 /* a fsp to use to save when breaking an oplock. */
221                 struct files_struct *oplock_save_chain_fsp;
222         
223                 /* how many files are open */
224                 int files_used;
225         
226                 /* limit for maximum open files */
227                 int real_max_open_files;
228         } file;
229
230         /* context associated with currently valid session setups */
231         struct {
232                 /* this holds info on session vuids that are already validated for this VC */
233                 struct smbsrv_session *session_list;
234                 uint16_t next_vuid; /* initialise to VUID_OFFSET */
235                 int num_validated_vuids;
236         } sessions;
237
238         /* this holds long term state specific to the printing subsystem */
239         struct {
240                 struct notify_queue *notify_queue_head;
241         } print;
242
243         /* the server_context holds a linked list of pending requests,
244          * this is used for blocking locks and requests blocked due to oplock
245          * break requests */
246         struct _smbsrv_pending_request {
247                 struct _smbsrv_pending_request *next, *prev;
248         
249                 /* the request itself - needs to be freed */
250                 struct smbsrv_request *request;
251         } *requests;
252
253         /* the timers context contains info on when we last did various
254          * functions */
255         struct {
256                 /* when did we last do timeout processing? */
257                 time_t last_timeout_processing;
258         
259                 /* when did we last sent a keepalive */
260                 time_t last_keepalive_sent;
261                 
262                 /* when we last checked the smb.conf for auto-reload */
263                 time_t last_smb_conf_reload;
264         } timers;
265
266         struct smb_signing_context signing;
267
268         struct substitute_context substitute;
269
270         struct dcesrv_context *dcesrv;
271
272         /* the pid of the process handling this session */
273         pid_t pid;
274         
275         struct server_connection *connection;
276
277         /* this holds a partially received request */
278         struct smbsrv_request *partial_req;
279
280         /* this holds list of replies that are waiting to be sent
281            to the client */
282         struct smbsrv_request *pending_send;
283 };