From 43370d1f5364d77fa5ad9699e9d24adbca1b3f18 Mon Sep 17 00:00:00 2001 From: Pyro57000 <147988717+Pyro57000@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:48:15 -0600 Subject: [PATCH] sharp share sorting utility --- sharpshares_sorter/Cargo.lock | 7 +++++ sharpshares_sorter/Cargo.toml | 8 +++++ sharpshares_sorter/src/main.rs | 56 ++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 sharpshares_sorter/Cargo.lock create mode 100644 sharpshares_sorter/Cargo.toml create mode 100644 sharpshares_sorter/src/main.rs diff --git a/sharpshares_sorter/Cargo.lock b/sharpshares_sorter/Cargo.lock new file mode 100644 index 0000000..7a1f92c --- /dev/null +++ b/sharpshares_sorter/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "sharpshares_sorter" +version = "0.1.0" diff --git a/sharpshares_sorter/Cargo.toml b/sharpshares_sorter/Cargo.toml new file mode 100644 index 0000000..2acd8b4 --- /dev/null +++ b/sharpshares_sorter/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "sharpshares_sorter" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/sharpshares_sorter/src/main.rs b/sharpshares_sorter/src/main.rs new file mode 100644 index 0000000..0d51829 --- /dev/null +++ b/sharpshares_sorter/src/main.rs @@ -0,0 +1,56 @@ +use std::fs; +use std::env; +use std::io::Write; + +fn main() { + let args: Vec = env::args().collect(); + if args.len() != 3{ + print!(" +Usage: +sharpshares_sorter /path/to/sharpshares/output /path/to/save/output + "); + } + else{ + let mut writable: Vec<&str> = Vec::new(); + let mut readable: Vec<&str> = Vec::new(); + let mut outfile = fs::File::create(&args[2]).expect("error creating output file"); + let shares = fs::read_to_string(&args[1]).expect("error reading shares file"); + let shares_vec: Vec<&str> = shares.split("\n").collect(); + for share in shares_vec{ + if share.len() != 0{ + let share_vec: Vec<&str> = share.split(" ").collect(); + let permission = share_vec[0]; + let share_name = share_vec[1]; + if permission.contains("r"){ + let share_name_trimmed = share_name.trim_end(); + readable.push(share_name_trimmed); + } + if permission.contains("w"){ + let share_name_trimmed = share_name.trim_end(); + writable.push(share_name_trimmed); + } + } + } + println!("writable!"); + writeln!(outfile, "********************************Writable*********************************").expect("error writing writable to outfile"); + writeln!(outfile, "++++++++++++++++++++++++++++++++admin access+++++++++++++++++++++++++++++").expect("error writing admin access to outfile"); + for share in &writable{ + if share.contains("C$") || share.contains("c$") || share.contains("Admin$"){ + println!("{}", share); + writeln!(outfile, "{}", share).expect("error writing admin share to outfile"); + } + } + writeln!(outfile, "++++++++++++++++++++++++++++++END OF ADMIN ACCESS++++++++++++++++++++++++++").expect("error writing admin ending porint"); + for share in &writable{ + println!("{}",share); + writeln!(outfile, "{}", share).expect("error writing writable shares to outfile"); + } + println!("==========================================================="); + println!("readable!"); + writeln!(outfile, "*******************************readable**********************************").expect("error writing readable to outfile"); + for share in readable{ + println!("{}", share); + writeln!(outfile,"{}", share).expect("error writing readable share to outfile"); + } + } +} \ No newline at end of file