r6907: Unixinfo for samba4, not activated by default.
[samba.git] / source / torture / torture.c
index b7ca730d1f316b8abd7560be1a2effc10fe0a70b..f5e52c53581489bff6a3635667b848d888a458e2 100644 (file)
@@ -80,16 +80,11 @@ BOOL torture_open_connection_share(struct smbcli_state **c,
                                   const char *sharename)
 {
        NTSTATUS status;
-       const char *username = lp_parm_string(-1, "torture", "username");
-       const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
-       const char *password = lp_parm_string(-1, "torture", "password");
 
        status = smbcli_full_connection(NULL,
-                                       c, lp_netbios_name(),
-                                       hostname, 
+                                       c, hostname, 
                                        sharename, NULL,
-                                       username, username[0]?userdomain:"",
-                                       password);
+                                       cmdline_credentials);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to open connection - %s\n", nt_errstr(status));
                return False;
@@ -123,18 +118,9 @@ BOOL torture_close_connection(struct smbcli_state *c)
        return ret;
 }
 
-/* initialise a DCOM context */
-NTSTATUS torture_dcom_init(struct dcom_context **ctx)
-{
-       dcom_init(ctx, lp_parm_string(-1, "torture", "userdomain"),
-                                       lp_parm_string(-1, "torture", "username"), 
-                                       lp_parm_string(-1, "torture", "password"));
-
-       return NT_STATUS_OK;
-}
-
 /* open a rpc connection to the chosen binding string */
-NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, 
+NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
+                               struct dcerpc_pipe **p, 
                                const char *pipe_name,
                                const char *pipe_uuid, 
                                uint32_t pipe_version)
@@ -147,16 +133,16 @@ NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
-                                    lp_parm_string(-1, "torture", "userdomain"), 
-                                    lp_parm_string(-1, "torture", "username"),
-                                    lp_parm_string(-1, "torture", "password"));
+       status = dcerpc_pipe_connect(parent_ctx, 
+                                    p, binding, pipe_uuid, pipe_version,
+                                    cmdline_credentials);
  
         return status;
 }
 
 /* open a rpc connection to a specific transport */
-NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p, 
+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,
@@ -164,11 +150,12 @@ NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
 {
         NTSTATUS status;
        const char *binding = lp_parm_string(-1, "torture", "binding");
-       struct dcerpc_binding b;
-       TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
+       struct dcerpc_binding *b;
+       TALLOC_CTX *mem_ctx = talloc_named(parent_ctx, 0, "torture_rpc_connection_smb");
 
        if (!binding) {
                printf("You must specify a ncacn binding string\n");
+               talloc_free(mem_ctx);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -179,24 +166,20 @@ NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
                return status;
        }
 
-       b.transport = transport;
+       b->transport = transport;
 
-       status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
-                                      lp_parm_string(-1, "torture", "userdomain"), 
-                                      lp_parm_string(-1, "torture", "username"),
-                                      lp_parm_string(-1, "torture", "password"));
+       status = dcerpc_pipe_connect_b(mem_ctx, p, b, pipe_uuid, pipe_version,
+                                                                  cmdline_credentials);
+                                          
+       if (NT_STATUS_IS_OK(status)) {
+               *p = talloc_reference(parent_ctx, *p);
+       } else {
+               *p = NULL;
+       }
+       talloc_free(mem_ctx);
         return status;
 }
 
-/* close a rpc connection to a named pipe */
-NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
-{
-       dcerpc_pipe_close(p);
-       return NT_STATUS_OK;
-}
-
-
 /* check if the server produced the expected error code */
 BOOL check_error(const char *location, struct smbcli_state *c, 
                 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
@@ -347,104 +330,6 @@ static BOOL run_torture(struct smbcli_state *cli, int dummy)
        return ret;
 }
 
-static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
-{
-       int fnum = -1;
-       uint_t i = 0;
-       uint8_t buf[131072];
-       uint8_t buf_rd[131072];
-       uint_t count;
-       uint_t countprev = 0;
-       ssize_t sent = 0;
-       BOOL correct = True;
-
-       for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
-       {
-               SIVAL(buf, i, random());
-       }
-
-       if (procnum == 0)
-       {
-               fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                               DENY_NONE);
-               if (fnum == -1) {
-                       printf("first open read/write of %s failed (%s)\n",
-                                       lockfname, smbcli_errstr(c->tree));
-                       return False;
-               }
-       }
-       else
-       {
-               for (i = 0; i < 500 && fnum == -1; i++)
-               {
-                       fnum = smbcli_open(c->tree, lockfname, O_RDONLY, 
-                                       DENY_NONE);
-                       msleep(10);
-               }
-               if (fnum == -1) {
-                       printf("second open read-only of %s failed (%s)\n",
-                                       lockfname, smbcli_errstr(c->tree));
-                       return False;
-               }
-       }
-
-       i = 0;
-       for (count = 0; count < sizeof(buf); count += sent)
-       {
-               if (count >= countprev) {
-                       printf("%d %8d\r", i, count);
-                       fflush(stdout);
-                       i++;
-                       countprev += (sizeof(buf) / 20);
-               }
-
-               if (procnum == 0)
-               {
-                       sent = ((uint_t)random()%(20))+ 1;
-                       if (sent > sizeof(buf) - count)
-                       {
-                               sent = sizeof(buf) - count;
-                       }
-
-                       if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
-                               printf("write failed (%s)\n", smbcli_errstr(c->tree));
-                               correct = False;
-                       }
-               }
-               else
-               {
-                       sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
-                                       sizeof(buf)-count);
-                       if (sent < 0)
-                       {
-                               printf("read failed offset:%d size:%d (%s)\n",
-                                               count, sizeof(buf)-count,
-                                               smbcli_errstr(c->tree));
-                               correct = False;
-                               sent = 0;
-                       }
-                       if (sent > 0)
-                       {
-                               if (memcmp(buf_rd+count, buf+count, sent) != 0)
-                               {
-                                       printf("read/write compare failed\n");
-                                       printf("offset: %d req %d recvd %d\n",
-                                               count, sizeof(buf)-count, sent);
-                                       correct = False;
-                                       break;
-                               }
-                       }
-               }
-
-       }
-
-       if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
-               printf("close failed (%s)\n", smbcli_errstr(c->tree));
-               correct = False;
-       }
-
-       return correct;
-}
 
 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
 {
@@ -527,6 +412,8 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
        return correct;
 }
 
+#define BOOLSTR(b) ((b) ? "Yes" : "No")
+
 static BOOL run_readwritetest(void)
 {
        struct smbcli_state *cli1, *cli2;
@@ -557,20 +444,6 @@ static BOOL run_readwritetest(void)
        return (test1 && test2);
 }
 
-static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
-{
-       BOOL test;
-
-       test = rw_torture3(cli, "\\multitest.txt");
-
-       if (!torture_close_connection(cli)) {
-               test = False;
-       }
-       
-       return test;
-}
-
-
 /*
   this checks to see if a secondary tconx can use open files from an
   earlier tconx
@@ -737,16 +610,11 @@ static BOOL run_tcon_devtype_test(void)
        BOOL ret = True;
        const char *host = lp_parm_string(-1, "torture", "host");
        const char *share = lp_parm_string(-1, "torture", "share");
-       const char *username = lp_parm_string(-1, "torture", "username");
-       const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
-       const char *password = lp_parm_string(-1, "torture", "password");
        
        status = smbcli_full_connection(NULL,
-                                       &cli1, lp_netbios_name(),
-                                       host, 
+                                       &cli1, host, 
                                        share, NULL,
-                                       username, userdomain,
-                                       password);
+                                       cmdline_credentials);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("could not open connection\n");
@@ -2324,7 +2192,6 @@ static struct {
        {"BASE-TCONDEV",  run_tcon_devtype_test, 0},
        {"BASE-VUID", run_vuidtest, 0},
        {"BASE-RW1",  run_readwritetest, 0},
-       {"BASE-RW2",  NULL, run_readwritemulti},
        {"BASE-OPEN", run_opentest, 0},
        {"BASE-DEFER_OPEN", NULL, run_deferopen},
        {"BASE-XCOPY", run_xcopy, 0},
@@ -2344,6 +2211,9 @@ static struct {
        {"BENCH-NBENCH",  torture_nbench, 0},
        {"BENCH-TORTURE", NULL, run_torture},
        {"BENCH-NBT",     torture_bench_nbt, 0},
+       {"BENCH-WINS",    torture_bench_wins, 0},
+       {"BENCH-RPC",     torture_bench_rpc, 0},
+       {"BENCH-CLDAP",   torture_bench_cldap, 0},
 
        /* RAW smb tests */
        {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
@@ -2390,6 +2260,7 @@ static struct {
         {"RPC-DFS", torture_rpc_dfs, 0},
         {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
         {"RPC-SAMR", torture_rpc_samr, 0},
+        {"RPC-UNIXINFO", torture_rpc_unixinfo, 0},
         {"RPC-NETLOGON", torture_rpc_netlogon, 0},
         {"RPC-SAMLOGON", torture_rpc_samlogon, 0},
         {"RPC-SAMSYNC", torture_rpc_samsync, 0},
@@ -2401,6 +2272,7 @@ static struct {
         {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
         {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
         {"RPC-WINREG", torture_rpc_winreg, 0},
+        {"RPC-INITSHUTDOWN", torture_rpc_initshutdown, 0},
         {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
         {"RPC-REMACT", torture_rpc_remact, 0},
         {"RPC-MGMT", torture_rpc_mgmt, 0},
@@ -2414,9 +2286,6 @@ static struct {
        {"RPC-DSSETUP", torture_rpc_dssetup, 0},
         {"RPC-ALTERCONTEXT", torture_rpc_alter_context, 0},
 
-       /* Distributed COM testers */
-       {"DCOM-SIMPLE", torture_dcom_simple, 0},
-
        /* local (no server) testers */
        {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
        {"LOCAL-ICONV", torture_local_iconv, 0},
@@ -2426,12 +2295,23 @@ static struct {
        {"LOCAL-IDTREE", torture_local_idtree, 0},
        {"LOCAL-SOCKET", torture_local_socket, 0},
 
+       /* COM (Component Object Model) testers */
+       {"COM-SIMPLE", torture_com_simple, 0 },
+
        /* ldap testers */
        {"LDAP-BASIC", torture_ldap_basic, 0},
+       {"LDAP-CLDAP", torture_cldap, 0},
 
        /* 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},
+       
+       /* libnet tests */
+       {"NET-USERINFO", torture_userinfo, 0},
+       {"NET-USERADD", torture_useradd, 0},
+       {"NET-USERDEL", torture_userdel, 0},
 
        {NULL, NULL, 0}};
 
@@ -2599,7 +2479,7 @@ static void usage(poptContext pc)
 static BOOL is_binding_string(const char *binding_string)
 {
        TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
-       struct dcerpc_binding binding_struct;
+       struct dcerpc_binding *binding_struct;
        NTSTATUS status;
        
        status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
@@ -2649,7 +2529,7 @@ static BOOL is_binding_string(const char *binding_string)
 #endif
 
        pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, 
-                               POPT_CONTEXT_KEEP_FIRST);
+                           POPT_CONTEXT_KEEP_FIRST);
 
        poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
 
@@ -2728,25 +2608,6 @@ static BOOL is_binding_string(const char *binding_string)
                lp_set_cmdline("torture:binding", binding);
        }
 
-       if (!lp_parm_string(-1,"torture","username")) {
-               lp_set_cmdline("torture:username", cmdline_get_username());
-       }
-       if (!lp_parm_string(-1,"torture","userdomain")) {
-               /* 
-                * backward compatibility
-                * maybe we should remove this to make this consistent
-                * for all cmdline tools
-                * --metze
-                */
-               if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
-                       cmdline_set_userdomain(lp_workgroup());
-               }
-               lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
-       }
-       if (!lp_parm_string(-1,"torture","password")) {
-               lp_set_cmdline("torture:password", cmdline_get_userpassword());
-       }
-
        if (argc_new == 0) {
                printf("You must specify a test to run, or 'ALL'\n");
        } else {