diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-09-26 14:11:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 14:11:40 +0100 |
commit | 12430a51e53dda659bd1e7136afeacf6bd2b8695 (patch) | |
tree | 4664dc9bbaa015f53291418eb7084a927e0a90e1 | |
parent | 60cd96905a9eab257074634a18aae8c711d62293 (diff) | |
parent | e648f720d3f9d6ecc8b335f5e7aa15f15b62317a (diff) | |
download | rspamd-12430a51e53dda659bd1e7136afeacf6bd2b8695.tar.gz rspamd-12430a51e53dda659bd1e7136afeacf6bd2b8695.zip |
Merge pull request #4283 from BtbN/fix_unix_fuzzy
[Fix] Allow fuzzy worker to listen on AF_UNIX sockets successfully
-rw-r--r-- | src/fuzzy_storage.c | 3 | ||||
-rw-r--r-- | src/libutil/addr.c | 27 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 385018565..8dc27e4b4 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -363,6 +363,9 @@ rspamd_fuzzy_check_write (struct fuzzy_session *session) } if (session->ctx->update_ips != NULL && session->addr) { + if (rspamd_inet_address_get_af (session->addr) == AF_UNIX) { + return TRUE; + } if (rspamd_match_radix_map_addr (session->ctx->update_ips, session->addr) == NULL) { return FALSE; diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 2e32d4bd1..71879e357 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -1060,6 +1060,19 @@ rspamd_inet_address_connect (const rspamd_inet_addr_t *addr, gint type, if (addr->af == AF_UNIX) { sa = (const struct sockaddr *)&addr->u.un->addr; + + if (type == (int)SOCK_DGRAM) { + struct sockaddr ca; + + memset (&ca, 0, sizeof(ca)); + ca.sa_family = AF_UNIX; + + r = bind (fd, &ca, sizeof (sa_family_t)); + if (r == -1) { + msg_info ("unix socket client autobind failed: %s, '%s'", + addr->u.un->addr.sun_path, strerror (errno)); + } + } } else { sa = &addr->u.in.addr.sa; @@ -1667,7 +1680,8 @@ rspamd_inet_address_from_sa (const struct sockaddr *sa, socklen_t slen) rspamd_inet_addr_t *addr; g_assert (sa != NULL); - g_assert (slen >= sizeof (struct sockaddr)); + /* Address of an AF_UNIX socket can be tiny */ + g_assert (slen >= sizeof (sa_family_t) + 1); addr = rspamd_inet_addr_create (sa->sa_family, NULL); @@ -1676,12 +1690,13 @@ rspamd_inet_address_from_sa (const struct sockaddr *sa, socklen_t slen) const struct sockaddr_un *un = (const struct sockaddr_un *)sa; g_assert (slen >= SUN_LEN (un)); + g_assert (slen <= sizeof (addr->u.un->addr)); - rspamd_strlcpy (addr->u.un->addr.sun_path, un->sun_path, - sizeof (addr->u.un->addr.sun_path)); -#if defined(FREEBSD) || defined(__APPLE__) - addr->u.un->addr.sun_len = un->sun_len; -#endif + /* sun_path can legally contain intermittent NULL bytes */ + memcpy (&addr->u.un->addr, un, slen); + + /* length of AF_UNIX addresses is variable */ + addr->slen = slen; } else if (sa->sa_family == AF_INET) { g_assert (slen >= sizeof (struct sockaddr_in)); |