Skip to content
Snippets Groups Projects
Commit 6dfe12dd authored by Esteban Collard's avatar Esteban Collard
Browse files

fin q8

parent 07247802
No related branches found
No related tags found
No related merge requests found
all : rmg
rmg : check_pass.o
gcc -o $@ $^
check_pass.o : check_pass.c
gcc -c -o $@ $^
clean:
rm -rf *.o
rm -rf rmg
#include "check_pass.h"
int verification_motDePasse(int identifiant, char *pwd){
FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
char *idRead = NULL;
char *pwdRead = NULL;
fp = fopen("/home/admin/passwd", "r");
if (fp == NULL){
printf("Erreur fichier mot de passe\n");
exit(EXIT_FAILURE);
}
while ((read = getline(&line, &len, fp)) != -1) {
idRead = strtok(line, ":");
if(atoi(idRead) == identifiant){
pwdRead = strtok(NULL,":");
pwdRead = strtok(pwdRead,"\n");
fclose(fp);
return strcmp(pwdRead,pwd);
}
}
}
int getIdentifiant(char *file) {
struct stat stats;
if (stat(file, &stats) == 0) {
return stats.st_gid;
} else {
perror("impossible de recuperer les identifiants du fichier");
exit(EXIT_FAILURE);
}
}
\ No newline at end of file
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
int verification_motDePasse(int identifiant, char *pwd);
int getIdentifiant(char *file);
\ No newline at end of file
#include <stdlib.h>
#include <stdio.h>
#include "check_pass.h"
int main(int argc, char *argv[]) {
if(argc<3){
printf("parametre non valide\n");
printf("exemple utilisation\n");
printf("rmg file password\n");
}
else{
uid_t uid = getuid();
gid_t gid = getuid();
// Verification id
if(getIdentifiant(argv[1])!=uid){
printf("id non valide\n");
exit(EXIT_FAILURE);
}
//verification mdp
if(verification_motDePasse(gid,argv[2])){
if(remove(argv[1]) == 0){
printf("Fichier supprimer\n");
}
else{ printf("Impossible de supprimer le fichier\n"); }
}
else{ printf("Mot de passe non valide\n"); }
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment