2
Unix SMB2 implementation.
4
Copyright (C) Stefan Metzmacher 2005
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
/* the context for a single SMB2 request. This is passed to any request-context
22
struct smb2srv_request {
23
/* the smbsrv_connection needs a list of requests queued for send */
24
struct smb2srv_request *next, *prev;
26
/* the server_context contains all context specific to this SMB socket */
27
struct smbsrv_connection *smb_conn;
29
/* conn is only set for operations that have a valid TID */
30
struct smbsrv_tcon *tcon;
32
/* the session context is derived from the vuid */
33
struct smbsrv_session *session;
35
#define SMB2SRV_REQ_CTRL_FLAG_NOT_REPLY (1<<0)
36
uint32_t control_flags;
38
/* the system time when the request arrived */
39
struct timeval request_time;
41
/* a pointer to the per request union smb_* io structure */
44
/* the ntvfs_request */
45
struct ntvfs_request *ntvfs;
47
/* Now the SMB2 specific stuff */
49
/* the status the backend returned */
52
/* for matching request and reply */
55
/* the id that can be used to cancel the request */
58
/* the offset to the next SMB2 Header for chained requests */
59
uint32_t chain_offset;
61
/* chained file handle */
62
uint8_t _chained_file_handle[16];
63
uint8_t *chained_file_handle;
67
struct smb2_request_buffer in;
68
struct smb2_request_buffer out;
71
struct smbsrv_request;
73
#include "smb_server/smb2/smb2_proto.h"
75
/* useful way of catching field size errors with file and line number */
76
#define SMB2SRV_CHECK_BODY_SIZE(req, size, dynamic) do { \
77
size_t is_size = req->in.body_size; \
78
uint16_t field_size; \
79
uint16_t want_size = ((dynamic)?(size)+1:(size)); \
80
if (is_size < (size)) { \
81
DEBUG(0,("%s: buffer too small 0x%x. Expected 0x%x\n", \
82
__location__, (unsigned)is_size, (unsigned)want_size)); \
83
smb2srv_send_error(req, NT_STATUS_INVALID_PARAMETER); \
86
field_size = SVAL(req->in.body, 0); \
87
if (field_size != want_size) { \
88
DEBUG(0,("%s: unexpected fixed body size 0x%x. Expected 0x%x\n", \
89
__location__, (unsigned)field_size, (unsigned)want_size)); \
90
smb2srv_send_error(req, NT_STATUS_INVALID_PARAMETER); \
95
#define SMB2SRV_CHECK(cmd) do {\
98
if (!NT_STATUS_IS_OK(_status)) { \
99
smb2srv_send_error(req, _status); \
104
/* useful wrapper for talloc with NO_MEMORY reply */
105
#define SMB2SRV_TALLOC_IO_PTR(ptr, type) do { \
106
ptr = talloc(req, type); \
108
smb2srv_send_error(req, NT_STATUS_NO_MEMORY); \
114
#define SMB2SRV_SETUP_NTVFS_REQUEST(send_fn, state) do { \
115
req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req, \
116
req->session->session_info,\
119
req, send_fn, state); \
121
smb2srv_send_error(req, NT_STATUS_NO_MEMORY); \
124
(void)talloc_steal(req->tcon->ntvfs, req); \
125
req->ntvfs->frontend_data.private_data = req; \
128
#define SMB2SRV_CHECK_FILE_HANDLE(handle) do { \
130
smb2srv_send_error(req, NT_STATUS_FILE_CLOSED); \
136
check if the backend wants to handle the request asynchronously.
137
if it wants it handled synchronously then call the send function
140
#define SMB2SRV_CALL_NTVFS_BACKEND(cmd) do { \
141
req->ntvfs->async_states->status = cmd; \
142
if (req->ntvfs->async_states->state & NTVFS_ASYNC_STATE_ASYNC) { \
144
_status = smb2srv_queue_pending(req); \
145
if (!NT_STATUS_IS_OK(_status)) { \
146
ntvfs_cancel(req->ntvfs); \
149
req->ntvfs->async_states->send_fn(req->ntvfs); \
153
/* check req->ntvfs->async_states->status and if not OK then send an error reply */
154
#define SMB2SRV_CHECK_ASYNC_STATUS_ERR_SIMPLE do { \
155
req = talloc_get_type(ntvfs->async_states->private_data, struct smb2srv_request); \
156
if (ntvfs->async_states->state & NTVFS_ASYNC_STATE_CLOSE || NT_STATUS_EQUAL(ntvfs->async_states->status, NT_STATUS_NET_WRITE_FAULT)) { \
157
smbsrv_terminate_connection(req->smb_conn, get_friendly_nt_error_msg (ntvfs->async_states->status)); \
161
req->status = ntvfs->async_states->status; \
162
if (NT_STATUS_IS_ERR(ntvfs->async_states->status)) { \
163
smb2srv_send_error(req, ntvfs->async_states->status); \
167
#define SMB2SRV_CHECK_ASYNC_STATUS_ERR(ptr, type) do { \
168
SMB2SRV_CHECK_ASYNC_STATUS_ERR_SIMPLE; \
169
ptr = talloc_get_type(req->io_ptr, type); \
171
#define SMB2SRV_CHECK_ASYNC_STATUS_SIMPLE do { \
172
req = talloc_get_type(ntvfs->async_states->private_data, struct smb2srv_request); \
173
if (ntvfs->async_states->state & NTVFS_ASYNC_STATE_CLOSE || NT_STATUS_EQUAL(ntvfs->async_states->status, NT_STATUS_NET_WRITE_FAULT)) { \
174
smbsrv_terminate_connection(req->smb_conn, get_friendly_nt_error_msg (ntvfs->async_states->status)); \
178
req->status = ntvfs->async_states->status; \
179
if (!NT_STATUS_IS_OK(ntvfs->async_states->status)) { \
180
smb2srv_send_error(req, ntvfs->async_states->status); \
184
#define SMB2SRV_CHECK_ASYNC_STATUS(ptr, type) do { \
185
SMB2SRV_CHECK_ASYNC_STATUS_SIMPLE; \
186
ptr = talloc_get_type(req->io_ptr, type); \