2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Andrew Tridgell 2003
Copyright ( C ) James J Myers 2003 < myersjj @ samba . org >
2004-09-13 14:33:07 +04:00
Copyright ( C ) Stefan Metzmacher 2004
2003-08-13 05:53:07 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2004-11-02 10:18:24 +03:00
# include "request.h"
# include "smbd/process_model.h"
2003-08-13 05:53:07 +04:00
/*
this header declares the core context structures associated with smb
sockets , tree connects , requests etc
the idea is that we will eventually get rid of all our global
2005-07-15 13:25:57 +04:00
variables and instead store our state from structures hanging off
2003-08-13 05:53:07 +04:00
these basic elements
*/
/* the current user context for a request */
2004-07-14 16:44:31 +04:00
struct smbsrv_session {
struct smbsrv_session * prev , * next ;
struct smbsrv_connection * smb_conn ;
2003-08-13 05:53:07 +04:00
/* the vuid is used to specify the security context for this
request . Note that this may not be the same vuid as we
received on the wire ( for example , for share mode or guest
access ) */
2004-05-25 21:24:24 +04:00
uint16_t vuid ;
2003-08-13 05:53:07 +04:00
2004-07-14 16:44:31 +04:00
struct gensec_security * gensec_ctx ;
struct auth_session_info * session_info ;
2005-04-10 11:39:51 +04:00
/* Distinguish between a VUID allocated for the multi-pass
* extended secrity session setup and one that is finished */
BOOL finished_sesssetup ;
2005-07-19 07:58:44 +04:00
struct timeval connect_time ;
2003-08-13 05:53:07 +04:00
} ;
2003-12-12 06:59:09 +03:00
/* we need a forward declaration of the ntvfs_ops strucutre to prevent
include recursion */
2004-09-29 17:17:09 +04:00
struct ntvfs_context ;
2003-12-12 06:59:09 +03:00
2004-06-28 12:27:36 +04:00
struct smbsrv_tcon {
struct smbsrv_tcon * next , * prev ;
2003-12-12 06:59:09 +03:00
/* the server context that this was created on */
2004-06-29 11:40:14 +04:00
struct smbsrv_connection * smb_conn ;
2003-12-12 06:59:09 +03:00
2005-01-13 21:49:10 +03:00
uint16_t tid ; /* an index passed over the wire (the TID) */
2003-12-12 06:59:09 +03:00
int service ;
BOOL read_only ;
BOOL admin_user ;
2004-09-29 17:17:09 +04:00
/* the NTVFS context - see source/ntvfs/ for details */
struct ntvfs_context * ntvfs_ctx ;
2003-12-12 06:59:09 +03:00
/* the reported filesystem type */
char * fs_type ;
/* the reported device type */
char * dev_type ;
2005-07-19 08:26:58 +04:00
2005-11-17 15:52:40 +03:00
/* some stuff to support share level security */
struct {
/* in share level security we need to fake up a session */
struct smbsrv_session * session ;
} sec_share ;
2005-07-19 08:26:58 +04:00
struct timeval connect_time ;
2003-12-12 06:59:09 +03:00
} ;
2004-10-29 01:48:53 +04:00
/* a set of flags to control handling of request structures */
# define REQ_CONTROL_LARGE (1<<1) /* allow replies larger than max_xmit */
2003-08-13 05:53:07 +04:00
/* the context for a single SMB request. This is passed to any request-context
functions */
2004-06-28 12:39:00 +04:00
struct smbsrv_request {
2004-10-28 09:09:42 +04:00
/* the smbsrv_connection needs a list of requests queued for send */
struct smbsrv_request * next , * prev ;
2003-08-13 05:53:07 +04:00
/* the server_context contains all context specific to this SMB socket */
2004-06-29 11:40:14 +04:00
struct smbsrv_connection * smb_conn ;
2003-08-13 05:53:07 +04:00
/* conn is only set for operations that have a valid TID */
2004-06-28 12:27:36 +04:00
struct smbsrv_tcon * tcon ;
2003-08-13 05:53:07 +04:00
2004-07-14 16:44:31 +04:00
/* the session context is derived from the vuid */
struct smbsrv_session * session ;
2003-08-13 05:53:07 +04:00
/* a set of flags to control usage of the request. See REQ_CONTROL_* */
unsigned control_flags ;
/* the smb pid is needed for locking contexts */
2004-05-25 21:24:24 +04:00
uint16_t smbpid ;
2003-08-13 05:53:07 +04:00
/* the flags from the SMB request, in raw form (host byte order) */
2004-05-25 21:24:24 +04:00
uint16_t flags , flags2 ;
2003-08-13 05:53:07 +04:00
/* the system time when the request arrived */
struct timeval request_time ;
/* this can contain a fnum from an earlier part of a chained
* message ( such as an SMBOpenX ) , or - 1 */
int chained_fnum ;
/* how far through the chain of SMB commands have we gone? */
unsigned chain_count ;
2004-05-22 15:16:21 +04:00
/* the sequence number for signing */
2004-05-25 17:57:39 +04:00
uint64_t seq_num ;
2004-05-22 15:16:21 +04:00
2004-10-29 01:48:53 +04:00
/* ntvfs per request async states */
struct ntvfs_async_state * async_states ;
2003-08-13 05:53:07 +04:00
2004-07-16 06:54:57 +04:00
struct request_buffer in ;
struct request_buffer out ;
2003-08-13 05:53:07 +04:00
} ;
/* this contains variables that should be used in % substitutions for
* smb . conf parameters */
struct substitute_context {
char * remote_arch ;
/* our local netbios name, as give to us by the client */
char * local_machine ;
/* the remote netbios name, as give to us by the client */
char * remote_machine ;
/* the select remote protocol */
char * remote_proto ;
/* the name of the client as should be displayed in
* smbstatus . Can be an IP or a netbios name */
char * client_name ;
/* the username for %U */
char * user_name ;
} ;
2005-09-26 20:57:08 +04:00
/* Remote architectures we know about. */
enum remote_arch_types { RA_UNKNOWN , RA_WFWG , RA_OS2 , RA_WIN95 , RA_WINNT , RA_WIN2K , RA_WINXP , RA_SAMBA } ;
2004-06-29 11:40:14 +04:00
/* smb server context structure. This should contain all the state
* information associated with a SMB server connection
*/
struct smbsrv_connection {
/* context that has been negotiated between the client and server */
struct {
/* have we already done the NBT session establishment? */
BOOL done_nbt_session ;
/* only one negprot per connection is allowed */
BOOL done_negprot ;
/* multiple session setups are allowed, but some parameters are
ignored in any but the first */
BOOL done_sesssetup ;
/*
* Size of data we can send to client . Set
* by the client for all protocols above CORE .
* Set by us for CORE protocol .
*/
unsigned max_send ; /* init to BUFFER_SIZE */
/*
* Size of the data we can receive . Set by us .
* Can be modified by the max xmit parameter .
*/
unsigned max_recv ; /* init to BUFFER_SIZE */
/* a guess at the remote architecture. Try not to rely on this - in almost
all cases using these values is the wrong thing to do */
enum remote_arch_types ra_type ;
/* the negotiatiated protocol */
enum protocol_types protocol ;
/* authentication context for multi-part negprot */
struct auth_context * auth_context ;
2005-10-20 07:47:55 +04:00
/* reference to the kerberos keytab, or machine trust account */
struct cli_credentials * server_credentials ;
2004-06-29 11:40:14 +04:00
/* did we tell the client we support encrypted passwords? */
BOOL encrypted_passwords ;
/* did we send an extended security negprot reply? */
BOOL spnego_negotiated ;
/* client capabilities */
uint32_t client_caps ;
/* the timezone we sent to the client */
int zone_offset ;
2005-01-22 08:36:32 +03:00
/* NBT names only set when done_nbt_session is true */
struct nbt_name * called_name ;
struct nbt_name * calling_name ;
2004-06-29 11:40:14 +04:00
} negotiate ;
2003-08-13 05:53:07 +04:00
2004-06-29 11:40:14 +04:00
/* the context associated with open tree connects on a smb socket */
struct {
2004-10-19 11:08:35 +04:00
/* an id tree used to allocate tids */
2004-10-22 10:57:31 +04:00
struct idr_context * idtree_tid ;
2005-11-18 15:20:16 +03:00
/* list of open tree connects */
struct smbsrv_tcon * list ;
} tcons ;
2003-08-13 05:53:07 +04:00
2004-06-29 11:40:14 +04:00
/* context associated with currently valid session setups */
struct {
int num_validated_vuids ;
2005-04-10 11:39:51 +04:00
/* an id tree used to allocate vuids */
2005-04-12 09:36:28 +04:00
/* this holds info on session vuids that are already
* validated for this VC */
2005-04-10 11:39:51 +04:00
struct idr_context * idtree_vuid ;
2005-07-19 07:58:44 +04:00
/* also kept as a link list so it can be enumerated by
the management code */
struct smbsrv_session * list ;
2004-07-14 16:44:31 +04:00
} sessions ;
2004-05-22 15:16:21 +04:00
2004-06-29 11:40:14 +04:00
/* the server_context holds a linked list of pending requests,
* this is used for blocking locks and requests blocked due to oplock
* break requests */
struct _smbsrv_pending_request {
struct _smbsrv_pending_request * next , * prev ;
/* the request itself - needs to be freed */
struct smbsrv_request * request ;
} * requests ;
2003-08-13 05:53:07 +04:00
2005-01-14 05:10:11 +03:00
struct smb_signing_context signing ;
2004-07-14 01:04:56 +04:00
2005-01-30 03:54:57 +03:00
struct stream_connection * connection ;
2004-10-28 08:36:12 +04:00
/* this holds a partially received request */
2005-11-09 13:51:26 +03:00
struct packet_context * packet ;
2004-10-28 09:09:42 +04:00
2004-12-16 15:31:34 +03:00
/* a list of partially received transaction requests */
struct smbsrv_trans_partial {
struct smbsrv_trans_partial * next , * prev ;
struct smbsrv_request * req ;
struct smb_trans2 * trans ;
uint8_t command ;
} * trans_partial ;
2005-06-20 12:47:52 +04:00
2005-08-01 23:48:16 +04:00
/* mark a connection for termination */
2005-11-09 13:51:26 +03:00
const char * terminate ;
2005-08-01 23:48:16 +04:00
2005-07-21 05:43:26 +04:00
/* configuration parameters */
struct {
enum security_types security ;
BOOL nt_status_support ;
} config ;
2003-08-13 05:53:07 +04:00
} ;