Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line split in secure mount and notify #84

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/secure_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,27 @@ fn check_mount(secure_dir: &str) -> Result<bool, Box<String>> {

// Check mount list for secure directory
for line in lines {
let tokens: Vec<&str> = line.split('/').collect();
let tokens: Vec<&str> = line.split(' ').collect();

if tokens.len() < 3 {
continue;
}

if tokens[2] == secure_dir {
if tokens[0] != "tmpfs" {
return emsg(format!("secure storage location {} already mounted on wrong file system type: {}. Unmount to continue.", secure_dir, tokens[0]).as_str(), None::<String>);
return emsg(
format!(
"secure storage location {} already mounted on wrong file system type: {}. Unmount to continue.",
secure_dir,
tokens[0]).as_str(),
None::<String>
);
} else {
info!(
"Using existing secure storage tmpsfs mount {}",
secure_dir
);
}

return Ok(true);
}
}
Expand All @@ -54,7 +64,7 @@ fn check_mount(secure_dir: &str) -> Result<bool, Box<String>> {
* implementation as the original python version, but the chown/geteuid
* functions are unsafe function in Rust to use.
*/
fn mount() -> Result<String, Box<String>> {
pub fn mount() -> Result<String, Box<String>> {
// Use /tmpfs-dev directory if MOUNT_SECURE flag is set, which doesn't
// mount to the system. This is for developement envrionment. No need to
// mount to file system.
Expand Down Expand Up @@ -83,6 +93,7 @@ fn mount() -> Result<String, Box<String>> {
let secure_dir = format!("{}/secure", common::WORK_DIR);
let secure_size =
config_get("/etc/keylime.conf", "cloud_agent", "secure_size");

match check_mount(&secure_dir) {
Ok(false) => {
// If the directory is not mount to file system, mount the directory to
Expand All @@ -92,6 +103,7 @@ fn mount() -> Result<String, Box<String>> {

// Create directory if the directory is not exist. The
// directory permission is set to 448.

if !secure_dir_path.exists() {
if let Err(e) = fs::create_dir(secure_dir_path) {
return emsg("Failed to create directory.", Some(e));
Expand Down