Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <utmpx.h>
- #include <unistd.h>
- #include <pwd.h>
- #include <grp.h>
- #include <dlfcn.h>
- char *(*fun)(char*);
- char *name;
- int main(int argc, char **argv)
- {
- int ip=0,grupa=0, wybor;
- while ((wybor = getopt (argc, argv, "ab")) != -1)
- switch(wybor) {
- case 'a' : ip = 1; break;
- case 'b' : grupa = 1; break;
- default: return 0;
- }
- struct utmpx *user;
- user = getutxent();
- struct group *grupy;
- struct passwd *pw;
- int ngroups, i, *groups;
- void *handle = dlopen("./libso.so.0.1", RTLD_LAZY);
- if (!handle)
- {
- dlerror();
- printf(" blad ");
- }
- else {
- fun = dlsym(handle, "fun");
- while ( user != NULL )
- {
- if(user->ut_type == USER_PROCESS)
- {
- printf("%s ", user->ut_user );
- if(user->ut_type == USER_PROCESS && ip == 1)
- printf("%s ", user->ut_host);
- if(user->ut_type == USER_PROCESS && grupa == 1)
- {
- //char *name = fun(user->ut_user);
- name=fun(user->ut_user);
- printf("%s", name);
- free(name);
- }
- printf("\n");
- }
- user=getutxent();
- }
- dlclose(handle);
- endutxent();
- }
- }
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <utmpx.h>
- #include <unistd.h>
- #include <pwd.h>
- #include <grp.h>
- #include "libso.h"
- char *fun(char *name)
- {
- struct utmpx *user;
- struct group *grupy;
- struct passwd *pw;
- int ngroups, i, *groups;
- char *mgrupy;
- mgrupy = malloc(100 * sizeof(char));
- groups = malloc(ngroups * sizeof (int));
- pw = getpwnam(name);
- getgrouplist(name, pw->pw_gid, groups, &ngroups);
- getgrouplist(name, pw->pw_gid, groups, &ngroups);
- for(i=0; i<ngroups; i++)
- {
- grupy=getgrgid(groups[i]);
- if(grupy !=NULL )
- {
- strcat(mgrupy,grupy->gr_name);
- }
- }
- free(groups);
- return mgrupy;
- }
- #include <stdlib.h>
- #include <stdio.h>
- #include <utmpx.h>
- #include <pwd.h>
- #include <grp.h>
- #include <string.h>
- #include <unistd.h>
- char *fun(char *name);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement