The smtpd.conf manual says:
> When using a `file' table, a list will be written with each value on a
> line by itself. Comments can be put anywhere in the file using a hash
> mark (`#'), and extend to the end of the current line.
Unfortunately this is not true :-).
Worse still, it causes silent configuration breakage in some cases, for
example consider if you have a list of IPs that you want to block stored in a
table:
$ cat /etc/mail/blocked_ips
10.0.0.1
10.0.0.50
10.1.2.3 # Sends loads of rubbish since last month
10.4.5.6
This would be loaded in smtpd.conf via something like:
table ip_reject_list file:/etc/mail/blocked_ips
No error would be reported, and smtpd would start just fine.
But the IP address with the comment would _not_ be included in the list!
The following patch fixes the problem:
--- table_static.c.dist Mon Jun 14 14:58:16 2021
+++ table_static.c Mon Nov 13 08:28:46 2023
@@ -118,6 +118,7 @@
char *keyp;
char *valp;
int ret = 0;
+ int i;
if ((fp = fopen(path, "r")) == NULL) {
log_warn("%s: fopen", path);
@@ -136,6 +137,14 @@
}
if (*keyp == '\0')
continue;
+
+ for (i=0; i<flen; i++) {
+ if (keyp[i]=='#') {
+ flen = i;
+ break ;
+ }
+ }
+
while (isspace((unsigned char)keyp[flen - 1]))
keyp[--flen] = '\0';
if (*keyp == '#') {