#200 port authpam.py to new python-pam version
Closed: Fixed None Opened 6 years ago by jdennis.

F23 introduced a major new version of python-pam. F22 to F23 rebased python-pam from 0.1.4 to 1.8.2.

In 0.1.4 the authenticate() call is a module level function. In 1.8.2 authenticate() is a method call belonging to the new pam class.

We can tell which pam module we've loaded because the new 1.8.2 version exports the version module variable, the earlier 0.1.4 version does not export a version symbol.

The new authenticate() method shares the same 3 parameters as the old function. We just need to ascertain which module we've loaded and setup either a function pointer to call through or a dummy pam class providing the authenticate() method via the authenticate function.

After a bit of research there is a better way to obtain the version by using pkg_resources, a standard Python module in distutils. It's smart enough to look in the egg info and various other places to find a package version. You just need to give it the name of the package, unfortunately not only did the API change in version 1.8.2 but it's python name also changed from "pam" to "python-pam".

The following code snippet can be used to identify the major and minor version of the pam module and should work in most contexts:

import pkg_resources

    py_pam_version = pkg_resources.get_distribution('python-pam').version
except pkg_resources.DistributionNotFound:
        py_pam_version = pkg_resources.get_distribution('pam').version
    except pkg_resources.DistributionNotFound:
        raise ImportError('cannot identity python pam module version')

py_pam_major_version, py_pam_minor_version = \
  map(int, py_pam_version.split('.')[0:2])

Fields changed

owner: => jdennis
status: new => assigned

Fields changed

owner: jdennis => cascardo

This has been fixed with 54ab11c .

resolution: => fixed
status: assigned => closed

Metadata Update from @puiterwijk:
- Issue assigned to cascardo

5 years ago

Login to comment on this ticket.