summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorBo Yang <boyang@samba.org>2009-05-14 10:13:12 +0800
committerBo Yang <boyang@samba.org>2009-05-13 18:47:00 +0800
commit05379f01252fc8b449f36130bcf00c321d7a1c37 (patch)
treeb13cff0de029da42f251e6ecec4e31763b0e3fbc /source3
parent42e0cb8c0a1b8470ac8e9ad1c5a741e299debb8f (diff)
downloadsamba-05379f01252fc8b449f36130bcf00c321d7a1c37.tar.gz
samba-05379f01252fc8b449f36130bcf00c321d7a1c37.tar.bz2
samba-05379f01252fc8b449f36130bcf00c321d7a1c37.zip
s3: return proper error code in cli_smb_req_send
Signed-off-by: Bo Yang <boyang@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/include/async_smb.h2
-rw-r--r--source3/libsmb/async_smb.c50
-rw-r--r--source3/libsmb/cliconnect.c19
-rw-r--r--source3/libsmb/clifile.c20
-rw-r--r--source3/libsmb/clireadwrite.c20
-rw-r--r--source3/libsmb/clitrans.c11
6 files changed, 83 insertions, 39 deletions
diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h
index 87ddca6677..c27dd2b36f 100644
--- a/source3/include/async_smb.h
+++ b/source3/include/async_smb.h
@@ -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);
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index 9fdd14793f..0d82894bdc 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -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;
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 38985363c2..16c15ce7db 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -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;
}
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 63e6c474db..3c13383669 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -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;
}
diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c
index 4e256ede57..d38de19508 100644
--- a/source3/libsmb/clireadwrite.c
+++ b/source3/libsmb/clireadwrite.c
@@ -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;
}
diff --git a/source3/libsmb/clitrans.c b/source3/libsmb/clitrans.c
index d6d78cc6c3..98c09ed6e7 100644
--- a/source3/libsmb/clitrans.c
+++ b/source3/libsmb/clitrans.c
@@ -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);