summaryrefslogtreecommitdiff
path: root/src/secure.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/secure.rs')
-rw-r--r--src/secure.rs19
1 files changed, 3 insertions, 16 deletions
diff --git a/src/secure.rs b/src/secure.rs
index 018bc4f..7c85ece 100644
--- a/src/secure.rs
+++ b/src/secure.rs
@@ -1,5 +1,5 @@
-use std::{os::{unix::prelude::PermissionsExt, linux::fs::MetadataExt}, fs, io::{self, ErrorKind}};
-use nix::unistd::{self, Uid};
+use std::{os::{unix::prelude::PermissionsExt, linux::fs::MetadataExt}, fs, io::{self, ErrorKind}, path::Path};
+use nix::unistd::{self, Uid, Gid};
/// Writes a file securly to a specified path with given data
@@ -40,19 +40,6 @@ pub fn read_file(dir: &str, file: &str) -> Option<String> {
}
-/// Elecate the privlages of the current process
-/// #### Arguments
-/// * `uid` - The uid to set the process to
-/// #### Returns
-/// If the process fails to elevate, it returns false
-pub fn elevate_privilages(uid: Uid) -> bool {
- if unistd::setuid(uid).is_err() {
- return false;
- }
- true
-}
-
-
/// Sets the permission for a secure file
/// #### Arguments
/// * `uid` - The user to own the file
@@ -62,7 +49,7 @@ pub fn elevate_privilages(uid: Uid) -> bool {
/// #### Returns
/// A ``io::Result<()>`` if the write succeded or failed
fn set_file_permissions(uid: u32, gid: u32, mode: u32, path: &str) -> Result<(), io::Error> {
- unistd::chown(std::path::Path::new(path), Some(unistd::Uid::from(uid)), Some(unistd::Gid::from(gid)))?;
+ unistd::chown(Path::new(path), Some(Uid::from(uid)), Some(Gid::from(gid)))?;
let metadata = fs::metadata(path)?;
let mut perms = metadata.permissions();
perms.set_mode(mode);