#include "../lib/util/tevent_ntstatus.h"
#include "rpc_server/srv_pipe_hnd.h"
#include "include/ntioctl.h"
+#include "../librpc/ndr/libndr.h"
static struct tevent_req *smbd_smb2_ioctl_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
uint32_t in_flags);
static NTSTATUS smbd_smb2_ioctl_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
- DATA_BLOB *out_output);
+ DATA_BLOB *out_output,
+ bool *disconnect);
static void smbd_smb2_request_ioctl_done(struct tevent_req *subreq);
NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req)
}
subreq = smbd_smb2_ioctl_send(req,
- req->sconn->smb2.event_ctx,
+ req->sconn->ev_ctx,
req,
in_ctl_code,
in_file_id_volatile,
}
tevent_req_set_callback(subreq, smbd_smb2_request_ioctl_done, req);
- return smbd_smb2_request_pending_queue(req, subreq, 500);
+ return smbd_smb2_request_pending_queue(req, subreq, 1000);
}
static void smbd_smb2_request_ioctl_done(struct tevent_req *subreq)
struct smbd_smb2_request);
const uint8_t *inbody;
int i = req->current_idx;
- uint8_t *outhdr;
DATA_BLOB outbody;
DATA_BLOB outdyn;
uint32_t in_ctl_code;
DATA_BLOB out_output_buffer = data_blob_null;
NTSTATUS status;
NTSTATUS error; /* transport error */
+ bool disconnect = false;
- status = smbd_smb2_ioctl_recv(subreq, req, &out_output_buffer);
+ status = smbd_smb2_ioctl_recv(subreq, req,
+ &out_output_buffer,
+ &disconnect);
DEBUG(10,("smbd_smb2_request_ioctl_done: smbd_smb2_ioctl_recv returned "
"%u status %s\n",
nt_errstr(status) ));
TALLOC_FREE(subreq);
+ if (disconnect) {
+ error = status;
+ smbd_server_connection_terminate(req->sconn,
+ nt_errstr(error));
+ return;
+ }
+
if (NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) {
/* also ok */
} else if (!NT_STATUS_IS_OK(status)) {
in_file_id_persistent = BVAL(inbody, 0x08);
in_file_id_volatile = BVAL(inbody, 0x10);
- outhdr = (uint8_t *)req->out.vector[i].iov_base;
-
outbody = data_blob_talloc(req->out.vector, NULL, 0x30);
if (outbody.data == NULL) {
error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
DATA_BLOB in_input;
uint32_t in_max_output;
DATA_BLOB out_output;
+ bool disconnect;
};
static void smbd_smb2_ioctl_pipe_write_done(struct tevent_req *subreq);
req);
return req;
- case 0x00144064: /* FSCTL_SRV_ENUMERATE_SNAPSHOTS */
+ case FSCTL_VALIDATE_NEGOTIATE_INFO_224:
{
- /*
- * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
- * and return their volume names. If max_data_count is 16, then it is just
- * asking for the number of volumes and length of the combined names.
- *
- * pdata is the data allocated by our caller, but that uses
- * total_data_count (which is 0 in our case) rather than max_data_count.
- * Allocate the correct amount and return the pointer to let
- * it be deallocated when we return.
- */
- struct shadow_copy_data *shadow_data = NULL;
- bool labels = False;
- uint32_t labels_data_count = 0;
- uint32_t data_count;
- uint32_t i;
- char *pdata;
+ struct smbXsrv_connection *conn = smbreq->sconn->conn;
+ uint32_t in_capabilities;
+ DATA_BLOB in_guid_blob;
+ struct GUID in_guid;
+ uint16_t in_security_mode;
+ uint16_t in_max_dialect;
+ uint16_t max_dialect;
+ DATA_BLOB out_guid_blob;
NTSTATUS status;
- if (fsp == NULL) {
- tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
+ if (in_input.length != 0x18) {
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}
- if (in_max_output < 16) {
- DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: "
- "in_max_output(%u) < 16 is invalid!\n",
- in_max_output));
- tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ if (in_max_output < 0x18) {
+ tevent_req_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
return tevent_req_post(req, ev);
}
- if (in_max_output > 16) {
- labels = True;
+ in_capabilities = IVAL(in_input.data, 0x00);
+ in_guid_blob = data_blob_const(in_input.data + 0x04, 16);
+ in_security_mode = SVAL(in_input.data, 0x14);
+ in_max_dialect = SVAL(in_input.data, 0x16);
+
+ status = GUID_from_ndr_blob(&in_guid_blob, &in_guid);
+ if (tevent_req_nterror(req, status)) {
+ return tevent_req_post(req, ev);
}
- shadow_data = talloc_zero(talloc_tos(),
- struct shadow_copy_data);
- if (tevent_req_nomem(shadow_data, req)) {
- DEBUG(0,("TALLOC_ZERO() failed!\n"));
+ max_dialect = conn->smb2.client.dialects[conn->smb2.client.num_dialects-1];
+ if (in_max_dialect != max_dialect) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return tevent_req_post(req, ev);
}
- /*
- * Call the VFS routine to actually do the work.
- */
- if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)
- != 0) {
- if (errno == ENOSYS) {
- DEBUG(5, ("FSCTL_GET_SHADOW_COPY_DATA: "
- "connectpath %s, not supported.\n",
- smbreq->conn->connectpath));
- status = NT_STATUS_NOT_SUPPORTED;
- } else {
- DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: "
- "connectpath %s, failed.\n",
- smbreq->conn->connectpath));
- status = map_nt_error_from_unix(errno);
- }
- TALLOC_FREE(shadow_data);
- tevent_req_nterror(req, status);
+ if (!GUID_compare(&in_guid, &conn->smb2.client.guid)) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return tevent_req_post(req, ev);
}
- labels_data_count =
- (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))
- + 2;
+ if (in_security_mode != conn->smb2.client.security_mode) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
+ }
- if (labels) {
- data_count = 12+labels_data_count+4;
- } else {
- data_count = 16;
+ if (in_capabilities != conn->smb2.client.capabilities) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
}
- if (labels && (in_max_output < data_count)) {
- DEBUG(0, ("FSCTL_GET_SHADOW_COPY_DATA: "
- "in_max_output(%u) too small (%u) bytes "
- "needed!\n", in_max_output, data_count));
- TALLOC_FREE(shadow_data);
- tevent_req_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
+ status = GUID_to_ndr_blob(&conn->smb2.server.guid, state,
+ &out_guid_blob);
+ if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
}
- state->out_output = data_blob_talloc(state, NULL, data_count);
+ state->out_output = data_blob_talloc(state, NULL, 0x18);
if (tevent_req_nomem(state->out_output.data, req)) {
return tevent_req_post(req, ev);
}
- pdata = (char *)state->out_output.data;
+ SIVAL(state->out_output.data, 0x00, conn->smb2.server.capabilities);
+ memcpy(state->out_output.data+0x04, out_guid_blob.data, 16);
+ SIVAL(state->out_output.data, 0x14, conn->smb2.server.security_mode);
+ SIVAL(state->out_output.data, 0x16, conn->smb2.server.dialect);
+
+ tevent_req_done(req);
+ return tevent_req_post(req, ev);
+ }
+
+ case FSCTL_VALIDATE_NEGOTIATE_INFO:
+ {
+ struct smbXsrv_connection *conn = smbreq->sconn->conn;
+ uint32_t in_capabilities;
+ DATA_BLOB in_guid_blob;
+ struct GUID in_guid;
+ uint16_t in_security_mode;
+ uint16_t in_num_dialects;
+ uint16_t i;
+ DATA_BLOB out_guid_blob;
+ NTSTATUS status;
- /* num_volumes 4 bytes */
- SIVAL(pdata, 0, shadow_data->num_volumes);
+ if (in_input.length < 0x18) {
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return tevent_req_post(req, ev);
+ }
+
+ in_capabilities = IVAL(in_input.data, 0x00);
+ in_guid_blob = data_blob_const(in_input.data + 0x04, 16);
+ in_security_mode = SVAL(in_input.data, 0x14);
+ in_num_dialects = SVAL(in_input.data, 0x16);
+
+ if (in_input.length != (0x18 + in_num_dialects*2)) {
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return tevent_req_post(req, ev);
+ }
+
+ if (in_max_output < 0x18) {
+ tevent_req_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
+ return tevent_req_post(req, ev);
+ }
- if (labels) {
- /* num_labels 4 bytes */
- SIVAL(pdata, 4, shadow_data->num_volumes);
+ status = GUID_from_ndr_blob(&in_guid_blob, &in_guid);
+ if (tevent_req_nterror(req, status)) {
+ return tevent_req_post(req, ev);
}
- /* needed_data_count 4 bytes */
- SIVAL(pdata, 8, labels_data_count+4);
+ if (in_num_dialects != conn->smb2.client.num_dialects) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
+ }
- pdata += 12;
+ for (i=0; i < in_num_dialects; i++) {
+ uint16_t v = SVAL(in_input.data, 0x18 + i*2);
- DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for "
- "path[%s].\n",
- shadow_data->num_volumes, fsp_str_dbg(fsp)));
- if (labels && shadow_data->labels) {
- for (i=0; i<shadow_data->num_volumes; i++) {
- srvstr_push(pdata, smbreq->flags2,
- pdata, shadow_data->labels[i],
- 2*sizeof(SHADOW_COPY_LABEL),
- STR_UNICODE|STR_TERMINATE);
- pdata += 2*sizeof(SHADOW_COPY_LABEL);
- DEBUGADD(10, ("Label[%u]: '%s'\n", i,
- shadow_data->labels[i]));
+ if (conn->smb2.client.dialects[i] != v) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
}
}
- TALLOC_FREE(shadow_data);
+ if (!GUID_compare(&in_guid, &conn->smb2.client.guid)) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
+ }
+
+ if (in_security_mode != conn->smb2.client.security_mode) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
+ }
+
+ if (in_capabilities != conn->smb2.client.capabilities) {
+ state->disconnect = true;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
+ }
+
+ status = GUID_to_ndr_blob(&conn->smb2.server.guid, state,
+ &out_guid_blob);
+ if (tevent_req_nterror(req, status)) {
+ return tevent_req_post(req, ev);
+ }
+
+ state->out_output = data_blob_talloc(state, NULL, 0x18);
+ if (tevent_req_nomem(state->out_output.data, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ SIVAL(state->out_output.data, 0x00, conn->smb2.server.capabilities);
+ memcpy(state->out_output.data+0x04, out_guid_blob.data, 16);
+ SIVAL(state->out_output.data, 0x14, conn->smb2.server.security_mode);
+ SIVAL(state->out_output.data, 0x16, conn->smb2.server.dialect);
tevent_req_done(req);
return tevent_req_post(req, ev);
- }
+ }
- default:
- if (IS_IPC(smbreq->conn)) {
- tevent_req_nterror(req, NT_STATUS_FS_DRIVER_REQUIRED);
+ default: {
+ uint8_t *out_data = NULL;
+ uint32_t out_data_len = 0;
+ NTSTATUS status;
+
+ if (fsp == NULL) {
+ tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
return tevent_req_post(req, ev);
}
- tevent_req_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST);
+
+ status = SMB_VFS_FSCTL(fsp,
+ state,
+ in_ctl_code,
+ smbreq->flags2,
+ in_input.data,
+ in_input.length,
+ &out_data,
+ in_max_output,
+ &out_data_len);
+ state->out_output = data_blob_const(out_data, out_data_len);
+ if (NT_STATUS_IS_OK(status)) {
+ tevent_req_done(req);
+ return tevent_req_post(req, ev);
+ }
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
+ if (IS_IPC(smbreq->conn)) {
+ status = NT_STATUS_FS_DRIVER_REQUIRED;
+ } else {
+ status = NT_STATUS_INVALID_DEVICE_REQUEST;
+ }
+ }
+
+ tevent_req_nterror(req, status);
return tevent_req_post(req, ev);
}
+ }
tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
return tevent_req_post(req, ev);
TALLOC_FREE(subreq);
subreq = np_read_send(state->smbreq->conn,
- state->smb2req->sconn->smb2.event_ctx,
+ state->smb2req->sconn->ev_ctx,
state->fsp->fake_file_handle,
state->out_output.data,
state->out_output.length);
static NTSTATUS smbd_smb2_ioctl_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
- DATA_BLOB *out_output)
+ DATA_BLOB *out_output,
+ bool *disconnect)
{
NTSTATUS status = NT_STATUS_OK;
struct smbd_smb2_ioctl_state *state = tevent_req_data(req,
struct smbd_smb2_ioctl_state);
+ *disconnect = state->disconnect;
+
if (tevent_req_is_nterror(req, &status)) {
if (!NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) {
tevent_req_received(req);