From afd555af4fba0acbf16c174dd9dece24181a1a38 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 3 May 2018 14:28:44 -0700 Subject: fixes #383 Would like peerid for IPC We offer uid, gid, process id, and even zone id where we have them. Docs and tests are provided. --- tests/ipc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'tests/ipc.c') diff --git a/tests/ipc.c b/tests/ipc.c index 54996ee3..4c8f5e41 100644 --- a/tests/ipc.c +++ b/tests/ipc.c @@ -10,11 +10,76 @@ #include "convey.h" #include "trantest.h" +#ifdef _WIN32 +#else +#include +#ifdef NNG_HAVE_GETPEERUCRED +#include +#endif +#endif + +#include "transport/ipc/ipc.h" // Inproc tests. +static int +check_props(nng_msg *msg) +{ + nng_pipe p; + size_t z; + nng_sockaddr la; + nng_sockaddr ra; + uint64_t id; + + p = nng_msg_get_pipe(msg); + So(nng_pipe_id(p) > 0); + So(nng_pipe_getopt_sockaddr(p, NNG_OPT_LOCADDR, &la) == 0); + So(la.s_family == NNG_AF_IPC); + // untyped + z = sizeof(nng_sockaddr); + So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); + So(z == sizeof(ra)); + So(ra.s_family == NNG_AF_IPC); + + So(nng_pipe_getopt_size(p, NNG_OPT_REMADDR, &z) == NNG_EBADTYPE); + z = 1; + So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == NNG_EINVAL); + +#ifdef _WIN32 + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_UID, &id) == + NNG_ENOTSUP); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_GID, &id) == + NNG_ENOTSUP); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == + NNG_ENOTSUP); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_PID, &id) == 0); + So(id == GetCurrentProcessId()); +#else + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_UID, &id) == 0); + So(id == (uint64_t) getuid()); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_GID, &id) == 0); + So(id == (uint64_t) getgid()); + +#if defined(NNG_HAVE_SOPEERCRED) || defined(NNG_HAVE_GETPEERUCRED) + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_PID, &id) == 0); + So(id == (uint64_t) getpid()); +#else + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_PID, &id) == + NNG_ENOTSUP); +#endif + +#ifdef NNG_HAVE_GETPEERUCRED + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == 0); + So(id == getzoneid()); +#else + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == + NNG_ENOTSUP); +#endif +#endif + return (0); +} TestMain("IPC Transport", { - trantest_test_all("ipc:///tmp/nng_ipc_test_%u"); + trantest_test_extended("ipc:///tmp/nng_ipc_test_%u", check_props); nng_fini(); }) -- cgit v1.2.3-70-g09d2