rustpam

Rust import PAM C functions


I'm trying to figure out how to write a Linux PAM in Rust and I've started with this repo. When I compile it with --features libpam (which enables #[link(name="pam")] that imports external C functions), the compiler complains:

error: linking with `cc` failed: exit status: 1
...
note: /usr/bin/ld: cannot find -lpam: No such file or directory

Looking around SO, I've realized that the pam library was not found to be linked. However, I just cannot figure out how to either install it (I can find many libpam-something packages, but no libpam) or locate it such that I can indicate to the compiler/linker where to find it.

When I look into other crates that also work with PAM, they all import the C functions using #[link(name="pam")], and none specifies how to make it work.

I'm using Ubuntu 22.04.


Solution

  • The necessary headers for PAM library can be installed on Ubuntu as part of libpam0g-dev package (link for jammy):

    sudo apt install libpam0g-dev
    

    Debian package has the same name (so sudo apt-get install libpam0g-dev), CentOS uses pam-devel package for that (sudo yum install pam-devel).

    Alternatively, on any platform you can use the source code from github and follow the installation instructions from README.