git-svn: trunk@2960
Tomasz Kojm authored on 2007/03/21 05:58:56... | ... |
@@ -45,7 +45,8 @@ |
45 | 45 |
|
46 | 46 |
char *txtquery(const char *domain, unsigned int *ttl) |
47 | 47 |
{ |
48 |
- unsigned char answer[PACKETSZ], host[128], *pt, *txt; |
|
48 |
+ unsigned char answer[PACKETSZ], host[128], *pt; |
|
49 |
+ char *txt; |
|
49 | 50 |
int len, exp, cttl, size, txtlen, type, qtype; |
50 | 51 |
|
51 | 52 |
|
... | ... |
@@ -117,11 +118,11 @@ char *txtquery(const char *domain, unsigned int *ttl) |
117 | 117 |
return NULL; |
118 | 118 |
} |
119 | 119 |
|
120 |
- if(!(txt = malloc(txtlen + 1))) |
|
120 |
+ if(!(txt = (char *) malloc(txtlen + 1))) |
|
121 | 121 |
return NULL; |
122 | 122 |
|
123 | 123 |
pt++; |
124 |
- strncpy(txt, pt, txtlen); |
|
124 |
+ memcpy(txt, pt, txtlen); |
|
125 | 125 |
txt[txtlen] = 0; |
126 | 126 |
*ttl = cttl; |
127 | 127 |
|
... | ... |
@@ -151,7 +151,7 @@ static void help(void) |
151 | 151 |
static int download(const struct cfgstruct *copt, const struct optstruct *opt, const char *datadir) |
152 | 152 |
{ |
153 | 153 |
int ret = 0, try = 0, maxattempts = 0; |
154 |
- struct cfgstruct *cpt; |
|
154 |
+ const struct cfgstruct *cpt; |
|
155 | 155 |
|
156 | 156 |
|
157 | 157 |
maxattempts = cfgopt(copt, "MaxAttempts")->numarg; |
... | ... |
@@ -194,7 +194,8 @@ int main(int argc, char **argv) |
194 | 194 |
int ret = 52; |
195 | 195 |
const char *newdir, *cfgfile; |
196 | 196 |
char *pidfile = NULL; |
197 |
- struct cfgstruct *copt, *cpt; |
|
197 |
+ struct cfgstruct *copt; |
|
198 |
+ const struct cfgstruct *cpt; |
|
198 | 199 |
#ifndef C_WINDOWS |
199 | 200 |
struct sigaction sigact; |
200 | 201 |
struct sigaction oldact; |
... | ... |
@@ -271,6 +272,8 @@ int main(int argc, char **argv) |
271 | 271 |
#ifdef C_WINDOWS |
272 | 272 |
if(!pthread_win32_process_attach_np()) { |
273 | 273 |
mprintf("!Can't start the win32 pthreads layer\n"); |
274 |
+ opt_free(opt); |
|
275 |
+ freecfg(copt); |
|
274 | 276 |
return 63; |
275 | 277 |
} |
276 | 278 |
#endif |
... | ... |
@@ -282,6 +285,7 @@ int main(int argc, char **argv) |
282 | 282 |
if(stat(cfgfile, &statbuf) == -1) { |
283 | 283 |
logg("^Can't stat %s (critical error)\n", cfgfile); |
284 | 284 |
opt_free(opt); |
285 |
+ freecfg(copt); |
|
285 | 286 |
return 56; |
286 | 287 |
} |
287 | 288 |
|
... | ... |
@@ -289,6 +293,7 @@ int main(int argc, char **argv) |
289 | 289 |
if(statbuf.st_mode & (S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) { |
290 | 290 |
logg("^Insecure permissions (for HTTPProxyPassword): %s must have no more than 0700 permissions.\n", cfgfile); |
291 | 291 |
opt_free(opt); |
292 |
+ freecfg(copt); |
|
292 | 293 |
return 56; |
293 | 294 |
} |
294 | 295 |
#endif |
... | ... |
@@ -305,6 +310,7 @@ int main(int argc, char **argv) |
305 | 305 |
if((user = getpwnam(unpuser)) == NULL) { |
306 | 306 |
logg("^Can't get information about user %s.\n", unpuser); |
307 | 307 |
opt_free(opt); |
308 |
+ freecfg(copt); |
|
308 | 309 |
return 60; |
309 | 310 |
} |
310 | 311 |
|
... | ... |
@@ -313,6 +319,7 @@ int main(int argc, char **argv) |
313 | 313 |
if(initgroups(unpuser, user->pw_gid)) { |
314 | 314 |
logg("^initgroups() failed.\n"); |
315 | 315 |
opt_free(opt); |
316 |
+ freecfg(copt); |
|
316 | 317 |
return 61; |
317 | 318 |
} |
318 | 319 |
#endif |
... | ... |
@@ -321,6 +328,7 @@ int main(int argc, char **argv) |
321 | 321 |
if(setgroups(1, &user->pw_gid)) { |
322 | 322 |
logg("^setgroups() failed.\n"); |
323 | 323 |
opt_free(opt); |
324 |
+ freecfg(copt); |
|
324 | 325 |
return 61; |
325 | 326 |
} |
326 | 327 |
#endif |
... | ... |
@@ -329,12 +337,14 @@ int main(int argc, char **argv) |
329 | 329 |
if(setgid(user->pw_gid)) { |
330 | 330 |
logg("^setgid(%d) failed.\n", (int) user->pw_gid); |
331 | 331 |
opt_free(opt); |
332 |
+ freecfg(copt); |
|
332 | 333 |
return 61; |
333 | 334 |
} |
334 | 335 |
|
335 | 336 |
if(setuid(user->pw_uid)) { |
336 | 337 |
logg("^setuid(%d) failed.\n", (int) user->pw_uid); |
337 | 338 |
opt_free(opt); |
339 |
+ freecfg(copt); |
|
338 | 340 |
return 61; |
339 | 341 |
} |
340 | 342 |
} |
... | ... |
@@ -364,6 +374,7 @@ int main(int argc, char **argv) |
364 | 364 |
if(logg("#--------------------------------------\n")) { |
365 | 365 |
mprintf("!Problem with internal logger (--log=%s).\n", logg_file); |
366 | 366 |
opt_free(opt); |
367 |
+ freecfg(copt); |
|
367 | 368 |
return 62; |
368 | 369 |
} |
369 | 370 |
} else if((cpt = cfgopt(copt, "UpdateLogFile"))->enabled) { |
... | ... |
@@ -371,6 +382,7 @@ int main(int argc, char **argv) |
371 | 371 |
if(logg("#--------------------------------------\n")) { |
372 | 372 |
mprintf("!Problem with internal logger (UpdateLogFile = %s).\n", logg_file); |
373 | 373 |
opt_free(opt); |
374 |
+ freecfg(copt); |
|
374 | 375 |
return 62; |
375 | 376 |
} |
376 | 377 |
} else |
... | ... |
@@ -384,6 +396,7 @@ int main(int argc, char **argv) |
384 | 384 |
if((fac = logg_facility(cpt->strarg)) == -1) { |
385 | 385 |
mprintf("!LogFacility: %s: No such facility.\n", cpt->strarg); |
386 | 386 |
opt_free(opt); |
387 |
+ freecfg(copt); |
|
387 | 388 |
return 62; |
388 | 389 |
} |
389 | 390 |
} |
... | ... |
@@ -402,6 +415,7 @@ int main(int argc, char **argv) |
402 | 402 |
if(chdir(newdir)) { |
403 | 403 |
logg("Can't change dir to %s\n", newdir); |
404 | 404 |
opt_free(opt); |
405 |
+ freecfg(copt); |
|
405 | 406 |
return 50; |
406 | 407 |
} else |
407 | 408 |
logg("*Current working dir is %s\n", newdir); |
... | ... |
@@ -410,10 +424,14 @@ int main(int argc, char **argv) |
410 | 410 |
if(opt_check(opt, "list-mirrors")) { |
411 | 411 |
if(mirman_read("mirrors.dat", &mdat, 1) == -1) { |
412 | 412 |
printf("Can't read mirrors.dat\n"); |
413 |
+ opt_free(opt); |
|
414 |
+ freecfg(copt); |
|
413 | 415 |
return 55; |
414 | 416 |
} |
415 | 417 |
mirman_list(&mdat); |
416 | 418 |
mirman_free(&mdat); |
419 |
+ opt_free(opt); |
|
420 |
+ freecfg(copt); |
|
417 | 421 |
return 0; |
418 | 422 |
} |
419 | 423 |
|
... | ... |
@@ -423,6 +441,8 @@ int main(int argc, char **argv) |
423 | 423 |
|
424 | 424 |
if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { |
425 | 425 |
logg("!Error at WSAStartup(): %d\n", WSAGetLastError()); |
426 |
+ opt_free(opt); |
|
427 |
+ freecfg(copt); |
|
426 | 428 |
return 1; |
427 | 429 |
} |
428 | 430 |
} |
... | ... |
@@ -445,6 +465,7 @@ int main(int argc, char **argv) |
445 | 445 |
if(checks <= 0) { |
446 | 446 |
logg("^Number of checks must be a positive integer.\n"); |
447 | 447 |
opt_free(opt); |
448 |
+ freecfg(copt); |
|
448 | 449 |
return 41; |
449 | 450 |
} |
450 | 451 |
|
... | ... |
@@ -452,6 +473,7 @@ int main(int argc, char **argv) |
452 | 452 |
if(checks > 50) { |
453 | 453 |
logg("^Number of checks must be between 1 and 50.\n"); |
454 | 454 |
opt_free(opt); |
455 |
+ freecfg(copt); |
|
455 | 456 |
return 41; |
456 | 457 |
} |
457 | 458 |
} |
... | ... |
@@ -555,6 +577,7 @@ int main(int argc, char **argv) |
555 | 555 |
} |
556 | 556 |
|
557 | 557 |
opt_free(opt); |
558 |
+ freecfg(copt); |
|
558 | 559 |
|
559 | 560 |
#ifdef C_WINDOWS |
560 | 561 |
WSACleanup(); |
... | ... |
@@ -187,7 +187,7 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
187 | 187 |
} |
188 | 188 |
|
189 | 189 |
if((host = gethostbyname(hostpt)) == NULL) { |
190 |
- char *herr; |
|
190 |
+ const char *herr; |
|
191 | 191 |
switch(h_errno) { |
192 | 192 |
case HOST_NOT_FOUND: |
193 | 193 |
herr = "Host not found"; |
... | ... |
@@ -259,10 +259,10 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip |
259 | 259 |
|
260 | 260 |
static int Rfc2822DateTime(char *buf, time_t mtime) |
261 | 261 |
{ |
262 |
- struct tm *time; |
|
262 |
+ struct tm *gmt; |
|
263 | 263 |
|
264 |
- time = gmtime(&mtime); |
|
265 |
- return strftime(buf, 36, "%a, %d %b %Y %X GMT", time); |
|
264 |
+ gmt = gmtime(&mtime); |
|
265 |
+ return strftime(buf, 36, "%a, %d %b %Y %X GMT", gmt); |
|
266 | 266 |
} |
267 | 267 |
|
268 | 268 |
static unsigned int fmt_base64(char *dest, const char *src, unsigned int len) |
... | ... |
@@ -668,7 +668,7 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna |
668 | 668 |
close(fd); |
669 | 669 |
|
670 | 670 |
if(totalsize > 0) |
671 |
- logg("Downloading %s [%i%]\n", srcfile, percentage); |
|
671 |
+ logg("Downloading %s [%i%%]\n", srcfile, percentage); |
|
672 | 672 |
else |
673 | 673 |
logg("Downloading %s [*]\n", srcfile); |
674 | 674 |
|
... | ... |
@@ -842,12 +842,12 @@ static struct cl_cvd *currentdb(const char *dbname, unsigned int *inc) |
842 | 842 |
static int updatedb(const char *dbname, const char *hostname, char *ip, int *signo, const struct cfgstruct *copt, const char *dnsreply, char *localip, int outdated, struct mirdat *mdat) |
843 | 843 |
{ |
844 | 844 |
struct cl_cvd *current, *remote; |
845 |
- struct cfgstruct *cpt; |
|
845 |
+ const struct cfgstruct *cpt; |
|
846 | 846 |
unsigned int nodb = 0, currver = 0, newver = 0, port = 0, i, j; |
847 | 847 |
int ret, ims = -1; |
848 | 848 |
char *pt, dbfile[32], dbinc[32], *bacinc = NULL; |
849 | 849 |
const char *proxy = NULL, *user = NULL, *pass = NULL, *uas = NULL; |
850 |
- unsigned int flevel = cl_retflevel(), inc; |
|
850 |
+ unsigned int flevel = cl_retflevel(), inc, maxattempts; |
|
851 | 851 |
struct stat sb; |
852 | 852 |
int ctimeout, rtimeout; |
853 | 853 |
|
... | ... |
@@ -1015,8 +1015,9 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig |
1015 | 1015 |
} |
1016 | 1016 |
} |
1017 | 1017 |
|
1018 |
+ maxattempts = cfgopt(copt, "MaxAttempts")->numarg; |
|
1018 | 1019 |
for(i = currver + 1; i <= newver; i++) { |
1019 |
- for(j = 0; j < cfgopt(copt, "MaxAttempts")->numarg; j++) { |
|
1020 |
+ for(j = 0; j < maxattempts; j++) { |
|
1020 | 1021 |
ret = getpatch(dbname, i, hostname, ip, localip, proxy, port, user, pass, uas, ctimeout, rtimeout, mdat); |
1021 | 1022 |
if(ret == 52 || ret == 58) { |
1022 | 1023 |
memset(ip, 0, 16); |
... | ... |
@@ -1086,7 +1087,7 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c |
1086 | 1086 |
unsigned int ttl, try = 0; |
1087 | 1087 |
char ipaddr[16], *dnsreply = NULL, *pt, *localip = NULL, *newver = NULL; |
1088 | 1088 |
const char *arg = NULL; |
1089 |
- struct cfgstruct *cpt; |
|
1089 |
+ const struct cfgstruct *cpt; |
|
1090 | 1090 |
struct mirdat mdat; |
1091 | 1091 |
#ifdef HAVE_RESOLV_H |
1092 | 1092 |
const char *dnsdbinfo; |
... | ... |
@@ -37,8 +37,8 @@ |
37 | 37 |
#include <netdb.h> |
38 | 38 |
#endif |
39 | 39 |
#include <sys/types.h> |
40 |
-/*#include <sys/socket.h> /* in nonblock.h */ |
|
41 | 40 |
#ifndef C_WINDOWS |
41 |
+#include <sys/socket.h> |
|
42 | 42 |
#include <sys/time.h> |
43 | 43 |
#endif |
44 | 44 |
#include <time.h> |
... | ... |
@@ -87,7 +87,7 @@ |
87 | 87 |
static int connect_error(int sock) |
88 | 88 |
{ |
89 | 89 |
int optval; |
90 |
- int optlen; |
|
90 |
+ socklen_t optlen; |
|
91 | 91 |
|
92 | 92 |
optlen = sizeof(optval); |
93 | 93 |
getsockopt(sock, SOL_SOCKET, SO_ERROR, &optval, &optlen); |
... | ... |
@@ -58,9 +58,10 @@ int notify(const char *cfgfile) |
58 | 58 |
#endif |
59 | 59 |
struct sockaddr_in server2; |
60 | 60 |
struct hostent *he; |
61 |
- struct cfgstruct *copt, *cpt; |
|
61 |
+ struct cfgstruct *copt; |
|
62 |
+ const struct cfgstruct *cpt; |
|
62 | 63 |
int sockd, bread; |
63 |
- char *socktype; |
|
64 |
+ const char *socktype; |
|
64 | 65 |
|
65 | 66 |
|
66 | 67 |
if((copt = getcfg(cfgfile, 1)) == NULL) { |
... | ... |
@@ -77,6 +78,7 @@ int notify(const char *cfgfile) |
77 | 77 |
if((sockd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { |
78 | 78 |
logg("^Clamd was NOT notified: Can't create socket endpoint for %s\n", cpt->strarg); |
79 | 79 |
perror("socket()"); |
80 |
+ freecfg(copt); |
|
80 | 81 |
return 1; |
81 | 82 |
} |
82 | 83 |
|
... | ... |
@@ -84,6 +86,7 @@ int notify(const char *cfgfile) |
84 | 84 |
closesocket(sockd); |
85 | 85 |
logg("^Clamd was NOT notified: Can't connect to clamd through %s\n", cpt->strarg); |
86 | 86 |
perror("connect()"); |
87 |
+ freecfg(copt); |
|
87 | 88 |
return 1; |
88 | 89 |
} |
89 | 90 |
|
... | ... |
@@ -99,6 +102,7 @@ int notify(const char *cfgfile) |
99 | 99 |
#endif |
100 | 100 |
logg("^Clamd was NOT notified: Can't create TCP socket\n"); |
101 | 101 |
perror("socket()"); |
102 |
+ freecfg(copt); |
|
102 | 103 |
return 1; |
103 | 104 |
} |
104 | 105 |
|
... | ... |
@@ -109,6 +113,7 @@ int notify(const char *cfgfile) |
109 | 109 |
if ((he = gethostbyname(cpt->strarg)) == 0) { |
110 | 110 |
perror("gethostbyname()"); |
111 | 111 |
logg("^Clamd was NOT notified: Can't resolve hostname '%s'\n", cpt->strarg); |
112 |
+ freecfg(copt); |
|
112 | 113 |
return 1; |
113 | 114 |
} |
114 | 115 |
server2.sin_addr = *(struct in_addr *) he->h_addr_list[0]; |
... | ... |
@@ -121,11 +126,13 @@ int notify(const char *cfgfile) |
121 | 121 |
logg("^Clamd was NOT notified: Can't connect to clamd on %s:%d\n", |
122 | 122 |
inet_ntoa(server2.sin_addr), ntohs(server2.sin_port)); |
123 | 123 |
perror("connect()"); |
124 |
+ freecfg(copt); |
|
124 | 125 |
return 1; |
125 | 126 |
} |
126 | 127 |
|
127 | 128 |
} else { |
128 | 129 |
logg("^Clamd was NOT notified: No socket specified in %s\n", cfgfile); |
130 |
+ freecfg(copt); |
|
129 | 131 |
return 1; |
130 | 132 |
} |
131 | 133 |
|
... | ... |
@@ -133,6 +140,7 @@ int notify(const char *cfgfile) |
133 | 133 |
logg("^Clamd was NOT notified: Could not write to %s socket\n", socktype); |
134 | 134 |
perror("write()"); |
135 | 135 |
closesocket(sockd); |
136 |
+ freecfg(copt); |
|
136 | 137 |
return 1; |
137 | 138 |
} |
138 | 139 |
|
... | ... |
@@ -142,11 +150,13 @@ int notify(const char *cfgfile) |
142 | 142 |
if(!strstr(buff, "RELOADING")) { |
143 | 143 |
logg("^Clamd was NOT notified: Unknown answer from clamd: '%s'\n", buff); |
144 | 144 |
closesocket(sockd); |
145 |
+ freecfg(copt); |
|
145 | 146 |
return 1; |
146 | 147 |
} |
147 | 148 |
|
148 | 149 |
closesocket(sockd); |
149 | 150 |
logg("Clamd successfully notified about the update.\n"); |
151 |
+ freecfg(copt); |
|
150 | 152 |
return 0; |
151 | 153 |
} |
152 | 154 |
|