| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
test suite for dcerpc ndr operations |
| 4 |
|
| 5 |
Copyright (C) Stefan Metzmacher 2023 |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "includes.h" |
| 22 |
#include "torture/ndr/ndr.h" |
| 23 |
#include "librpc/gen_ndr/ndr_dcerpc.h" |
| 24 |
#include "torture/ndr/proto.h" |
| 25 |
|
| 26 |
/* |
| 27 |
* ncacn_packet: struct ncacn_packet |
| 28 |
* rpc_vers : 0x05 (5) |
| 29 |
* rpc_vers_minor : 0x00 (0) |
| 30 |
* ptype : DCERPC_PKT_CO_CANCEL (18) |
| 31 |
* pfc_flags : 0x06 (6) |
| 32 |
* 0: DCERPC_PFC_FLAG_FIRST |
| 33 |
* 1: DCERPC_PFC_FLAG_LAST |
| 34 |
* 1: DCERPC_PFC_FLAG_PENDING_CANCEL_OR_HDR_SIGNING |
| 35 |
* 0: DCERPC_PFC_FLAG_CONC_MPX |
| 36 |
* 0: DCERPC_PFC_FLAG_DID_NOT_EXECUTE |
| 37 |
* 0: DCERPC_PFC_FLAG_MAYBE |
| 38 |
* 0: DCERPC_PFC_FLAG_OBJECT_UUID |
| 39 |
* drep: ARRAY(4) |
| 40 |
* [0] : 0x10 (16) |
| 41 |
* [1] : 0x00 (0) |
| 42 |
* [2] : 0x00 (0) |
| 43 |
* [3] : 0x00 (0) |
| 44 |
* frag_length : 0x0010 (16) |
| 45 |
* auth_length : 0x0000 (0) |
| 46 |
* call_id : 0x00000001 (1) |
| 47 |
* u : union dcerpc_payload(case 18) |
| 48 |
* co_cancel: struct dcerpc_co_cancel |
| 49 |
* auth_info : DATA_BLOB length=0 |
| 50 |
*/ |
| 51 |
static const uint8_t ncacn_packet_co_cancel_data[] = { |
| 52 |
0x05, 0x00, 0x12, 0x06, 0x10, 0x00, 0x00, 0x00, |
| 53 |
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 54 |
}; |
| 55 |
|
| 56 |
static bool ncacn_packet_co_cancel_check(struct torture_context *tctx, |
| 57 |
struct ncacn_packet *pkt) |
| 58 |
{ |
| 59 |
torture_assert_int_equal(tctx, pkt->rpc_vers, 5, "rpc_vers"); |
| 60 |
torture_assert_int_equal(tctx, pkt->rpc_vers_minor, 0, "rpc_vers_minor"); |
| 61 |
torture_assert_int_equal(tctx, pkt->ptype, DCERPC_PKT_CO_CANCEL, "ptype"); |
| 62 |
torture_assert_int_equal(tctx, pkt->pfc_flags, |
| 63 |
DCERPC_PFC_FLAG_LAST | |
| 64 |
DCERPC_PFC_FLAG_PENDING_CANCEL_OR_HDR_SIGNING, |
| 65 |
"pfc_flags"); |
| 66 |
torture_assert_int_equal(tctx, pkt->drep[0], DCERPC_DREP_LE, "drep[0]"); |
| 67 |
torture_assert_int_equal(tctx, pkt->drep[1], 0, "drep[1]"); |
| 68 |
torture_assert_int_equal(tctx, pkt->drep[2], 0, "drep[2]"); |
| 69 |
torture_assert_int_equal(tctx, pkt->drep[3], 0, "drep[3]"); |
| 70 |
torture_assert_int_equal(tctx, pkt->frag_length, 16, "frag_length"); |
| 71 |
torture_assert_int_equal(tctx, pkt->auth_length, 0, "auth_length"); |
| 72 |
torture_assert_int_equal(tctx, pkt->call_id, 1, "call_id"); |
| 73 |
torture_assert_int_equal(tctx, pkt->u.co_cancel.auth_info.length, 0, |
| 74 |
"co_cancel.auth_info.length"); |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
/* |
| 79 |
* ncacn_packet: struct ncacn_packet |
| 80 |
* rpc_vers : 0x05 (5) |
| 81 |
* rpc_vers_minor : 0x00 (0) |
| 82 |
* ptype : DCERPC_PKT_ORPHANED (19) |
| 83 |
* pfc_flags : 0x03 (3) |
| 84 |
* 1: DCERPC_PFC_FLAG_FIRST |
| 85 |
* 1: DCERPC_PFC_FLAG_LAST |
| 86 |
* 0: DCERPC_PFC_FLAG_PENDING_CANCEL_OR_HDR_SIGNING |
| 87 |
* 0: DCERPC_PFC_FLAG_CONC_MPX |
| 88 |
* 0: DCERPC_PFC_FLAG_DID_NOT_EXECUTE |
| 89 |
* 0: DCERPC_PFC_FLAG_MAYBE |
| 90 |
* 0: DCERPC_PFC_FLAG_OBJECT_UUID |
| 91 |
* drep: ARRAY(4) |
| 92 |
* [0] : 0x10 (16) |
| 93 |
* [1] : 0x00 (0) |
| 94 |
* [2] : 0x00 (0) |
| 95 |
* [3] : 0x00 (0) |
| 96 |
* frag_length : 0x0010 (16) |
| 97 |
* auth_length : 0x0000 (0) |
| 98 |
* call_id : 0x00000008 (8) |
| 99 |
* u : union dcerpc_payload(case 19) |
| 100 |
* orphaned: struct dcerpc_orphaned |
| 101 |
* auth_info : DATA_BLOB length=0 |
| 102 |
*/ |
| 103 |
static const uint8_t ncacn_packet_orphaned_data[] = { |
| 104 |
0x05, 0x00, 0x13, 0x03, 0x10, 0x00, 0x00, 0x00, |
| 105 |
0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 106 |
}; |
| 107 |
|
| 108 |
static bool ncacn_packet_orphaned_check(struct torture_context *tctx, |
| 109 |
struct ncacn_packet *pkt) |
| 110 |
{ |
| 111 |
torture_assert_int_equal(tctx, pkt->rpc_vers, 5, "rpc_vers"); |
| 112 |
torture_assert_int_equal(tctx, pkt->rpc_vers_minor, 0, "rpc_vers_minor"); |
| 113 |
torture_assert_int_equal(tctx, pkt->ptype, DCERPC_PKT_ORPHANED, "ptype"); |
| 114 |
torture_assert_int_equal(tctx, pkt->pfc_flags, |
| 115 |
DCERPC_PFC_FLAG_FIRST|DCERPC_PFC_FLAG_LAST, |
| 116 |
"pfc_flags"); |
| 117 |
torture_assert_int_equal(tctx, pkt->drep[0], DCERPC_DREP_LE, "drep[0]"); |
| 118 |
torture_assert_int_equal(tctx, pkt->drep[1], 0, "drep[1]"); |
| 119 |
torture_assert_int_equal(tctx, pkt->drep[2], 0, "drep[2]"); |
| 120 |
torture_assert_int_equal(tctx, pkt->drep[3], 0, "drep[3]"); |
| 121 |
torture_assert_int_equal(tctx, pkt->frag_length, 16, "frag_length"); |
| 122 |
torture_assert_int_equal(tctx, pkt->auth_length, 0, "auth_length"); |
| 123 |
torture_assert_int_equal(tctx, pkt->call_id, 8, "call_id"); |
| 124 |
torture_assert_int_equal(tctx, pkt->u.orphaned.auth_info.length, 0, |
| 125 |
"orphaned.auth_info.length"); |
| 126 |
return true; |
| 127 |
} |
| 128 |
|
| 129 |
struct torture_suite *ndr_dcerpc_suite(TALLOC_CTX *ctx) |
| 130 |
{ |
| 131 |
struct torture_suite *suite = torture_suite_create(ctx, "dcerpc"); |
| 132 |
struct torture_suite *co_cancel = torture_suite_create(ctx, "co_cancel"); |
| 133 |
struct torture_suite *orphaned = torture_suite_create(ctx, "orphaned"); |
| 134 |
|
| 135 |
torture_suite_add_suite(suite, co_cancel); |
| 136 |
torture_suite_add_ndr_pull_validate_test(co_cancel, |
| 137 |
ncacn_packet, |
| 138 |
ncacn_packet_co_cancel_data, |
| 139 |
ncacn_packet_co_cancel_check); |
| 140 |
|
| 141 |
torture_suite_add_suite(suite, orphaned); |
| 142 |
torture_suite_add_ndr_pull_validate_test(orphaned, |
| 143 |
ncacn_packet, |
| 144 |
ncacn_packet_orphaned_data, |
| 145 |
ncacn_packet_orphaned_check); |
| 146 |
|
| 147 |
return suite; |
| 148 |
} |