-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_attrs_cleaner.h
61 lines (48 loc) · 2.18 KB
/
file_attrs_cleaner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef INIT_FILE_ATTRS_CLEANER_H_
#define INIT_FILE_ATTRS_CLEANER_H_
#include <string>
#include <vector>
#include <base/files/file_path.h>
namespace file_attrs_cleaner {
extern const char xdg_origin_url[];
extern const char xdg_referrer_url[];
enum class AttributeCheckStatus {
ERROR = 0,
NO_ATTR,
CLEAR_FAILED,
CLEARED,
};
// Whether we allow |path| to be marked with immutable file attribute.
// If |path| is supposed to be a directory, set |isdir| to true.
bool ImmutableAllowed(const base::FilePath& path, bool isdir);
// Check the file attributes of the specified path. |path| is used for logging
// and policy checking, so |fd| needs to be an open handle to it. This helps
// with TOCTTOU issues. If |path| is supposed to be a directory, set |isdir|
// to true.
AttributeCheckStatus CheckFileAttributes(const base::FilePath& path,
bool isdir,
int fd);
// Remove download-related URL extended attributes. See crbug.com/919486.
// This cannot use a file descriptor because the files we want to clear xattrs
// from are encrypted and therefore cannot be opened.
// Report whether the file actually had the relevant extended attributes for
// metrics purposes.
AttributeCheckStatus RemoveURLExtendedAttributes(const base::FilePath& path);
// Recursively scan the file attributes of paths under |dir|.
// Don't recurse into any subdirectories that exactly match any string in
// |skip_recurse|.
// Populate |url_xattrs_count| if files with those attributes were found.
bool ScanDir(const base::FilePath& dir,
const std::vector<std::string>& skip_recurse,
int* url_xattrs_count);
// Convenience function.
static inline bool ScanDir(const std::string& dir,
const std::vector<std::string>& skip_recurse,
int* url_xattrs_count) {
return ScanDir(base::FilePath(dir), skip_recurse, url_xattrs_count);
}
} // namespace file_attrs_cleaner
#endif // INIT_FILE_ATTRS_CLEANER_H_