1

I try to create a python script to check the password instead of my computer, So i use python-pam for that. The problem is that i don't know how i can use my script in the common-auth file.

I tried this:

auth    required                        /home/gamzer/test-python-pam.py

But it tells me this:

sudo: PAM unable to dlopen(/home/gamzer/test-python-pam.py): /home/gamzer/test-python-pam.py: invalid ELF header

Here's my script:

import pam
from getpass import getuser, getpass

if pam.authenticate(getuser(), getpass()):
        print 'ok'
else:
        print 'not ok'
Gamliel Cohen
  • 138
  • 3
  • 15

2 Answers2

2

First off - you cannot use python code as a PAM module, it has to be compiled code that satisfies certain interface requirements. See here for more info.

Also - what you are trying here seems circular, using PAM itself to implement PAM functionality.

dngrs
  • 269
  • 1
  • 4
  • maybe I can use a wrapper or a compiler of some sort in order to use python? this one seems to use python with pam https://github.com/Boltgolt/howdy – Gamliel Cohen Dec 18 '18 at 08:49
0

Are you trying to

  1. use PAM to check a password in a python program that needs to verify a password, or

  2. implement a new authentication method for the system to use?

In case #2, @dngrs is exactly right--you can't do it that way.

In case #1, you don't need anything in the common-auth file. Also, to check a password in your Python code, I think you need to create a PAM object, so it would look more like this:

import pam
from getpass import getuser, getpass

p = pam.pam()
if p.authenticate(getuser(), getpass()):
    print 'ok'
else:
    print 'not ok'

as shown in the python-pam README

Win
  • 551
  • 2
  • 5