Skip to content

Commit b71a2cb

Browse files
committed
Add storage permissions to UserDetail
This extends the UserDetail trait with a storage_permissions method that allow storage back-ends to limit what a user can do.
1 parent 0c03169 commit b71a2cb

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/auth/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ pub(crate) mod authenticator;
6363
pub use authenticator::{AuthenticationError, Authenticator, ClientCert, Credentials};
6464

6565
mod user;
66-
pub use user::{DefaultUser, UserDetail};
66+
pub use user::{DefaultUser, StoragePermissions, UserDetail};

src/auth/user.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bitflags::bitflags;
12
use std::{
23
fmt::{self, Debug, Display, Formatter},
34
path::Path,
@@ -27,6 +28,39 @@ pub trait UserDetail: Send + Sync + Display + Debug {
2728
fn home(&self) -> Option<&Path> {
2829
None
2930
}
31+
32+
/// Tells what the user is authorised to do in terms of FTP filesystem operations.
33+
///
34+
/// The default implementation gives all permissions.
35+
fn storage_permissions(&self) -> StoragePermissions {
36+
StoragePermissions::all()
37+
}
38+
}
39+
40+
bitflags! {
41+
/// The FTP operations that can be enabled/disabled for the storage back-end.
42+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
43+
pub struct StoragePermissions: u32 {
44+
/// If set allows FTP make directory
45+
const MK_DIR = 0b00000001;
46+
/// If set allows FTP remove directory
47+
const RM_DIR = 0b00000010;
48+
/// If set allows FTP GET i.e. clients can download files.
49+
const GET = 0b00000100;
50+
/// If set allows FTP PUT i.e. clients can upload files.
51+
const PUT = 0b00001000;
52+
/// If set allows FTP DELE i.e. clients can remove files.
53+
const DEL = 0b00010000;
54+
/// If set allows FTP RENAME i.e. clients can rename directories and files
55+
const RENAME = 0b00100000;
56+
/// If set allows the extended SITE MD5 command to calculate checksums
57+
const MD5 = 0b01000000;
58+
/// If set allows clients to list the contents of a directory.
59+
const LIST = 0b10000000;
60+
61+
/// Convenience aggregation of all the write operation bits.
62+
const WRITE_OPS = Self::MK_DIR.bits() | Self::RM_DIR.bits() | Self::PUT.bits() | Self::DEL.bits() | Self::RENAME.bits();
63+
}
3064
}
3165

3266
/// DefaultUser is a default implementation of the `UserDetail` trait that doesn't hold any user

src/storage/storage_backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub trait Metadata {
6767
}
6868
}
6969

70-
/// Represents the permissions of a _FTP File_
70+
/// Represents the permissions of an _FTP File_
7171
pub struct Permissions(pub u32);
7272

7373
const PERM_READ: u32 = 0b100100100;

0 commit comments

Comments
 (0)