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.1.tar.gz
(5.9 kB
view details)
Built Distribution
File details
Details for the file unix_cred-0.2.1.tar.gz
.
File metadata
- Download URL: unix_cred-0.2.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f147d35df7a6bf3b6bdcbef300a93acdb3ec59a887c3101a5920e67b9f4734f4 |
|
MD5 | cbcc1f1c225438b59c88d47815e28bed |
|
BLAKE2b-256 | 53f822c5302a7df8b698c8f439008714cb5f78b3531a5a71ba64653adda74c92 |
File details
Details for the file unix_cred-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: unix_cred-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5b4102a8ac720da0224ef2689973d3231526c62fde23194ca8303c47fb2941 |
|
MD5 | 3d345acd85fc7333da3f6db73ff29519 |
|
BLAKE2b-256 | c0757daa846210090c79db42b761da72580bae4bc4b9970bfedd264751b5c1fb |