Merge branch 'odin' of git.hitchhiker-linux.org:jeang3nie/shitbox into odin
This commit is contained in:
commit
28d7b4c624
@ -1 +0,0 @@
|
||||
//! Functions for parsing and managing permissions
|
@ -1,10 +1,10 @@
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
use std::{env, path::PathBuf, process, string::ToString};
|
||||
|
||||
pub mod chmod;
|
||||
mod cmd;
|
||||
pub use cmd::Cmd;
|
||||
pub mod math;
|
||||
pub mod mode;
|
||||
pub mod pw;
|
||||
|
||||
/// Defines the location relative to the binary where a command will be installed
|
||||
|
67
src/mode/mod.rs
Normal file
67
src/mode/mod.rs
Normal file
@ -0,0 +1,67 @@
|
||||
//! Functions for parsing and managing permissions
|
||||
|
||||
pub fn get_umask() -> u32 {
|
||||
let mask = unsafe { libc::umask(0) };
|
||||
let umask = unsafe {libc::umask(mask) };
|
||||
umask
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Bits {
|
||||
Suid = 0o4000,
|
||||
Sgid = 0o2000,
|
||||
Sticky = 0o1000,
|
||||
URead = 0o400,
|
||||
UWrite = 0o200,
|
||||
UExec = 0o100,
|
||||
GRead = 0o40,
|
||||
GWrite = 0o20,
|
||||
GExec = 0o10,
|
||||
ORead = 0o4,
|
||||
OWrite = 0o2,
|
||||
OExec = 0o1,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Op {
|
||||
Add,
|
||||
Remove,
|
||||
Equals,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Who {
|
||||
User,
|
||||
Group,
|
||||
Other,
|
||||
All,
|
||||
}
|
||||
|
||||
pub struct Parser {
|
||||
mode: u32,
|
||||
op: Option<Op>,
|
||||
who: Option<Who>,
|
||||
}
|
||||
|
||||
impl Default for Parser {
|
||||
fn default() -> Self {
|
||||
let umask = get_umask();
|
||||
let mut mode = 0o0777;
|
||||
mode &= umask;
|
||||
Self {
|
||||
mode,
|
||||
op: None,
|
||||
who: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
fn new(mode: u32) -> Self {
|
||||
Self {
|
||||
mode,
|
||||
op: None,
|
||||
who: None,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user