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-2005
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 #include "smbd/process_model.h"
27 this header declares the core context structures associated with smb
28 sockets, tree connects, requests etc
30 the idea is that we will eventually get rid of all our global
31 variables and instead store our state from structures hanging off
35 /* the current user context for a request */
36 struct smbsrv_session {
37 struct smbsrv_session *prev, *next;
39 struct smbsrv_connection *smb_conn;
41 /* the vuid is used to specify the security context for this
42 request. Note that this may not be the same vuid as we
43 received on the wire (for example, for share mode or guest
47 struct gensec_security *gensec_ctx;
49 struct auth_session_info *session_info;
51 /* Distinguish between a VUID allocated for the multi-pass
52 * extended secrity session setup and one that is finished */
53 BOOL finished_sesssetup;
55 struct timeval connect_time;
58 /* we need a forward declaration of the ntvfs_ops strucutre to prevent
63 struct smbsrv_tcon *next, *prev;
65 /* the server context that this was created on */
66 struct smbsrv_connection *smb_conn;
69 * an index passed over the wire:
73 uint32_t tid; /* an index passed over the wire (the TID) */
79 /* the NTVFS context - see source/ntvfs/ for details */
80 struct ntvfs_context *ntvfs_ctx;
82 /* the reported filesystem type */
85 /* the reported device type */
88 /* some stuff to support share level security */
90 /* in share level security we need to fake up a session */
91 struct smbsrv_session *session;
94 /* some statictics for the management tools */
96 struct timeval connect_time;
100 /* a set of flags to control handling of request structures */
101 #define REQ_CONTROL_LARGE (1<<1) /* allow replies larger than max_xmit */
103 /* the context for a single SMB request. This is passed to any request-context
105 struct smbsrv_request {
106 /* the smbsrv_connection needs a list of requests queued for send */
107 struct smbsrv_request *next, *prev;
109 /* the server_context contains all context specific to this SMB socket */
110 struct smbsrv_connection *smb_conn;
112 /* conn is only set for operations that have a valid TID */
113 struct smbsrv_tcon *tcon;
115 /* the session context is derived from the vuid */
116 struct smbsrv_session *session;
118 /* a set of flags to control usage of the request. See REQ_CONTROL_* */
119 unsigned control_flags;
121 /* the smb pid is needed for locking contexts */
124 /* the flags from the SMB request, in raw form (host byte order) */
125 uint16_t flags, flags2;
127 /* the system time when the request arrived */
128 struct timeval request_time;
130 /* this can contain a fnum from an earlier part of a chained
131 * message (such as an SMBOpenX), or -1 */
134 /* how far through the chain of SMB commands have we gone? */
135 unsigned chain_count;
137 /* the sequence number for signing */
140 /* ntvfs per request async states */
141 struct ntvfs_async_state *async_states;
143 struct request_buffer in;
144 struct request_buffer out;
147 /* this contains variables that should be used in % substitutions for
148 * smb.conf parameters */
149 struct substitute_context {
152 /* our local netbios name, as give to us by the client */
155 /* the remote netbios name, as give to us by the client */
156 char *remote_machine;
158 /* the select remote protocol */
161 /* the name of the client as should be displayed in
162 * smbstatus. Can be an IP or a netbios name */
165 /* the username for %U */
169 /* Remote architectures we know about. */
170 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_WINXP, RA_SAMBA};
172 /* smb server context structure. This should contain all the state
173 * information associated with a SMB server connection
175 struct smbsrv_connection {
176 /* context that has been negotiated between the client and server */
178 /* have we already done the NBT session establishment? */
179 BOOL done_nbt_session;
181 /* only one negprot per connection is allowed */
184 /* multiple session setups are allowed, but some parameters are
185 ignored in any but the first */
189 * Size of data we can send to client. Set
190 * by the client for all protocols above CORE.
191 * Set by us for CORE protocol.
193 unsigned max_send; /* init to BUFFER_SIZE */
196 * Size of the data we can receive. Set by us.
197 * Can be modified by the max xmit parameter.
199 unsigned max_recv; /* init to BUFFER_SIZE */
201 /* a guess at the remote architecture. Try not to rely on this - in almost
202 all cases using these values is the wrong thing to do */
203 enum remote_arch_types ra_type;
205 /* the negotiatiated protocol */
206 enum protocol_types protocol;
208 /* authentication context for multi-part negprot */
209 struct auth_context *auth_context;
211 /* reference to the kerberos keytab, or machine trust account */
212 struct cli_credentials *server_credentials;
214 /* did we tell the client we support encrypted passwords? */
215 BOOL encrypted_passwords;
217 /* did we send an extended security negprot reply? */
218 BOOL spnego_negotiated;
220 /* client capabilities */
221 uint32_t client_caps;
223 /* the timezone we sent to the client */
226 /* NBT names only set when done_nbt_session is true */
227 struct nbt_name *called_name;
228 struct nbt_name *calling_name;
231 /* the context associated with open tree connects on a smb socket */
233 /* an id tree used to allocate tids */
234 struct idr_context *idtree_tid;
236 /* this is the limit of vuid values for this connection */
237 uint32_t idtree_limit;
239 /* list of open tree connects */
240 struct smbsrv_tcon *list;
243 /* context associated with currently valid session setups */
245 int num_validated_vuids;
247 /* an id tree used to allocate vuids */
248 /* this holds info on session vuids that are already
249 * validated for this VC */
250 struct idr_context *idtree_vuid;
252 /* also kept as a link list so it can be enumerated by
253 the management code */
254 struct smbsrv_session *list;
257 /* the server_context holds a linked list of pending requests,
258 * this is used for blocking locks and requests blocked due to oplock
260 struct _smbsrv_pending_request {
261 struct _smbsrv_pending_request *next, *prev;
263 /* the request itself - needs to be freed */
264 struct smbsrv_request *request;
267 struct smb_signing_context signing;
269 struct stream_connection *connection;
271 /* this holds a partially received request */
272 struct packet_context *packet;
274 /* a list of partially received transaction requests */
275 struct smbsrv_trans_partial {
276 struct smbsrv_trans_partial *next, *prev;
277 struct smbsrv_request *req;
278 struct smb_trans2 *trans;
282 /* mark a connection for termination */
283 const char *terminate;
285 /* configuration parameters */
287 enum security_types security;
288 BOOL nt_status_support;