1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
--- milter-regex.c.orig 2019-04-02 15:47:26 UTC
+++ milter-regex.c
@@ -62,6 +62,7 @@ extern int parse_ruleset(const char *,
static const char *rule_file_name = "/etc/milter-regex.conf";
static int debug = 0;
+static int quiet = 0;
static unsigned maxlines = 0;
static pthread_mutex_t mutex;
@@ -99,6 +100,7 @@ static void msg(int, struct context *,
#define USER "_milter-regex"
#define OCONN "unix:/var/spool/milter-regex/sock"
+#define OPID "/var/spool/milter-regex/milter-regex.pid"
#define RCODE_REJECT "554"
#define RCODE_TEMPFAIL "451"
#define XCODE_REJECT "5.7.1"
@@ -647,6 +649,9 @@ msg(int priority, struct context *contex
va_list ap;
char msg[8192];
+ if (LOG_PRI(priority) > LOG_INFO && quiet)
+ return;
+
va_start(ap, fmt);
if (context != NULL)
snprintf(msg, sizeof(msg), "%s [%s]: ", context->host_name,
@@ -685,6 +690,7 @@ main(int argc, char **argv)
{
int ch, maskpri = LOG_INFO;
const char *oconn = OCONN;
+ const char *pid_file_name = OPID;
const char *user = USER;
const char *jail = NULL;
sfsistat r = MI_FAILURE;
@@ -693,8 +699,10 @@ main(int argc, char **argv)
const char *puser = NULL;
mode_t pperm = 0600;
int facility = LOG_DAEMON;
+ pid_t pid;
+ FILE *pid_fd = NULL;
- while ((ch = getopt(argc, argv, "c:df:j:l:m:p:u:G:P:U:")) != -1) {
+ while ((ch = getopt(argc, argv, "c:df:j:l:m:p:qr:u:G:P:U:")) != -1) {
switch (ch) {
case 'c':
rule_file_name = optarg;
@@ -724,6 +732,12 @@ main(int argc, char **argv)
case 'p':
oconn = optarg;
break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 'r':
+ pid_file_name = optarg;
+ break;
case 'u':
user = optarg;
break;
@@ -845,6 +859,20 @@ main(int argc, char **argv)
}
msg(LOG_INFO, NULL, "started: %s", rcsid);
+
+ umask(0006);
+
+ if((pid_fd = fopen(pid_file_name, "w")) == NULL) {
+ msg(LOG_ERR, NULL, "can't open file: %s", pid_file_name);
+ goto done;
+ } else {
+ pid = getpid();
+ fprintf(pid_fd, "%d", (int) pid);
+ fclose(pid_fd);
+ }
+
+ umask(0117); /* make socket group writeable */
+
r = smfi_main();
if (r != MI_SUCCESS)
msg(LOG_ERR, NULL, "smfi_main: terminating due to error");
|