2020-04-24 23:06:34 +02:00
|
|
|
/*
|
|
|
|
* Mailattach - a program to remove attachments and replace them with links.
|
|
|
|
* Licensed under the Apache 2.0 License. Parts taken from the sendmail
|
|
|
|
* libmilter sample. License restrictions from their license may apply.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-04-28 23:31:18 +02:00
|
|
|
#include <getopt.h>
|
2020-04-29 00:08:34 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
2020-04-24 23:06:34 +02:00
|
|
|
|
2020-04-28 22:39:01 +02:00
|
|
|
#include "network.h"
|
2020-04-25 00:53:36 +02:00
|
|
|
#include "config.h"
|
2020-04-28 18:50:30 +02:00
|
|
|
|
2020-04-26 18:01:10 +02:00
|
|
|
|
|
|
|
int main(int argc, char* argv[]){
|
|
|
|
|
|
|
|
printf("INIT\n");
|
2020-04-28 23:31:18 +02:00
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (1){
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"abort-pgp", no_argument, &abort_on_pgp, 1},
|
|
|
|
{"abort-dkim", no_argument, &abort_on_dkim,1},
|
|
|
|
{"noabort-pgp", no_argument, &abort_on_pgp, 0},
|
|
|
|
{"noabort-dkim",no_argument, &abort_on_dkim,0},
|
2020-04-29 15:16:35 +02:00
|
|
|
{"verbose", no_argument, &verbose, 1},
|
|
|
|
{"quiet", no_argument, &verbose, 0},
|
2020-04-30 19:43:44 +02:00
|
|
|
{"only-base64", no_argument, &only_base64, 1},
|
|
|
|
{"other-base64",no_argument, &only_base64, 0},
|
2020-04-28 23:31:18 +02:00
|
|
|
{"in-port", required_argument, 0, 'i'},
|
|
|
|
{"out-port", required_argument, 0, 'o'},
|
2020-04-29 00:08:34 +02:00
|
|
|
{"instance-id", required_argument, 0, 'n'},
|
2020-04-29 17:33:23 +02:00
|
|
|
{"directory", required_argument, 0, 'd'},
|
2020-04-30 22:38:33 +02:00
|
|
|
{"minfilesize", required_argument, 0, 's'},
|
2020-04-29 17:33:23 +02:00
|
|
|
{"url", required_argument, 0, 'u'},
|
2020-04-28 23:31:18 +02:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
/* getopt_long stores the option index here. */
|
|
|
|
int option_index = 0;
|
|
|
|
|
2020-04-30 22:38:33 +02:00
|
|
|
c = getopt_long (argc, argv, "n:i:o:d:u:s:",
|
2020-04-28 23:31:18 +02:00
|
|
|
long_options, &option_index);
|
|
|
|
|
|
|
|
/* Detect the end of the options. */
|
|
|
|
if (c == -1){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c){
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
listen_port = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
forward_port = atoi(optarg);
|
|
|
|
break;
|
2020-04-29 00:08:34 +02:00
|
|
|
|
|
|
|
case 'n':
|
|
|
|
instance_id = optarg;
|
|
|
|
break;
|
2020-04-29 17:33:23 +02:00
|
|
|
|
|
|
|
case 'd':
|
|
|
|
directory = optarg;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
url_base = optarg;
|
|
|
|
break;
|
2020-04-30 22:38:33 +02:00
|
|
|
case 's':
|
|
|
|
min_filesize = atol(optarg);
|
|
|
|
break;
|
2020-04-28 23:31:18 +02:00
|
|
|
|
|
|
|
case '?':
|
|
|
|
/* getopt_long already printed an error message. */
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 00:08:34 +02:00
|
|
|
/* 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");
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 17:33:23 +02:00
|
|
|
|
|
|
|
if(directory == NULL){
|
|
|
|
fprintf(stderr, "directory option MUST be set!\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(url_base == NULL){
|
|
|
|
fprintf(stderr, "url option MUST be set!\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:16:35 +02:00
|
|
|
if(verbose){
|
2020-04-29 00:08:34 +02:00
|
|
|
|
2020-04-29 15:16:35 +02:00
|
|
|
printf("Incoming port: %u outgoing port: %u on loopback "
|
|
|
|
"interface\n", listen_port, forward_port);
|
2020-04-28 23:43:09 +02:00
|
|
|
|
2020-04-30 19:43:44 +02:00
|
|
|
printf("Aborting on PGP signed/encrypted messages: %s\n",
|
2020-04-30 21:15:04 +02:00
|
|
|
abort_on_pgp ? "true" : "false");
|
2020-04-28 23:43:09 +02:00
|
|
|
|
2020-04-30 19:43:44 +02:00
|
|
|
printf("Aborting on DKIM signed messages: %s\n",
|
2020-04-29 15:16:35 +02:00
|
|
|
abort_on_dkim ? "true" : "false");
|
|
|
|
|
|
|
|
printf("Instance id for messages: %s\n",
|
|
|
|
instance_id);
|
2020-04-29 17:33:23 +02:00
|
|
|
|
2020-04-30 19:43:44 +02:00
|
|
|
printf("Only saving bas64 encoded files: %s\n",
|
2020-04-30 21:14:03 +02:00
|
|
|
only_base64 ? "true":"false");
|
2020-04-30 22:38:33 +02:00
|
|
|
|
|
|
|
printf("Min filesize to store messages: %liB\n",
|
|
|
|
min_filesize);
|
2020-04-30 19:43:44 +02:00
|
|
|
|
|
|
|
|
2020-04-29 17:33:23 +02:00
|
|
|
printf("Placing files into [%s] linked by [%s]\n", directory,
|
|
|
|
url_base);
|
2020-04-29 15:16:35 +02:00
|
|
|
}
|
2020-04-28 23:31:18 +02:00
|
|
|
|
2020-04-28 22:39:01 +02:00
|
|
|
if(init_net() < 0){
|
|
|
|
return EXIT_FAILURE;
|
2020-04-26 18:01:10 +02:00
|
|
|
}
|
2020-04-24 23:06:34 +02:00
|
|
|
|
2020-04-28 23:31:18 +02:00
|
|
|
loop_clients();
|
|
|
|
return EXIT_SUCCESS;
|
2020-04-25 00:53:36 +02:00
|
|
|
|
2020-04-24 23:06:34 +02:00
|
|
|
}
|