summaryrefslogtreecommitdiffstats
path: root/debian/tests/pam-test.py
blob: 0024ca5c2e729fe88d0d4e68cc1c7a78c5f05c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python3
# Copyright 2023, Sam Hartman
# This code may be redistributed under the same terms as Linux Pam
# itself, or at your pution, under the GNU General Public License,
# version 3. 


import PAM

def conversation(auth, queries, userdata):
    results = []
    for prompt, type in queries:
        if type == PAM.PAM_PROMPT_ECHO_OFF:
            results.append(('ThisLongPasswordIsHardCoded', 0))
        else: results.append(('',0))
    return results
# set a password

auth = PAM.pam()
auth.start('passwd')
auth.set_item(PAM.PAM_USER, 'pam_test')
auth.set_item(PAM.PAM_CONV, conversation)
auth.chauthtok()

# Now authenticate and session
auth = PAM.pam()
auth.start('login')
auth.set_item(PAM.PAM_USER, 'pam_test')
auth.set_item(PAM.PAM_CONV, conversation)
auth.authenticate()
auth.acct_mgmt()
auth.open_session()
auth.close_session()