I would like to know if user is root, without minding if that user is using a fakeroot-like tool or not.
I tried the functions getuid()
, geteuid()
and getlogin()
, but when I launch fakeroot
command each of these sends my own account information instead of root
.
For this code:
printf("%d %d %s\n", getuid(), geteuid(), getlogin());
Here is what I get:
% fakeroot ./busybox rm
1000 1000 julien
When I would like to get something like:
0 0 root
(the login would be enough)
nneonneo got the reason right, but here's the solution: Fakeroot-ng. It uses
ptrace
and system call interception, rather thanLD_PRELOAD
and library call interception, which makes it compatible with static linking, much more robust, and even able to handle calls made from inside libc (which otherwise would not be hookable).