Add mount command on linux

This commit is contained in:
oupson 2022-05-31 22:56:51 +02:00
parent f8dba77275
commit 8418d1795d
Signed by: oupson
GPG Key ID: 3BD88615552EFCB7
4 changed files with 140 additions and 3 deletions

100
Cargo.lock generated
View File

@ -116,6 +116,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -241,6 +247,22 @@ dependencies = [
"termcolor", "termcolor",
] ]
[[package]]
name = "fuser"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "104ed58f182bc2975062cd3fab229e82b5762de420e26cf5645f661402694599"
dependencies = [
"libc",
"log",
"memchr",
"page_size",
"pkg-config",
"smallvec",
"users",
"zerocopy",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.5" version = "0.14.5"
@ -382,6 +404,16 @@ version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435" checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435"
[[package]]
name = "page_size"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "password-hash" name = "password-hash"
version = "0.3.2" version = "0.3.2"
@ -402,6 +434,12 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "pkg-config"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]] [[package]]
name = "polyval" name = "polyval"
version = "0.5.3" version = "0.5.3"
@ -491,6 +529,7 @@ dependencies = [
"env_logger", "env_logger",
"log", "log",
"rustcryptfs-lib", "rustcryptfs-lib",
"rustcryptfs-linux",
"serde", "serde",
"serde_json", "serde_json",
] ]
@ -515,6 +554,12 @@ dependencies = [
[[package]] [[package]]
name = "rustcryptfs-linux" name = "rustcryptfs-linux"
version = "0.1.0" version = "0.1.0"
dependencies = [
"fuser",
"log",
"rustcryptfs-lib",
"thiserror",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
@ -586,6 +631,12 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
@ -609,6 +660,18 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "synstructure"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.3" version = "1.1.3"
@ -656,6 +719,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "universal-hash" name = "universal-hash"
version = "0.4.1" version = "0.4.1"
@ -666,6 +735,16 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "users"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
dependencies = [
"libc",
"log",
]
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -708,3 +787,24 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zerocopy"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "332f188cc1bcf1fe1064b8c58d150f497e697f49774aa846f2dc949d9a25f236"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0fbc82b82efe24da867ee52e015e58178684bd9dd64c34e66bdf21da2582a9f"
dependencies = [
"proc-macro2",
"syn",
"synstructure",
]

View File

@ -12,4 +12,7 @@ serde_json = "1.0.78"
clap = { version = "3.1.18", features = ["derive"] } clap = { version = "3.1.18", features = ["derive"] }
log = "0.4.17" log = "0.4.17"
rustcryptfs-lib = { path = "../rustcryptfs-lib" } rustcryptfs-lib = { path = "../rustcryptfs-lib" }
env_logger = "0.9.0" env_logger = "0.9.0"
[target.'cfg(target_os = "linux")'.dependencies]
rustcryptfs-linux = { path = "../rustcryptfs-linux" }

View File

@ -1,3 +1,5 @@
use std::path::PathBuf;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
@ -14,6 +16,9 @@ pub(crate) enum Commands {
// List file contained in a directory // List file contained in a directory
Ls(LsCommand), Ls(LsCommand),
/// Mount an encrypted folder
Mount(MountCommand),
} }
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
@ -42,4 +47,17 @@ pub(crate) struct LsCommand {
/// The password /// The password
#[clap(short, long)] #[clap(short, long)]
pub(crate) password : Option<String> pub(crate) password : Option<String>
} }
#[derive(Debug, Parser)]
pub(crate) struct MountCommand {
/// The directory
pub(crate) path: PathBuf,
/// The mount point
pub(crate) mountpoint: PathBuf,
/// The password
#[clap(short, long)]
pub(crate) password: Option<String>,
}

View File

@ -6,7 +6,7 @@ use std::{
use clap::Parser; use clap::Parser;
use args::{DecryptCommand, LsCommand}; use args::{DecryptCommand, LsCommand, MountCommand};
use rustcryptfs_lib::GocryptFs; use rustcryptfs_lib::GocryptFs;
mod args; mod args;
@ -19,6 +19,7 @@ fn main() -> anyhow::Result<()> {
match &args.command { match &args.command {
args::Commands::Decrypt(c) => decrypt_file(c), args::Commands::Decrypt(c) => decrypt_file(c),
args::Commands::Ls(c) => ls(c), args::Commands::Ls(c) => ls(c),
args::Commands::Mount(c) => mount(c),
} }
} }
@ -102,3 +103,18 @@ fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[cfg(target_os = "linux")]
fn mount(mount: &MountCommand) -> anyhow::Result<()> {
use rustcryptfs_linux::EncryptedFs;
let fs = EncryptedFs::new(&mount.path);
fs.mount(&mount.mountpoint);
Ok(())
}
#[cfg(not(target_os = "linux"))]
fn mount(mount: &MountCommand) -> anyhow::Result<()> {
unimplemented!()
}