From 98c9b21bcc781be27130c48cbbe1cd8b3ae854c2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Sep 2015 00:57:50 +0200 Subject: [PATCH 1/6] libreplace: Fix the build on Solaris Signed-off-by: Volker Lendecke --- lib/replace/replace.c | 2 +- lib/replace/wscript | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/replace/replace.c b/lib/replace/replace.c index 798990a..c9c12a4 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -829,7 +829,7 @@ int rep_clock_gettime(clockid_t clk_id, struct timespec *tp) struct timeval tval; switch (clk_id) { case 0: /* CLOCK_REALTIME :*/ -#ifdef HAVE_GETTIMEOFDAY_TZ +#if defined(HAVE_GETTIMEOFDAY_TZ) || defined(HAVE_GETTIMEOFDAY_TZ_VOID) gettimeofday(&tval,NULL); #else gettimeofday(&tval); diff --git a/lib/replace/wscript b/lib/replace/wscript index 9a8b7f7..0be52f7 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -506,6 +506,11 @@ removeea setea 'int gettimeofday(struct timeval *tv, struct timezone *tz)', define='HAVE_GETTIMEOFDAY_TZ', headers='sys/time.h') + conf.CHECK_C_PROTOTYPE('gettimeofday', + 'int gettimeofday(struct timeval *tv, void *tz)', + define='HAVE_GETTIMEOFDAY_TZ_VOID', + headers='sys/time.h') + conf.CHECK_CODE('#include "test/snprintf.c"', define="HAVE_C99_VSNPRINTF", execute=True, -- 1.9.1 From c70d08b6fa0851da215dcde74469b6ec553e2eef Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Sep 2015 00:58:00 +0200 Subject: [PATCH 2/6] lib: Fix the build on Solaris Signed-off-by: Volker Lendecke --- lib/util/time_basic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/time_basic.c b/lib/util/time_basic.c index e4b0886..8113bb5 100644 --- a/lib/util/time_basic.c +++ b/lib/util/time_basic.c @@ -29,7 +29,7 @@ a gettimeofday wrapper **/ _PUBLIC_ void GetTimeOfDay(struct timeval *tval) { -#ifdef HAVE_GETTIMEOFDAY_TZ +#if defined(HAVE_GETTIMEOFDAY_TZ) || defined(HAVE_GETTIMEOFDAY_TZ_VOID) gettimeofday(tval,NULL); #else gettimeofday(tval); -- 1.9.1 From ca287d9b6fb8c893c8e1ec3e76bf27ffb633e3ab Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Sep 2015 00:35:45 +0200 Subject: [PATCH 3/6] lib: We only need the fd-passing check once unix_dgram_send will tell us as well Bug: https://bugzilla.samba.org/show_bug.cgi?id=11053 Signed-off-by: Volker Lendecke --- source3/lib/unix_msg/unix_msg.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 0baaa9d..782748b 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -798,12 +798,6 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, return EINVAL; } -#ifndef HAVE_STRUCT_MSGHDR_MSG_CONTROL - if (num_fds > 0) { - return ENOSYS; - } -#endif /* ! HAVE_STRUCT_MSGHDR_MSG_CONTROL */ - if (num_fds > INT8_MAX) { return EINVAL; } -- 1.9.1 From 0f42209787b4ba27501f404b3a58d8c765f15ea2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Sep 2015 00:46:33 +0200 Subject: [PATCH 4/6] lib: Move some routines around in msghdr.c This way we only need one #ifdef for ACCRIGHTS Bug: https://bugzilla.samba.org/show_bug.cgi?id=1105 Signed-off-by: Volker Lendecke --- source3/lib/msghdr.c | 96 ++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/source3/lib/msghdr.c b/source3/lib/msghdr.c index de0eed4..d89b7c1 100644 --- a/source3/lib/msghdr.c +++ b/source3/lib/msghdr.c @@ -58,6 +58,54 @@ ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, return cmsg_space; } +size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, + size_t num_fds) +{ + size_t ret = CMSG_SPACE(sizeof(int) * num_fds); + + if (bufsize < ret) { + return ret; + } + if (msg != NULL) { + if (num_fds != 0) { + msg->msg_control = buf; + msg->msg_controllen = ret; + } else { + msg->msg_control = NULL; + msg->msg_controllen = 0; + } + } + return ret; +} + +size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size) +{ + struct cmsghdr *cmsg; + size_t num_fds; + + for(cmsg = CMSG_FIRSTHDR(msg); + cmsg != NULL; + cmsg = CMSG_NXTHDR(msg, cmsg)) + { + if ((cmsg->cmsg_type == SCM_RIGHTS) && + (cmsg->cmsg_level == SOL_SOCKET)) { + break; + } + } + + if (cmsg == NULL) { + return 0; + } + + num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int); + + if ((num_fds != 0) && (fds != NULL) && (fds_size >= num_fds)) { + memcpy(fds, CMSG_DATA(cmsg), num_fds * sizeof(int)); + } + + return num_fds; +} + struct msghdr_buf { struct msghdr msg; struct sockaddr_storage addr; @@ -130,51 +178,3 @@ struct msghdr *msghdr_buf_msghdr(struct msghdr_buf *msg) { return &msg->msg; } - -size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, - size_t num_fds) -{ - size_t ret = CMSG_SPACE(sizeof(int) * num_fds); - - if (bufsize < ret) { - return ret; - } - if (msg != NULL) { - if (num_fds != 0) { - msg->msg_control = buf; - msg->msg_controllen = ret; - } else { - msg->msg_control = NULL; - msg->msg_controllen = 0; - } - } - return ret; -} - -size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size) -{ - struct cmsghdr *cmsg; - size_t num_fds; - - for(cmsg = CMSG_FIRSTHDR(msg); - cmsg != NULL; - cmsg = CMSG_NXTHDR(msg, cmsg)) - { - if ((cmsg->cmsg_type == SCM_RIGHTS) && - (cmsg->cmsg_level == SOL_SOCKET)) { - break; - } - } - - if (cmsg == NULL) { - return 0; - } - - num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int); - - if ((num_fds != 0) && (fds != NULL) && (fds_size >= num_fds)) { - memcpy(fds, CMSG_DATA(cmsg), num_fds * sizeof(int)); - } - - return num_fds; -} -- 1.9.1 From e90232a50969424699580ab2226020a04be0d4d6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Sep 2015 00:54:42 +0200 Subject: [PATCH 5/6] lib: Support fd passing using the 4.3BSD way This is required on Solaris Bug: https://bugzilla.samba.org/show_bug.cgi?id=1105 Signed-off-by: Volker Lendecke --- source3/lib/msghdr.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/source3/lib/msghdr.c b/source3/lib/msghdr.c index d89b7c1..2aa2f2e 100644 --- a/source3/lib/msghdr.c +++ b/source3/lib/msghdr.c @@ -21,6 +21,8 @@ #include "lib/util/iov_buf.h" #include +#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) + ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, const int *fds, size_t num_fds) { @@ -106,6 +108,84 @@ size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size) return num_fds; } +#elif defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS) + +ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, + const int *fds, size_t num_fds) +{ + size_t needed; + + if (num_fds > INT8_MAX) { + return -1; + } + + needed = sizeof(int) * num_fds; + + if ((msg == NULL) || (needed > bufsize)) { + return needed; + } + + memcpy(buf, fds, needed); + + msg->msg_accrights = (caddr_t) buf; + msg->msg_accrightslen = needed; + + return needed; +} + +size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, + size_t num_fds) +{ + size_t ret = num_fds * sizeof(int); + + if (bufsize < ret) { + return ret; + } + + if (msg != NULL) { + if (num_fds != 0) { + msg->msg_accrights = (caddr_t) buf; + msg->msg_accrightslen = ret; + } else { + msg->msg_accrights = NULL; + msg->msg_accrightslen = 0; + } + } + return ret; +} + +size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size) +{ + size_t num_fds = msg->msg_accrightslen / sizeof(int); + + if ((fds != 0) && (num_fds <= fds_size)) { + memcpy(fds, msg->msg_accrights, msg->msg_accrightslen); + } + + return num_fds; +} + +#else + +ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, + const int *fds, size_t num_fds) +{ + return -1; +} + +size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize, + size_t num_fds) +{ + return 0; +} + +size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size) +{ + return 0; +} + +#endif + struct msghdr_buf { struct msghdr msg; struct sockaddr_storage addr; -- 1.9.1 From d9e3c5688699b3170ef25434fac997cdd1c0dbdc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Sep 2015 00:36:23 +0200 Subject: [PATCH 6/6] lib: We can do ACCRIGHTS style fdpassing Bug: https://bugzilla.samba.org/show_bug.cgi?id=1105 Signed-off-by: Volker Lendecke --- source3/lib/unix_msg/unix_msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 782748b..3221133 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -572,11 +572,11 @@ static int unix_dgram_send(struct unix_dgram_ctx *ctx, return EINVAL; } -#ifndef HAVE_STRUCT_MSGHDR_MSG_CONTROL +#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS) if (num_fds > 0) { return ENOSYS; } -#endif /* ! HAVE_STRUCT_MSGHDR_MSG_CONTROL */ +#endif for (i = 0; i < num_fds; i++) { /* -- 1.9.1