fakeroot(1) | Handleiding van Debian | fakeroot(1) |
fakeroot - voert een commando uit in een omgeving die root-privileges fingeert voor het manipuleren van bestanden
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 voert een commando uit in een omgeving waarin het voor dit commando lijkt alsof het root-privileges heeft voor het bewerken van bestanden. Zo kunnen gebruikers in archieven (zoals tar, ar, .deb enz.) bestanden opnemen met eigenaar en toegangsrechten die normaal gesproken alleen root mag instellen. Zonder fakeroot zou men root-toegang nodig hebben om de bestanden in het archief aan te maken met de juiste toegangsrechten en eigenaar en ze dan in te pakken, of men zou de archieven direct, dus zonder gebruik te maken van het archiveerprogramma, moeten opbouwen.
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))
Bent u van plan met behulp van fakeroot programmatuurpakketten te maken, probeer dan eerst het fakeroot-pakket zelf opnieuw op te bouwen. De regel `build' in het bestand debian/rules bevat namelijk een aantal tests (die vooral fouten in oude versies van fakeroot opsporen). Als deze tests niet slagen (omdat u bijvoorbeeld bepaalde libc5-programma's op uw systeem heeft), dan zullen andere pakketten die u met behulp van fakeroot opbouwt waarschijnlijk ook niet goed werken. Dit kan dan echter veel moeilijker te ontdekken zijn.
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).
Hieronder ziet u een voorbeeldsessie met fakeroot. Merk op dat binnen de nagebootste root-omgeving de bestandsbewerkingen die root-privileges vereisen lijken te slagen, maar in het echt niet worden uitgevoerd.
$ whoami joost $ fakeroot /bin/bash # whoami root # mknod hda3 b 3 1 # ls -ld hda3 brw-r--r-- 1 root root 3, 1 2007-01-21 12:02 hda3 # chown joost:root hda3 # ls -ld hda3 brw-r--r-- 1 joost root 3, 1 2007-01-21 12:02 hda3 # ls -ld / drwxr-xr-x 22 root root 600 2007-01-20 23:58 / # chown joost:users / # chmod a+w / # ls -ld / drwxrwxrwx 22 joost users 600 2007-01-20 23:58 / # exit $ ls -ld / drwxr-xr-x 22 root root 600 2007-01-20 23:58 / $ ls -ld hda3 -rw-r--r-- 1 joost users 0 2007-01-21 12:06 hda3
Alleen de bewerkingen die de gebruiker joost toch al mocht uitvoeren, gebeuren ook echt.
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 is een normaal programma, zonder setuid. Het verhoogt de privileges van de gebruiker niet, en verlaagt dus ook niet de veiligheid van het systeem.
/usr/lib/*/libfakeroot-*.so The shared library containing the wrapper functions.
touch foo fakeroot ls -al foo
uitvoert, in deze of in omgekeerde volgorde,
fakeroot touch testbestand ls -al testbestand
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’.
Het programma omhult open() niet. Dit is op zichzelf geen fout, maar als een programma een commando open ("bestand", O_WRONLY, 000) uitvoert, dan iets naar het bestand bestand schrijft, het sluit, en dan nogmaals probeert het bestand voor uitlezen te openen, dan mislukt die open()-aanroep, omdat de toegangsrechten van het bestand op 000 staan. De fout zit erin dat als root hetzelfde doet, open() wel degelijk zal slagen, omdat de toegangsrechten voor root nooit worden nagetrokken. Ik heb er niettemin voor gekozen open() niet te omhullen, omdat open() door vele andere functies in libc wordt gebruikt (ook door al omhulde functies), wat kan uitmonden in oneindige lussen (nu of in de toekomst, wanneer de implementatie van verscheidene libc-functies enigzins verandert).
fakeroot wordt verspreid onder de voorwaarden van de GNU General Public License (GPL 2.0 of recenter).
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 | Project Debian |