Added instance id option to mark messages
Signed-off-by: tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
1312510074
commit
0524358cef
|
@ -26,4 +26,6 @@ extern uint16_t listen_port, forward_port;
|
||||||
|
|
||||||
extern int abort_on_pgp, abort_on_dkim;
|
extern int abort_on_pgp, abort_on_dkim;
|
||||||
|
|
||||||
|
extern char* instance_id;
|
||||||
|
|
||||||
#endif /* CONFIG_H */
|
#endif /* CONFIG_H */
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
uint16_t listen_port = 4269, forward_port = 4270;
|
uint16_t listen_port = 4269, forward_port = 4270;
|
||||||
int abort_on_pgp = true, abort_on_dkim = true;
|
int abort_on_pgp = true, abort_on_dkim = true;
|
||||||
|
char* instance_id = NULL;
|
||||||
|
|
|
@ -58,6 +58,7 @@ bool detect_dkim(struct email_t* mail){
|
||||||
if(strcasestr(mail->message, dkim_signatures[i]) != NULL
|
if(strcasestr(mail->message, dkim_signatures[i]) != NULL
|
||||||
&& strcasestr(mail->message, dkim_signatures[i])
|
&& strcasestr(mail->message, dkim_signatures[i])
|
||||||
<= (mail->message+mail->header_len)){
|
<= (mail->message+mail->header_len)){
|
||||||
|
/* DKIM only happens inside the header, not the body! */
|
||||||
points++;
|
points++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/main.c
24
src/main.c
|
@ -7,6 +7,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -27,12 +30,13 @@ int main(int argc, char* argv[]){
|
||||||
{"noabort-dkim",no_argument, &abort_on_dkim,0},
|
{"noabort-dkim",no_argument, &abort_on_dkim,0},
|
||||||
{"in-port", required_argument, 0, 'i'},
|
{"in-port", required_argument, 0, 'i'},
|
||||||
{"out-port", required_argument, 0, 'o'},
|
{"out-port", required_argument, 0, 'o'},
|
||||||
|
{"instance-id", required_argument, 0, 'n'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
/* getopt_long stores the option index here. */
|
/* getopt_long stores the option index here. */
|
||||||
int option_index = 0;
|
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);
|
long_options, &option_index);
|
||||||
|
|
||||||
/* Detect the end of the options. */
|
/* Detect the end of the options. */
|
||||||
|
@ -51,6 +55,10 @@ int main(int argc, char* argv[]){
|
||||||
forward_port = atoi(optarg);
|
forward_port = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'n':
|
||||||
|
instance_id = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
/* getopt_long already printed an error message. */
|
/* getopt_long already printed an error message. */
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -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",
|
printf("Incoming port: %u outgoing port: %u on loopback interface\n",
|
||||||
listen_port, forward_port);
|
listen_port, forward_port);
|
||||||
|
|
||||||
|
@ -70,6 +89,9 @@ int main(int argc, char* argv[]){
|
||||||
printf("Ignoring DKIM signed messages: %s\n",
|
printf("Ignoring DKIM signed messages: %s\n",
|
||||||
abort_on_dkim ? "true" : "false");
|
abort_on_dkim ? "true" : "false");
|
||||||
|
|
||||||
|
printf("Instance id for messages: %s\n",
|
||||||
|
instance_id);
|
||||||
|
|
||||||
if(init_net() < 0){
|
if(init_net() < 0){
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue