|
|
813923 |
Description: systemd-like socket activation support for libmilter
|
|
|
813923 |
Author: Mikhail Gusarov
|
|
|
813923 |
diff --git a/libmilter/docs/smfi_setconn.html b/libmilter/docs/smfi_setconn.html
|
|
|
813923 |
index eba7c5b..5b272a0 100644
|
|
|
813923 |
--- a/libmilter/docs/smfi_setconn.html
|
|
|
813923 |
+++ b/libmilter/docs/smfi_setconn.html
|
|
|
813923 |
@@ -43,6 +43,7 @@ Set the socket through which this filter should communicate with sendmail.
|
|
|
813923 |
{unix|local}:/path/to/file -- A named pipe.
|
|
|
813923 |
inet:port@{hostname|ip-address} -- An IPV4 socket.
|
|
|
813923 |
inet6:port@{hostname|ip-address} -- An IPV6 socket.
|
|
|
813923 |
+ fd:number -- Pre-opened file descriptor.
|
|
|
813923 |
|
|
|
813923 |
|
|
|
813923 |
|
|
|
813923 |
diff --git a/libmilter/listener.c b/libmilter/listener.c
|
|
|
813923 |
index 11d92bb..2ab533d 100644
|
|
|
813923 |
--- a/libmilter/listener.c
|
|
|
813923 |
+++ b/libmilter/listener.c
|
|
|
813923 |
@@ -197,6 +197,11 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
813923 |
L_socksize = sizeof addr.sin6;
|
|
|
813923 |
}
|
|
|
813923 |
#endif /* NETINET6 */
|
|
|
813923 |
+ else if (strcasecmp(p, "fd") == 0)
|
|
|
813923 |
+ {
|
|
|
813923 |
+ addr.sa.sa_family = AF_UNSPEC;
|
|
|
813923 |
+ L_socksize = sizeof (_SOCK_ADDR);
|
|
|
813923 |
+ }
|
|
|
813923 |
else
|
|
|
813923 |
{
|
|
|
813923 |
smi_log(SMI_LOG_ERR, "%s: unknown socket type %s",
|
|
|
813923 |
@@ -443,7 +448,21 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
813923 |
}
|
|
|
813923 |
#endif /* NETINET || NETINET6 */
|
|
|
813923 |
|
|
|
813923 |
- sock = socket(addr.sa.sa_family, SOCK_STREAM, 0);
|
|
|
813923 |
+ if (addr.sa.sa_family == AF_UNSPEC)
|
|
|
813923 |
+ {
|
|
|
813923 |
+ char *end;
|
|
|
813923 |
+ sock = strtol(colon, &end, 10);
|
|
|
813923 |
+ if (*end != '\0' || sock < 0)
|
|
|
813923 |
+ {
|
|
|
813923 |
+ smi_log(SMI_LOG_ERR, "%s: expected positive integer as fd, got %s", name, colon);
|
|
|
813923 |
+ return INVALID_SOCKET;
|
|
|
813923 |
+ }
|
|
|
813923 |
+ }
|
|
|
813923 |
+ else
|
|
|
813923 |
+ {
|
|
|
813923 |
+ sock = socket(addr.sa.sa_family, SOCK_STREAM, 0);
|
|
|
813923 |
+ }
|
|
|
813923 |
+
|
|
|
813923 |
if (!ValidSocket(sock))
|
|
|
813923 |
{
|
|
|
813923 |
smi_log(SMI_LOG_ERR,
|
|
|
813923 |
@@ -466,6 +485,7 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
813923 |
#if NETUNIX
|
|
|
813923 |
addr.sa.sa_family != AF_UNIX &&
|
|
|
813923 |
#endif /* NETUNIX */
|
|
|
813923 |
+ addr.sa.sa_family != AF_UNSPEC &&
|
|
|
813923 |
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &sockopt,
|
|
|
813923 |
sizeof(sockopt)) == -1)
|
|
|
813923 |
{
|
|
|
813923 |
@@ -511,7 +531,8 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
813923 |
}
|
|
|
813923 |
#endif /* NETUNIX */
|
|
|
813923 |
|
|
|
813923 |
- if (bind(sock, &addr.sa, L_socksize) < 0)
|
|
|
813923 |
+ if (addr.sa.sa_family != AF_UNSPEC &&
|
|
|
813923 |
+ bind(sock, &addr.sa, L_socksize) < 0)
|
|
|
813923 |
{
|
|
|
813923 |
smi_log(SMI_LOG_ERR,
|
|
|
813923 |
"%s: Unable to bind to port %s: %s",
|
|
|
813923 |
@@ -818,7 +839,7 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
|
|
|
813923 |
# ifdef BSD4_4_SOCKADDR
|
|
|
813923 |
cliaddr.sa.sa_len == 0 ||
|
|
|
813923 |
# endif /* BSD4_4_SOCKADDR */
|
|
|
813923 |
- cliaddr.sa.sa_family != L_family))
|
|
|
813923 |
+ (L_family != AF_UNSPEC && cliaddr.sa.sa_family != L_family)))
|
|
|
813923 |
{
|
|
|
813923 |
(void) closesocket(connfd);
|
|
|
813923 |
connfd = INVALID_SOCKET;
|