Skip to content

Commit

Permalink
Move restricting VFS to own crate
Browse files Browse the repository at this point in the history
I've moved the delegating storage back-end in src/storage/restrict.rs
to its own crate at https://crates.io/crates/unftp-sbe-restrict.
  • Loading branch information
hannesdejager committed Sep 14, 2023
1 parent 4242e3c commit 23782b8
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 257 deletions.
115 changes: 91 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ version="0.1.2"
[dependencies]
async-trait = "0.1.68"
base64 = "0.13.1"
bitflags = "1.3.2"
clap = { version = "3.2.25", features = ["derive", "env"] }
console-subscriber = { version = "0.1.9", optional = true }
flate2 = "1.0.26"
Expand All @@ -52,6 +51,7 @@ unftp-sbe-gcs = { version = "0.2.3", optional = true }
unftp-auth-rest = { version = "0.2.2", optional = true }
unftp-auth-jsonfile = { version = "0.3.1", optional = true }
unftp-sbe-rooter = "0.1.0"
unftp-sbe-restrict = "0.1.0"

# Purely to resolve conflicts
tracing= "0.1.37"
Expand Down
1 change: 1 addition & 0 deletions docs/libunftp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Known storage back-ends:
* [unftp-sbe-fs](https://crates.io/crates/unftp-sbe-fs) - Stores files on the local filesystem
* [unftp-sbe-gcs](https://crates.io/crates/unftp-sbe-gcs) - Stores files in Google Cloud Storage
* [unftp-sbe-rooter](https://crates.io/crates/unftp-sbe-rooter) - Wraps another storage back-end in order to root a user to a specific home directory.
* [unftp-sbe-restrict](https://crates.io/crates/unftp-sbe-rooter) - Wraps another storage back-end in order to restrict the FTP operations a user can do i.e. provide authorization.

Known authentication back-ends:

Expand Down
17 changes: 4 additions & 13 deletions src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use async_trait::async_trait;
use bitflags::bitflags;
use libunftp::auth::{AuthenticationError, Credentials, DefaultUser, UserDetail};
use serde::Deserialize;
use std::fmt::Formatter;
use std::path::PathBuf;
use unftp_sbe_restrict::{UserWithPermissions, VfsOperations};

/// The unFTP user details
#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -57,18 +57,9 @@ impl crate::storage::UserWithRoot for User {
}
}

bitflags! {
pub struct VfsOperations: u32 {
const MK_DIR = 0b00000001;
const RM_DIR = 0b00000010;
const GET = 0b00000100;
const PUT = 0b00001000;
const DEL = 0b00010000;
const RENAME = 0b00100000;
const MD5 = 0b01000000;
const LIST = 0b10000000;

const WRITE_OPS = Self::MK_DIR.bits | Self::RM_DIR.bits | Self::PUT.bits | Self::DEL.bits | Self::RENAME.bits;
impl UserWithPermissions for User {
fn permissions(&self) -> VfsOperations {
self.vfs_permissions
}
}

Expand Down
Loading

0 comments on commit 23782b8

Please sign in to comment.