3

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)

4

2 回答 2

5

看起来好像您的二进制 ( busybox) 是针对静态编译的libcfakeroot使用动态库预加载来拦截和替换对各种libc函数的调用,但这仅在您的二进制文件动态链接到libc. 如果是静态链接,函数调用绑定到二进制内部的真实调用,所以没有办法拦截它们。

于 2013-09-07T16:59:05.760 回答
4

nneonneo 得到了正确的原因,但这是解决方案:Fakeroot-ng。它使用ptrace系统调用拦截,而不是LD_PRELOAD库调用拦截,这使得它与静态链接兼容,更加健壮,甚至能够处理从 libc 内部进行的调用(否则将无法挂钩)。

于 2013-09-07T17:03:54.537 回答