~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to clamav-milter/clamav-milter.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:
52
52
    const struct optstruct *opt;
53
53
    struct optstruct *opts;
54
54
    time_t currtime;
 
55
    mode_t umsk;
55
56
    int ret;
56
57
 
57
58
    memset(&descr, 0, sizeof(struct smfiDesc));
162
163
 
163
164
    if((opt = optget(opts, "LogFile"))->enabled) {
164
165
        logg_file = opt->strarg;
165
 
        if(strlen(logg_file) < 2 || logg_file[0] != '/') {
 
166
        if(!cli_is_abspath(logg_file)) {
166
167
            fprintf(stderr, "ERROR: LogFile requires full path.\n");
167
168
            logg_close();
168
169
            optfree(opts);
223
224
    if(strcasecmp(pt, "No")) {
224
225
        char myname[255];
225
226
 
226
 
        if(!gethostname(myname, sizeof(myname))) {
 
227
        if(((opt = optget(opts, "ReportHostname"))->enabled && strncpy(myname, opt->strarg, sizeof(myname))) || !gethostname(myname, sizeof(myname))) {
227
228
            myname[sizeof(myname)-1] = '\0';
228
229
            snprintf(xvirushdr, sizeof(xvirushdr), "clamav-milter %s at %s", get_version(), myname);
229
 
            xvirushdr[sizeof(xvirushdr)-1] = '\0';
230
 
        } else {
 
230
        } else
231
231
            snprintf(xvirushdr, sizeof(xvirushdr), "clamav-milter %s", get_version());
232
 
            xvirushdr[sizeof(xvirushdr)-1] = '\0';
233
 
        }
 
232
        xvirushdr[sizeof(xvirushdr)-1] = '\0';
234
233
 
235
234
        descr.xxfi_flags |= SMFIF_ADDHDRS;
236
235
 
282
281
        return 1;
283
282
    }
284
283
    opt = optget(opts, "FixStaleSocket");
 
284
    umsk = umask(0777); /* socket is created with 000 to avoid races */ 
285
285
    if(smfi_opensocket(opt->enabled) == MI_FAILURE) {
286
286
        logg("!Failed to create socket %s\n", my_socket);
287
287
        localnets_free();
290
290
        optfree(opts);
291
291
        return 1;
292
292
    }
 
293
    umask(umsk); /* restore umask */
 
294
    if(strncmp(my_socket, "inet:", 5) && strncmp(my_socket, "inet6:", 6)) {
 
295
        /* set group ownership and perms on the local socket */
 
296
        char *sock_name = my_socket;
 
297
        mode_t sock_mode;
 
298
        if(!strncmp(my_socket, "unix:", 5))
 
299
            sock_name += 5;
 
300
        if(!strncmp(my_socket, "local:", 6))
 
301
            sock_name += 6;
 
302
        if(*my_socket == ':')
 
303
            sock_name ++;
 
304
 
 
305
        if(optget(opts, "MilterSocketGroup")->enabled) {
 
306
            char *gname = optget(opts, "MilterSocketGroup")->strarg, *end;
 
307
            gid_t sock_gid = strtol(gname, &end, 10);
 
308
            if(*end) {
 
309
                struct group *pgrp = getgrnam(gname);
 
310
                if(!pgrp) {
 
311
                    logg("!Unknown group %s\n", gname);
 
312
                    localnets_free();
 
313
                    whitelist_free();
 
314
                    logg_close();
 
315
                    optfree(opts);
 
316
                    return 1;
 
317
                }
 
318
                sock_gid = pgrp->gr_gid;
 
319
            }
 
320
            if(chown(sock_name, -1, sock_gid)) {
 
321
                logg("!Failed to change socket ownership to group %s\n", gname);
 
322
                localnets_free();
 
323
                whitelist_free();
 
324
                logg_close();
 
325
                optfree(opts);
 
326
                return 1;
 
327
            }
 
328
        }
 
329
        if(optget(opts, "MilterSocketMode")->enabled) {
 
330
            char *end;
 
331
            sock_mode = strtol(optget(opts, "MilterSocketMode")->strarg, &end, 8);
 
332
            if(*end) {
 
333
                logg("!Invalid MilterSocketMode %s\n", optget(opts, "MilterSocketMode")->strarg);
 
334
                localnets_free();
 
335
                whitelist_free();
 
336
                logg_close();
 
337
                optfree(opts);
 
338
                return 1;
 
339
            }
 
340
        } else
 
341
            sock_mode = 0777 & ~umsk;
 
342
 
 
343
        if(chmod(sock_name, sock_mode & 0666)) {
 
344
            logg("!Cannot set milter socket permission to %s\n", optget(opts, "MilterSocketMode")->strarg);
 
345
            localnets_free();
 
346
            whitelist_free();
 
347
            logg_close();
 
348
            optfree(opts);
 
349
            return 1;
 
350
        }
 
351
    }
293
352
 
294
353
    maxfilesize = optget(opts, "MaxFileSize")->numarg;
295
354
    readtimeout = optget(opts, "ReadTimeout")->numarg;