lib: Make sid_parse return the parsed length
[samba.git] / source3 / torture / torture.c
index c4c8754bcb4497c0e919a0b16cd141e46aa574ec..7a209859b3f86c52e2f719566b9f17fa7dd5c82d 100644 (file)
@@ -7256,6 +7256,207 @@ static bool run_posix_ofd_lock_test(int dummy)
        return correct;
 }
 
+/*
+  Test POSIX mkdir is case-sensitive.
+ */
+static bool run_posix_mkdir_test(int dummy)
+{
+       static struct cli_state *cli;
+       const char *fname_foo = "POSIX_foo";
+       const char *fname_foo_Foo = "POSIX_foo/Foo";
+       const char *fname_foo_foo = "POSIX_foo/foo";
+       const char *fname_Foo = "POSIX_Foo";
+       const char *fname_Foo_Foo = "POSIX_Foo/Foo";
+       const char *fname_Foo_foo = "POSIX_Foo/foo";
+       bool correct = false;
+       NTSTATUS status;
+       TALLOC_CTX *frame = NULL;
+       uint16_t fnum = (uint16_t)-1;
+
+       frame = talloc_stackframe();
+
+       printf("Starting POSIX mkdir test\n");
+
+       if (!torture_open_connection(&cli, 0)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+       status = torture_setup_unix_extensions(cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       cli_posix_rmdir(cli, fname_foo_foo);
+       cli_posix_rmdir(cli, fname_foo_Foo);
+       cli_posix_rmdir(cli, fname_foo);
+
+       cli_posix_rmdir(cli, fname_Foo_foo);
+       cli_posix_rmdir(cli, fname_Foo_Foo);
+       cli_posix_rmdir(cli, fname_Foo);
+
+       /*
+        * Create a file POSIX_foo then try
+        * and use it in a directory path by
+        * doing mkdir POSIX_foo/bar.
+        * The mkdir should fail with
+        * NT_STATUS_OBJECT_PATH_NOT_FOUND
+        */
+
+       status = cli_posix_open(cli,
+                       fname_foo,
+                       O_RDWR|O_CREAT,
+                       0666,
+                       &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_open of %s failed error %s\n",
+                       fname_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_foo_foo, 0777);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
+               printf("cli_posix_mkdir of %s should fail with "
+                       "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
+                       "%s instead\n",
+                       fname_foo_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_close failed %s\n", nt_errstr(status));
+               goto out;
+       }
+       fnum = (uint16_t)-1;
+
+       status = cli_posix_unlink(cli, fname_foo);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_unlink of %s failed error %s\n",
+                       fname_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /*
+        * Now we've deleted everything, posix_mkdir, posix_rmdir,
+        * posix_open, posix_unlink, on
+        * POSIX_foo/foo should return NT_STATUS_OBJECT_PATH_NOT_FOUND
+        * not silently create POSIX_foo/foo.
+        */
+
+       status = cli_posix_mkdir(cli, fname_foo_foo, 0777);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
+               printf("cli_posix_mkdir of %s should fail with "
+                       "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
+                       "%s instead\n",
+                       fname_foo_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_posix_rmdir(cli, fname_foo_foo);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
+               printf("cli_posix_rmdir of %s should fail with "
+                       "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
+                       "%s instead\n",
+                       fname_foo_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_posix_open(cli,
+                       fname_foo_foo,
+                       O_RDWR|O_CREAT,
+                       0666,
+                       &fnum);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
+               printf("cli_posix_open of %s should fail with "
+                       "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
+                       "%s instead\n",
+                       fname_foo_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_posix_unlink(cli, fname_foo_foo);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
+               printf("cli_posix_unlink of %s should fail with "
+                       "NT_STATUS_OBJECT_PATH_NOT_FOUND got "
+                       "%s instead\n",
+                       fname_foo_foo,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_foo, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed\n", fname_foo);
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_Foo, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed\n", fname_Foo);
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_foo_foo, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed\n", fname_foo_foo);
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_foo_Foo, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed\n", fname_foo_Foo);
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_Foo_foo, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed\n", fname_Foo_foo);
+               goto out;
+       }
+
+       status = cli_posix_mkdir(cli, fname_Foo_Foo, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed\n", fname_Foo_Foo);
+               goto out;
+       }
+
+       printf("POSIX mkdir test passed\n");
+       correct = true;
+
+  out:
+
+       if (fnum != (uint16_t)-1) {
+               cli_close(cli, fnum);
+               fnum = (uint16_t)-1;
+       }
+
+       cli_posix_rmdir(cli, fname_foo_foo);
+       cli_posix_rmdir(cli, fname_foo_Foo);
+       cli_posix_rmdir(cli, fname_foo);
+
+       cli_posix_rmdir(cli, fname_Foo_foo);
+       cli_posix_rmdir(cli, fname_Foo_Foo);
+       cli_posix_rmdir(cli, fname_Foo);
+
+       if (!torture_close_connection(cli)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
+
+
 static uint32_t open_attrs_table[] = {
                FILE_ATTRIBUTE_NORMAL,
                FILE_ATTRIBUTE_ARCHIVE,
@@ -10677,6 +10878,7 @@ static bool run_local_sid_to_string(int dummy) {
 }
 
 static bool run_local_binary_to_sid(int dummy) {
+       struct sid_parse_ret ret;
        struct dom_sid *sid = talloc(NULL, struct dom_sid);
        static const uint8_t good_binary_sid[] = {
                0x1, /* revision number */
@@ -10761,13 +10963,16 @@ static bool run_local_binary_to_sid(int dummy) {
                0x1, 0x1, 0x1, 0x1, /* auth[31] */
        };
 
-       if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
+       ret = sid_parse(good_binary_sid, sizeof(good_binary_sid), sid);
+       if (ret.len == -1) {
                return false;
        }
-       if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
+       ret = sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid);
+       if (ret.len != -1) {
                return false;
        }
-       if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
+       ret = sid_parse(long_binary_sid, sizeof(long_binary_sid), sid);
+       if (ret.len != -1) {
                return false;
        }
        return true;
@@ -11895,6 +12100,10 @@ static struct {
                .name  = "POSIX-OFD-LOCK",
                .fn    = run_posix_ofd_lock_test,
        },
+       {
+               .name  = "POSIX-MKDIR",
+               .fn    = run_posix_mkdir_test,
+       },
        {
                .name  = "WINDOWS-BAD-SYMLINK",
                .fn    = run_symlink_open_test,
@@ -12329,6 +12538,10 @@ static struct {
                .name  = "LOCAL-NAMEMAP-CACHE1",
                .fn    = run_local_namemap_cache1,
        },
+       {
+               .name  = "LOCAL-IDMAP-CACHE1",
+               .fn    = run_local_idmap_cache1,
+       },
        {
                .name  = "qpathinfo-bufsize",
                .fn    = run_qpathinfo_bufsize,