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.
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 0 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.1.0.tar.gz
(6.5 kB
view hashes)
Built Distribution
unix_cred-0.1.0-py3-none-any.whl
(10.4 kB
view hashes)
Close
Hashes for unix_cred-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22810a766de624862492ac5b6fe965e80498bbe5e345a8aa0b4564146ef8db35 |
|
MD5 | fff00017e7edb42afbf7e207c43559cd |
|
BLAKE2b-256 | 353d26296953f4a4549ad330d317167e92625b35546040f0015b8e32a548381a |