Skip to main content

directory_scan/
directory_scan.rs

1#!/usr/bin/env cargo
2//! Directory scanning example
3//! 
4//! Run with: cargo run --example directory_scan
5
6use execheck::{scan_directory, print_report, OutputFormat, ScanOptions, FileFilter};
7use std::path::PathBuf;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    // Configure scan options
11    let options = ScanOptions {
12        recursive: false,        // Only scan top level
13        issues_only: true,       // Only show files with security issues
14        strict: false,          // Don't exit on issues
15        file_filter: FileFilter::All, // All executable types
16        one_filesystem: false,   // Allow crossing filesystem boundaries
17    };
18    
19    // Scan a directory (adjust path as needed)
20    let scan_path = PathBuf::from("/usr/bin");
21    println!("Scanning directory: {} (issues only)", scan_path.display());
22    
23    match scan_directory(&scan_path, &options) {
24        Ok(report) => {
25            println!("\n=== Scan Summary ===");
26            println!("Total files analyzed: {}", report.summary.total_files);
27            println!("Secure files: {}", report.summary.secure_files);
28            println!("Files with issues: {}", report.summary.insecure_files);
29            println!("Unsupported files: {}", report.summary.unsupported_files);
30            
31            if report.summary.insecure_files > 0 {
32                println!("\n=== Files with Security Issues ===");
33                print_report(&report, &OutputFormat::Human, None)?;
34            } else {
35                println!("\nAll analyzed files have good security posture! ✓");
36            }
37        }
38        Err(e) => {
39            eprintln!("Failed to scan directory: {}", e);
40            std::process::exit(1);
41        }
42    }
43    
44    Ok(())
45}