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
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
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 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "libcli/smb2/smb2_calls.h"
#include "libcli/raw/ioctl.h"
#include "librpc/rpc/dcerpc.h"
+#include "librpc/rpc/dcerpc_proto.h"
/* transport private information used by SMB2 pipe transport */
struct smb2_private {
struct smb2_handle handle;
struct smb2_tree *tree;
const char *server_name;
+ bool dead;
};
*/
static void pipe_dead(struct dcerpc_connection *c, NTSTATUS status)
{
- c->transport.recv_data(c, NULL, status);
+ struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
+
+ if (smb->dead) {
+ return;
+ }
+
+ smb->dead = true;
+
+ if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) {
+ status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
+ }
+
+ if (NT_STATUS_EQUAL(NT_STATUS_OK, status)) {
+ status = NT_STATUS_END_OF_FILE;
+ }
+
+ if (c->transport.recv_data) {
+ c->transport.recv_data(c, NULL, status);
+ }
}
uint16_t frag_length;
NTSTATUS status;
- state = talloc_get_type(req->async.private, struct smb2_read_state);
- smb = talloc_get_type(state->c->transport.private, struct smb2_private);
+ state = talloc_get_type(req->async.private_data, struct smb2_read_state);
+ smb = talloc_get_type(state->c->transport.private_data, struct smb2_private);
status = smb2_read_recv(req, state, &io);
if (NT_STATUS_IS_ERR(status)) {
return;
}
- status = data_blob_append(state, &state->data,
- io.out.data.data, io.out.data.length);
- if (NT_STATUS_IS_ERR(status)) {
- pipe_dead(state->c, status);
+ if (!data_blob_append(state, &state->data,
+ io.out.data.data, io.out.data.length)) {
+ pipe_dead(state->c, NT_STATUS_NO_MEMORY);
talloc_free(state);
return;
}
}
req->async.fn = smb2_read_callback;
- req->async.private = state;
+ req->async.private_data = state;
}
*/
static NTSTATUS send_read_request_continue(struct dcerpc_connection *c, DATA_BLOB *blob)
{
- struct smb2_private *smb = c->transport.private;
+ struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
struct smb2_read io;
struct smb2_read_state *state;
struct smb2_request *req;
}
req->async.fn = smb2_read_callback;
- req->async.private = state;
+ req->async.private_data = state;
return NT_STATUS_OK;
}
*/
static NTSTATUS send_read_request(struct dcerpc_connection *c)
{
+ struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
+
+ if (smb->dead) {
+ return NT_STATUS_CONNECTION_DISCONNECTED;
+ }
+
return send_read_request_continue(c, NULL);
}
*/
static void smb2_trans_callback(struct smb2_request *req)
{
- struct smb2_trans_state *state = talloc_get_type(req->async.private,
+ struct smb2_trans_state *state = talloc_get_type(req->async.private_data,
struct smb2_trans_state);
struct dcerpc_connection *c = state->c;
NTSTATUS status;
*/
static NTSTATUS smb2_send_trans_request(struct dcerpc_connection *c, DATA_BLOB *blob)
{
- struct smb2_private *smb = talloc_get_type(c->transport.private,
+ struct smb2_private *smb = talloc_get_type(c->transport.private_data,
struct smb2_private);
struct smb2_ioctl io;
struct smb2_trans_state *state;
}
req->async.fn = smb2_trans_callback;
- req->async.private = state;
+ req->async.private_data = state;
talloc_steal(state, req);
*/
static void smb2_write_callback(struct smb2_request *req)
{
- struct dcerpc_connection *c = req->async.private;
+ struct dcerpc_connection *c = (struct dcerpc_connection *)req->async.private_data;
if (!NT_STATUS_IS_OK(req->status)) {
DEBUG(0,("dcerpc_smb2: write callback error\n"));
send a packet to the server
*/
static NTSTATUS smb2_send_request(struct dcerpc_connection *c, DATA_BLOB *blob,
- BOOL trigger_read)
+ bool trigger_read)
{
- struct smb2_private *smb = c->transport.private;
+ struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
struct smb2_write io;
struct smb2_request *req;
+ if (smb->dead) {
+ return NT_STATUS_CONNECTION_DISCONNECTED;
+ }
+
if (trigger_read) {
return smb2_send_trans_request(c, blob);
}
}
req->async.fn = smb2_write_callback;
- req->async.private = c;
+ req->async.private_data = c;
return NT_STATUS_OK;
}
/*
shutdown SMB pipe connection
*/
-static NTSTATUS smb2_shutdown_pipe(struct dcerpc_connection *c)
+static NTSTATUS smb2_shutdown_pipe(struct dcerpc_connection *c, NTSTATUS status)
{
- struct smb2_private *smb = c->transport.private;
+ struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
struct smb2_close io;
struct smb2_request *req;
/* maybe we're still starting up */
- if (!smb) return NT_STATUS_OK;
+ if (!smb) return status;
ZERO_STRUCT(io);
io.in.file.handle = smb->handle;
talloc_free(smb);
- return NT_STATUS_OK;
+ return status;
}
/*
*/
static const char *smb2_peer_name(struct dcerpc_connection *c)
{
- struct smb2_private *smb = talloc_get_type(c->transport.private,
+ struct smb2_private *smb = talloc_get_type(c->transport.private_data,
struct smb2_private);
return smb->server_name;
}
*/
static const char *smb2_target_hostname(struct dcerpc_connection *c)
{
- struct smb2_private *smb = talloc_get_type(c->transport.private,
+ struct smb2_private *smb = talloc_get_type(c->transport.private_data,
struct smb2_private);
return smb->tree->session->transport->socket->hostname;
}
*/
static NTSTATUS smb2_session_key(struct dcerpc_connection *c, DATA_BLOB *session_key)
{
- struct smb2_private *smb = talloc_get_type(c->transport.private,
+ struct smb2_private *smb = talloc_get_type(c->transport.private_data,
struct smb2_private);
*session_key = smb->tree->session->session_key;
if (session_key->data == NULL) {
static void pipe_open_recv(struct smb2_request *req);
-struct composite_context *dcerpc_pipe_open_smb2_send(struct dcerpc_connection *c,
+struct composite_context *dcerpc_pipe_open_smb2_send(struct dcerpc_pipe *p,
struct smb2_tree *tree,
const char *pipe_name)
{
struct pipe_open_smb2_state *state;
struct smb2_create io;
struct smb2_request *req;
+ struct dcerpc_connection *c = p->conn;
ctx = composite_create(c, c->event_ctx);
if (ctx == NULL) return NULL;
state->ctx = ctx;
ZERO_STRUCT(io);
- io.in.access_mask =
+ io.in.desired_access =
SEC_STD_READ_CONTROL |
SEC_FILE_READ_ATTRIBUTE |
SEC_FILE_WRITE_ATTRIBUTE |
io.in.share_access =
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE;
- io.in.open_disposition = NTCREATEX_DISP_OPEN;
+ io.in.create_disposition = NTCREATEX_DISP_OPEN;
io.in.create_options =
NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
NTCREATEX_OPTIONS_UNKNOWN_400000;
- io.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
+ io.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
if ((strncasecmp(pipe_name, "/pipe/", 6) == 0) ||
(strncasecmp(pipe_name, "\\pipe\\", 6) == 0)) {
static void pipe_open_recv(struct smb2_request *req)
{
struct pipe_open_smb2_state *state =
- talloc_get_type(req->async.private,
+ talloc_get_type(req->async.private_data,
struct pipe_open_smb2_state);
struct composite_context *ctx = state->ctx;
struct dcerpc_connection *c = state->c;
fill in the transport methods
*/
c->transport.transport = NCACN_NP;
- c->transport.private = NULL;
+ c->transport.private_data = NULL;
c->transport.shutdown_pipe = smb2_shutdown_pipe;
c->transport.peer_name = smb2_peer_name;
c->transport.target_hostname = smb2_target_hostname;
smb->server_name= strupper_talloc(smb,
tree->session->transport->socket->hostname);
if (composite_nomem(smb->server_name, ctx)) return;
+ smb->dead = false;
- c->transport.private = smb;
+ c->transport.private_data = smb;
composite_done(ctx);
}
return status;
}
-NTSTATUS dcerpc_pipe_open_smb2(struct dcerpc_connection *c,
+NTSTATUS dcerpc_pipe_open_smb2(struct dcerpc_pipe *p,
struct smb2_tree *tree,
const char *pipe_name)
{
- struct composite_context *ctx = dcerpc_pipe_open_smb2_send(c, tree, pipe_name);
+ struct composite_context *ctx = dcerpc_pipe_open_smb2_send(p, tree, pipe_name);
return dcerpc_pipe_open_smb2_recv(ctx);
}
*/
struct smb2_tree *dcerpc_smb2_tree(struct dcerpc_connection *c)
{
- struct smb2_private *smb = talloc_get_type(c->transport.private,
+ struct smb2_private *smb = talloc_get_type(c->transport.private_data,
struct smb2_private);
return smb->tree;
}