Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 3ffb46e

Browse files
thkukukahkok
authored andcommitted
Add extra path for firewall-cmd
1 parent 4b071b0 commit 3ffb46e

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

man/tallow.conf.5.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ tallow will operate with built-in defaults.
1919

2020
## OPTIONS
2121

22+
`fwcmd_path`=`<string>`
23+
Specifies the location of the ipset(1) firewall-cmd(1) programs. By
24+
default, tallow will look in "/usr/sbin" for them.
25+
2226
`ipt_path`=`<string>`
23-
Specifies the location of the ipset(1) program and iptables(1),
24-
ip6tables(1), or firewall-cmd(1) programs. By default, tallow will
25-
look in "/usr/sbin" for them.
27+
Specifies the location of the ipset(1) program and iptables(1) or
28+
ip6tables(1) programs. By default, tallow will look in "/usr/sbin"
29+
for them.
2630

2731
`expires`=`<int>`
2832
The number of seconds that IP addresses are blocked for. Note that
@@ -58,7 +62,7 @@ default, tallow will create new firewall-cmd(1) or iptables(1) and ip6tables(1)
5862
rules when needed automatically. If set to `1`, `tallow(1)` will not create any
5963
new firewall DROP rules or ipset sets that are needed work. You should create
6064
them manually before tallow starts up and remove them afterwards using the sets
61-
of commands below.
65+
of commands below.
6266

6367
Use the following commands if you're using iptables(1):
6468

src/tallow.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define MAX_OFFSETS 30
3636

3737
static char ipt_path[PATH_MAX];
38+
static char fwcmd_path[PATH_MAX];
3839
static int expires = 3600;
3940
static int has_ipv6 = 0;
4041
static bool nocreate = false;
@@ -71,17 +72,17 @@ static void ext_ignore(char *fmt, ...)
7172
static void reset_rules(void)
7273
{
7374
/* reset all rules in case the running fw changes */
74-
ext_ignore("%s/firewall-cmd --permanent --direct --remove-rule ipv4 filter INPUT 1 -m set --match-set tallow src -j DROP 2> /dev/null", ipt_path);
75-
ext_ignore("%s/firewall-cmd --permanent --delete-ipset=tallow 2> /dev/null", ipt_path);
75+
ext_ignore("%s/firewall-cmd --permanent --direct --remove-rule ipv4 filter INPUT 1 -m set --match-set tallow src -j DROP 2> /dev/null", fwcmd_path);
76+
ext_ignore("%s/firewall-cmd --permanent --delete-ipset=tallow 2> /dev/null", fwcmd_path);
7677

7778
/* delete iptables ref to set before the ipset! */
7879
ext_ignore("%s/iptables -t filter -D INPUT -m set --match-set tallow src -j DROP 2> /dev/null", ipt_path);
7980
ext_ignore("%s/ipset destroy tallow 2> /dev/null", ipt_path);
8081

8182
if (has_ipv6) {
82-
ext_ignore("%s/firewall-cmd --permanent --direct --remove-rule ipv6 filter INPUT 1 -m set --match-set tallow6 src -j DROP 2> /dev/null", ipt_path);
83-
ext_ignore("%s/firewall-cmd --permanent --delete-ipset=tallow6 2> /dev/null", ipt_path);
84-
83+
ext_ignore("%s/firewall-cmd --permanent --direct --remove-rule ipv6 filter INPUT 1 -m set --match-set tallow6 src -j DROP 2> /dev/null", fwcmd_path);
84+
ext_ignore("%s/firewall-cmd --permanent --delete-ipset=tallow6 2> /dev/null", fwcmd_path);
85+
8586
/* delete iptables ref to set before the ipset! */
8687
ext_ignore("%s/ip6tables -t filter -D INPUT -m set --match-set tallow6 src -j DROP 2> /dev/null", ipt_path);
8788
ext_ignore("%s/ipset destroy tallow6 2> /dev/null", ipt_path);
@@ -100,39 +101,39 @@ static void setup(void)
100101

101102
/* firewalld */
102103
char *fwd_path;
103-
if (asprintf(&fwd_path, "%s/firewall-cmd", ipt_path) < 0) {
104+
if (asprintf(&fwd_path, "%s/firewall-cmd", fwcmd_path) < 0) {
104105
exit(EXIT_FAILURE);
105106
}
106107

107-
if ((access(fwd_path, X_OK) == 0) && ext("%s/firewall-cmd --state --quiet", ipt_path) == 0) {
108+
if ((access(fwd_path, X_OK) == 0) && ext("%s/firewall-cmd --state --quiet", fwcmd_path) == 0) {
108109
fprintf(stdout, "firewalld is running and will be used by tallow.\n");
109110

110111
reset_rules();
111112

112113
/* create ipv4 rule and ipset */
113-
if (ext("%s/firewall-cmd --permanent --quiet --new-ipset=tallow --type=hash:ip --family=inet --option=timeout=%d", ipt_path, expires)) {
114+
if (ext("%s/firewall-cmd --permanent --quiet --new-ipset=tallow --type=hash:ip --family=inet --option=timeout=%d", fwcmd_path, expires)) {
114115
fprintf(stderr, "Unable to create ipv4 ipset with firewall-cmd.\n");
115116
exit(EXIT_FAILURE);
116117
}
117-
if (ext("%s/firewall-cmd --permanent --direct --quiet --add-rule ipv4 filter INPUT 1 -m set --match-set tallow src -j DROP", ipt_path)) {
118+
if (ext("%s/firewall-cmd --permanent --direct --quiet --add-rule ipv4 filter INPUT 1 -m set --match-set tallow src -j DROP", fwcmd_path)) {
118119
fprintf(stderr, "Unable to create ipv4 firewalld rule.\n");
119120
exit(EXIT_FAILURE);
120121
}
121122

122123
/* create ipv6 rule and ipset */
123124
if (has_ipv6) {
124-
if (ext("%s/firewall-cmd --permanent --quiet --new-ipset=tallow6 --type=hash:ip --family=inet6 --option=timeout=%d", ipt_path, expires)) {
125+
if (ext("%s/firewall-cmd --permanent --quiet --new-ipset=tallow6 --type=hash:ip --family=inet6 --option=timeout=%d", fwcmd_path, expires)) {
125126
fprintf(stderr, "Unable to create ipv6 ipset with firewall-cmd.\n");
126127
exit(EXIT_FAILURE);
127128
}
128-
if (ext("%s/firewall-cmd --permanent --direct --quiet --add-rule ipv6 filter INPUT 1 -m set --match-set tallow6 src -j DROP ", ipt_path)) {
129+
if (ext("%s/firewall-cmd --permanent --direct --quiet --add-rule ipv6 filter INPUT 1 -m set --match-set tallow6 src -j DROP ", fwcmd_path)) {
129130
fprintf(stderr, "Unable to create ipv6 firewalld rule.\n");
130131
exit(EXIT_FAILURE);
131132
}
132133
}
133134

134135
/* reload firewalld for ipsets to load */
135-
if (ext("%s/firewall-cmd --reload --quiet", ipt_path, expires)) {
136+
if (ext("%s/firewall-cmd --reload --quiet", fwcmd_path, expires)) {
136137
fprintf(stderr, "Unable to reload firewalld rules.\n");
137138
exit(EXIT_FAILURE);
138139
}
@@ -292,6 +293,7 @@ int main(void)
292293
json_load_patterns();
293294

294295
strcpy(ipt_path, "/usr/sbin");
296+
strcpy(fwcmd_path, "/usr/sbin");
295297

296298
#ifdef DEBUG
297299
fprintf(stderr, "Debug output enabled. Send SIGUSR1 to dump internal state table\n");
@@ -331,6 +333,8 @@ int main(void)
331333
// todo: filter leading/trailing whitespace
332334
if (!strcmp(key, "ipt_path"))
333335
strncpy(ipt_path, val, PATH_MAX - 1);
336+
if (!strcmp(key, "fwcmd_path"))
337+
strncpy(fwcmd_path, val, PATH_MAX - 1);
334338
if (!strcmp(key, "expires"))
335339
expires = atoi(val);
336340
if (!strcmp(key, "whitelist"))

tallow.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# tallow.conf - see `man tallow.conf` for more information
33

4+
#fwcmd_path=/usr/sbin
45
#ipt_path=/usr/sbin
56
#expires=3600
67
#whitelist=127.0.0.1

0 commit comments

Comments
 (0)