Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 280521 | Differences between
and this patch

Collapse All | Expand All

(-)pym/portage/__init__.py (-14 / +10 lines)
Lines 6688-6695 Link Here
6688
			if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]):
6688
			if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]):
6689
				os.unlink(dest)
6689
				os.unlink(dest)
6690
			if selinux_enabled:
6690
			if selinux_enabled:
6691
				sid = selinux.get_lsid(src)
6691
				selinux.symlink(target,dest,src)
6692
				selinux.secure_symlink(target,dest,sid)
6693
			else:
6692
			else:
6694
				os.symlink(target,dest)
6693
				os.symlink(target,dest)
6695
			lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
6694
			lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
Lines 6744-6750 Link Here
6744
	if not hardlinked and (selinux_enabled or sstat.st_dev == dstat.st_dev):
6743
	if not hardlinked and (selinux_enabled or sstat.st_dev == dstat.st_dev):
6745
		try:
6744
		try:
6746
			if selinux_enabled:
6745
			if selinux_enabled:
6747
				ret=selinux.secure_rename(src,dest)
6746
				ret=selinux.rename(src,dest)
6748
			else:
6747
			else:
6749
				ret=os.rename(src,dest)
6748
				ret=os.rename(src,dest)
6750
			renamefailed=0
6749
			renamefailed=0
Lines 6762-6769 Link Here
6762
		if stat.S_ISREG(sstat[stat.ST_MODE]):
6761
		if stat.S_ISREG(sstat[stat.ST_MODE]):
6763
			try: # For safety copy then move it over.
6762
			try: # For safety copy then move it over.
6764
				if selinux_enabled:
6763
				if selinux_enabled:
6765
					selinux.secure_copy(src,dest+"#new")
6764
					selinux.copyfile(src,dest+"#new")
6766
					selinux.secure_rename(dest+"#new",dest)
6765
					selinux.rename(dest+"#new",dest)
6767
				else:
6766
				else:
6768
					shutil.copyfile(src,dest+"#new")
6767
					shutil.copyfile(src,dest+"#new")
6769
					os.rename(dest+"#new",dest)
6768
					os.rename(dest+"#new",dest)
Lines 6776-6790 Link Here
6776
				return None
6775
				return None
6777
		else:
6776
		else:
6778
			#we don't yet handle special, so we need to fall back to /bin/mv
6777
			#we don't yet handle special, so we need to fall back to /bin/mv
6779
			if selinux_enabled:
6778
			a=commands.getstatusoutput(MOVE_BINARY+" -f "+"'"+src+"' '"+dest+"'")
6780
				a=commands.getstatusoutput(MOVE_BINARY+" -c -f "+"'"+src+"' '"+dest+"'")
6779
			if a[0]!=0:
6781
			else:
6780
				print "!!! Failed to move special file:"
6782
				a=commands.getstatusoutput(MOVE_BINARY+" -f "+"'"+src+"' '"+dest+"'")
6781
				print "!!! '"+src+"' to '"+dest+"'"
6783
				if a[0]!=0:
6782
				print "!!!",a
6784
					print "!!! Failed to move special file:"
6783
				return None # failure
6785
					print "!!! '"+src+"' to '"+dest+"'"
6786
					print "!!!",a
6787
					return None # failure
6788
		try:
6784
		try:
6789
			if didcopy:
6785
			if didcopy:
6790
				if stat.S_ISLNK(sstat[stat.ST_MODE]):
6786
				if stat.S_ISLNK(sstat[stat.ST_MODE]):
(-)pym/portage/_selinux.py (-4 / +72 lines)
Lines 2-8 Link Here
2
# Distributed under the terms of the GNU General Public License v2
2
# Distributed under the terms of the GNU General Public License v2
3
# $Id$
3
# $Id$
4
4
5
import selinux
5
import os,shutil,selinux,string
6
from selinux import is_selinux_enabled
6
from selinux import is_selinux_enabled, getfilecon, lgetfilecon
7
from selinux_aux import setexec, secure_symlink, secure_rename, \
7
8
	secure_copy, secure_mkdir, getcontext, get_sid, get_lsid
8
def copyfile(src,dest):
9
	# without the str() I get an error:
10
	# failed to move src, dest
11
	# in method 'getfilecon', argument 1 of type 'char const *'
12
	(rc,ctx)=selinux.lgetfilecon(str(src))
13
	if rc < 0:
14
		raise OSError("copyfile: Failed getting context of \"%s\"." % src)
15
16
	setfscreate(ctx)
17
	shutil.copyfile(src,dest)
18
	setfscreate()
19
20
def getcontext():
21
	(rc,ctx)=selinux.getcon()
22
	if rc < 0:
23
		raise OSError("getcontext: Failed getting current process context.")
24
25
	return ctx
26
27
def mkdir(target,refdir):
28
	(rc,ctx)=selinux.getfilecon(refdir)
29
	if rc < 0:
30
		raise OSError("mkdir: Failed getting context of reference directory \"%s\"." % refdir)
31
32
	setfscreatecon(ctx)
33
	os.mkdir(target)
34
	setfscreatecon()
35
36
def rename(src,dest):
37
	# without the str() I get an error:
38
	# failed to move src, dest
39
	# in method 'getfilecon', argument 1 of type 'char const *'
40
	(rc,ctx)=selinux.lgetfilecon(str(src))
41
	if rc < 0:
42
		raise OSError("rename: Failed getting context of \"%s\"." % src)
43
44
	setfscreate(ctx)
45
	os.rename(src,dest)
46
	setfscreate()
47
48
def setexec(ctx="\n"):
49
	if selinux.setexeccon(ctx) < 0:
50
		raise OSError("setexec: Failed setting exec() context \"%s\"." % ctx)
51
52
def setfscreate(ctx="\n"):
53
	if selinux.setfscreatecon(ctx) < 0:
54
		raise OSError("setfscreate: Failed setting fs create context \"%s\"." % ctx)
55
56
def spawn(selinux_type,spawn_func,mycommand, opt_name=None, **keywords):
57
	con = getcontext().split(":")
58
	con[2] = selinux_type
59
	setexec(string.join(con,":"))
60
61
	retval = spawn_func(mycommand, opt_name=opt_name, **keywords)
62
63
	setexec()
64
	return retval
65
66
def symlink(target,link,reflnk):
67
	# without the str() I get an error:
68
	# failed to properly create symlink
69
	# in method 'lgetfilecon', argument 1 of type 'char const *'
70
	(rc,ctx)=selinux.lgetfilecon(str(reflnk))
71
	if rc < 0:
72
		raise OSError("symlink: Failed getting context of reference symlink \"%s\"." % reflnk)
73
74
	setfscreate(ctx)
75
	os.symlink(target,link)
76
	setfscreate()

Return to bug 280521