]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/misc-progs/tripwirectrl.c
Connections.cgi neu geschrieben.
[people/pmueller/ipfire-2.x.git] / src / misc-progs / tripwirectrl.c
CommitLineData
92004c61
CS
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <fcntl.h>
7#include "setuid.h"
8
9#define BUFFER_SIZE 1024
10
11char command[BUFFER_SIZE];
12
13int main(int argc, char *argv[])
14{
15
16 if (!(initsetuid()))
17 exit(1);
18
19 // Check what command is asked
20 if (argc==1)
21 {
22 fprintf (stderr, "Missing tripwirectrl command!\n");
23 return 1;
24 }
25
26 if (strcmp(argv[1], "tripwirelog")==0)
27 {
1cdddb12
MT
28 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/twprint -m r --cfgfile /var/ipfire/tripwire/tw.cfg --twrfile /var/ipfire/tripwire/report/%s", argv[2]);
29 safe_system(command);
30 return 0;
92004c61
CS
31 }
32
33 if (strcmp(argv[1], "generatereport")==0)
34 {
1465b127
MT
35 safe_system("/usr/sbin/tripwire --check --cfgfile /var/ipfire/tripwire/tw.cfg --polfile /var/ipfire/tripwire/tw.pol >/dev/null 2>&1");
36 return 0;
37 }
38
39 if (strcmp(argv[1], "deletereport")==0)
40 {
41 sprintf(command, "rm -f /var/ipfire/tripwire/report/%s", argv[2]);
42 safe_system(command);
92004c61
CS
43 return 0;
44 }
45
46 if (strcmp(argv[1], "updatedatabase")==0)
47 {
1465b127 48 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/tripwire --update --accept-all --cfgfile /var/ipfire/tripwire/tw.cfg --polfile /var/ipfire/tripwire/tw.pol --local-passphrase %s --twrfile %s >/dev/null 2>&1", argv[2], argv[3]);
92004c61 49 safe_system(command);
92004c61
CS
50 return 0;
51 }
52
53 if (strcmp(argv[1], "keys")==0)
54 {
1465b127
MT
55 printf("Generating Site Key<br />");
56 snprintf(command, BUFFER_SIZE-1, "rm -rf /var/ipfire/tripwire/site.key && /usr/sbin/twadmin --generate-keys --site-keyfile /var/ipfire/tripwire/site.key --site-passphrase %s && chmod 640 /var/ipfire/tripwire/site.key >/dev/null 2>&1", argv[2]);
92004c61 57 safe_system(command);
1465b127
MT
58 printf("Generating Local Key<br />");
59 snprintf(command, BUFFER_SIZE-1, "rm -rf /var/ipfire/tripwire/local.key && /usr/sbin/twadmin --generate-keys --local-keyfile /var/ipfire/tripwire/local.key --local-passphrase %s && chmod 640 /var/ipfire/tripwire/local.key >/dev/null 2>&1", argv[3]);
92004c61 60 safe_system(command);
1465b127
MT
61 printf("Generating Config File<br />");
62 snprintf(command, BUFFER_SIZE-1, "rm -rf /var/ipfire/tripwire/tw.cfg && /usr/sbin/twadmin --create-cfgfile --cfgfile /var/ipfire/tripwire/tw.cfg --site-keyfile /var/ipfire/tripwire/site.key --site-passphrase %s /var/ipfire/tripwire/twcfg.txt && chmod 640 /var/ipfire/tripwire/tw.cfg >/dev/null 2>&1", argv[2]);
92004c61 63 safe_system(command);
1465b127
MT
64 printf("Generating Policy File<br />");
65 snprintf(command, BUFFER_SIZE-1, "rm -rf /var/ipfire/tripwire/tw.pol && /usr/sbin/twadmin --create-polfile --cfgfile /var/ipfire/tripwire/tw.cfg --site-keyfile /var/ipfire/tripwire/site.key --site-passphrase %s /var/ipfire/tripwire/twpol.txt && chmod 640 /var/ipfire/tripwire/tw.pol >/dev/null 2>&1", argv[2]);
92004c61 66 safe_system(command);
1465b127
MT
67 printf("Initialising - This may take a while depending on your Policy<br />");
68 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/tripwire --init --cfgfile /var/ipfire/tripwire/tw.cfg --polfile /var/ipfire/tripwire/tw.pol --local-passphrase %s >/dev/null 2>&1", argv[3]);
92004c61 69 safe_system(command);
92004c61
CS
70 return 0;
71 }
72
73 if (strcmp(argv[1], "generatepolicy")==0)
74 {
1465b127
MT
75 printf("Generating Policy File<br />");
76 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/twadmin --create-polfile --site-keyfile /var/ipfire/tripwire/site.key --site-passphrase %s --polfile /var/ipfire/tripwire/tw.pol --cfgfile /var/ipfire/tripwire/tw.cfg /var/ipfire/tripwire/twpol.txt >/dev/null 2>&1", argv[2]);
92004c61 77 safe_system(command);
1465b127
MT
78 printf("Initialising - This may take a while depending on your Policy<br />");
79 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/tripwire --init --cfgfile /var/ipfire/tripwire/tw.cfg --polfile /var/ipfire/tripwire/tw.cfg --local-passphrase %s >/dev/null 2>&1", argv[3]);
92004c61 80 safe_system(command);
92004c61
CS
81 return 0;
82 }
83
84 if (strcmp(argv[1], "resetpolicy")==0)
85 {
1465b127
MT
86 printf("Generating Policy File<br />");
87 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/twadmin --create-polfile --site-keyfile /var/ipfire/tripwire/site.key --site-passphrase %s --polfile /var/ipfire/tripwire/tw.pol --cfgfile /var/ipfire/tripwire/tw.cfg /var/ipfire/tripwire/twpol.default >/dev/null 2>&1", argv[2]);
92004c61 88 safe_system(command);
1465b127
MT
89 printf("Initialising - This may take a while depending on your Policy");
90 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/tripwire --init --cfgfile /var/ipfire/tripwire/tw.cfg --polfile /var/ipfire/tripwire/tw.cfg --local-passphrase %s >/dev/null 2>&1", argv[3]);
92004c61 91 safe_system(command);
92004c61
CS
92 return 0;
93 }
94
95 if (strcmp(argv[1], "readconfig")==0)
96 {
97 safe_system("/bin/chown nobody:nobody /var/ipfire/tripwire/twcfg.txt");
92004c61
CS
98 return 0;
99 }
100
101 if (strcmp(argv[1], "lockconfig")==0)
102 {
103 safe_system("/bin/chown root:root /var/ipfire/tripwire/twcfg.txt");
92004c61
CS
104 return 0;
105 }
1cdddb12 106return 0;
1465b127 107}