signed DCERPC over TCP now works !
[jra/samba/.git] / source4 / torture / torture.c
index fca54de64efa422c905d83c449366ab036cf1540..11b27f12ebfb227d7de37e4d0daea27c8be3ccb5 100644 (file)
@@ -26,7 +26,6 @@ int torture_entries=1000;
 int torture_failures=1;
 static int procnum; /* records process count number when forking */
 static struct cli_state *current_cli;
-static char *randomfname;
 static BOOL use_oplocks;
 static BOOL use_level_II_oplocks;
 static const char *client_txt = "client_oplocks.txt";
@@ -131,6 +130,42 @@ BOOL torture_close_connection(struct cli_state *c)
        return ret;
 }
 
+/* open a rpc connection to a named pipe */
+static NTSTATUS torture_rpc_tcp(struct dcerpc_pipe **p, 
+                               const char *pipe_name,
+                               const char *pipe_uuid, 
+                               uint32 pipe_version)
+{
+        NTSTATUS status;
+       char *host = lp_parm_string(-1, "torture", "host");
+       const char *port = lp_parm_string(-1, "torture", "share");
+
+       DEBUG(2,("Connecting to dcerpc server %s:%s\n", host, port));
+
+       status = dcerpc_pipe_open_tcp(p, host, atoi(port));
+       if (!NT_STATUS_IS_OK(status)) {
+                printf("Open of pipe '%s' failed with error (%s)\n",
+                      pipe_name, nt_errstr(status));
+                return status;
+        }
+
+       /* always do NDR validation in smbtorture */
+       (*p)->flags |= DCERPC_DEBUG_VALIDATE_BOTH;
+
+       /* bind to the pipe, using the uuid as the key */
+       status = dcerpc_bind_auth_ntlm(*p, pipe_uuid, pipe_version,
+                                      lp_workgroup(),
+                                      lp_parm_string(-1, "torture", "username"),
+                                      lp_parm_string(-1, "torture", "password"));
+       if (!NT_STATUS_IS_OK(status)) {
+               dcerpc_pipe_close(*p);
+               return status;
+       }
+        return status;
+}
+
+
 /* open a rpc connection to a named pipe */
 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, 
                                const char *pipe_name,
@@ -139,21 +174,49 @@ NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
 {
         struct cli_state *cli;
         NTSTATUS status;
+       char *transport = lp_parm_string(-1, "torture", "transport");
+
+       if (strcmp(transport, "ncacn_ip_tcp") == 0) {
+               return torture_rpc_tcp(p, pipe_name, pipe_uuid, pipe_version);
+       }
+
+       if (strcmp(transport, "ncacn_np") != 0) {
+               printf("Unsupported RPC transport '%s'\n", transport);
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       if (! *lp_parm_string(-1, "torture", "share")) {
+               lp_set_cmdline("torture:share", "ipc$");
+       }
 
        if (!torture_open_connection(&cli)) {
                 return NT_STATUS_UNSUCCESSFUL;
        }
 
-        if (!(*p = dcerpc_pipe_init(cli->tree))) {
-                return NT_STATUS_NO_MEMORY;
-       }
-       status = dcerpc_pipe_open_smb(*p, pipe_name, pipe_uuid, pipe_version);
+       status = dcerpc_pipe_open_smb(p, cli->tree, pipe_name);
        if (!NT_STATUS_IS_OK(status)) {
                 printf("Open of pipe '%s' failed with error (%s)\n",
                       pipe_name, nt_errstr(status));
+               torture_close_connection(cli);
                 return status;
         }
+
+       /* bind to the pipe, using the uuid as the key */
+#if 1
+       status = dcerpc_bind_auth_ntlm(*p, pipe_uuid, pipe_version,
+                                      lp_workgroup(),
+                                      lp_parm_string(-1, "torture", "username"),
+                                      lp_parm_string(-1, "torture", "password"));
+#else
+       status = dcerpc_bind_auth_none(*p, pipe_uuid, pipe_version);
+#endif
+       if (!NT_STATUS_IS_OK(status)) {
+               dcerpc_pipe_close(*p);
+               return status;
+       }
+
+       /* always do NDR validation in smbtorture */
+       (*p)->flags |= DCERPC_DEBUG_VALIDATE_BOTH;
  
         return status;
 }
@@ -161,17 +224,8 @@ NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
 /* close a rpc connection to a named pipe */
 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
 {
-       union smb_close io;
-       NTSTATUS status;
-
-       io.close.level = RAW_CLOSE_CLOSE;
-       io.close.in.fnum = p->fnum;
-       io.close.in.write_time = 0;
-       status = smb_raw_close(p->tree, &io);
-
        dcerpc_pipe_close(p);
-
-       return status;
+       return NT_STATUS_OK;
 }
 
 
@@ -328,7 +382,7 @@ static BOOL run_torture(int dummy)
        return ret;
 }
 
-static BOOL rw_torture3(struct cli_state *c, char *lockfname)
+static BOOL rw_torture3(struct cli_state *c, const char *lockfname)
 {
        int fnum = -1;
        unsigned int i = 0;
@@ -546,8 +600,7 @@ static BOOL run_readwritemulti(int dummy)
 
        cli = current_cli;
 
-       printf("run_readwritemulti: fname %s\n", randomfname);
-       test = rw_torture3(cli, randomfname);
+       test = rw_torture3(cli, "\\multitest.txt");
 
        if (!torture_close_connection(cli)) {
                test = False;
@@ -3994,6 +4047,11 @@ static struct {
         {"RPC-SAMR", torture_rpc_samr, 0},
         {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
         {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
+        {"RPC-ATSVC", torture_rpc_atsvc, 0},
+        {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
+        {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
+        {"RPC-WINREG", torture_rpc_winreg, 0},
+        {"RPC-MGMT", torture_rpc_mgmt, 0},
        {NULL, NULL, 0}};
 
 
@@ -4017,9 +4075,6 @@ static BOOL run_test(const char *name)
        }
 
        for (i=0;torture_ops[i].name;i++) {
-               asprintf(&randomfname, "\\XX%x", 
-                        (unsigned)random());
-
                if (gen_fnmatch(name, torture_ops[i].name) == 0) {
                        double t;
                        matched = True;
@@ -4133,27 +4188,50 @@ static void usage(void)
         for(p = argv[1]; *p; p++)
           if(*p == '\\')
             *p = '/';
-       if (strncmp(argv[1], "//", 2)) {
-               usage();
-       }
 
-       host = strdup(&argv[1][2]);
-       p = strchr_m(&host[2],'/');
-       if (!p) {
-               usage();
+
+       /* see if its a RPC transport specifier */
+       if (strncmp(argv[1], "ncacn", 5) == 0) {
+               char *transport = strdup(argv[1]);
+               p = strchr_m(transport, ':');
+               if (!p) usage();
+               *p = 0;
+               host = p+1;
+               p = strchr_m(host, ':');
+               if (p) {
+                       *p = 0;
+                       share = p+1;
+                       lp_set_cmdline("torture:share", share);
+               } else {
+                       share = "";
+                       lp_set_cmdline("torture:share", share);
+               }
+               lp_set_cmdline("torture:host", host);
+               lp_set_cmdline("torture:transport", transport);
+       } else {
+               if (strncmp(argv[1], "//", 2)) {
+                       usage();
+               }
+
+               host = strdup(&argv[1][2]);
+               p = strchr_m(&host[2],'/');
+               if (!p) {
+                       usage();
+               }
+               *p = 0;
+               share = strdup(p+1);
+               
+               lp_set_cmdline("torture:host", host);
+               lp_set_cmdline("torture:share", share);
+               lp_set_cmdline("torture:password", "");
+               lp_set_cmdline("torture:transport", "ncacn_np");
        }
-       *p = 0;
-       share = strdup(p+1);
 
        if (getenv("LOGNAME")) {
                username = strdup(getenv("LOGNAME"));
        }
-
-       lp_set_cmdline("torture:host", host);
-       lp_set_cmdline("torture:share", share);
        lp_set_cmdline("torture:username", username);
-       lp_set_cmdline("torture:password", "");
+
 
        argc--;
        argv++;