[exim-cvs] Unix socket creds definitions for BSD-ish platfor…

トップ ページ
このメッセージを削除
このメッセージに返信
著者: Exim Git Commits Mailing List
日付:  
To: exim-cvs
題目: [exim-cvs] Unix socket creds definitions for BSD-ish platforms
Gitweb: https://git.exim.org/exim.git/commitdiff/f254e59264330fee415229fe8af2fa974d1d3a10
Commit:     f254e59264330fee415229fe8af2fa974d1d3a10
Parent:     8f9adfd36222d4e9e730734e00dffe874073e5b4
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Wed Feb 19 13:54:59 2020 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Wed Feb 19 13:59:32 2020 +0000


    Unix socket creds definitions for BSD-ish platforms
---
 src/src/daemon.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)


diff --git a/src/src/daemon.c b/src/src/daemon.c
index a6980e9..265ee2b 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -992,7 +992,7 @@ where = US"socket";
if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0)
goto bad;
#else
-if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0))) < 0)
+if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
goto bad;
(void)fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
#endif
@@ -1049,18 +1049,34 @@ DEBUG(D_queue_run) debug_printf("%s from addr%s '%s'\n", __FUNCTION__,
*sun.sun_path ? "" : " abstract", sun.sun_path+ (*sun.sun_path ? 0 : 1));

/* Refuse to handle the item unless the peer has good credentials */
+#ifdef SCM_CREDENTIALS
+# define EXIM_SCM_CR_TYPE SCM_CREDENTIALS
+#elif defined(SCM_CREDS)
+# define EXIM_SCM_CR_TYPE SCM_CREDS
+#else
+# error no SCM creds knowlege
+#endif

 for (struct cmsghdr * cp = CMSG_FIRSTHDR(&msg);
      cp;
      cp = CMSG_NXTHDR(&msg, cp))
-  if (cp->cmsg_level == SOL_SOCKET && cp->cmsg_type == SCM_CREDENTIALS)
+  if (cp->cmsg_level == SOL_SOCKET && cp->cmsg_type == EXIM_SCM_CR_TYPE)
   {
+#ifdef SCM_CREDENTIALS
   struct ucred * cr = (struct ucred *) CMSG_DATA(cp);
   if (cr->uid && cr->uid != exim_uid)
     {
     DEBUG(D_queue_run) debug_printf("%s: sender creds pid %d uid %d gid %d\n",
       __FUNCTION__, (int)cr->pid, (int)cr->uid, (int)cr->gid);
     return FALSE;
+#elif defined(SCM_CREDS)
+  struct cmsgcred * cr = (struct cmsgcred *) CMSG_DATA(cp);
+  if (cr->cmcred_uid && cr->cmcred_uid != exim_uid)
+    {
+    DEBUG(D_queue_run) debug_printf("%s: sender creds pid %d uid %d gid %d\n",
+      __FUNCTION__, (int)cr->cmcred_pid, (int)cr->cmcred_uid, (int)cr->cmcred_gid);
+    return FALSE;
+#endif
     }
   break;
   }
@@ -1085,7 +1101,8 @@ switch (buf[0])
     DEBUG(D_queue_run)
       debug_printf("%s: queue size request: %s\n", __FUNCTION__, buf);


-    if (sendto(daemon_notifier_fd, buf, len, 0, &sun, msg.msg_namelen) < 0)
+    if (sendto(daemon_notifier_fd, buf, len, 0,
+        (const struct sockaddr *)&sun, msg.msg_namelen) < 0)
       log_write(0, LOG_MAIN|LOG_PANIC,
     "%s: sendto: %s\n", __FUNCTION__, strerror(errno));
     return FALSE;