1 # data.py -- Calculated/Discovered Data Values
2 # Copyright 1998-2009 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
6 import os, sys, pwd, grp, platform
9 portage.proxy.lazyimport.lazyimport(globals(),
10 'portage.util:writemsg',
13 from portage.output import colorize
14 from portage.output import create_color_func
15 bad = create_color_func("BAD")
17 ostype=platform.system()
19 if ostype == "DragonFly" or ostype.endswith("BSD"):
24 lchown = getattr(os, "lchown", None)
27 if ostype == "Darwin":
28 def lchown(*pos_args, **key_args):
33 lchown = missingos.lchown
35 def lchown(*pos_args, **key_args):
36 writemsg(colorize("BAD", "!!!") + \
37 " It seems that os.lchown does not" + \
38 " exist. Please rebuild python.\n", noiselevel=-1)
41 def portage_group_warning():
42 warn_prefix = bad("*** WARNING *** ")
44 "For security reasons, only system administrators should be",
45 "allowed in the portage group. Untrusted users or processes",
46 "can potentially exploit the portage group for attacks such as",
47 "local privilege escalation."
50 writemsg(warn_prefix, noiselevel=-1)
51 writemsg(x, noiselevel=-1)
52 writemsg("\n", noiselevel=-1)
53 writemsg("\n", noiselevel=-1)
55 # Portage has 3 security levels that depend on the uid and gid of the main
56 # process and are assigned according to the following table:
58 # Privileges secpass uid gid
60 # group 1 any portage_gid
63 # If the "wheel" group does not exist then wheelgid falls back to 0.
64 # If the "portage" group does not exist then portage_uid falls back to wheelgid.
74 wheelgid=grp.getgrnam("wheel")[2]
78 #Discover the uid and gid of the portage user/group
80 portage_uid=pwd.getpwnam("portage")[2]
81 portage_gid=grp.getgrnam("portage")[2]
82 if secpass < 1 and portage_gid in os.getgroups():
87 writemsg(colorize("BAD",
88 "portage: 'portage' user or group missing.") + "\n", noiselevel=-1)
90 " For the defaults, line 1 goes into passwd, " + \
91 "and 2 into group.\n", noiselevel=-1)
92 writemsg(colorize("GOOD",
93 " portage:x:250:250:portage:/var/tmp/portage:/bin/false") \
94 + "\n", noiselevel=-1)
95 writemsg(colorize("GOOD", " portage::250:portage") + "\n",
97 portage_group_warning()
99 userpriv_groups = [portage_gid]
101 # Get a list of group IDs for the portage user. Do not use grp.getgrall()
102 # since it is known to trigger spurious SIGPIPE problems with nss_ldap.
103 from commands import getstatusoutput
104 mystatus, myoutput = getstatusoutput("id -G portage")
105 if mystatus == os.EX_OK:
106 for x in myoutput.split():
108 userpriv_groups.append(int(x))
112 userpriv_groups = list(set(userpriv_groups))
113 del getstatusoutput, mystatus, myoutput