Allow building without server
This commit is contained in:
parent
ba5fa16cc1
commit
70b8ff57f5
|
@ -3,7 +3,8 @@ name = "quinoa"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
server = ["dep:pam-client", "dep:pam-client-macos"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.71"
|
||||
|
@ -30,7 +31,7 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
|||
triggered = "0.1.2"
|
||||
|
||||
[target.'cfg(not(target_os = "macos"))'.dependencies]
|
||||
pam-client = { version = "0.5.0", default-features = false, features = ["serde"] }
|
||||
pam-client = { version = "0.5.0", default-features = false, features = ["serde"], optional = true }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
pam-client-macos = { package = "pam-client", version = "0.5.0", path = "../../../../../Users/michael/b/rust-pam-client", default-features = false, features = ["serde"] }
|
||||
pam-client-macos = { package = "pam-client", version = "0.5.0", path = "../../../../../Users/michael/b/rust-pam-client", default-features = false, features = ["serde"], optional = true }
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -12,7 +12,7 @@ mod pty;
|
|||
mod terminfo;
|
||||
mod user_info;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(all(feature = "server", target_os = "macos"))]
|
||||
use pam_client_macos as pam_client;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
|
@ -31,6 +31,7 @@ use std::task::Poll;
|
|||
use anyhow::{Context, Result};
|
||||
use base64::Engine as _;
|
||||
use nix::unistd::{Gid, Uid};
|
||||
#[cfg(feature = "server")]
|
||||
use pam_client::ConversationHandler;
|
||||
use quinn::{ReadExactError, RecvStream, SendStream};
|
||||
use rustls::client::ServerCertVerifier;
|
||||
|
@ -102,6 +103,7 @@ async fn main() -> Result<()> {
|
|||
async fn run_cmd(mut args: std::env::Args) -> Result<()> {
|
||||
let cmd = args.next().expect("COMMAND");
|
||||
match cmd.as_str() {
|
||||
#[cfg(feature = "server")]
|
||||
"server" => run_server().await,
|
||||
"client" => run_client(args).await,
|
||||
_ => Err(anyhow!("Unrecognized command: {}", cmd)),
|
||||
|
@ -119,6 +121,7 @@ struct ClientConfig {
|
|||
known_hosts: parking_lot::Mutex<Vec<KnownHost<'static>>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
async fn run_server() -> Result<()> {
|
||||
let cfg = {
|
||||
let opt_listen = std::env::var("BIND_ADDR")
|
||||
|
@ -734,7 +737,7 @@ async fn do_auth_prompt(
|
|||
stdout.write_all(&prompt).await?;
|
||||
let answer = rpassword::read_password()?;
|
||||
let answer = CString::new(answer)?;
|
||||
write_msg(send, &Answer::Prompt(Ok(answer))).await?;
|
||||
write_msg(send, &Answer::Prompt(answer)).await?;
|
||||
},
|
||||
Question::TextInfo(s) => {
|
||||
stdout.write_all(b"INFO ").await?;
|
||||
|
@ -765,6 +768,7 @@ async fn do_auth_prompt(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
async fn greet_conn(cfg: &'static ServerConfig, conn: quinn::Connecting) -> Result<()> {
|
||||
info!("greeting connection");
|
||||
|
||||
|
@ -789,8 +793,6 @@ async fn greet_conn(cfg: &'static ServerConfig, conn: quinn::Connecting) -> Resu
|
|||
}
|
||||
|
||||
mod auth {
|
||||
use super::pam_client;
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -808,10 +810,11 @@ mod auth {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum Answer {
|
||||
Prompt(Result<CString, pam_client::ErrorCode>),
|
||||
Prompt(CString),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
async fn authenticate_conn(cfg: &'static ServerConfig, conn: &quinn::Connection) -> Result<()> {
|
||||
use auth::*;
|
||||
|
||||
|
@ -855,7 +858,7 @@ async fn authenticate_conn(cfg: &'static ServerConfig, conn: &quinn::Connection)
|
|||
echo: true,
|
||||
})?;
|
||||
match self.answer()? {
|
||||
Answer::Prompt(r) => r,
|
||||
Answer::Prompt(s) => Ok(s),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -868,7 +871,7 @@ async fn authenticate_conn(cfg: &'static ServerConfig, conn: &quinn::Connection)
|
|||
echo: false,
|
||||
})?;
|
||||
match self.answer()? {
|
||||
Answer::Prompt(r) => r,
|
||||
Answer::Prompt(s) => Ok(s),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,6 +1025,7 @@ async fn authenticate_conn(cfg: &'static ServerConfig, conn: &quinn::Connection)
|
|||
.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
async fn handle_conn(
|
||||
cfg: &'static ServerConfig,
|
||||
conn: &quinn::Connection,
|
||||
|
|
Loading…
Reference in New Issue