[Buildbot-devel] How to compile code as root user

Dustin Sallings dustin at spy.net
Sat Aug 21 02:04:19 UTC 2010


On Aug 20, 2010, at 17:13, Ian Zimmerman wrote:

> I need root for my build too, since chroot is an essential element of
> the build.  (We build an entire linux distro from scratch, more or
> less.)  And yes, everybody hates it, but nobody has been able to come
> up with anything better, mostly due to innumerable source packages
> looking in places where they shouldn't for configuration values.
> 
> I am guessing this need is a bit more common than textbooks would have
> it, and so we shouldn't be too hard on Raj (and me :)


	Just make a setuid chroot specific to what you're doing.  Something like this should work fine (barely tried it):


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sysexits.h>
#include <assert.h>

int main(int argc, char **argv) {
    assert(argc > 2);
    assert(argv[argc] == 0);

    if (chroot(argv[1]) != 0) {
        perror("chroot");
        exit(EX_OSERR);
    }

    if (seteuid(getuid()) != 0) {
        perror("getuid");
        exit(EX_OSERR);
    }

    assert(getuid() != 0);
    assert(geteuid() != 0);

    execvp(argv[2], argv+2);
    perror("execvp");
    exit(EX_OSERR);
}


-- 
Dustin Sallings

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://buildbot.net/pipermail/devel/attachments/20100820/89430588/attachment.html>


More information about the devel mailing list