-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparse.c
182 lines (168 loc) · 4.13 KB
/
parse.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "avu.h"
/* my cool itao implementation */
void itoa(uint16_t val, char *s)
{
uint8_t c = 0, i = 0;
while (val)
{
s[c++] = val % 10 + '0';
val /= 10;
}
s[c] = '\0';
while (i < c / 2)
{
s[i] ^= s[c-i-1];
s[c-i-1] ^= s[i];
s[i] ^= s[c-i-1];
i++;
}
}
int parse_config(char *conf)
{
FILE *fd;
char buf[MAXBUF], *delim = "=\n";
char *p, *q, *brk;
if ((fd = fopen(conf, "r")) == NULL)
{
perror("fopen (config):");
exit(-1);
}
while (fgets(buf, MAXBUF-1, fd))
{
if (buf[0] == '\n' || buf[0] == '#')
continue;
if ((p = strtok(buf, "=")))
{
if (strcasecmp(p, "logging") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if ((q = strtok_r(p, ":", &brk)))
{
q = strtok_r(NULL, "\n", &brk);
if (strcasecmp(q, "nostdout") == 0)
opts.nostdout = 1;
else
if (strcasecmp(q, "stdout") == 0)
opts.nostdout = 0;
else
printf("The 'logging' directive does not recognize the second argument"
"defaulting to logfile %s and printing to stdout\n", opts.logfile);
if ((opts.logfile = strdup(p)) == NULL)
{
perror("strdup");
exit(-1);
}
}
opts.logging = 1;
}
else
printf("No logfile specified, ignoring 'logging' directive\n");
continue;
} else
if (strcasecmp(p, "recursion") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.recursion = 1;
}
else
printf("The 'recursion' directive requires either 'yes' or 'no', defaulting to no\n");
continue;
} else
if (strcasecmp(p, "verbose") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.verbose = 1;
}
else
printf("The 'verbose' directive requires either 'yes' or 'no', defaulting to no\n");
continue;
} else
if (strcasecmp(p, "debug") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.debug = 1;
}
else
printf("The 'debug' directive requires either 'yes' or 'no', defaulting to no\n");
continue;
}
else
if (strcasecmp(p, "kill_infected_process") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.kp = 0;
}
else
printf("The 'kill_infected_process' directive requires either 'yes' or 'no', defaulting to no\n");
continue;
}
else
if (strcasecmp(p, "host_entry_detection") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "default") == 0)
opts.alternative_entry_detection = 0;
else
if (strcasecmp(p, "alt") == 0)
opts.alternative_entry_detection = 1;
else
printf("The 'host_entry_detection' directive requires either 'default' or 'alt', defaulting to default\n");
continue;
}
}
else
if (strcasecmp(p, "elf_disinfect") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.elf_disinfect = 1;
else
if (strcasecmp(p, "no") == 0)
opts.elf_disinfect = 0;
else
printf("The 'elf_disinfect' directive requires either 'yes' or 'no', defaulting to yes\n");
}
}
else
if (strcasecmp(p, "extract_parasite") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.extract_parasite = 1;
else
if (strcasecmp(p, "no") == 0)
opts.extract_parasite = 0;
else
printf("The 'extract_parasite' directive requires either 'yes' or 'no', defaulting to no\n");
}
}
if (strcasecmp(p, "check_plt_hijack") == 0)
{
if ((p = strtok(NULL, "\n")))
{
if (strcasecmp(p, "yes") == 0)
opts.plt_hijack = 1;
else
if (strcasecmp(p, "no") == 0)
opts.plt_hijack = 0;
else
printf("The 'check_plt_hijack' directive requires either 'yes' or 'no', defaulting to no\n");
}
}
}
}
fclose(fd);
return 0;
}