Skip to content

Commit c84f693

Browse files
committed
Python: Adjust PamAuthorization examples
They did not have proper formatting (only 2 spaces), and I restructured them a bit more so they look like code in the wild
1 parent 0c53444 commit c84f693

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
def authenticate(self, username, password, service='login', encoding='utf-8', resetcreds=True):
2-
libpam = CDLL(find_library("pam"))
3-
pam_authenticate = libpam.pam_authenticate
4-
pam_authenticate.restype = c_int
5-
pam_authenticate.argtypes = [PamHandle, c_int]
6-
7-
8-
handle = PamHandle()
9-
conv = PamConv(my_conv, 0)
10-
retval = pam_start(service, username, byref(conv), byref(handle))
11-
12-
retval = pam_authenticate(handle, 0)
13-
return retval == 0
1+
libpam = CDLL(find_library("pam"))
2+
3+
pam_authenticate = libpam.pam_authenticate
4+
pam_authenticate.restype = c_int
5+
pam_authenticate.argtypes = [PamHandle, c_int]
6+
7+
def authenticate(username, password, service='login'):
8+
def my_conv(n_messages, messages, p_response, app_data):
9+
"""
10+
Simple conversation function that responds to any prompt where the echo is off with the supplied password
11+
"""
12+
...
13+
14+
handle = PamHandle()
15+
conv = PamConv(my_conv, 0)
16+
retval = pam_start(service, username, byref(conv), byref(handle))
17+
18+
retval = pam_authenticate(handle, 0)
19+
return retval == 0
Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
def authenticate(self, username, password, service='login', encoding='utf-8', resetcreds=True):
2-
libpam = CDLL(find_library("pam"))
3-
pam_authenticate = libpam.pam_authenticate
4-
pam_acct_mgmt = libpam.pam_acct_mgmt
5-
pam_authenticate.restype = c_int
6-
pam_authenticate.argtypes = [PamHandle, c_int]
7-
pam_acct_mgmt.restype = c_int
8-
pam_acct_mgmt.argtypes = [PamHandle, c_int]
9-
10-
handle = PamHandle()
11-
conv = PamConv(my_conv, 0)
12-
retval = pam_start(service, username, byref(conv), byref(handle))
1+
libpam = CDLL(find_library("pam"))
132

14-
retval = pam_authenticate(handle, 0)
15-
if retval == 0:
16-
retval = pam_acct_mgmt(handle, 0)
17-
return retval == 0
3+
pam_authenticate = libpam.pam_authenticate
4+
pam_authenticate.restype = c_int
5+
pam_authenticate.argtypes = [PamHandle, c_int]
6+
7+
pam_acct_mgmt = libpam.pam_acct_mgmt
8+
pam_acct_mgmt.restype = c_int
9+
pam_acct_mgmt.argtypes = [PamHandle, c_int]
10+
11+
def authenticate(username, password, service='login'):
12+
def my_conv(n_messages, messages, p_response, app_data):
13+
"""
14+
Simple conversation function that responds to any prompt where the echo is off with the supplied password
15+
"""
16+
...
17+
18+
handle = PamHandle()
19+
conv = PamConv(my_conv, 0)
20+
retval = pam_start(service, username, byref(conv), byref(handle))
21+
22+
retval = pam_authenticate(handle, 0)
23+
if retval == 0:
24+
retval = pam_acct_mgmt(handle, 0)
25+
return retval == 0

0 commit comments

Comments
 (0)