as my related question doesn't seem to get much love, here another one: What's the proper way to authenticate a user via username/password prompt in Linux nowadays?
In principle, I suppose I would have to obtain username and password, read salt and hash of the corresponding user from /etc/shadow. I would then calculate the hash of the given password and the stored salt and check if the result matches the hash stored in /etc/shadow.
Normally, I could simply authenticate via PAM (e.g. pam_unix) which does all this already but my application is a custom PAM module and I found no method to call one PAM module from another. If this is possible somehow, I'd gladly go for this solution.
As of now, I found this really dated tutorial http://www.tldp.org/HOWTO/Shadow-Password-HOWTO-8.html from 1996 when, apparently, shadow support was not yet built into libc. It mentions pw_auth and valid as helper functions for authentication. I tried implanting these into my code and linking against libshadow.a of the shadow-tools but I get 'unresolved external reference' errors for pw_auth and valid. The code looks something like this:
if ((pw->pw_passwd && pw->pw_passwd[0] == '@' && pw_auth (pw->pw_passwd+1, pw->pw_name, PW_LOGIN, NULL)) || !valid (passwd, pw)) { return (UPAP_AUTHNAK); } I haven't checked this further but anyway this is not a preferred solution as I'd have to update my code every time shadow-utils are updated.
I'd much rather link to a library (that isn't PAM) that provides authentication against /etc/shadow. Is there such thing and I didn't find it yet? Or some other solution?
pam_unix(andpam_ldap).pam_unixanymore (except when my module fails).