roken: add rk_getpwuid_r()
TODO: implement non-POSIX getpwnam_r()/getpwuid_r() wrappers
This commit is contained in:
@@ -40,6 +40,9 @@
|
|||||||
|
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||||
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
|
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
|
||||||
|
|
||||||
#if !defined(POSIX_GETPWNAM_R) || defined(TEST_GETXXYYY)
|
#if !defined(POSIX_GETPWNAM_R) || defined(TEST_GETXXYYY)
|
||||||
@@ -87,6 +90,35 @@ do { \
|
|||||||
return 0;
|
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 */
|
#endif /* POSIX_GETPWNAM_R */
|
||||||
|
|
||||||
#ifdef TEST_GETXXYYY
|
#ifdef TEST_GETXXYYY
|
||||||
|
@@ -648,9 +648,12 @@ ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
|
|||||||
|
|
||||||
#ifdef POSIX_GETPWNAM_R
|
#ifdef POSIX_GETPWNAM_R
|
||||||
#define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
|
#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
|
#else
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||||
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
|
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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user