From 8308f373253be4dd352be4ced44f89d98a99c3ef Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:30:27 +0300 Subject: [PATCH 01/10] style rule "Prototypes should not have variable names associated with the types" --- daemon.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon.h b/daemon.h index 440cf01..ca24fe8 100644 --- a/daemon.h +++ b/daemon.h @@ -1,6 +1,6 @@ #ifndef DAEMON_H #define DAEMON_H 1 void daemonShutdown(); -void signal_handler(int sig); -void daemonize(char *rundir, char *pidfile); +void signal_handler(int); +void daemonize(char *, char *); #endif From 33a3feb1872af3dd853c04cfa9dd8b51df4b5a14 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:31:22 +0300 Subject: [PATCH 02/10] style rule "Kernel include files come first; /usr/include files should be shorted" --- daemon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/daemon.c b/daemon.c index 159b7fb..d7b804b 100644 --- a/daemon.c +++ b/daemon.c @@ -3,17 +3,17 @@ * http://www.4pmp.com/2009/12/a-simple-daemon-in-c/ * with a few adjustments to better fit our needs. */ +#include +#include + +#include +#include +#include #include #include #include #include -#include -#include -#include #include -#include -#include - #include "daemon.h" From dc64dab5fa49b270095a1c0d400f6e451fb36840 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:33:47 +0300 Subject: [PATCH 03/10] style rule "Kernel include files come first; network includes next, blank line, ordered /usr/include list" --- dnsbl-divert.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dnsbl-divert.c b/dnsbl-divert.c index dde4b3d..d99ce90 100644 --- a/dnsbl-divert.c +++ b/dnsbl-divert.c @@ -33,26 +33,28 @@ #include #include #include +#include +#include #include #include #include #include #include #include -#include -#include #include #include + +#include // for isdigit +#include +#include +#include +#include #include #include #include -#include #include #include // for getopt -#include // for isdigit -#include -#include -#include + #include "stdpf.h" #include "daemon.h" From b33467def9f79f4a7e8ee82abe14d721cbe13c46 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:36:53 +0300 Subject: [PATCH 04/10] style include file rules --- stdpf.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stdpf.c b/stdpf.c index 1aacf34..d064356 100644 --- a/stdpf.c +++ b/stdpf.c @@ -1,20 +1,21 @@ #include #include #include +#include +#include #include #include #include #include #include -#include -#include #include -#include + +#include #include #include -#include +#include #include -#include +#include #include "stdpf.h" From b2acb0cac533976e4ef7d2bf64cfe08c53194525 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:37:19 +0300 Subject: [PATCH 05/10] style rule function prototypes --- stdpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdpf.h b/stdpf.h index 826094f..596440d 100644 --- a/stdpf.h +++ b/stdpf.h @@ -10,7 +10,7 @@ if (mask < 8) b[0] &= (0xFF << ( 8 - mask)); \ } -void add(char *tname, struct in_addr *ip, uint8_t mask); +void add(char *, struct in_addr *, uint8_t); void ets_pf_open(); void ets_pf_close(); #endif From a4fa9b1526fe73fb024938902c85d310d3609c0c Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:48:42 +0300 Subject: [PATCH 06/10] replace DAEMON_NAME with __progname --- dnsbl-divert.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dnsbl-divert.c b/dnsbl-divert.c index d99ce90..562d84e 100644 --- a/dnsbl-divert.c +++ b/dnsbl-divert.c @@ -88,7 +88,8 @@ static char *revip_str(char *ip) { } void usage() { - printf("usage: %s -p pnum -t tbl -c tch [dns]\n",DAEMON_NAME); + extern char *__progname; + printf("usage: %s -p pnum -t tbl -c tch [dns]\n",__progname); printf("\tpnum divert port number to bind (1-65535)\n"); printf("\ttbl table to populate with DNSBLed hosts (up to %d chars)\n",PF_TABLE_NAME_SIZE); printf("\ttch table to cache already-looked-up hosts (up to %d chars)\n",PF_TABLE_NAME_SIZE); @@ -110,9 +111,11 @@ int main(int argc, char *argv[]) { char pidPath[64]; char syslogLine[256]; + extern char *__progname; extern char *optarg; extern int optind; int ch, cherr=0, pflag=0, tflag=0, cflag=0; + while ((ch = getopt(argc, argv, "p:t:c:")) != -1) { switch (ch) { case 'p': @@ -157,7 +160,7 @@ int main(int argc, char *argv[]) { /* Logging */ setlogmask(LOG_UPTO(LOG_INFO)); - openlog(DAEMON_NAME, LOG_CONS | LOG_PERROR, LOG_USER); + openlog(__progname, LOG_CONS | LOG_PERROR, LOG_USER); syslog(LOG_INFO, "Daemon starting up"); From 01d6aa6bccfa1e42f4337226b2da749a4dacda00 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:49:10 +0300 Subject: [PATCH 07/10] sort order based on style --- heartbleed-divert.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/heartbleed-divert.c b/heartbleed-divert.c index 4370b37..7c924d1 100644 --- a/heartbleed-divert.c +++ b/heartbleed-divert.c @@ -25,10 +25,11 @@ #include #include #include + +#include #include #include #include -#include #define DIVERT_PORT 700 #define DAEMON_NAME "heartbleed-divert" From ceebc30b5a1c7edc2c8f117907ef817959882d51 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:52:22 +0300 Subject: [PATCH 08/10] replace DAEMON_NAME with __progname --- bofh-divert.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bofh-divert.c b/bofh-divert.c index 31c86eb..c3f7fa7 100644 --- a/bofh-divert.c +++ b/bofh-divert.c @@ -52,7 +52,8 @@ #define DAEMON_NAME "bofh-divert" void usage() { - fprintf(stderr,"usage: %s -p pnum -t tname\n",DAEMON_NAME); + extern char *__progname; + fprintf(stderr,"usage: %s -p pnum -t tname\n",__progname); fprintf(stderr,"\tpnum divert port number to bind (1-65535)\n"); fprintf(stderr,"\ttname table to add collected host IPs (up to %d chars)\n",PF_TABLE_NAME_SIZE); exit(EXIT_FAILURE); From 9c28d39a5b096b43611acabba86199c536a4a85f Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 12:59:44 +0300 Subject: [PATCH 09/10] move towards a cleaner makefile for better ports support --- Makefile | 48 ++++--------------- bofh/Makefile | 9 ++++ bofh-divert.c => bofh/bofh-divert.c | 0 dnsbl/Makefile | 9 ++++ dnsbl-divert.c => dnsbl/dnsbl-divert.c | 0 heartbleed/Makefile | 9 ++++ .../heartbleed-divert.c | 0 7 files changed, 35 insertions(+), 40 deletions(-) create mode 100644 bofh/Makefile rename bofh-divert.c => bofh/bofh-divert.c (100%) create mode 100644 dnsbl/Makefile rename dnsbl-divert.c => dnsbl/dnsbl-divert.c (100%) create mode 100644 heartbleed/Makefile rename heartbleed-divert.c => heartbleed/heartbleed-divert.c (100%) diff --git a/Makefile b/Makefile index 0fe36a3..2e3942b 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,8 @@ -# Build the diverters dont write this with eclipse :P -# SAMPLE needs work -# - -BINDIR = /usr/local/sbin - -all: bofh-divert dnsbl-divert - -install: install-bofh install-dnsbl - -uninstall: uninstall-bofh uninstall-dnsbl - -clean: - rm -rf stdpf.o daemon.o dnsbl-divert bofh-divert - -bofh-divert: bofh-divert.c daemon.o stdpf.o - gcc -o bofh-divert bofh-divert.c daemon.o stdpf.o - -dnsbl-divert: dnsbl-divert.c daemon.o stdpf.o - gcc -o dnsbl-divert dnsbl-divert.c daemon.o stdpf.o - -daemon.o: daemon.c - gcc -c daemon.c - -stdpf.o: stdpf.c - gcc -c stdpf.c - -install-bofh: - install -Ss -o root -g wheel -m 750 bofh-divert $(BINDIR)/bofh-divert - install -o root -g wheel -m 750 rc.bofh /etc/rc.d/bofh_divert - -install-dnsbl: - install -Ss -o root -g wheel -m 750 dnsbl-divert $(BINDIR)/dnsbl-divert - install -o root -g wheel -m 750 rc.dnsbl /etc/rc.d/dnsbl_divert - -uninstall-bofh: - rm $(BINDIR)/bofh-divert /etc/rc.d/rc.bofh - -uninstall-dnsbl: - rm $(BINDIR)/dnsbl-divert /etc/rc.d/rc.dnsbl +# taken from pfstatd +SUBDIR= bofh +SUBDIR+= dnsbl +#SUBDIR+= heartbleed +CFLAGS+= -Wall +CFLAGS+= -I${.CURDIR} + +.include \ No newline at end of file diff --git a/bofh/Makefile b/bofh/Makefile new file mode 100644 index 0000000..1747e45 --- /dev/null +++ b/bofh/Makefile @@ -0,0 +1,9 @@ +# taken from pfstatd +PROG= bofh-divert +SRCS= bofh-divert.c daemon.c stdpf.c +#MAN= pfstatd.8 +.PATH: ${.CURDIR}/.. +CFLAGS+= -Wall +CFLAGS+= -I${.CURDIR}/.. + +.include \ No newline at end of file diff --git a/bofh-divert.c b/bofh/bofh-divert.c similarity index 100% rename from bofh-divert.c rename to bofh/bofh-divert.c diff --git a/dnsbl/Makefile b/dnsbl/Makefile new file mode 100644 index 0000000..0369680 --- /dev/null +++ b/dnsbl/Makefile @@ -0,0 +1,9 @@ +# taken from pfstatd +PROG= dnsbl-divert +SRCS= dnsbl-divert.c daemon.c stdpf.c +#MAN= pfstatd.8 +.PATH: ${.CURDIR}/.. +CFLAGS+= -Wall +CFLAGS+= -I${.CURDIR}/.. + +.include \ No newline at end of file diff --git a/dnsbl-divert.c b/dnsbl/dnsbl-divert.c similarity index 100% rename from dnsbl-divert.c rename to dnsbl/dnsbl-divert.c diff --git a/heartbleed/Makefile b/heartbleed/Makefile new file mode 100644 index 0000000..f602db2 --- /dev/null +++ b/heartbleed/Makefile @@ -0,0 +1,9 @@ +# taken from pfstatd +PROG= heartbleed-divert +SRCS= heartbleed-divert.c +#MAN= pfstatd.8 +.PATH: ${.CURDIR}/.. +CFLAGS+= -Wall +CFLAGS+= -I${.CURDIR}/.. + +.include \ No newline at end of file diff --git a/heartbleed-divert.c b/heartbleed/heartbleed-divert.c similarity index 100% rename from heartbleed-divert.c rename to heartbleed/heartbleed-divert.c From 71ba6580de48773cf77f140eb26dc0e7b22cfa05 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 29 Jun 2015 14:24:50 +0300 Subject: [PATCH 10/10] make sure we empty the man page build for now --- bofh/Makefile | 2 +- dnsbl/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bofh/Makefile b/bofh/Makefile index 1747e45..026d3fc 100644 --- a/bofh/Makefile +++ b/bofh/Makefile @@ -1,7 +1,7 @@ # taken from pfstatd PROG= bofh-divert SRCS= bofh-divert.c daemon.c stdpf.c -#MAN= pfstatd.8 +MAN= .PATH: ${.CURDIR}/.. CFLAGS+= -Wall CFLAGS+= -I${.CURDIR}/.. diff --git a/dnsbl/Makefile b/dnsbl/Makefile index 0369680..2e2f24f 100644 --- a/dnsbl/Makefile +++ b/dnsbl/Makefile @@ -1,7 +1,7 @@ # taken from pfstatd PROG= dnsbl-divert SRCS= dnsbl-divert.c daemon.c stdpf.c -#MAN= pfstatd.8 +MAN= .PATH: ${.CURDIR}/.. CFLAGS+= -Wall CFLAGS+= -I${.CURDIR}/..