summaryrefslogtreecommitdiff
path: root/src/secure.rs
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-11 09:56:48 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-11 09:56:48 -0500
commitde24d5499ac83f426228b28b90bed8f26e68fb3b (patch)
tree7a37f98005e8337d078db9edf1fec89de4a98f04 /src/secure.rs
parentupdate config format (diff)
downloadcrab-de24d5499ac83f426228b28b90bed8f26e68fb3b.tar.gz
crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.tar.bz2
crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.zip
doc string, refactor, config token error
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);