Pergunta

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?

Foi útil?

Solução 2

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

Outras dicas

The example first lines are missing. The provided 'pam_conv' function asks the password to the user. You must define your own function returning a constant password:

def pam_conv(auth, query_list, userData):
    return [(the_password,0)]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top