2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
6 Copyright (C) Stefan Metzmacher 2004
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.
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.
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.
24 this header declares the core context structures associated with smb
25 sockets, tree connects, requests etc
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
32 /* the current user context for a request */
33 struct smbsrv_session {
34 struct smbsrv_session *prev, *next;
36 struct smbsrv_connection *smb_conn;
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
44 struct gensec_security *gensec_ctx;
46 struct auth_session_info *session_info;
49 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
54 struct smbsrv_tcon *next, *prev;
56 /* the server context that this was created on */
57 struct smbsrv_connection *smb_conn;
59 uint16_t cnum; /* an index passed over the wire (the TID) */
64 /* the NTVFS context - see source/ntvfs/ for details */
65 struct ntvfs_context *ntvfs_ctx;
67 /* the reported filesystem type */
70 /* the reported device type */
74 /* the context for a single SMB request. This is passed to any request-context
76 struct smbsrv_request {
77 /* the server_context contains all context specific to this SMB socket */
78 struct smbsrv_connection *smb_conn;
80 /* conn is only set for operations that have a valid TID */
81 struct smbsrv_tcon *tcon;
83 /* the session context is derived from the vuid */
84 struct smbsrv_session *session;
86 /* a set of flags to control usage of the request. See REQ_CONTROL_* */
87 unsigned control_flags;
89 /* the smb pid is needed for locking contexts */
92 /* the flags from the SMB request, in raw form (host byte order) */
93 uint16_t flags, flags2;
95 /* the system time when the request arrived */
96 struct timeval request_time;
98 /* this can contain a fnum from an earlier part of a chained
99 * message (such as an SMBOpenX), or -1 */
102 /* how far through the chain of SMB commands have we gone? */
103 unsigned chain_count;
105 /* the sequence number for signing */
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
117 If async.send_fn is NULL then the backend cannot ask for a
118 delayed reply for this request
120 note that the async.private pointer is private to the front
121 end not the backend. The backend must not change it.
124 void (*send_fn)(struct smbsrv_request *);
129 struct request_buffer in;
130 struct request_buffer out;
133 /* this contains variables that should be used in % substitutions for
134 * smb.conf parameters */
135 struct substitute_context {
138 /* our local netbios name, as give to us by the client */
141 /* the remote netbios name, as give to us by the client */
142 char *remote_machine;
144 /* the select remote protocol */
147 /* the name of the client as should be displayed in
148 * smbstatus. Can be an IP or a netbios name */
151 /* the username for %U */
155 #include "smbd/process_model.h"
157 /* smb server context structure. This should contain all the state
158 * information associated with a SMB server connection
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 */
165 /* context that has been negotiated between the client and server */
167 /* have we already done the NBT session establishment? */
168 BOOL done_nbt_session;
170 /* only one negprot per connection is allowed */
173 /* multiple session setups are allowed, but some parameters are
174 ignored in any but the first */
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.
182 unsigned max_send; /* init to BUFFER_SIZE */
185 * Size of the data we can receive. Set by us.
186 * Can be modified by the max xmit parameter.
188 unsigned max_recv; /* init to BUFFER_SIZE */
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;
194 /* the negotiatiated protocol */
195 enum protocol_types protocol;
197 /* authentication context for multi-part negprot */
198 struct auth_context *auth_context;
200 /* state of NTLMSSP auth */
201 struct auth_ntlmssp_state *ntlmssp_state;
203 /* did we tell the client we support encrypted passwords? */
204 BOOL encrypted_passwords;
206 /* did we send an extended security negprot reply? */
207 BOOL spnego_negotiated;
209 /* client capabilities */
210 uint32_t client_caps;
212 /* the timezone we sent to the client */
216 /* the context associated with open tree connects on a smb socket */
218 struct smbsrv_tcon *tcons;
220 /* number of open connections */
225 /* the context associated with open files on an smb socket */
227 struct files_struct *files; /* open files */
228 struct bitmap *file_bmap; /* bitmap used to allocate file handles */
230 /* a fsp to use when chaining */
231 struct files_struct *chain_fsp;
233 /* a fsp to use to save when breaking an oplock. */
234 struct files_struct *oplock_save_chain_fsp;
236 /* how many files are open */
239 /* limit for maximum open files */
240 int real_max_open_files;
243 /* context associated with currently valid session setups */
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;
251 /* this holds long term state specific to the printing subsystem */
253 struct notify_queue *notify_queue_head;
256 /* the server_context holds a linked list of pending requests,
257 * this is used for blocking locks and requests blocked due to oplock
259 struct _smbsrv_pending_request {
260 struct _smbsrv_pending_request *next, *prev;
262 /* the request itself - needs to be freed */
263 struct smbsrv_request *request;
266 /* the timers context contains info on when we last did various
269 /* when did we last do timeout processing? */
270 time_t last_timeout_processing;
272 /* when did we last sent a keepalive */
273 time_t last_keepalive_sent;
275 /* when we last checked the smb.conf for auto-reload */
276 time_t last_smb_conf_reload;
279 struct smb_signing_context signing;
281 struct substitute_context substitute;
283 struct dcesrv_context *dcesrv;
285 /* the pid of the process handling this session */
288 struct server_connection *connection;