Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
115 lines (98 sloc) 2.58 KB
//#include "pfile.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LENG_STRING 100
#define PAM_SM_AUTH
#include <security/pam_modules.h>
//#include <MYSQL/mysql.h>
#ifndef PAM_EXTERN
#define PAM_EXTERN extern
#endif
static FILE* open_login_file(char *nom_fichier){
FILE *login_file = fopen(nom_fichier, "r");
return login_file;
}
static int close_login_file(FILE* login_file){
return fclose(login_file);
}
static int check_pwd(const char* pwd, char* chaine){
// vérification du mot de passe
if(strncmp(chaine, pwd, strlen(pwd))==0){
//printf("PWD %s OK\n", pwd);
return 1;
}
return 0;
}
static int check_authentification(const char *username, const char* pwd, FILE *fichier){
char *founded_username = NULL;
char temp[LENG_STRING]="";
if (fichier!=NULL){
while(fgets(temp, LENG_STRING, fichier)){
char user_temp[LENG_STRING]="";
// récupération du nom de l'utilisateur (extraction de la premiere partie de la chaine : avant le ':')
int i=0;
for (i ; i < strlen(temp); i++){
if (temp[i]==58){ // ":"
//printf("username : %s\n", user_temp);
break;
}
else{
user_temp[i]=temp[i];
}
}
if (user_temp!=""){ //comparaison du nom de l'utilisateur
if (strcmp(user_temp, username)==0){
//printf("username %s OK\n", username);
if(check_pwd(pwd, strstr(temp, ":")+1)){
return 1;
}
else{
return 0;
}
}
}
}
}
return 0;
}
PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flgs, int argc, const char **argv){
/*FILE* testf = open_login_file("/home/user/pam/README");
const char *user;
const char *pwd;
if(pam_get_user(pamh, &user, NULL) != PAM_SUCCESS){
return PAM_AUTH_ERR;
}
if(pam_get_pass(pamh, &pwd, NULL) != PAM_SUCCESS){
return PAM_AUTH_ERR;
}*/
return PAM_SUCCESS;/*
if(check_authentification(user, "strong_pwd", testf)){
close_login_file(testf);
return PAM_SUCCESS;
}
else{
close_login_file(testf);
return PAM_AUTH_ERR;
}*/
}
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_SERVICE_ERR);
}