2004/Dec/28

/*
*
* NAME
* pam_llfs_auth.c -- Copyright (C) 2005 Mr. Kriangkrai Nitranon
* ptk386@hotmail.com
*
* DESCRIPTION:
* This defines a PAM useable module for use with fingerprint scanner_AFS4000
*
* AUTHOR:
* Kriangkrai Nitranon, 01/01/05
*
* LICENSE: See file LICENSE.
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <scanner.h>
#include <VFinger.h>
#include <string.h>
#include <security/pam_modules.h>


struct scanner_info* scanner = &scanner_AFS4000;

void do_extraction (unsigned char *fileName, BYTE* features,int w , int h, int dpi)
{
DWORD features_size = 0;
int ret = 0;
ret = VFExtract (w, h, (BYTE *) fileName, dpi, features, &features_size, 0);
if (ret != VFE_OK)
{
if (ret == VFE_LOW_QUALITY_IMAGE)
{
printf ("WARNING: Image1 is low quality.\n");
}
else
{
printf ("An error1 occured. Exiting %d.\n",ret);
exit (1);
}
}

printf("G: %d, size: %d byetes, minutiae count: %d\n",VFFeatGetG(features),features_size,VFFeatGetMinutiaCount(features));
}
int get_file(char *name,char **image)
{
FILE *file;
char *buffer;
long Lsize;
file = fopen(name,"rb");
if(file==NULL)
exit(1);
fseek(file,0,SEEK_END);
Lsize = ftell(file);
printf("Lsize = %d\n",Lsize);
rewind(file);
buffer = (char*)malloc(Lsize);
if(buffer == NULL)
exit(2);
fread(buffer,1,Lsize,file);
*image = buffer;
fclose(file);
return 0;
}
PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, const char **argv)
{
/* define value for pam */
const char *uid;
char *passwd;
int retval;

fprintf(stdout,"pam start to authenticate\n");
/* get the user id */
retval = pam_get_user(pamh, &uid, NULL);


if(retval == PAM_SUCCESS)
{
if( uid == NULL )
{
fprintf(stderr, "bad uid [%s]\n",uid);
}

}
else
{
fprintf(stderr, "trouble reading uid \n");
return PAM_INCOMPLETE;
}

/* define value for scanner and Verifinger */
int ret;
int i = scanner -> init();
int dpi = scanner -> dpi;
int w1, w2, h2, h1;
int result = 0;
char *name = scanner -> name;
char *imageFromFile , *imageFromScanner;
char filename[256]="";
BYTE featuresFromFile[VF_MAX_FEATURES_SIZE], featuresFromScanner[VF_MAX_FEATURES_SIZE];
VFMatchDetails md;
md.Size = sizeof(md);

strcat(filename,"/etc/llfs/");
strcat(filename,uid);

/* initialize and set value for Verifinger Linux SDK */

ret = VFInitialize();
fprintf(stdout,"VFInitialize returns %d \n",ret);
if (ret != VFE_OK){
fprintf(stderr,"VFInitialize error");
return 1;
}
/* int threshold = 60;
//int threshold = 60;
//int threshold = 72;
//int threshold = 84;
ret = VFSetParameter(VFP_MATCHING_THRESHOLD, (INT)threshold, NULL);
if (ret != VFE_OK){
fprintf(stderr,"VFSetParameter error");
return 1;
} */
int rotation = 180;
ret = VFSetParameter(VFP_MAXIMAL_ROTATION, (INT)rotation, NULL);
if (ret != VFE_OK){
fprintf(stderr,"VFSetParameter error");
return 1;
}
/* open /dev/usb/device and select until a scanned fingerprint is received */
fscanf(stdout,"Please scan your finger \n");
do
{
imageFromScanner = scanner -> read(&w1, &h1);
}while(imageFromScanner == NULL);
do_extraction (imageFromScanner, featuresFromScanner, w1, h1, dpi);

fprintf(stdout,"filename = %s \n",filename);
/* get image from file that has same name as uid in /etc/llfs */
get_file(filename,&imageFromFile);
do_extraction (imageFromFile, featuresFromFile, 96, 96, 250);
free(imageFromFile);

/* performs fingerprint verification between image from file and image from scanner*/
result = VFVerify(featuresFromFile, featuresFromScanner, &md, 0);
switch (result)
{
case VFE_OK:
/* SUCCESS set the username for llfslogin */
printf ("Fingerprints matched. Similarity: %d\n", md.Similarity);
pam_set_item(pamh, PAM_USER,(const void *)uid);
return PAM_SUCCESS;
break;
case VFE_FAILED:
/* FAILURE authentication has failed */
printf("Fingerprints didn't match. Similarity: %d\n", md.Similarity);
return PAM_AUTH_ERR;
break;
default:
return PAM_AUTH_ERR;
break;
}

return PAM_SUCCESS;
}
PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc,
const char **argv) {

return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc,
const char **argv) {


return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
const char **argv) {

return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc,
const char **argv) {


return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc,
const char **argv) {

return PAM_SUCCESS;
}

Comment

Comment:

Tweet