fakeroot(1) | Manual Debian | fakeroot(1) |
fakeroot - corre um comando num ambiente onde finge privilégios de root para manipulação de ficheiro
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 corre um comando num ambiente onde aparenta ter privilégios de root para manipulação de ficheiros. Isto é útil para permitir aos utilizadores criar arquivos (tar, ar, .deb etc.) com ficheiros dentro com permissões/posse de root. Sem o fakeroot seria preciso ter privilégios de root para criar os ficheiros constituintes dos arquivos com as permissões e posse atuais, e depois empacota-los, ou seria preciso construir os arquivos diretamente, sem usar o arquivador.
fakeroot funciona ao substituir as funções da biblioteca de manipulação de ficheiros (chmod(2), stat(2) etc.), por outras que simulam o efeito que teriam as funções da biblioteca real, caso o utilizador fosse realmente o root. Estas funções envolventes estão numa biblioteca partilhada /usr/lib/*/libfakeroot-*.so ou localização semelhante na sua plataforma. O objecto partilhado é carregado através do mecanismo LD_PRELOAD do carregador dinâmico. (Veja ld.so(8))
Se você pretende compilar pacotes com o fakeroot, por favor tente primeiro compilar o pacote fakeroot: a fase "debian/rules build" tem alguns testes (testar principalmente por bugs em antigas versões do fakeroot). Se esses testes falharem (por exemplo porque você tem certos programas da libc5 no seu sistema), os outros pacotes que compilem com o fakeroot irão muito provavelmente falhar também, mas possivelmente de maneiras muito mais subtis.
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).
Aqui está uma sessão exemplo com o fakeroot. Note que dentro do ambiente fingido de root a manipulação de ficheiro que requer privilégios de root tem sucesso, mas na realidade não está a acontecer.
$ 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
Apenas os efeitos que o utilizador joost podia fazer aconteceram de verdade.
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 é um programa normal, não-setuid. Não aumenta os privilégios do utilizador nem baixa a segurança do sistema.
/usr/lib/*/libfakeroot-*.so A biblioteca partilhada que contém as funções wrapper.
touch foo fakeroot ls -al foo
ou do outro modo contrário,
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’.
Não envolve open(). Isto não é mau por si próprio, mas se um programa fizer open("file", O_WRONLY, 000), escrever no ficheiro "file" e o fechar, e depois tentar abri-lo para ler o ficheiro, então essa abertura vai falhar, pois o modo do ficheiro será 000. O bug é tal que se o root fizer o mesmo, open() irá ter sucesso, pois as permissões não são verificadas para o root. Eu escolhi não envolver open(), pois open() é usado por muitas outras funções na libc (mesmo aquelas que já estão envolvidas), assim criando ciclos viciosos (ou possíveis ciclos futuros, quando a implementação de várias funções da libc mudarem ligeiramente).
fakeroot é distribuído sob a GNU General Public License. (GPL 2.0 ou superior).
Américo Monteiro <a_monteiro@gmx.com>
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 | Projecto Debian |