Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: base/test/test_file_util_win.cc

Issue 2124373002: [PPAPI] Quarantine files that are writeable by a Pepper plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@consolidate-file-metadata
Patch Set: Address comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/test/test_file_util.h ('k') | chrome/browser/download/download_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/test/test_file_util.h" 5 #include "base/test/test_file_util.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <shlwapi.h> 8 #include <shlwapi.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <wchar.h> 10 #include <wchar.h>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 DWORD rc = SetNamedSecurityInfo(path_ptr.get(), SE_FILE_OBJECT, 153 DWORD rc = SetNamedSecurityInfo(path_ptr.get(), SE_FILE_OBJECT,
154 DACL_SECURITY_INFORMATION, nullptr, nullptr, 154 DACL_SECURITY_INFORMATION, nullptr, nullptr,
155 new_dacl, nullptr); 155 new_dacl, nullptr);
156 LocalFree(security_descriptor); 156 LocalFree(security_descriptor);
157 LocalFree(new_dacl); 157 LocalFree(new_dacl);
158 158
159 return rc == ERROR_SUCCESS; 159 return rc == ERROR_SUCCESS;
160 } 160 }
161 161
162 // Checks if the volume supports Alternate Data Streams. This is required for
163 // the Zone Identifier implementation.
164 bool VolumeSupportsADS(const FilePath& path) {
165 wchar_t drive[MAX_PATH] = {0};
166 wcscpy_s(drive, MAX_PATH, path.value().c_str());
167
168 if (!PathStripToRootW(drive))
169 return false;
170
171 DWORD fs_flags = 0;
172 if (!GetVolumeInformationW(drive, NULL, 0, 0, NULL, &fs_flags, NULL, 0))
173 return false;
174
175 if (fs_flags & FILE_NAMED_STREAMS)
176 return true;
177
178 return false;
179 }
180
181 // Return whether the ZoneIdentifier is correctly set to "Internet" (3)
182 // Only returns a valid result when called from same process as the
183 // one that (was supposed to have) set the zone identifier.
184 bool HasInternetZoneIdentifier(const FilePath& full_path) {
185 FilePath zone_path(full_path.value() + L":Zone.Identifier");
186 std::string zone_path_contents;
187 if (!ReadFileToString(zone_path, &zone_path_contents))
188 return false;
189
190 std::vector<std::string> lines = SplitString(
191 zone_path_contents, "\n", TRIM_WHITESPACE, SPLIT_WANT_ALL);
192 switch (lines.size()) {
193 case 3:
194 // optional empty line at end of file:
195 if (!lines[2].empty())
196 return false;
197 // fall through:
198 case 2:
199 return lines[0] == "[ZoneTransfer]" && lines[1] == "ZoneId=3";
200 default:
201 return false;
202 }
203 }
204
205 bool MakeFileUnreadable(const FilePath& path) { 162 bool MakeFileUnreadable(const FilePath& path) {
206 return DenyFilePermission(path, GENERIC_READ); 163 return DenyFilePermission(path, GENERIC_READ);
207 } 164 }
208 165
209 bool MakeFileUnwritable(const FilePath& path) { 166 bool MakeFileUnwritable(const FilePath& path) {
210 return DenyFilePermission(path, GENERIC_WRITE); 167 return DenyFilePermission(path, GENERIC_WRITE);
211 } 168 }
212 169
213 FilePermissionRestorer::FilePermissionRestorer(const FilePath& path) 170 FilePermissionRestorer::FilePermissionRestorer(const FilePath& path)
214 : path_(path), info_(NULL), length_(0) { 171 : path_(path), info_(NULL), length_(0) {
215 info_ = GetPermissionInfo(path_, &length_); 172 info_ = GetPermissionInfo(path_, &length_);
216 DCHECK(info_ != NULL); 173 DCHECK(info_ != NULL);
217 DCHECK_NE(0u, length_); 174 DCHECK_NE(0u, length_);
218 } 175 }
219 176
220 FilePermissionRestorer::~FilePermissionRestorer() { 177 FilePermissionRestorer::~FilePermissionRestorer() {
221 if (!RestorePermissionInfo(path_, info_, length_)) 178 if (!RestorePermissionInfo(path_, info_, length_))
222 NOTREACHED(); 179 NOTREACHED();
223 } 180 }
224 181
225 } // namespace base 182 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_file_util.h ('k') | chrome/browser/download/download_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698