Information utilisateur
From Tuxunix
Exemple d'execution
[tuxedo@macMob:GETPWD] $./infoUser Usage: ./infoUser nom_utilisateur
[tuxedo@macMob:GETPWD] $./infoUser tuxedo Login : tuxedo Pwd : ******** Uid : 501 Gid : 501 Dir : /Users/tuxedo Shell : /bin/bash Commentaire : tuxedo
1. 2.#include <stdio.h> 3.#include <sys/types.h> 4.#include <pwd.h> 5.#include <string.h> 6.#include <stdlib.h> 7. 8.int main(int argc, char *argv[]){ 9. 10. struct passwd *E; 11. 12. if(argc != 2){ 13. fprintf(stderr,"Usage: %s nom_utilisateur\n", argv[0]); 14. exit(1); 15. } 16. while(( E = getpwent()) != NULL){ 17. if(strcmp(E->pw_name, argv[1]) == 0){ 18. 19. printf("Login : %s\n", E->pw_name); 20. printf("Pwd : %s\n", E->pw_passwd); 21. printf("Uid : %d\n", E->pw_uid); 22. printf("Gid : %d\n", E->pw_gid); 23. printf("Dir : %s\n", E->pw_dir); 24. printf("Shell : %s\n", E->pw_shell); 25. printf("Commentaire : %s\n", E->pw_gecos); 26. exit(0); 27. 28. } 29. 30. } 31. fprintf(stderr,"Utilisateur %s n'esxite pas!!", argv[1]); 32. exit(2); 33.} /*main*/

