TODO msg: start re-adding fd=passing with accrights
authorMichael Adam <obnox@samba.org>
Tue, 19 May 2015 23:35:20 +0000 (01:35 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 4 Sep 2015 16:02:54 +0000 (18:02 +0200)
source3/lib/msghdr.c

index de0eed46264b18adfc00a49775c14b175e5442c0..72e4b0945e799b4e023456d626815a506cf4b873 100644 (file)
 #include "lib/util/iov_buf.h"
 #include <sys/socket.h>
 
 #include "lib/util/iov_buf.h"
 #include <sys/socket.h>
 
+ #if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS)
+ # error Can not pass file descriptors
+ #endif
+
 ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
                        const int *fds, size_t num_fds)
 {
 ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
                        const int *fds, size_t num_fds)
 {
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
        size_t fds_size = sizeof(int) * MIN(num_fds, INT8_MAX);
        size_t cmsg_len = CMSG_LEN(fds_size);
        size_t cmsg_space = CMSG_SPACE(fds_size);
        size_t fds_size = sizeof(int) * MIN(num_fds, INT8_MAX);
        size_t cmsg_len = CMSG_LEN(fds_size);
        size_t cmsg_space = CMSG_SPACE(fds_size);
@@ -56,6 +61,27 @@ ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
        msg->msg_controllen = cmsg->cmsg_len;
 
        return cmsg_space;
        msg->msg_controllen = cmsg->cmsg_len;
 
        return cmsg_space;
+#else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
+
+       if (num_fds == 0) {
+               if (msg != NULL) {
+                       msg->msg_accrights = NULL;
+                       msg->msg_accrightslen = 0;
+               }
+               return 0;
+       }
+       if (num_fds > INT8_MAX) {
+               return -1;
+       }
+       if ((msg == NULL) || (num_fds > bufsize)) {
+               return num_fds;
+       }
+
+       msg->accrights = buf;
+       msg->accrights_len = num_fds;
+
+       return num_fds;
+#endif
 }
 
 struct msghdr_buf {
 }
 
 struct msghdr_buf {