r9584: Fix a race condition in Samba 3. If two files are opened simultaneously with
[sfrench/samba-autobuild/.git] / source4 / torture / torture.c
index 4cc61bc288d9d4f52cbf941248b5708d6f60ad67..dde3c7bd5be145d0398a4ed4d813b7fab3ffc3e0 100644 (file)
@@ -76,16 +76,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;
@@ -102,7 +103,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);
 }
 
 
@@ -185,30 +186,22 @@ NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx,
 BOOL check_error(const char *location, struct smbcli_state *c, 
                 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
 {
-        if (smbcli_is_dos_error(c->tree)) {
-                uint8_t class;
-                uint32_t num;
-
-                /* Check DOS error */
-
-                smbcli_dos_error(c, &class, &num);
-
+       NTSTATUS status;
+       
+       status = smbcli_nt_error(c->tree);
+       if (NT_STATUS_IS_DOS(status)) {
+               int class, num;
+               class = NT_STATUS_DOS_CLASS(status);
+               num = NT_STATUS_DOS_CODE(status);
                 if (eclass != class || ecode != num) {
-                        printf("unexpected error code class=%d code=%d\n", 
-                               (int)class, (int)num);
-                        printf(" expected %d/%d %s (at %s)\n"
-                               (int)eclass, (int)ecode, nt_errstr(nterr), location);
+                        printf("unexpected error code %s\n", nt_errstr(status));
+                        printf(" expected %s or %s (at %s)\n", 
+                              nt_errstr(NT_STATUS_DOS(eclass, ecode))
+                               nt_errstr(nterr), location);
                         return False;
                 }
-
         } else {
-                NTSTATUS status;
-
-                /* Check NT error */
-
-                status = smbcli_nt_error(c->tree);
-
-                if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
+                if (!NT_STATUS_EQUAL(nterr, status)) {
                         printf("unexpected error code %s\n", nt_errstr(status));
                         printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
                         return False;
@@ -376,14 +369,14 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
 
                if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
                        printf("write failed (%s)\n", smbcli_errstr(c1->tree));
-                       printf("wrote %d, expected %d\n", bytes_written, buf_size); 
+                       printf("wrote %d, expected %d\n", (int)bytes_written, (int)buf_size); 
                        correct = False;
                        break;
                }
 
                if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
                        printf("read failed (%s)\n", smbcli_errstr(c2->tree));
-                       printf("read %d, expected %d\n", bytes_read, buf_size); 
+                       printf("read %d, expected %d\n", (int)bytes_read, (int)buf_size); 
                        correct = False;
                        break;
                }
@@ -550,6 +543,8 @@ static BOOL run_tcon_test(void)
        cli->tree = tree1;  /* restore initial tree */
        cli->tree->tid = cnum1;
 
+       smbcli_unlink(tree1, fname);
+
        if (!torture_close_connection(cli)) {
                return False;
        }
@@ -1352,9 +1347,10 @@ static BOOL run_vuidtest(void)
                correct = False;
        }
 
-       if ( (cli->transport->error.etype != ETYPE_DOS) ||
-            (cli->transport->error.e.dos.eclass != ERRSRV) ||
-            (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
+       if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
+                            NT_STATUS_DOS(ERRSRV, ERRbaduid)) &&
+           !NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
+                            NT_STATUS_INVALID_HANDLE)) {
                printf("ERROR: qfileinfo should have returned DOS error "
                       "ERRSRV:ERRbaduid\n  but returned %s\n",
                       smbcli_errstr(cli->tree));
@@ -1938,7 +1934,7 @@ BOOL torture_ioctl_test(void)
 
                        if (NT_STATUS_IS_OK(status)) {
                                printf("ioctl device=0x%x function=0x%x OK : %d bytes\n", 
-                                       device, function, parms.ioctl.out.blob.length);
+                                       device, function, (int)parms.ioctl.out.blob.length);
                        }
                }
        }
@@ -2009,7 +2005,7 @@ BOOL torture_chkpath_test(void)
        }
 
        if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
-               ret = check_error(__location__, cli, ERRDOS, ERRbadfile
+               ret = check_error(__location__, cli, ERRDOS, ERRbadpath
                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
        } else {
                printf("* chkpath on a non existent file should fail\n");
@@ -2073,7 +2069,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
        p = lp_parm_string(-1, "torture", "unclist");
        if (p) {
-               unc_list = file_lines_load(p, &num_unc_names);
+               unc_list = file_lines_load(p, &num_unc_names, NULL);
                if (!unc_list || num_unc_names <= 0) {
                        printf("Failed to load unc names list from '%s'\n", p);
                        exit(1);
@@ -2112,9 +2108,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)) {
@@ -2264,6 +2262,7 @@ static struct {
        {"RAW-RENAME", torture_raw_rename, 0},
        {"RAW-SEEK", torture_raw_seek, 0},
        {"RAW-EAS", torture_raw_eas, 0},
+       {"RAW-EAMAX", torture_max_eas, 0},
        {"RAW-STREAMS", torture_raw_streams, 0},
        {"RAW-ACLS", torture_raw_acls, 0},
        {"RAW-RAP", torture_raw_rap, 0},
@@ -2323,6 +2322,7 @@ static struct {
        {"LOCAL-BINDING", torture_local_binding_string, 0},
        {"LOCAL-IDTREE", torture_local_idtree, 0},
        {"LOCAL-SOCKET", torture_local_socket, 0},
+       {"LOCAL-PAC", torture_pac, 0},
 
        /* COM (Component Object Model) testers */
        {"COM-SIMPLE", torture_com_simple, 0 },
@@ -2341,9 +2341,15 @@ static struct {
        {"NET-USERINFO", torture_userinfo, 0},
        {"NET-USERADD", torture_useradd, 0},
        {"NET-USERDEL", torture_userdel, 0},
+       {"NET-USERMOD", torture_usermod, 0},
        {"NET-DOMOPEN", torture_domainopen, 0},
-       {"NET-LOOKUP", torture_lookup, 0},
+       {"NET-API-LOOKUP", torture_lookup, 0},
+       {"NET-API-LOOKUPHOST", torture_lookup_host, 0},
+       {"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}};