3535#define MAX_OFFSETS 30
3636
3737static char ipt_path [PATH_MAX ];
38+ static char fwcmd_path [PATH_MAX ];
3839static int expires = 3600 ;
3940static int has_ipv6 = 0 ;
4041static bool nocreate = false;
@@ -71,17 +72,17 @@ static void ext_ignore(char *fmt, ...)
7172static 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" ))
0 commit comments