summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2025-01-09 19:02:29 -0600
committer@syxhe <https://t.me/syxhe>2025-01-09 19:02:29 -0600
commitfa458059e57801dceb63a4ce0ddaef8ad5a49eb2 (patch)
treec3e0d60cbcbd08962ae713b51ea259f34b8239da
parent248e80cb5d5a411cc6362919f1b495f29fe57f9d (diff)
Figure out why linking wasn't working
-rw-r--r--src/encryption.c63
-rw-r--r--src/encryption.h3
2 files changed, 44 insertions, 22 deletions
diff --git a/src/encryption.c b/src/encryption.c
index 6da9603..828bde2 100644
--- a/src/encryption.c
+++ b/src/encryption.c
@@ -23,43 +23,60 @@ int checkSodium(void) {
23} 23}
24 24
25// To encrypt: 25// To encrypt:
26// 1- Create a temp file with the correct name in the root folder of the partition being encrypted 26// 1- Create a temp file with the correct name in the root folder of the partition being encrypted --
27 // 1.1- Detect the partition and find the root folder 27 // 1.1- Detect the partition and find the root folder -- DONE || NOT NECESSARY
28 // 1.2- Create the temp file with the correct name 28 // 1.2- Create the temp file -- DONE
29// 2- Encrypt the file's contents to the temp file 29// 2- Encrypt the file's contents to the temp file --
30 // 2.1- Open the file 30 // 2.1- Open the file --
31 // 2.2- Stream the file's contents into some encryption algo 31 // 2.2- Stream the file's contents into some encryption algo --
32 // 2.3- Pipe the output of the encryption into the temp file 32 // 2.3- Pipe the output of the encryption into the temp file --
33// 3- Once the file has been encrypted, hard link it back to the original location 33// 3- Once the file has been encrypted, hard link it back to the original location, with the right name --
34// 4- Delete the original file 34// 4- Delete the original file --
35// 5- Delete the temp file 35// 5- Delete the temp file --
36 36
37 37
38int maketmp(const char *dest) { 38int maketmp(const char *dest) {
39 int fd = open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR)); 39 return open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR));
40 if(fd < 0) 40}
41 error(1, errno, "Couldn't open temp file at %s", dest); 41
42int encrypttotmp(const char *toencrypt) {
43 struct stat esb;
44 int efd = -1;
45
46 // Make sure the file is real and an actual file that can be encrypted
47 if(stat(toencrypt, &esb) < 0)
48 return -1;
49 if(!S_ISREG(esb.st_mode))
50 return -2;
42 51
43 return fd; 52 // Open the file as read-only
53 if((efd = open(toencrypt, O_RDONLY)) < 0)
54 return -3;
55
56 // Need to get a secret key from a password and then set up cryptostream from libsodium
57
58 return 0;
44} 59}
45 60
61#define TESTING
62#ifdef TESTING
46 63
47#include <string.h> 64#include <string.h>
48 65
49int main(void) { 66int main(void) {
50 const char *testmsg = "we do a little testing\n"; 67 const char *dir = ".", *testmsg = "we do a little testing\n";
68 char *path = NULL;
51 69
52 int fd = maketmp("."); 70 int fd = maketmp(dir);
71 if(fd < 0)
72 error(1, errno, "Couldn't make temp file at %s", dir);
53 73
54 if(write(fd, testmsg, strlen(testmsg)) < 0) 74 if(write(fd, testmsg, strlen(testmsg)) < 0)
55 error(1, errno, "write broke"); 75 error(1, errno, "write broke");
56 76
57 // if(linkat(fd, "", AT_FDCWD, "kys/now", AT_EMPTY_PATH) < 0)
58 // error(1, errno, "linkat broke");
59
60 char *path = NULL;
61 asprintf(&path, "/proc/self/fd/%d", fd); 77 asprintf(&path, "/proc/self/fd/%d", fd);
62 linkat(AT_FDCWD, path, AT_FDCWD, "./test", AT_SYMLINK_FOLLOW); 78 linkat(AT_FDCWD, path, AT_FDCWD, "./test", AT_SYMLINK_FOLLOW);
79 free(path);
63 80
64 // Apparently, I don't have the CAP_DAC_READ_SEARCH capibility. Thanks for the solution, linux man pages 81 // Apparently, I don't have the CAP_DAC_READ_SEARCH capibility. Thanks for the solution, linux man pages
65 82
@@ -67,4 +84,6 @@ int main(void) {
67 error(1, errno, "close broke"); 84 error(1, errno, "close broke");
68 85
69 return 0; 86 return 0;
70} \ No newline at end of file 87}
88
89#endif \ No newline at end of file
diff --git a/src/encryption.h b/src/encryption.h
index 945f73d..b609d52 100644
--- a/src/encryption.h
+++ b/src/encryption.h
@@ -4,4 +4,7 @@
4// Checks if sodium is initialized. Initializes it if not 4// Checks if sodium is initialized. Initializes it if not
5int checkSodium(void); 5int checkSodium(void);
6 6
7// open() with the flags O_TMPFILE, O_WRONLY, O_CLOEXEC, and O_SYNC. Opened with mode S_IRUSR, S_IWUSR
8int maketmp(const char *dest);
9
7#endif \ No newline at end of file 10#endif \ No newline at end of file