Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <utmpx.h>
  6. #include <paths.h>
  7. #include <string.h>
  8. #include <sys/types.h>
  9. #include <pwd.h>
  10. #include <grp.h>
  11. #include <dlfcn.h>
  12.  
  13. extern int opterr, optopt;
  14.  
  15. void (*iddisplay)(char*);
  16. void (*gdisplay)(char*);
  17.  
  18. int main(int argc, char **argv) {
  19.        
  20.     int c;
  21.     struct utmpx *ptr;
  22.  
  23.     if (argc == 1) {
  24.  
  25.         ptr = getutxent();
  26.         while (ptr != NULL) {
  27.                 printf("User : %s\n", ptr->ut_user);
  28.                 ptr = getutxent();
  29.         }
  30.        
  31.         return -1;
  32.     }
  33.  
  34.     void* handler = dlopen("./lib", RTLD_LAZY);
  35.    
  36.     if (handler == NULL)
  37.     {
  38.         dlerror();
  39.         exit(EXIT_FAILURE);
  40.     }
  41.    
  42.    
  43.     iddisplay = dlsym(handler, "iddisplay");
  44.     gdisplay = dlsym(handler, "gdisplay");
  45.    
  46.     opterr = 0;
  47.  
  48.     while ((c = getopt(argc, argv, "abc:")) != -1)
  49.         switch (c) {
  50.         case 'a':
  51.  
  52.             while ((ptr = getutxent()) != NULL) {
  53.                 iddisplay(ptr->ut_user);
  54.                
  55.             }
  56.             break;
  57.         case 'b':
  58.             while ((ptr = getutxent()) != NULL) {
  59.                 gdisplay(ptr->ut_user);
  60.             }
  61.             break;
  62.         case '?':
  63.             if (optopt == 'c')
  64.                 fprintf(stderr, "Option -%c requires an argument.\n", optopt);
  65.             else if (isprint(optopt))
  66.                 fprintf(stderr, "Unknown option `-%c'.\n", optopt);
  67.             else
  68.                 fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
  69.             return 1;
  70.         default:
  71.  
  72.             abort();
  73.         }
  74.  
  75.     dlclose(handler);
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement