C/C++ Authenticating against master.passwd

Hi,

I'm trying to write a simple authentication plugin for use with openvpn. The idea is to authenticate users again master.passwd.
For some reason the hashed password in master.passwd doesn't match the one supplied by the user (same clear text password and hashing algorithm in both cases).

Is the hashed password altered by the salt used?

What am iI missing here?
Relevant code below
Code:
/* Provide salt to crypt() */
  char salt[] = "8Y67afCkOP!(=(";

  FILE *fp;
  if( (fp = fopen("/etc/openvpn_users","r")) == NULL ){

  fprintf(stderr,"%s","Couldn't open file \"openvpn_users\" for reading\n");
  exit(5);
  }
  /* Read from buffer */
  fread(buff,1,100,fp);
  fclose(fp);

  /* Read the username */
  printf("Username:");
  fgets(username,sizeof(username),stdin);

  /* Remove trailing '\n' */
  username[strlen(username) - 1] = '\0';

  /* Read the password */
  crypt_set_format("sha512");
  char *password = getpass("password:");
  printf("Password is:%s",password);

  /* Crypt */
  strlcpy(enc_pass,crypt(pass,salt),sizeof(enc_pass));
  struct passwd *local_pass = getpwnam(username);
  if( local_pass == NULL){
  printf("%s",strerror(errno));
  exit(1);
  }
 
Shouldn't you be replicating or better using /usr/src/lib/libpam/modules/pam_unix/pam_unix.c ? salt is the existing password entry.

Juha
 
Top