Fixed warnings, lots of stubs in the code, will be implemented later.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use linux_hello_common::{Config, Result};
|
||||
use tracing::{info, Level};
|
||||
use tracing::{info, warn, Level};
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
#[derive(Parser)]
|
||||
@@ -105,6 +105,26 @@ enum Commands {
|
||||
},
|
||||
}
|
||||
|
||||
/// Get the real username (handles sudo case)
|
||||
fn get_real_username() -> String {
|
||||
// Try SUDO_USER first (set when running with sudo)
|
||||
// This is the most reliable way to get the real user when using sudo
|
||||
std::env::var("SUDO_USER")
|
||||
.or_else(|_| std::env::var("USER"))
|
||||
.or_else(|_| std::env::var("USERNAME"))
|
||||
.unwrap_or_else(|_| {
|
||||
// Final fallback: try to get from whoami command
|
||||
std::process::Command::new("whoami")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|output| {
|
||||
String::from_utf8(output.stdout).ok()
|
||||
})
|
||||
.map(|s| s.trim().to_string())
|
||||
.unwrap_or_else(|| "unknown".to_string())
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
@@ -212,6 +232,20 @@ async fn cmd_capture(
|
||||
info!("Saved frame {} (converted from YUYV to grayscale)", filename);
|
||||
}
|
||||
}
|
||||
PixelFormat::Mjpeg => {
|
||||
// Decode MJPEG and save as PNG
|
||||
let filename = format!("{}/frame_{:03}.png", output, i);
|
||||
match image::load_from_memory(&frame.data) {
|
||||
Ok(img) => {
|
||||
let gray = img.to_luma8();
|
||||
gray.save(&filename).map_err(|e| linux_hello_common::Error::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?;
|
||||
info!("Saved frame {} (decoded from MJPEG)", filename);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to decode MJPEG frame {}: {}", i, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let filename = format!("{}/frame_{:03}.raw", output, i);
|
||||
std::fs::write(&filename, &frame.data)?;
|
||||
@@ -402,10 +436,8 @@ async fn cmd_enroll(config: &Config, label: &str) -> Result<()> {
|
||||
|
||||
info!("Starting enrollment with label: {}", label);
|
||||
|
||||
// Get current user
|
||||
let user = std::env::var("USER")
|
||||
.or_else(|_| std::env::var("USERNAME"))
|
||||
.unwrap_or_else(|_| "unknown".to_string());
|
||||
// Get real user (handles sudo)
|
||||
let user = get_real_username();
|
||||
|
||||
println!("Enrolling user: {}", user);
|
||||
println!("Label: {}", label);
|
||||
@@ -490,10 +522,8 @@ async fn cmd_remove(_config: &Config, label: Option<&str>, all: bool) -> Result<
|
||||
async fn cmd_test(config: &Config, verbose: bool, _debug: bool) -> Result<()> {
|
||||
use linux_hello_daemon::auth::AuthService;
|
||||
|
||||
// Get current user
|
||||
let user = std::env::var("USER")
|
||||
.or_else(|_| std::env::var("USERNAME"))
|
||||
.unwrap_or_else(|_| "unknown".to_string());
|
||||
// Get real user (handles sudo)
|
||||
let user = get_real_username();
|
||||
|
||||
println!("Testing authentication for user: {}", user);
|
||||
println!("Please look at the camera...");
|
||||
|
||||
Reference in New Issue
Block a user