]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/misc-progs/addonctrl.c
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / src / misc-progs / addonctrl.c
1 /* This file is part of the IPFire Firewall.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <fcntl.h>
14 #include "setuid.h"
15
16 #define BUFFER_SIZE 1024
17
18 int main(int argc, char *argv[]) {
19 char command[BUFFER_SIZE];
20
21 if (!(initsetuid()))
22 exit(1);
23
24 if (argc < 3) {
25 fprintf(stderr, "\nMissing arguments.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
26 exit(1);
27 }
28
29 const char* name = argv[1];
30
31 if (strlen(name) > 32) {
32 fprintf(stderr, "\nString to large.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
33 exit(1);
34 }
35
36 // Check if the input argument is valid
37 if (!is_valid_argument_alnum(name)) {
38 fprintf(stderr, "Invalid add-on name: %s\n", name);
39 exit(2);
40 }
41
42 sprintf(command, "/opt/pakfire/db/installed/meta-%s", name);
43 FILE *fp = fopen(command,"r");
44 if ( fp ) {
45 fclose(fp);
46 } else {
47 fprintf(stderr, "\nAddon '%s' not found.\n\naddonctrl addon (start|stop|restart|reload|status|enable|disable)\n\n", name);
48 exit(1);
49 }
50
51 if (strcmp(argv[2], "start") == 0) {
52 snprintf(command, BUFFER_SIZE - 1, "/etc/rc.d/init.d/%s start", name);
53 safe_system(command);
54 } else if (strcmp(argv[2], "stop") == 0) {
55 snprintf(command, BUFFER_SIZE - 1, "/etc/rc.d/init.d/%s stop", name);
56 safe_system(command);
57 } else if (strcmp(argv[2], "restart") == 0) {
58 snprintf(command, BUFFER_SIZE - 1, "/etc/rc.d/init.d/%s restart", name);
59 safe_system(command);
60 } else if (strcmp(argv[2], "reload") == 0) {
61 snprintf(command, BUFFER_SIZE - 1, "/etc/rc.d/init.d/%s reload", name);
62 safe_system(command);
63 } else if (strcmp(argv[2], "status") == 0) {
64 snprintf(command, BUFFER_SIZE - 1, "/etc/rc.d/init.d/%s status", name);
65 safe_system(command);
66 } else if (strcmp(argv[2], "enable") == 0) {
67 snprintf(command, BUFFER_SIZE - 1, "mv -f /etc/rc.d/rc3.d/off/S??%s /etc/rc.d/rc3.d" , name);
68 safe_system(command);
69 } else if (strcmp(argv[2], "disable") == 0) {
70 snprintf(command, BUFFER_SIZE - 1, "mkdir -p /etc/rc.d/rc3.d/off");
71 safe_system(command);
72 snprintf(command, BUFFER_SIZE - 1, "mv -f /etc/rc.d/rc3.d/S??%s /etc/rc.d/rc3.d/off" , name);
73 safe_system(command);
74 } else {
75 fprintf(stderr, "\nBad argument given.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
76 exit(1);
77 }
78
79 return 0;
80 }