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

Side by Side Diff: platform.h

Issue 2645008: Update on feedback, update dbus API, add unit tests. TEST=manual,unit,BVT BUG=3628 323 (Closed) Base URL: ssh://git@chromiumos-git/cryptohome.git
Patch Set: Address second round of feedback. Created 10 years, 6 months 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 | « mount_unittest.cc ('k') | platform.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CRYPTOHOME_PLATFORM_H_
6 #define CRYPTOHOME_PLATFORM_H_
7
8 #include <base/basictypes.h>
9 #include <string>
10 #include <vector>
11
12 namespace cryptohome {
13
14 // Default mount options
15 extern const int kDefaultMountOptions;
16 // Default length to use in call to getpwnam_r if the system default is not
17 // available
18 extern const int kDefaultPwnameLength;
19 // Default umask
20 extern const int kDefaultUmask;
21 // Where to find mtab
22 extern const std::string kMtab;
23 // The procfs dir
24 extern const std::string kProcDir;
25
26 // TODO(fes): Description
27 class Platform {
28 public:
29
30 Platform();
31
32 virtual ~Platform();
33
34 // Calls the platform mount
35 //
36 // Paramters
37 // from - The node to mount from
38 // to - The node to mount to
39 // type - The fs type
40 // mount_options - The mount options to pass to mount()
41 bool Mount(const std::string& from, const std::string& to,
42 const std::string& type, const std::string& mount_options);
43
44 // Calls the platform unmount
45 //
46 // Parameters
47 // path - The path to unmount
48 // lazy - Whether to call a lazy unmount
49 // was_busy (OUT) - Set to true on return if the mount point was busy
50 bool Unmount(const std::string& path, bool lazy, bool* was_busy);
51
52 // Returns true if the directory is in the mtab
53 //
54 // Parameters
55 // directory - The directory to check
56 bool IsDirectoryMounted(const std::string& directory);
57
58 // Returns true if the directory is in the mtab mounted with the specified
59 // source
60 //
61 // Parameters
62 // directory - The directory to check
63 // from - The source node
64 bool IsDirectoryMountedWith(const std::string& directory,
65 const std::string& from);
66
67 // Terminates or kills processes (except the current) that have files open on
68 // the specified path. Returns true if it tried to kill any processes.
69 //
70 // Parameters
71 // path - The path to check if the process has open files on
72 // hard - If true, send a SIGKILL instead of SIGTERM
73 bool TerminatePidsWithOpenFiles(const std::string& path, bool hard);
74
75 // Returns a vector of PIDs that have files open on the given path
76 //
77 // Parameters
78 // path - The path to check if the process has open files on
79 // pids (OUT) - The PIDs found
80 void LookForOpenFiles(const std::string& path_in, std::vector<pid_t>* pids);
81
82 // Terminates or kills processes (except the current) that have the user ID
83 // specified. Returns true if it tried to kill any processes.
84 //
85 // Parameters
86 // path - The path to check if the process has open files on
87 // hard - If true, send a SIGKILL instead of SIGTERM
88 bool TerminatePidsForUser(const uid_t uid, bool hard);
89
90 // Returns a vector of PIDs whose Real, Effective, Saved, or File UID is equal
91 // to that requested
92 //
93 // Parameters
94 // uid - the user ID to search for
95 // pids (OUT) - the list of PIDs
96 void GetPidsForUser(uid_t uid, std::vector<pid_t>* pids);
97
98 // Calls the platform chown() function recursively on the directory
99 //
100 // Parameters
101 // directory - The directory to set ownership on
102 // user_id - The user_id to assign ownership to
103 // group_id - The group_id to assign ownership to
104 bool SetOwnership(const std::string& directory, uid_t user_id,
105 gid_t group_id);
106
107 // Sets the current umask, returning the old mask
108 //
109 // Parameters
110 // new_mask - The mask to set
111 int SetMask(int new_mask);
112
113 // Returns the user and group ids for a user
114 //
115 // Parameters
116 // user - The username to query for
117 // user_id (OUT) - The user ID on success
118 // group_id (OUT) - The group ID on success
119 bool GetUserId(const std::string& user, uid_t* user_id, gid_t* group_id);
120
121 // Clears the user keyring
122 static void ClearUserKeyring();
123
124 // Overrides the default mount options
125 void set_mount_options(int value) {
126 mount_options_ = value;
127 }
128
129 // Overrides the default mtab file
130 void set_mtab_file(const std::string& value) {
131 mtab_file_ = value;
132 }
133
134 // Overrides the default procfs dir
135 void set_proc_dir(const std::string& value) {
136 proc_dir_ = value;
137 }
138
139 private:
140 int mount_options_;
141 int umask_;
142 std::string mtab_file_;
143 std::string proc_dir_;
144
145 DISALLOW_COPY_AND_ASSIGN(Platform);
146 };
147
148 } // namespace cryptohome
149
150 #endif // CRYPTOHOME_PLATFORM_H_
OLDNEW
« no previous file with comments | « mount_unittest.cc ('k') | platform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698