A library that simplifies reading peer credentials from Unix domain sockets
Project description
unix_cred
A Python library that simplifies reading peer credentials from Unix domain sockets.
Installation
$ pip install unix-cred
Examples
>>> import os
>>> import socket
>>> import unix_cred
>>> server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> server.bind("/tmp/unix_cred-test")
>>> server.listen(1)
>>> cli = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> cli.connect("/tmp/unix_cred-test")
>>> server_cli = server.accept()[0]
>>> # Check the peer credentials on each end against the current process's
>>> assert unix_cred.get_peer_uid_gid(cli) == (os.geteuid(), os.getegid())
>>> assert unix_cred.get_peer_uid_gid(server_cli) == (os.geteuid(), os.getegid())
>>> # Not supported on all systems
>>> # On some systems this function is not defined; on certain versions of other systems
>>> # it may return None for the PID
>>> assert unix_cred.get_peer_pid_uid_gid(cli) == (os.getpid(), os.geteuid(), os.getegid())
>>> assert unix_cred.get_peer_pid_uid_gid(server_cli) == (os.getpid(), os.geteuid(), os.getegid())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
unix_cred-0.2.0.tar.gz
(7.1 kB
view hashes)
Built Distribution
unix_cred-0.2.0-py3-none-any.whl
(10.8 kB
view hashes)
Close
Hashes for unix_cred-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4ae2e552f1865b38bc0c6d682569a6fde92c19790ce92c23111cae6811f4265 |
|
MD5 | 764b6ccec0895546b4beb4a1ca0fd393 |
|
BLAKE2b-256 | 4ff39335886f04ab5652ee4d9c683a77220d17de5b99db60ee19be2ec5d3311c |