-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipscromp_gatekeeper.c
More file actions
82 lines (60 loc) · 1.52 KB
/
ipscromp_gatekeeper.c
File metadata and controls
82 lines (60 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <syslog.h>
#include <stdlib.h>
#define REPO "/var/spool/ipscromp"
int main(int argc, char **argv)
{
DIR *dir = NULL;
struct dirent *dirp = NULL;
struct stat statbuf;
char fqfname[300], dynfw[512], uid[256];
time_t oldest;
struct timeval tv;
if (argc != 2) {
printf("usage: %s <minutes>\n", argv[0]);
return 0;
}
gettimeofday(&tv, NULL);
oldest = tv.tv_sec - (atoi(argv[1]) * 60);
dir = opendir(REPO);
if (!dir) {
printf("ERROR: can't open directory %s\n", REPO);
return 0;
}
openlog("ipscromp", LOG_CONS|LOG_PID, LOG_DAEMON);
while ((dirp = readdir(dir)) != NULL) {
if ((strcmp(dirp->d_name, ".") == 0) ||
strcmp(dirp->d_name, "..") == 0)
continue;
sprintf(fqfname, "%s/%s", REPO, dirp->d_name);
if (lstat(fqfname, &statbuf) < 0)
continue;
if (statbuf.st_mtime < oldest) {
FILE *fp = fopen(fqfname, "r");
if (fp) {
memset(uid, 0x0, sizeof(uid));
fgets(uid, sizeof(uid)-1, fp);
uid[strlen(uid)-1] = 0;
fclose(fp);
}
else {
strcpy(uid, "unknown");
}
printf("EXPIRING: %s (%s) \n", dirp->d_name, uid);
syslog(LOG_NOTICE, "Expiring: %s (%s)\n", dirp->d_name, uid);
unlink(fqfname);
sprintf(dynfw, "/usr/local/sbin/ipscromp_dynfw close %s > /dev/null 2>&1", dirp->d_name);
system(dynfw);
}
}
closedir(dir);
closelog();
return 0;
}