r14173: change smb interface structures to always use
[gd/samba-autobuild/.git] / source4 / torture / torture.c
index 1c8937369b47d428553d1a8e1cfafbda8c7db515..9598e1ea2e5ad375546fb2e9228a2d3a9826282f 100644 (file)
@@ -1,5 +1,3 @@
-#error "remove this line to fix the build"
-
 /* 
    Unix SMB/CIFS implementation.
    SMB torture tester
 */
 
 #include "includes.h"
-#include "dynconfig.h"
-#include "clilist.h"
 #include "lib/cmdline/popt_common.h"
 #include "libcli/raw/libcliraw.h"
 #include "system/time.h"
 #include "system/wait.h"
 #include "system/filesys.h"
-#include "ioctl.h"
-#include "librpc/gen_ndr/ndr_security.h"
+#include "libcli/raw/ioctl.h"
+#include "libcli/libcli.h"
+#include "lib/ldb/include/ldb.h"
+#include "librpc/rpc/dcerpc_table.h"
+#include "lib/events/events.h"
+#include "libcli/resolve/resolve.h"
+
+#include "torture/basic/proto.h"
+#include "torture/raw/proto.h"
+#include "torture/smb2/proto.h"
+#include "torture/rpc/proto.h"
+#include "torture/rap/proto.h"
+#include "torture/auth/proto.h"
+#include "torture/local/proto.h"
+#include "torture/nbench/proto.h"
+#include "torture/ldap/proto.h"
+#include "torture/com/proto.h"
+#include "torture/nbt/proto.h"
+#include "torture/libnet/proto.h"
+#include "torture/torture.h"
 
 int torture_nprocs=4;
-int torture_numops=100;
+int torture_numops=10;
 int torture_entries=1000;
 int torture_failures=1;
 int torture_seed=0;
@@ -78,16 +92,17 @@ failed:
        return NULL;
 }
 
-BOOL torture_open_connection_share(struct smbcli_state **c, 
+BOOL torture_open_connection_share(TALLOC_CTX *mem_ctx,
+                                  struct smbcli_state **c, 
                                   const char *hostname, 
-                                  const char *sharename)
+                                  const char *sharename,
+                                  struct event_context *ev)
 {
        NTSTATUS status;
 
-       status = smbcli_full_connection(NULL,
-                                       c, hostname, 
+       status = smbcli_full_connection(mem_ctx, c, hostname, 
                                        sharename, NULL,
-                                       cmdline_credentials, NULL);
+                                       cmdline_credentials, ev);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to open connection - %s\n", nt_errstr(status));
                return False;
@@ -104,7 +119,7 @@ BOOL torture_open_connection(struct smbcli_state **c)
        const char *host = lp_parm_string(-1, "torture", "host");
        const char *share = lp_parm_string(-1, "torture", "share");
 
-       return torture_open_connection_share(c, host, share);
+       return torture_open_connection_share(NULL, c, host, share, NULL);
 }
 
 
@@ -124,9 +139,7 @@ BOOL torture_close_connection(struct smbcli_state *c)
 /* open a rpc connection to the chosen binding string */
 NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
                                struct dcerpc_pipe **p, 
-                               const char *pipe_name,
-                               const char *pipe_uuid, 
-                               uint32_t pipe_version)
+                               const struct dcerpc_interface_table *table)
 {
         NTSTATUS status;
        const char *binding = lp_parm_string(-1, "torture", "binding");
@@ -137,7 +150,7 @@ NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx,
        }
 
        status = dcerpc_pipe_connect(parent_ctx, 
-                                    p, binding, pipe_uuid, pipe_version,
+                                    p, binding, table,
                                     cmdline_credentials, NULL);
  
         return status;
@@ -146,9 +159,7 @@ NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx,
 /* open a rpc connection to a specific transport */
 NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx, 
                                          struct dcerpc_pipe **p, 
-                                         const char *pipe_name,
-                                         const char *pipe_uuid, 
-                                         uint32_t pipe_version,
+                                         const struct dcerpc_interface_table *table,
                                          enum dcerpc_transport_t transport)
 {
         NTSTATUS status;
@@ -171,7 +182,7 @@ NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx,
 
        b->transport = transport;
 
-       status = dcerpc_pipe_connect_b(mem_ctx, p, b, pipe_uuid, pipe_version,
+       status = dcerpc_pipe_connect_b(mem_ctx, p, b, table,
                                       cmdline_credentials, NULL);
                                           
        if (NT_STATUS_IS_OK(status)) {
@@ -902,46 +913,35 @@ static BOOL run_negprot_nowait(void)
 
        printf("Filling send buffer\n");
 
-       for (i=0;i<10000;i++) {
+       for (i=0;i<100;i++) {
                struct smbcli_request *req;
-               time_t t1 = time(NULL);
                req = smb_raw_negotiate_send(cli->transport, PROTOCOL_NT1);
-               while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
-                       smbcli_transport_process(cli->transport);
-               }
+               event_loop_once(cli->transport->socket->event.ctx);
                if (req->state == SMBCLI_REQUEST_ERROR) {
-                       printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
-                       torture_close_connection(cli);
-                       return correct;
-               }
-               if (req->state == SMBCLI_REQUEST_SEND) {
-                       break;
-               }
-       }
-
-       if (i == 10000) {
-               printf("send buffer failed to fill\n");
-               if (!torture_close_connection(cli)) {
-                       correct = False;
+                       if (i > 0) {
+                               printf("Failed to fill pipe packet[%d] - %s (ignored)\n", i+1, nt_errstr(req->status));
+                               break;
+                       } else {
+                               printf("Failed to fill pipe - %s \n", nt_errstr(req->status));
+                               torture_close_connection(cli);
+                               return False;
+                       }
                }
-               return correct;
        }
 
-       printf("send buffer filled after %d requests\n", i);
-
        printf("Opening secondary connection\n");
        if (!torture_open_connection(&cli2)) {
-               return False;
-       }
-
-       if (!torture_close_connection(cli)) {
+               printf("Failed to open secondary connection\n");
                correct = False;
        }
 
        if (!torture_close_connection(cli2)) {
+               printf("Failed to close secondary connection\n");
                correct = False;
        }
 
+       torture_close_connection(cli);
+
        printf("finished negprot nowait test\n");
 
        return correct;
@@ -1922,7 +1922,7 @@ BOOL torture_ioctl_test(void)
        }
 
        parms.ioctl.level = RAW_IOCTL_IOCTL;
-       parms.ioctl.in.fnum = fnum;
+       parms.ioctl.file.fnum = fnum;
        parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
        status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
        printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
@@ -2109,9 +2109,11 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
                        while (1) {
                                if (hostname) {
-                                       if (torture_open_connection_share(&current_cli,
+                                       if (torture_open_connection_share(NULL,
+                                                                         &current_cli,
                                                                          hostname, 
-                                                                         sharename)) {
+                                                                         sharename,
+                                                                         NULL)) {
                                                break;
                                        }
                                } else if (torture_open_connection(&current_cli)) {
@@ -2168,7 +2170,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
        for (i=0;i<torture_nprocs;i++) {
                int ret;
-               while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
+               while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
                if (ret == -1 || WEXITSTATUS(status) != 0) {
                        *result = False;
                }
@@ -2267,6 +2269,16 @@ static struct {
        {"RAW-RAP", torture_raw_rap, 0},
        {"RAW-COMPOSITE", torture_raw_composite, 0},
 
+       /* SMB2 tests */
+       {"SMB2-CONNECT", torture_smb2_connect, 0},
+       {"SMB2-SCAN", torture_smb2_scan, 0},
+       {"SMB2-SCANGETINFO", torture_smb2_getinfo_scan, 0},
+       {"SMB2-SCANSETINFO", torture_smb2_setinfo_scan, 0},
+       {"SMB2-SCANFIND", torture_smb2_find_scan, 0},
+       {"SMB2-GETINFO", torture_smb2_getinfo, 0},
+       {"SMB2-SETINFO", torture_smb2_setinfo, 0},
+       {"SMB2-FIND", torture_smb2_find, 0},
+
        /* protocol scanners */
        {"SCAN-TRANS2", torture_trans2_scan, 0},
        {"SCAN-NTTRANS", torture_nttrans_scan, 0},
@@ -2281,6 +2293,7 @@ static struct {
 
        /* rpc testers */
         {"RPC-LSA", torture_rpc_lsa, 0},
+        {"RPC-LSALOOKUP", torture_rpc_lsa_lookup, 0},
         {"RPC-SECRETS", torture_rpc_lsa_secrets, 0},
         {"RPC-ECHO", torture_rpc_echo, 0},
         {"RPC-DFS", torture_rpc_dfs, 0},
@@ -2307,10 +2320,12 @@ static struct {
         {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
        {"RPC-MULTIBIND", torture_multi_bind, 0},
        {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
-       {"RPC-LOGIN", torture_rpc_login, 0},
+       {"RPC-CRACKNAMES", torture_rpc_drsuapi_cracknames, 0},
        {"RPC-ROT", torture_rpc_rot, 0},
        {"RPC-DSSETUP", torture_rpc_dssetup, 0},
         {"RPC-ALTERCONTEXT", torture_rpc_alter_context, 0},
+        {"RPC-JOIN", torture_rpc_join, 0},
+        {"RPC-DSSYNC", torture_rpc_dssync, 0},
 
        /* local (no server) testers */
        {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
@@ -2319,9 +2334,15 @@ static struct {
        {"LOCAL-MESSAGING", torture_local_messaging, 0},
        {"LOCAL-IRPC",  torture_local_irpc, 0},
        {"LOCAL-BINDING", torture_local_binding_string, 0},
+       {"LOCAL-STRLIST", torture_local_util_strlist, 0},
+       {"LOCAL-FILE", torture_local_util_file, 0},
        {"LOCAL-IDTREE", torture_local_idtree, 0},
        {"LOCAL-SOCKET", torture_local_socket, 0},
        {"LOCAL-PAC", torture_pac, 0},
+       {"LOCAL-REGISTRY", torture_registry, 0},
+       {"LOCAL-RESOLVE", torture_local_resolve, 0},
+       {"LOCAL-SDDL", torture_local_sddl, 0},
+       {"LOCAL-NDR", torture_local_ndr, 0},
 
        /* COM (Component Object Model) testers */
        {"COM-SIMPLE", torture_com_simple, 0 },
@@ -2333,8 +2354,11 @@ static struct {
        /* nbt tests */
        {"NBT-REGISTER", torture_nbt_register, 0},
        {"NBT-WINS", torture_nbt_wins, 0},
-       {"NBT-WINSREPLICATION", torture_nbt_winsreplication, 0},
        {"NBT-DGRAM", torture_nbt_dgram, 0},
+       {"NBT-BROWSE", torture_nbt_browse, 0},
+       {"NBT-WINSREPLICATION-SIMPLE", torture_nbt_winsreplication_simple, 0},
+       {"NBT-WINSREPLICATION-REPLICA", torture_nbt_winsreplication_replica, 0},
+       {"NBT-WINSREPLICATION-OWNED", torture_nbt_winsreplication_owned, 0},
        
        /* libnet tests */
        {"NET-USERINFO", torture_userinfo, 0},
@@ -2347,6 +2371,8 @@ static struct {
        {"NET-API-LOOKUPPDC", torture_lookup_pdc, 0},
        {"NET-API-CREATEUSER", torture_createuser, 0},
        {"NET-API-RPCCONNECT", torture_rpc_connect, 0},
+       {"NET-API-LISTSHARES", torture_listshares, 0},
+       {"NET-API-DELSHARE", torture_delshare, 0},
 
        {NULL, NULL, 0}};
 
@@ -2541,10 +2567,12 @@ static void max_runtime_handler(int sig)
        int argc_new;
        char **argv_new;
        poptContext pc;
-       enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,OPT_DANGEROUS};
+       enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,
+           OPT_DANGEROUS,OPT_SMB_PORTS};
+
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               {"smb-ports",   'p', POPT_ARG_STRING, NULL,             0,      "SMB ports",    NULL},
+               {"smb-ports",   'p', POPT_ARG_STRING, NULL,     OPT_SMB_PORTS,  "SMB ports",    NULL},
                {"seed",          0, POPT_ARG_INT,  &torture_seed,      0,      "seed",         NULL},
                {"num-progs",     0, POPT_ARG_INT,  &torture_nprocs,    0,      "num progs",    NULL},
                {"num-ops",       0, POPT_ARG_INT,  &torture_numops,    0,      "num ops",      NULL},
@@ -2570,6 +2598,9 @@ static void max_runtime_handler(int sig)
        setbuffer(stdout, NULL, 0);
 #endif
 
+       /* we are never interested in SIGPIPE */
+       BlockSignals(True,SIGPIPE);
+
        pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, 
                            POPT_CONTEXT_KEEP_FIRST);
 
@@ -2592,6 +2623,9 @@ static void max_runtime_handler(int sig)
                case OPT_DANGEROUS:
                        lp_set_cmdline("torture:dangerous", "Yes");
                        break;
+               case OPT_SMB_PORTS:
+                       lp_set_cmdline("smb ports", poptGetOptArg(pc));
+                       break;
                default:
                        d_printf("Invalid option %s: %s\n", 
                                 poptBadOption(pc, 0), poptStrerror(opt));
@@ -2610,8 +2644,11 @@ static void max_runtime_handler(int sig)
                alarm(max_runtime);
        }
 
-       smbtorture_init_subsystems;
+       ldb_global_init();
+
+       dcerpc_init();
 
+       dcerpc_table_init();
 
        if (torture_seed == 0) {
                torture_seed = time(NULL);