0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 07:31:03 +08:00

Fix failing test case in test_filter_ipc.

Add explicit check for primary group.
This commit is contained in:
Brandon Carpenter 2013-12-06 00:46:14 -08:00
parent f5b6bd70f3
commit af808203d7
3 changed files with 27 additions and 5 deletions

View File

@ -170,7 +170,6 @@ case "${host_os}" in
fi
AC_DEFINE(ZMQ_HAVE_LINUX, 1, [Have Linux OS])
libzmq_on_linux="yes"
AC_CHECK_DECLS([SO_PEERCRED], [AC_DEFINE(ZMQ_HAVE_SO_PEERCRED, 1, [Have SO_PEERCRED socket option])], [], [#include <sys/socket.h>])
if test "x$libzmq_tipc_support" = "xyes"; then
AC_DEFINE(ZMQ_HAVE_TIPC, 1, [Have TIPC support])
@ -216,7 +215,6 @@ case "${host_os}" in
libzmq_pedantic="no"
libzmq_werror="no"
AC_DEFINE(ZMQ_HAVE_OSX, 1, [Have DarwinOSX OS])
AC_CHECK_DECLS([LOCAL_PEERCRED], [AC_DEFINE(ZMQ_HAVE_LOCAL_PEERCRED, 1, [Have LOCAL_PEERCRED socket option])], [], [#include <sys/socket.h>])
AC_LANG_PUSH([C++])
LIBZMQ_CHECK_LANG_FLAG_PREPEND([-Wno-uninitialized])
AC_LANG_POP([C++])
@ -351,6 +349,9 @@ if test "x$zmq_disable_eventfd" != "xyes"; then
[AC_DEFINE(ZMQ_HAVE_EVENTFD, 1, [Have eventfd extension.])])
fi
AC_CHECK_DECLS([SO_PEERCRED], [AC_DEFINE(ZMQ_HAVE_SO_PEERCRED, 1, [Have SO_PEERCRED socket option])], [], [#include <sys/socket.h>])
AC_CHECK_DECLS([LOCAL_PEERCRED], [AC_DEFINE(ZMQ_HAVE_LOCAL_PEERCRED, 1, [Have LOCAL_PEERCRED socket option])], [], [#include <sys/socket.h>])
# Use c++ in subsequent tests
AC_LANG_PUSH(C++)

View File

@ -215,6 +215,7 @@ bool zmq::ipc_listener_t::filter (fd_t sock)
if (getsockopt (sock, SOL_SOCKET, SO_PEERCRED, &cred, &size))
return false;
if (options.ipc_uid_accept_filters.find (cred.uid) != options.ipc_uid_accept_filters.end () ||
options.ipc_gid_accept_filters.find (cred.gid) != options.ipc_gid_accept_filters.end () ||
options.ipc_pid_accept_filters.find (cred.pid) != options.ipc_pid_accept_filters.end ())
return true;
@ -227,9 +228,10 @@ bool zmq::ipc_listener_t::filter (fd_t sock)
it != options.ipc_gid_accept_filters.end (); it++) {
if (!(gr = getgrgid (*it)))
continue;
for (char **mem = gr->gr_mem; *mem; mem++)
for (char **mem = gr->gr_mem; *mem; mem++) {
if (!strcmp (*mem, pw->pw_name))
return true;
}
}
return false;
}

View File

@ -20,6 +20,9 @@
#include <string.h>
#include <sys/types.h>
#include <string>
#include <sstream>
#include "testutil.hpp"
static void bounce_fail (void *server, void *client)
@ -52,6 +55,8 @@ static void bounce_fail (void *server, void *client)
template <class T>
static void run_test (int opt, T optval, int expected_error, int bounce_test)
{
int rc;
void *ctx = zmq_ctx_new ();
assert (ctx);
@ -59,7 +64,7 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
assert (sb);
if (opt) {
int rc = zmq_setsockopt(sb, opt, &optval, sizeof (optval));
rc = zmq_setsockopt(sb, opt, &optval, sizeof (optval));
if (expected_error) {
assert (rc == -1);
assert (zmq_errno () == expected_error);
@ -71,6 +76,20 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
void *sc = zmq_socket (ctx, ZMQ_PAIR);
assert (sc);
// If a test fails, don't hang for too long
int timeout = 1500;
rc = zmq_setsockopt (sb, ZMQ_RCVTIMEO, &timeout, sizeof (int));
assert (rc == 0);
rc = zmq_setsockopt (sb, ZMQ_SNDTIMEO, &timeout, sizeof (int));
assert (rc == 0);
rc = zmq_setsockopt (sc, ZMQ_RCVTIMEO, &timeout, sizeof (int));
assert (rc == 0);
rc = zmq_setsockopt (sc, ZMQ_SNDTIMEO, &timeout, sizeof (int));
assert (rc == 0);
int interval = -1;
rc = zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int));
assert (rc == 0);
if (bounce_test) {
int rc = zmq_bind (sb, "ipc://@/tmp/test");
assert (rc == 0);
@ -87,7 +106,7 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
close_zero_linger (sc);
close_zero_linger (sb);
int rc = zmq_ctx_term (ctx);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
}