r890: convert samba4 to use [u]int8_t instead of [u]int8
[jelmer/samba4-debian.git] / source / torture / torture.c
index 09ab503274295a85cde09eb0566d05022c5861c2..7351f42c8b320a4de00727c27aa6ee16b5c7301f 100644 (file)
@@ -142,7 +142,7 @@ BOOL torture_close_connection(struct cli_state *c)
 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, 
                                const char *pipe_name,
                                const char *pipe_uuid, 
-                               uint32 pipe_version)
+                               uint32_t pipe_version)
 {
         NTSTATUS status;
        char *binding = lp_parm_string(-1, "torture", "binding");
@@ -170,11 +170,11 @@ NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
 
 /* check if the server produced the expected error code */
 static BOOL check_error(int line, struct cli_state *c, 
-                       uint8 eclass, uint32 ecode, NTSTATUS nterr)
+                       uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
 {
         if (cli_is_dos_error(c->tree)) {
-                uint8 class;
-                uint32 num;
+                uint8_t class;
+                uint32_t num;
 
                 /* Check DOS error */
 
@@ -206,7 +206,7 @@ static BOOL check_error(int line, struct cli_state *c,
 }
 
 
-static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
+static BOOL wait_lock(struct cli_state *c, int fnum, uint32_t offset, uint32_t len)
 {
        while (NT_STATUS_IS_ERR(cli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
                if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
@@ -330,7 +330,7 @@ static BOOL rw_torture3(struct cli_state *c, const char *lockfname)
        BOOL correct = True;
 
        srandom(1);
-       for (i = 0; i < sizeof(buf); i += sizeof(uint32))
+       for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
        {
                SIVAL(buf, i, sys_random());
        }
@@ -665,8 +665,8 @@ static BOOL run_tcon_test(int dummy)
        struct cli_state *cli;
        const char *fname = "\\tcontest.tmp";
        int fnum1;
-       uint16 cnum1, cnum2, cnum3;
-       uint16 vuid1, vuid2;
+       uint16_t cnum1, cnum2, cnum3;
+       uint16_t vuid1, vuid2;
        char buf[4];
        BOOL ret = True;
        struct cli_tree *tree1;
@@ -1031,10 +1031,10 @@ static BOOL run_locktest3(int dummy)
        struct cli_state *cli1, *cli2;
        const char *fname = "\\lockt3.lck";
        int fnum1, fnum2, i;
-       uint32 offset;
+       uint32_t offset;
        BOOL correct = True;
 
-#define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
+#define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops
 
        if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
                return False;
@@ -1489,6 +1489,8 @@ static BOOL run_locktest7(int dummy)
        struct cli_state *cli1;
        const char *fname = "\\lockt7.lck";
        int fnum1;
+       int fnum2;
+       size_t size;
        char buf[200];
        BOOL correct = False;
 
@@ -1603,11 +1605,38 @@ static BOOL run_locktest7(int dummy)
                goto fail;
        }
 
-       cli_unlock(cli1->tree, fnum1, 130, 0);
+       printf("Testing truncate of locked file.\n");
+
+       fnum2 = cli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
+
+       if (fnum2 == -1) {
+               printf("Unable to truncate locked file.\n");
+               correct = False;
+               goto fail;
+       } else {
+               printf("Truncated locked file.\n");
+       }
+
+       if (NT_STATUS_IS_ERR(cli_getatr(cli1->tree, fname, NULL, &size, NULL))) {
+               printf("getatr failed (%s)\n", cli_errstr(cli1->tree));
+               correct = False;
+               goto fail;
+       }
+
+       if (size != 0) {
+               printf("Unable to truncate locked file. Size was %u\n", size);
+               correct = False;
+               goto fail;
+       }
+
+       cli1->session->pid = 1;
+
+       cli_unlock(cli1->tree, fnum1, 130, 4);
        correct = True;
 
 fail:
        cli_close(cli1->tree, fnum1);
+       cli_close(cli1->tree, fnum2);
        cli_unlink(cli1->tree, fname);
        torture_close_connection(cli1);
 
@@ -2769,7 +2798,7 @@ static BOOL run_vuidtest(int dummy)
        time_t c_time, a_time, m_time, w_time, m_time2;
        BOOL correct = True;
 
-       uint16 orig_vuid;
+       uint16_t orig_vuid;
        NTSTATUS result;
 
        printf("starting vuid test\n");
@@ -3225,7 +3254,81 @@ error_test60:
        }
 
        printf("non-io open test #7 passed.\n");
+
 error_test70:
+
+       printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
+
+       cli_unlink(cli1->tree, fname);
+
+       fnum1 = cli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
+       if (fnum1 == -1) {
+               printf("(8) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1->tree));
+               return False;
+       }
+       
+       /* write 20 bytes. */
+       
+       memset(buf, '\0', 20);
+
+       if (cli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
+               printf("(8) write failed (%s)\n", cli_errstr(cli1->tree));
+               correct = False;
+       }
+
+       /* Ensure size == 20. */
+       if (NT_STATUS_IS_ERR(cli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
+               printf("(8) getatr (1) failed (%s)\n", cli_errstr(cli1->tree));
+               CHECK_MAX_FAILURES(error_test80);
+               return False;
+       }
+       
+       if (fsize != 20) {
+               printf("(8) file size != 20\n");
+               CHECK_MAX_FAILURES(error_test80);
+               return False;
+       }
+
+       /* Get an exclusive lock on the open file. */
+       if (NT_STATUS_IS_ERR(cli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
+               printf("(8) lock1 failed (%s)\n", cli_errstr(cli1->tree));
+               CHECK_MAX_FAILURES(error_test80);
+               return False;
+       }
+
+       fnum2 = cli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
+       if (fnum1 == -1) {
+               printf("(8) open (2) of %s with truncate failed (%s)\n", fname, cli_errstr(cli1->tree));
+               return False;
+       }
+
+       /* Ensure size == 0. */
+       if (NT_STATUS_IS_ERR(cli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
+               printf("(8) getatr (2) failed (%s)\n", cli_errstr(cli1->tree));
+               CHECK_MAX_FAILURES(error_test80);
+               return False;
+       }
+       
+       if (fsize != 0) {
+               printf("(8) file size != 0\n");
+               CHECK_MAX_FAILURES(error_test80);
+               return False;
+       }
+
+       if (NT_STATUS_IS_ERR(cli_close(cli1->tree, fnum1))) {
+               printf("(8) close1 failed (%s)\n", cli_errstr(cli1->tree));
+               return False;
+       }
+       
+       if (NT_STATUS_IS_ERR(cli_close(cli1->tree, fnum2))) {
+               printf("(8) close1 failed (%s)\n", cli_errstr(cli1->tree));
+               return False;
+       }
+       
+error_test80:
+
+       printf("open test #8 passed.\n");
+
        cli_unlink(cli1->tree, fname);
 
        if (!torture_close_connection(cli1)) {
@@ -3239,7 +3342,7 @@ error_test70:
 }
 
 
-static uint32 open_attrs_table[] = {
+static uint32_t open_attrs_table[] = {
                FILE_ATTRIBUTE_NORMAL,
                FILE_ATTRIBUTE_ARCHIVE,
                FILE_ATTRIBUTE_READONLY,
@@ -3261,9 +3364,9 @@ static uint32 open_attrs_table[] = {
 
 struct trunc_open_results {
        unsigned int num;
-       uint32 init_attr;
-       uint32 trunc_attr;
-       uint32 result_attr;
+       uint32_t init_attr;
+       uint32_t trunc_attr;
+       uint32_t result_attr;
 };
 
 static struct trunc_open_results attr_results[] = {
@@ -3301,7 +3404,7 @@ static BOOL run_openattrtest(int dummy)
        const char *fname = "\\openattr.file";
        int fnum1;
        BOOL correct = True;
-       uint16 attr;
+       uint16_t attr;
        unsigned int i, j, k, l;
        int failures = 0;
 
@@ -3311,7 +3414,7 @@ static BOOL run_openattrtest(int dummy)
                return False;
        }
        
-       for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
+       for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
                cli_setatr(cli1->tree, fname, 0, 0);
                cli_unlink(cli1->tree, fname);
                fnum1 = cli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
@@ -3493,7 +3596,7 @@ static void del_fn(file_info *finfo, const char *mask, void *state)
 BOOL torture_ioctl_test(int dummy)
 {
        struct cli_state *cli;
-       uint16 device, function;
+       uint16_t device, function;
        int fnum;
        const char *fname = "\\ioctl.dat";
        NTSTATUS status;
@@ -4037,6 +4140,7 @@ static struct {
         {"RPC-MGMT", torture_rpc_mgmt, 0},
         {"RPC-SCANNER", torture_rpc_scanner, 0},
         {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
+/*     {"NTLMSSP-SELFCHECK", torture_ntlmssp_self_check, 0},*/
        {NULL, NULL, 0}};
 
 
@@ -4097,7 +4201,7 @@ static BOOL run_test(const char *name)
 */
 static void parse_user(const char *user)
 {
-       char *username, *password, *p;
+       char *username, *password = NULL, *p;
 
        username = strdup(user);
        p = strchr_m(username,'%');
@@ -4107,9 +4211,17 @@ static void parse_user(const char *user)
        }
 
        lp_set_cmdline("torture:username", username);
-       lp_set_cmdline("torture:password", password);
-}
 
+       if (password) {
+               lp_set_cmdline("torture:password", password);
+       }
+
+       if (!lp_parm_string(-1,"torture","password")) {
+               password = getpass("password:");
+
+               lp_set_cmdline("torture:password", password);
+       }
+}
 
 static void usage(void)
 {
@@ -4279,6 +4391,10 @@ static void usage(void)
                }
        }
 
+       if (!lp_parm_string(-1,"torture","password")) {
+               lp_set_cmdline("torture:password", "");
+       }
+
        if (argc == optind) {
                printf("You must specify a test to run, or 'ALL'\n");
        } else {