s3:torture:delete: untangle function call from result check
[kai/samba.git] / source3 / torture / torture.c
index bad398618847538a9da0e8ba1f0501e2114140e6..6ba228460f72e0344399f8e33715895a04dcc5dd 100644 (file)
@@ -72,61 +72,6 @@ bool torture_showall = False;
 
 static double create_procs(bool (*fn)(int), bool *result);
 
-
-/* return a pointer to a anonymous shared memory segment of size "size"
-   which will persist across fork() but will disappear when all processes
-   exit 
-
-   The memory is not zeroed 
-
-   This function uses system5 shared memory. It takes advantage of a property
-   that the memory is not destroyed if it is attached when the id is removed
-   */
-void *shm_setup(int size)
-{
-       int shmid;
-       void *ret;
-
-#ifdef __QNXNTO__
-       shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
-       if (shmid == -1) {
-               printf("can't get shared memory\n");
-               exit(1);
-       }
-       shm_unlink("private");
-       if (ftruncate(shmid, size) == -1) {
-               printf("can't set shared memory size\n");
-               exit(1);
-       }
-       ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
-       if (ret == MAP_FAILED) {
-               printf("can't map shared memory\n");
-               exit(1);
-       }
-#else
-       shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
-       if (shmid == -1) {
-               printf("can't get shared memory\n");
-               exit(1);
-       }
-       ret = (void *)shmat(shmid, 0, 0);
-       if (!ret || ret == (void *)-1) {
-               printf("can't attach to shared memory\n");
-               return NULL;
-       }
-       /* the following releases the ipc, but note that this process
-          and all its children will still have access to the memory, its
-          just that the shmid is no longer valid for other shm calls. This
-          means we don't leave behind lots of shm segments after we exit 
-
-          See Stevens "advanced programming in unix env" for details
-          */
-       shmctl(shmid, IPC_RMID, 0);
-#endif
-
-       return ret;
-}
-
 /********************************************************************
  Ensure a connection is encrypted.
 ********************************************************************/
@@ -2580,7 +2525,7 @@ static void alarm_handler(int dummy)
 
 static void alarm_handler_parent(int dummy)
 {
-       cli_state_disconnect(alarm_cli);
+       smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_OK);
 }
 
 static void do_local_lock(int read_fd, int write_fd)
@@ -3053,7 +2998,8 @@ static bool run_negprot_nowait(int dummy)
        for (i=0;i<50000;i++) {
                struct tevent_req *req;
 
-               req = cli_negprot_send(ev, ev, cli, PROTOCOL_NT1);
+               req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout,
+                                          PROTOCOL_CORE, PROTOCOL_NT1);
                if (req == NULL) {
                        TALLOC_FREE(ev);
                        return false;
@@ -3554,7 +3500,7 @@ static bool run_oplock2(int dummy)
        size_t nread;
        NTSTATUS status;
 
-       shared_correct = (volatile bool *)shm_setup(sizeof(bool));
+       shared_correct = (volatile bool *)anonymous_shared_allocate(sizeof(bool));
        *shared_correct = True;
 
        use_level_II_oplocks = True;
@@ -4004,8 +3950,11 @@ static bool run_deletetest(int dummy)
        /* This should fail with a sharing violation - open for delete is only compatible
           with SHARE_DELETE. */
 
-       if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                       FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL,
+                             FILE_SHARE_READ|FILE_SHARE_WRITE,
+                             FILE_OPEN, 0, 0, &fnum2);
+       if (NT_STATUS_IS_OK(status)) {
                printf("[3] open  - 2 of %s succeeded - should have failed.\n", fname);
                correct = False;
                goto fail;
@@ -4045,7 +3994,8 @@ static bool run_deletetest(int dummy)
 
        /* This should fail - file should no longer be there. */
 
-       if (NT_STATUS_IS_OK(cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
+       status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
+       if (NT_STATUS_IS_OK(status)) {
                printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
                status = cli_close(cli1, fnum1);
                if (!NT_STATUS_IS_OK(status)) {
@@ -5401,6 +5351,13 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
+       /* Ensure st_mode == 0600 */
+       if ((sbuf.st_ex_mode & 07777) != 0600) {
+               printf("posix_open - bad permissions 0%o != 0600\n",
+                               (unsigned int)(sbuf.st_ex_mode & 07777));
+               goto out;
+       }
+
        /* Test ftruncate - set file size back to zero. */
        status = cli_ftruncate(cli1, fnum1, 0);
        if (!NT_STATUS_IS_OK(status)) {
@@ -5631,6 +5588,26 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
+       /* Check directory opens with a specific permission. */
+       status = cli_posix_mkdir(cli1, dname, 0700);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure st_mode == 0700 */
+       status = cli_posix_stat(cli1, dname, &sbuf);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("stat failed (%s)\n", nt_errstr(status));
+               goto out;
+       }
+
+       if ((sbuf.st_ex_mode & 07777) != 0700) {
+               printf("posix_mkdir - bad permissions 0%o != 0700\n",
+                               (unsigned int)(sbuf.st_ex_mode & 07777));
+               goto out;
+       }
+
        printf("Simple POSIX open test passed\n");
        correct = true;
 
@@ -6043,7 +6020,7 @@ bool torture_chkpath_test(int dummy)
                ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
        } else {
-               printf("* chkpath on a non existant file should fail\n");
+               printf("* chkpath on a non existent file should fail\n");
                ret = False;
        }
 
@@ -6183,10 +6160,10 @@ static bool run_eatest(int dummy)
                correct = False;
        }
 
-       /* Try and delete a non existant EA. */
+       /* Try and delete a non existent EA. */
        status = cli_set_ea_path(cli, fname, "foo", "", 0);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("deleting non-existant EA 'foo' should succeed. %s\n",
+               printf("deleting non-existent EA 'foo' should succeed. %s\n",
                       nt_errstr(status));
                correct = False;
        }
@@ -6307,7 +6284,8 @@ static bool run_error_map_extract(int dummy) {
        }
        disable_spnego = false;
 
-       status = cli_negprot(c_nt, PROTOCOL_NT1);
+       status = smbXcli_negprot(c_nt->conn, c_nt->timeout, PROTOCOL_CORE,
+                                PROTOCOL_NT1);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("%s rejected the NT-error negprot (%s)\n", host,
@@ -6334,7 +6312,8 @@ static bool run_error_map_extract(int dummy) {
        disable_spnego = false;
        force_dos_errors = false;
 
-       status = cli_negprot(c_dos, PROTOCOL_NT1);
+       status = smbXcli_negprot(c_dos->conn, c_dos->timeout, PROTOCOL_CORE,
+                                PROTOCOL_NT1);
        if (!NT_STATUS_IS_OK(status)) {
                printf("%s rejected the DOS-error negprot (%s)\n", host,
                       nt_errstr(status));
@@ -6537,7 +6516,7 @@ static bool run_chain1(int dummy)
        if (reqs[2] == NULL) return false;
        tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
 
-       status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
+       status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
@@ -6593,7 +6572,7 @@ static bool run_chain2(int dummy)
        if (reqs[1] == NULL) return false;
        tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
 
-       status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
+       status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
@@ -8626,7 +8605,7 @@ static bool run_local_dbtrans(int dummy)
                        break;
                }
 
-               status = dbwrap_fetch_uint32(db, "transtest", &val);
+               status = dbwrap_fetch_uint32_bystring(db, "transtest", &val);
                if (!NT_STATUS_IS_OK(status)) {
                        printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
                               nt_errstr(status));
@@ -8639,7 +8618,7 @@ static bool run_local_dbtrans(int dummy)
                        }
                }
 
-               status = dbwrap_fetch_uint32(db, "transtest", &val2);
+               status = dbwrap_fetch_uint32_bystring(db, "transtest", &val2);
                if (!NT_STATUS_IS_OK(status)) {
                        printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
                               nt_errstr(status));
@@ -8841,13 +8820,13 @@ static double create_procs(bool (*fn)(int), bool *result)
 
        synccount = 0;
 
-       child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
+       child_status = (volatile pid_t *)anonymous_shared_allocate(sizeof(pid_t)*torture_nprocs);
        if (!child_status) {
                printf("Failed to setup shared memory\n");
                return -1;
        }
 
-       child_status_out = (volatile bool *)shm_setup(sizeof(bool)*torture_nprocs);
+       child_status_out = (volatile bool *)anonymous_shared_allocate(sizeof(bool)*torture_nprocs);
        if (!child_status_out) {
                printf("Failed to setup result status shared memory\n");
                return -1;