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 "content/browser/download/file_metadata_linux.h" | 5 #include "content/browser/download/quarantine.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <sys/xattr.h> | 9 #include <sys/xattr.h> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/threading/thread_restrictions.h" | |
| 15 #include "content/browser/download/quarantine_constants_linux.h" | |
| 14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| 17 | 19 |
| 18 const char kSourceURLAttrName[] = "user.xdg.origin.url"; | 20 const char kSourceURLExtendedAttrName[] = "user.xdg.origin.url"; |
| 19 const char kReferrerURLAttrName[] = "user.xdg.referrer.url"; | 21 const char kReferrerURLExtendedAttrName[] = "user.xdg.referrer.url"; |
| 20 | 22 |
| 21 static void SetExtendedFileAttribute(const char* path, const char* name, | 23 namespace { |
| 22 const char* value, size_t value_size, | 24 |
| 23 int flags) { | 25 bool SetExtendedFileAttribute(const char* path, |
| 26 const char* name, | |
| 27 const char* value, | |
| 28 size_t value_size, | |
| 29 int flags) { | |
| 30 base::ThreadRestrictions::AssertIOAllowed(); | |
| 24 int result = setxattr(path, name, value, value_size, flags); | 31 int result = setxattr(path, name, value, value_size, flags); |
| 25 if (result) { | 32 if (result) { |
| 26 DPLOG(ERROR) | 33 DPLOG(ERROR) << "Could not set extended attribute " << name << " on file " |
| 27 << "Could not set extended attribute " << name << " on file " << path; | 34 << path; |
| 35 return false; | |
| 28 } | 36 } |
| 37 return true; | |
| 29 } | 38 } |
| 30 | 39 |
| 31 void AddOriginMetadataToFile(const base::FilePath& file, const GURL& source, | 40 } // namespace |
| 32 const GURL& referrer) { | 41 |
| 42 QuarantineFileResult QuarantineFile(const base::FilePath& file, | |
| 43 const GURL& source_url, | |
| 44 const GURL& referrer_url, | |
| 45 const std::string& client_guid) { | |
| 33 DCHECK(base::PathIsWritable(file)); | 46 DCHECK(base::PathIsWritable(file)); |
| 34 if (source.is_valid()) { | 47 bool succeeded = true; |
| 35 SetExtendedFileAttribute(file.value().c_str(), kSourceURLAttrName, | 48 if (source_url.is_valid()) { |
|
svaldez
2016/07/11 14:55:45
Should you be early failing if setting the SourceU
asanka
2016/09/12 15:36:37
Currently it's possible for the referrer URL to be
| |
| 36 source.spec().c_str(), source.spec().length(), 0); | 49 succeeded = SetExtendedFileAttribute( |
| 50 file.value().c_str(), kSourceURLExtendedAttrName, | |
| 51 source_url.spec().c_str(), source_url.spec().length(), 0); | |
| 37 } | 52 } |
| 38 if (referrer.is_valid()) { | 53 if (referrer_url.is_valid()) { |
| 39 SetExtendedFileAttribute(file.value().c_str(), kReferrerURLAttrName, | 54 succeeded = SetExtendedFileAttribute(file.value().c_str(), |
| 40 referrer.spec().c_str(), referrer.spec().length(), 0); | 55 kReferrerURLExtendedAttrName, |
| 56 referrer_url.spec().c_str(), | |
| 57 referrer_url.spec().length(), 0) && | |
| 58 succeeded; | |
| 41 } | 59 } |
| 60 return succeeded ? QuarantineFileResult::OK | |
| 61 : QuarantineFileResult::ANNOTATION_FAILED; | |
| 42 } | 62 } |
| 43 | 63 |
| 44 } // namespace content | 64 } // namespace content |
| OLD | NEW |