-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetc_passwd.c
executable file
·35 lines (30 loc) · 1.08 KB
/
etc_passwd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
FILE *file, *exel;
file = fopen("/etc/passwd", "r");
exel = fopen("copy_user.csv", "w"); // Nouveau fichier pour les utilisateurs redirigés
if (file == NULL || exel == NULL) {
perror("Erreur lors de l'ouverture du fichier");
return 1;
}
char line[1000];
char user[900];
char home_directory[100];
char shell[200];
int uid, gid;
srand(time(NULL));
fprintf(exel,"USER NAME,HOME DIRECTORY,SHELL,E-MAIL,PASSWD\n");
while (fgets(line, sizeof(line), file) != NULL) {
if (sscanf(line, "%[^:]:%*[^:]:%d:%d:%*[^:]:%[^:]:%[^\n]", user, &uid, &gid, home_directory, shell) ==5) {
printf("Utilisateur: %s\nUID: %d\nGID: %d\nDossier personnel: %s\nShell: %s\n\n", user, uid, gid, home_directory, shell);
if (uid >= 1000 && gid >= 1000 && gid<2000 && uid<2000) {
}
}
}
fclose(file);
fclose(exel);
return 0;
}