You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
822 B
34 lines
822 B
#define _GNU_SOURCE
|
|
|
|
#include <dlfcn.h>
|
|
#include <pwd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
|
|
char *getlogin(void) {
|
|
return getenv("USER");
|
|
}
|
|
|
|
int getlogin_r(char *buf, size_t bufsize) {
|
|
strncpy(buf, getlogin(), bufsize);
|
|
return 0;
|
|
}
|
|
|
|
struct passwd *getpwuid(uid_t uid) {
|
|
struct passwd *(*getpwuid)(uid_t) = dlsym(RTLD_NEXT, "getpwuid");
|
|
if (getpwuid == NULL) {
|
|
fprintf(stderr, "Unable to find the adress of the getpwuid function: %s\n", dlerror());
|
|
return NULL;
|
|
}
|
|
struct passwd *pass = getpwuid(uid);
|
|
char *name = getenv("USER");
|
|
if (name == NULL) {
|
|
fprintf(stderr, "Could not find the USER environment variable. Using the real username.\n");
|
|
return pass;
|
|
}
|
|
pass->pw_name = name;
|
|
return pass;
|
|
}
|