Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <utmpx.h>
- #include <paths.h>
- #include <string.h>
- #include <sys/types.h>
- #include <pwd.h>
- #include <grp.h>
- #include <dlfcn.h>
- extern int opterr, optopt;
- void (*iddisplay)(char*);
- void (*gdisplay)(char*);
- int main(int argc, char **argv) {
- int c;
- struct utmpx *ptr;
- if (argc == 1) {
- ptr = getutxent();
- while (ptr != NULL) {
- printf("User : %s\n", ptr->ut_user);
- ptr = getutxent();
- }
- return -1;
- }
- void* handler = dlopen("./lib", RTLD_LAZY);
- if (handler == NULL)
- {
- dlerror();
- exit(EXIT_FAILURE);
- }
- iddisplay = dlsym(handler, "iddisplay");
- gdisplay = dlsym(handler, "gdisplay");
- opterr = 0;
- while ((c = getopt(argc, argv, "abc:")) != -1)
- switch (c) {
- case 'a':
- while ((ptr = getutxent()) != NULL) {
- iddisplay(ptr->ut_user);
- }
- break;
- case 'b':
- while ((ptr = getutxent()) != NULL) {
- gdisplay(ptr->ut_user);
- }
- break;
- case '?':
- if (optopt == 'c')
- fprintf(stderr, "Option -%c requires an argument.\n", optopt);
- else if (isprint(optopt))
- fprintf(stderr, "Unknown option `-%c'.\n", optopt);
- else
- fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
- return 1;
- default:
- abort();
- }
- dlclose(handler);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement