diff options
Diffstat (limited to 'src/encryption.c')
| -rw-r--r-- | src/encryption.c | 35 |
1 files changed, 22 insertions, 13 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 | ||
| 289 | CLEANUP_encryptviatmp: | 289 | CLEANUP_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 | ||
| 439 | int __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 | } | 448 | static 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 | ||
| 445 | ctqueue * 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); | 460 | ctqueue * 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 |
