Permalink
Browse files

Add milter-based daemon

  • Loading branch information...
1 parent 3f59dcd commit 52feccaca1b7579a277a75d3182367c6d0379a20 @andrenth committed Jul 9, 2012
View
19 _oasis
@@ -44,6 +44,25 @@ Executable "spf-policyd"
lwt.syntax,
lwt.preemptive
+Executable "spf-milter"
+ Path: src
+ BuildTools: ocamlbuild
+ MainIs: spf_milter.ml
+ Install: true
+ CompiledObject: best
+ BuildDepends: spf,
+ milter,
+ str,
+ unix,
+ threads,
+ uint.uint32,
+ uint.uint128,
+ release,
+ lwt,
+ lwt.unix,
+ lwt.syntax,
+ lwt.preemptive
+
Executable spf_test
Path: lib_test
BuildTools: ocamlbuild
View
16 _tags
@@ -1,5 +1,5 @@
# OASIS_START
-# DO NOT EDIT (digest: 4bfbfbb0d597bf96fbdcddfb5903bd5c)
+# DO NOT EDIT (digest: e048003be779e46cc3cbda2b41f971e1)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
@@ -41,8 +41,22 @@
<src/spf_policyd.{native,byte}>: pkg_lwt.unix
<src/spf_policyd.{native,byte}>: pkg_lwt.syntax
<src/spf_policyd.{native,byte}>: pkg_lwt.preemptive
+# Executable spf-milter
+<src/spf_milter.{native,byte}>: use_spf
+<src/spf_milter.{native,byte}>: pkg_unix
+<src/spf_milter.{native,byte}>: pkg_milter
+<src/spf_milter.{native,byte}>: pkg_str
+<src/spf_milter.{native,byte}>: pkg_threads
+<src/spf_milter.{native,byte}>: pkg_uint.uint32
+<src/spf_milter.{native,byte}>: pkg_uint.uint128
+<src/spf_milter.{native,byte}>: pkg_release
+<src/spf_milter.{native,byte}>: pkg_lwt
+<src/spf_milter.{native,byte}>: pkg_lwt.unix
+<src/spf_milter.{native,byte}>: pkg_lwt.syntax
+<src/spf_milter.{native,byte}>: pkg_lwt.preemptive
<src/*.ml{,i}>: use_spf
<src/*.ml{,i}>: pkg_unix
+<src/*.ml{,i}>: pkg_milter
<src/*.ml{,i}>: pkg_str
<src/*.ml{,i}>: pkg_threads
<src/*.ml{,i}>: pkg_uint.uint32
View
@@ -0,0 +1,12 @@
+if [ ! `which milter-test-server` ]; then
+ echo -n "Please install 'milter-test-server'"
+ echo -n ' [http://milter-manager.sourceforge.net]'
+ echo ' or add it to your PATH'
+ exit 1
+fi
+
+runtest() {
+ echo "$1" | grep -q "$2"
+}
+
+CONNSPEC=inet:9999@localhost
View
@@ -0,0 +1,47 @@
+-- Echo that the test is starting
+mt.echo("*** begin test")
+-- start the filter
+binpath = mt.getcwd() .. "/_build/src"
+daemon = "spfd.native"
+filter = binpath .. "/" .. daemon
+
+mt.echo("*** executing " .. filter)
+mt.startfilter(filter)
+mt.sleep(2)
+
+conn = "inet:9999@127.0.0.1"
+envfrom = "andre@digirati.com.br"
+helofqdn = "mta112.f1.k8.com.br"
+heloaddr = "187.73.32.184"
+
+conn = mt.connect(conn)
+if conn == nil then
+ error "mt.connect() failed"
+end
+
+if mt.conninfo(conn, helofqdn, heloaddr) ~= nil then
+ error "mt.conninfo() failed"
+end
+if mt.getreply(conn) ~= SMFIR_CONTINUE then
+ error "mt.conninfo() unexpected reply"
+end
+if mt.mailfrom(conn, envfrom) ~= nil then
+ error "mt.mailfrom() failed"
+end
+if mt.getreply(conn) ~= SMFIR_CONTINUE then
+ error "mt.mailfrom() unexpected reply"
+end
+
+-- end of message; let the filter react
+if mt.eom(conn) ~= nil then
+ error "mt.eom() failed"
+end
+if mt.getreply(conn) ~= SMFIR_CONTINUE then
+ error "mt.eom() unexpected reply"
+end
+
+if not mt.eom_check(conn, MT_HDRADD, "Received-SPF") then
+ error "no header added"
+end
+
+mt.disconnect(conn)
View
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. `dirname $0`/config.sh
+
+ENVFROM="spf-test@openspf.net"
+HELOFQDN="`host -t mx openspf.net | awk '{ print $NF}'`"
+
+runtest "`milter-test-server \
+ --connection-spec $CONNSPEC \
+ --connect-address inet:8888@$HELOFQDN \
+ --helo-fqdn $HELOFQDN \
+ --envelope-from $ENVFROM`" \
+ '^status: reject'
+
+exit $?
View
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. `dirname $0`/config.sh
+
+ENVFROM=spf-test@digirati.com.br
+HELOADDR="`host mxz.f1.k8.com.br | head -n1 | awk '{ print $NF}'`"
+HELOFQDN="`host $HELOADDR | head -n1 | awk '{ print $NF}'`"
+
+runtest "`milter-test-server \
+ --connection-spec $CONNSPEC \
+ --connect-address inet:8888@$HELOADDR \
+ --helo-fqdn $HELOFQDN \
+ --envelope-from $ENVFROM`" \
+ '^status: pass'
+
+exit $?
View
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+. `dirname $0`/config.sh
+
+ENVFROM='spf-test@bradescoseguros.com.br'
+HELOFQDN='gwmail.bradescoseguros.com.br'
+
+runtest "`milter-test-server \
+ --connection-spec $CONNSPEC \
+ --connect-address inet:8888@$HELOFQDN \
+ --helo-fqdn $HELOFQDN \
+ --envelope-from $ENVFROM \
+ --reading-timeout 30 \
+ --writing-timeout 30`" \
+ '^status: temporary-failure'
+
+exit $?
View
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.2.0 *)
(* OASIS_START *)
-(* DO NOT EDIT (digest: 223271f8b456d339d8a8464aa86f9e49) *)
+(* DO NOT EDIT (digest: ca6cad8e2e57eac64dc639c68761d1f6) *)
(*
Regenerated by OASIS v0.3.0
Visit http://oasis.forge.ocamlcore.org for more information and
@@ -5728,6 +5728,43 @@ let setup_t =
bs_nativeopt = [(OASISExpr.EBool true, [])];
},
{exec_custom = false; exec_main_is = "spf_policyd.ml"; });
+ Executable
+ ({
+ cs_name = "spf-milter";
+ cs_data = PropList.Data.create ();
+ cs_plugin_data = [];
+ },
+ {
+ bs_build = [(OASISExpr.EBool true, true)];
+ bs_install = [(OASISExpr.EBool true, true)];
+ bs_path = "src";
+ bs_compiled_object = Best;
+ bs_build_depends =
+ [
+ InternalLibrary "spf";
+ FindlibPackage ("milter", None);
+ FindlibPackage ("str", None);
+ FindlibPackage ("unix", None);
+ FindlibPackage ("threads", None);
+ FindlibPackage ("uint.uint32", None);
+ FindlibPackage ("uint.uint128", None);
+ FindlibPackage ("release", None);
+ FindlibPackage ("lwt", None);
+ FindlibPackage ("lwt.unix", None);
+ FindlibPackage ("lwt.syntax", None);
+ FindlibPackage ("lwt.preemptive", None)
+ ];
+ bs_build_tools = [ExternalTool "ocamlbuild"];
+ bs_c_sources = [];
+ bs_data_files = [];
+ bs_ccopt = [(OASISExpr.EBool true, [])];
+ bs_cclib = [(OASISExpr.EBool true, [])];
+ bs_dlllib = [(OASISExpr.EBool true, [])];
+ bs_dllpath = [(OASISExpr.EBool true, [])];
+ bs_byteopt = [(OASISExpr.EBool true, [])];
+ bs_nativeopt = [(OASISExpr.EBool true, [])];
+ },
+ {exec_custom = false; exec_main_is = "spf_milter.ml"; });
Executable
({
cs_name = "spf_test";
@@ -5760,14 +5797,14 @@ let setup_t =
};
oasis_fn = Some "_oasis";
oasis_version = "0.3.0";
- oasis_digest = Some "h\023\025\233\237eSC\011\003\140z\221\199p8";
+ oasis_digest = Some "v \015[\142\207q;\241\232C\242\222\031+\157";
oasis_exec = None;
oasis_setup_args = [];
setup_update = false;
};;
let setup () = BaseSetup.setup setup_t;;
-# 5772 "setup.ml"
+# 5809 "setup.ml"
(* OASIS_STOP *)
let () = setup ();;
View
@@ -0,0 +1,27 @@
+type t =
+ { user : string
+ ; listen_address : string
+ ; log_level : Lwt_log.level
+ ; local_addresses : Network.t list
+ ; relay_addresses : Network.t list
+ ; fail_on_helo_temperror : bool
+ }
+
+let default_local_addresses =
+ List.map Network.of_string
+ [ "127.0.0.0/8"
+ ; "::ffff:127.0.0.0/104"
+ ]
+
+let default_relay_addresses =
+ List.map Network.of_string
+ []
+
+let default =
+ { user = "andre"
+ ; listen_address = "inet:9999@127.0.0.1"
+ ; log_level = Lwt_log.Debug
+ ; local_addresses = default_local_addresses
+ ; relay_addresses = default_relay_addresses
+ ; fail_on_helo_temperror = true
+ }
Oops, something went wrong.

0 comments on commit 52fecca

Please sign in to comment.