diff --git a/lib/roken/getxxyyy.c b/lib/roken/getxxyyy.c index 5beed69df..f6c6d8ea8 100644 --- a/lib/roken/getxxyyy.c +++ b/lib/roken/getxxyyy.c @@ -40,6 +40,9 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); + +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); #endif #if !defined(POSIX_GETPWNAM_R) || defined(TEST_GETXXYYY) @@ -87,6 +90,35 @@ do { \ return 0; } +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +rk_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **result) +{ + struct passwd *p; + size_t slen, n = 0; + + *result = NULL; + + p = getpwuid(uid); + if(p == NULL) + return (errno = ENOENT); + + memset(pwd, 0, sizeof(*pwd)); + + APPEND(pw_name); + if (p->pw_passwd) + APPEND(pw_name); + pwd->pw_uid = p->pw_uid; + pwd->pw_gid = p->pw_gid; + APPEND(pw_gecos); + APPEND(pw_dir); + APPEND(pw_shell); + + *result = pwd; + + return 0; +} + #endif /* POSIX_GETPWNAM_R */ #ifdef TEST_GETXXYYY diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index 3f6d1afa5..4bbc2fa7e 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -648,9 +648,12 @@ ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t); #ifdef POSIX_GETPWNAM_R #define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd) +#define rk_getpwuid_r(_u, _pw, _b, _sz, _pwd) getpwuid_r(_u, _pw, _b, _sz, _pwd) #else ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); #endif #endif