From: Zeng L. <zen...@cn...> - 2014-04-24 10:44:39
|
Signed-off-by: Zeng Linggang <zen...@cn...> --- include/safe_macros.h | 10 ++++++++++ lib/safe_macros.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/safe_macros.h b/include/safe_macros.h index 25846f4..e9fc485 100644 --- a/include/safe_macros.h +++ b/include/safe_macros.h @@ -126,6 +126,16 @@ int safe_setuid(const char *file, const int lineno, #define SAFE_SETUID(cleanup_fn, uid) \ safe_setuid(__FILE__, __LINE__, cleanup_fn, (uid)) +int safe_getresuid(const char *file, const int lineno, + void (*cleanup_fn)(void), uid_t *ruid, uid_t *euid, uid_t *suid); +#define SAFE_GETRESUID(cleanup_fn, ruid, euid, suid) \ + safe_getresuid(__FILE__, __LINE__, cleanup_fn, (ruid), (euid), (suid)) + +int safe_getresgid(const char *file, const int lineno, + void (*cleanup_fn)(void), gid_t *rgid, gid_t *egid, gid_t *sgid); +#define SAFE_GETRESGID(cleanup_fn, rgid, egid, sgid) \ + safe_getresgid(__FILE__, __LINE__, cleanup_fn, (rgid), (egid), (sgid)) + int safe_unlink(const char *file, const int lineno, void (*cleanup_fn)(void), const char *pathname); #define SAFE_UNLINK(cleanup_fn, pathname) \ diff --git a/lib/safe_macros.c b/lib/safe_macros.c index 0d805e9..b4fe02f 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -310,6 +310,38 @@ int safe_setuid(const char *file, const int lineno, void (*cleanup_fn) (void), return rval; } +int safe_getresuid(const char *file, const int lineno, void (*cleanup_fn)(void), + uid_t *ruid, uid_t *euid, uid_t *suid) +{ + int rval; + + rval = getresuid(ruid, euid, suid); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: getresuid(%u, %u, %u) failed", + file, lineno, (unsigned) *ruid, (unsigned) *euid, + (unsigned) *suid); + } + + return rval; +} + +int safe_getresgid(const char *file, const int lineno, void (*cleanup_fn)(void), + gid_t *rgid, gid_t *egid, gid_t *sgid) +{ + int rval; + + rval = getresgid(rgid, egid, sgid); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: getresgid(%u, %u, %u) failed", + file, lineno, (unsigned) *rgid, (unsigned) *egid, + (unsigned) *sgid); + } + + return rval; +} + int safe_unlink(const char *file, const int lineno, void (*cleanup_fn) (void), const char *pathname) { -- 1.8.4.2 |