Skip to content

Commit cf9e409

Browse files
authored
Merge pull request trusteddomainproject#375 from thegushi/fix/ignorehosts-reload
opendmarc: reload IgnoreHosts on SIGHUP (issue trusteddomainproject#193)
2 parents ff1dbaf + 0b6cc50 commit cf9e409

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

CHANGES-202605.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ CREATE TABLE IF NOT EXISTS suppressions (
102102
## Signal handling
103103

104104
- **SIGHUP now triggers config reload instead of shutdown**: SIGHUP was handled identically to SIGTERM, causing the filter to exit. Unix convention is that SIGHUP triggers a configuration reload in long-running daemons. The reload path already existed (previously reachable via SIGUSR1 only); SIGHUP is now folded into it. SIGTERM and SIGINT remain the shutdown signals. (#323, issue #322)
105+
- **`IgnoreHosts` not reloaded on SIGHUP**: `IgnoreHosts` was loaded once at startup in `main()` and never refreshed, making it the only configuration option that survived a SIGHUP unchanged. The list (including the always-present localhost defaults) is now loaded in `dmarcf_config_load()` alongside every other option and freed in `dmarcf_config_free()`. (#375, issue #193)
105106

106107
---
107108

opendmarc/opendmarc.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ struct dmarcf_config
198198
char ** conf_ignoredomains;
199199
struct list * conf_domainwhitelist;
200200
unsigned int conf_domainwhitelisthashcount;
201+
struct list * conf_ignorehosts;
201202
};
202203

203204
/* LIST -- basic linked list of strings */
@@ -270,7 +271,6 @@ _Bool no_i_whine;
270271
_Bool testmode;
271272
int diesig;
272273
struct dmarcf_config *curconf;
273-
struct list *ignore;
274274
char *progname;
275275
char *conffile;
276276
char *sock;
@@ -1170,6 +1170,7 @@ dmarcf_config_load(struct config *data, struct dmarcf_config *conf,
11701170
char basedir[MAXPATHLEN + 1];
11711171
char *whitelist = NULL;
11721172
char *whitelistfile = NULL;
1173+
char *ignorefile = NULL;
11731174
struct list *cur;
11741175
int whitelistsize = DEF_WHITELIST_SIZE;
11751176

@@ -1330,6 +1331,9 @@ dmarcf_config_load(struct config *data, struct dmarcf_config *conf,
13301331

13311332
(void) config_get(data, "DomainWhitelistSize", &whitelistsize,
13321333
sizeof whitelistsize);
1334+
1335+
(void) config_get(data, "IgnoreHosts", &ignorefile,
1336+
sizeof ignorefile);
13331337
}
13341338

13351339
if (conf->conf_trustedauthservids == NULL &&
@@ -1479,6 +1483,20 @@ dmarcf_config_load(struct config *data, struct dmarcf_config *conf,
14791483
}
14801484
}
14811485

1486+
if (ignorefile != NULL)
1487+
{
1488+
if (!dmarcf_loadlist(ignorefile, &conf->conf_ignorehosts))
1489+
{
1490+
fprintf(stderr,
1491+
"%s: can't load ignore list from %s: %s\n",
1492+
progname, ignorefile, strerror(errno));
1493+
return EX_DATAERR;
1494+
}
1495+
}
1496+
1497+
dmarcf_addlist("127.0.0.1", &conf->conf_ignorehosts);
1498+
dmarcf_addlist("::1", &conf->conf_ignorehosts);
1499+
14821500
return 0;
14831501
}
14841502

@@ -1832,13 +1850,16 @@ mlfi_connect(SMFICTX *ctx, char *host, _SOCK_ADDR *ip)
18321850

18331851
dmarcf_config_reload();
18341852

1835-
if (dmarcf_checkhost(host, ignore) ||
1836-
(ip != NULL && dmarcf_checkip(ip, ignore)))
1853+
pthread_mutex_lock(&conf_lock);
1854+
if (dmarcf_checkhost(host, curconf->conf_ignorehosts) ||
1855+
(ip != NULL && dmarcf_checkip(ip, curconf->conf_ignorehosts)))
18371856
{
18381857
if (curconf->conf_dolog)
18391858
syslog(LOG_INFO, "ignoring connection from %s", host);
1859+
pthread_mutex_unlock(&conf_lock);
18401860
return SMFIS_ACCEPT;
18411861
}
1862+
pthread_mutex_unlock(&conf_lock);
18421863

18431864
/* copy hostname and IP information to a connection context */
18441865
cc = dmarcf_getpriv(ctx);
@@ -4131,6 +4152,9 @@ dmarcf_config_free(struct dmarcf_config *conf)
41314152
hdestroy();
41324153
}
41334154

4155+
if (conf->conf_ignorehosts != NULL)
4156+
dmarcf_freelist(conf->conf_ignorehosts);
4157+
41344158
free(conf);
41354159
}
41364160

@@ -4207,7 +4231,6 @@ main(int argc, char **argv)
42074231
char *become = NULL;
42084232
char *chrootdir = NULL;
42094233
char *extract = NULL;
4210-
char *ignorefile = NULL;
42114234
char *p;
42124235
char *pidfile = NULL;
42134236
char *testfile = NULL;
@@ -4223,7 +4246,6 @@ main(int argc, char **argv)
42234246
sock = NULL;
42244247
no_i_whine = TRUE;
42254248
conffile = NULL;
4226-
ignore = NULL;
42274249

42284250
memset(myhostname, '\0', sizeof myhostname);
42294251
(void) gethostname(myhostname, sizeof myhostname);
@@ -4527,25 +4549,6 @@ main(int argc, char **argv)
45274549

45284550
(void) config_get(cfg, "ChangeRootDirectory", &chrootdir,
45294551
sizeof chrootdir);
4530-
4531-
(void) config_get(cfg, "IgnoreHosts", &ignorefile,
4532-
sizeof ignorefile);
4533-
}
4534-
4535-
if (ignorefile != NULL)
4536-
{
4537-
if (!dmarcf_loadlist(ignorefile, &ignore))
4538-
{
4539-
fprintf(stderr,
4540-
"%s: can't load ignore list from %s: %s\n",
4541-
progname, ignorefile, strerror(errno));
4542-
return EX_DATAERR;
4543-
}
4544-
}
4545-
else if (!testmode)
4546-
{
4547-
dmarcf_addlist("127.0.0.1", &ignore);
4548-
dmarcf_addlist("::1", &ignore);
45494552
}
45504553

45514554
if (!gotp && !testmode)
@@ -5273,8 +5276,6 @@ main(int argc, char **argv)
52735276

52745277
/* release memory */
52755278
dmarcf_config_free(curconf);
5276-
if (ignore != NULL)
5277-
dmarcf_freelist(ignore);
52785279

52795280
/* tell the reloader thread to die */
52805281
die = TRUE;

0 commit comments

Comments
 (0)