Python PAM module using ctypes, py3
Project description
python-pam
Python pam module supporting py3 (and py2) for Linux type systems (!windows)
Commandline example:
[david@Scott python-pam]$ python pam/pam.py
Username: david
Password:
Auth result: Success (0)
Pam Environment List item: XDG_SEAT=seat0
Pam Environment item: XDG_SEAT=seat0
Missing Pam Environment item: asdf=None
Open session: Success (0)
Close session: Success (0)
Inline examples:
[david@Scott python-pam]$ python
Python 3.9.7 (default, Oct 10 2021, 15:13:22)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pam
>>> p = pam.authenticate()
>>> p.authenticate('david', 'correctpassword')
True
>>> p.authenticate('david', 'badpassword')
False
>>> p.authenticate('david', 'correctpassword', service='login')
True
>>> p.authenticate('david', 'correctpassword', service='unknownservice')
False
>>> p.authenticate('david', 'correctpassword', service='login', resetcreds=True)
True
>>> p.authenticate('david', 'correctpassword', encoding='latin-1')
True
>>> print('{} {}'.format(p.code, p.reason))
0 Success
>>> p.authenticate('david', 'badpassword')
False
>>> print('{} {}'.format(p.code, p.reason))
7 Authentication failure
>>>
Authentication and privileges
Please note, python-pam and all tools that do authentication follow two rules:
- You have root (or privileged access): you can check any account's password for validity
- You don't have root: you can only check the validity of the username running the tool
If you need to authenticate multiple users, you must use an authentication stack that at some stage has privileged access. On Linux systems one example of doing this is using SSSD.
Typical Linux installations check against /etc/shadow
with pam_unix.so
which will spawn /usr/bin/unix_chkpwd
to verify the password. Both of these are intentionally written to meet the above two rules. You can test the functionality of unix_chkpwd
in the following manner:
Replace good
with the correct password, replace david
with your appropriate username.
~$ mkfifo /tmp/myfifo
~$ (echo -ne 'good\0' > /tmp/myfifo & /usr/bin/unix_chkpwd david nullok < /tmp/myfifo ) ; echo $?
0
~$ (echo -ne 'bad\0' > /tmp/myfifo & /usr/bin/unix_chkpwd david nullok < /tmp/myfifo ) ; echo $?
7
~$ (echo -ne 'good\0' > /tmp/myfifo & /usr/bin/unix_chkpwd someotheruser nullok < /tmp/myfifo ) ; echo $?
9
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-pam-2.0.2.tar.gz
.
File metadata
- Download URL: python-pam-2.0.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97235235ba9b82dbae8068d1099508455949b275f77273ca22fdbd8b1fb5d950 |
|
MD5 | 1ee6201b3a696d3e022d67643547496c |
|
BLAKE2b-256 | 6ada879f1c849e886b783239b8a4710daac73535ba2cfcf672ee4548543e3a74 |
File details
Details for the file python_pam-2.0.2-py3-none-any.whl
.
File metadata
- Download URL: python_pam-2.0.2-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac51dd8953ac59aa45505882b565eef6a22e0423dcf25d63369902080416c20 |
|
MD5 | 4b9adc75fa9638b7e8dd62f311f1bbc0 |
|
BLAKE2b-256 | 9b2d9fbb3bd686a474d76fbd0b79abdcc016f3da760b1d1c2048bf4c611a4939 |