2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 this header declares the core context structures associated with smb
24 sockets, tree connects, requests etc
26 the idea is that we will eventually get rid of all our global
27 variables and instead store our stang from structures hanging off
31 /* the current user context for a request */
33 /* the vuid is used to specify the security context for this
34 request. Note that this may not be the same vuid as we
35 received on the wire (for example, for share mode or guest
39 struct user_struct *vuser;
43 /* each backend has to be one one of the following 3 basic types. In
44 * earlier versions of Samba backends needed to handle all types, now
45 * we implement them separately. */
46 enum ntvfs_type {NTVFS_DISK, NTVFS_PRINT, NTVFS_IPC};
48 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
53 struct smbsrv_tcon *next, *prev;
55 /* the server context that this was created on */
56 struct smbsrv_context *smb_ctx;
58 /* a talloc context for all data in this structure */
61 /* a private structure used by the active NTVFS backend */
64 uint16_t cnum; /* an index passed over the wire (the TID) */
70 /* the NTVFS operations - see source/ntvfs/ and include/ntvfs.h for details */
71 const struct ntvfs_ops *ntvfs_ops;
73 /* the reported filesystem type */
76 /* the reported device type */
80 /* the context for a single SMB request. This is passed to any request-context
82 struct smbsrv_request {
83 /* the server_context contains all context specific to this SMB socket */
84 struct smbsrv_context *smb_ctx;
86 /* conn is only set for operations that have a valid TID */
87 struct smbsrv_tcon *tcon;
89 /* the user context is derived from the vuid plus smb.conf options */
90 struct smbsrv_user *user_ctx;
92 /* a talloc context for the lifetime of this request */
95 /* a set of flags to control usage of the request. See REQ_CONTROL_* */
96 unsigned control_flags;
98 /* the smb pid is needed for locking contexts */
101 /* the flags from the SMB request, in raw form (host byte order) */
102 uint16_t flags, flags2;
104 /* the system time when the request arrived */
105 struct timeval request_time;
107 /* this can contain a fnum from an earlier part of a chained
108 * message (such as an SMBOpenX), or -1 */
111 /* how far through the chain of SMB commands have we gone? */
112 unsigned chain_count;
114 /* the sequence number for signing */
117 /* the async structure allows backend functions to delay
118 replying to requests. To use this, the front end must set
119 async.send_fn to a function to be called by the backend
120 when the reply is finally ready to be sent. The backend
121 must set async.status to the status it wants in the
122 reply. The backend must set the REQ_CONTROL_ASYNC
123 control_flag on the request to indicate that it wishes to
126 If async.send_fn is NULL then the backend cannot ask for a
127 delayed reply for this request
129 note that the async.private pointer is private to the front
130 end not the backend. The backend must not change it.
133 void (*send_fn)(struct smbsrv_request *);
139 /* the raw SMB buffer, including the 4 byte length header */
142 /* the size of the raw buffer, including 4 byte header */
145 /* how much has been allocated - on reply the buffer is over-allocated to
146 prevent too many realloc() calls
150 /* the start of the SMB header - this is always buffer+4 */
153 /* the command words and command word count. vwv points
154 into the raw buffer */
158 /* the data buffer and size. data points into the raw buffer */
162 /* ptr is used as a moving pointer into the data area
163 * of the packet. The reason its here and not a local
164 * variable in each function is that when a realloc of
165 * a reply packet is done we need to move this
173 /* the context associated with open files on an smb socket */
174 struct files_context {
175 struct files_struct *files; /* open files */
176 struct bitmap *file_bmap; /* bitmap used to allocate file handles */
178 /* a fsp to use when chaining */
179 struct files_struct *chain_fsp;
181 /* a fsp to use to save when breaking an oplock. */
182 struct files_struct *oplock_save_chain_fsp;
184 /* how many files are open */
187 /* limit for maximum open files */
188 int real_max_open_files;
192 /* the context associated with open tree connects on a smb socket */
193 struct tree_context {
194 struct smbsrv_tcon *tcons;
196 /* number of open connections */
201 /* context associated with currently valid session setups */
202 struct users_context {
203 /* users from session setup */
204 char *session_users; /* was a pstring */
206 /* this holds info on user ids that are already validated for this VC */
207 struct user_struct *validated_users;
208 int next_vuid; /* initialise to VUID_OFFSET */
209 int num_validated_vuids;
213 /* this contains variables that should be used in % substitutions for
214 * smb.conf parameters */
215 struct substitute_context {
218 /* our local netbios name, as give to us by the client */
221 /* the remote netbios name, as give to us by the client */
222 char *remote_machine;
224 /* the select remote protocol */
227 /* the name of the client as should be displayed in
228 * smbstatus. Can be an IP or a netbios name */
231 /* the username for %U */
235 /* context that has been negotiated between the client and server */
236 struct negotiate_context {
237 /* have we already done the NBT session establishment? */
238 BOOL done_nbt_session;
240 /* only one negprot per connection is allowed */
243 /* multiple session setups are allowed, but some parameters are
244 ignored in any but the first */
248 * Size of data we can send to client. Set
249 * by the client for all protocols above CORE.
250 * Set by us for CORE protocol.
252 unsigned max_send; /* init to BUFFER_SIZE */
255 * Size of the data we can receive. Set by us.
256 * Can be modified by the max xmit parameter.
258 unsigned max_recv; /* init to BUFFER_SIZE */
260 /* a guess at the remote architecture. Try not to rely on this - in almost
261 all cases using these values is the wrong thing to do */
262 enum remote_arch_types ra_type;
264 /* the negotiatiated protocol */
265 enum protocol_types protocol;
267 /* authentication context for multi-part negprot */
268 struct auth_context *auth_context;
270 /* state of NTLMSSP auth */
271 struct auth_ntlmssp_state *ntlmssp_state;
273 /* did we tell the client we support encrypted passwords? */
274 BOOL encrypted_passwords;
276 /* did we send an extended security negprot reply? */
277 BOOL spnego_negotiated;
279 /* client capabilities */
280 uint32_t client_caps;
282 /* the timezone we sent to the client */
286 /* this is the context for a SMB socket associated with the socket itself */
287 struct socket_context {
288 /* the open file descriptor */
291 /* the last read error on the socket, if any (replaces smb_read_error global) */
294 /* a count of the number of packets we have received. We
295 * actually only care about zero/non-zero at this stage */
298 /* the network address of the client */
303 /* this holds long term state specific to the printing subsystem */
304 struct printing_context {
305 struct notify_queue *notify_queue_head;
309 /* the server_context holds a linked list of pending requests,
310 * this is used for blocking locks and requests blocked due to oplock
312 struct pending_request {
313 struct pending_request *next, *prev;
315 /* the request itself - needs to be freed */
316 struct smbsrv_request *request;
319 /* the timers context contains info on when we last did various
321 struct timers_context {
322 /* when did we last do timeout processing? */
323 time_t last_timeout_processing;
325 /* when did we last sent a keepalive */
326 time_t last_keepalive_sent;
328 /* when we last checked the smb.conf for auto-reload */
329 time_t last_smb_conf_reload;
333 struct signing_context {
335 uint64_t next_seq_num;
336 enum smb_signing_state signing_state;
339 #include "smbd/process_model.h"
341 /* smb server context structure. This should contain all the state
342 * information associated with a SMB server */
343 struct smbsrv_context {
344 /* a talloc context for all data in this structure */
347 struct negotiate_context negotiate;
349 struct substitute_context substitute;
351 struct socket_context socket;
353 struct files_context file;
355 struct tree_context tree;
357 struct users_context users;
359 struct printing_context print;
361 struct timers_context timers;
363 struct dcesrv_context dcesrv;
365 struct signing_context signing;
367 /* the pid of the process handling this session */
370 /* pointer to list of events that we are waiting on */
371 struct event_context *events;
373 /* process model specific operations */
374 const struct model_ops *model_ops;