validate with system password

tittu
tittu used Ask the Experts™
on
The requirement is  if user enters password,
password needs to be validated against system encrypted password.

for example : login nameis guest and password is guest123.

the process is already running in guest login, if user enters password , the password should be validated aganist system password , which is similiar to screen saver/xlock passwd
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
Try this, it uses the pam module, which is the way most other system programs do it. It will prompt for the password for the user.

Make sure to add the entry to /etc/pam.d as directed below.
/* Linux pam sample / mrjoltcola */
 
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
 
/*
  before this program will work you need to add the entry under /etc/pam.d with same name as this program.
  # myauth
  auth required pam_unix.so
  account required pam_unix.so
 
 
  compile with: gcc myauth.c -o myauth -lpam -lpam_misc
*/
 
struct pam_conv conv = { misc_conv, 0 };
 
int main(int argc, char * argv[]) {
   struct passwd * pw = NULL;
   pam_handle_t * pamh = NULL;
   int ret;
 
   /* Get password file entry for this user, so we can pass username to pam */
   pw = getpwuid(getuid());
   if(!pw) {
      perror("getpwuid"); exit(1);
   }
 
   if((ret = pam_start(argv[0], pw->pw_name, &conv, &pamh)) != PAM_SUCCESS) {
      printf("Pam start failed\n"); exit(0);
   }
 
   if((ret = pam_authenticate(pamh, 0)) != PAM_SUCCESS) {
      printf("User auth failed\n"); exit(0);
   }
 
   if(pam_end(pamh, ret) != PAM_SUCCESS) {
      perror("pam_end");
      pamh = NULL; exit(1);
   }
}

Open in new window

Author

Commented:
partially accepted

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial