You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/sbin/clamd
  7. CLAMD_CONFIGFILE="/tmp/clamav/clamd.conf"
  8. validate_clamav_section() {
  9. uci_load_validate clamav clamav "$1" "$2" \
  10. 'clamd_config_file:string' \
  11. 'LogFile:string' \
  12. 'LogFileMaxSize:string' \
  13. 'LogVerbose:string' \
  14. 'ExtendedDetectionInfo:string' \
  15. 'LogTime:string' \
  16. 'OfficialDatabaseOnly:string' \
  17. 'StreamMinPort:uinteger' \
  18. 'StreamMaxPort:uinteger' \
  19. 'MaxThreads:uinteger' \
  20. 'ReadTimeout:uinteger' \
  21. 'CommandReadTimeout:uinteger' \
  22. 'MaxDirectoryRecursion:uinteger' \
  23. 'FollowDirectorySymlinks:string' \
  24. 'FollowFileSymlinks:string' \
  25. 'SelfCheck:uinteger' \
  26. 'DetectPUA:string' \
  27. 'ScanPE:string' \
  28. 'DisableCertCheck:string' \
  29. 'ScanELF:string' \
  30. 'DetectBrokenExecutables:string' \
  31. 'ScanOLE2:string' \
  32. 'ScanPDF:string' \
  33. 'ScanSWF:string' \
  34. 'ScanMail:string' \
  35. 'ScanPartialMessages:string' \
  36. 'ScanArchive:string' \
  37. 'TemporaryDirectory:string' \
  38. 'ArchiveBlockEncrypted:string' \
  39. 'MaxFileSize:string' \
  40. 'LocalSocket:string' \
  41. 'User:string' \
  42. 'ExitOnOOM:string' \
  43. 'DatabaseDirectory:string'
  44. }
  45. start_clamav_instance() {
  46. [ "$2" = 0 ] || {
  47. echo "validation failed"
  48. return 1
  49. }
  50. mkdir -p $DatabaseDirectory
  51. mkdir -p /etc/clamav/
  52. mkdir -p /var/run/clamav/
  53. chmod a+rw /var/run/clamav
  54. mkdir -p $(dirname $CLAMD_CONFIGFILE)
  55. ln -sf $clamd_config_file $CLAMD_CONFIGFILE
  56. echo "LogFile " $LogFile > $CLAMD_CONFIGFILE
  57. echo "LogFileMaxSize " $LogFileMaxSize >> $CLAMD_CONFIGFILE
  58. echo "LogVerbose " $LogVerbose >> $CLAMD_CONFIGFILE
  59. echo "ExtendedDetectionInfo " $ExtendedDetectionInfo >> $CLAMD_CONFIGFILE
  60. echo "LogTime " $LogTime >> $CLAMD_CONFIGFILE
  61. echo "OfficialDatabaseOnly " $OfficialDatabaseOnly >> $CLAMD_CONFIGFILE
  62. echo "StreamMinPort " $StreamMinPort >> $CLAMD_CONFIGFILE
  63. echo "StreamMaxPort " $StreamMaxPort >> $CLAMD_CONFIGFILE
  64. echo "MaxThreads " $MaxThreads >> $CLAMD_CONFIGFILE
  65. echo "ReadTimeout " $ReadTimeout >> $CLAMD_CONFIGFILE
  66. echo "CommandReadTimeout " $CommandReadTimeout >> $CLAMD_CONFIGFILE
  67. echo "MaxDirectoryRecursion " $MaxDirectoryRecursion >> $CLAMD_CONFIGFILE
  68. echo "FollowDirectorySymlinks " $FollowDirectorySymlinks >> $CLAMD_CONFIGFILE
  69. echo "FollowFileSymlinks " $FollowFileSymlinks >> $CLAMD_CONFIGFILE
  70. echo "SelfCheck " $SelfCheck >> $CLAMD_CONFIGFILE
  71. echo "DetectPUA " $DetectPUA >> $CLAMD_CONFIGFILE
  72. echo "ScanPE " $ScanPE >> $CLAMD_CONFIGFILE
  73. echo "DisableCertCheck " $DisableCertCheck >> $CLAMD_CONFIGFILE
  74. echo "ScanELF " $ScanELF >> $CLAMD_CONFIGFILE
  75. echo "DetectBrokenExecutables " $DetectBrokenExecutables >> $CLAMD_CONFIGFILE
  76. echo "ScanOLE2 " $ScanOLE2 >> $CLAMD_CONFIGFILE
  77. echo "ScanPDF " $ScanPDF >> $CLAMD_CONFIGFILE
  78. echo "ScanSWF " $ScanSWF >> $CLAMD_CONFIGFILE
  79. echo "ScanMail " $ScanMail >> $CLAMD_CONFIGFILE
  80. echo "ScanPartialMessages " $ScanPartialMessages >> $CLAMD_CONFIGFILE
  81. echo "ScanArchive " $ScanArchive >> $CLAMD_CONFIGFILE
  82. echo "TemporaryDirectory " $TemporaryDirectory >> $CLAMD_CONFIGFILE
  83. echo "ArchiveBlockEncrypted " $ArchiveBlockEncrypted >> $CLAMD_CONFIGFILE
  84. echo "MaxFileSize " $MaxFileSize >> $CLAMD_CONFIGFILE
  85. echo "LocalSocket " $LocalSocket >> $CLAMD_CONFIGFILE
  86. echo "User " $User >> $CLAMD_CONFIGFILE
  87. echo "ExitOnOOM " $ExitOnOOM >> $CLAMD_CONFIGFILE
  88. echo "DatabaseDirectory " $DatabaseDirectory >> $CLAMD_CONFIGFILE
  89. procd_open_instance
  90. procd_set_param command $PROG -c $CLAMD_CONFIGFILE
  91. procd_set_param file $CLAMD_CONFIGFILE
  92. procd_close_instance
  93. }
  94. start_service()
  95. {
  96. validate_clamav_section clamav start_clamav_instance
  97. }
  98. stop_service()
  99. {
  100. service_stop $PROG
  101. }
  102. service_triggers()
  103. {
  104. procd_add_reload_trigger "clamav"
  105. procd_add_validation validate_clamav_section
  106. }