From 0524358cef990482f4c1ccdde320ab9ad0309255 Mon Sep 17 00:00:00 2001 From: tyrolyean Date: Wed, 29 Apr 2020 00:08:34 +0200 Subject: [PATCH] Added instance id option to mark messages Signed-off-by: tyrolyean --- include/config.h | 2 ++ src/config.c | 4 ++++ src/detect.c | 1 + src/main.c | 24 +++++++++++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index adfd0b0..7ceb29a 100644 --- a/include/config.h +++ b/include/config.h @@ -26,4 +26,6 @@ extern uint16_t listen_port, forward_port; extern int abort_on_pgp, abort_on_dkim; +extern char* instance_id; + #endif /* CONFIG_H */ diff --git a/src/config.c b/src/config.c index 7d62b30..8cb4876 100644 --- a/src/config.c +++ b/src/config.c @@ -14,7 +14,11 @@ * specific language governing permissions and limitations * under the License. */ + #include "config.h" +#include + uint16_t listen_port = 4269, forward_port = 4270; int abort_on_pgp = true, abort_on_dkim = true; +char* instance_id = NULL; diff --git a/src/detect.c b/src/detect.c index bcf96cc..61fea86 100644 --- a/src/detect.c +++ b/src/detect.c @@ -58,6 +58,7 @@ bool detect_dkim(struct email_t* mail){ if(strcasestr(mail->message, dkim_signatures[i]) != NULL && strcasestr(mail->message, dkim_signatures[i]) <= (mail->message+mail->header_len)){ + /* DKIM only happens inside the header, not the body! */ points++; } diff --git a/src/main.c b/src/main.c index 99bdd72..aed82fd 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "network.h" #include "config.h" @@ -27,12 +30,13 @@ int main(int argc, char* argv[]){ {"noabort-dkim",no_argument, &abort_on_dkim,0}, {"in-port", required_argument, 0, 'i'}, {"out-port", required_argument, 0, 'o'}, + {"instance-id", required_argument, 0, 'n'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long (argc, argv, "i:o:pd", + c = getopt_long (argc, argv, "n:i:o:pd", long_options, &option_index); /* Detect the end of the options. */ @@ -50,6 +54,10 @@ int main(int argc, char* argv[]){ case 'o': forward_port = atoi(optarg); break; + + case 'n': + instance_id = optarg; + break; case '?': /* getopt_long already printed an error message. */ @@ -61,6 +69,17 @@ int main(int argc, char* argv[]){ } } + /* If not already specified, populate the instance ID with the sytem + * hostname. + */ + if(instance_id == NULL){ + instance_id = malloc(HOST_NAME_MAX + 1); + memset(instance_id, 0, HOST_NAME_MAX + 1); + if(gethostname(instance_id, HOST_NAME_MAX) < 0){ + perror("gethostname failed! set instance id manually"); + } + } + printf("Incoming port: %u outgoing port: %u on loopback interface\n", listen_port, forward_port); @@ -69,6 +88,9 @@ int main(int argc, char* argv[]){ printf("Ignoring DKIM signed messages: %s\n", abort_on_dkim ? "true" : "false"); + + printf("Instance id for messages: %s\n", + instance_id); if(init_net() < 0){ return EXIT_FAILURE;