]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
misc-progs: Add wireguardctrl
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Apr 2024 17:13:32 +0000 (17:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 14:48:32 +0000 (16:48 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/misc-progs/Makefile
src/misc-progs/wireguardctrl.c [new file with mode: 0644]

index 1ae12b2946b91899bb61bad042876b5a54d87691..9d380c158eb80add4070a20c4e42880c1bdfa6a4 100644 (file)
@@ -32,7 +32,7 @@ SUID_PROGS = squidctrl sshctrl ipfirereboot \
        smartctrl clamavctrl addonctrl pakfire wlanapctrl \
        setaliases urlfilterctrl updxlratorctrl fireinfoctrl rebuildroutes \
        getconntracktable wirelessclient torctrl ddnsctrl unboundctrl \
-       captivectrl
+       captivectrl wireguardctrl
 
 OBJS = $(patsubst %,%.o,$(PROGS) $(SUID_PROGS))
 
diff --git a/src/misc-progs/wireguardctrl.c b/src/misc-progs/wireguardctrl.c
new file mode 100644 (file)
index 0000000..0c25764
--- /dev/null
@@ -0,0 +1,44 @@
+/* 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 <stdio.h>
+#include <string.h>
+
+#include "setuid.h"
+
+int main(int argc, char** argv) {
+       // Become root
+       if (!initsetuid())
+               exit(1);
+
+       // Check if we have enough arguments
+       if (argc < 2) {
+               fprintf(stderr, "\nNot enough arguments.\n\n");
+               exit(1);
+       }
+
+       if (strcmp(argv[1], "start") == 0) {
+               return run("/etc/rc.d/init.d/wireguard", argv + 1);
+
+       } else if (strcmp(argv[1], "stop") == 0) {
+               return run("/etc/rc.d/init.d/wireguard", argv + 1);
+
+       } else if (strcmp(argv[1], "dump") == 0) {
+               const char* args[] = {
+                       "show",
+                       (argc > 2) ? argv[2] : "wg0",
+                       "dump",
+                       NULL,
+               };
+
+               return run("/usr/bin/wg", args);
+       
+       }
+       fprintf(stderr, "Invalid command\n");
+       exit(1);
+}