~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to freshclam/freshclam.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16
16
 *  MA 02110-1301, USA.
17
17
 */
18
 
#ifdef  _MSC_VER
19
 
#include <winsock.h>
20
 
#endif
21
18
 
22
19
#if HAVE_CONFIG_H
23
20
#include "clamav-config.h"
33
30
#include <signal.h>
34
31
#include <time.h>
35
32
#include <sys/types.h>
36
 
#ifndef C_WINDOWS
 
33
#ifndef _WIN32
37
34
#include <sys/wait.h>
38
35
#endif
39
36
#include <sys/stat.h>
40
37
#include <fcntl.h>
41
 
#ifndef C_WINDOWS
 
38
#ifdef  HAVE_PWD_H
42
39
#include <pwd.h>
 
40
#endif
 
41
#ifdef HAVE_GRP_H
43
42
#include <grp.h>
44
43
#endif
45
44
 
131
130
    mprintf("\n");
132
131
    mprintf("    --config-file=FILE                   read configuration from FILE.\n");
133
132
    mprintf("    --log=FILE           -l FILE         log into FILE\n");
 
133
#ifndef _WIN32
134
134
    mprintf("    --daemon             -d              run in daemon mode\n");
135
135
    mprintf("    --pid=FILE           -p FILE         save daemon's pid in FILE\n");
136
136
    mprintf("    --user=USER          -u USER         run as USER\n");
 
137
#endif
137
138
    mprintf("    --no-dns                             force old non-DNS verification method\n");
138
139
    mprintf("    --checks=#n          -c #n           number of checks per day, 1 <= n <= 50\n");
139
140
    mprintf("    --datadir=DIRECTORY                  download new databases into DIRECTORY\n");
165
166
    } else {
166
167
        while(opt) {
167
168
            ret = downloadmanager(opts, opt->strarg, datadir, try == maxattempts - 1);
 
169
#ifndef _WIN32
168
170
            alarm(0);
169
 
 
 
171
#endif
170
172
            if(ret == 52 || ret == 54 || ret == 58 || ret == 59) {
171
173
                if(try < maxattempts - 1) {
172
174
                    logg("Trying again in 5 secs...\n");
198
200
        char *pt;
199
201
        struct optstruct *opts;
200
202
        const struct optstruct *opt;
201
 
#ifndef C_WINDOWS
 
203
#ifndef _WIN32
202
204
        struct sigaction sigact;
203
205
        struct sigaction oldact;
204
206
#endif
205
 
#if !defined(C_OS2) && !defined(C_WINDOWS)
 
207
#ifdef HAVE_PWD_H
206
208
        const char *dbowner;
207
209
        struct passwd *user;
208
210
#endif
212
214
 
213
215
    if((opts = optparse(NULL, argc, argv, 1, OPT_FRESHCLAM, 0, NULL)) == NULL) {
214
216
        mprintf("!Can't parse command line options\n");
215
 
        return 1;
 
217
        return 40;
216
218
    }
217
219
 
218
220
    if(optget(opts, "help")->enabled) {
227
229
    if((opts = optparse(cfgfile, 0, NULL, 1, OPT_FRESHCLAM, 0, opts)) == NULL) {
228
230
        fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", pt);
229
231
        free(pt);
230
 
        return 1;
 
232
        return 40;
231
233
    }
232
234
    free(pt);
233
235
 
239
241
        return 0;
240
242
    }
241
243
 
242
 
#ifdef C_WINDOWS
243
 
    if(!pthread_win32_process_attach_np()) {
244
 
        mprintf("!Can't start the win32 pthreads layer\n");
245
 
        optfree(opts);
246
 
        return 63;
247
 
    }
248
 
#endif
249
 
 
250
244
    if(optget(opts, "HTTPProxyPassword")->enabled) {
251
245
        if(stat(cfgfile, &statbuf) == -1) {
252
246
            logg("^Can't stat %s (critical error)\n", cfgfile);
254
248
            return 56;
255
249
        }
256
250
 
257
 
#ifndef C_WINDOWS
 
251
#ifndef _WIN32
258
252
        if(statbuf.st_mode & (S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) {
259
253
            logg("^Insecure permissions (for HTTPProxyPassword): %s must have no more than 0700 permissions.\n", cfgfile);
260
254
            optfree(opts);
263
257
#endif
264
258
    }
265
259
 
266
 
#if !defined(C_OS2) && !defined(C_WINDOWS)
 
260
#ifdef HAVE_PWD_H
267
261
    /* freshclam shouldn't work with root privileges */
268
262
    dbowner = optget(opts, "DatabaseOwner")->strarg;
269
263
 
304
298
            return 61;
305
299
        }
306
300
    }
307
 
#endif
 
301
#endif /* HAVE_PWD_H */
308
302
 
309
303
    /* initialize some important variables */
310
304
 
378
372
        return 0;
379
373
    }
380
374
 
381
 
#ifdef  C_WINDOWS
382
 
    {
383
 
            WSADATA wsaData;
384
 
 
385
 
        if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) {
386
 
            logg("!Error at WSAStartup(): %d\n", WSAGetLastError());
387
 
            optfree(opts);
388
 
            return 1;
389
 
        }
390
 
    }
391
 
#endif
392
 
 
393
375
    if(optget(opts, "daemon")->enabled) {
394
376
            int bigsleep, checks;
395
 
#ifndef C_WINDOWS
 
377
#ifndef _WIN32
396
378
            time_t now, wakeup;
397
379
 
398
380
        memset(&sigact, 0, sizeof(struct sigaction));
417
399
 
418
400
        bigsleep = 24 * 3600 / checks;
419
401
 
420
 
#if !defined(C_OS2) && !defined(C_WINDOWS)
 
402
#ifndef _WIN32
421
403
        if(!optget(opts, "Foreground")->enabled) {
422
404
            if(daemonize() == -1) {
423
405
                logg("!daemonize() failed\n");
438
420
 
439
421
        logg("#freshclam daemon %s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n", get_version());
440
422
 
441
 
#ifdef  C_WINDOWS
 
423
#ifdef _WIN32
442
424
        signal(SIGINT, daemon_sighandler);
443
425
        terminate = 0;
444
426
#else
472
454
            sigaction(SIGUSR1, &sigact, &oldact);
473
455
#endif
474
456
 
475
 
#ifdef  C_WINDOWS
 
457
#ifdef  _WIN32
476
458
            sleep(bigsleep);
477
459
#else   
478
460
            time(&wakeup);
525
507
 
526
508
    optfree(opts);
527
509
 
528
 
#ifdef C_WINDOWS
529
 
    WSACleanup();
530
 
 
531
 
    if(!pthread_win32_process_detach_np()) {
532
 
        mprintf("!Can't stop the win32 pthreads layer\n");
533
 
        return 63;
534
 
    }
535
 
#endif
536
 
 
537
510
    return(ret);
538
511
}