Kouhei Sutou
null+****@clear*****
Tue Jan 31 13:27:51 JST 2017
Kouhei Sutou 2017-01-31 13:27:51 +0900 (Tue, 31 Jan 2017) New Revision: b7226a3a33029250c7e43d81641f59ad620e4ffd https://github.com/milter-manager/milter-manager/commit/b7226a3a33029250c7e43d81641f59ad620e4ffd Message: Support rmilter detection only on CentOS 6 Added files: binding/ruby/lib/milter/manager/rmilter-socket-detector.rb Modified files: binding/ruby/lib/milter/manager/Makefile.am binding/ruby/lib/milter/manager/redhat-init-detector.rb binding/ruby/test/manager/test-redhat-init-detector.rb data/defaults/redhat.conf Modified: binding/ruby/lib/milter/manager/Makefile.am (+2 -1) =================================================================== --- binding/ruby/lib/milter/manager/Makefile.am 2017-01-16 09:14:36 +0900 (acc2b73) +++ binding/ruby/lib/milter/manager/Makefile.am 2017-01-31 13:27:51 +0900 (1ce0d9c) @@ -25,4 +25,5 @@ dist_binding_lib_milter_DATA = \ postfix-condition-table-parser.rb \ postfix-cidr-table.rb \ postfix-regexp-table.rb \ - file-reader.rb + file-reader.rb \ + rmilter-socket-detector.rb Modified: binding/ruby/lib/milter/manager/redhat-init-detector.rb (+13 -1) =================================================================== --- binding/ruby/lib/milter/manager/redhat-init-detector.rb 2017-01-16 09:14:36 +0900 (46aa061) +++ binding/ruby/lib/milter/manager/redhat-init-detector.rb 2017-01-31 13:27:51 +0900 (6c867fb) @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2014 Kouhei Sutou <kou****@clear*****> +# Copyright (C) 2009-2017 Kouhei Sutou <kou****@clear*****> # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -16,6 +16,7 @@ require 'milter/manager/file-reader' require 'milter/manager/init-detector' require 'milter/manager/enma-socket-detector' +require 'milter/manager/rmilter-socket-detector' module Milter::Manager class RedHatInitDetector @@ -63,6 +64,16 @@ module Milter::Manager @script_name == "opendkim" end + def detect_rmilter_connection_spec + conf_file = @variables["rmilter_CONF_FILE"] || + etc_file("rmilter", "rmilter.conf.sysvinit") + Milter::Manager::RmilterSocketDetector.new(conf_file).detect + end + + def rmilter? + @script_name == "rmilter" + end + private def parse_custom_conf parse_sysconfig(sysconfig) @@ -159,6 +170,7 @@ module Milter::Manager spec ||= detect_clamav_milter_connection_spec end spec ||= detect_opendkim_connection_spec if opendkim? + spec ||= detect_rmilter_connection_spec if rmilter? spec end Added: binding/ruby/lib/milter/manager/rmilter-socket-detector.rb (+48 -0) 100644 =================================================================== --- /dev/null +++ binding/ruby/lib/milter/manager/rmilter-socket-detector.rb 2017-01-31 13:27:51 +0900 (da401fa) @@ -0,0 +1,48 @@ +# Copyright (C) 2017 Kouhei Sutou <kou****@clear*****> +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library. If not, see <http://www.gnu.org/licenses/>. + +require "milter/manager/file-reader" + +module Milter::Manager + class RmilterSocketDetector + def initialize(conf_file) + @conf_file = conf_file + end + + def detect + return nil unless File.readable?(@conf_file) + + parse(@conf_file) + end + + private + def parse(path) + connection_spec = nil + content = FileReader.read(path) + content.each_line do |line| + case line + when /\A\s*\.(?:try_)?include\s+(.+)$/ + sub_path_pattern = $1.strip + Dir.glob(sub_path_pattern).each do |sub_path| + connection_spec = parse(sub_path) || connection_spec + end + when /\A\s*bind_socket\s*=\s*(.+);$/ + connection_spec = $1.strip + end + end + connection_spec + end + end +end Modified: binding/ruby/test/manager/test-redhat-init-detector.rb (+82 -0) =================================================================== --- binding/ruby/test/manager/test-redhat-init-detector.rb 2017-01-16 09:14:36 +0900 (598faef) +++ binding/ruby/test/manager/test-redhat-init-detector.rb 2017-01-31 13:27:51 +0900 (27c575e) @@ -617,6 +617,57 @@ EOC "local:/var/run/opendkim/opendkim.socket"]]) end + def test_apply_rmilter_style + rmilter_conf_sysvinit = @tmp_dir + "rmilter.conf.sysvinit" + rmilter_conf_common = @tmp_dir + "rmilter.conf.common" + (@init_d + "rmilter").open("w") do |file| + file << rmilter_init_header(rmilter_conf_sysvinit.to_s) + end + + rmilter_conf_sysvinit.open("w") do |conf| + conf << <<-CONF +# sysvinit-specific settings for rmilter + +.include #{rmilter_conf_common} + +bind_socket = unix:/var/run/rmilter/rmilter.sock; + +# pidfile - path to pid file +# Default: pidfile = /var/run/rmilter.pid + +pidfile = /var/run/rmilter/rmilter.pid; + +# include user's configuration +.try_include #{@tmp_dir}/rmilter.conf.local +.try_include #{@tmp_dir}/rmilter.conf.d/*.conf +.try_include #{@tmp_dir}/rmilter/rmilter.conf.local +.try_include #{@tmp_dir}/rmilter/conf.d/*.conf + CONF + end + + rmilter_conf_common.open("w") do |conf| + conf << <<-CONF +# bind_socket - socket credits for local bind: +# unix:/path/to/file - bind to local socket +# inet:port at host - bind to inet socket +# Default: bind_socket = unix:/var/tmp/rmilter.sock; + +bind_socket = unix:/run/rmilter/rmilter.sock; + CONF + end + + detector = redhat_init_detector("rmilter") + detector.detect + detector.apply(@loader) + assert_equal("rmilter", detector.name) + assert_eggs([["rmilter", + "rmilter is a spam filtering system", + false, + (@init_d + "rmilter").to_s, + "start", + "unix:/var/run/rmilter/rmilter.sock"]]) + end + private def redhat_init_detector(name, options={}) detector = Milter::Manager::RedHatInitDetector.new(@configuration, name) @@ -927,4 +978,35 @@ CONFIG=#{opendkim_conf} USER=opendkim EOS end + + def rmilter_init_header(rmilter_conf) + <<-HEADER +#!/bin/sh +# +# rmilter - this script starts and stops the rmilter daemon +# +# chkconfig: - 85 15 +# description: rmilter is a spam filtering system +# processname: rmilter +# config: #{rmilter_conf} +# config: /etc/sysconfig/rmilter +# pidfile: /var/run/rmilter/rmilter.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Check that networking is up. +[ "$NETWORKING" = "no" ] && exit 0 + +rmilter="/usr/sbin/rmilter" +prog=$(basename $rmilter) + +rmilter_CONF_FILE="#{rmilter_conf}" +rmilter_USER="_rmilter" +rmilter_GROUP="adm" + HEADER + end end Modified: data/defaults/redhat.conf (+3 -0) =================================================================== --- data/defaults/redhat.conf 2017-01-16 09:14:36 +0900 (3b0823c) +++ data/defaults/redhat.conf 2017-01-31 13:27:51 +0900 (516db67) @@ -14,6 +14,9 @@ candidates = [ ["Remote Network", "Unauthenticated", "No Stress"]], ["amavisd", []], ["opendkim", []], + ["rmilter", + ["Remote Network", "S25R", "Unauthenticated", "No Stress"], + ], ] candidates.each do |candidate, conditions, spec_detector| detector = RedHatDetector.new(configuration, candidate, &spec_detector) -------------- next part -------------- An HTML attachment was scrubbed... 下载