Added support for handling passed access rights.
@@ -2127,6 +2127,41 @@ doURL(int sockfd, const void *buf, size_t len, enum metric_t src)
return 0;
}
+static int
+doAccessRights(struct msghdr *msg)
+{
+ int *recvfd;
+ struct cmsghdr *cmptr;
+ struct stat sbuf;
+
+ if (((cmptr = CMSG_FIRSTHDR(msg)) != NULL) &&
+ (cmptr->cmsg_len > 0) &&
+ (cmptr->cmsg_level == SOL_SOCKET) &&
+ (cmptr->cmsg_type == SCM_RIGHTS)) {
+ // voila; we have a new fd
+ int i, numfds;
+
+ numfds = (cmptr->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int);
+ if (numfds <= 0) return -1;
+ recvfd = ((int *) CMSG_DATA(cmptr));
+
+ for (i = 0; i < numfds; i++) {
+ // file or socket?
+ if (fstat(recvfd[i], &sbuf) != -1) {
+ if ((sbuf.st_mode & S_IFMT) == S_IFSOCK) {
+ doAddNewSock(recvfd[i]);
+ } else {
+ doOpen(recvfd[i], "Received_Access_Rights", FD, "recvmsg");
+ }
+ } else {
+ DBG("errno: %d", errno);
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
static int
doRecv(int sockfd, ssize_t rc)
{
@@ -4852,6 +4887,7 @@ recvmsg(int sockfd, struct msghdr *msg, int flags)
}
doRecv(sockfd, rc);
+ doAccessRights(msg);
} else {
doErrorMetric(NET_ERR_RX_TX, EVENT_BASED, "recvmsg", "nopath");
}
