I would to like to validate a username and password correspond to a valid unix account.

The current solution I have uses expect to wait for a password prompt and then supply the password and see if the login succeeds.

Is there a kernel API or a user space function that can validate a login / password.

I guess part of my confusion is I am not sure if this is a kernel space service?

link|improve this question

25% accept rate
feedback

3 Answers

up vote 2 down vote accepted

You should use pam. On debian/ubuntu you can:

apt-get install python-pam

Simple code in python pamtest.py:

See the /usr/share/doc/python-pam/examples/pamtest.py file. It's really short and does what you want.

To test it, run:

python /usr/share/doc/python-pam/examples/pamtest.py

There is also an example in C pamexample.c.

To test it:

gcc /usr/share/doc/python-pam/examples/pamexample.c -lpam -l pam_misc
./pam_misc theuser
link|improve this answer
feedback

It's strictly user-space.

link|improve this answer
feedback

to check if a user credentials are good you can try logging as him:

su - username

But reading about PAM may be a better route in the long term

link|improve this answer
To kick start your search, this is a page with a list of different PAM modules... kernel.org/pub/linux/libs/pam/modules.html – Mike Keller Aug 2 '11 at 20:30
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.