}
NTSTATUS smb2cli_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
- struct iovec **piov, int body_size)
+ struct iovec **piov,
+ const struct smb2cli_req_expected_response *expected,
+ size_t num_expected)
{
struct smb2cli_req_state *state =
tevent_req_data(req,
struct smb2cli_req_state);
NTSTATUS status;
+ size_t body_size;
+ bool found_status = false;
+ bool found_size = false;
+ size_t i;
+
+ if (num_expected == 0) {
+ found_status = true;
+ found_size = true;
+ }
if (tevent_req_is_nterror(req, &status)) {
+ for (i=0; i < num_expected; i++) {
+ if (NT_STATUS_EQUAL(status, expected[i].status)) {
+ found_status = true;
+ break;
+ }
+ }
+
+ if (found_status) {
+ return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
+ }
+
return status;
}
status = NT_STATUS(IVAL(state->recv_iov[0].iov_base, SMB2_HDR_STATUS));
+ body_size = SVAL(state->recv_iov[1].iov_base, 0);
- if (body_size != 0) {
- if (body_size != SVAL(state->recv_iov[1].iov_base, 0)) {
- return NT_STATUS_INVALID_NETWORK_RESPONSE;
+ for (i=0; i < num_expected; i++) {
+ if (!NT_STATUS_EQUAL(status, expected[i].status)) {
+ continue;
+ }
+
+ found_status = true;
+ if (expected[i].body_size == 0) {
+ found_size = true;
+ break;
+ }
+
+ if (expected[i].body_size == body_size) {
+ found_size = true;
+ break;
}
}
+
+ if (!found_status) {
+ return status;
+ }
+
+ if (!found_size) {
+ return NT_STATUS_INVALID_NETWORK_RESPONSE;
+ }
+
if (piov != NULL) {
*piov = talloc_move(mem_ctx, &state->recv_iov);
}
uint32_t dyn_len);
NTSTATUS smb2cli_req_compound_submit(struct tevent_req **reqs,
int num_reqs);
+
+struct smb2cli_req_expected_response {
+ NTSTATUS status;
+ uint16_t body_size;
+};
+
struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct cli_state *cli,
const uint8_t *dyn,
uint32_t dyn_len);
NTSTATUS smb2cli_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
- struct iovec **piov, int body_size);
+ struct iovec **piov,
+ const struct smb2cli_req_expected_response *expected,
+ size_t num_expected);
#endif
struct tevent_req);
NTSTATUS status;
struct iovec *iov;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x3C
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 60);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
struct iovec *iov;
uint8_t *body;
uint32_t offset, length;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x59
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 89);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
struct tevent_req);
NTSTATUS status;
struct iovec *iov;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x04
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 4);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
NTSTATUS status;
struct iovec *iov;
uint8_t *body;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x41
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 65);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(subreq);
tevent_req_nterror(req, status);
NTSTATUS status;
struct iovec *iov;
uint16_t data_offset;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x09
+ }
+ };
- status = smb2cli_req_recv(subreq, state, &iov, 9);
+ status = smb2cli_req_recv(subreq, state, &iov,
+ expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
NTSTATUS status;
struct iovec *iov;
uint8_t data_offset;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = STATUS_BUFFER_OVERFLOW,
+ .body_size = 0x11
+ },
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x11
+ }
+ };
- status = smb2cli_req_recv(subreq, state, &iov, 17);
+ status = smb2cli_req_recv(subreq, state, &iov,
+ expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
NTSTATUS status;
struct iovec *iov;
uint16_t offset, length;
-
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 9);
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_MORE_PROCESSING_REQUIRED,
+ .body_size = 0x09
+ },
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x09
+ }
+ };
+
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (!NT_STATUS_IS_OK(status) &&
!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
TALLOC_FREE(subreq);
struct tevent_req);
NTSTATUS status;
struct iovec *iov;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x04
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 4);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
NTSTATUS status;
struct iovec *iov;
uint8_t *body;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x10
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 16);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(subreq);
tevent_req_nterror(req, status);
struct tevent_req);
NTSTATUS status;
struct iovec *iov;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x04
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 4);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
struct tevent_req);
NTSTATUS status;
struct iovec *iov;
+ static const struct smb2cli_req_expected_response expected[] = {
+ {
+ .status = NT_STATUS_OK,
+ .body_size = 0x11
+ }
+ };
- status = smb2cli_req_recv(subreq, talloc_tos(), &iov, 17);
+ status = smb2cli_req_recv(subreq, talloc_tos(), &iov,
+ expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}