libcli: move ioctl function field defs to smb_constants
[rusty/samba.git] / source4 / librpc / rpc / dcerpc_smb2.c
index 4767165fba8dd62596f9d3689fa763776ec62a48..75fb423df4e6a0c96683e5755abd90c891285c9a 100644 (file)
 #include "libcli/composite/composite.h"
 #include "libcli/smb2/smb2.h"
 #include "libcli/smb2/smb2_calls.h"
-#include "libcli/raw/ioctl.h"
+#include "../libcli/smb/smb_constants.h"
 #include "librpc/rpc/dcerpc.h"
 #include "librpc/rpc/dcerpc_proto.h"
+#include "librpc/rpc/rpc_common.h"
 
 /* transport private information used by SMB2 pipe transport */
 struct smb2_private {
@@ -40,7 +41,7 @@ struct smb2_private {
 /*
   tell the dcerpc layer that the transport is dead
 */
-static void pipe_dead(struct dcerpc_connection *c, NTSTATUS status)
+static void pipe_dead(struct dcecli_connection *c, NTSTATUS status)
 {
        struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
 
@@ -68,7 +69,7 @@ static void pipe_dead(struct dcerpc_connection *c, NTSTATUS status)
    this holds the state of an in-flight call
 */
 struct smb2_read_state {
-       struct dcerpc_connection *c;
+       struct dcecli_connection *c;
        DATA_BLOB data;
 };
 
@@ -77,6 +78,7 @@ struct smb2_read_state {
 */
 static void smb2_read_callback(struct smb2_request *req)
 {
+       struct dcecli_connection *c;
        struct smb2_private *smb;
        struct smb2_read_state *state;
        struct smb2_read io;
@@ -85,26 +87,27 @@ static void smb2_read_callback(struct smb2_request *req)
 
        state = talloc_get_type(req->async.private_data, struct smb2_read_state);
        smb = talloc_get_type(state->c->transport.private_data, struct smb2_private);
+       c = state->c;
 
        status = smb2_read_recv(req, state, &io);
        if (NT_STATUS_IS_ERR(status)) {
-               pipe_dead(state->c, status);
                talloc_free(state);
+               pipe_dead(c, status);
                return;
        }
 
        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);
+               pipe_dead(c, NT_STATUS_NO_MEMORY);
                return;
        }
 
        if (state->data.length < 16) {
                DEBUG(0,("dcerpc_smb2: short packet (length %d) in read callback!\n",
                         (int)state->data.length));
-               pipe_dead(state->c, NT_STATUS_INFO_LENGTH_MISMATCH);
                talloc_free(state);
+               pipe_dead(c, NT_STATUS_INFO_LENGTH_MISMATCH);
                return;
        }
 
@@ -112,7 +115,6 @@ static void smb2_read_callback(struct smb2_request *req)
 
        if (frag_length <= state->data.length) {
                DATA_BLOB data = state->data;
-               struct dcerpc_connection *c = state->c;
                talloc_steal(c, data.data);
                talloc_free(state);
                c->transport.recv_data(c, &data, NT_STATUS_OK);
@@ -130,8 +132,8 @@ static void smb2_read_callback(struct smb2_request *req)
        
        req = smb2_read_send(smb->tree, &io);
        if (req == NULL) {
-               pipe_dead(state->c, NT_STATUS_NO_MEMORY);
                talloc_free(state);
+               pipe_dead(c, NT_STATUS_NO_MEMORY);
                return;
        }
 
@@ -144,14 +146,14 @@ static void smb2_read_callback(struct smb2_request *req)
   trigger a read request from the server, possibly with some initial
   data in the read buffer
 */
-static NTSTATUS send_read_request_continue(struct dcerpc_connection *c, DATA_BLOB *blob)
+static NTSTATUS send_read_request_continue(struct dcecli_connection *c, DATA_BLOB *blob)
 {
        struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
        struct smb2_read io;
        struct smb2_read_state *state;
        struct smb2_request *req;
 
-       state = talloc(smb, struct smb2_read_state);
+       state = talloc(c, struct smb2_read_state);
        if (state == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -189,7 +191,7 @@ static NTSTATUS send_read_request_continue(struct dcerpc_connection *c, DATA_BLO
 /*
   trigger a read request from the server
 */
-static NTSTATUS send_read_request(struct dcerpc_connection *c)
+static NTSTATUS send_read_request(struct dcecli_connection *c)
 {
        struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
 
@@ -204,7 +206,7 @@ static NTSTATUS send_read_request(struct dcerpc_connection *c)
    this holds the state of an in-flight trans call
 */
 struct smb2_trans_state {
-       struct dcerpc_connection *c;
+       struct dcecli_connection *c;
 };
 
 /*
@@ -214,7 +216,7 @@ static void smb2_trans_callback(struct smb2_request *req)
 {
        struct smb2_trans_state *state = talloc_get_type(req->async.private_data,
                                                        struct smb2_trans_state);
-       struct dcerpc_connection *c = state->c;
+       struct dcecli_connection *c = state->c;
        NTSTATUS status;
        struct smb2_ioctl io;
 
@@ -240,7 +242,7 @@ static void smb2_trans_callback(struct smb2_request *req)
 /*
   send a SMBtrans style request, using a named pipe read_write fsctl
 */
-static NTSTATUS smb2_send_trans_request(struct dcerpc_connection *c, DATA_BLOB *blob)
+static NTSTATUS smb2_send_trans_request(struct dcecli_connection *c, DATA_BLOB *blob)
 {
         struct smb2_private *smb = talloc_get_type(c->transport.private_data,
                                                   struct smb2_private);
@@ -258,7 +260,7 @@ static NTSTATUS smb2_send_trans_request(struct dcerpc_connection *c, DATA_BLOB *
        ZERO_STRUCT(io);
        io.in.file.handle       = smb->handle;
        io.in.function          = FSCTL_NAMED_PIPE_READ_WRITE;
-       io.in.max_response_size = 0x1000;
+       io.in.max_response_size = 0x2000;
        io.in.flags             = 1;
        io.in.out               = *blob;
 
@@ -281,7 +283,7 @@ static NTSTATUS smb2_send_trans_request(struct dcerpc_connection *c, DATA_BLOB *
 */
 static void smb2_write_callback(struct smb2_request *req)
 {
-       struct dcerpc_connection *c = (struct dcerpc_connection *)req->async.private_data;
+       struct dcecli_connection *c = (struct dcecli_connection *)req->async.private_data;
 
        if (!NT_STATUS_IS_OK(req->status)) {
                DEBUG(0,("dcerpc_smb2: write callback error\n"));
@@ -294,7 +296,7 @@ static void smb2_write_callback(struct smb2_request *req)
 /* 
    send a packet to the server
 */
-static NTSTATUS smb2_send_request(struct dcerpc_connection *c, DATA_BLOB *blob, 
+static NTSTATUS smb2_send_request(struct dcecli_connection *c, DATA_BLOB *blob, 
                                  bool trigger_read)
 {
        struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
@@ -324,10 +326,15 @@ static NTSTATUS smb2_send_request(struct dcerpc_connection *c, DATA_BLOB *blob,
        return NT_STATUS_OK;
 }
 
+static void free_request(struct smb2_request *req)
+{
+       talloc_free(req);
+}
+
 /* 
    shutdown SMB pipe connection
 */
-static NTSTATUS smb2_shutdown_pipe(struct dcerpc_connection *c, NTSTATUS status)
+static NTSTATUS smb2_shutdown_pipe(struct dcecli_connection *c, NTSTATUS status)
 {
        struct smb2_private *smb = (struct smb2_private *)c->transport.private_data;
        struct smb2_close io;
@@ -341,7 +348,7 @@ static NTSTATUS smb2_shutdown_pipe(struct dcerpc_connection *c, NTSTATUS status)
        req = smb2_close_send(smb->tree, &io);
        if (req != NULL) {
                /* we don't care if this fails, so just free it if it succeeds */
-               req->async.fn = (void (*)(struct smb2_request *))talloc_free;
+               req->async.fn = free_request;
        }
 
        talloc_free(smb);
@@ -352,7 +359,7 @@ static NTSTATUS smb2_shutdown_pipe(struct dcerpc_connection *c, NTSTATUS status)
 /*
   return SMB server name
 */
-static const char *smb2_peer_name(struct dcerpc_connection *c)
+static const char *smb2_peer_name(struct dcecli_connection *c)
 {
        struct smb2_private *smb = talloc_get_type(c->transport.private_data,
                                                   struct smb2_private);
@@ -362,7 +369,7 @@ static const char *smb2_peer_name(struct dcerpc_connection *c)
 /*
   return remote name we make the actual connection (good for kerberos) 
 */
-static const char *smb2_target_hostname(struct dcerpc_connection *c)
+static const char *smb2_target_hostname(struct dcecli_connection *c)
 {
        struct smb2_private *smb = talloc_get_type(c->transport.private_data, 
                                                   struct smb2_private);
@@ -372,7 +379,7 @@ static const char *smb2_target_hostname(struct dcerpc_connection *c)
 /*
   fetch the user session key 
 */
-static NTSTATUS smb2_session_key(struct dcerpc_connection *c, DATA_BLOB *session_key)
+static NTSTATUS smb2_session_key(struct dcecli_connection *c, DATA_BLOB *session_key)
 {
        struct smb2_private *smb = talloc_get_type(c->transport.private_data,
                                                   struct smb2_private);
@@ -384,7 +391,7 @@ static NTSTATUS smb2_session_key(struct dcerpc_connection *c, DATA_BLOB *session
 }
 
 struct pipe_open_smb2_state {
-       struct dcerpc_connection *c;
+       struct dcecli_connection *c;
        struct composite_context *ctx;
 };
 
@@ -398,7 +405,7 @@ struct composite_context *dcerpc_pipe_open_smb2_send(struct dcerpc_pipe *p,
        struct pipe_open_smb2_state *state;
        struct smb2_create io;
        struct smb2_request *req;
-       struct dcerpc_connection *c = p->conn;
+       struct dcecli_connection *c = p->conn;
 
        ctx = composite_create(c, c->event_ctx);
        if (ctx == NULL) return NULL;
@@ -427,7 +434,7 @@ struct composite_context *dcerpc_pipe_open_smb2_send(struct dcerpc_pipe *p,
        io.in.create_disposition = NTCREATEX_DISP_OPEN;
        io.in.create_options   = 
                NTCREATEX_OPTIONS_NON_DIRECTORY_FILE | 
-               NTCREATEX_OPTIONS_UNKNOWN_400000;
+               NTCREATEX_OPTIONS_NO_RECALL;
        io.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
 
        if ((strncasecmp(pipe_name, "/pipe/", 6) == 0) || 
@@ -447,7 +454,7 @@ static void pipe_open_recv(struct smb2_request *req)
                talloc_get_type(req->async.private_data,
                                struct pipe_open_smb2_state);
        struct composite_context *ctx = state->ctx;
-       struct dcerpc_connection *c = state->c;
+       struct dcecli_connection *c = state->c;
        struct smb2_tree *tree = req->tree;
        struct smb2_private *smb;
        struct smb2_create io;
@@ -504,7 +511,7 @@ NTSTATUS dcerpc_pipe_open_smb2(struct dcerpc_pipe *p,
 /*
   return the SMB2 tree used for a dcerpc over SMB2 pipe
 */
-struct smb2_tree *dcerpc_smb2_tree(struct dcerpc_connection *c)
+struct smb2_tree *dcerpc_smb2_tree(struct dcecli_connection *c)
 {
        struct smb2_private *smb = talloc_get_type(c->transport.private_data,
                                                   struct smb2_private);