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

Add storage permissions to UserDetail #511

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ pub(crate) mod authenticator;
pub use authenticator::{AuthenticationError, Authenticator, ClientCert, Credentials};

mod user;
pub use user::{DefaultUser, UserDetail};
pub use user::{DefaultUser, StoragePermissions, UserDetail};
34 changes: 34 additions & 0 deletions src/auth/user.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bitflags::bitflags;
use std::{
fmt::{self, Debug, Display, Formatter},
path::Path,
Expand Down Expand Up @@ -27,6 +28,39 @@ pub trait UserDetail: Send + Sync + Display + Debug {
fn home(&self) -> Option<&Path> {
None
}

/// Tells what the user is authorised to do in terms of FTP filesystem operations.
///
/// The default implementation gives all permissions.
fn storage_permissions(&self) -> StoragePermissions {
StoragePermissions::all()
}
}

bitflags! {
/// The FTP operations that can be enabled/disabled for the storage back-end.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StoragePermissions: u32 {
/// If set allows FTP make directory
const MK_DIR = 0b00000001;
/// If set allows FTP remove directory
const RM_DIR = 0b00000010;
/// If set allows FTP GET i.e. clients can download files.
const GET = 0b00000100;
/// If set allows FTP PUT i.e. clients can upload files.
const PUT = 0b00001000;
/// If set allows FTP DELE i.e. clients can remove files.
const DEL = 0b00010000;
/// If set allows FTP RENAME i.e. clients can rename directories and files
const RENAME = 0b00100000;
/// If set allows the extended SITE MD5 command to calculate checksums
const MD5 = 0b01000000;
/// If set allows clients to list the contents of a directory.
const LIST = 0b10000000;

/// Convenience aggregation of all the write operation bits.
const WRITE_OPS = Self::MK_DIR.bits() | Self::RM_DIR.bits() | Self::PUT.bits() | Self::DEL.bits() | Self::RENAME.bits();
}
}

/// DefaultUser is a default implementation of the `UserDetail` trait that doesn't hold any user
Expand Down
2 changes: 1 addition & 1 deletion src/storage/storage_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait Metadata {
}
}

/// Represents the permissions of a _FTP File_
/// Represents the permissions of an _FTP File_
pub struct Permissions(pub u32);

const PERM_READ: u32 = 0b100100100;
Expand Down
Loading