On 31/08/2026 16:06 EEST Michael Grimm via dovecot
<[1][email protected]> wrote:
Lucas Holt via dovecot <[2][email protected]> wrote:
On FreeBSD and MidnightBSD, Dovecot's net_getunixcred() relies on
getpeereid(), which lacks PID info, causing every imap-login
connection to register with anvil as pid=-1 and collide in its
per-process hash.
Here's an example fix for the problem. Note this was AI generated with
claude fable and I don't know what your AI policy is.
I am experiencing the same issue with 'pid=-1', like:
dovecot[34682]: anvil: Warning: conn unix:anvil (uid=0): Handshake with
duplicate service=imap-login pid=-1 - replacing the old connection
In src/lib/net.c I found:
#elif defined(HAVE_SYS_UCRED_H)
# include <sys/ucred.h> /* for FreeBSD struct xucred */
#endif
BTW: HAVE_SYS_UCRED_H can be found both in 2.3 and 2.4 src/lib/net.c but
*never* being used?!
Thus I patched src/lib/net.c as follows (highly inspired by yor patch):
--- src/lib/net.c.orig 2026-08-31 09:31:46.699701000 +0200
+++ src/lib/net.c 2026-08-31 09:45:40.751524000 +0200
@@ -832,6 +832,25 @@
cred_r->gid = ucred.unp_egid;
cred_r->pid = ucred.unp_pid;
return 0;
+#elif defined(HAVE_SYS_UCRED_H)
+ /* FreeBSD 13+, MidnightBSD 4+ (may also provide getpeereid, but we
also want pid) */
+ struct xucred ucred;
+ socklen_t len = sizeof(ucred);
+
+ if (getsockopt(fd, 0, LOCAL_PEERCRED, &ucred, &len) < 0) {
+ i_error("getsockopt(LOCAL_PEERCRED) failed: %m");
+ return -1;
+ }
+
+ if (ucred.cr_version != XUCRED_VERSION) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ cred_r->uid = ucred.cr_uid;
+ cred_r->gid = ucred.cr_gid;
+ cred_r->pid = ucred.cr_pid;
+ return 0;
#elif defined(HAVE_GETPEEREID)
/* OSX 10.4+, FreeBSD 4.6+, OpenBSD 3.0+, NetBSD 5.0+ */
if (getpeereid(fd, &cred_r->uid, &cred_r->gid) < 0) {
This runs perfectly well for the last 24 hours and all anvil: messages
disappeared.
Now, there are a couple of FreeBSD switches in src/lib/net.c waiting for
some cleanup as I assume ;-)
Thanks and regards,
Michael
There is also
https://github.com/dovecot/core/commit/ab03bf38b599a0fe22cb9b0b2a55470826800555.patch
now
Aki
References
Visible links
1. mailto:[email protected]
2. mailto:[email protected]
_______________________________________________
dovecot mailing list -- [email protected]
To unsubscribe send an email to [email protected]