This file is indexed.

postinst is in clamav-daemon 0.99+dfsg-1ubuntu1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
#! /bin/sh
# postinst script for #PACKAGE#
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

#loading debconf module
. /usr/share/debconf/confmodule

to_lower()
{
  word="$1"
  lcword=$(echo "$word" | tr A-Z a-z)
  echo "$lcword"
}

is_true()
{
  var="$1"
  lcvar=$(to_lower "$var")
  [ 'true' = "$lcvar" ] || [ 'yes' = "$lcvar" ] || [ 1 = "$lcvar" ]
  return $?
}

is_false()
{
  var="$1"
  lcvar=$(to_lower "$var")
  [ 'false' = "$lcvar" ] || [ 'no' = "$lcvar" ] || [ 0 = "$lcvar" ]
  return $?
}

ucf_cleanup()
{
  # This only does something if I've fucked up before
  # Not entirely impossible :(

  configfile=$1

  if [ `grep "$configfile" /var/lib/ucf/hashfile | wc -l` -gt 1 ]; then
    grep -v "$configfile" /var/lib/ucf/hashfile > /var/lib/ucf/hashfile.tmp
    grep "$configfile" /var/lib/ucf/hashfile | tail -n 1  >> /var/lib/ucf/hashfile.tmp
    mv /var/lib/ucf/hashfile.tmp /var/lib/ucf/hashfile
  fi
}

add_to_ucf()
{
  configfile=$1
  ucffile=$2

  if ! grep -q "$configfile" /var/lib/ucf/hashfile; then
    md5sum $configfile >> /var/lib/ucf/hashfile
    cp $configfile $ucffile
  fi
}

ucf_upgrade_check()
{
  configfile=$1
  sourcefile=$2
  ucffile=$3

  if [ -f "$configfile" ]; then
    add_to_ucf $configfile $ucffile
    ucf --three-way --debconf-ok "$sourcefile" "$configfile"
  else
    [ -d /var/lib/ucf/cache ] || mkdir -p /var/lib/ucf/cache
    pathfind restorecon && restorecon /var/lib/ucf/cache
    cp $sourcefile $configfile
    add_to_ucf $configfile $ucffile
  fi
}

slurp_config()
{
  CLAMAVCONF="$1"
  
  if [ -e "$CLAMAVCONF" ]; then
    for variable in `egrep -a -v '^[[:space:]]*(#|$)' "$CLAMAVCONF" | awk '{print $1}'`; do
      case "$variable" in
        DatabaseMirror)
        if [ -z "$DatabaseMirror" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$value $i"
          done
        else
          continue
        fi
        ;;
        DatabaseCustomURL)
        if [ -z "$DatabaseCustomURL" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$value $i"
          done
        else
          continue
        fi
        ;;
        IncludePUA)
        if [ -z "$IncludePUA" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$i $value"
          done
        else
          continue
        fi
        ;;
        ExcludePUA)
        if [ -z "$ExcludePUA" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$i $value"
          done
        else
          continue
        fi
        ;;
        ExtraDatabase)
        if [ -z "$ExtraDatabase" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$value $i"
          done
        else
          continue
        fi
        ;;
        VirusEvent|OnUpdateExecute|OnErrorExecute|RejectMsg)
        value=`grep -a ^$variable $CLAMAVCONF | head -n1 | sed -e s/$variable\ //`
        ;;
        *)
        value=`grep -a "^$variable[[:space:]]" $CLAMAVCONF | head -n1 | awk '{print $2}'`
        ;;
      esac
      if [ -z "$value" ]; then 
        export "$variable"="true"
      elif [ "$value" != "$variable" ]; then
        export "$variable"="$value"
      else
        export "$variable"="true"
      fi
      unset value
    done
  fi
}

pathfind() {
  OLDIFS="$IFS"
  IFS=:
  for p in $PATH; do
    if [ -x "$p/$*" ]; then
      IFS="$OLDIFS"
      return 0
    fi
  done
  IFS="$OLDIFS"
  return 1
}

set_debconf_value()
{
prog=$1
name=$2
eval variable="\$${name}"
if [ -n "$variable" ]; then
  db_set clamav-$prog/$name "$variable" || true
fi
}

make_dir()
{
  DIR=$1
  if [ -d "$DIR" ]; then
    return 0;
  fi
  [ -n "$User" ] || User=clamav
  mkdir -p -m 0755 "$DIR"
  chown "$User" "$DIR"
  pathfind restorecon && restorecon "$DIR"
}

# Debconf Functions

isdigit ()
{
  case $1 in
    [[:digit:]]*)
    ISDIGIT=1
    ;;
    *)
    ISDIGIT=0
    ;;
  esac
}

inputdigit ()
{
  ISDIGIT=0
  while [ "$ISDIGIT" = '0' ]; do
    db_input "$1" "$2" || true
    if ! db_go; then
      return 30
    fi
    db_get $2 || true
    isdigit $RET
    if [ "$ISDIGIT" = '0' ]; then
      db_input critical clamav-base/numinfo || true
      db_go
    fi
  done
  return 0
}

StateGeneric()
{
  PRIO=$1
  QUESTION=$2
  NEXT=$3
  LAST=$4

  db_input $PRIO $QUESTION || true
  if db_go; then
    STATE=$NEXT
  else
    STATE=$LAST
  fi
}

StateGenericDigit()
{
  PRIO=$1
  QUESTION=$2
  NEXT=$3
  LAST=$4

  inputdigit $PRIO $QUESTION || true
  if db_go; then
    STATE=$NEXT
  else
    STATE=$LAST
  fi
}


case "$1" in
  configure)

  # The DEB*FILE files are used temporarily during the update of the CLAMAV* files.
  DEBCONFFILE=/var/lib/clamav/clamav.conf
  CLAMAVCONF=/etc/clamav/clamd.conf
  DEBROTATEFILE=/var/lib/clamav/clamdrotate.debconf
  CLAMAVROTATEFILE=/etc/logrotate.d/clamav-daemon
  DEBSYSTEMDLISTENCONF=/var/lib/clamav/extend.conf
  CLAMAVSYSTEMDLISTENCONF=/etc/systemd/system/clamav-daemon.socket.d/extend.conf

  # Update the configuration file
  db_get clamav-daemon/debconf || true
  if [ "$RET" = "true" ]; then
    # Handle the configuration via debconf

    # Read the configuration file
    slurp_config "$CLAMAVCONF"

    # Get the debconf configuration
    db_get clamav-daemon/User || true
    User="$RET"
    db_get clamav-daemon/AddGroups || true
    AddGroups="$RET"
    db_get clamav-daemon/TcpOrLocal || true
    if [ "$RET" = "TCP" ]; then
      sock="tcp"
      db_get clamav-daemon/TCPSocket || true
      TCPSocket="$RET"
      db_get clamav-daemon/TCPAddr
      TCPAddr="$RET"
    else
      sock="unix"
      db_get clamav-daemon/LocalSocket || true
      LocalSocket="$RET"
      db_get clamav-daemon/FixStaleSocket || true
      FixStaleSocket="$RET"
      db_get clamav-daemon/LocalSocketGroup || true
      LocalSocketGroup="$RET"
      db_get clamav-daemon/LocalSocketMode || true
      LocalSocketMode="$RET"
    fi
    db_get clamav-daemon/ScanMail || true
    ScanMail="$RET"
    db_get clamav-daemon/ScanArchive || true
    ScanArchive="$RET"
    db_get clamav-daemon/MaxDirectoryRecursion || true
    if [ "$RET" != "0" ]; then
      MaxDirectoryRecursion="$RET"
      db_get clamav-daemon/FollowDirectorySymlinks || true
      FollowDirectorySymlinks="$RET"
    else
      MaxDirectoryRecursion=15
      FollowDirectorySymlinks=false
    fi
    db_get clamav-daemon/FollowFileSymlinks || true
    FollowFileSymlinks="$RET"
    db_get clamav-daemon/ThreadTimeout || true
    ThreadTimeout="$RET"
    db_get clamav-daemon/ReadTimeout || true
    ReadTimeout="$RET"
    [ -z "$ReadTimeout" ] && ReadTimeout="$ThreadTimeout"
    db_get clamav-daemon/MaxThreads || true
    MaxThreads="$RET"
    db_get clamav-daemon/MaxConnectionQueueLength || true
    MaxConnectionQueueLength="$RET"
    db_get clamav-daemon/StreamMaxLength || true
    StreamMaxLength="$RET"
    db_get clamav-daemon/LogSyslog || true
    LogSyslog="$RET"
    db_get clamav-daemon/LogFile || true
    if [ "$RET" != "" ]; then
      LogFile="$RET"
      db_get clamav-daemon/LogTime || true
      LogTime="$RET"
    fi
    db_get clamav-daemon/LogRotate || true
    LogRotate="$RET"
    db_get clamav-daemon/SelfCheck || true
    SelfCheck="$RET"
    db_get clamav-daemon/StatsEnabled || true
    StatsEnabled="$RET"
    db_get clamav-daemon/StatsPEDisabled || true
    StatsPEDisabled="$RET"
    db_get clamav-daemon/StatsHostID || true
    StatsHostID="$RET"
    db_get clamav-daemon/StatsTimeout || true
    StatsTimeout="$RET"
    db_get clamav-daemon/Bytecode || true
    Bytecode="$RET"
    if [ "$Bytecode" = "true" ]; then
      db_get clamav-daemon/BytecodeSecurity || true
      BytecodeSecurity="$RET"
      db_get clamav-daemon/BytecodeTimeout || true
      BytecodeTimeout="$RET"
    fi
    db_get clamav-daemon/ScanOnAccess || true
    ScanOnAccess="$RET"
    if [ "$ScanOnAccess" = "true" ]; then
      db_get clamav-daemon/OnAccessMaxFileSize || true
      OnAccessMaxFileSize="$RET"
    fi
    db_get clamav-daemon/AllowAllMatchScan || true
    AllowAllMatchScan="$RET"
    db_get clamav-daemon/ForceToDisk || true
    ForceToDisk="$RET"
    db_get clamav-daemon/DisableCertCheck || true
    DisableCertCheck="$RET"
    db_get clamav-daemon/ScanSWF || true
    ScanSWF="$RET"
    db_get clamav-daemon/MaxEmbeddedPE || true
    MaxEmbeddedPE="$RET"
    db_get clamav-daemon/MaxHTMLNormalize || true
    MaxHTMLNormalize="$RET"
    db_get clamav-daemon/MaxHTMLNoTags || true
    MaxHTMLNoTags="$RET"
    db_get clamav-daemon/MaxScriptNormalize || true
    MaxScriptNormalize="$RET"
    db_get clamav-daemon/MaxZipTypeRcg || true
    MaxZipTypeRcg="$RET"

    # Test for the broken versions, see #741675.
    if [ "$2" = "0.98.1+dfsg-3" ] || [ "$2" = "0.98.1+dfsg-1+deb7u2" ] || [ "$2" = "0.98.1+dfsg-1+deb6u2" ]; then
      # Use the defaults instead of the bogus values created by that versions.
      db_metaget clamav-daemon/LogRotate default || true
      LogRotate="$RET"
      db_metaget clamav-daemon/ScanOnAccess default || true
      ScanOnAccess="$RET"
      OnAccessMaxFileSize=""
      OnAccessIncludePath=""
      OnAccessExcludePath=""
      OnAccessExcludeUID=""
      db_metaget clamav-daemon/AllowAllMatchScan default || true
      AllowAllMatchScan="$RET"
      db_metaget clamav-daemon/ForceToDisk default || true
      ForceToDisk="$RET"
      db_metaget clamav-daemon/DisableCertCheck default || true
      DisableCertCheck="$RET"
      db_metaget clamav-daemon/ScanSWF default || true
      ScanSWF="$RET"
      db_metaget clamav-daemon/MaxEmbeddedPE default || true
      MaxEmbeddedPE="$RET"
      db_metaget clamav-daemon/MaxHTMLNormalize default || true
      MaxHTMLNormalize="$RET"
      db_metaget clamav-daemon/MaxHTMLNoTags default || true
      MaxHTMLNoTags="$RET"
      db_metaget clamav-daemon/MaxScriptNormalize default || true
      MaxScriptNormalize="$RET"
      db_metaget clamav-daemon/MaxZipTypeRcg default || true
      MaxZipTypeRcg="$RET"
    fi

    # Set default values for options not configured via debconf
    [ -z "$LogFileUnlock" ] && LogFileUnlock=false
    [ -z "$LogFileMaxSize" ] && LogFileMaxSize=0
    [ -z "$LogClean" ] && LogClean=false
    [ -z "$LogFacility" ] && LogFacility=LOG_LOCAL6
    [ -z "$LogVerbose" ] && LogVerbose=false
    [ -z "$ExtendedDetectionInfo" ] && ExtendedDetectionInfo=true
    [ -z "$DatabaseDirectory" ] && DatabaseDirectory='/var/lib/clamav'
    [ -z "$OfficialDatabaseOnly" ] && OfficialDatabaseOnly=false
    [ -z "$CommandReadTimeout" ] && CommandReadTimeout=5
    [ -z "$SendBufTimeout" ] && SendBufTimeout=200
    [ -z "$MaxQueue" ] && MaxQueue=100
    [ -z "$IdleTimeout" ] && IdleTimeout=30
    [ -z "$CrossFilesystems" ] && CrossFilesystems=true
    if [ -n "$AddGroups" ]; then 
      AllowSupplementaryGroups=true
    else
      AllowSupplementaryGroups=false
    fi
    [ -z "$ExitOnOOM" ] && ExitOnOOM=false
    [ -z "$Foreground" ] && Foreground=false
    [ -z "$Debug" ] && Debug=false
    [ -z "$LeaveTemporaryFiles" ] && LeaveTemporaryFiles=false
    [ -z "$DetectPUA" ] && DetectPUA=false
    [ -z "$AlgorithmicDetection" ] && AlgorithmicDetection=true
    [ -z "$DisableCache" ] && DisableCache=false
    [ -z "$ScanPE" ] && ScanPE=true
    [ -z "$ScanELF" ] && ScanELF=true
    [ -z "$DetectBrokenExecutables" ] && DetectBrokenExecutables=false
    [ -z "$ScanOLE2" ] && ScanOLE2=true
    [ -z "$OLE2BlockMacros" ] && OLE2BlockMacros=false
    [ -z "$ScanPDF" ] && ScanPDF=true
    [ -z "$ScanPartialMessages" ] && ScanPartialMessages=false
    [ -z "$PhishingSignatures" ] && PhishingSignatures=true
    [ -z "$PhishingScanURLs" ] && PhishingScanURLs=true
    [ -z "$PhishingAlwaysBlockSSLMismatch" ] && PhishingAlwaysBlockSSLMismatch=false
    [ -z "$PhishingAlwaysBlockCloak" ] && PhishingAlwaysBlockCloak=false
    [ -z "$PartitionIntersection" ] && PartitionIntersection=false
    [ -z "$HeuristicScanPrecedence" ] && HeuristicScanPrecedence=false
    [ -z "$StructuredDataDetection" ] && StructuredDataDetection=false
    [ -z "$ScanHTML" ] && ScanHTML=true
    [ -z "$ArchiveBlockEncrypted" ] && ArchiveBlockEncrypted=false
    [ -z "$MaxScanSize" ] && MaxScanSize=100M
    [ -z "$MaxFileSize" ] && MaxFileSize=25M
    [ -z "$MaxRecursion" ] && MaxRecursion=16
    [ -z "$MaxFiles" ] && MaxFiles=10000
    [ -z "$MaxPartitions" ] && MaxPartitions=50
    [ -z "$MaxIconsPE" ] && MaxIconsPE=100
    [ -z "$PCREMatchLimit" ] && PCREMatchLimit=10000
    [ -z "$PCRERecMatchLimit" ] && PCRERecMatchLimit=5000
    [ -z "$PCREMaxFileSize" ] && PCREMaxFileSize=25M

    if `dpkg --compare-versions "$2" lt 0.98.7+dfsg-2~`; then
      # Update the MaxRecursion variable, if it is the previous default value.
      if [ "$MaxRecursion" = "10" ]; then
        MaxRecursion=16
      fi
    fi

    # Create the new configuration file
    echo "#Automatically Generated by clamav-daemon postinst" > $DEBCONFFILE
    echo "#To reconfigure clamd run #dpkg-reconfigure clamav-daemon" >> $DEBCONFFILE
    echo "#Please read /usr/share/doc/clamav-daemon/README.Debian.gz for details" >> $DEBCONFFILE
    echo "[Socket]" > "$DEBSYSTEMDLISTENCONF"
    echo "ListenStream=" >> "$DEBSYSTEMDLISTENCONF"
    echo "SocketUser=$User" >> "$DEBSYSTEMDLISTENCONF"
    if [ "$sock" = "tcp" ]; then
      echo "TCPSocket $TCPSocket" >> $DEBCONFFILE
      if [ "$TCPAddr" = "any" ]; then
        echo "ListenStream=$TCPSocket" >> "$DEBSYSTEMDLISTENCONF"
      else
        echo "TCPAddr $TCPAddr" >> $DEBCONFFILE
        echo "ListenStream=$TCPAddr:$TCPSocket" >> "$DEBSYSTEMDLISTENCONF"
      fi
    else
      echo "LocalSocket $LocalSocket" >> $DEBCONFFILE
      echo "ListenStream=$LocalSocket" >> "$DEBSYSTEMDLISTENCONF"
      echo "FixStaleSocket $FixStaleSocket" >> $DEBCONFFILE
      echo "LocalSocketGroup $LocalSocketGroup" >> $DEBCONFFILE
      echo "SocketGroup=$LocalSocketGroup" >> "$DEBSYSTEMDLISTENCONF"
      echo "LocalSocketMode $LocalSocketMode" >> $DEBCONFFILE
      echo "SocketMode=$LocalSocketMode" >> "$DEBSYSTEMDLISTENCONF"
    fi
    # Finish the configuration file update, by applying changes to the real configuration file.
    mkdir -p `dirname $CLAMAVSYSTEMDLISTENCONF` 2>/dev/null || true
    ucf_cleanup "$CLAMAVSYSTEMDLISTENCONF"
    ucf_upgrade_check "$CLAMAVSYSTEMDLISTENCONF" "$DEBSYSTEMDLISTENCONF" /var/lib/ucf/cache/:etc:systemd:system:clamav-daemon.socket.d:extend.conf
    rm -f "$DEBSYSTEMDLISTENCONF"
    if [ -e "$CLAMAVSYSTEMDLISTENCONF".dpkg-old ]; then
      echo "Removing old systemd socket override options for clamav-daemon"
      rm -f "$CLAMAVSYSTEMDLISTENCONF".dpkg-old
    fi

    if [ -n "$TemporaryDirectory" ]; then
	cat >> $DEBCONFFILE << EOF
TemporaryDirectory $TemporaryDirectory
EOF
    else
	cat >> $DEBCONFFILE << EOF
# TemporaryDirectory is not set to its default /tmp here to make overriding
# the default with environment variables TMPDIR/TMP/TEMP possible
EOF
    fi

    cat >> $DEBCONFFILE << EOF
User $User
AllowSupplementaryGroups $AllowSupplementaryGroups
ScanMail $ScanMail
ScanArchive $ScanArchive
ArchiveBlockEncrypted $ArchiveBlockEncrypted
MaxDirectoryRecursion $MaxDirectoryRecursion
FollowDirectorySymlinks $FollowDirectorySymlinks
FollowFileSymlinks $FollowFileSymlinks
ReadTimeout $ReadTimeout
MaxThreads $MaxThreads
MaxConnectionQueueLength $MaxConnectionQueueLength
LogSyslog $LogSyslog
LogRotate $LogRotate
LogFacility $LogFacility
LogClean $LogClean
LogVerbose $LogVerbose
DatabaseDirectory $DatabaseDirectory
OfficialDatabaseOnly $OfficialDatabaseOnly
SelfCheck $SelfCheck
Foreground $Foreground
Debug $Debug
ScanPE $ScanPE
MaxEmbeddedPE $MaxEmbeddedPE
ScanOLE2 $ScanOLE2
ScanPDF $ScanPDF
ScanHTML $ScanHTML
MaxHTMLNormalize $MaxHTMLNormalize
MaxHTMLNoTags $MaxHTMLNoTags
MaxScriptNormalize $MaxScriptNormalize
MaxZipTypeRcg $MaxZipTypeRcg
ScanSWF $ScanSWF
DetectBrokenExecutables $DetectBrokenExecutables
ExitOnOOM $ExitOnOOM
LeaveTemporaryFiles $LeaveTemporaryFiles
AlgorithmicDetection $AlgorithmicDetection
ScanELF $ScanELF
IdleTimeout $IdleTimeout
CrossFilesystems $CrossFilesystems
PhishingSignatures $PhishingSignatures
PhishingScanURLs $PhishingScanURLs
PhishingAlwaysBlockSSLMismatch $PhishingAlwaysBlockSSLMismatch
PhishingAlwaysBlockCloak $PhishingAlwaysBlockCloak
PartitionIntersection $PartitionIntersection
DetectPUA $DetectPUA
ScanPartialMessages $ScanPartialMessages
HeuristicScanPrecedence $HeuristicScanPrecedence
StructuredDataDetection $StructuredDataDetection
CommandReadTimeout $CommandReadTimeout
SendBufTimeout $SendBufTimeout
MaxQueue $MaxQueue
ExtendedDetectionInfo $ExtendedDetectionInfo
OLE2BlockMacros $OLE2BlockMacros
ScanOnAccess $ScanOnAccess
AllowAllMatchScan $AllowAllMatchScan
ForceToDisk $ForceToDisk
DisableCertCheck $DisableCertCheck
DisableCache $DisableCache
MaxScanSize $MaxScanSize
MaxFileSize $MaxFileSize
MaxRecursion $MaxRecursion
MaxFiles $MaxFiles
MaxPartitions $MaxPartitions
MaxIconsPE $MaxIconsPE
PCREMatchLimit $PCREMatchLimit
PCRERecMatchLimit $PCRERecMatchLimit
PCREMaxFileSize $PCREMaxFileSize
StatsEnabled $StatsEnabled
StatsPEDisabled $StatsPEDisabled
StatsHostID $StatsHostID
StatsTimeout $StatsTimeout
EOF

    if is_true "$StructuredDataDetection"; then
      [ -z "$StructuredMinCreditCardCount" ] || StructuredMinCreditCardCount=3
      [ -z "$StructuredMinSSNCount" ] || StructuredMinSSNCount=3
      [ -z "$StructuredSSNFormatNormal" ] || StructuredSSNFormatNormal=true
      [ -z "$StructuredSSNFormatStripped" ] || StructuredSSNFormatStripped=false
      cat >> $DEBCONFFILE << EOF
StructuredMinCreditCardCount $StructuredMinCreditCardCount
StructuredMinSSNCount $StructuredMinSSNCount
StructuredSSNFormatNormal $StructuredSSNFormatNormal
StructuredSSNFormatStripped $StructuredSSNFormatStripped
EOF
    fi

    if [ -n "$StreamMaxLength" ]; then
      if [ "$StreamMaxLength" -gt 0 ] ;then
        StreamMaxLength="${StreamMaxLength}M"
      fi
      echo "StreamMaxLength $StreamMaxLength" >> $DEBCONFFILE
    fi
    if [ -n "$IncludePUA" ]; then
      for i in $IncludePUA; do
        echo "IncludePUA $i" >> $DEBCONFFILE
      done
    fi
    if [ -n "$ExcludePUA" ]; then
      for e in $ExcludePUA; do
        echo "ExcludePUA $i" >> $DEBCONFFILE
      done
    fi
    if [ -n "$LogFile" ]; then
      echo "LogFile $LogFile" >> $DEBCONFFILE
      echo "LogTime $LogTime" >> $DEBCONFFILE
      echo "LogFileUnlock $LogFileUnlock" >> $DEBCONFFILE
      echo "LogFileMaxSize $LogFileMaxSize" >> $DEBCONFFILE
    fi

    echo "Bytecode $Bytecode" >> $DEBCONFFILE
    if is_true "$Bytecode"; then
      echo "BytecodeSecurity $BytecodeSecurity" >> $DEBCONFFILE
      echo "BytecodeTimeout $BytecodeTimeout" >> $DEBCONFFILE
    fi
    if `dpkg --compare-versions "$2" lt 0.98.7+dfsg-2~`; then
      # Remove the PidFile variable from the configuration, if it is the previous default value.
      if [ "$PidFile" = "/var/run/clamav/clamd.pid" ]; then
        PidFile=''
      fi
    fi
    # Preserve manually created, usually not needed options.
    [ -n "$PidFile" ] && echo "PidFile $PidFile" >> $DEBCONFFILE
    [ -n "$ExcludePath" ] && echo "ExcludePath $ExcludePath" >> $DEBCONFFILE
    [ -n "$VirusEvent" ] && echo "VirusEvent $VirusEvent" >> $DEBCONFFILE
    [ -n "$StreamMinPort" ] && echo "StreamMinPort $StreamMinPort" >> $DEBCONFFILE
    [ -n "$StreamMaxPort" ] && echo "StreamMaxPort $StreamMaxPort" >> $DEBCONFFILE
    [ -n "$OnAccessMaxFileSize" ] && echo "OnAccessMaxFileSize $OnAccessMaxFileSize" >> $DEBCONFFILE
    [ -n "$OnAccessIncludePath" ] && echo "OnAccessIncludePath $OnAccessIncludePath" >> $DEBCONFFILE
    [ -n "$OnAccessExcludePath" ] && echo "OnAccessExcludePath $OnAccessExcludePath" >> $DEBCONFFILE
    [ -n "$OnAccessExcludeUID" ] && echo "OnAccessExcludeUID $OnAccessExcludeUID" >> $DEBCONFFILE
    [ -n "$OnAccessMountPath" ] && echo "OnAccessMountPath $OnAccessMountPath" >> $DEBCONFFILE
    [ -n "$OnAccessDisableDDD" ] && echo "OnAccessDisableDDD $OnAccessDisableDDD" >> $DEBCONFFILE
    [ -n "$OnAccessPrevention" ] && echo "OnAccessPrevention $OnAccessPrevention" >> $DEBCONFFILE
    [ -n "$OnAccessExtraScanning" ] && echo "OnAccessExtraScanning $OnAccessExtraScanning" >> $DEBCONFFILE

    # Preserve old, deprecated options.
    [ -n "$ClamukoScanOnAccess" ] && echo "ClamukoScanOnAccess $ClamukoScanOnAccess" >> $DEBCONFFILE
    [ -n "$ClamukoScanOnOpen" ] && echo "ClamukoScanOnOpen $ClamukoScanOnOpen" >> $DEBCONFFILE
    [ -n "$ClamukoScanOnClose" ] && echo "ClamukoScanOnClose $ClamukoScanOnClose" >> $DEBCONFFILE
    [ -n "$ClamukoScanOnExec" ] && echo "ClamukoScanOnExec $ClamukoScanOnExec" >> $DEBCONFFILE
    [ -n "$ClamukoIncludePath" ] && echo "ClamukoIncludePath $ClamukoIncludePath" >> $DEBCONFFILE
    [ -n "$ClamukoIncludePath" ] && echo "ClamukoIncludePath $ClamukoIncludePath" >> $DEBCONFFILE
    [ -n "$ClamukoExcludePath" ] && echo "ClamukoExcludePath $ClamukoExcludePath" >> $DEBCONFFILE
    [ -n "$ClamukoMaxFileSize" ] && echo "ClamukoMaxFileSize $ClamukoMaxFileSize" >> $DEBCONFFILE
    [ -n "$ClamukoScannerCount" ] && echo "ClamukoScannerCount $ClamukoScannerCount" >> $DEBCONFFILE
    [ -n "$ClamukoExcludeUID" ] && echo "ClamukoExcludeUID $ClamukoExcludeUID" >> $DEBCONFFILE

    # Finish the configuration file update, by applying changes to the real configuration file.
    ucf_cleanup "$CLAMAVCONF"
    ucf_upgrade_check "$CLAMAVCONF" "$DEBCONFFILE" /var/lib/ucf/cache/:etc:clamav:clamd.conf
    rm -f "$DEBCONFFILE"

    # Add additional groups (if any)
    if [ -n "$AddGroups" ]; then
      for group in $AddGroups; do
        id "$User" | grep -q "$group" || adduser "$User" "$group"
      done
    fi

  else
    # Let the configuration be handled manually.
    ucf_cleanup "$CLAMAVCONF"
    ucf_upgrade_check "$CLAMAVCONF" /usr/share/doc/clamav-daemon/examples/clamd.conf.sample /var/lib/ucf/cache/:etc:clamav:clamd.conf
    if [ -e "$CLAMAVSYSTEMDLISTENCONF" ]; then
      echo "Disabling old systemd socket override options for clamav-daemon"
      mv "$CLAMAVSYSTEMDLISTENCONF" "$CLAMAVSYSTEMDLISTENCONF".dpkg-old
      ucf -p "$CLAMAVSYSTEMDLISTENCONF"
    fi
  fi

  # Set permission for the configuration file.
  chmod 644 $CLAMAVCONF || true
  chown root:root $CLAMAVCONF || true

  # Read the configuration file
  slurp_config "$CLAMAVCONF"

  if [ -n "$LogFile" ]; then
    if echo "$LogFile" | grep -q '^/dev/'; then
      make_logrotate=false
    else
      if [ "$LogRotate" = "true" ]; then
        make_logrotate=true
      else
        make_logrotate=false
      fi
    fi
    [ -z "$User" ] && User=clamav
    if [ "$make_logrotate" = 'true' ]; then
      # update the logrotate file
      echo "$LogFile {" > $DEBROTATEFILE
      echo "     rotate 12" >> $DEBROTATEFILE
      echo "     weekly" >> $DEBROTATEFILE
      echo "     compress" >> $DEBROTATEFILE
      echo "     delaycompress" >> $DEBROTATEFILE
      echo "     create 640  $User adm" >> $DEBROTATEFILE
      echo "     postrotate" >> $DEBROTATEFILE
      echo "     if [ -d /run/systemd/system ]; then" >> $DEBROTATEFILE
      echo "         systemctl -q is-active clamav-daemon && systemctl kill --signal=SIGHUP clamav-daemon || true" >> $DEBROTATEFILE
      echo "     else" >> $DEBROTATEFILE
      echo "         /etc/init.d/clamav-daemon reload-log > /dev/null || true" >> $DEBROTATEFILE
      echo "     fi" >> $DEBROTATEFILE
      echo "     endscript" >> $DEBROTATEFILE
      echo "     }" >> $DEBROTATEFILE
      touch "$LogFile"
      if [ -f "$LogFile" ] && [ ! -L "$LogFile" ]; then
        chown "$User":adm "$LogFile"
        chmod 0640 "$LogFile"
      fi
      ucf_cleanup "$CLAMAVROTATEFILE"
      ucf_upgrade_check "$CLAMAVROTATEFILE" "$DEBROTATEFILE" /var/lib/ucf/cache/:etc:logrotate.d:clamav-daemon
      rm -f $DEBROTATEFILE
      if [ -e "$CLAMAVROTATEFILE".dpkg-old ]; then
        echo "Removing old logrotate script for clamav-daemon"
        rm -f "$CLAMAVROTATEFILE".dpkg-old
      fi
    else
      if [ -e "$CLAMAVROTATEFILE" ]; then
        echo "Disabling old logrotate script for clamav-daemon"
        mv "$CLAMAVROTATEFILE" "$CLAMAVROTATEFILE".dpkg-old
        ucf -p "$CLAMAVROTATEFILE"
      fi
    fi
  else
    if [ -e "$CLAMAVROTATEFILE" ]; then
      echo "Disabling old logrotate script for clamav-daemon"
      mv "$CLAMAVROTATEFILE" "$CLAMAVROTATEFILE".dpkg-old
      ucf -p "$CLAMAVROTATEFILE"
    fi
  fi

  db_stop || true

  ;;
  abort-upgrade|abort-remove|abort-deconfigure)
  ;;
  *)
  echo "postinst called with unknown argument \`$1'" >&2
  exit 1
  ;;
esac

# AppArmor integration
if [ "$1" = "configure" ]; then
    APP_PROFILE=/etc/apparmor.d/usr.sbin.clamd
    if [ -f "$APP_PROFILE" ]; then
        # Add the local/ include
        LOCAL_APP_PROFILE=/etc/apparmor.d/local/usr.sbin.clamd

        test -e "$LOCAL_APP_PROFILE" || {
            tmp=`mktemp`
        cat <<EOM > "$tmp"
# Site-specific additions and overrides for usr.sbin.clamd.
# For more details, please see /etc/apparmor.d/local/README.
EOM
            mkdir `dirname $LOCAL_APP_PROFILE` 2>/dev/null || true
            mv -f "$tmp" "$LOCAL_APP_PROFILE"
            chmod 644 "$LOCAL_APP_PROFILE"
        }

        # Reload the profile, including any abstraction updates
        if aa-status --enabled 2>/dev/null; then
            apparmor_parser -r -T -W "$APP_PROFILE" || true
        fi
    fi
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask clamav-daemon.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled clamav-daemon.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable clamav-daemon.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state clamav-daemon.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask clamav-daemon.socket >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled clamav-daemon.socket; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable clamav-daemon.socket >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state clamav-daemon.socket >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/clamav-daemon" ]; then
		update-rc.d clamav-daemon defaults >/dev/null
	fi
	if [ -x "/etc/init.d/clamav-daemon" ] || [ -e "/etc/init/clamav-daemon.conf" ]; then
		invoke-rc.d clamav-daemon start || exit $?
	fi
fi
# End automatically added section


exit 0