Add a separate client binary, with some common code to the server.

The cargo workspace thing was a PITA to figure out, but it seems to be working.  Could maybe be simplified?
This commit is contained in:
Barry Pederson
2024-11-02 15:58:35 -07:00
parent 46ad77f19e
commit 076e48f457
16 changed files with 380 additions and 255 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "client"
version = "0.2.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.20", features = ["derive"] }
common = { path = "../common" }
+23
View File
@@ -0,0 +1,23 @@
mod options;
use crate::options::OPTIONS;
use common::{read_string, Request};
use std::os::unix::net::UnixStream;
fn main() -> std::io::Result<()> {
let mut stream = UnixStream::connect(&OPTIONS.socket_name)?;
println!("Connected to server");
let request = Request {
userid: OPTIONS.username.clone(),
password: OPTIONS.password.clone(),
service: "ignore-this".to_string(),
realm: "also-ignore-this".to_string(),
};
request.write_to_stream(&mut stream)?;
let response = read_string(&mut stream)?;
println!("Response: {}", response);
Ok(())
}
+22
View File
@@ -0,0 +1,22 @@
use clap::Parser;
use std::path::PathBuf;
use std::sync::LazyLock;
#[derive(Parser, Clone, Debug)]
/// saslauthd test client
pub struct Opt {
#[arg(
short = 'f',
long = "socket-name",
default_value = "/tmp/saslauthd.sock"
)]
pub socket_name: PathBuf,
#[arg(default_value = "bp")]
pub username: String,
#[arg(default_value = "some-rad-password")]
pub password: String,
}
pub static OPTIONS: LazyLock<Opt> = LazyLock::new(Opt::parse);