Created
February 22, 2012 00:47
-
-
Save medigeek/1880253 to your computer and use it in GitHub Desktop.
Idea for timekpr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# sudo ./pamtest.py <username> | |
# If your run this as root, you don't need authentication. | |
# Perfect for True or False (if user is allowed to login or not) | |
import sys | |
import PAM | |
from getpass import getpass | |
def pam_conv(auth, query_list, userData): | |
resp = [] | |
for i in range(len(query_list)): | |
query, type = query_list[i] | |
if type == PAM.PAM_PROMPT_ECHO_ON: | |
val = raw_input(query) | |
resp.append((val, 0)) | |
elif type == PAM.PAM_PROMPT_ECHO_OFF: | |
val = getpass(query) | |
resp.append((val, 0)) | |
elif type == PAM.PAM_PROMPT_ERROR_MSG or type == PAM.PAM_PROMPT_TEXT_INFO: | |
print query | |
resp.append(('', 0)) | |
else: | |
return None | |
return resp | |
service = 'login' | |
if len(sys.argv) == 2: | |
user = sys.argv[1] | |
else: | |
#user = None | |
exit("Usage: ./pamtest.py <username>") | |
auth = PAM.pam() | |
auth.start(service) | |
if user != None: | |
auth.set_item(PAM.PAM_USER, user) | |
auth.set_item(PAM.PAM_CONV, pam_conv) | |
try: | |
#auth.authenticate() | |
auth.acct_mgmt() | |
except PAM.error, resp: | |
print 'Go away! (%s)' % resp | |
except: | |
print 'Internal error' | |
else: | |
print 'Good to go!' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment