Why does implementing a python module for freeradius fails with error "libpython2.7.so: cannot open shared object file" ?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7.2
  • freeradius-python-3.0.4-6.el7

Issue

  • Implementing a python module for freeradius fails with error:
 Failed loading libpython symbols into global symbol table: libpython2.7.so: cannot open shared object file: No such file or directory

Resolution

  • Install python-devel rpm which provides dependency library libpython2.7.so.

Root Cause

  • from source code file freeradius-server/src/modules/rlm_python/rlm_python.c; explicitly load libpython, so symbols will be available to lib-dynload modules
if (python_instances == 0) {
        INFO("Python version: %s", Py_GetVersion());

        python_dlhandle = dlopen("libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) ".so",
                     RTLD_NOW | RTLD_GLOBAL);
        if (!python_dlhandle) WARN("Failed loading libpython symbols into global symbol table: %s", dlerror());

Diagnostic Steps

  • Python module for freeradius (without python-devel package install)
# radiusd -X
[...]
  # Loaded module rlm_python
  # Instantiating module "python" from file /etc/raddb/mods-enabled/python
  python {
    mod_instantiate = "example"
    mod_authorize = "example"
    mod_authenticate = "example"
    mod_preacct = "example"
    mod_accounting = "example"
    mod_checksimul = "example"
    mod_pre_proxy = "example"
    mod_post_proxy = "example"
    mod_post_auth = "example"
    mod_recv_coa = "example"
    mod_send_coa = "example"
    mod_detach = "example"
  }
Failed loading libpython symbols into global symbol table: libpython2.7.so: cannot open shared object file: No such file or directory
mod_init done
  • libpython2.7.so library is provided by python-devel rpm.
[root@dhcp5-123 ~]# rpm -qf /usr/lib64/libpython2.7.so
python-devel-2.7.5-34.el7.x86_64

[root@dhcp5-123 ~]# rpm -qf /usr/lib64/libpython2.7.so.1.0 
python-libs-2.7.5-34.el7.x86_64
  • After installing the python-devel rpm, python module gets loaded successfully:
# radiusd -X
[...]
  # Instantiating module "python" from file /etc/raddb/mods-enabled/python
  python {
    mod_instantiate = "example"
    mod_authorize = "example"
    mod_authenticate = "example"
    mod_preacct = "example"
    mod_accounting = "example"
    mod_checksimul = "example"
    mod_pre_proxy = "example"
    mod_post_proxy = "example"
    mod_post_auth = "example"
    mod_recv_coa = "example"
    mod_send_coa = "example"
    mod_detach = "example"
  }
mod_init done

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments