Skip to content

Commit

Permalink
server: Load and dispatch login/default collection
Browse files Browse the repository at this point in the history
This change loads and dispatches the login/default collection/keyring into
the object tree.

This change also adds,
--login command line option to oo7-daemon.
-l, --login option will read a password from stdin, and use it to unlock
the login keyring.
Note: currently -l option will only load the login keyring and not perform
anything related to unlocking the keyring.

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed Oct 22, 2024
1 parent 31dcf63 commit 7ff8bfe
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ rust-version.workspace = true
version.workspace = true

[dependencies]
clap.workspace = true
oo7 = { workspace = true, features = ["unstable"] }
rand = "0.8"
rpassword = "7.3"
serde.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing = "0.1"
Expand Down
34 changes: 33 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,47 @@ mod service;
mod service_manager;
mod session;

use clap::Parser;
use oo7::portal::Secret;
use service::{Result, Service};

const BINARY_NAME: &str = env!("CARGO_BIN_NAME");

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(
short = 'l',
long,
default_value_t = false,
help = "Read a password from stdin, and use it to unlock the login keyring."
)]
login: bool,
}

#[tokio::main]
async fn main() -> Result<()> {
let secret: Option<Secret> = None;
let args = Args::parse();
let mut secret: Option<Secret> = None;
tracing_subscriber::fmt::init();

if args.login {
match rpassword::prompt_password("Enter the login password: ") {
Ok(password) => {
if password.is_empty() {
tracing::error!("Login password can't be empty.");
std::process::exit(1);
} else {
secret = Some(Secret::from(password.into_bytes()))
}
}
Err(err) => {
tracing::error!("{err}");
std::process::exit(1);
}
};
}

tracing::info!("Starting {}", BINARY_NAME);

let connection = Service::run().await?;
Expand Down
20 changes: 18 additions & 2 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,24 @@ impl Service {
let manager = service.manager();

if secret.is_some() {
// this is for the login collection
// create and dispatch login/default collection
let login = Collection::new(
"login",
"default",
manager.clone(),
Arc::new(match Keyring::open("login", secret.unwrap()).await {
Ok(keyring) => keyring,
Err(err) => {
tracing::error!("Failed to open login keyring: {}", err);
std::process::exit(1);
}
}),
);
service.set_collections(login.path().clone()).await;
connection
.object_server()
.at(login.path().clone(), login)
.await?;
}

// create and dispatch temporary session collection
Expand All @@ -174,7 +191,6 @@ impl Service {
}),
);
service.set_collections(session.path().clone()).await;

connection
.object_server()
.at(session.path().clone(), session)
Expand Down

0 comments on commit 7ff8bfe

Please sign in to comment.