| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | count number of calls on an interface
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Andrew Tridgell 2003
|
|---|
| 7 | Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007
|
|---|
| 8 |
|
|---|
| 9 | This program is free software; you can redistribute it and/or modify
|
|---|
| 10 | it under the terms of the GNU General Public License as published by
|
|---|
| 11 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 12 | (at your option) any later version.
|
|---|
| 13 |
|
|---|
| 14 | This program is distributed in the hope that it will be useful,
|
|---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | GNU General Public License for more details.
|
|---|
| 18 |
|
|---|
| 19 | You should have received a copy of the GNU General Public License
|
|---|
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #include "includes.h"
|
|---|
| 24 | #include "torture/torture.h"
|
|---|
| 25 | #include "librpc/ndr/libndr.h"
|
|---|
| 26 | #include "librpc/ndr/ndr_table.h"
|
|---|
| 27 | #include "torture/rpc/rpc.h"
|
|---|
| 28 | #include "param/param.h"
|
|---|
| 29 | #include "librpc/rpc/dcerpc_proto.h"
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | bool count_calls(struct torture_context *tctx,
|
|---|
| 34 | TALLOC_CTX *mem_ctx,
|
|---|
| 35 | const struct ndr_interface_table *iface,
|
|---|
| 36 | bool all)
|
|---|
| 37 | {
|
|---|
| 38 | struct dcerpc_pipe *p;
|
|---|
| 39 | DATA_BLOB stub_in, stub_out;
|
|---|
| 40 | int i;
|
|---|
| 41 | NTSTATUS status = torture_rpc_connection(tctx, &p, iface);
|
|---|
| 42 | if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)
|
|---|
| 43 | || NT_STATUS_EQUAL(NT_STATUS_NET_WRITE_FAULT, status)
|
|---|
| 44 | || NT_STATUS_EQUAL(NT_STATUS_PORT_UNREACHABLE, status)
|
|---|
| 45 | || NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, status)) {
|
|---|
| 46 | if (all) {
|
|---|
| 47 | /* Not fatal if looking for all pipes */
|
|---|
| 48 | return true;
|
|---|
| 49 | } else {
|
|---|
| 50 | printf("Failed to open '%s' to count calls - %s\n", iface->name, nt_errstr(status));
|
|---|
| 51 | return false;
|
|---|
| 52 | }
|
|---|
| 53 | } else if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 54 | printf("Failed to open '%s' to count calls - %s\n", iface->name, nt_errstr(status));
|
|---|
| 55 | return false;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | stub_in = data_blob_talloc(p, mem_ctx, 0);
|
|---|
| 59 |
|
|---|
| 60 | printf("\nScanning pipe '%s'\n", iface->name);
|
|---|
| 61 |
|
|---|
| 62 | for (i=0;i<500;i++) {
|
|---|
| 63 | status = dcerpc_request(p, NULL, i, p, &stub_in, &stub_out);
|
|---|
| 64 | if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT) &&
|
|---|
| 65 | p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
|
|---|
| 66 | i--;
|
|---|
| 67 | break;
|
|---|
| 68 | }
|
|---|
| 69 | if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT) &&
|
|---|
| 70 | p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
|
|---|
| 71 | i--;
|
|---|
| 72 | break;
|
|---|
| 73 | }
|
|---|
| 74 | if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
|
|---|
| 75 | i--;
|
|---|
| 76 | break;
|
|---|
| 77 | }
|
|---|
| 78 | if (NT_STATUS_EQUAL(status, NT_STATUS_PIPE_DISCONNECTED)) {
|
|---|
| 79 | i--;
|
|---|
| 80 | break;
|
|---|
| 81 | }
|
|---|
| 82 | if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
|
|---|
| 83 | i--;
|
|---|
| 84 | break;
|
|---|
| 85 | }
|
|---|
| 86 | if (NT_STATUS_EQUAL(status, NT_STATUS_LOGON_FAILURE)) {
|
|---|
| 87 | i--;
|
|---|
| 88 | break;
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | if (i==500) {
|
|---|
| 93 | talloc_free(p);
|
|---|
| 94 | printf("no limit on calls: %s!?\n", nt_errstr(status));
|
|---|
| 95 | return false;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | printf("Found %d calls\n", i);
|
|---|
| 99 |
|
|---|
| 100 | talloc_free(p);
|
|---|
| 101 |
|
|---|
| 102 | return true;
|
|---|
| 103 |
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | bool torture_rpc_countcalls(struct torture_context *torture)
|
|---|
| 107 | {
|
|---|
| 108 | const struct ndr_interface_table *iface;
|
|---|
| 109 | const char *iface_name;
|
|---|
| 110 | bool ret = true;
|
|---|
| 111 | const struct ndr_interface_list *l;
|
|---|
| 112 | iface_name = lp_parm_string(torture->lp_ctx, NULL, "countcalls", "interface");
|
|---|
| 113 | if (iface_name != NULL) {
|
|---|
| 114 | iface = ndr_table_by_name(iface_name);
|
|---|
| 115 | if (!iface) {
|
|---|
| 116 | printf("Unknown interface '%s'\n", iface_name);
|
|---|
| 117 | return false;
|
|---|
| 118 | }
|
|---|
| 119 | return count_calls(torture, torture, iface, false);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | for (l=ndr_table_list();l;l=l->next) {
|
|---|
| 123 | TALLOC_CTX *loop_ctx;
|
|---|
| 124 | loop_ctx = talloc_named(torture, 0, "torture_rpc_councalls loop context");
|
|---|
| 125 | ret &= count_calls(torture, loop_ctx, l->table, true);
|
|---|
| 126 | talloc_free(loop_ctx);
|
|---|
| 127 | }
|
|---|
| 128 | return ret;
|
|---|
| 129 | }
|
|---|