Skip to content
Snippets Groups Projects
Commit 061bbd11 authored by Lhomme Lucien's avatar Lhomme Lucien
Browse files

question8

parent d6200814
No related branches found
Tags IHM-V1
No related merge requests found
question8/Screenshot from 2022-01-19 17-17-00.png

25.2 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int check_pass(__uid_t user, char *pass) {
char * line = NULL;
size_t len = 0;
size_t read;
FILE *fp = fopen("/home/admin/passwd", "r");
if (fp == NULL) {
printf("fopen failed, errno = %d\n", errno);
exit(EXIT_FAILURE);
}
while ((read = getline(&line, &len, fp)) != -1) {
unsigned long i = 0;
while (i < len && line[i] != ':') {
i++;
}
char vOut[64];
snprintf(vOut, 64, "%d", user);
if (strncmp(vOut, line, i) == 0) {
if (strncmp(pass, &line[i+1], len-1-i) == 0) {
return 0;
}
}
}
fclose(fp);
return 1;
}
\ No newline at end of file
int check_pass(__uid_t user, char *pass);
\ No newline at end of file
File added
File added
lhomme:123456
File added
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include "check_pass.h"
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char* argv[]) {
struct stat buf;
if (argc == 2) {
stat(argv[1], &buf);
if (buf.st_gid == getgid()) {
printf("Entrez votre mot de passe : ");
char pass[64];
fgets(pass, 64, stdin);
if (check_pass(getuid(), pass) == 0) {
remove(argv[1]);
printf("Le fichier à bien été supprimé.\n");
} else {
printf("T'as pas le bon mot de passe.\n");
}
} else {
printf("T'as pas le bon groupe.\n");
}
}
}
\ No newline at end of file
File added
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