aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-07-02 23:01:46 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-07-02 23:01:46 +0200
commita34aedfda6d9c39d6d38c91f1ae9a342f98ca0aa (patch)
tree3c17ae954cbbce6c6b85e672e9002a21d06c67eb /lockchain-core
parentf903e653d59fa923210f5a583f7f8adc663a5dd5 (diff)
Throwing stuff against walls
Diffstat (limited to 'lockchain-core')
-rw-r--r--lockchain-core/src/errors.rs28
-rw-r--r--lockchain-core/src/users/auth.rs9
2 files changed, 31 insertions, 6 deletions
diff --git a/lockchain-core/src/errors.rs b/lockchain-core/src/errors.rs
index 18f23f3..6a5b632 100644
--- a/lockchain-core/src/errors.rs
+++ b/lockchain-core/src/errors.rs
@@ -8,9 +8,12 @@
//! turning a `VaultAlreadyExists` failure to
//! a `FailedInitialise`.
+use std::error;
+use std::fmt::{Display, Formatter, Result};
+
/// A collection of common error codes that can be
/// returned by lockchain API functions
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub enum Error {
/// Creating a vault where one already exists
VaultAlreadyExists,
@@ -35,3 +38,26 @@ pub enum Error {
// #[hidden_docs]
__NonExhaustive,
}
+
+impl error::Error for Error {}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ Error::VaultAlreadyExists => "Vault already exists",
+ Error::InvalidPath => "Path invalid",
+ Error::InvalidName => "Name invalid",
+ Error::InvalidCryptoLayer => "Cryptography layer incompatible",
+ Error::FailedCrypto => "Failed cryptographic operation",
+ Error::FailedSelfTest => "Failed self text",
+ Error::FailedLoading => "Failed to load",
+ Error::FailedInitalise => "Failed to initialise",
+ Error::FailedCreation => "Failed to create",
+ _ => "Unknown failure",
+ }
+ )
+ }
+}
diff --git a/lockchain-core/src/users/auth.rs b/lockchain-core/src/users/auth.rs
index ad25757..ec2aea7 100644
--- a/lockchain-core/src/users/auth.rs
+++ b/lockchain-core/src/users/auth.rs
@@ -6,7 +6,7 @@
// use nix::sys::wait::*;
// use nix::unistd::{fork, ForkResult};
-use pam_auth::{self, Authenticator, PamError, Result as PamResult};
+use pam_auth::Authenticator;
#[derive(Debug)]
pub enum AuthError {
@@ -17,22 +17,21 @@ pub enum AuthError {
}
/// Simple way to authenticate a user for administrative actions
-///
+///
/// Attempts to open a PAM session for the provided user/pw combination
/// then attempts to write to a tmpfile in the lockchain config directory.
/// If this action is successful the user is either the same running the
/// lockchain server *or* has access to the file via group permissions.
-///
+///
/// This does rely on `lockchain` being properly configured on the server
/// i.e. not using public permissions for the configuration/ state directory.
-///
+///
/// **Note** as of `lockchain v0.9.0` this function has not been implemented
/// yet due to issues in the `pam-auth` dependency.
#[allow(unused_variables)]
pub fn pam_authenticate(username: &str, password: &str) -> Result<(), AuthError> {
// Err(AuthError::FailedPAM)
-
// match fork().map_err(|_| AuthError::FailedFork)? {
// ForkResult::Parent { child } => {
// waitpid(child, None).unwrap();