2

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?

user237251
  • 211
  • 1
  • 10
  • Whoops I didn't see this topic for a month, excuse that please. Undefined symbol means it can't find it as `extern C`. So you're on the right track, were you able to fix it? Did you see this guide here - https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/ctypes.open – Noitidart Jul 07 '16 at 22:16
  • you might find this submodule useful in your addons, it has ctyped a lot of stuff for all of the platforms - https://github.com/Noitidart/ostypes – Noitidart Jul 12 '16 at 20:02
  • 1
    Hi @Noitidart. I fixed this a few days after I first posed the question. Simply forgot answering it myself. Turned out I needed to explicitly link to libpam during the build process. Thanks for giving us ostypes, btw. I really enjoy using it. – user237251 Jul 20 '16 at 01:31
  • Thanks! I really am excited to hear you're using ostypes! :) If your work is public I would love to see how you're using it. I updated it last week, the mac and linux types had a bug in that they were dependent on variable of `core.os.*`. – Noitidart Jul 20 '16 at 01:37
  • Hey there! Are you Happy-Ferret from Github? You forked a lot of my stuff, which is cool! What are you up to? Are you up for some collaboration? I am currently needing some help to record system audio with DirectShow API. I am having troulbe with the documentation. I did pull off taking sound into Mic, and putting directly out to the speakers here - https://github.com/Noitidart/ostypes_playground/blob/audio-capture/bootstrap.js#L247-L615 – Noitidart Aug 25 '16 at 02:44
  • 1
    Indeed I am. :) I recently ran into some issues where repositories I had previously bookmarked/stared disappeared/were removed so I thought "better safe than sorry" and went on a nightly "fork spree". The plan is to build a hobby operating system targeting average users (designers, students, senior citizens, etc). For this, I'm using part of the Mozilla platform (Xulrunner, currently. Although I wish it wasn't deprecated, I'm more than willing to maintain it if possible). – user237251 Aug 27 '16 at 16:14
  • Haha that's funny! If you ever want to team up on some js-ctypes stuff let me know I would love to help out! That's aa cool idea! I wish XULRunner wasn't deprecated too :( If you want I can try to get you in touch with some people at Mozilla, so you can talk about why it was deprecated and if there are chances to bring it back. Or if there are alternatives planned. – Noitidart Aug 28 '16 at 01:08
  • 1
    Hey. Do you use gitter.im, by any chance? I'd love to move the conversation there. – user237251 Aug 28 '16 at 09:12
  • I don't but I can set it up. Would love to chat about this! Will let you know once I set it up. Edit: whoa that was easy I had set this up before it looks like, im signed in with my github account :) – Noitidart Aug 28 '16 at 11:03
  • Yep. It's straightforward, thanks to be integrated with Github. Just dropped you a private message over there. – user237251 Aug 28 '16 at 14:20

1 Answers1

4

Fixed it about a month ago. Turned out to be a linking problem. Here is how to properly compile it against libpam.

gcc -fPIC -c DM.c
gcc -shared -o DM.so DM.o -lpam
user237251
  • 211
  • 1
  • 10