Julien Fouilhé Julien Fouilhé - 11 months ago 81
C Question

How to know if user is root or fakeroot?

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

, but when I launch
command each of these sends my own account information instead of

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)

R.. R..
Answer Source

nneonneo got the reason right, but here's the solution: Fakeroot-ng. It uses ptrace and system call interception, rather than LD_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).