Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <utmp.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <pwd.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8. #include <dlfcn.h>
  9. #include <fcntl.h>
  10. #include <grp.h>
  11.  
  12. int main()
  13. {
  14. void *bibl;
  15. void (*LibUser)(char *);
  16. int error = 0;
  17. struct utmp a;
  18.  
  19. bibl=dlopen("./libProg.so", RTLD_LAZY);
  20. if (!bibl) error = 1;
  21. else
  22. {
  23.     LibUser = dlsym(bibl, "LibUser");
  24.     if(!LibUser) error = 1;
  25. }
  26. int utmp = open (_PATH_UTMP, O_RDONLY);
  27. while(read(utmp, &a, sizeof(struct utmp))>0)
  28. {
  29.     if(a.ut_type=7)
  30.     {
  31.         if (!error) LibUser(a.ut_user);
  32.         else printf("%s\n", a.ut_user);
  33.     }
  34. }
  35. close (utmp);
  36. if (bibl) dlclose (bibl);
  37. return 0;
  38. }
Add Comment
Please, Sign In to add comment