Search code examples
pythonpamnon-interactive

Python PAM non-interactive authentication


I have modified the example python script:

service = 'passwd'

if len(sys.argv) == 3:
    user = sys.argv[1]
    password = sys.argv[2]
else:
    print 'error'

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!'

This works, but asks me to input the password. I would like instead to verify the password which is passed as a parameter (sys.argv[2]). Documentation is non-existant, so how should I do it?


Solution

  • When I was finding solution for interactive password prompt, I only found this solution python expect lib