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.

119 lines
4.0 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_validate_section clamav clamav "${1}" \
  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_service() {
  46. local clamd_config_file LogFile LogTime StreamMinPort \
  47. StreamMaxPort MaxThreads ReadTimeout CommandReadTimeout MaxDirectoryRecursion \
  48. FollowFileSymlinks FollowDirectorySymlinks SelfCheck DetectPUA ScanPE DisableCertCheck \
  49. ScanELF DetectBrokenExecutables ScanOLE2 ScanPDF ScanSWF ScanMail ScanPartialMessages \
  50. ScanArchive TemporaryDirectory ArchiveBlockEncrypted MaxFileSize LocalSocket User \
  51. DatabaseDirectory
  52. validate_clamav_section clamav || {
  53. echo "validation failed"
  54. return 1
  55. }
  56. mkdir -p $DatabaseDirectory
  57. mkdir -p /etc/clamav/
  58. mkdir -p /var/run/clamav/
  59. chmod a+rw /var/run/clamav
  60. mkdir -p $(dirname $CLAMD_CONFIGFILE)
  61. ln -sf $clamd_config_file $CLAMD_CONFIGFILE
  62. echo "LogFile " $LogFile > $CLAMD_CONFIGFILE
  63. echo "LogFileMaxSize " $LogFileMaxSize >> $CLAMD_CONFIGFILE
  64. echo "LogVerbose " $LogVerbose >> $CLAMD_CONFIGFILE
  65. echo "ExtendedDetectionInfo " $ExtendedDetectionInfo >> $CLAMD_CONFIGFILE
  66. echo "LogTime " $LogTime >> $CLAMD_CONFIGFILE
  67. echo "OfficialDatabaseOnly " $OfficialDatabaseOnly >> $CLAMD_CONFIGFILE
  68. echo "StreamMinPort " $StreamMinPort >> $CLAMD_CONFIGFILE
  69. echo "StreamMaxPort " $StreamMaxPort >> $CLAMD_CONFIGFILE
  70. echo "MaxThreads " $MaxThreads >> $CLAMD_CONFIGFILE
  71. echo "ReadTimeout " $ReadTimeout >> $CLAMD_CONFIGFILE
  72. echo "CommandReadTimeout " $CommandReadTimeout >> $CLAMD_CONFIGFILE
  73. echo "MaxDirectoryRecursion " $MaxDirectoryRecursion >> $CLAMD_CONFIGFILE
  74. echo "FollowDirectorySymlinks " $FollowDirectorySymlinks >> $CLAMD_CONFIGFILE
  75. echo "FollowFileSymlinks " $FollowFileSymlinks >> $CLAMD_CONFIGFILE
  76. echo "SelfCheck " $SelfCheck >> $CLAMD_CONFIGFILE
  77. echo "DetectPUA " $DetectPUA >> $CLAMD_CONFIGFILE
  78. echo "ScanPE " $ScanPE >> $CLAMD_CONFIGFILE
  79. echo "DisableCertCheck " $DisableCertCheck >> $CLAMD_CONFIGFILE
  80. echo "ScanELF " $ScanELF >> $CLAMD_CONFIGFILE
  81. echo "DetectBrokenExecutables " $DetectBrokenExecutables >> $CLAMD_CONFIGFILE
  82. echo "ScanOLE2 " $ScanOLE2 >> $CLAMD_CONFIGFILE
  83. echo "ScanPDF " $ScanPDF >> $CLAMD_CONFIGFILE
  84. echo "ScanSWF " $ScanSWF >> $CLAMD_CONFIGFILE
  85. echo "ScanMail " $ScanMail >> $CLAMD_CONFIGFILE
  86. echo "ScanPartialMessages " $ScanPartialMessages >> $CLAMD_CONFIGFILE
  87. echo "ScanArchive " $ScanArchive >> $CLAMD_CONFIGFILE
  88. echo "TemporaryDirectory " $TemporaryDirectory >> $CLAMD_CONFIGFILE
  89. echo "ArchiveBlockEncrypted " $ArchiveBlockEncrypted >> $CLAMD_CONFIGFILE
  90. echo "MaxFileSize " $MaxFileSize >> $CLAMD_CONFIGFILE
  91. echo "LocalSocket " $LocalSocket >> $CLAMD_CONFIGFILE
  92. echo "User " $User >> $CLAMD_CONFIGFILE
  93. echo "ExitOnOOM " $ExitOnOOM >> $CLAMD_CONFIGFILE
  94. echo "DatabaseDirectory " $DatabaseDirectory >> $CLAMD_CONFIGFILE
  95. procd_open_instance
  96. procd_set_param command $PROG -c $CLAMD_CONFIGFILE
  97. procd_set_param file $CLAMD_CONFIGFILE
  98. procd_close_instance
  99. }
  100. stop_service()
  101. {
  102. service_stop ${PROG}
  103. }
  104. service_triggers()
  105. {
  106. procd_add_reload_trigger "clamav"
  107. procd_add_validation validate_clamav_section
  108. }