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 /* the domain name, user name etc - mostly used in % substitutions */
40 struct userdom_struct *user;
42 struct user_struct *vuser;
45 /* the context for a single SMB request. This is passed to any request-context
47 struct request_context {
48 /* the server_context contains all context specific to this SMB socket */
49 struct server_context *smb;
51 /* conn is only set for operations that have a valid TID */
52 struct tcon_context *conn;
54 /* the user context is derived from the vuid plus smb.conf options */
55 struct user_context *user_ctx;
57 /* a talloc context for the lifetime of this request */
60 /* a set of flags to control usage of the request. See REQ_CONTROL_* */
61 unsigned control_flags;
63 /* the smb pid is needed for locking contexts */
66 /* the flags from the SMB request, in raw form (host byte order) */
69 /* the system time when the request arrived */
70 struct timeval request_time;
72 /* this can contain a fnum from an earlier part of a chained
73 * message (such as an SMBOpenX), or -1 */
76 /* how far through the chain of SMB commands have we gone? */
79 /* the async structure allows backend functions to delay
80 replying to requests. To use this, the front end must set
81 async.send_fn to a function to be called by the backend
82 when the reply is finally ready to be sent. The backend
83 must set async.status to the status it wants in the
84 reply. The backend must set the REQ_CONTROL_ASYNC
85 control_flag on the request to indicate that it wishes to
88 If async.send_fn is NULL then the backend cannot ask for a
89 delayed reply for this request
91 note that the async.private pointer is private to the front
92 end not the backend. The backend must not change it.
95 void (*send_fn)(struct request_context *);
101 /* the raw SMB buffer, including the 4 byte length header */
104 /* the size of the raw buffer, including 4 byte header */
107 /* how much has been allocated - on reply the buffer is over-allocated to
108 prevent too many realloc() calls
112 /* the start of the SMB header - this is always buffer+4 */
115 /* the command words and command word count. vwv points
116 into the raw buffer */
120 /* the data buffer and size. data points into the raw buffer */
124 /* ptr is used as a moving pointer into the data area
125 * of the packet. The reason its here and not a local
126 * variable in each function is that when a realloc of
127 * a reply packet is done we need to move this
135 /* the context associated with open files on an smb socket */
136 struct files_context {
137 struct files_struct *files; /* open files */
138 struct bitmap *file_bmap; /* bitmap used to allocate file handles */
140 /* a fsp to use when chaining */
141 struct files_struct *chain_fsp;
143 /* a fsp to use to save when breaking an oplock. */
144 struct files_struct *oplock_save_chain_fsp;
146 /* how many files are open */
149 /* limit for maximum open files */
150 int real_max_open_files;
154 /* the context associated with open tree connects on a smb socket */
155 struct tree_context {
156 struct tcon_context *connections;
158 /* number of open connections */
163 /* context associated with currently valid session setups */
164 struct users_context {
165 /* users from session setup */
166 char *session_users; /* was a pstring */
168 /* this holds info on user ids that are already validated for this VC */
169 struct user_struct *validated_users;
170 int next_vuid; /* initialise to VUID_OFFSET */
171 int num_validated_vuids;
175 /* this contains variables that should be used in % substitutions for
176 * smb.conf parameters */
177 struct substitute_context {
180 /* our local netbios name, as give to us by the client */
183 /* the remote netbios name, as give to us by the client */
184 char *remote_machine;
186 /* the select remote protocol */
189 /* the name of the client as should be displayed in
190 * smbstatus. Can be an IP or a netbios name */
193 /* the username for %U */
197 /* context that has been negotiated between the client and server */
198 struct negotiate_context {
199 /* have we already done the NBT session establishment? */
200 BOOL done_nbt_session;
202 /* only one negprot per connection is allowed */
205 /* multiple session setups are allowed, but some parameters are
206 ignored in any but the first */
210 * Size of data we can send to client. Set
211 * by the client for all protocols above CORE.
212 * Set by us for CORE protocol.
214 unsigned max_send; /* init to BUFFER_SIZE */
217 * Size of the data we can receive. Set by us.
218 * Can be modified by the max xmit parameter.
220 unsigned max_recv; /* init to BUFFER_SIZE */
222 /* a guess at the remote architecture. Try not to rely on this - in almost
223 all cases using these values is the wrong thing to do */
224 enum remote_arch_types ra_type;
226 /* the negotiatiated protocol */
227 enum protocol_types protocol;
229 /* authentication context for multi-part negprot */
230 struct auth_context *auth_context;
232 /* state of NTLMSSP auth */
233 struct auth_ntlmssp_state *ntlmssp_state;
235 /* did we tell the client we support encrypted passwords? */
236 BOOL encrypted_passwords;
238 /* did we send an extended security negprot reply? */
239 BOOL spnego_negotiated;
241 /* client capabilities */
245 /* this is the context for a SMB socket associated with the socket itself */
246 struct socket_context {
247 /* the open file descriptor */
250 /* the last read error on the socket, if any (replaces smb_read_error global) */
253 /* a count of the number of packets we have received. We
254 * actually only care about zero/non-zero at this stage */
257 /* the network address of the client */
262 /* this holds long term state specific to the printing subsystem */
263 struct printing_context {
264 struct notify_queue *notify_queue_head;
268 /* the server_context holds a linked list of pending requests,
269 * this is used for blocking locks and requests blocked due to oplock
271 struct pending_request {
272 struct pending_request *next, *prev;
274 /* the request itself - needs to be freed */
275 struct request_context *request;
278 /* the timers context contains info on when we last did various
280 struct timers_context {
281 /* when did we last do timeout processing? */
282 time_t last_timeout_processing;
284 /* when did we last sent a keepalive */
285 time_t last_keepalive_sent;
287 /* when we last checked the smb.conf for auto-reload */
288 time_t last_smb_conf_reload;
292 /* the process model operations structure - contains function pointers to
293 the model-specific implementations of each operation */
295 /* called at startup when the model is selected */
296 void (*model_startup)(void);
298 /* function to accept new connection */
299 void (*accept_connection)(struct event_context *, struct fd_event *, time_t, uint16);
301 /* function to terminate a connection */
302 void (*terminate_connection)(struct server_context *smb, const char *reason);
304 /* function to exit server */
305 void (*exit_server)(struct server_context *smb, const char *reason);
307 /* returns process or thread id */
308 int (*get_id)(struct request_context *req);
312 /* smb context structure. This should contain all the state
313 * information associated with a SMB server */
314 struct server_context {
315 /* a talloc context for all data in this structure */
318 struct negotiate_context negotiate;
320 struct substitute_context substitute;
322 struct socket_context socket;
324 struct files_context file;
326 struct tree_context tree;
328 struct users_context users;
330 struct printing_context print;
332 struct timers_context timers;
334 /* the pid of the process handling this session */
337 /* pointer make to smbd daemon context */
338 struct smbd_context *smbd;
340 /* pointer to list of events that we are waiting on */
341 struct event_context *events;
343 /* process model specific operations */
344 struct model_ops *model_ops;