c40633eb06270ade0374675bb81cc59668352aeb
[bbaumbach/samba-autobuild/.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 /* the context for a single SMB request. This is passed to any request-context 
75    functions */
76 struct smbsrv_request {
77         /* the server_context contains all context specific to this SMB socket */
78         struct smbsrv_connection *smb_conn;
79
80         /* conn is only set for operations that have a valid TID */
81         struct smbsrv_tcon *tcon;
82
83         /* the session context is derived from the vuid */
84         struct smbsrv_session *session;
85
86         /* a set of flags to control usage of the request. See REQ_CONTROL_* */
87         unsigned control_flags;
88
89         /* the smb pid is needed for locking contexts */
90         uint16_t smbpid;
91
92         /* the flags from the SMB request, in raw form (host byte order) */
93         uint16_t flags, flags2;
94
95         /* the system time when the request arrived */
96         struct timeval request_time;
97
98         /* this can contain a fnum from an earlier part of a chained
99          * message (such as an SMBOpenX), or -1 */
100         int chained_fnum;
101
102         /* how far through the chain of SMB commands have we gone? */
103         unsigned chain_count;
104
105         /* the sequence number for signing */
106         uint64_t seq_num;
107
108         /* the async structure allows backend functions to delay
109            replying to requests. To use this, the front end must set
110            async.send_fn to a function to be called by the backend
111            when the reply is finally ready to be sent. The backend
112            must set async.status to the status it wants in the
113            reply. The backend must set the REQ_CONTROL_ASYNC
114            control_flag on the request to indicate that it wishes to
115            delay the reply
116
117            If async.send_fn is NULL then the backend cannot ask for a
118            delayed reply for this request
119
120            note that the async.private pointer is private to the front
121            end not the backend. The backend must not change it.
122         */
123         struct {
124                 void (*send_fn)(struct smbsrv_request *);
125                 void *private;
126                 NTSTATUS status;
127         } async;
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 #include "smbd/process_model.h"
156
157 /* smb server context structure. This should contain all the state
158  * information associated with a SMB server connection 
159  */
160 struct smbsrv_connection {
161         /* a count of the number of packets we have received. We
162          * actually only care about zero/non-zero at this stage */
163         unsigned pkt_count;
164
165         /* context that has been negotiated between the client and server */
166         struct {
167                 /* have we already done the NBT session establishment? */
168                 BOOL done_nbt_session;
169         
170                 /* only one negprot per connection is allowed */
171                 BOOL done_negprot;
172         
173                 /* multiple session setups are allowed, but some parameters are
174                    ignored in any but the first */
175                 BOOL done_sesssetup;
176                 
177                 /* 
178                  * Size of data we can send to client. Set
179                  *  by the client for all protocols above CORE.
180                  *  Set by us for CORE protocol.
181                  */
182                 unsigned max_send; /* init to BUFFER_SIZE */
183         
184                 /*
185                  * Size of the data we can receive. Set by us.
186                  * Can be modified by the max xmit parameter.
187                  */
188                 unsigned max_recv; /* init to BUFFER_SIZE */
189         
190                 /* a guess at the remote architecture. Try not to rely on this - in almost
191                    all cases using these values is the wrong thing to do */
192                 enum remote_arch_types ra_type;
193         
194                 /* the negotiatiated protocol */
195                 enum protocol_types protocol;
196         
197                 /* authentication context for multi-part negprot */
198                 struct auth_context *auth_context;
199         
200                 /* state of NTLMSSP auth */
201                 struct auth_ntlmssp_state *ntlmssp_state;
202         
203                 /* did we tell the client we support encrypted passwords? */
204                 BOOL encrypted_passwords;
205         
206                 /* did we send an extended security negprot reply? */
207                 BOOL spnego_negotiated;
208         
209                 /* client capabilities */
210                 uint32_t client_caps;
211         
212                 /* the timezone we sent to the client */
213                 int zone_offset;
214         } negotiate;
215
216         /* the context associated with open tree connects on a smb socket */
217         struct {
218                 struct smbsrv_tcon *tcons;
219
220                 /* number of open connections */
221                 struct bitmap *bmap;
222                 int num_open;
223         } tree;
224
225         /* the context associated with open files on an smb socket */
226         struct {
227                 struct files_struct *files; /* open files */
228                 struct bitmap *file_bmap; /* bitmap used to allocate file handles */
229         
230                 /* a fsp to use when chaining */
231                 struct files_struct *chain_fsp;
232         
233                 /* a fsp to use to save when breaking an oplock. */
234                 struct files_struct *oplock_save_chain_fsp;
235         
236                 /* how many files are open */
237                 int files_used;
238         
239                 /* limit for maximum open files */
240                 int real_max_open_files;
241         } file;
242
243         /* context associated with currently valid session setups */
244         struct {
245                 /* this holds info on session vuids that are already validated for this VC */
246                 struct smbsrv_session *session_list;
247                 uint16_t next_vuid; /* initialise to VUID_OFFSET */
248                 int num_validated_vuids;
249         } sessions;
250
251         /* this holds long term state specific to the printing subsystem */
252         struct {
253                 struct notify_queue *notify_queue_head;
254         } print;
255
256         /* the server_context holds a linked list of pending requests,
257          * this is used for blocking locks and requests blocked due to oplock
258          * break requests */
259         struct _smbsrv_pending_request {
260                 struct _smbsrv_pending_request *next, *prev;
261         
262                 /* the request itself - needs to be freed */
263                 struct smbsrv_request *request;
264         } *requests;
265
266         /* the timers context contains info on when we last did various
267          * functions */
268         struct {
269                 /* when did we last do timeout processing? */
270                 time_t last_timeout_processing;
271         
272                 /* when did we last sent a keepalive */
273                 time_t last_keepalive_sent;
274                 
275                 /* when we last checked the smb.conf for auto-reload */
276                 time_t last_smb_conf_reload;
277         } timers;
278
279         struct smb_signing_context signing;
280
281         struct substitute_context substitute;
282
283         struct dcesrv_context *dcesrv;
284
285         /* the pid of the process handling this session */
286         pid_t pid;
287         
288         struct server_connection *connection;
289 };