diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-03 14:28:44 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-03 15:14:45 -0700 |
| commit | afd555af4fba0acbf16c174dd9dece24181a1a38 (patch) | |
| tree | 9d49fec85c58ecad9a034a98e092627968494bc0 /src/transport | |
| parent | fa986e725f08e30eab68e16765b2cf71613b871c (diff) | |
| download | nng-afd555af4fba0acbf16c174dd9dece24181a1a38.tar.gz nng-afd555af4fba0acbf16c174dd9dece24181a1a38.tar.bz2 nng-afd555af4fba0acbf16c174dd9dece24181a1a38.zip | |
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.
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/ipc/ipc.c | 68 | ||||
| -rw-r--r-- | src/transport/ipc/ipc.h | 19 |
2 files changed, 87 insertions, 0 deletions
diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 3dbccb50..e5f3d533 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -537,6 +537,54 @@ nni_ipc_pipe_get_addr(void *arg, void *buf, size_t *szp, int typ) return (nni_copyout_sockaddr(&p->sa, buf, szp, typ)); } +static int +nni_ipc_pipe_get_peer_uid(void *arg, void *buf, size_t *szp, int typ) +{ + nni_ipc_pipe *p = arg; + uint64_t id; + int rv; + if ((rv = nni_plat_ipc_pipe_get_peer_uid(p->ipp, &id)) != 0) { + return (rv); + } + return (nni_copyout_u64(id, buf, szp, typ)); +} + +static int +nni_ipc_pipe_get_peer_gid(void *arg, void *buf, size_t *szp, int typ) +{ + nni_ipc_pipe *p = arg; + uint64_t id; + int rv; + if ((rv = nni_plat_ipc_pipe_get_peer_gid(p->ipp, &id)) != 0) { + return (rv); + } + return (nni_copyout_u64(id, buf, szp, typ)); +} + +static int +nni_ipc_pipe_get_peer_pid(void *arg, void *buf, size_t *szp, int typ) +{ + nni_ipc_pipe *p = arg; + uint64_t id; + int rv; + if ((rv = nni_plat_ipc_pipe_get_peer_pid(p->ipp, &id)) != 0) { + return (rv); + } + return (nni_copyout_u64(id, buf, szp, typ)); +} + +static int +nni_ipc_pipe_get_peer_zoneid(void *arg, void *buf, size_t *szp, int typ) +{ + nni_ipc_pipe *p = arg; + uint64_t id; + int rv; + if ((rv = nni_plat_ipc_pipe_get_peer_zoneid(p->ipp, &id)) != 0) { + return (rv); + } + return (nni_copyout_u64(id, buf, szp, typ)); +} + static void nni_ipc_ep_fini(void *arg) { @@ -785,6 +833,26 @@ static nni_tran_pipe_option nni_ipc_pipe_options[] = { .po_type = NNI_TYPE_SOCKADDR, .po_getopt = nni_ipc_pipe_get_addr, }, + { + .po_name = NNG_OPT_IPC_PEER_UID, + .po_type = NNI_TYPE_UINT64, + .po_getopt = nni_ipc_pipe_get_peer_uid, + }, + { + .po_name = NNG_OPT_IPC_PEER_GID, + .po_type = NNI_TYPE_UINT64, + .po_getopt = nni_ipc_pipe_get_peer_gid, + }, + { + .po_name = NNG_OPT_IPC_PEER_PID, + .po_type = NNI_TYPE_UINT64, + .po_getopt = nni_ipc_pipe_get_peer_pid, + }, + { + .po_name = NNG_OPT_IPC_PEER_ZONEID, + .po_type = NNI_TYPE_UINT64, + .po_getopt = nni_ipc_pipe_get_peer_zoneid, + }, // terminate list { .po_name = NULL, diff --git a/src/transport/ipc/ipc.h b/src/transport/ipc/ipc.h index 42cbdb08..497fb2b5 100644 --- a/src/transport/ipc/ipc.h +++ b/src/transport/ipc/ipc.h @@ -28,4 +28,23 @@ NNG_DECL int nng_ipc_register(void); // this for security. #define NNG_OPT_IPC_PERMISSIONS "ipc:permissions" +// Peer UID. This is only available on POSIX style systems. +#define NNG_OPT_IPC_PEER_UID "ipc:peer-uid" + +// Peer GID (primary group). This is only available on POSIX style systems. +#define NNG_OPT_IPC_PEER_GID "ipc:peer-gid" + +// Peer process ID. Available on Windows, Linux, and SunOS. +// In theory we could obtain this with the first message sent, +// but we have elected not to do this for now. (Nice RFE for a FreeBSD +// guru though.) +#define NNG_OPT_IPC_PEER_PID "ipc:peer-pid" + +// Peer Zone ID. Only on SunOS systems. (Linux containers have no +// definable kernel identity; they are a user-land fabrication made up +// from various pieces of different namespaces. FreeBSD does have +// something called JailIDs, but it isn't obvious how to determine this, +// or even if processes can use IPC across jail boundaries.) +#define NNG_OPT_IPC_PEER_ZONEID "ipc:peer-zoneid" + #endif // NNG_TRANSPORT_IPC_IPC_H |
