From: 
Subject: Debian changes

The Debian packaging of milterfrom is maintained in git, using a workflow
similar to the one described in dgit-maint-merge(7).
The Debian delta is represented by this one combined patch; there isn't a
patch queue that can be represented as a quilt series.

A detailed breakdown of the changes is available from their canonical
representation -- git commits in the packaging repository.
For example, to see the changes made by the Debian maintainer in the first
upload of upstream version 1.2.3, you could use:

    % git clone https://git.dgit.debian.org/milterfrom
    % cd milterfrom
    % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'

(If you have dgit, use `dgit clone milterfrom`, rather than plain `git clone`.)

We don't use debian/source/options single-debian-patch because it has bugs.
Therefore, NMUs etc. may nevertheless have made additional patches.

---

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3746f5e..8e1da0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,20 +1,22 @@
-#milterfrom CHANGELOG
+# milterfrom CHANGELOG
 
 Version 1.0.4 2025-10-05
-* Added optional argument `-r` to reject on multiple From: address fields like From:Grouping<g@example> <auth@example.com>
-* Added optional argument `-n`  to reject null sender unless authentication matches the From: address.
+
+* Added optional argument `-r` to reject on multiple `From:` address fields `like From:Grouping<g@example> <auth@example.com>`
+* Added optional argument `-n`  to reject null sender unless authentication matches the `From:` address.
 * See CERT/CC disclosure VU#517845 kb.cert.org/vuls/id/517845
 
 
 Version 1.0.3 2025-09-24
+
 * Added verification of no control characters inside carrots.
-[See references https://blog.slonser.info/posts/email-attacks/ ]
+  [See references https://blog.slonser.info/posts/email-attacks/ ]
 
 Version 1.0.2  2023-09-18
 
-* Fixed bug on null sender to SMFIS_ACCEPT and no more filtering
+* Fixed bug on null sender to `SMFIS_ACCEPT` and no more filtering
 * Added syslog on null sender event with connection details (IP,name)
-* Changed syslog to be from log_event routine
+* Changed syslog to be from `log_event` routine
 
 Version 1.0.1  2023-08-30
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 84bc249..7890c66 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,21 +1,24 @@
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.10)
 
 project(MilterFrom C)
 
-option(WITH_SYSTEMD "Install Systemd unit files" ON)
-set(SYSTEMD_UNITDIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system" CACHE PATH "Systemd unit directory")
+find_package(PkgConfig QUIET)
+pkg_get_variable(SYSTEMD_SYSTEM_UNIT_DIR systemd systemd_system_unit_dir DEFINE_VARIABLES prefix=${CMAKE_INSTALL_PREFIX})
 
 list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
+include(GNUInstallDirs)
 
+set(THREADS_PREFER_PTHREAD_FLAG TRUE)
 find_package(Threads REQUIRED)
 find_package(Milter REQUIRED)
 
 add_executable(milterfrom src/milterfrom.c)
-target_include_directories(milterfrom PRIVATE ${Milter_INCLUDE_DIRS})
-target_link_libraries(milterfrom ${Milter_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(milterfrom PRIVATE Milter::milter Threads::Threads)
 
-install(TARGETS milterfrom DESTINATION bin)
-if(NOT WIN32 AND WITH_SYSTEMD)
-	configure_file(systemd/milterfrom.service.in ${CMAKE_CURRENT_BINARY_DIR}/systemd/milterfrom.service)
-	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/systemd/milterfrom.service DESTINATION ${SYSTEMD_UNITDIR})
+install(TARGETS milterfrom DESTINATION "${CMAKE_INSTALL_BINDIR}")
+install(FILES man/milterfrom.1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
+if(SYSTEMD_SYSTEM_UNIT_DIR)
+	configure_file(systemd/milterfrom.service.in ${CMAKE_CURRENT_BINARY_DIR}/systemd/milterfrom.service @ONLY)
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/systemd/milterfrom.service systemd/milterfrom.socket
+		DESTINATION ${SYSTEMD_SYSTEM_UNIT_DIR})
 endif()
diff --git a/README.md b/README.md
index b16cc03..db832cb 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
 # MilterFrom
+
 This milter compares the envelope sender with the sender specified in the mail header for authenticated users.
 
 It aims to resolve the problem that OpenDKIM signs ALL mails with domains listed in its databases. If you have a multi user setup, user A "a@example.invalid" can send mails with the from field "From: b@example.invalid" and OpenDKIM signs it although user A should not be allowed to send authenticated mails from "b@example.invalid".
@@ -6,26 +7,29 @@ It aims to resolve the problem that OpenDKIM signs ALL mails with domains listed
 The postconf option "reject_authenticated_sender_login_mismatch" doesn't solve the problem at all, because it only enforces the envelope sender to be correct. This milter further ensures that the sender specified in the header matches the envelope sender.
 
 ## Dependencies (as Debian package names)
-* git cmake make gcc
-* libmilter1.0.1 libmilter-dev
+
+* git cmake make gcc pkg-config
+* libmilter1.0.1 libmilter-dev systemd-dev
 
 ## Build and install
+
 ```bash
-mkdir build
-cd $_
-cmake -DWITH_SYSTEMD=ON ..
-make
-make install # this installs the executable and the Systemd unit
+cmake -B build
+cmake --build build
+cmake --install build # this installs the executable and the Systemd unit
 systemctl daemon-reload
 ```
 
 If you wish to install to a custom directory:
+
 ```bash
-cmake -DWITH_SYSTEMD=ON -DCMAKE_INSTALL_PREFIX=/tmp/your/path ..
+cmake -DCMAKE_INSTALL_PREFIX=/tmp/your/path ..
 ```
 
 ## Configure (on a Systemd and Postfix environment)
+
 Add a user:
+
 ```bash
 groupadd milterfrom
 useradd -g milterfrom -s /bin/false -d /var/spool/postfix/milterfrom milterfrom
@@ -35,12 +39,14 @@ chown milterfrom:milterfrom /var/spool/postfix/milterfrom
 ```
 
 Configure postfix to use the milter:
+
 ```
 postconf -e "smtpd_milters = unix:/milterfrom/milterfrom$([[ $(postconf -h smtpd_milters) != "" ]] && echo -n ", " && postconf -h smtpd_milters)"
 postconf -e "non_smtpd_milters = unix:/milterfrom/milterfrom$([[ $(postconf -h non_smtpd_milters) != "" ]] && echo -n ", " && postconf -h non_smtpd_milters)"
 ```
 
 Start everything:
+
 ```bash
 systemctl enable milterfrom
 service milterfrom start
@@ -48,9 +54,11 @@ service postfix restart
 ```
 
 ## Example
+
 ```bash
 openssl s_client -connect mail.coolkids.invalid -starttls smtp
 ```
+
 ```
 CONNECTED(00000003)
 [TLS stuff]
@@ -82,10 +90,13 @@ closed
 ```
 
 ## Run
+
 To start the daemon directly, run the following (Remove the `-d` to run in foreground):
+
 ```bash
 milterfrom -u milterfrom -g milterfrom -m 002 -d -p /var/run/milterfrom.pid -s /var/spool/postfix/milterfrom/milterfrom
 ```
 
 ## License
+
 Licensed under the 3-Clause BSD License.
diff --git a/cmake/FindMilter.cmake b/cmake/FindMilter.cmake
index b1d36c7..cbd9c27 100644
--- a/cmake/FindMilter.cmake
+++ b/cmake/FindMilter.cmake
@@ -1,34 +1,49 @@
-# - Try to find Milter lib
+# - Try to find Milter lib with pkg-config, falling back to manual search
 #
-# The following variables are defined
+# The following imported target is defined:
 #
-#  Milter_FOUND - system has Milter lib
-#  Milter_INCLUDE_DIR - the Milter include directory
-#  Milter_LIBRARY - the Milter library
+# - Milter::milter
 
-find_path(Milter_INCLUDE_DIR libmilter/mfapi.h
-	/usr/local/include
-	/usr/include
-	/opt/local/include
-	/sw/local/include
-	/sw/include
-	NO_DEFAULT_PATH
-)
-find_library(Milter_LIBRARY
-	NAMES "milter"
-	PATHS
-	~/Library/Frameworks
-	/Library/Frameworks
-	/usr/local/lib
-	/usr/local/lib64
-	/usr/lib
-	/usr/lib64
-	/opt/local/lib
-	/sw/local/lib
-	/sw/lib
-)
+find_package(PkgConfig QUIET)
+pkg_search_module(MILTER QUIET IMPORTED_TARGET milter)
 
-set(Milter_FOUND FALSE)
-if(Milter_INCLUDE_DIR AND Milter_LIBRARY)
-	set(Milter_FOUND TRUE)
-endif(Milter_INCLUDE_DIR AND Milter_LIBRARY)
+if(MILTER_FOUND)
+	if(NOT TARGET Milter::milter)
+		add_library(Milter::milter ALIAS PkgConfig::MILTER)
+	endif()
+else()
+	find_path(MILTER_INCLUDE_DIRS libmilter/mfapi.h
+		/usr/local/include
+		/usr/include
+		/opt/local/include
+		/sw/local/include
+		/sw/include
+		NO_DEFAULT_PATH
+	)
+	find_library(MILTER_LINK_LIBRARIES
+		NAMES "milter"
+		PATHS
+		~/Library/Frameworks
+		/Library/Frameworks
+		/usr/local/lib
+		/usr/local/lib64
+		/usr/lib
+		/usr/lib64
+		/opt/local/lib
+		/sw/local/lib
+		/sw/lib
+	)
+	if(MILTER_INCLUDE_DIRS AND MILTER_LINK_LIBRARIES)
+		add_library(Milter::milter INTERFACE IMPORTED)
+		set_target_properties(Milter::milter PROPERTIES
+			INTERFACE_INCLUDE_DIRECTORIES "${MILTER_INCLUDE_DIRS}"
+			INTERFACE_LINK_LIBRARIES "${MILTER_LINK_LIBRARIES}"
+		)
+	endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Milter
+	REQUIRED_VARS MILTER_LINK_LIBRARIES MILTER_INCLUDE_DIRS
+	VERSION_VAR MILTER_VERSION
+)
diff --git a/man/milterfrom.1 b/man/milterfrom.1
new file mode 100644
index 0000000..83c7aaa
--- /dev/null
+++ b/man/milterfrom.1
@@ -0,0 +1,49 @@
+.\" SPDX-FileCopyrightText: 2026 Andrea Pappacoda <andrea@pappacoda.it>
+.\" SPDX-License-Identifier: BSD-3-Clause
+.Dd 2026-11-28
+.Dt MILTERFROM 1
+.Os
+.
+.Sh NAME
+.Nm milterfrom
+.Nd enforce equal From header address and envelope sender
+.
+.Sh SYNOPSIS
+.Nm
+.Fl s Ar socket
+.Op Fl dhvrn
+.Op Fl p Ar pidfile
+.Op Fl u Ar userid
+.Op Fl g Ar groupid
+.Op Fl m Ar umask
+.
+.Sh DESCRIPTION
+.Nm
+is a milter that compares the envelope sender with the sender specified in the
+message header, preventing logged-in users from spoofing the From address.
+.Pp
+It complements Postfix options like
+.Ic reject_authenticated_sender_login_mismatch ,
+which only check correspondence between the SASL login name and the envelope
+sender.
+.
+.Sh EXIT STATUS
+.Ex -std
+.
+.Sh EXAMPLES
+.Bd -literal
+milterfrom -s /var/spool/postfix/milterfrom/milterfrom -nr
+.Ed
+.
+.Sh SEE ALSO
+.Xr postconf 5
+.
+.Sh AUTHORS
+.An -nosplit
+.Nm
+was written by
+.An Maximilian von Buelow Lk https://von-buelow.eu .
+This manual page was written by
+.An Andrea Pappacoda Aq Mt andrea@pappacoda.it
+for the Debian project
+.Pq and may be used by others .
diff --git a/systemd/milterfrom.service.in b/systemd/milterfrom.service.in
index a756e2f..4e0388f 100644
--- a/systemd/milterfrom.service.in
+++ b/systemd/milterfrom.service.in
@@ -2,10 +2,31 @@
 Description=A milter that enforces equal envelope and header sender
 
 [Service]
-Type=forking
-PIDFile=/var/run/milterfrom.pid
-ExecStart=@CMAKE_INSTALL_PREFIX@/bin/milterfrom -d -p /var/run/milterfrom.pid -u milterfrom -g milterfrom -m 002 -s /var/spool/postfix/milterfrom/milterfrom
+Type=exec
+ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/milterfrom -s fd:0
 ExecReload=/bin/kill -HUP $MAINPID
+DynamicUser=yes
+StandardInput=socket
 
-[Install]
-WantedBy=multi-user.target
\ No newline at end of file
+CapabilityBoundingSet=
+LockPersonality=yes
+MemoryDenyWriteExecute=yes
+PrivateDevices=yes
+PrivateNetwork=yes
+PrivateUsers=yes
+ProcSubset=pid
+ProtectClock=yes
+ProtectControlGroups=strict
+ProtectHome=yes
+ProtectHostname=yes
+ProtectKernelLogs=yes
+ProtectKernelModules=yes
+ProtectKernelTunables=yes
+ProtectProc=invisible
+RestrictAddressFamilies=none
+RestrictNamespaces=yes
+RestrictRealtime=yes
+SystemCallArchitectures=native
+SystemCallFilter=@system-service
+SystemCallFilter=~ @privileged @resources
+UMask=0077
diff --git a/systemd/milterfrom.socket b/systemd/milterfrom.socket
new file mode 100644
index 0000000..e2835df
--- /dev/null
+++ b/systemd/milterfrom.socket
@@ -0,0 +1,5 @@
+[Socket]
+ListenStream=/var/spool/postfix/milterfrom/milterfrom
+
+[Install]
+WantedBy=sockets.target
