r14363: Remove credentials.h from the global includes.
[abartlet/samba.git/.git] / source4 / torture / torture.c
index e60f1caf78ddcee8714a857d28d38079812c166e..3236bbb89c39dcfae21e1a5a3a29d6527060c209 100644 (file)
 */
 
 #include "includes.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 "auth/credentials/credentials.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"
+#include "build.h"
+#include "dlinklist.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;
@@ -37,6 +57,7 @@ static int procnum; /* records process count number when forking */
 static struct smbcli_state *current_cli;
 static BOOL use_oplocks;
 static BOOL use_level_II_oplocks;
+#define MAX_COLS 80 /* FIXME: Determine this at run-time */
 
 BOOL torture_showall = False;
 
@@ -122,9 +143,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");
@@ -135,7 +154,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;
@@ -144,9 +163,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;
@@ -169,7 +186,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)) {
@@ -900,46 +917,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;
@@ -1920,7 +1926,7 @@ BOOL torture_ioctl_test(void)
        }
 
        parms.ioctl.level = RAW_IOCTL_IOCTL;
-       parms.ioctl.in.fnum = fnum;
+       parms.ioctl.in.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));
@@ -2168,7 +2174,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;
                }
@@ -2190,7 +2196,7 @@ static struct {
        const char *name;
        BOOL (*fn)(void);
        BOOL (*multi_fn)(struct smbcli_state *, int );
-} torture_ops[] = {
+} builtin_torture_ops[] = {
        /* base tests */
        {"BASE-FDPASS", run_fdpasstest, 0},
        {"BASE-LOCK1",  torture_locktest1,  0},
@@ -2267,6 +2273,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 +2297,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},
@@ -2308,10 +2325,11 @@ static struct {
        {"RPC-MULTIBIND", torture_multi_bind, 0},
        {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
        {"RPC-CRACKNAMES", torture_rpc_drsuapi_cracknames, 0},
-       {"RPC-LOGIN", torture_rpc_login, 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},
@@ -2320,13 +2338,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},
-
-       /* COM (Component Object Model) testers */
-       {"COM-SIMPLE", torture_com_simple, 0 },
+       {"LOCAL-SDDL", torture_local_sddl, 0},
+       {"LOCAL-NDR", torture_local_ndr, 0},
 
        /* ldap testers */
        {"LDAP-BASIC", torture_ldap_basic, 0},
@@ -2335,8 +2355,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},
@@ -2354,50 +2377,98 @@ static struct {
 
        {NULL, NULL, 0}};
 
+static void register_builtin_ops(void)
+{
+       int i;
+       for (i = 0; builtin_torture_ops[i].name; i++) {
+               register_torture_op(builtin_torture_ops[i].name, 
+                                                       builtin_torture_ops[i].fn, 
+                                                       builtin_torture_ops[i].multi_fn);
+       }
+}
 
 
+static struct torture_op {
+       const char *name;
+       BOOL (*fn)(void);
+       BOOL (*multi_fn)(struct smbcli_state *, int );
+       struct torture_op *prev, *next;
+}* torture_ops = NULL;;
+
+static struct torture_op *find_torture_op(const char *name)
+{
+       struct torture_op *o;
+       for (o = torture_ops; o; o = o->next) {
+               if (strcmp(name, o->name) == 0)
+                       return o;
+       }
+
+       return NULL;
+}
+
+NTSTATUS register_torture_op(const char *name, BOOL (*fn)(void), BOOL (*multi_fn)(struct smbcli_state *, int ))
+{
+       struct torture_op *op;
+       
+       /* Check for duplicates */
+       if (find_torture_op(name) != NULL) {
+               DEBUG(0,("There already is a torture op registered with the name %s!\n", name));
+               return NT_STATUS_OBJECT_NAME_COLLISION;
+       }
+
+       op = talloc(talloc_autofree_context(), struct torture_op);
+
+       op->name = talloc_strdup(op, name);
+       op->fn = fn;
+       op->multi_fn = multi_fn;
+
+       DLIST_ADD(torture_ops, op);
+       
+       return NT_STATUS_OK;
+}
+
 /****************************************************************************
 run a specified test or "ALL"
 ****************************************************************************/
 static BOOL run_test(const char *name)
 {
        BOOL ret = True;
-       int i;
+       struct torture_op *o;
        BOOL matched = False;
 
        if (strequal(name,"ALL")) {
-               for (i=0;torture_ops[i].name;i++) {
-                       if (!run_test(torture_ops[i].name)) {
+               for (o = torture_ops; o; o = o->next) {
+                       if (!run_test(o->name)) {
                                ret = False;
                        }
                }
                return ret;
        }
 
-       for (i=0;torture_ops[i].name;i++) {
-               if (gen_fnmatch(name, torture_ops[i].name) == 0) {
+       for (o = torture_ops; o; o = o->next) {
+               if (gen_fnmatch(name, o->name) == 0) {
                        double t;
                        matched = True;
                        init_iconv();
-                       printf("Running %s\n", torture_ops[i].name);
-                       if (torture_ops[i].multi_fn) {
+                       printf("Running %s\n", o->name);
+                       if (o->multi_fn) {
                                BOOL result = False;
-                               t = torture_create_procs(torture_ops[i].multi_fn, 
+                               t = torture_create_procs(o->multi_fn, 
                                                         &result);
                                if (!result) { 
                                        ret = False;
-                                       printf("TEST %s FAILED!\n", torture_ops[i].name);
+                                       printf("TEST %s FAILED!\n", o->name);
                                }
                                         
                        } else {
                                struct timeval tv = timeval_current();
-                               if (!torture_ops[i].fn()) {
+                               if (!o->fn()) {
                                        ret = False;
-                                       printf("TEST %s FAILED!\n", torture_ops[i].name);
+                                       printf("TEST %s FAILED!\n", o->name);
                                }
                                t = timeval_elapsed(&tv);
                        }
-                       printf("%s took %g secs\n\n", torture_ops[i].name, t);
+                       printf("%s took %g secs\n\n", o->name, t);
                }
        }
 
@@ -2451,8 +2522,8 @@ static void parse_dns(const char *dns)
 
 static void usage(poptContext pc)
 {
+       struct torture_op *o;
        int i;
-       int perline = 5;
 
        poptPrintUsage(pc, stdout, 0);
        printf("\n");
@@ -2501,12 +2572,15 @@ static void usage(poptContext pc)
 
        printf("    //server/share\n\n");
 
-       printf("tests are:");
-       for (i=0;torture_ops[i].name;i++) {
-               if ((i%perline)==0) {
+       printf("tests are:\n");
+
+       i = 0;
+       for (o = torture_ops; o; o = o->next) {
+               if (i + strlen(o->name) >= MAX_COLS) {
                        printf("\n");
+                       i = 0;
                }
-               printf("%s ", torture_ops[i].name);
+               i+=printf("%s ", o->name);
        }
        printf("\n\n");
 
@@ -2545,10 +2619,14 @@ 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};
+       init_module_fn static_init[] = STATIC_smbtorture_MODULES;
+       init_module_fn *shared_init = load_samba_modules(NULL, "torture");
+       
        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},
@@ -2574,6 +2652,16 @@ static void max_runtime_handler(int sig)
        setbuffer(stdout, NULL, 0);
 #endif
 
+       register_builtin_ops();
+
+       run_init_functions(static_init);
+       run_init_functions(shared_init);
+
+       talloc_free(shared_init);
+
+       /* we are never interested in SIGPIPE */
+       BlockSignals(True,SIGPIPE);
+
        pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, 
                            POPT_CONTEXT_KEEP_FIRST);
 
@@ -2596,6 +2684,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));
@@ -2614,8 +2705,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);