Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "webkit/fileapi/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 if (file_system_options_.is_incognito()) | 218 if (file_system_options_.is_incognito()) |
| 219 // TODO(kinuko): return an isolated temporary directory. | 219 // TODO(kinuko): return an isolated temporary directory. |
| 220 return base::FilePath(); | 220 return base::FilePath(); |
| 221 | 221 |
| 222 if (!IsAllowedScheme(url.origin())) | 222 if (!IsAllowedScheme(url.origin())) |
| 223 return base::FilePath(); | 223 return base::FilePath(); |
| 224 | 224 |
| 225 return GetBaseDirectoryForOriginAndType(url.origin(), url.type(), create); | 225 return GetBaseDirectoryForOriginAndType(url.origin(), url.type(), create); |
| 226 } | 226 } |
| 227 | 227 |
| 228 bool SandboxMountPointProvider::IsAccessAllowed(const FileSystemURL& url) { | |
| 229 if (!CanHandleType(url.type())) | |
| 230 return false; | |
| 231 // We essentially depend on quota to do our access controls, so here | |
| 232 // we only check if the requested scheme is allowed or not. | |
| 233 return IsAllowedScheme(url.origin()); | |
| 234 } | |
| 235 | |
| 236 bool SandboxMountPointProvider::IsRestrictedFileName(const base::FilePath& filen ame) | |
| 237 const { | |
| 238 if (filename.value().empty()) | |
| 239 return false; | |
| 240 | |
| 241 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { | |
| 242 // Exact match. | |
| 243 if (filename.value() == kRestrictedNames[i]) | |
| 244 return true; | |
| 245 } | |
| 246 | |
| 247 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { | |
| 248 if (filename.value().find(kRestrictedChars[i]) != | |
| 249 base::FilePath::StringType::npos) | |
| 250 return true; | |
| 251 } | |
| 252 | |
| 253 return false; | |
| 254 } | |
| 255 | |
| 256 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil( | 228 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil( |
| 257 FileSystemType type) { | 229 FileSystemType type) { |
| 258 DCHECK(sandbox_file_util_.get()); | 230 DCHECK(sandbox_file_util_.get()); |
| 259 return sandbox_file_util_->sync_file_util(); | 231 return sandbox_file_util_->sync_file_util(); |
| 260 } | 232 } |
| 261 | 233 |
| 262 AsyncFileUtil* SandboxMountPointProvider::GetAsyncFileUtil( | 234 AsyncFileUtil* SandboxMountPointProvider::GetAsyncFileUtil( |
| 263 FileSystemType type) { | 235 FileSystemType type) { |
| 264 return sandbox_file_util_.get(); | 236 return sandbox_file_util_.get(); |
| 265 } | 237 } |
| 266 | 238 |
| 267 FilePermissionPolicy SandboxMountPointProvider::GetPermissionPolicy( | 239 FilePermissionPolicy SandboxMountPointProvider::GetPermissionPolicy( |
| 268 const FileSystemURL& url, int permissions) const { | 240 const FileSystemURL& url, int permissions) const { |
| 241 if (!CanHandleType(url.type()) || !IsAllowedScheme(url.origin())) | |
| 242 return FILE_PERMISSION_ALWAYS_DENY; | |
| 243 | |
| 244 if (url.path().ReferencesParent()) | |
| 245 return FILE_PERMISSION_ALWAYS_DENY; | |
| 246 | |
| 247 // Any write access is disallowed on the root path. | |
| 248 if ((url.path().value().length() == 0 || | |
| 249 url.path().DirName().value() == url.path().value()) && | |
| 250 (permissions &~ kReadFilePermissions)) | |
|
ericu
2013/02/05 21:51:57
Ditto.
| |
| 251 return FILE_PERMISSION_ALWAYS_DENY; | |
| 252 | |
| 253 if ((permissions & kCreateFilePermissions) == kCreateFilePermissions) { | |
| 254 // See if the name is allowed to create. | |
| 255 FilePath filename = VirtualPath::BaseName(url.path()); | |
| 256 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { | |
| 257 if (filename.value() == kRestrictedNames[i]) | |
| 258 return FILE_PERMISSION_ALWAYS_DENY; | |
| 259 } | |
| 260 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { | |
| 261 if (filename.value().find(kRestrictedChars[i]) != | |
| 262 FilePath::StringType::npos) | |
| 263 return FILE_PERMISSION_ALWAYS_DENY; | |
| 264 } | |
| 265 } | |
| 266 | |
| 269 // Access to the sandbox directory (and only to the directory) should be | 267 // Access to the sandbox directory (and only to the directory) should be |
| 270 // always allowed. | 268 // always allowed. |
| 271 CHECK(CanHandleType(url.type())); | |
| 272 CHECK(!url.path().ReferencesParent()); | |
| 273 return FILE_PERMISSION_ALWAYS_ALLOW; | 269 return FILE_PERMISSION_ALWAYS_ALLOW; |
| 274 } | 270 } |
| 275 | 271 |
| 276 FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation( | 272 FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation( |
| 277 const FileSystemURL& url, | 273 const FileSystemURL& url, |
| 278 FileSystemContext* context, | 274 FileSystemContext* context, |
| 279 base::PlatformFileError* error_code) const { | 275 base::PlatformFileError* error_code) const { |
| 280 scoped_ptr<FileSystemOperationContext> operation_context( | 276 scoped_ptr<FileSystemOperationContext> operation_context( |
| 281 new FileSystemOperationContext(context)); | 277 new FileSystemOperationContext(context)); |
| 282 | 278 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 } | 579 } |
| 584 return false; | 580 return false; |
| 585 } | 581 } |
| 586 | 582 |
| 587 ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() { | 583 ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() { |
| 588 DCHECK(sandbox_file_util_.get()); | 584 DCHECK(sandbox_file_util_.get()); |
| 589 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util()); | 585 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util()); |
| 590 } | 586 } |
| 591 | 587 |
| 592 } // namespace fileapi | 588 } // namespace fileapi |
| OLD | NEW |