From ca9a0441e4bf226755aa29c3dc3a0d4867d32d89 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 10 Aug 2009 17:33:00 +0000 Subject: Bug #280998 - Misc selinux fixes. Thanks to Chris PeBenito for this patch. svn path=/main/trunk/; revision=13977 --- pym/portage/_selinux.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'pym/portage/_selinux.py') diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py index 2a50f7434..1b5f530ce 100644 --- a/pym/portage/_selinux.py +++ b/pym/portage/_selinux.py @@ -61,19 +61,27 @@ def rename(src, dest): finally: setfscreate() +def settype(newtype): + ret = getcontext().split(":") + ret[2] = newtype + return ":".join(ret) + def setexec(ctx="\n"): + if isinstance(ctx, unicode): + ctx = ctx.encode('utf_8', 'replace') if selinux.setexeccon(ctx) < 0: raise OSError("setexec: Failed setting exec() context \"%s\"." % ctx) def setfscreate(ctx="\n"): + if isinstance(ctx, unicode): + ctx = ctx.encode('utf_8', 'replace') if selinux.setfscreatecon(ctx) < 0: raise OSError( "setfscreate: Failed setting fs create context \"%s\"." % ctx) def spawn(selinux_type, spawn_func, mycommand, opt_name=None, **keywords): - con = getcontext().split(":") - con[2] = selinux_type - setexec(":".join(con)) + con = settype(selinux_type) + setexec(con) try: return spawn_func(mycommand, opt_name=opt_name, **keywords) finally: -- cgit v1.2.3-1-g7c22