| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 sub_dir_ = base_dir_.AppendASCII("sub_dir"); | 1860 sub_dir_ = base_dir_.AppendASCII("sub_dir"); |
| 1861 ASSERT_TRUE(file_util::CreateDirectory(sub_dir_)); | 1861 ASSERT_TRUE(file_util::CreateDirectory(sub_dir_)); |
| 1862 | 1862 |
| 1863 text_file_ = sub_dir_.AppendASCII("file.txt"); | 1863 text_file_ = sub_dir_.AppendASCII("file.txt"); |
| 1864 CreateTextFile(text_file_, L"This text file has some text in it."); | 1864 CreateTextFile(text_file_, L"This text file has some text in it."); |
| 1865 | 1865 |
| 1866 // Get the user and group files are created with from |base_dir_|. | 1866 // Get the user and group files are created with from |base_dir_|. |
| 1867 struct stat stat_buf; | 1867 struct stat stat_buf; |
| 1868 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); | 1868 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); |
| 1869 uid_ = stat_buf.st_uid; | 1869 uid_ = stat_buf.st_uid; |
| 1870 gid_ = stat_buf.st_gid; | 1870 ok_gids_.insert(stat_buf.st_gid); |
| 1871 bad_gids_.insert(stat_buf.st_gid + 1); |
| 1872 |
| 1871 ASSERT_EQ(uid_, getuid()); // This process should be the owner. | 1873 ASSERT_EQ(uid_, getuid()); // This process should be the owner. |
| 1872 | 1874 |
| 1873 // To ensure that umask settings do not cause the initial state | 1875 // To ensure that umask settings do not cause the initial state |
| 1874 // of permissions to be different from what we expect, explicitly | 1876 // of permissions to be different from what we expect, explicitly |
| 1875 // set permissions on the directories we create. | 1877 // set permissions on the directories we create. |
| 1876 // Make all files and directories non-world-writable. | 1878 // Make all files and directories non-world-writable. |
| 1877 mode_t enabled_permissions = | 1879 mode_t enabled_permissions = |
| 1878 S_IRWXU | // User can read, write, traverse | 1880 S_IRWXU | // User can read, write, traverse |
| 1879 S_IRWXG; // Group can read, write, traverse | 1881 S_IRWXG; // Group can read, write, traverse |
| 1880 mode_t disabled_permissions = | 1882 mode_t disabled_permissions = |
| 1881 S_IRWXO; // Other users can't read, write, traverse. | 1883 S_IRWXO; // Other users can't read, write, traverse. |
| 1882 | 1884 |
| 1883 ASSERT_NO_FATAL_FAILURE( | 1885 ASSERT_NO_FATAL_FAILURE( |
| 1884 ChangePosixFilePermissions( | 1886 ChangePosixFilePermissions( |
| 1885 base_dir_, enabled_permissions, disabled_permissions)); | 1887 base_dir_, enabled_permissions, disabled_permissions)); |
| 1886 ASSERT_NO_FATAL_FAILURE( | 1888 ASSERT_NO_FATAL_FAILURE( |
| 1887 ChangePosixFilePermissions( | 1889 ChangePosixFilePermissions( |
| 1888 sub_dir_, enabled_permissions, disabled_permissions)); | 1890 sub_dir_, enabled_permissions, disabled_permissions)); |
| 1889 } | 1891 } |
| 1890 | 1892 |
| 1891 FilePath base_dir_; | 1893 FilePath base_dir_; |
| 1892 FilePath sub_dir_; | 1894 FilePath sub_dir_; |
| 1893 FilePath text_file_; | 1895 FilePath text_file_; |
| 1894 uid_t uid_; | 1896 uid_t uid_; |
| 1895 gid_t gid_; | 1897 |
| 1898 std::set<gid_t> ok_gids_; |
| 1899 std::set<gid_t> bad_gids_; |
| 1896 }; | 1900 }; |
| 1897 | 1901 |
| 1898 TEST_F(VerifyPathControlledByUserTest, BadPaths) { | 1902 TEST_F(VerifyPathControlledByUserTest, BadPaths) { |
| 1899 // File does not exist. | 1903 // File does not exist. |
| 1900 FilePath does_not_exist = base_dir_.AppendASCII("does") | 1904 FilePath does_not_exist = base_dir_.AppendASCII("does") |
| 1901 .AppendASCII("not") | 1905 .AppendASCII("not") |
| 1902 .AppendASCII("exist"); | 1906 .AppendASCII("exist"); |
| 1903 | |
| 1904 EXPECT_FALSE( | 1907 EXPECT_FALSE( |
| 1905 file_util::VerifyPathControlledByUser( | 1908 file_util::VerifyPathControlledByUser( |
| 1906 base_dir_, does_not_exist, uid_, gid_)); | 1909 base_dir_, does_not_exist, uid_, ok_gids_)); |
| 1907 | 1910 |
| 1908 // |base| not a subpath of |path|. | 1911 // |base| not a subpath of |path|. |
| 1909 EXPECT_FALSE( | 1912 EXPECT_FALSE( |
| 1910 file_util::VerifyPathControlledByUser(sub_dir_, base_dir_, uid_, gid_)); | 1913 file_util::VerifyPathControlledByUser( |
| 1914 sub_dir_, base_dir_, uid_, ok_gids_)); |
| 1911 | 1915 |
| 1912 // An empty base path will fail to be a prefix for any path. | 1916 // An empty base path will fail to be a prefix for any path. |
| 1913 FilePath empty; | 1917 FilePath empty; |
| 1914 EXPECT_FALSE( | 1918 EXPECT_FALSE( |
| 1915 file_util::VerifyPathControlledByUser(empty, base_dir_, uid_, gid_)); | 1919 file_util::VerifyPathControlledByUser( |
| 1920 empty, base_dir_, uid_, ok_gids_)); |
| 1916 | 1921 |
| 1917 // Finding that a bad call fails proves nothing unless a good call succeeds. | 1922 // Finding that a bad call fails proves nothing unless a good call succeeds. |
| 1918 EXPECT_TRUE( | 1923 EXPECT_TRUE( |
| 1919 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 1924 file_util::VerifyPathControlledByUser( |
| 1925 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 1920 } | 1926 } |
| 1921 | 1927 |
| 1922 TEST_F(VerifyPathControlledByUserTest, Symlinks) { | 1928 TEST_F(VerifyPathControlledByUserTest, Symlinks) { |
| 1923 // Symlinks in the path should cause failure. | 1929 // Symlinks in the path should cause failure. |
| 1924 | 1930 |
| 1925 // Symlink to the file at the end of the path. | 1931 // Symlink to the file at the end of the path. |
| 1926 FilePath file_link = base_dir_.AppendASCII("file_link"); | 1932 FilePath file_link = base_dir_.AppendASCII("file_link"); |
| 1927 ASSERT_TRUE(file_util::CreateSymbolicLink(text_file_, file_link)) | 1933 ASSERT_TRUE(file_util::CreateSymbolicLink(text_file_, file_link)) |
| 1928 << "Failed to create symlink."; | 1934 << "Failed to create symlink."; |
| 1929 | 1935 |
| 1930 EXPECT_FALSE( | 1936 EXPECT_FALSE( |
| 1931 file_util::VerifyPathControlledByUser(base_dir_, file_link, uid_, gid_)); | 1937 file_util::VerifyPathControlledByUser( |
| 1938 base_dir_, file_link, uid_, ok_gids_)); |
| 1932 EXPECT_FALSE( | 1939 EXPECT_FALSE( |
| 1933 file_util::VerifyPathControlledByUser(file_link, file_link, uid_, gid_)); | 1940 file_util::VerifyPathControlledByUser( |
| 1941 file_link, file_link, uid_, ok_gids_)); |
| 1934 | 1942 |
| 1935 // Symlink from one directory to another within the path. | 1943 // Symlink from one directory to another within the path. |
| 1936 FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir"); | 1944 FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir"); |
| 1937 ASSERT_TRUE(file_util::CreateSymbolicLink(sub_dir_, link_to_sub_dir)) | 1945 ASSERT_TRUE(file_util::CreateSymbolicLink(sub_dir_, link_to_sub_dir)) |
| 1938 << "Failed to create symlink."; | 1946 << "Failed to create symlink."; |
| 1939 | 1947 |
| 1940 FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt"); | 1948 FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt"); |
| 1941 ASSERT_TRUE(file_util::PathExists(file_path_with_link)); | 1949 ASSERT_TRUE(file_util::PathExists(file_path_with_link)); |
| 1942 | 1950 |
| 1943 EXPECT_FALSE( | 1951 EXPECT_FALSE( |
| 1944 file_util::VerifyPathControlledByUser( | 1952 file_util::VerifyPathControlledByUser( |
| 1945 base_dir_, file_path_with_link, uid_, gid_)); | 1953 base_dir_, file_path_with_link, uid_, ok_gids_)); |
| 1946 | 1954 |
| 1947 EXPECT_FALSE( | 1955 EXPECT_FALSE( |
| 1948 file_util::VerifyPathControlledByUser( | 1956 file_util::VerifyPathControlledByUser( |
| 1949 link_to_sub_dir, file_path_with_link, uid_, gid_)); | 1957 link_to_sub_dir, file_path_with_link, uid_, ok_gids_)); |
| 1950 | 1958 |
| 1951 // Symlinks in parents of base path are allowed. | 1959 // Symlinks in parents of base path are allowed. |
| 1952 EXPECT_TRUE( | 1960 EXPECT_TRUE( |
| 1953 file_util::VerifyPathControlledByUser( | 1961 file_util::VerifyPathControlledByUser( |
| 1954 file_path_with_link, file_path_with_link, uid_, gid_)); | 1962 file_path_with_link, file_path_with_link, uid_, ok_gids_)); |
| 1955 } | 1963 } |
| 1956 | 1964 |
| 1957 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) { | 1965 TEST_F(VerifyPathControlledByUserTest, OwnershipChecks) { |
| 1958 // Get a uid that is not the uid of files we create. | 1966 // Get a uid that is not the uid of files we create. |
| 1959 uid_t bad_uid = uid_ + 1; | 1967 uid_t bad_uid = uid_ + 1; |
| 1960 | 1968 |
| 1961 // Get a gid that is not ours. | |
| 1962 gid_t bad_gid = gid_ + 1; | |
| 1963 | |
| 1964 // Make all files and directories non-world-writable. | 1969 // Make all files and directories non-world-writable. |
| 1965 ASSERT_NO_FATAL_FAILURE( | 1970 ASSERT_NO_FATAL_FAILURE( |
| 1966 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 1971 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
| 1967 ASSERT_NO_FATAL_FAILURE( | 1972 ASSERT_NO_FATAL_FAILURE( |
| 1968 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 1973 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
| 1969 ASSERT_NO_FATAL_FAILURE( | 1974 ASSERT_NO_FATAL_FAILURE( |
| 1970 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 1975 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
| 1971 | 1976 |
| 1972 // We control these paths. | 1977 // We control these paths. |
| 1973 EXPECT_TRUE( | 1978 EXPECT_TRUE( |
| 1974 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 1979 file_util::VerifyPathControlledByUser( |
| 1980 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 1975 EXPECT_TRUE( | 1981 EXPECT_TRUE( |
| 1976 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 1982 file_util::VerifyPathControlledByUser( |
| 1983 base_dir_, text_file_, uid_, ok_gids_)); |
| 1977 EXPECT_TRUE( | 1984 EXPECT_TRUE( |
| 1978 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 1985 file_util::VerifyPathControlledByUser( |
| 1986 sub_dir_, text_file_, uid_, ok_gids_)); |
| 1979 | 1987 |
| 1980 // Another user does not control these paths. | 1988 // Another user does not control these paths. |
| 1981 EXPECT_FALSE( | 1989 EXPECT_FALSE( |
| 1982 file_util::VerifyPathControlledByUser( | 1990 file_util::VerifyPathControlledByUser( |
| 1983 base_dir_, sub_dir_, bad_uid, gid_)); | 1991 base_dir_, sub_dir_, bad_uid, ok_gids_)); |
| 1984 EXPECT_FALSE( | 1992 EXPECT_FALSE( |
| 1985 file_util::VerifyPathControlledByUser( | 1993 file_util::VerifyPathControlledByUser( |
| 1986 base_dir_, text_file_, bad_uid, gid_)); | 1994 base_dir_, text_file_, bad_uid, ok_gids_)); |
| 1987 EXPECT_FALSE( | 1995 EXPECT_FALSE( |
| 1988 file_util::VerifyPathControlledByUser( | 1996 file_util::VerifyPathControlledByUser( |
| 1989 sub_dir_, text_file_, bad_uid, gid_)); | 1997 sub_dir_, text_file_, bad_uid, ok_gids_)); |
| 1990 | 1998 |
| 1991 // Another group does not control the paths. | 1999 // Another group does not control the paths. |
| 1992 EXPECT_FALSE( | 2000 EXPECT_FALSE( |
| 1993 file_util::VerifyPathControlledByUser( | 2001 file_util::VerifyPathControlledByUser( |
| 1994 base_dir_, sub_dir_, uid_, bad_gid)); | 2002 base_dir_, sub_dir_, uid_, bad_gids_)); |
| 1995 EXPECT_FALSE( | 2003 EXPECT_FALSE( |
| 1996 file_util::VerifyPathControlledByUser( | 2004 file_util::VerifyPathControlledByUser( |
| 1997 base_dir_, text_file_, uid_, bad_gid)); | 2005 base_dir_, text_file_, uid_, bad_gids_)); |
| 1998 EXPECT_FALSE( | 2006 EXPECT_FALSE( |
| 1999 file_util::VerifyPathControlledByUser( | 2007 file_util::VerifyPathControlledByUser( |
| 2000 sub_dir_, text_file_, uid_, bad_gid)); | 2008 sub_dir_, text_file_, uid_, bad_gids_)); |
| 2009 } |
| 2010 |
| 2011 TEST_F(VerifyPathControlledByUserTest, GroupWriteTest) { |
| 2012 // Make all files and directories writable only by their owner. |
| 2013 ASSERT_NO_FATAL_FAILURE( |
| 2014 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH|S_IWGRP)); |
| 2015 ASSERT_NO_FATAL_FAILURE( |
| 2016 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH|S_IWGRP)); |
| 2017 ASSERT_NO_FATAL_FAILURE( |
| 2018 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH|S_IWGRP)); |
| 2019 |
| 2020 // Any group is okay because the path is not group-writable. |
| 2021 EXPECT_TRUE( |
| 2022 file_util::VerifyPathControlledByUser( |
| 2023 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2024 EXPECT_TRUE( |
| 2025 file_util::VerifyPathControlledByUser( |
| 2026 base_dir_, text_file_, uid_, ok_gids_)); |
| 2027 EXPECT_TRUE( |
| 2028 file_util::VerifyPathControlledByUser( |
| 2029 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2030 |
| 2031 EXPECT_TRUE( |
| 2032 file_util::VerifyPathControlledByUser( |
| 2033 base_dir_, sub_dir_, uid_, bad_gids_)); |
| 2034 EXPECT_TRUE( |
| 2035 file_util::VerifyPathControlledByUser( |
| 2036 base_dir_, text_file_, uid_, bad_gids_)); |
| 2037 EXPECT_TRUE( |
| 2038 file_util::VerifyPathControlledByUser( |
| 2039 sub_dir_, text_file_, uid_, bad_gids_)); |
| 2040 |
| 2041 // No group is okay, because we don't check the group |
| 2042 // if no group can write. |
| 2043 std::set<gid_t> no_gids; // Empty set of gids. |
| 2044 EXPECT_TRUE( |
| 2045 file_util::VerifyPathControlledByUser( |
| 2046 base_dir_, sub_dir_, uid_, no_gids)); |
| 2047 EXPECT_TRUE( |
| 2048 file_util::VerifyPathControlledByUser( |
| 2049 base_dir_, text_file_, uid_, no_gids)); |
| 2050 EXPECT_TRUE( |
| 2051 file_util::VerifyPathControlledByUser( |
| 2052 sub_dir_, text_file_, uid_, no_gids)); |
| 2053 |
| 2054 |
| 2055 // Make all files and directories writable by their group. |
| 2056 ASSERT_NO_FATAL_FAILURE( |
| 2057 ChangePosixFilePermissions(base_dir_, S_IWGRP, 0u)); |
| 2058 ASSERT_NO_FATAL_FAILURE( |
| 2059 ChangePosixFilePermissions(sub_dir_, S_IWGRP, 0u)); |
| 2060 ASSERT_NO_FATAL_FAILURE( |
| 2061 ChangePosixFilePermissions(text_file_, S_IWGRP, 0u)); |
| 2062 |
| 2063 // Now |ok_gids_| works, but |bad_gids_| fails. |
| 2064 EXPECT_TRUE( |
| 2065 file_util::VerifyPathControlledByUser( |
| 2066 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2067 EXPECT_TRUE( |
| 2068 file_util::VerifyPathControlledByUser( |
| 2069 base_dir_, text_file_, uid_, ok_gids_)); |
| 2070 EXPECT_TRUE( |
| 2071 file_util::VerifyPathControlledByUser( |
| 2072 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2073 |
| 2074 EXPECT_FALSE( |
| 2075 file_util::VerifyPathControlledByUser( |
| 2076 base_dir_, sub_dir_, uid_, bad_gids_)); |
| 2077 EXPECT_FALSE( |
| 2078 file_util::VerifyPathControlledByUser( |
| 2079 base_dir_, text_file_, uid_, bad_gids_)); |
| 2080 EXPECT_FALSE( |
| 2081 file_util::VerifyPathControlledByUser( |
| 2082 sub_dir_, text_file_, uid_, bad_gids_)); |
| 2083 |
| 2084 // Because any group in the group set is allowed, |
| 2085 // the union of good and bad gids passes. |
| 2086 |
| 2087 std::set<gid_t> multiple_gids; |
| 2088 std::set_union( |
| 2089 ok_gids_.begin(), ok_gids_.end(), |
| 2090 bad_gids_.begin(), bad_gids_.end(), |
| 2091 std::inserter(multiple_gids, multiple_gids.begin())); |
| 2092 |
| 2093 EXPECT_TRUE( |
| 2094 file_util::VerifyPathControlledByUser( |
| 2095 base_dir_, sub_dir_, uid_, multiple_gids)); |
| 2096 EXPECT_TRUE( |
| 2097 file_util::VerifyPathControlledByUser( |
| 2098 base_dir_, text_file_, uid_, multiple_gids)); |
| 2099 EXPECT_TRUE( |
| 2100 file_util::VerifyPathControlledByUser( |
| 2101 sub_dir_, text_file_, uid_, multiple_gids)); |
| 2102 |
| 2001 } | 2103 } |
| 2002 | 2104 |
| 2003 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { | 2105 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { |
| 2004 // Make all files and directories non-world-writable. | 2106 // Make all files and directories non-world-writable. |
| 2005 ASSERT_NO_FATAL_FAILURE( | 2107 ASSERT_NO_FATAL_FAILURE( |
| 2006 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 2108 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
| 2007 ASSERT_NO_FATAL_FAILURE( | 2109 ASSERT_NO_FATAL_FAILURE( |
| 2008 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 2110 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
| 2009 ASSERT_NO_FATAL_FAILURE( | 2111 ASSERT_NO_FATAL_FAILURE( |
| 2010 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 2112 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
| 2011 | 2113 |
| 2012 // Initialy, we control all parts of the path. | 2114 // Initialy, we control all parts of the path. |
| 2013 EXPECT_TRUE( | 2115 EXPECT_TRUE( |
| 2014 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2116 file_util::VerifyPathControlledByUser( |
| 2117 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2015 EXPECT_TRUE( | 2118 EXPECT_TRUE( |
| 2016 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2119 file_util::VerifyPathControlledByUser( |
| 2120 base_dir_, text_file_, uid_, ok_gids_)); |
| 2017 EXPECT_TRUE( | 2121 EXPECT_TRUE( |
| 2018 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2122 file_util::VerifyPathControlledByUser( |
| 2123 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2019 | 2124 |
| 2020 // Make base_dir_ world-writable. | 2125 // Make base_dir_ world-writable. |
| 2021 ASSERT_NO_FATAL_FAILURE( | 2126 ASSERT_NO_FATAL_FAILURE( |
| 2022 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u)); | 2127 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u)); |
| 2023 EXPECT_FALSE( | 2128 EXPECT_FALSE( |
| 2024 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2129 file_util::VerifyPathControlledByUser( |
| 2130 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2025 EXPECT_FALSE( | 2131 EXPECT_FALSE( |
| 2026 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2132 file_util::VerifyPathControlledByUser( |
| 2133 base_dir_, text_file_, uid_, ok_gids_)); |
| 2027 EXPECT_TRUE( | 2134 EXPECT_TRUE( |
| 2028 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2135 file_util::VerifyPathControlledByUser( |
| 2136 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2029 | 2137 |
| 2030 // Make sub_dir_ world writable. | 2138 // Make sub_dir_ world writable. |
| 2031 ASSERT_NO_FATAL_FAILURE( | 2139 ASSERT_NO_FATAL_FAILURE( |
| 2032 ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u)); | 2140 ChangePosixFilePermissions(sub_dir_, S_IWOTH, 0u)); |
| 2033 EXPECT_FALSE( | 2141 EXPECT_FALSE( |
| 2034 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2142 file_util::VerifyPathControlledByUser( |
| 2143 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2035 EXPECT_FALSE( | 2144 EXPECT_FALSE( |
| 2036 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2145 file_util::VerifyPathControlledByUser( |
| 2146 base_dir_, text_file_, uid_, ok_gids_)); |
| 2037 EXPECT_FALSE( | 2147 EXPECT_FALSE( |
| 2038 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2148 file_util::VerifyPathControlledByUser( |
| 2149 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2039 | 2150 |
| 2040 // Make text_file_ world writable. | 2151 // Make text_file_ world writable. |
| 2041 ASSERT_NO_FATAL_FAILURE( | 2152 ASSERT_NO_FATAL_FAILURE( |
| 2042 ChangePosixFilePermissions(text_file_, S_IWOTH, 0u)); | 2153 ChangePosixFilePermissions(text_file_, S_IWOTH, 0u)); |
| 2043 EXPECT_FALSE( | 2154 EXPECT_FALSE( |
| 2044 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2155 file_util::VerifyPathControlledByUser( |
| 2156 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2045 EXPECT_FALSE( | 2157 EXPECT_FALSE( |
| 2046 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2158 file_util::VerifyPathControlledByUser( |
| 2159 base_dir_, text_file_, uid_, ok_gids_)); |
| 2047 EXPECT_FALSE( | 2160 EXPECT_FALSE( |
| 2048 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2161 file_util::VerifyPathControlledByUser( |
| 2162 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2049 | 2163 |
| 2050 // Make sub_dir_ non-world writable. | 2164 // Make sub_dir_ non-world writable. |
| 2051 ASSERT_NO_FATAL_FAILURE( | 2165 ASSERT_NO_FATAL_FAILURE( |
| 2052 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); | 2166 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); |
| 2053 EXPECT_FALSE( | 2167 EXPECT_FALSE( |
| 2054 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2168 file_util::VerifyPathControlledByUser( |
| 2169 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2055 EXPECT_FALSE( | 2170 EXPECT_FALSE( |
| 2056 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2171 file_util::VerifyPathControlledByUser( |
| 2172 base_dir_, text_file_, uid_, ok_gids_)); |
| 2057 EXPECT_FALSE( | 2173 EXPECT_FALSE( |
| 2058 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2174 file_util::VerifyPathControlledByUser( |
| 2175 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2059 | 2176 |
| 2060 // Make base_dir_ non-world-writable. | 2177 // Make base_dir_ non-world-writable. |
| 2061 ASSERT_NO_FATAL_FAILURE( | 2178 ASSERT_NO_FATAL_FAILURE( |
| 2062 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); | 2179 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); |
| 2063 EXPECT_TRUE( | 2180 EXPECT_TRUE( |
| 2064 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2181 file_util::VerifyPathControlledByUser( |
| 2182 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2065 EXPECT_FALSE( | 2183 EXPECT_FALSE( |
| 2066 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2184 file_util::VerifyPathControlledByUser( |
| 2185 base_dir_, text_file_, uid_, ok_gids_)); |
| 2067 EXPECT_FALSE( | 2186 EXPECT_FALSE( |
| 2068 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2187 file_util::VerifyPathControlledByUser( |
| 2188 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2069 | 2189 |
| 2070 // Back to the initial state: Nothing is writable, so every path | 2190 // Back to the initial state: Nothing is writable, so every path |
| 2071 // should pass. | 2191 // should pass. |
| 2072 ASSERT_NO_FATAL_FAILURE( | 2192 ASSERT_NO_FATAL_FAILURE( |
| 2073 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); | 2193 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); |
| 2074 EXPECT_TRUE( | 2194 EXPECT_TRUE( |
| 2075 file_util::VerifyPathControlledByUser(base_dir_, sub_dir_, uid_, gid_)); | 2195 file_util::VerifyPathControlledByUser( |
| 2196 base_dir_, sub_dir_, uid_, ok_gids_)); |
| 2076 EXPECT_TRUE( | 2197 EXPECT_TRUE( |
| 2077 file_util::VerifyPathControlledByUser(base_dir_, text_file_, uid_, gid_)); | 2198 file_util::VerifyPathControlledByUser( |
| 2199 base_dir_, text_file_, uid_, ok_gids_)); |
| 2078 EXPECT_TRUE( | 2200 EXPECT_TRUE( |
| 2079 file_util::VerifyPathControlledByUser(sub_dir_, text_file_, uid_, gid_)); | 2201 file_util::VerifyPathControlledByUser( |
| 2202 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2080 } | 2203 } |
| 2081 | 2204 |
| 2082 #endif // defined(OS_POSIX) | 2205 #endif // defined(OS_POSIX) |
| 2083 | 2206 |
| 2084 } // namespace | 2207 } // namespace |
| OLD | NEW |