git-svn: trunk@2235
Tomasz Kojm authored on 2006/09/06 05:45:39... | ... |
@@ -32,7 +32,6 @@ |
32 | 32 |
#include <time.h> |
33 | 33 |
#include <pwd.h> |
34 | 34 |
#include <grp.h> |
35 |
-#include <clamav.h> |
|
36 | 35 |
|
37 | 36 |
#if defined(USE_SYSLOG) && !defined(C_AIX) |
38 | 37 |
#include <syslog.h> |
... | ... |
@@ -42,26 +41,40 @@ |
42 | 42 |
#include <sys/resource.h> |
43 | 43 |
#endif |
44 | 44 |
|
45 |
-#include "options.h" |
|
46 |
-#include "cfgparser.h" |
|
47 |
-#include "others.h" |
|
48 |
-/* Fixes gcc warning */ |
|
49 |
-#include "../libclamav/others.h" |
|
45 |
+#include "target.h" |
|
46 |
+ |
|
47 |
+#include "libclamav/clamav.h" |
|
48 |
+#include "libclamav/others.h" |
|
49 |
+ |
|
50 |
+#include "shared/memory.h" |
|
51 |
+#include "shared/output.h" |
|
52 |
+#include "shared/options.h" |
|
53 |
+#include "shared/cfgparser.h" |
|
54 |
+#include "shared/misc.h" |
|
55 |
+ |
|
56 |
+#include "server.h" |
|
50 | 57 |
#include "tcpserver.h" |
51 | 58 |
#include "localserver.h" |
52 | 59 |
#include "others.h" |
53 |
-#include "memory.h" |
|
54 |
-#include "output.h" |
|
55 | 60 |
#include "shared.h" |
56 |
-#include "target.h" |
|
57 |
-#include "misc.h" |
|
58 | 61 |
|
59 |
-void help(void); |
|
60 | 62 |
|
61 | 63 |
short debug_mode = 0, logok = 0; |
62 |
- |
|
63 | 64 |
short foreground = 0; |
64 | 65 |
|
66 |
+void help(void) |
|
67 |
+{ |
|
68 |
+ printf("\n"); |
|
69 |
+ printf(" Clam AntiVirus Daemon "VERSION"\n"); |
|
70 |
+ printf(" (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n"); |
|
71 |
+ |
|
72 |
+ printf(" --help -h Show this help.\n"); |
|
73 |
+ printf(" --version -V Show version number.\n"); |
|
74 |
+ printf(" --debug Enable debug mode.\n"); |
|
75 |
+ printf(" --config-file=FILE -c FILE Read configuration from FILE.\n\n"); |
|
76 |
+ |
|
77 |
+} |
|
78 |
+ |
|
65 | 79 |
int main(int argc, char **argv) |
66 | 80 |
{ |
67 | 81 |
struct cfgstruct *copt, *cpt; |
... | ... |
@@ -69,7 +82,8 @@ int main(int argc, char **argv) |
69 | 69 |
time_t currtime; |
70 | 70 |
struct cl_node *root = NULL; |
71 | 71 |
const char *dbdir, *cfgfile; |
72 |
- int ret, virnum = 0, tcpsock = 0, localsock = 0; |
|
72 |
+ int ret, tcpsock = 0, localsock = 0; |
|
73 |
+ unsigned int sigs = 0; |
|
73 | 74 |
int lsockets[2], nlsockets = 0; |
74 | 75 |
unsigned int dboptions = 0; |
75 | 76 |
#ifdef C_LINUX |
... | ... |
@@ -95,11 +109,14 @@ int main(int argc, char **argv) |
95 | 95 |
|
96 | 96 |
if(opt_check(opt, "version")) { |
97 | 97 |
print_version(); |
98 |
- exit(0); |
|
98 |
+ opt_free(opt); |
|
99 |
+ return 0; |
|
99 | 100 |
} |
100 | 101 |
|
101 | 102 |
if(opt_check(opt, "help")) { |
102 | 103 |
help(); |
104 |
+ opt_free(opt); |
|
105 |
+ return 0; |
|
103 | 106 |
} |
104 | 107 |
|
105 | 108 |
if(opt_check(opt, "debug")) { |
... | ... |
@@ -112,7 +129,6 @@ int main(int argc, char **argv) |
112 | 112 |
perror("setrlimit"); |
113 | 113 |
#endif |
114 | 114 |
debug_mode = 1; |
115 |
- |
|
116 | 115 |
} |
117 | 116 |
|
118 | 117 |
/* parse the config file */ |
... | ... |
@@ -123,8 +139,10 @@ int main(int argc, char **argv) |
123 | 123 |
|
124 | 124 |
if((copt = getcfg(cfgfile, 1)) == NULL) { |
125 | 125 |
fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", cfgfile); |
126 |
- exit(1); |
|
126 |
+ opt_free(opt); |
|
127 |
+ return 1; |
|
127 | 128 |
} |
129 |
+ opt_free(opt); |
|
128 | 130 |
|
129 | 131 |
umask(0); |
130 | 132 |
|
... | ... |
@@ -134,7 +152,9 @@ int main(int argc, char **argv) |
134 | 134 |
if((user = getpwnam(cpt->strarg)) == NULL) { |
135 | 135 |
fprintf(stderr, "ERROR: Can't get information about user %s.\n", cpt->strarg); |
136 | 136 |
logg("!Can't get information about user %s.\n", cpt->strarg); |
137 |
- exit(1); |
|
137 |
+ logg_close(); |
|
138 |
+ freecfg(copt); |
|
139 |
+ return 1; |
|
138 | 140 |
} |
139 | 141 |
|
140 | 142 |
if(cfgopt(copt, "AllowSupplementaryGroups")->enabled) { |
... | ... |
@@ -142,7 +162,9 @@ int main(int argc, char **argv) |
142 | 142 |
if(initgroups(cpt->strarg, user->pw_gid)) { |
143 | 143 |
fprintf(stderr, "ERROR: initgroups() failed.\n"); |
144 | 144 |
logg("!initgroups() failed.\n"); |
145 |
- exit(1); |
|
145 |
+ logg_close(); |
|
146 |
+ freecfg(copt); |
|
147 |
+ return 1; |
|
146 | 148 |
} |
147 | 149 |
#else |
148 | 150 |
logg("AllowSupplementaryGroups: initgroups() not supported.\n"); |
... | ... |
@@ -152,7 +174,9 @@ int main(int argc, char **argv) |
152 | 152 |
if(setgroups(1, &user->pw_gid)) { |
153 | 153 |
fprintf(stderr, "ERROR: setgroups() failed.\n"); |
154 | 154 |
logg("!setgroups() failed.\n"); |
155 |
- exit(1); |
|
155 |
+ logg_close(); |
|
156 |
+ freecfg(copt); |
|
157 |
+ return 1; |
|
156 | 158 |
} |
157 | 159 |
#endif |
158 | 160 |
} |
... | ... |
@@ -160,13 +184,17 @@ int main(int argc, char **argv) |
160 | 160 |
if(setgid(user->pw_gid)) { |
161 | 161 |
fprintf(stderr, "ERROR: setgid(%d) failed.\n", (int) user->pw_gid); |
162 | 162 |
logg("!setgid(%d) failed.\n", (int) user->pw_gid); |
163 |
- exit(1); |
|
163 |
+ logg_close(); |
|
164 |
+ freecfg(copt); |
|
165 |
+ return 1; |
|
164 | 166 |
} |
165 | 167 |
|
166 | 168 |
if(setuid(user->pw_uid)) { |
167 | 169 |
fprintf(stderr, "ERROR: setuid(%d) failed.\n", (int) user->pw_uid); |
168 | 170 |
logg("!setuid(%d) failed.\n", (int) user->pw_uid); |
169 |
- exit(1); |
|
171 |
+ logg_close(); |
|
172 |
+ freecfg(copt); |
|
173 |
+ return 1; |
|
170 | 174 |
} |
171 | 175 |
|
172 | 176 |
logg("Running as user %s (UID %d, GID %d)\n", user->pw_name, user->pw_uid, user->pw_gid); |
... | ... |
@@ -174,7 +202,6 @@ int main(int argc, char **argv) |
174 | 174 |
#endif |
175 | 175 |
|
176 | 176 |
/* initialize logger */ |
177 |
- |
|
178 | 177 |
logg_lock = cfgopt(copt, "LogFileUnlock")->enabled; |
179 | 178 |
logg_time = cfgopt(copt, "LogTime")->enabled; |
180 | 179 |
logok = cfgopt(copt, "LogClean")->enabled; |
... | ... |
@@ -188,12 +215,16 @@ int main(int argc, char **argv) |
188 | 188 |
logg_file = cpt->strarg; |
189 | 189 |
if(strlen(logg_file) < 2 || (logg_file[0] != '/' && logg_file[0] != '\\' && logg_file[1] != ':')) { |
190 | 190 |
fprintf(stderr, "ERROR: LogFile requires full path.\n"); |
191 |
- exit(1); |
|
191 |
+ logg_close(); |
|
192 |
+ freecfg(copt); |
|
193 |
+ return 1; |
|
192 | 194 |
} |
193 | 195 |
time(&currtime); |
194 |
- if(logg("+++ Started at %s", ctime(&currtime))) { |
|
196 |
+ if(logg("#+++ Started at %s", ctime(&currtime))) { |
|
195 | 197 |
fprintf(stderr, "ERROR: Problem with internal logger. Please check the permissions on the %s file.\n", logg_file); |
196 |
- exit(1); |
|
198 |
+ logg_close(); |
|
199 |
+ freecfg(copt); |
|
200 |
+ return 1; |
|
197 | 201 |
} |
198 | 202 |
} else |
199 | 203 |
logg_file = NULL; |
... | ... |
@@ -204,8 +235,10 @@ int main(int argc, char **argv) |
204 | 204 |
|
205 | 205 |
cpt = cfgopt(copt, "LogFacility"); |
206 | 206 |
if((fac = logg_facility(cpt->strarg)) == -1) { |
207 |
- fprintf(stderr, "ERROR: LogFacility: %s: No such facility.\n", cpt->strarg); |
|
208 |
- exit(1); |
|
207 |
+ logg("!LogFacility: %s: No such facility.\n", cpt->strarg); |
|
208 |
+ logg_close(); |
|
209 |
+ freecfg(copt); |
|
210 |
+ return 1; |
|
209 | 211 |
} |
210 | 212 |
|
211 | 213 |
openlog("clamd", LOG_PID, fac); |
... | ... |
@@ -213,14 +246,12 @@ int main(int argc, char **argv) |
213 | 213 |
} |
214 | 214 |
#endif |
215 | 215 |
|
216 |
- logg("clamd daemon "VERSION" (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n"); |
|
216 |
+ logg("#clamd daemon "VERSION" (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n"); |
|
217 | 217 |
|
218 | 218 |
if(logg_size) |
219 |
- logg("Log file size limited to %d bytes.\n", logg_size); |
|
219 |
+ logg("#Log file size limited to %d bytes.\n", logg_size); |
|
220 | 220 |
else |
221 |
- logg("Log file size limit disabled.\n"); |
|
222 |
- |
|
223 |
- logg("*Verbose logging activated.\n"); |
|
221 |
+ logg("#Log file size limit disabled.\n"); |
|
224 | 222 |
|
225 | 223 |
#ifdef C_LINUX |
226 | 224 |
procdev = 0; |
... | ... |
@@ -237,9 +268,10 @@ int main(int argc, char **argv) |
237 | 237 |
localsock = 1; |
238 | 238 |
|
239 | 239 |
if(!tcpsock && !localsock) { |
240 |
- fprintf(stderr, "ERROR: You must select server type (local/tcp).\n"); |
|
241 |
- logg("!Please select server type (local/TCP).\n"); |
|
242 |
- exit(1); |
|
240 |
+ logg("!Please define server type (local and/or TCP).\n"); |
|
241 |
+ logg_close(); |
|
242 |
+ freecfg(copt); |
|
243 |
+ return 1; |
|
243 | 244 |
} |
244 | 245 |
|
245 | 246 |
/* set the temporary dir */ |
... | ... |
@@ -251,30 +283,33 @@ int main(int argc, char **argv) |
251 | 251 |
|
252 | 252 |
/* load the database(s) */ |
253 | 253 |
dbdir = cfgopt(copt, "DatabaseDirectory")->strarg; |
254 |
- logg("Reading databases from %s\n", dbdir); |
|
254 |
+ logg("#Reading databases from %s\n", dbdir); |
|
255 | 255 |
|
256 | 256 |
if(!cfgopt(copt, "DetectPhishing")->enabled) { |
257 | 257 |
dboptions |= CL_DB_NOPHISHING; |
258 | 258 |
logg("Not loading phishing signatures.\n"); |
259 | 259 |
} |
260 | 260 |
|
261 |
- if((ret = cl_load(dbdir, &root, &virnum, dboptions))) { |
|
262 |
- fprintf(stderr, "ERROR: %s\n", cl_strerror(ret)); |
|
261 |
+ if((ret = cl_load(dbdir, &root, &sigs, dboptions))) { |
|
263 | 262 |
logg("!%s\n", cl_strerror(ret)); |
264 |
- exit(1); |
|
263 |
+ logg_close(); |
|
264 |
+ freecfg(copt); |
|
265 |
+ return 1; |
|
265 | 266 |
} |
266 | 267 |
|
267 | 268 |
if(!root) { |
268 |
- fprintf(stderr, "ERROR: Database initialization error.\n"); |
|
269 | 269 |
logg("!Database initialization error.\n"); |
270 |
- exit(1); |
|
270 |
+ logg_close(); |
|
271 |
+ freecfg(copt); |
|
272 |
+ return 1; |
|
271 | 273 |
} |
272 | 274 |
|
273 |
- logg("Protecting against %d viruses.\n", virnum); |
|
275 |
+ logg("#Loaded %d signatures.\n", sigs); |
|
274 | 276 |
if((ret = cl_build(root)) != 0) { |
275 |
- fprintf(stderr, "ERROR: Database initialization error: %s\n", cl_strerror(ret));; |
|
276 | 277 |
logg("!Database initialization error: %s\n", cl_strerror(ret));; |
277 |
- exit(1); |
|
278 |
+ logg_close(); |
|
279 |
+ freecfg(copt); |
|
280 |
+ return 1; |
|
278 | 281 |
} |
279 | 282 |
|
280 | 283 |
/* fork into background */ |
... | ... |
@@ -285,31 +320,32 @@ int main(int argc, char **argv) |
285 | 285 |
} else |
286 | 286 |
foreground = 1; |
287 | 287 |
|
288 |
- if(tcpsock) |
|
289 |
- lsockets[nlsockets++] = tcpserver(copt, root); |
|
288 |
+ if(tcpsock) { |
|
289 |
+ lsockets[nlsockets] = tcpserver(copt); |
|
290 |
+ if(lsockets[nlsockets] == -1) { |
|
291 |
+ logg_close(); |
|
292 |
+ freecfg(copt); |
|
293 |
+ return 1; |
|
294 |
+ } |
|
295 |
+ nlsockets++; |
|
296 |
+ } |
|
290 | 297 |
|
291 |
- if(localsock) |
|
292 |
- lsockets[nlsockets++] = localserver(copt, root); |
|
298 |
+ if(localsock) { |
|
299 |
+ lsockets[nlsockets] = localserver(copt); |
|
300 |
+ if(lsockets[nlsockets] == -1) { |
|
301 |
+ logg_close(); |
|
302 |
+ freecfg(copt); |
|
303 |
+ if(tcpsock) |
|
304 |
+ close(lsockets[0]); |
|
305 |
+ return 1; |
|
306 |
+ } |
|
307 |
+ nlsockets++; |
|
308 |
+ } |
|
293 | 309 |
|
294 | 310 |
ret = acceptloop_th(lsockets, nlsockets, root, copt); |
295 | 311 |
|
296 | 312 |
logg_close(); |
297 | 313 |
freecfg(copt); |
298 |
- return ret; |
|
299 |
-} |
|
300 |
- |
|
301 |
-void help(void) |
|
302 |
-{ |
|
303 |
- |
|
304 |
- printf("\n"); |
|
305 |
- printf(" Clam AntiVirus Daemon "VERSION"\n"); |
|
306 |
- printf(" (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n"); |
|
307 |
- |
|
308 |
- printf(" --help -h Show this help.\n"); |
|
309 |
- printf(" --version -V Show version number.\n"); |
|
310 |
- printf(" --debug Enable debug mode.\n"); |
|
311 |
- printf(" --config-file=FILE -c FILE Read configuration from FILE.\n\n"); |
|
312 | 314 |
|
313 |
- exit(0); |
|
315 |
+ return ret; |
|
314 | 316 |
} |
315 |
- |
... | ... |
@@ -29,14 +29,16 @@ |
29 | 29 |
#include <sys/stat.h> |
30 | 30 |
#include <signal.h> |
31 | 31 |
#include <pthread.h> |
32 |
-#include <clamav.h> |
|
32 |
+ |
|
33 |
+#include "libclamav/clamav.h" |
|
34 |
+ |
|
35 |
+#include "shared/cfgparser.h" |
|
36 |
+#include "shared/output.h" |
|
33 | 37 |
|
34 | 38 |
#include "server.h" |
35 | 39 |
#include "others.h" |
36 |
-#include "cfgparser.h" |
|
37 | 40 |
#include "dazukoio.h" |
38 | 41 |
#include "clamuko.h" |
39 |
-#include "output.h" |
|
40 | 42 |
|
41 | 43 |
struct dazuko_access *acc; |
42 | 44 |
|
... | ... |
@@ -27,20 +27,21 @@ |
27 | 27 |
#include <sys/socket.h> |
28 | 28 |
#include <sys/stat.h> |
29 | 29 |
#include <sys/un.h> |
30 |
-#include <clamav.h> |
|
31 | 30 |
#include <errno.h> |
32 | 31 |
|
33 |
-#include "options.h" |
|
34 |
-#include "cfgparser.h" |
|
32 |
+#include "libclamav/clamav.h" |
|
33 |
+ |
|
34 |
+#include "shared/options.h" |
|
35 |
+#include "shared/cfgparser.h" |
|
36 |
+ |
|
35 | 37 |
#include "others.h" |
36 | 38 |
#include "server.h" |
37 | 39 |
#include "output.h" |
38 | 40 |
|
39 |
-int localserver(const struct cfgstruct *copt, struct cl_node *root) |
|
41 |
+int localserver(const struct cfgstruct *copt) |
|
40 | 42 |
{ |
41 | 43 |
struct sockaddr_un server; |
42 | 44 |
int sockfd, backlog; |
43 |
- struct cfgstruct *cpt; |
|
44 | 45 |
struct stat foo; |
45 | 46 |
char *estr; |
46 | 47 |
|
... | ... |
@@ -50,40 +51,41 @@ int localserver(const struct cfgstruct *copt, struct cl_node *root) |
50 | 50 |
|
51 | 51 |
if((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { |
52 | 52 |
estr = strerror(errno); |
53 |
- /* |
|
54 |
- fprintf(stderr, "ERROR: socket() error: %s\n", estr); |
|
55 |
- */ |
|
56 | 53 |
logg("!Socket allocation error: %s\n", estr); |
57 |
- exit(1); |
|
54 |
+ return -1; |
|
58 | 55 |
} |
59 | 56 |
|
60 | 57 |
if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) == -1) { |
61 | 58 |
if(errno == EADDRINUSE) { |
62 | 59 |
if(connect(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) >= 0) { |
63 |
- close(sockfd); |
|
64 | 60 |
logg("!Socket file %s is in use by another process.\n", server.sun_path); |
65 |
- exit(1); |
|
61 |
+ close(sockfd); |
|
62 |
+ return -1; |
|
66 | 63 |
} |
67 | 64 |
if(cfgopt(copt, "FixStaleSocket")->enabled) { |
68 | 65 |
logg("^Socket file %s exists. Unclean shutdown? Removing...\n", server.sun_path); |
69 | 66 |
if(unlink(server.sun_path) == -1) { |
70 | 67 |
estr = strerror(errno); |
71 | 68 |
logg("!Socket file %s could not be removed: %s\n", server.sun_path, estr); |
72 |
- exit(1); |
|
69 |
+ close(sockfd); |
|
70 |
+ return -1; |
|
73 | 71 |
} |
74 | 72 |
if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) == -1) { |
75 | 73 |
estr = strerror(errno); |
76 | 74 |
logg("!Socket file %s could not be bound: %s (unlink tried)\n", server.sun_path, estr); |
77 |
- exit(1); |
|
75 |
+ close(sockfd); |
|
76 |
+ return -1; |
|
78 | 77 |
} |
79 | 78 |
} else if(stat(server.sun_path, &foo) != -1) { |
80 | 79 |
logg("!Socket file %s exists. Either remove it, or configure a different one.\n", server.sun_path); |
81 |
- exit(1); |
|
80 |
+ close(sockfd); |
|
81 |
+ return -1; |
|
82 | 82 |
} |
83 | 83 |
} else { |
84 | 84 |
estr = strerror(errno); |
85 | 85 |
logg("!Socket file %s could not be bound: %s\n", server.sun_path, estr); |
86 |
- exit(1); |
|
86 |
+ close(sockfd); |
|
87 |
+ return -1; |
|
87 | 88 |
} |
88 | 89 |
} |
89 | 90 |
|
... | ... |
@@ -94,11 +96,9 @@ int localserver(const struct cfgstruct *copt, struct cl_node *root) |
94 | 94 |
|
95 | 95 |
if(listen(sockfd, backlog) == -1) { |
96 | 96 |
estr = strerror(errno); |
97 |
- /* |
|
98 |
- fprintf(stderr, "ERROR: listen() error: %s\n", estr); |
|
99 |
- */ |
|
100 | 97 |
logg("!listen() error: %s\n", estr); |
101 |
- exit(1); |
|
98 |
+ close(sockfd); |
|
99 |
+ return -1; |
|
102 | 100 |
} |
103 | 101 |
|
104 | 102 |
return sockfd; |
... | ... |
@@ -33,7 +33,6 @@ |
33 | 33 |
#include <sys/time.h> |
34 | 34 |
#include <sys/wait.h> |
35 | 35 |
|
36 |
- |
|
37 | 36 |
#if HAVE_SYS_PARAM_H |
38 | 37 |
#include <sys/param.h> |
39 | 38 |
#endif |
... | ... |
@@ -68,11 +67,12 @@ |
68 | 68 |
#endif /* HAVE_POLL_H */ |
69 | 69 |
#endif /* HAVE_POLL */ |
70 | 70 |
|
71 |
-#include "memory.h" |
|
72 |
-#include "cfgparser.h" |
|
71 |
+#include "shared/memory.h" |
|
72 |
+#include "shared/cfgparser.h" |
|
73 |
+#include "shared/output.h" |
|
74 |
+ |
|
73 | 75 |
#include "session.h" |
74 | 76 |
#include "others.h" |
75 |
-#include "output.h" |
|
76 | 77 |
|
77 | 78 |
#define ENV_FILE "CLAM_VIRUSEVENT_FILENAME" |
78 | 79 |
#define ENV_VIRUS "CLAM_VIRUSEVENT_VIRUSNAME" |
... | ... |
@@ -139,8 +139,14 @@ int poll_fds(int *fds, int nfds, int timeout_sec) |
139 | 139 |
struct pollfd poll_1[1]; |
140 | 140 |
struct pollfd *poll_data = poll_1; |
141 | 141 |
|
142 |
- if (nfds>1) |
|
143 |
- poll_data = malloc(nfds*sizeof(*poll_data)); |
|
142 |
+ if (nfds>1) { |
|
143 |
+ poll_data = mmalloc(nfds*sizeof(*poll_data)); |
|
144 |
+ if(!poll_data) { |
|
145 |
+ logg("!poll_fds: Can't allocate memory for poll_data\n"); |
|
146 |
+ return -1; |
|
147 |
+ } |
|
148 |
+ } |
|
149 |
+ |
|
144 | 150 |
for (i=0; i<nfds; i++) { |
145 | 151 |
poll_data[i].fd = fds[i]; |
146 | 152 |
poll_data[i].events = POLLIN; |
... | ... |
@@ -392,7 +398,7 @@ int readsock(int sockfd, char *buf, size_t size, unsigned char delim, int timeou |
392 | 392 |
if(fd < 0) |
393 | 393 |
return -1; |
394 | 394 |
n = snprintf(buf, size, "FD %d", fd); |
395 |
- if(n >= size) |
|
395 |
+ if((size_t) n >= size) |
|
396 | 396 |
return -1; |
397 | 397 |
return n; |
398 | 398 |
} |
... | ... |
@@ -36,7 +36,6 @@ |
36 | 36 |
#include <netinet/in.h> |
37 | 37 |
#include <arpa/inet.h> |
38 | 38 |
#include <netdb.h> |
39 |
-#include <clamav.h> |
|
40 | 39 |
#include <pthread.h> |
41 | 40 |
|
42 | 41 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
... | ... |
@@ -44,16 +43,18 @@ |
44 | 44 |
#include <stddef.h> |
45 | 45 |
#endif |
46 | 46 |
|
47 |
-#include "cfgparser.h" |
|
47 |
+#include "libclamav/clamav.h" |
|
48 |
+#include "libclamav/others.h" |
|
49 |
+ |
|
50 |
+#include "shared/cfgparser.h" |
|
51 |
+#include "shared/memory.h" |
|
52 |
+#include "shared/output.h" |
|
53 |
+ |
|
48 | 54 |
#include "others.h" |
49 | 55 |
#include "scanner.h" |
50 |
-#include "memory.h" |
|
51 | 56 |
#include "shared.h" |
52 |
-#include "output.h" |
|
53 | 57 |
#include "network.h" |
54 | 58 |
|
55 |
-#include "../libclamav/others.h" |
|
56 |
- |
|
57 | 59 |
#ifdef C_LINUX |
58 | 60 |
dev_t procdev; /* /proc device */ |
59 | 61 |
#endif |
... | ... |
@@ -97,9 +98,9 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne |
97 | 97 |
} result; |
98 | 98 |
#endif |
99 | 99 |
struct stat statbuf; |
100 |
- struct cfgstruct *cpt; |
|
101 | 100 |
char *fname; |
102 |
- int ret = 0, scanret = 0, maxdirrec = 0; |
|
101 |
+ int ret = 0, scanret = 0; |
|
102 |
+ unsigned int maxdirrec = 0; |
|
103 | 103 |
|
104 | 104 |
|
105 | 105 |
maxdirrec = cfgopt(copt, "MaxDirectoryRecursion")->numarg; |
... | ... |
@@ -196,7 +197,8 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne |
196 | 196 |
int scan(const char *filename, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, short contscan) |
197 | 197 |
{ |
198 | 198 |
struct stat sb; |
199 |
- int ret = 0, reclev = 0; |
|
199 |
+ int ret = 0; |
|
200 |
+ unsigned int reclev = 0; |
|
200 | 201 |
const char *virname; |
201 | 202 |
|
202 | 203 |
|
... | ... |
@@ -257,7 +259,7 @@ int scan(const char *filename, unsigned long int *scanned, const struct cl_node |
257 | 257 |
return ret; |
258 | 258 |
} |
259 | 259 |
|
260 |
-int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, short contscan) |
|
260 |
+int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc) |
|
261 | 261 |
{ |
262 | 262 |
int ret; |
263 | 263 |
const char *virname; |
... | ... |
@@ -20,15 +20,14 @@ |
20 | 20 |
#ifndef __SCANNER_H |
21 | 21 |
#define __SCANNER_H |
22 | 22 |
|
23 |
-#include <clamav.h> |
|
24 |
-#include "cfgparser.h" |
|
25 |
- |
|
23 |
+#include "libclamav/clamav.h" |
|
24 |
+#include "shared/cfgparser.h" |
|
26 | 25 |
|
27 | 26 |
int dirscan(const char *dirname, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, short contscan); |
28 | 27 |
|
29 | 28 |
int scan(const char *filename, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, short contscan); |
30 | 29 |
|
31 |
-int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, short contscan); |
|
30 |
+int scanfd(const int fd, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc); |
|
32 | 31 |
|
33 | 32 |
int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt); |
34 | 33 |
|
... | ... |
@@ -31,16 +31,18 @@ |
31 | 31 |
#include <sys/types.h> |
32 | 32 |
#include <sys/socket.h> |
33 | 33 |
#include <unistd.h> |
34 |
-#include <clamav.h> |
|
34 |
+ |
|
35 |
+#include "libclamav/clamav.h" |
|
36 |
+ |
|
37 |
+#include "shared/memory.h" |
|
38 |
+#include "shared/output.h" |
|
35 | 39 |
|
36 | 40 |
#include "server.h" |
37 | 41 |
#include "thrmgr.h" |
38 | 42 |
#include "session.h" |
39 | 43 |
#include "clamuko.h" |
40 | 44 |
#include "others.h" |
41 |
-#include "memory.h" |
|
42 | 45 |
#include "shared.h" |
43 |
-#include "output.h" |
|
44 | 46 |
|
45 | 47 |
#define BUFFSIZE 1024 |
46 | 48 |
#define FALSE (0) |
... | ... |
@@ -69,7 +71,6 @@ void scanner_thread(void *arg) |
69 | 69 |
client_conn_t *conn = (client_conn_t *) arg; |
70 | 70 |
sigset_t sigset; |
71 | 71 |
int ret, timeout, i, session=FALSE; |
72 |
- struct cfgstruct *cpt; |
|
73 | 72 |
|
74 | 73 |
|
75 | 74 |
/* ignore all signals */ |
... | ... |
@@ -160,8 +161,8 @@ void sighandler_th(int sig) |
160 | 160 |
static struct cl_node *reload_db(struct cl_node *root, const struct cfgstruct *copt, int do_check) |
161 | 161 |
{ |
162 | 162 |
const char *dbdir; |
163 |
- int virnum=0, retval; |
|
164 |
- struct cfgstruct *cpt; |
|
163 |
+ int retval; |
|
164 |
+ unsigned int sigs = 0; |
|
165 | 165 |
static struct cl_stat *dbstat=NULL; |
166 | 166 |
unsigned int dboptions = 0; |
167 | 167 |
|
... | ... |
@@ -203,7 +204,7 @@ static struct cl_node *reload_db(struct cl_node *root, const struct cfgstruct *c |
203 | 203 |
logg("Not loading phishing signatures.\n"); |
204 | 204 |
} |
205 | 205 |
|
206 |
- if((retval = cl_load(dbdir, &root, &virnum, dboptions))) { |
|
206 |
+ if((retval = cl_load(dbdir, &root, &sigs, dboptions))) { |
|
207 | 207 |
logg("!reload db failed: %s\n", cl_strerror(retval)); |
208 | 208 |
exit(-1); |
209 | 209 |
} |
... | ... |
@@ -218,7 +219,7 @@ static struct cl_node *reload_db(struct cl_node *root, const struct cfgstruct *c |
218 | 218 |
cl_strerror(retval)); |
219 | 219 |
exit(-1); |
220 | 220 |
} |
221 |
- logg("Database correctly reloaded (%d viruses)\n", virnum); |
|
221 |
+ logg("Database correctly reloaded (%d signatures)\n", sigs); |
|
222 | 222 |
|
223 | 223 |
return root; |
224 | 224 |
} |
... | ... |
@@ -33,24 +33,25 @@ |
33 | 33 |
#include <signal.h> |
34 | 34 |
#include <errno.h> |
35 | 35 |
|
36 |
-#include "cfgparser.h" |
|
36 |
+#include "libclamav/clamav.h" |
|
37 |
+#include "libclamav/str.h" |
|
38 |
+ |
|
39 |
+#include "shared/cfgparser.h" |
|
40 |
+#include "shared/memory.h" |
|
41 |
+#include "shared/output.h" |
|
42 |
+ |
|
37 | 43 |
#include "others.h" |
38 | 44 |
#include "scanner.h" |
39 | 45 |
#include "server.h" |
40 | 46 |
#include "clamuko.h" |
41 | 47 |
#include "session.h" |
42 |
-#include "str.h" /* libclamav */ |
|
43 |
-#include "clamav.h" |
|
44 |
-#include "output.h" |
|
45 |
-#include "memory.h" |
|
46 | 48 |
|
47 | 49 |
static pthread_mutex_t ctime_mutex = PTHREAD_MUTEX_INITIALIZER; |
48 | 50 |
|
49 | 51 |
int command(int desc, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int timeout) |
50 | 52 |
{ |
51 | 53 |
char buff[1025]; |
52 |
- int bread, opt, retval; |
|
53 |
- struct cfgstruct *cpt; |
|
54 |
+ int bread, opt; |
|
54 | 55 |
|
55 | 56 |
|
56 | 57 |
bread = readsock(desc, buff, sizeof(buff)-1, '\n', timeout, 0, 1); |
... | ... |
@@ -135,7 +136,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
135 | 135 |
} else if(!strncmp(buff, CMD12, strlen(CMD12))) { /* FD */ |
136 | 136 |
int fd = atoi(buff + strlen(CMD12) + 1); |
137 | 137 |
|
138 |
- scanfd(fd, NULL, root, limits, options, copt, desc, 0); |
|
138 |
+ scanfd(fd, NULL, root, limits, options, copt, desc); |
|
139 | 139 |
close(fd); /* FIXME: should we close it here? */ |
140 | 140 |
|
141 | 141 |
} else { |
... | ... |
@@ -38,8 +38,8 @@ |
38 | 38 |
#define CMD11 "SHUTDOWN" |
39 | 39 |
#define CMD12 "FD" |
40 | 40 |
|
41 |
-#include <clamav.h> |
|
42 |
-#include "cfgparser.h" |
|
41 |
+#include "libclamav/clamav.h" |
|
42 |
+#include "shared/cfgparser.h" |
|
43 | 43 |
|
44 | 44 |
int command(int desc, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int timeout); |
45 | 45 |
|
... | ... |
@@ -27,21 +27,23 @@ |
27 | 27 |
#include <sys/socket.h> |
28 | 28 |
#include <netinet/in.h> |
29 | 29 |
#include <arpa/inet.h> |
30 |
-#include <clamav.h> |
|
31 | 30 |
#include <errno.h> |
32 | 31 |
#include <netdb.h> |
33 | 32 |
|
34 |
-#include "options.h" |
|
35 |
-#include "cfgparser.h" |
|
33 |
+#include "libclamav/clamav.h" |
|
34 |
+ |
|
35 |
+#include "shared/options.h" |
|
36 |
+#include "shared/cfgparser.h" |
|
37 |
+#include "shared/output.h" |
|
38 |
+#include "shared/network.h" |
|
39 |
+ |
|
36 | 40 |
#include "others.h" |
37 | 41 |
#include "server.h" |
38 |
-#include "output.h" |
|
39 | 42 |
|
40 |
-int tcpserver(const struct cfgstruct *copt, struct cl_node *root) |
|
43 |
+int tcpserver(const struct cfgstruct *copt) |
|
41 | 44 |
{ |
42 | 45 |
struct sockaddr_in server; |
43 | 46 |
int sockfd, backlog; |
44 |
- struct cfgstruct *cpt; |
|
45 | 47 |
struct cfgstruct *taddr; |
46 | 48 |
struct hostent he; |
47 | 49 |
char *estr, buf[1024]; |
... | ... |
@@ -54,7 +56,7 @@ int tcpserver(const struct cfgstruct *copt, struct cl_node *root) |
54 | 54 |
if((taddr = cfgopt(copt, "TCPAddr"))->enabled) { |
55 | 55 |
if(r_gethostbyname(taddr->strarg, &he, buf, sizeof(buf)) == -1) { |
56 | 56 |
logg("!r_gethostbyname(%s) error: %s\n", taddr->strarg, strerror(errno)); |
57 |
- exit(1); |
|
57 |
+ return -1; |
|
58 | 58 |
} |
59 | 59 |
server.sin_addr = *(struct in_addr *) he.h_addr_list[0]; |
60 | 60 |
} else |
... | ... |
@@ -64,7 +66,7 @@ int tcpserver(const struct cfgstruct *copt, struct cl_node *root) |
64 | 64 |
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { |
65 | 65 |
estr = strerror(errno); |
66 | 66 |
logg("!socket() error: %s\n", estr); |
67 |
- exit(1); |
|
67 |
+ return -1; |
|
68 | 68 |
} |
69 | 69 |
|
70 | 70 |
if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void *) &true, sizeof(true)) == -1) { |
... | ... |
@@ -74,7 +76,8 @@ int tcpserver(const struct cfgstruct *copt, struct cl_node *root) |
74 | 74 |
if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) == -1) { |
75 | 75 |
estr = strerror(errno); |
76 | 76 |
logg("!bind() error: %s\n", estr); |
77 |
- exit(1); |
|
77 |
+ close(sockfd); |
|
78 |
+ return -1; |
|
78 | 79 |
} else { |
79 | 80 |
if(taddr->enabled) |
80 | 81 |
logg("Bound to address %s on tcp port %d\n", taddr->strarg, cfgopt(copt, "TCPSocket")->numarg); |
... | ... |
@@ -88,7 +91,8 @@ int tcpserver(const struct cfgstruct *copt, struct cl_node *root) |
88 | 88 |
if(listen(sockfd, backlog) == -1) { |
89 | 89 |
estr = strerror(errno); |
90 | 90 |
logg("!listen() error: %s\n", estr); |
91 |
- exit(1); |
|
91 |
+ close(sockfd); |
|
92 |
+ return -1; |
|
92 | 93 |
} |
93 | 94 |
|
94 | 95 |
return sockfd; |
... | ... |
@@ -20,9 +20,8 @@ |
20 | 20 |
#ifndef __TCPSERVER_H |
21 | 21 |
#define __TCPSERVER_H |
22 | 22 |
|
23 |
-#include "options.h" |
|
24 |
-#include "cfgparser.h" |
|
23 |
+#include "shared/cfgparser.h" |
|
25 | 24 |
|
26 |
-int tcpserver(const struct cfgstruct *copt, struct cl_node *root); |
|
25 |
+int tcpserver(const struct cfgstruct *copt); |
|
27 | 26 |
|
28 | 27 |
#endif |
... | ... |
@@ -17,15 +17,16 @@ |
17 | 17 |
* MA 02110-1301, USA. |
18 | 18 |
*/ |
19 | 19 |
|
20 |
+#include <stdio.h> |
|
20 | 21 |
#include <pthread.h> |
21 | 22 |
#include <time.h> |
22 | 23 |
#include <errno.h> |
23 | 24 |
|
24 |
-#include "thrmgr.h" |
|
25 |
+#include "shared/memory.h" |
|
26 |
+#include "shared/output.h" |
|
25 | 27 |
|
28 |
+#include "thrmgr.h" |
|
26 | 29 |
#include "others.h" |
27 |
-#include "memory.h" |
|
28 |
-#include "output.h" |
|
29 | 30 |
|
30 | 31 |
#define FALSE (0) |
31 | 32 |
#define TRUE (1) |