*/
#include "libcli/raw/request.h"
-#include "smbd/process_model.h"
#include "libcli/raw/interfaces.h"
+#include "lib/events/events.h"
+#include "lib/socket/socket.h"
+#include "lib/util/dlinklist.h"
/*
this header declares the core context structures associated with smb
/* also kept as a link list so it can be enumerated by
the management code */
struct smbsrv_session *list;
-} sessions;
+};
+
+struct smbsrv_handles_context {
+ /* an id tree used to allocate file handles */
+ struct idr_context *idtree_hid;
+
+ /* this is the limit of handle values for this context */
+ uint64_t idtree_limit;
+
+ /* also kept as a link list so it can be enumerated by
+ the management code */
+ struct smbsrv_handle *list;
+};
/* the current user context for a request */
struct smbsrv_session {
struct smbsrv_connection *smb_conn;
+ /*
+ * in SMB2 tcons belong to just one session
+ * and not to the whole connection
+ */
struct smbsrv_tcons_context smb2_tcons;
+ /*
+ * the open file handles for this session,
+ * used for SMBexit, SMBulogoff and SMB2 SessionLogoff
+ */
+ struct smbsrv_handle_session_item *handles;
+
/*
* an index passed over the wire:
* - 16 bit for smb
struct auth_session_info *session_info;
- /* some statictics for the management tools */
+ /* some statistics for the management tools */
struct {
/* the time when the session setup started */
struct timeval connect_time;
/* the time when the session setup was finished */
struct timeval auth_time;
+ /* the time when the last request comes in */
+ struct timeval last_request_time;
} statistics;
};
/* the server context that this was created on */
struct smbsrv_connection *smb_conn;
+ /* the open file handles on this tcon */
+ struct smbsrv_handles_context handles;
+
/*
* an index passed over the wire:
* - 16 bit for smb
struct smbsrv_session *session;
} smb2;
- /* some statictics for the management tools */
+ /* some statistics for the management tools */
struct {
+ /* the time when the tree connect started */
struct timeval connect_time;
+ /* the time when the last request comes in */
+ struct timeval last_request_time;
+ } statistics;
+};
+
+struct smbsrv_handle {
+ struct smbsrv_handle *next, *prev;
+
+ /* the tcon the handle belongs to */
+ struct smbsrv_tcon *tcon;
+
+ /* the session the handle was opened on */
+ struct smbsrv_session *session;
+
+ /* the smbpid used on the open, used for SMBexit */
+ uint16_t smbpid;
+
+ /*
+ * this is for adding the handle into a linked list
+ * on the smbsrv_session, we can't use *next,*prev
+ * for this because they're used for the linked list on the
+ * smbsrv_tcon
+ */
+ struct smbsrv_handle_session_item {
+ struct smbsrv_handle_session_item *prev, *next;
+ struct smbsrv_handle *handle;
+ } session_item;
+
+ /*
+ * the value passed over the wire
+ * - 16 bit for smb
+ * - 64 bit for smb2
+ * Note: for SMB2 handles are 128 bit
+ * we'll fill the 2nd 64 bit with:
+ * - 32 bit TID
+ * - 32 bit 0xFFFFFFFF
+ */
+ uint64_t hid;
+
+ /*
+ * the ntvfs handle passed to the ntvfs backend
+ */
+ struct ntvfs_handle *ntvfs;
+
+ /* some statistics for the management tools */
+ struct {
+ /* the time when the tree connect started */
+ struct timeval open_time;
+ /* the time when the last request comes in */
+ struct timeval last_use_time;
} statistics;
};
/* a set of flags to control handling of request structures */
-#define REQ_CONTROL_LARGE (1<<1) /* allow replies larger than max_xmit */
+#define SMBSRV_REQ_CONTROL_LARGE (1<<1) /* allow replies larger than max_xmit */
+
+#define SMBSRV_REQ_DEFAULT_STR_FLAGS(req) (((req)->flags2 & FLAGS2_UNICODE_STRINGS) ? STR_UNICODE : STR_ASCII)
/* the context for a single SMB request. This is passed to any request-context
functions */
/* the session context is derived from the vuid */
struct smbsrv_session *session;
- /* a set of flags to control usage of the request. See REQ_CONTROL_* */
- unsigned control_flags;
-
- /* the flags from the SMB request, in raw form (host byte order) */
- uint16_t flags2;
+ /* a set of flags to control usage of the request. See SMBSRV_REQ_CONTROL_* */
+ uint32_t control_flags;
/* the system time when the request arrived */
struct timeval request_time;
+ /* a pointer to the per request union smb_* io structure */
+ void *io_ptr;
+
+ /* the ntvfs_request */
+ struct ntvfs_request *ntvfs;
+
+ /* Now the SMB specific stuff */
+
+ /* the flags from the SMB request, in raw form (host byte order) */
+ uint16_t flags2;
+
/* this can contain a fnum from an earlier part of a chained
* message (such as an SMBOpenX), or -1 */
int chained_fnum;
struct request_buffer in;
struct request_buffer out;
-
- /*
- * the following elemets will be part of a future ntvfs_request struct
- */
-
- /* the ntvfs_context this requests belongs to */
- struct ntvfs_context *ctx;
-
- /* ntvfs per request async states */
- struct ntvfs_async_state *async_states;
-
- /* the session_info, with security_token and maybe delegated credentials */
- struct auth_session_info *session_info;
-
- /* the smb pid is needed for locking contexts */
- uint16_t smbpid;
-
-uint16_t smbmid;
-
- /* some statictics for the management tools */
- struct {
- /* the system time when the request arrived */
- struct timeval request_time;
- } statistics;
};
-/* 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;
-};
-
-/* 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};
-
-enum security_types {SEC_SHARE,SEC_USER} security;
+enum security_types {SEC_SHARE,SEC_USER};
/* smb server context structure. This should contain all the state
* information associated with a SMB server connection
*/
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;
struct nbt_name *calling_name;
} negotiate;
- /* the context associated with open tree connects on a smb socket */
+ /* the context associated with open tree connects on a smb socket, not for SMB2 */
struct smbsrv_tcons_context smb_tcons;
/* context associated with currently valid session setups */
struct smbsrv_sessions_context sessions;
- /* 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;
+ /*
+ * the server_context holds a linked list of pending requests,
+ * this is used for finding the request structures on ntcancel requests
+ * For SMB only
+ */
+ struct smbsrv_request *requests;
+
+ /*
+ * the server_context holds a linked list of pending requests,
+ * and an idtree for finding the request structures on SMB2 Cancel
+ * For SMB2 only
+ */
+ struct {
+ /* an id tree used to allocate ids */
+ struct idr_context *idtree_req;
+
+ /* this is the limit of pending requests values for this connection */
+ uint32_t idtree_limit;
+
+ /* list of open tree connects */
+ struct smb2srv_request *list;
+ } requests2;
struct smb_signing_context signing;
-
+
struct stream_connection *connection;
/* this holds a partially received request */
enum security_types security;
BOOL nt_status_support;
} config;
+
+ /* some statictics for the management tools */
+ struct {
+ /* the time when the client connects */
+ struct timeval connect_time;
+ /* the time when the last request comes in */
+ struct timeval last_request_time;
+ } statistics;
+
+ struct share_context *share_context;
};
#include "smb_server/smb_server_proto.h"
#include "smb_server/smb/smb_proto.h"
+
+/* useful way of catching wct errors with file and line number */
+#define SMBSRV_CHECK_WCT(req, wcount) do { \
+ if ((req)->in.wct != (wcount)) { \
+ DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", \
+ (req)->in.wct, __FILE__, __LINE__, wcount)); \
+ smbsrv_send_error(req, NT_STATUS_DOS(ERRSRV, ERRerror)); \
+ return; \
+ } \
+} while (0)
+
+/* useful wrapper for talloc with NO_MEMORY reply */
+#define SMBSRV_TALLOC_IO_PTR(ptr, type) do { \
+ ptr = talloc(req, type); \
+ if (!ptr) { \
+ smbsrv_send_error(req, NT_STATUS_NO_MEMORY); \
+ return; \
+ } \
+ req->io_ptr = ptr; \
+} while (0)
+
+#define SMBSRV_SETUP_NTVFS_REQUEST(send_fn, state) do { \
+ req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req, \
+ req->session->session_info,\
+ SVAL(req->in.hdr,HDR_PID), \
+ req->request_time, \
+ req, send_fn, state); \
+ if (!req->ntvfs) { \
+ smbsrv_send_error(req, NT_STATUS_NO_MEMORY); \
+ return; \
+ } \
+ (void)talloc_steal(req->tcon->ntvfs, req); \
+ req->ntvfs->frontend_data.private_data = req; \
+} while (0)
+
+#define SMBSRV_CHECK_FILE_HANDLE(handle) do { \
+ if (!handle) { \
+ smbsrv_send_error(req, NT_STATUS_INVALID_HANDLE); \
+ return; \
+ } \
+} while (0)
+
+#define SMBSRV_CHECK_FILE_HANDLE_ERROR(handle, _status) do { \
+ if (!handle) { \
+ smbsrv_send_error(req, _status); \
+ return; \
+ } \
+} while (0)
+
+#define SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(handle) do { \
+ if (!handle) { \
+ return NT_STATUS_INVALID_HANDLE; \
+ } \
+} while (0)
+
+#define SMBSRV_CHECK(cmd) do {\
+ NTSTATUS _status; \
+ _status = cmd; \
+ if (!NT_STATUS_IS_OK(_status)) { \
+ smbsrv_send_error(req, _status); \
+ return; \
+ } \
+} while (0)
+
+/*
+ check if the backend wants to handle the request asynchronously.
+ if it wants it handled synchronously then call the send function
+ immediately
+*/
+#define SMBSRV_CALL_NTVFS_BACKEND(cmd) do { \
+ req->ntvfs->async_states->status = cmd; \
+ if (req->ntvfs->async_states->state & NTVFS_ASYNC_STATE_ASYNC) { \
+ DLIST_ADD_END(req->smb_conn->requests, req, struct smbsrv_request *); \
+ } else { \
+ req->ntvfs->async_states->send_fn(req->ntvfs); \
+ } \
+} while (0)
+
+/* check req->ntvfs->async_states->status and if not OK then send an error reply */
+#define SMBSRV_CHECK_ASYNC_STATUS_ERR_SIMPLE do { \
+ req = talloc_get_type(ntvfs->async_states->private_data, struct smbsrv_request); \
+ if (NT_STATUS_IS_ERR(ntvfs->async_states->status)) { \
+ smbsrv_send_error(req, ntvfs->async_states->status); \
+ return; \
+ } \
+} while (0)
+#define SMBSRV_CHECK_ASYNC_STATUS_ERR(ptr, type) do { \
+ SMBSRV_CHECK_ASYNC_STATUS_ERR_SIMPLE; \
+ ptr = talloc_get_type(req->io_ptr, type); \
+} while (0)
+#define SMBSRV_CHECK_ASYNC_STATUS_SIMPLE do { \
+ req = talloc_get_type(ntvfs->async_states->private_data, struct smbsrv_request); \
+ if (!NT_STATUS_IS_OK(ntvfs->async_states->status)) { \
+ smbsrv_send_error(req, ntvfs->async_states->status); \
+ return; \
+ } \
+} while (0)
+#define SMBSRV_CHECK_ASYNC_STATUS(ptr, type) do { \
+ SMBSRV_CHECK_ASYNC_STATUS_SIMPLE; \
+ ptr = talloc_get_type(req->io_ptr, type); \
+} while (0)
+
+/* zero out some reserved fields in a reply */
+#define SMBSRV_VWV_RESERVED(start, count) memset(req->out.vwv + VWV(start), 0, (count)*2)