Best way to check for system user and password in C

Hello,

I'm implementing a very simple FTP client, and to do the login I would like to check against system users instead of using my own database, so that I can give the proper permissions to the newly created process that I spawn with fork. What's the best way for doing this in C?

I've read about the getpwnam function, that returns a struct passwd that has the field pw_passwd to compare against (using the crypt function), but I'm not sure if this is quite standard, is there any other way to do this?

Thanks, Roger.

I would suggest to use PAM , instead of reinventing the wheel .

The pam_authenticate function is used to authenticate the current user.

#include <security/pam_appl.h>
int pam_authenticate (pam_handle_t *pamh, int flags);

Google for
Linux-PAM Application Developers' Guide

Thanks, I've already got a code sample from CryptNoMore

OK , but if you want it portable among Unixes , PAM is the way.

Yes, CryptNoMore shows examples about how to use OpenDirectory, PAM and Crypt. I've used the PAM part of the code, which runs fine on both Mac OS X and Linux at least.

Thanks for the reply.