#define _GNU_SOURCE #include "encryption.h" #include "shared.h" #include #include #include #include #include #include #include #include #include int checkSodium(void) { int ret = sodium_init(); if(ret < 0) error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting..."); return ret; } // To encrypt: // 1- Create a temp file with the correct name in the root folder of the partition being encrypted // 1.1- Detect the partition and find the root folder // 1.2- Create the temp file with the correct name // 2- Encrypt the file's contents to the temp file // 2.1- Open the file // 2.2- Stream the file's contents into some encryption algo // 2.3- Pipe the output of the encryption into the temp file // 3- Once the file has been encrypted, hard link it back to the original location // 4- Delete the original file // 5- Delete the temp file int maketmp(const char *dest) { int fd = open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR)); if(fd < 0) error(1, errno, "Couldn't open temp file at %s", dest); return fd; } #include int main(void) { const char *testmsg = "we do a little testing\n"; int fd = maketmp("."); if(write(fd, testmsg, strlen(testmsg)) < 0) error(1, errno, "write broke"); // if(linkat(fd, "", AT_FDCWD, "kys/now", AT_EMPTY_PATH) < 0) // error(1, errno, "linkat broke"); char *path = NULL; asprintf(&path, "/proc/self/fd/%d", fd); linkat(AT_FDCWD, path, AT_FDCWD, "./test", AT_SYMLINK_FOLLOW); // Apparently, I don't have the CAP_DAC_READ_SEARCH capibility. Thanks for the solution, linux man pages if(close(fd) < 0) error(1, errno, "close broke"); return 0; }