diff options
-rw-r--r-- | docs/mock.1 | 6 | ||||
-rw-r--r-- | etc/mock/epel-4-x86_64.cfg | 2 | ||||
-rw-r--r-- | etc/mock/epel-5-x86_64.cfg | 2 | ||||
-rw-r--r-- | etc/mock/fedora-7-x86_64.cfg | 2 | ||||
-rw-r--r-- | etc/mock/fedora-8-x86_64.cfg | 2 | ||||
-rw-r--r-- | etc/mock/fedora-devel-x86_64.cfg | 2 | ||||
-rwxr-xr-x | py/mock.py | 12 | ||||
-rw-r--r-- | py/mock/util.py | 13 |
8 files changed, 31 insertions, 10 deletions
diff --git a/docs/mock.1 b/docs/mock.1 index beaf2fb..531d117 100644 --- a/docs/mock.1 +++ b/docs/mock.1 @@ -137,6 +137,12 @@ Change directory where config files are found \fB\-\-rpmbuild_timeout=\fR\fISECONDS\fP Fail build if rpmbuild takes longer than 'timeout' seconds .TP +\fB\-\-unpriv\fR +Drop privileges before running command when using --chroot +.TP +\fB\-\-cwd=\fR\fIDIR\fP +Change to the specified directory (relative to the chroot) before running command when using --chroot +.TP \fB\-q\fR, \fB\-\-quiet\fR Be quiet. .TP diff --git a/etc/mock/epel-4-x86_64.cfg b/etc/mock/epel-4-x86_64.cfg index 5819ad7..ea973d4 100644 --- a/etc/mock/epel-4-x86_64.cfg +++ b/etc/mock/epel-4-x86_64.cfg @@ -18,7 +18,7 @@ gpgcheck=0 assumeyes=1 # grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all # .i?86 packages except these. -exclude=[!g]*.i*86 g[!l]*.i?86 gl[!i]*.i?86 gli[!b]*.i?86 glib[!c]*.i?86 +exclude=[A-Za-fh-z]*.i?86 g[A-Za-km-z]*.i?86 gl[A-Za-hj-z]*.i?86 gli[A-Zac-z]*.i?86 glib[A-Za-bd-z]*.i?86 # repos diff --git a/etc/mock/epel-5-x86_64.cfg b/etc/mock/epel-5-x86_64.cfg index 559e2a4..0ee699c 100644 --- a/etc/mock/epel-5-x86_64.cfg +++ b/etc/mock/epel-5-x86_64.cfg @@ -18,7 +18,7 @@ gpgcheck=0 assumeyes=1 # grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all # .i?86 packages except these. -exclude=[!g]*.i*86 g[!l]*.i?86 gl[!i]*.i?86 gli[!b]*.i?86 glib[!c]*.i?86 +exclude=[A-Za-fh-z]*.i?86 g[A-Za-km-z]*.i?86 gl[A-Za-hj-z]*.i?86 gli[A-Zac-z]*.i?86 glib[A-Za-bd-z]*.i?86 # repos diff --git a/etc/mock/fedora-7-x86_64.cfg b/etc/mock/fedora-7-x86_64.cfg index 0c1d085..fe1f101 100644 --- a/etc/mock/fedora-7-x86_64.cfg +++ b/etc/mock/fedora-7-x86_64.cfg @@ -15,7 +15,7 @@ gpgcheck=0 assumeyes=1 # grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all # .i?86 packages except these. -exclude=[!g]*.i*86 g[!l]*.i?86 gl[!i]*.i?86 gli[!b]*.i?86 glib[!c]*.i?86 +exclude=[A-Za-fh-z]*.i?86 g[A-Za-km-z]*.i?86 gl[A-Za-hj-z]*.i?86 gli[A-Zac-z]*.i?86 glib[A-Za-bd-z]*.i?86 # repos diff --git a/etc/mock/fedora-8-x86_64.cfg b/etc/mock/fedora-8-x86_64.cfg index afd6f63..430adcf 100644 --- a/etc/mock/fedora-8-x86_64.cfg +++ b/etc/mock/fedora-8-x86_64.cfg @@ -15,7 +15,7 @@ gpgcheck=0 assumeyes=1 # grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all # .i?86 packages except these. -exclude=[!g]*.i*86 g[!l]*.i?86 gl[!i]*.i?86 gli[!b]*.i?86 glib[!c]*.i?86 +exclude=[A-Za-fh-z]*.i?86 g[A-Za-km-z]*.i?86 gl[A-Za-hj-z]*.i?86 gli[A-Zac-z]*.i?86 glib[A-Za-bd-z]*.i?86 # repos diff --git a/etc/mock/fedora-devel-x86_64.cfg b/etc/mock/fedora-devel-x86_64.cfg index 950b583..e69c88a 100644 --- a/etc/mock/fedora-devel-x86_64.cfg +++ b/etc/mock/fedora-devel-x86_64.cfg @@ -15,7 +15,7 @@ gpgcheck=0 assumeyes=1 # grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all # .i?86 packages except these. -exclude=[!g]*.i*86 g[!l]*.i?86 gl[!i]*.i?86 gli[!b]*.i?86 glib[!c]*.i?86 +exclude=[A-Za-fh-z]*.i?86 g[A-Za-km-z]*.i?86 gl[A-Za-hj-z]*.i?86 gli[A-Zac-z]*.i?86 glib[A-Za-bd-z]*.i?86 # repos @@ -150,6 +150,12 @@ def command_parse(config_opts): dest="rpmbuild_timeout", type="int", default=None, help="Fail build if rpmbuild takes longer than 'timeout'" " seconds ") + parser.add_option("--unpriv", action="store_true", default=False, + help="Drop privileges before running command when using --chroot") + parser.add_option("--cwd", action="store", default=None, + metavar="DIR", + help="Change to the specified directory (relative to the chroot)" + " before running command when using --chroot") # verbosity parser.add_option("-v", "--verbose", action="store_const", const=2, @@ -532,7 +538,11 @@ def main(ret): chroot._resetLogging() try: chroot._mountall() - chroot.doChroot(args, shell=shell) + if options.unpriv: + chroot.doChroot(args, shell=shell, + uid=chroot.chrootuid, gid=chroot.chrootgid, cwd=options.cwd) + else: + chroot.doChroot(args, shell=shell, cwd=options.cwd) finally: chroot._umountall() diff --git a/py/mock/util.py b/py/mock/util.py index 6f52b6d..a0a6b65 100644 --- a/py/mock/util.py +++ b/py/mock/util.py @@ -201,6 +201,10 @@ def condChroot(chrootPath): os.chroot(chrootPath) uid.setresuid(saved['ruid'], saved['euid']) +def condChdir(cwd): + if cwd is not None: + os.chdir(cwd) + def condDropPrivs(uid, gid): if gid is not None: os.setregid(gid, gid) @@ -256,12 +260,12 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0): # The "Not-as-complicated" version # decorate(traceLog()) -def do(command, shell=False, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uid=None, gid=None, personality=None, *args, **kargs): +def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True, returnOutput=0, uid=None, gid=None, personality=None, *args, **kargs): logger = kargs.get("logger", getLog()) output = "" start = time.time() - preexec = ChildPreExec(personality, chrootPath, uid, gid) + preexec = ChildPreExec(personality, chrootPath, cwd, uid, gid) try: child = None logger.debug("Executing command: %s" % command) @@ -312,9 +316,10 @@ def do(command, shell=False, chrootPath=None, timeout=0, raiseExc=True, returnOu return output class ChildPreExec(object): - def __init__(self, personality, chrootPath, uid, gid): + def __init__(self, personality, chrootPath, cwd, uid, gid): self.personality = personality self.chrootPath = chrootPath + self.cwd = cwd self.uid = uid self.gid = gid @@ -323,4 +328,4 @@ class ChildPreExec(object): condPersonality(self.personality) condChroot(self.chrootPath) condDropPrivs(self.uid, self.gid) - + condChdir(self.cwd) |