Skip to content

Commit

Permalink
Support rmilter detection only on CentOS 6
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 31, 2017
1 parent 52b15b4 commit b7226a3
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 2 deletions.
3 changes: 2 additions & 1 deletion binding/ruby/lib/milter/manager/Makefile.am
Expand Up @@ -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
14 changes: 13 additions & 1 deletion binding/ruby/lib/milter/manager/redhat-init-detector.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2009-2017 Kouhei Sutou <kou@clear-code.com>
#
# 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
Expand All @@ -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
Expand Down Expand Up @@ -63,6 +64,16 @@ def opendkim?
@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)
Expand Down Expand Up @@ -159,6 +170,7 @@ def guess_application_specific_spec_before
spec ||= detect_clamav_milter_connection_spec
end
spec ||= detect_opendkim_connection_spec if opendkim?
spec ||= detect_rmilter_connection_spec if rmilter?
spec
end

Expand Down
48 changes: 48 additions & 0 deletions binding/ruby/lib/milter/manager/rmilter-socket-detector.rb
@@ -0,0 +1,48 @@
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
#
# 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
82 changes: 82 additions & 0 deletions binding/ruby/test/manager/test-redhat-init-detector.rb
Expand Up @@ -617,6 +617,57 @@ def test_apply_opendkim_style
"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@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)
Expand Down Expand Up @@ -927,4 +978,35 @@ def opendkim_init_header(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
3 changes: 3 additions & 0 deletions data/defaults/redhat.conf
Expand Up @@ -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)
Expand Down

0 comments on commit b7226a3

Please sign in to comment.