-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.c
140 lines (124 loc) · 2.68 KB
/
report.c
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<sys/types.h>
#include<unistd.h>
#include"dnsqry.h"
#define BUFSIZE 1024
struct config_entry {
char *cond;
char *vuln;
char *advi;
struct config_entry *next;
};
inline static void synerr(void);
int
report(struct servers *llp, const char *config)
{
FILE *cf;
char buf [BUFSIZE], *op, flag = 0;
register char *p;
struct config_entry *confent, *start;
size_t len;
int ret;
if (!(confent = (struct config_entry *)malloc(sizeof(*confent))))
vexit("malloc");
confent->next = NULL;
if (config)
{
if(!(cf=(fopen(config,"r"))))
{
fprintf(stderr,"Unable to open: %s!\n",config);
vexit("fopen");
}
}
else if (!(cf = fopen("porkbind.conf", "r")))
{
fprintf(stderr,"Unable to open: porkbind.conf!\n");
vexit("fopen");
}
if (!llp->ver||llp->ver==(char*)-1)
return (0);
/* Fix for alpha/beta version numbers. */
llp->ver=genver(llp->ver);
/*
* Read configuration file entries into memory and organize them into
* a data structure.
*/
start = confent, confent->next = NULL;
while (fgets(buf, BUFSIZE, cf)) {
op = buf, p = op;
/* Comment -- ignore. */
while (isspace(*p))
p++;
if (*p == '#')
continue;
while (!isspace(*p) && *p)
p++;
/* Blank line */
if (!*p)
continue;
*p = 0;
len = p - op;
if (!(confent->cond = (char *)malloc(len + 1)))
vexit("malloc");
/* Paranoid strncpy()'s follow. */
strncpy(confent->cond, op, len);
*(confent->cond + len) = 0;
p++;
while (*p != '"' && isspace(*p))
p++;
op = ++p;
while (*p && *p != '"')
p++;
if (!*p)
synerr();
*p = 0;
len = p - op;
if (!(confent->vuln = (char *)malloc(len + 1)))
vexit("malloc");
strncpy(confent->vuln, op, len);
*(confent->vuln + len) = 0;
p++;
while (isspace(*p))
p++;
op = p;
while (!isspace(*p) && *p)
p++;
if (!*p)
synerr();
*p = 0;
len = p - op;
while (!(confent->advi = (char *)malloc(len + 1)))
vexit("malloc");
strncpy(confent->advi, op, len);
*(confent->advi + len) = 0;
if (!
(confent->next =
(struct config_entry *)malloc(sizeof(*confent->next))))
vexit("malloc");
confent = confent->next;
confent->next = NULL;
}
if (confent->next) {
free(confent->next);
confent->next = NULL;
}
for (confent = start; confent->next; confent = confent->next) {
if ((ret = chkver(llp->ver, confent->cond))) {
if (!flag)
printf("\n%s may be vulnerable to...\n", llp->ns);
printf("\t%s: %s\n",
confent->vuln, confent->advi);
flag = 1;
}
}
return (0);
}
static void
synerr(void)
{
puts("Syntax error in porkbind.conf");
exit(EXIT_FAILURE);
}