r24872: Use torture API a bit more
[kai/samba.git] / source4 / torture / rpc / scanner.c
index f93ea0419a875b3975aff839f14dc0845edd2d6a..e1d7c69676fe13ff192c65be199c2c148e15f2e8 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "torture/torture.h"
+#include "librpc/gen_ndr/ndr_mgmt_c.h"
+#include "librpc/ndr/ndr_table.h"
+#include "torture/rpc/rpc.h"
 
 /*
   work out how many calls there are for an interface
  */
-static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
+static bool test_num_calls(struct torture_context *tctx, 
+                          const struct ndr_interface_table *iface,
                           TALLOC_CTX *mem_ctx,
-                          struct dcerpc_syntax_id *id)
+                          struct ndr_syntax_id *id)
 {
        struct dcerpc_pipe *p;
        NTSTATUS status;
-       const char *uuid;
        int i;
        DATA_BLOB stub_in, stub_out;
        int idl_calls;
+       struct ndr_interface_table tbl;
 
-       uuid = GUID_string(mem_ctx, &id->uuid);
+       /* FIXME: This should be fixed when torture_rpc_connection 
+        * takes a ndr_syntax_id */
+       tbl.name = iface->name;
+       tbl.syntax_id = *id;
 
-       status = torture_rpc_connection(&p, iface->name,
-                                       uuid, id->if_version);
+       status = torture_rpc_connection(tctx, &p, iface);
        if (!NT_STATUS_IS_OK(status)) {
+               char *uuid_str = GUID_string(mem_ctx, &id->uuid);
                printf("Failed to connect to '%s' on '%s' - %s\n", 
-                      uuid, iface->name, nt_errstr(status));
-               return False;
+                      uuid_str, iface->name, nt_errstr(status));
+               talloc_free(uuid_str);
+               return True;
        }
 
        /* make null calls */
@@ -51,7 +59,7 @@ static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
        memset(stub_in.data, 0xFF, stub_in.length);
 
        for (i=0;i<200;i++) {
-               status = dcerpc_request(p, i, mem_ctx, &stub_in, &stub_out);
+               status = dcerpc_request(p, NULL, i, False, mem_ctx, &stub_in, &stub_out);
                if (!NT_STATUS_IS_OK(status) &&
                    p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
                        break;
@@ -69,7 +77,7 @@ static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
        }
 
        printf("\t%d calls available\n", i);
-       idl_calls = idl_num_calls(uuid, id->if_version);
+       idl_calls = ndr_interface_num_calls(&id->uuid, id->if_version);
        if (idl_calls == -1) {
                printf("\tinterface not known in local IDL\n");
        } else if (i != idl_calls) {
@@ -79,115 +87,63 @@ static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
        }
 
 done:
-       torture_rpc_close(p);
-       return True;
+       talloc_free(p);
+       return true;
 }
 
-/*
-  ask the server what interface IDs are available on this endpoint
-*/
-static BOOL test_inq_if_ids(struct dcerpc_pipe *p, 
-                           TALLOC_CTX *mem_ctx,
-                           const struct dcerpc_interface_table *iface)
-{
-       NTSTATUS status;
-       struct mgmt_inq_if_ids r;
-       int i;
-       
-       status = dcerpc_mgmt_inq_if_ids(p, mem_ctx, &r);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("inq_if_ids failed - %s\n", nt_errstr(status));
-               return False;
-       }
-
-       if (!W_ERROR_IS_OK(r.out.result)) {
-               printf("inq_if_ids gave error code %s\n", win_errstr(r.out.result));
-               return False;
-       }
-
-       if (!r.out.if_id_vector) {
-               printf("inq_if_ids gave NULL if_id_vector\n");
-               return False;
-       }
 
-       for (i=0;i<r.out.if_id_vector->count;i++) {
-               const char *uuid;
-               struct dcerpc_syntax_id *id = r.out.if_id_vector->if_id[i].id;
-               if (!id) continue;
 
-               uuid = GUID_string(mem_ctx, &id->uuid),
-
-               printf("\n\tuuid %s  version 0x%08x '%s'\n",
-                      uuid,
-                      id->if_version, idl_pipe_name(uuid, id->if_version));
-               test_num_calls(iface, mem_ctx, id);
-       }
-
-       return True;
-}
-
-
-BOOL torture_rpc_scanner(void)
+bool torture_rpc_scanner(struct torture_context *torture)
 {
         NTSTATUS status;
         struct dcerpc_pipe *p;
-       TALLOC_CTX *mem_ctx;
+       TALLOC_CTX *loop_ctx;
        BOOL ret = True;
-       int i;
-       const char *binding = lp_parm_string(-1, "torture", "binding");
-       struct dcerpc_binding b;
-
-       mem_ctx = talloc_init("torture_rpc_scanner");
+       const struct ndr_interface_list *l;
+       struct dcerpc_binding *b;
 
-       if (!binding) {
-               printf("You must supply a ncacn binding string\n");
-               return False;
-       }
-       
-       status = dcerpc_parse_binding(mem_ctx, binding, &b);
+       status = torture_rpc_binding(torture, &b);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to parse binding '%s'\n", binding);
-               return False;
+               return false;
        }
 
-       for (i=0;dcerpc_pipes[i];i++) {         
+       for (l=ndr_table_list();l;l=l->next) {          
+               loop_ctx = talloc_named(torture, 0, "torture_rpc_scanner loop context");
                /* some interfaces are not mappable */
-               if (dcerpc_pipes[i]->num_calls == 0 ||
-                   strcmp(dcerpc_pipes[i]->name, "mgmt") == 0) {
+               if (l->table->num_calls == 0 ||
+                   strcmp(l->table->name, "mgmt") == 0) {
+                       talloc_free(loop_ctx);
                        continue;
                }
 
-               printf("\nTesting pipe '%s'\n", dcerpc_pipes[i]->name);
+               printf("\nTesting pipe '%s'\n", l->table->name);
 
-               if (b.transport == NCACN_IP_TCP) {
-                       status = dcerpc_epm_map_binding(mem_ctx, &b, 
-                                                        dcerpc_pipes[i]->uuid,
-                                                        dcerpc_pipes[i]->if_version);
+               if (b->transport == NCACN_IP_TCP) {
+                       status = dcerpc_epm_map_binding(torture, b, l->table, NULL);
                        if (!NT_STATUS_IS_OK(status)) {
-                               printf("Failed to map port for uuid %s\n", dcerpc_pipes[i]->uuid);
+                               printf("Failed to map port for uuid %s\n", 
+                                          GUID_string(loop_ctx, &l->table->syntax_id.uuid));
+                               talloc_free(loop_ctx);
                                continue;
                        }
                } else {
-                       b.endpoint = dcerpc_pipes[i]->name;
+                       b->endpoint = talloc_strdup(b, l->table->name);
                }
 
-               lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, &b));
+               lp_set_cmdline("torture:binding", dcerpc_binding_string(torture, b));
 
-               status = torture_rpc_connection(&p, 
-                                               dcerpc_pipes[i]->name,
-                                               DCERPC_MGMT_UUID,
-                                               DCERPC_MGMT_VERSION);
+               status = torture_rpc_connection(torture, &p, &ndr_table_mgmt);
                if (!NT_STATUS_IS_OK(status)) {
+                       talloc_free(loop_ctx);
                        ret = False;
                        continue;
                }
        
-               if (!test_inq_if_ids(p, mem_ctx, dcerpc_pipes[i])) {
+               if (!test_inq_if_ids(torture, p, torture, test_num_calls, l->table)) {
                        ret = False;
                }
-
-               torture_rpc_close(p);
        }
 
        return ret;
 }
+