Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FirefighterBlu3/python-pam
Python pam module supporting py3 (py2 support still exists but is deprecated)
https://github.com/FirefighterBlu3/python-pam
hacktoberfest hacktoberfest2021 linux pam pam-authentication python python3
Last synced: 5 days ago
JSON representation
Python pam module supporting py3 (py2 support still exists but is deprecated)
- Host: GitHub
- URL: https://github.com/FirefighterBlu3/python-pam
- Owner: FirefighterBlu3
- License: mit
- Created: 2014-08-03T16:54:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-11-28T12:39:16.000Z (12 months ago)
- Last Synced: 2024-04-26T19:47:14.830Z (7 months ago)
- Topics: hacktoberfest, hacktoberfest2021, linux, pam, pam-authentication, python, python3
- Language: Python
- Homepage:
- Size: 89.8 KB
- Stars: 104
- Watchers: 4
- Forks: 22
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# python-pam
Python pam module supporting py3 (and py2) for Linux type systems (!windows)
Commandline example:
```bash
[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:
```python
[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 toolIf 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
```