[2/2] New binary: optionsfwctrl - needed for new firewall DNS/NTP options

Message ID 20201227123020.4556-2-matthias.fischer@ipfire.org
State Superseded
Headers
Series [1/2] optionsfw.cgi: Forcing DNS and NTP requests to use only local servers on GREEN/BLUE |

Commit Message

Matthias Fischer Dec. 27, 2020, 12:30 p.m. UTC
  Signed-off-by: Matthias Fischer <matthias.fischer@ipfire.org>
---
 config/rootfiles/common/misc-progs |  1 +
 src/misc-progs/Makefile            |  2 +-
 src/misc-progs/optionsfwctrl.c     | 36 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 src/misc-progs/optionsfwctrl.c
  

Patch

diff --git a/config/rootfiles/common/misc-progs b/config/rootfiles/common/misc-progs
index c48a474b2..9d928ec72 100644
--- a/config/rootfiles/common/misc-progs
+++ b/config/rootfiles/common/misc-progs
@@ -18,6 +18,7 @@  usr/local/bin/launch-ether-wake
 usr/local/bin/logwatch
 #usr/local/bin/mpfirectrl
 usr/local/bin/openvpnctrl
+usr/local/bin/optionsfwctrl
 usr/local/bin/pakfire
 usr/local/bin/qosctrl
 usr/local/bin/rebuildhosts
diff --git a/src/misc-progs/Makefile b/src/misc-progs/Makefile
index bea54e773..9d8afcb3f 100644
--- a/src/misc-progs/Makefile
+++ b/src/misc-progs/Makefile
@@ -26,7 +26,7 @@  PROGS = iowrap
 SUID_PROGS = squidctrl sshctrl ipfirereboot \
 	ipsecctrl timectrl dhcpctrl suricatactrl \
 	applejuicectrl rebuildhosts backupctrl collectdctrl \
-	logwatch wioscan wiohelper openvpnctrl firewallctrl \
+	logwatch wioscan wiohelper openvpnctrl firewallctrl optionsfwctrl \
 	wirelessctrl getipstat qosctrl launch-ether-wake \
 	redctrl syslogdctrl extrahdctrl sambactrl upnpctrl \
 	smartctrl clamavctrl addonctrl pakfire mpfirectrl wlanapctrl \
diff --git a/src/misc-progs/optionsfwctrl.c b/src/misc-progs/optionsfwctrl.c
new file mode 100644
index 000000000..f66b10983
--- /dev/null
+++ b/src/misc-progs/optionsfwctrl.c
@@ -0,0 +1,36 @@ 
+/* This file is part of the IPFire Firewall.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence.  See the file COPYING for details.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "setuid.h"
+
+int main(int argc, char *argv[]) {
+
+	if (!(initsetuid()))
+		exit(1);
+
+	if (argc < 2) {
+		fprintf(stderr, "\nNo argument given.\n\noptionsfwctrl restart|reload\n\n");
+		exit(1);
+	}
+
+	if (strcmp(argv[1], "restart") == 0) {
+		safe_system("/etc/rc.d/init.d/firewall restart");
+	} else if (strcmp(argv[1], "reload") == 0) {
+		safe_system("/etc/rc.d/init.d/firewall reload");
+	} else {
+		fprintf(stderr, "\nBad argument given.\n\noptionsfwctrl restart|reload\n\n");
+		exit(1);
+	}
+
+	return 0;
+}