0

If I run su, it asks for the password of the target user. If i run it as root, it does not ask for a password. But if I run it in fakeroot, how is it possible that it will ask for a password? Should fakeroot not make all programs think that you are root? For my own program, the only way of doing this would be trying to run su, and look at the return code. but how does su do that?

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Jun 12, 2023 at 14:39

2 Answers 2

1

su detects nothing.

From man fakeroot:

fakeroot works by replacing the file manipulation library functions (chmod(2), stat(2) etc.) by ones that simulate the effect the real library functions would have had, had the user really been root.
These wrapper functions are in a shared library /usr/lib/*/libfake‐root-\*.so or similar location on your platform. The shared object is loaded through the LD_PRELOAD mechanism of the dynamic loader. (See ld.so(8))

su, being a setuid executable, always runs as root - but doesn't care about LD_PRELOAD¹. So, while "normal" programs are being told they're run as root by replacing the functions with which they ask for that, su never sees that modification. So, su just runs as usual.


¹ that would be a terrible security hole; you could just set LD_PRELOAD to contain a library that does whatever you want to be done, and it would automatically be executed as root if you could run any setuid executable

0
0

The documentation for fakeroot (see man fakeroot) seems to answer this for you:

DESCRIPTION fakeroot runs a command in an environment wherein it appears to have root privileges for file manipulation.

and,

EXAMPLES Only the effects that user joost could do anyway happen for real

and finally,

SECURITY ASPECTS fakeroot is a regular, non-setuid program. It does not enhance a user's privileges, or decrease the system's security.

In the first block, note the word appears. In the examples extract, consider the user joost to be you. In the final section, there's a clear statement that fakeroot does not add privileges or decrease security in any way. Specifically, this means that it does not change how the real su works.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.