Refactoring: Add the routine cli_request_send()
authorVolker Lendecke <vl@samba.org>
Fri, 1 Aug 2008 21:14:51 +0000 (23:14 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 28 Aug 2008 15:53:36 +0000 (17:53 +0200)
cli_request_send() is supposed to bundle all generic SMB-header handling. This
makes cli_request_new static to async_smb.c.
(This used to be commit 7e73dd4e7622db64d30d48ba106892e0895fc188)

source3/include/async_smb.h
source3/include/proto.h
source3/libsmb/async_smb.c
source3/libsmb/clireadwrite.c

index 19408be74b4c324bfc7ca8d78bd0f0b167f7db3b..5ec6b12050a3bef32f5641cf21b63c09a4e15ed7 100644 (file)
 #include "includes.h"
 
 /*
- * Create a fresh async smb request
+ * Ship a new smb request to the server
  */
 
-struct async_req *cli_request_new(TALLOC_CTX *mem_ctx,
-                                 struct event_context *ev,
-                                 struct cli_state *cli,
-                                 uint8_t num_words, size_t num_bytes,
-                                 struct cli_request **preq);
+struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, struct cli_state *cli,
+                                  uint8_t smb_command,
+                                  uint8_t additional_flags,
+                                  uint8_t wct, const uint16_t *vwv,
+                                  uint16_t num_bytes, const uint8_t *bytes);
 
 /*
  * Convenience function to get the SMB part out of an async_req
index d5e942a6d7143561afec442d2ec10a196b9bbb82..0e691d9062175ece1559287b9886d7bac7996998 100644 (file)
@@ -4201,21 +4201,6 @@ bool asn1_write_enumerated(ASN1_DATA *data, uint8 v);
 bool ber_write_OID_String(DATA_BLOB *blob, const char *OID);
 bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID);
 
-/* The following definitions come from libsmb/async_smb.c  */
-
-NTSTATUS cli_pull_error(char *buf);
-void cli_set_error(struct cli_state *cli, NTSTATUS status);
-struct async_req *cli_request_new(TALLOC_CTX *mem_ctx,
-                                 struct event_context *ev,
-                                 struct cli_state *cli,
-                                 uint8_t num_words, size_t num_bytes,
-                                 struct cli_request **preq);
-struct cli_request *cli_request_get(struct async_req *req);
-struct cli_tmp_event *cli_tmp_event_ctx(TALLOC_CTX *mem_ctx,
-                                       struct cli_state *cli);
-NTSTATUS cli_add_event_ctx(struct cli_state *cli,
-                          struct event_context *event_ctx);
-
 /* The following definitions come from libsmb/cliconnect.c  */
 
 ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user, 
index 58bba2bfc703d130686442bdaf1980ed5a0a794a..454bd8169bd1f0def98c95d4e6ec1b4b26b2df1c 100644 (file)
@@ -114,11 +114,11 @@ static int cli_request_destructor(struct cli_request *req)
  * Create a fresh async smb request
  */
 
-struct async_req *cli_request_new(TALLOC_CTX *mem_ctx,
-                                 struct event_context *ev,
-                                 struct cli_state *cli,
-                                 uint8_t num_words, size_t num_bytes,
-                                 struct cli_request **preq)
+static struct async_req *cli_request_new(TALLOC_CTX *mem_ctx,
+                                        struct event_context *ev,
+                                        struct cli_state *cli,
+                                        uint8_t num_words, size_t num_bytes,
+                                        struct cli_request **preq)
 {
        struct async_req *result;
        struct cli_request *cli_req;
@@ -160,6 +160,58 @@ struct async_req *cli_request_new(TALLOC_CTX *mem_ctx,
        return result;
 }
 
+/*
+ * Ship a new smb request to the server
+ */
+struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, struct cli_state *cli,
+                                  uint8_t smb_command,
+                                  uint8_t additional_flags,
+                                  uint8_t wct, const uint16_t *vwv,
+                                  uint16_t num_bytes, const uint8_t *bytes)
+{
+       struct async_req *result;
+       struct cli_request *req;
+
+       result = cli_request_new(mem_ctx, cli->event_ctx, cli, wct, num_bytes,
+                                &req);
+       if (result == NULL) {
+               DEBUG(0, ("cli_request_new failed\n"));
+               return NULL;
+       }
+
+       cli_set_message(req->outbuf, wct, num_bytes, false);
+       SCVAL(req->outbuf, smb_com, smb_command);
+       SSVAL(req->outbuf, smb_tid, cli->cnum);
+       cli_setup_packet_buf(cli, req->outbuf);
+
+       memcpy(req->outbuf + smb_vwv0, vwv, sizeof(uint16_t) * wct);
+       memcpy(smb_buf(req->outbuf), bytes, num_bytes);
+       SSVAL(req->outbuf, smb_mid, req->mid);
+       SCVAL(cli->outbuf, smb_flg,
+             CVAL(cli->outbuf,smb_flg) | additional_flags);
+
+       cli_calculate_sign_mac(cli, req->outbuf);
+
+       if (cli_encryption_on(cli)) {
+               NTSTATUS status;
+               char *enc_buf;
+
+               status = cli_encrypt_message(cli, req->outbuf, &enc_buf);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("Error in encrypting client message. "
+                                 "Error %s\n", nt_errstr(status)));
+                       TALLOC_FREE(req);
+                       return NULL;
+               }
+               req->outbuf = enc_buf;
+               req->enc_state = cli->trans_enc_state;
+       }
+
+       event_fd_set_writeable(cli->fd_event);
+
+       return result;
+}
+
 /*
  * Convenience function to get the SMB part out of an async_req
  */
index a57f1e07857e19f3937ad51b9bbfed7c63bbc47f..2b34fce5bd61eb30e8b8f55847f0179a38423a5c 100644 (file)
@@ -47,7 +47,9 @@ struct async_req *cli_read_andx_send(TALLOC_CTX *mem_ctx,
        struct async_req *result;
        struct cli_request *req;
        bool bigoffset = False;
-       char *enc_buf;
+
+       uint16_t vwv[12];
+       uint8_t wct = 10;
 
        if (size > cli_read_max_bufsize(cli)) {
                DEBUG(0, ("cli_read_andx_send got size=%d, can only handle "
@@ -56,60 +58,37 @@ struct async_req *cli_read_andx_send(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       result = cli_request_new(mem_ctx, cli->event_ctx, cli, 12, 0, &req);
+       SCVAL(vwv + 0, 0, 0xFF);
+       SCVAL(vwv + 0, 1, 0);
+       SSVAL(vwv + 1, 0, 0);
+       SSVAL(vwv + 2, 0, fnum);
+       SIVAL(vwv + 3, 0, offset);
+       SSVAL(vwv + 5, 0, size);
+       SSVAL(vwv + 6, 0, size);
+       SSVAL(vwv + 7, 0, (size >> 16));
+       SSVAL(vwv + 8, 0, 0);
+       SSVAL(vwv + 9, 0, 0);
+
+       if ((SMB_BIG_UINT)offset >> 32) {
+               bigoffset = True;
+               SIVAL(vwv + 10, 0,
+                     (((SMB_BIG_UINT)offset)>>32) & 0xffffffff);
+               wct += 2;
+       }
+
+       result = cli_request_send(mem_ctx, cli, SMBreadX, 0, wct, vwv,
+                                 0, NULL);
        if (result == NULL) {
-               DEBUG(0, ("cli_request_new failed\n"));
                return NULL;
        }
 
+       req = cli_request_get(result);
+
        req->data.read.ofs = offset;
        req->data.read.size = size;
        req->data.read.received = 0;
        req->data.read.rcvbuf = NULL;
 
-       if ((SMB_BIG_UINT)offset >> 32)
-               bigoffset = True;
-
-       cli_set_message(req->outbuf, bigoffset ? 12 : 10, 0, False);
-
-       SCVAL(req->outbuf,smb_com,SMBreadX);
-       SSVAL(req->outbuf,smb_tid,cli->cnum);
-       cli_setup_packet_buf(cli, req->outbuf);
-
-       SCVAL(req->outbuf,smb_vwv0,0xFF);
-       SCVAL(req->outbuf,smb_vwv0+1,0);
-       SSVAL(req->outbuf,smb_vwv1,0);
-       SSVAL(req->outbuf,smb_vwv2,fnum);
-       SIVAL(req->outbuf,smb_vwv3,offset);
-       SSVAL(req->outbuf,smb_vwv5,size);
-       SSVAL(req->outbuf,smb_vwv6,size);
-       SSVAL(req->outbuf,smb_vwv7,(size >> 16));
-       SSVAL(req->outbuf,smb_vwv8,0);
-       SSVAL(req->outbuf,smb_vwv9,0);
-       SSVAL(req->outbuf,smb_mid,req->mid);
-
-       if (bigoffset) {
-               SIVAL(req->outbuf, smb_vwv10,
-                     (((SMB_BIG_UINT)offset)>>32) & 0xffffffff);
-       }
-
-       cli_calculate_sign_mac(cli, req->outbuf);
-
-       event_fd_set_writeable(cli->fd_event);
-
-       if (cli_encryption_on(cli)) {
-               NTSTATUS status;
-               status = cli_encrypt_message(cli, req->outbuf, &enc_buf);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0, ("Error in encrypting client message. "
-                                 "Error %s\n", nt_errstr(status)));
-                       TALLOC_FREE(req);
-                       return NULL;
-               }
-               req->outbuf = enc_buf;
-               req->enc_state = cli->trans_enc_state;
-       }
-
        return result;
 }