Having recently fallen in love with js-ctypes (really handy for writing small applications that need access to some underlying OS functionality), I'm attempting to use them for a small login manager prototype where I'd like to expose PAM.
For this, I've been following a GNU/Linux display manager tutorial, compiling the pam.c file found in its Github ^1 repository and calling login(const char *username, const char *password, pid_t *child_pid)
from my javascript code.
I used the following commands to compile the library :
- gcc -fPIC -c pam.c
- gcc -shared -o pam.so pam.o
The javascript calling code is as follows (user and pw are two textboxes defined in XUL):
function login(user, pw) {
var {ctypes} = Components.utils.import("resource://gre/modules/ctypes.jsm", null);
Components.utils.import("resource://gre/modules/Services.jsm");
var cr = Components.classes['@mozilla.org/chrome/chrome-registry;1'].getService(Components.interfaces.nsIChromeRegistry);
var chromeURI_myLib = Services.io.newURI('chrome://app/content/lib/pam.so', 'UTF-8', null);
var localFile_myLib = cr.convertChromeURL(chromeURI_myLib);
var jarPath_myLib = localFile_myLib.spec;
var filePath_myLib = localFile_myLib.path;
var libc = ctypes.open(filePath_myLib);
/* Import a function */
var loginFunc = libc.declare("login", /* function name */
ctypes.default_abi, /* call ABI */
ctypes.int,
ctypes.char.ptr,
ctypes.char.ptr);
loginFunc(user, pw);
}
Unfortunately, when running the application and calling this function, the application quits with the following error message
symbol lookup error: /login-manager/chrome/content/lib/pam.so: undefined symbol: pam_start
pam_start is defined outside the scope of the pam.c/pam.h provided with the tutorial. It's definition can be found inside /usr/lib/security/pam_appl.h
. How can I alleviate this fact and create a shared object that will let me properly call the login()
and logout()
functions provided as part of the original tutorial^2?