fakeroot(1) | Debian manual | fakeroot(1) |
fakeroot - utför ett kommando i en miljö som fejkar root-privilegier för filmanipulation
fakeroot [-l|--lib library] [--faked faked-binary] [-i load-file] [-s save-file] [-u|--unknown-is-real] [-b|--fd-base] [-h|--help] [-v|--version] [--] [command]
fakeroot utför ett kommando i en miljö där kommandot tror sig ha root-privilegier för filmanipulering. Detta är användbart för att ge användare möjlighet att skapa arkiv (tar, ar, .deb osv) som innehåller filer med root-rättigheter/ägarskap. Utan fakeroot tvingas man att ha root-privilegier för att skapa de filer arkivet består av med korrekt ägarskaps- och rättighetsinformation, alternativt konstruera arkiven manuellt utan att använda arkiveringsprogrammet.
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/*/libfakeroot-*.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))
Om du planerar att bygga paket med hjälp av fakeroot, försök först att bygga fakeroot-paketet: ”debian/rules build”-stadiet har ett par tester (som mestadels testar efter buggar i gamla versioner av fakeroot). Om dessa tester misslyckas (till exempel på grund av att du har vissa libc5-program på ditt system) så är det troligt att du också kommer att misslyckas bygga andra paket, och det är möjligt att dessa fel blir betydligt svårare att hitta.
Also, note that it's best not to do the building of the binaries themselves under fakeroot. Especially configure and friends don't like it when the system suddenly behaves differently from what they expect (or, they randomly unset some environment variables, some of which fakeroot needs).
Här är ett exempel på hur fakeroot kan användas. Notera att i den fejkade root-miljön så lyckas filmanipulering som kräver root-privilegier, trots att den egentligen inte utförs.
$ whoami joost $ fakeroot /bin/bash # whoami root # mknod hda3 b 3 1 # ls -ld hda3 brw-r--r-- 1 root root 3, 1 Jul 2 22:58 hda3 # chown joost:root hda3 # ls -ld hda3 brw-r--r-- 1 joost root 3, 1 Jul 2 22:58 hda3 # ls -ld / drwxr-xr-x 20 root root 1024 Jun 17 21:50 / # chown joost:users / # chmod a+w / # ls -ld / drwxrwxrwx 20 joost users 1024 Jun 17 21:50 / # exit $ ls -ld / drwxr-xr-x 20 root root 1024 Jun 17 21:50 // $ ls -ld hda3 -rw-r--r-- 1 joost users 0 Jul 2 22:58 hda3
Enbart de operationer som användaren joost skulle kunna ha genomfört som sig själv utförs på riktigt.
fakeroot was specifically written to enable users to create Debian GNU/Linux packages (in the deb(5) format) without giving them root privileges. This can be done by commands like dpkg-buildpackage -rfakeroot or debuild -rfakeroot (actually, -rfakeroot is default in debuild nowadays, so you don't need that argument).
fakeroot är ett vanligt program utan setuid. Det ger inte användaren några extra privilegier, och minskar inte systemets säkerhet.
/usr/lib/*/libfakeroot-*.so The shared library containing the wrapper functions.
touch foo fakeroot ls -al foo
eller omvänt,
fakeroot touch foo ls -al foo
fakeroot has no way of knowing that in the first case, the owner of foo really should be joost while the second case it should have been root. For the Debian packaging, defaulting to giving all "unknown" files uid=gid=0, is always OK. The real way around this is to wrap open() and create(), but that creates other problems, as demonstrated by the libtricks package. This package wrapped many more functions, and tried to do a lot more than fakeroot . It turned out that a minor upgrade of libc (from one where the stat() function didn't use open() to one with a stat() function that did (in some cases) use open() ), would cause unexplainable segfaults (that is, the libc6 stat() called the wrapped open() , which would then call the libc6 stat() , etc). Fixing them wasn't all that easy, but once fixed, it was just a matter of time before another function started to use open(), never mind trying to port it to a different operating system. Thus I decided to keep the number of functions wrapped by fakeroot as small as possible, to limit the likelihood of ‘collisions’.
fakeroot har ingen ersättningsfunktion för open(). Detta i sig självt är inget fel, men om ett program utför open("fil", O_WRONLY, 000), försöker skriva till filen ”fil”, stänger den, och sedan försöker att läsa filen, så misslyckas detta då filen kommer att ha rättigheterna 000. Felet består i att om en process med root-privilegier försöker sig på det samma, så kommer anropet till open() att lyckas, eftersom filrättigheter inte kontrolleras alls för root. Jag valde att inte skriva ersättningsfunktioner för open(), eftersom open() används av många andra funktioner i libc (även de som har ersättningsfunktioner), vilket ger upphov till cirkelreferenser eller potential för cirkelreferenser ifall implementationen av vissa funktioner i libc förändras).
fakeroot distribueras under GNU General Public License. (GPL 2.0 eller senare).
David Weinehall <tao@kernel.org>
mostly by J.H.M. Dassen <jdassen@debian.org> with rather a lot of modsifications and additions by joost and Clint.
debuild(1), dpkg-buildpackage(1), faked(1), /usr/share/doc/fakeroot/DEBUG
2024-12-19 | Debian Project |