s3: return proper error code in cli_smb_req_send
authorBo Yang <boyang@samba.org>
Thu, 14 May 2009 02:13:12 +0000 (10:13 +0800)
committerBo Yang <boyang@samba.org>
Wed, 13 May 2009 10:47:00 +0000 (18:47 +0800)
Signed-off-by: Bo Yang <boyang@samba.org>
source3/include/async_smb.h
source3/libsmb/async_smb.c
source3/libsmb/cliconnect.c
source3/libsmb/clifile.c
source3/libsmb/clireadwrite.c
source3/libsmb/clitrans.c

index 87ddca6677679ff4d24497c937e19e86e6baa90d..c27dd2b36f9d61cd42981c1dfe10db9a7c1381c0 100644 (file)
@@ -47,7 +47,7 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx,
                                      uint8_t wct, uint16_t *vwv,
                                      int iov_count,
                                      struct iovec *bytes_iov);
-bool cli_smb_req_send(struct tevent_req *req);
+NTSTATUS cli_smb_req_send(struct tevent_req *req);
 size_t cli_smb_wct_ofs(struct tevent_req **reqs, int num_reqs);
 bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs);
 uint8_t *cli_smb_inbuf(struct tevent_req *req);
index 9fdd14793f1fecf4db047b961623847fd0fb3313..0d82894bdc7afef64e807c7764df7dfaf1691fc2 100644 (file)
@@ -512,8 +512,8 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx,
        return result;
 }
 
-static bool cli_signv(struct cli_state *cli, struct iovec *iov, int count,
-                     uint32_t *seqnum)
+static NTSTATUS cli_signv(struct cli_state *cli, struct iovec *iov, int count,
+                         uint32_t *seqnum)
 {
        uint8_t *buf;
 
@@ -523,31 +523,32 @@ static bool cli_signv(struct cli_state *cli, struct iovec *iov, int count,
         */
 
        if ((count <= 0) || (iov[0].iov_len < smb_wct)) {
-               return false;
+               return NT_STATUS_INVALID_PARAMETER;
        }
 
        buf = iov_concat(talloc_tos(), iov, count);
        if (buf == NULL) {
-               return false;
+               return NT_STATUS_NO_MEMORY;
        }
 
        cli_calculate_sign_mac(cli, (char *)buf, seqnum);
        memcpy(iov[0].iov_base, buf, iov[0].iov_len);
 
        TALLOC_FREE(buf);
-       return true;
+       return NT_STATUS_OK;
 }
 
 static void cli_smb_sent(struct tevent_req *subreq);
 
-static bool cli_smb_req_iov_send(struct tevent_req *req,
-                                struct cli_smb_state *state,
-                                struct iovec *iov, int iov_count)
+static NTSTATUS cli_smb_req_iov_send(struct tevent_req *req,
+                                    struct cli_smb_state *state,
+                                    struct iovec *iov, int iov_count)
 {
        struct tevent_req *subreq;
+       NTSTATUS status;
 
        if (iov[0].iov_len < smb_wct) {
-               return false;
+               return NT_STATUS_INVALID_PARAMETER;
        }
 
        if (state->mid != 0) {
@@ -558,17 +559,18 @@ static bool cli_smb_req_iov_send(struct tevent_req *req,
 
        smb_setlen((char *)iov[0].iov_base, iov_len(iov, iov_count) - 4);
 
-       if (!cli_signv(state->cli, iov, iov_count, &state->seqnum)) {
-               return false;
+       status = cli_signv(state->cli, iov, iov_count, &state->seqnum);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
 
        if (cli_encryption_on(state->cli)) {
-               NTSTATUS status;
                char *buf, *enc_buf;
 
                buf = (char *)iov_concat(talloc_tos(), iov, iov_count);
                if (buf == NULL) {
-                       return false;
+                       return NT_STATUS_NO_MEMORY;
                }
                status = cli_encrypt_message(state->cli, (char *)buf,
                                             &enc_buf);
@@ -576,13 +578,13 @@ static bool cli_smb_req_iov_send(struct tevent_req *req,
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("Error in encrypting client message: %s\n",
                                  nt_errstr(status)));
-                       return false;
+                       return status;
                }
                buf = (char *)talloc_memdup(state, enc_buf,
                                            smb_len(enc_buf)+4);
                SAFE_FREE(enc_buf);
                if (buf == NULL) {
-                       return false;
+                       return NT_STATUS_NO_MEMORY;
                }
                iov[0].iov_base = (void *)buf;
                iov[0].iov_len = talloc_get_size(buf);
@@ -593,19 +595,19 @@ static bool cli_smb_req_iov_send(struct tevent_req *req,
                                     state->cli->fd, iov, iov_count);
        }
        if (subreq == NULL) {
-               return false;
+               return NT_STATUS_NO_MEMORY;
        }
        tevent_req_set_callback(subreq, cli_smb_sent, req);
-       return true;
+       return NT_STATUS_OK;
 }
 
-bool cli_smb_req_send(struct tevent_req *req)
+NTSTATUS cli_smb_req_send(struct tevent_req *req)
 {
        struct cli_smb_state *state = tevent_req_data(
                req, struct cli_smb_state);
 
        if (state->cli->fd == -1) {
-               return false;
+               return NT_STATUS_CONNECTION_DISCONNECTED;
        }
 
        return cli_smb_req_iov_send(req, state, state->iov, state->iov_count);
@@ -622,6 +624,7 @@ struct tevent_req *cli_smb_send(TALLOC_CTX *mem_ctx,
 {
        struct tevent_req *req;
        struct iovec iov;
+       NTSTATUS status;
 
        iov.iov_base = CONST_DISCARD(void *, bytes);
        iov.iov_len = num_bytes;
@@ -631,8 +634,11 @@ struct tevent_req *cli_smb_send(TALLOC_CTX *mem_ctx,
        if (req == NULL) {
                return NULL;
        }
-       if (!cli_smb_req_send(req)) {
-               TALLOC_FREE(req);
+
+       status = cli_smb_req_send(req);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
        }
        return req;
 }
@@ -1033,7 +1039,7 @@ bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
                chain_padding = next_padding;
        }
 
-       if (!cli_smb_req_iov_send(reqs[0], last_state, iov, iovlen)) {
+       if (!NT_STATUS_IS_OK(cli_smb_req_iov_send(reqs[0], last_state, iov, iovlen))) {
                goto fail;
        }
        return true;
index 38985363c2e67846193293e1a8f7ada53daf5922..16c15ce7db96505f3eef1cea76b3475489ae426f 100644 (file)
@@ -238,12 +238,18 @@ struct tevent_req *cli_session_setup_guest_send(TALLOC_CTX *mem_ctx,
                                                struct cli_state *cli)
 {
        struct tevent_req *req, *subreq;
+       NTSTATUS status;
 
        req = cli_session_setup_guest_create(mem_ctx, ev, cli, &subreq);
-       if ((req == NULL) || !cli_smb_req_send(subreq)) {
-               TALLOC_FREE(req);
+       if (req == NULL) {
                return NULL;
        }
+
+       status = cli_smb_req_send(subreq);
+       if (NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
        return req;
 }
 
@@ -1392,13 +1398,18 @@ struct tevent_req *cli_tcon_andx_send(TALLOC_CTX *mem_ctx,
                                      const char *pass, int passlen)
 {
        struct tevent_req *req, *subreq;
+       NTSTATUS status;
 
        req = cli_tcon_andx_create(mem_ctx, ev, cli, share, dev, pass, passlen,
                                   &subreq);
-       if ((req == NULL) || !cli_smb_req_send(subreq)) {
-               TALLOC_FREE(req);
+       if (req == NULL) {
                return NULL;
        }
+       status = cli_smb_req_send(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
        return req;
 }
 
index 63e6c474db66e2342bb462e74f6e1e9b2b273eb4..3c133836698e92ad7b09b451af58c11fff78eddf 100644 (file)
@@ -1484,13 +1484,19 @@ struct tevent_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
                                 int flags, int share_mode)
 {
        struct tevent_req *req, *subreq;
+       NTSTATUS status;
 
        req = cli_open_create(mem_ctx, ev, cli, fname, flags, share_mode,
                              &subreq);
-       if ((req == NULL) || !cli_smb_req_send(subreq)) {
-               TALLOC_FREE(req);
+       if (req == NULL) {
                return NULL;
        }
+
+       status = cli_smb_req_send(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
        return req;
 }
 
@@ -1612,12 +1618,18 @@ struct tevent_req *cli_close_send(TALLOC_CTX *mem_ctx,
                                uint16_t fnum)
 {
        struct tevent_req *req, *subreq;
+       NTSTATUS status;
 
        req = cli_close_create(mem_ctx, ev, cli, fnum, &subreq);
-       if ((req == NULL) || !cli_smb_req_send(subreq)) {
-               TALLOC_FREE(req);
+       if (req == NULL) {
                return NULL;
        }
+
+       status = cli_smb_req_send(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
        return req;
 }
 
index 4e256ede57d2fe16b33bb3621e6648ccea11b6df..d38de1950800d4f4d25ac6b4ef9558b056f9de07 100644 (file)
@@ -139,13 +139,19 @@ struct tevent_req *cli_read_andx_send(TALLOC_CTX *mem_ctx,
                                      off_t offset, size_t size)
 {
        struct tevent_req *req, *subreq;
+       NTSTATUS status;
 
        req = cli_read_andx_create(mem_ctx, ev, cli, fnum, offset, size,
                                   &subreq);
-       if ((req == NULL) || !cli_smb_req_send(subreq)) {
-               TALLOC_FREE(req);
+       if (req == NULL) {
                return NULL;
        }
+
+       status = cli_smb_req_send(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
        return req;
 }
 
@@ -870,13 +876,19 @@ struct tevent_req *cli_write_andx_send(TALLOC_CTX *mem_ctx,
                                       off_t offset, size_t size)
 {
        struct tevent_req *req, *subreq;
+       NTSTATUS status;
 
        req = cli_write_andx_create(mem_ctx, ev, cli, fnum, mode, buf, offset,
                                    size, NULL, 0, &subreq);
-       if ((req == NULL) || !cli_smb_req_send(subreq)) {
-               TALLOC_FREE(req);
+       if (req == NULL) {
                return NULL;
        }
+
+       status = cli_smb_req_send(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
        return req;
 }
 
index d6d78cc6c3ec62cd6adda5bf959fc467a7400f4b..98c09ed6e7346c7ad3c84b1f9d0a644221b37afc 100644 (file)
@@ -1011,6 +1011,7 @@ struct tevent_req *cli_trans_send(
        struct cli_trans_state *state;
        int iov_count;
        uint8_t wct;
+       NTSTATUS status;
 
        req = tevent_req_create(mem_ctx, &state, struct cli_trans_state);
        if (req == NULL) {
@@ -1083,8 +1084,9 @@ struct tevent_req *cli_trans_send(
                return tevent_req_post(req, ev);
        }
        state->mid = cli_smb_req_mid(subreq);
-       if (!cli_smb_req_send(subreq)) {
-               tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+       status = cli_smb_req_send(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
                return tevent_req_post(req, state->ev);
        }
        cli_state_seqnum_persistent(cli, state->mid);
@@ -1154,8 +1156,9 @@ static void cli_trans_done(struct tevent_req *subreq)
                }
                cli_smb_req_set_mid(subreq, state->mid);
 
-               if (!cli_smb_req_send(subreq)) {
-                       status = NT_STATUS_NO_MEMORY;
+               status = cli_smb_req_send(subreq);
+
+               if (!NT_STATUS_IS_OK(status)) {
                        goto fail;
                }
                tevent_req_set_callback(subreq, cli_trans_done, req);