Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <utmpx.h>
  5. #include <unistd.h>
  6. #include <pwd.h>
  7. #include <grp.h>
  8. #include <dlfcn.h>
  9.  
  10. char *(*fun)(char*);
  11. char *name;
  12.  
  13. int main(int argc, char **argv)
  14. {
  15.  
  16.  
  17. int ip=0,grupa=0, wybor;
  18. while ((wybor = getopt (argc, argv, "ab")) != -1)
  19. switch(wybor) {
  20. case 'a' : ip = 1; break;
  21. case 'b' : grupa = 1; break;
  22. default: return 0;
  23. }
  24.  
  25. struct utmpx *user;
  26. user = getutxent();
  27.  
  28. struct group *grupy;
  29. struct passwd *pw;
  30. int ngroups, i, *groups;
  31.  
  32. void *handle = dlopen("./libso.so.0.1", RTLD_LAZY);
  33. if (!handle)
  34. {
  35. dlerror();
  36. printf(" blad ");
  37. }
  38. else {
  39. fun = dlsym(handle, "fun");
  40. while ( user != NULL )
  41. {
  42. if(user->ut_type == USER_PROCESS)
  43. {
  44. printf("%s ", user->ut_user );
  45.  
  46. if(user->ut_type == USER_PROCESS && ip == 1)
  47. printf("%s ", user->ut_host);
  48.  
  49. if(user->ut_type == USER_PROCESS && grupa == 1)
  50. {
  51. //char *name = fun(user->ut_user);
  52. name=fun(user->ut_user);
  53. printf("%s", name);
  54. free(name);
  55. }
  56. printf("\n");
  57. }
  58. user=getutxent();
  59. }
  60. dlclose(handle);
  61. endutxent();
  62. }
  63. }
  64.  
  65.  
  66.  
  67. #include <stdio.h>
  68. #include <string.h>
  69. #include <stdlib.h>
  70. #include <utmpx.h>
  71. #include <unistd.h>
  72. #include <pwd.h>
  73. #include <grp.h>
  74. #include "libso.h"
  75.  
  76.  
  77. char *fun(char *name)
  78. {
  79.  
  80. struct utmpx *user;
  81.  
  82. struct group *grupy;
  83. struct passwd *pw;
  84. int ngroups, i, *groups;
  85. char *mgrupy;
  86.  
  87. mgrupy = malloc(100 * sizeof(char));
  88.  
  89. groups = malloc(ngroups * sizeof (int));
  90. pw = getpwnam(name);
  91. getgrouplist(name, pw->pw_gid, groups, &ngroups);
  92. getgrouplist(name, pw->pw_gid, groups, &ngroups);
  93.  
  94. for(i=0; i<ngroups; i++)
  95. {
  96. grupy=getgrgid(groups[i]);
  97. if(grupy !=NULL )
  98. {
  99. strcat(mgrupy,grupy->gr_name);
  100.  
  101. }
  102. }
  103. free(groups);
  104. return mgrupy;
  105.  
  106. }
  107.  
  108.  
  109. #include <stdlib.h>
  110. #include <stdio.h>
  111. #include <utmpx.h>
  112. #include <pwd.h>
  113. #include <grp.h>
  114. #include <string.h>
  115. #include <unistd.h>
  116.  
  117. char *fun(char *name);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement