commit 9af015166c2b138c72ea077efa0e71d353afc1b0
parent 6951360748af18a62b6c743a132091fe8391fca0
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sun, 10 Oct 2021 00:07:51 +0200
Check blacklist and whitelist
Ensure that they don't have any overlapping entries.
Diffstat:
M | main.c | | | 26 | ++++++++++++++++++++++++++ |
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/main.c b/main.c
@@ -85,6 +85,29 @@ readline(int fd)
}
int
+foverlap(int fd1, int fd2)
+{
+ FILE *fp1, *fp2;
+ int r1, r2;
+ char buf1[16], buf2[16];
+
+ fp1 = fdopen(fd1, "r");
+ fp2 = fdopen(fd2, "r");
+ do {
+ r1 = fscanf(fp1, "%s\n", buf1);
+ if (r1 != EOF) {
+ do {
+ r2 = fscanf(fp2, "%s\n", buf2);
+ if (r2 != EOF
+ && !strcmp(buf1, buf2))
+ return 1;
+ } while (r2 != EOF);
+ }
+ } while(r1 != EOF);
+ return 0;
+}
+
+int
main(int argc, char **argv)
{
char *line;
@@ -105,6 +128,9 @@ main(int argc, char **argv)
if (fd_white == -1)
err(1, "open failed: %s", white_list);
+ if (foverlap(fd_black, fd_white))
+ errx(1, "blacklist and whitelist are not mutually exclusive.");
+
for ( ; ; ) {
while ((line = readline(fd)) == NULL) {
usleep(500000);